Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove workers node compatibility layer
Browse files Browse the repository at this point in the history
wydengyre committed Jan 25, 2024
1 parent efb053c commit a7fbce3
Showing 10 changed files with 194 additions and 111 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
raiplayrss
==========

`npm run build-podcast` to build the intermediate `podcast` lib.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
}
},
"files": {
"include": ["cf/**/*.ts", "cf/**/*.json","lib/**/*.ts", "lib/**/*.json"],
"include": ["cf/**/*.ts", "cf/**/*.json","lib/**/*.ts", "lib/**/*.json", "tools/*.ts"],
"ignore": ["cf/.wrangler"]
}
}
3 changes: 3 additions & 0 deletions build/podcast/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
index.js
types
*.d.ts
3 changes: 3 additions & 0 deletions build/podcast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Podcast dependency gets inserted here so that we don't need any Node libraries to run the site.

Currently, the podcast lib we use depends on Node for a few things. We can just compile a version with stubs and we should be good to go.
1 change: 0 additions & 1 deletion cf/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name = "raiplayrss"
main = "./worker.ts"
compatibility_date = "2024-01-16"
node_compat = true

[env.prod.vars]
BASE_URL = "https://raiplayrss.workers.dev/"
6 changes: 3 additions & 3 deletions lib/feed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PromisePool } from "@supercharge/promise-pool";
import { FeedOptions, ItemOptions, Podcast } from "podcast";
import { z } from "zod";
import { Podcast } from "../build/podcast/index.js";
import { Fetcher as MediaFetcher } from "./media.js";

const cardSchema = z.object({
@@ -116,7 +116,7 @@ export class Convertor {
this.#raiBaseUrl,
).toString();

const options: FeedOptions = {
const options = {
// feedUrl: TODO
// siteUrl: TODO
imageUrl,
@@ -136,7 +136,7 @@ export class Convertor {
return new Podcast(options, results).buildXml();
}

async convertCard(card: Card): Promise<ItemOptions> {
async convertCard(card: Card) {
const imageUrl = new URL(card.image, this.#raiBaseUrl).toString();
const date = new Date(card.track_info.date);
const mediaInfo = await this.#fetcher.fetchInfo(
227 changes: 126 additions & 101 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,21 +3,23 @@
"version": "0.0.0",
"description": "",
"scripts": {
"build-podcast": "tsx --tsconfig ./tools/tsconfig.json tools/build-podcast.ts",
"clean": "rm -rf dist",
"check": "npm run lint && npm run typecheck",
"ci": "npm run ci-check && npm run test",
"ci": "npm run build-podcast && npm run ci-check && npm run test",
"ci-check": "npm run ci-lint && npm run typecheck",
"ci-lint": "biome ci cf lib cf/testdata",
"ci-lint": "biome ci cf lib",
"deploy": "wrangler -c cf/wrangler.toml --env prod deploy",
"deploy-preview": "wrangler -c cf/wrangler.toml deploy --dry-run --outdir '../dist'",
"dev": "wrangler -c cf/wrangler.toml dev",
"lint": "biome check --apply cf lib",
"lint": "biome check --apply cf lib tools",
"test": "npm run test-lib && npm run test-cf",
"test-cf": "tsx --tsconfig ./cf/tsconfig.json --env-file=cf/.dev.vars --test 'cf/**/*.test.ts'",
"test-lib": "tsx --tsconfig ./lib/tsconfig.json --test 'lib/**/*.test.ts'",
"typecheck": "npm run typecheck-lib && npm run typecheck-cf",
"typecheck": "npm run typecheck-lib && npm run typecheck-cf && npm run typecheck-tools",
"typecheck-cf": "tsc --project cf/tsconfig.json",
"typecheck-lib": "tsc --project lib/tsconfig.json"
"typecheck-lib": "tsc --project lib/tsconfig.json",
"typecheck-tools": "tsc --project tools/tsconfig.json"
},
"author": "",
"license": "ISC",
@@ -28,6 +30,8 @@
"@podverse/podcast-feed-parser": "^1.1.1",
"@tsconfig/node21": "^21.0.1",
"@whatwg-node/server": "^0.9.23",
"esbuild": "0.19.12",
"esbuild-plugin-polyfill-node": "0.3.0",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"wrangler": "^3.24.0"
35 changes: 35 additions & 0 deletions tools/build-podcast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { readFileSync, writeFileSync } from "node:fs";
import { cp } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "esbuild";
import { polyfillNode } from "esbuild-plugin-polyfill-node";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const entrypointPath = path.join(
__dirname,
"../node_modules/podcast/dist/esm/index.js",
);
const podcastOutPath = path.join(__dirname, "../build/podcast/index.js");
const typesPath = path.join(__dirname, "../node_modules/podcast/dist/types");
const typesOutPath = path.join(__dirname, "../build/podcast/types");

const copyP = cp(typesPath, typesOutPath, { recursive: true });

const buildP = build({
entryPoints: [entrypointPath],
bundle: true,
format: "esm",
outfile: podcastOutPath,
plugins: [polyfillNode({})],
});

await Promise.all([copyP, buildP]);

// this is a horrible hack for some kind of showstopper bug in the output
const outputFileContent = readFileSync(podcastOutPath, "utf-8");
const fixedContent = outputFileContent
.replace("self.TextEncoder", "globalThis.TextEncoder")
.replace("self.TextDecoder", "globalThis.TextDecoder");
writeFileSync(podcastOutPath, fixedContent);
10 changes: 10 additions & 0 deletions tools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/node21/tsconfig.json",
"compilerOptions": {
"module": "nodenext",
"resolveJsonModule": true,
"noEmit": true
},
"include": ["*.ts"]
}

0 comments on commit a7fbce3

Please sign in to comment.