From 9e61e1722c19b48bd3b11095edef0112a8bbbcf5 Mon Sep 17 00:00:00 2001 From: Matt Leon <108271225+wydengyre@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:29:24 +0700 Subject: [PATCH] separate rai from lib (#48) resolves https://github.com/wydengyre/raiplayrss/issues/40 --- biome.json | 2 +- {lib => cf}/declarations.d.ts | 0 cf/tsconfig.json | 4 +-- cf/tsconfig.test.json | 2 +- cf/worker.test.ts | 2 +- cf/worker.ts | 4 +-- package.json | 25 +++++++++++-------- rai/declarations.d.ts | 1 + {lib => rai}/feed.test.ts | 0 {lib => rai}/feed.ts | 0 {lib => rai}/fetch.ts | 0 {lib => rai}/media.test.ts | 0 {lib => rai}/media.ts | 0 {lib => rai}/test/generi.json | 0 {lib => rai}/test/lastoriaingiallo.json | 0 .../test/lastoriaingiallo.parsed.json | 0 {lib => rai}/test/parse-feed.ts | 0 {lib => rai}/tsconfig.json | 0 {lib => rai}/tsconfig.test.json | 0 server/declarations.d.ts | 1 + {lib => server}/feed-handler.test.ts | 14 +++++------ {lib => server}/feed-handler.ts | 4 +-- {lib => server}/genres.test.ts | 4 +-- {lib => server}/genres.ts | 2 +- {lib => server}/handler.test.ts | 12 ++++----- {lib => server}/handler.ts | 2 +- {lib => server}/logger.ts | 0 server/tsconfig.json | 6 +++++ server/tsconfig.test.json | 9 +++++++ 29 files changed, 58 insertions(+), 36 deletions(-) rename {lib => cf}/declarations.d.ts (100%) create mode 100644 rai/declarations.d.ts rename {lib => rai}/feed.test.ts (100%) rename {lib => rai}/feed.ts (100%) rename {lib => rai}/fetch.ts (100%) rename {lib => rai}/media.test.ts (100%) rename {lib => rai}/media.ts (100%) rename {lib => rai}/test/generi.json (100%) rename {lib => rai}/test/lastoriaingiallo.json (100%) rename {lib => rai}/test/lastoriaingiallo.parsed.json (100%) rename {lib => rai}/test/parse-feed.ts (100%) rename {lib => rai}/tsconfig.json (100%) rename {lib => rai}/tsconfig.test.json (100%) create mode 100644 server/declarations.d.ts rename {lib => server}/feed-handler.test.ts (91%) rename {lib => server}/feed-handler.ts (91%) rename {lib => server}/genres.test.ts (90%) rename {lib => server}/genres.ts (96%) rename {lib => server}/handler.test.ts (94%) rename {lib => server}/handler.ts (96%) rename {lib => server}/logger.ts (100%) create mode 100644 server/tsconfig.json create mode 100644 server/tsconfig.test.json diff --git a/biome.json b/biome.json index fe9a70f..3b58c63 100644 --- a/biome.json +++ b/biome.json @@ -10,7 +10,7 @@ } }, "files": { - "include": ["cf/**/*.ts", "cf/**/*.json","lib/**/*.ts", "lib/**/*.json", "tools/**/*.ts"], + "include": ["rai/**/*.ts", "rai/**/*.json", "server/**/*.ts", "server/**/*.json", "cf/**/*.ts", "cf/**/*.json", "tools/**/*.ts"], "ignore": ["cf/.wrangler"] } } diff --git a/lib/declarations.d.ts b/cf/declarations.d.ts similarity index 100% rename from lib/declarations.d.ts rename to cf/declarations.d.ts diff --git a/cf/tsconfig.json b/cf/tsconfig.json index 2fb69c9..ca0f9ae 100644 --- a/cf/tsconfig.json +++ b/cf/tsconfig.json @@ -1,9 +1,9 @@ { "$schema": "https://json.schemastore.org/tsconfig", - "extends": "../lib/tsconfig.json", + "extends": "../server/tsconfig.json", "compilerOptions": { "types": ["@cloudflare/workers-types"] }, "include": ["*.ts"], - "exclude": ["*.test.ts"] + "exclude": ["*.test.ts", "declarations.d.ts"] } diff --git a/cf/tsconfig.test.json b/cf/tsconfig.test.json index 5eca346..5820e96 100644 --- a/cf/tsconfig.test.json +++ b/cf/tsconfig.test.json @@ -4,6 +4,6 @@ "compilerOptions": { "types": ["node"] }, - "include": ["*.test.ts", "../lib/declarations.d.ts"], + "include": ["*.test.ts", "declarations.d.ts"], "exclude": [] } diff --git a/cf/worker.test.ts b/cf/worker.test.ts index 43fea9e..7299f25 100644 --- a/cf/worker.test.ts +++ b/cf/worker.test.ts @@ -5,7 +5,7 @@ import { getPodcastFromFeed } from "@podverse/podcast-feed-parser"; import { createServerAdapter } from "@whatwg-node/server"; import { Router, RouterType, error, json } from "itty-router"; import { UnstableDevWorker, unstable_dev } from "wrangler"; -import genresJson from "../lib/test/generi.json" with { type: "json" }; +import genresJson from "../rai/test/generi.json" with { type: "json" }; import feedJson from "./test/lastoriaingiallo.json" with { type: "json" }; import expectedJson from "./test/lastoriaingiallo.parsed.json" with { type: "json", diff --git a/cf/worker.ts b/cf/worker.ts index 54bc415..2f661e0 100644 --- a/cf/worker.ts +++ b/cf/worker.ts @@ -1,5 +1,5 @@ -import { mkFetchHandler } from "../lib/handler.js"; -import * as logger from "../lib/logger.js"; +import { mkFetchHandler } from "../server/handler.js"; +import * as logger from "../server/logger.js"; export default (>{ fetch: (request, env, _ctx) => { diff --git a/package.json b/package.json index df783c5..84242f0 100644 --- a/package.json +++ b/package.json @@ -8,25 +8,30 @@ "check": "npm run lint && npm run typecheck", "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", + "ci-lint": "biome ci rai server cf tools", "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 tools", - "test": "npm run test-lib && npm run test-cf", + "lint": "biome check --apply rai server cf tools", + "test": "npm run test-rai && npm run test-server && npm run test-cf", "test-cf": "tsx --tsconfig ./cf/tsconfig.json --test 'cf/**/*.test.ts'", "test-cf-only": "tsx --tsconfig ./cf/tsconfig.json --test --test-only 'cf/**/*.test.ts'", - "test-lib": "tsx --tsconfig ./lib/tsconfig.json --test 'lib/**/*.test.ts'", - "test-lib-only": "tsx --tsconfig ./lib/tsconfig.json --test --test-only 'lib/**/*.test.ts'", - "typecheck": "concurrently \"npm run typecheck-lib\" \"npm run typecheck-cf\" \"npm run typecheck-tools\"", + "test-server": "tsx --tsconfig ./server/tsconfig.json --test 'server/**/*.test.ts'", + "test-server-only": "tsx --tsconfig ./server/tsconfig.json --test --test-only 'server/**/*.test.ts'", + "test-rai": "tsx --tsconfig ./rai/tsconfig.json --test 'rai/**/*.test.ts'", + "test-rai-only": "tsx --tsconfig ./rai/tsconfig.json --test --test-only 'rai/**/*.test.ts'", + "typecheck": "concurrently \"npm run typecheck-rai\" \"npm run typecheck-server\" \"npm run typecheck-cf\" \"npm run typecheck-tools\"", "//": "the output from typecheck can be hard to read, so we run them serially to make it easier", - "typecheck-serial": "npm run typecheck-lib && npm run typecheck-cf && npm run typecheck-tools", + "typecheck-serial": "npm run typecheck-rai && npm run typecheck-server && npm run typecheck-cf && npm run typecheck-tools", "typecheck-cf": "npm run typecheck-cf-prod && npm run typecheck-cf-test", "typecheck-cf-prod": "tsc --project cf/tsconfig.json", "typecheck-cf-test": "tsc --project cf/tsconfig.test.json", - "typecheck-lib": "npm run typecheck-lib-prod && npm run typecheck-lib-test", - "typecheck-lib-prod": "tsc --project lib/tsconfig.json", - "typecheck-lib-test": "tsc --project lib/tsconfig.test.json", + "typecheck-server": "npm run typecheck-server-prod && npm run typecheck-server-test", + "typecheck-server-prod": "tsc --project server/tsconfig.json", + "typecheck-server-test": "tsc --project server/tsconfig.test.json", + "typecheck-rai": "npm run typecheck-rai-prod && npm run typecheck-rai-test", + "typecheck-rai-prod": "tsc --project rai/tsconfig.json", + "typecheck-rai-test": "tsc --project rai/tsconfig.test.json", "typecheck-tools": "tsc --project tools/tsconfig.json" }, "author": "", diff --git a/rai/declarations.d.ts b/rai/declarations.d.ts new file mode 100644 index 0000000..0b0ceff --- /dev/null +++ b/rai/declarations.d.ts @@ -0,0 +1 @@ +declare module "@podverse/podcast-feed-parser"; diff --git a/lib/feed.test.ts b/rai/feed.test.ts similarity index 100% rename from lib/feed.test.ts rename to rai/feed.test.ts diff --git a/lib/feed.ts b/rai/feed.ts similarity index 100% rename from lib/feed.ts rename to rai/feed.ts diff --git a/lib/fetch.ts b/rai/fetch.ts similarity index 100% rename from lib/fetch.ts rename to rai/fetch.ts diff --git a/lib/media.test.ts b/rai/media.test.ts similarity index 100% rename from lib/media.test.ts rename to rai/media.test.ts diff --git a/lib/media.ts b/rai/media.ts similarity index 100% rename from lib/media.ts rename to rai/media.ts diff --git a/lib/test/generi.json b/rai/test/generi.json similarity index 100% rename from lib/test/generi.json rename to rai/test/generi.json diff --git a/lib/test/lastoriaingiallo.json b/rai/test/lastoriaingiallo.json similarity index 100% rename from lib/test/lastoriaingiallo.json rename to rai/test/lastoriaingiallo.json diff --git a/lib/test/lastoriaingiallo.parsed.json b/rai/test/lastoriaingiallo.parsed.json similarity index 100% rename from lib/test/lastoriaingiallo.parsed.json rename to rai/test/lastoriaingiallo.parsed.json diff --git a/lib/test/parse-feed.ts b/rai/test/parse-feed.ts similarity index 100% rename from lib/test/parse-feed.ts rename to rai/test/parse-feed.ts diff --git a/lib/tsconfig.json b/rai/tsconfig.json similarity index 100% rename from lib/tsconfig.json rename to rai/tsconfig.json diff --git a/lib/tsconfig.test.json b/rai/tsconfig.test.json similarity index 100% rename from lib/tsconfig.test.json rename to rai/tsconfig.test.json diff --git a/server/declarations.d.ts b/server/declarations.d.ts new file mode 100644 index 0000000..0b0ceff --- /dev/null +++ b/server/declarations.d.ts @@ -0,0 +1 @@ +declare module "@podverse/podcast-feed-parser"; diff --git a/lib/feed-handler.test.ts b/server/feed-handler.test.ts similarity index 91% rename from lib/feed-handler.test.ts rename to server/feed-handler.test.ts index b63d263..7c9decc 100644 --- a/lib/feed-handler.test.ts +++ b/server/feed-handler.test.ts @@ -1,15 +1,15 @@ import { strict as assert } from "node:assert"; import test from "node:test"; import { json } from "itty-router"; -import { feedHandler } from "./feed-handler.js"; -import { FetchWithErr, NotOk, OkResponse } from "./fetch.js"; -import * as logger from "./logger.js"; -import genresJson from "./test/generi.json"; -import feedJson from "./test/lastoriaingiallo.json"; -import expectedJson from "./test/lastoriaingiallo.parsed.json" with { +import { FetchWithErr, NotOk, OkResponse } from "../rai/fetch.js"; +import genresJson from "../rai/test/generi.json"; +import feedJson from "../rai/test/lastoriaingiallo.json"; +import expectedJson from "../rai/test/lastoriaingiallo.parsed.json" with { type: "json", }; -import { parseFeed } from "./test/parse-feed.js"; +import { parseFeed } from "../rai/test/parse-feed.js"; +import { feedHandler } from "./feed-handler.js"; +import * as logger from "./logger.js"; test("feed-handler", async (t) => { await t.test(rssFeedSuccess); diff --git a/lib/feed-handler.ts b/server/feed-handler.ts similarity index 91% rename from lib/feed-handler.ts rename to server/feed-handler.ts index b762dc9..d63cdd5 100644 --- a/lib/feed-handler.ts +++ b/server/feed-handler.ts @@ -1,6 +1,6 @@ import { createResponse } from "itty-router"; -import { convertFeed } from "./feed.js"; -import { FetchWithErr, NotOk } from "./fetch.js"; +import { convertFeed } from "../rai/feed.js"; +import { FetchWithErr, NotOk } from "../rai/fetch.js"; import { Logger } from "./logger.js"; export { Config, feedHandler }; diff --git a/lib/genres.test.ts b/server/genres.test.ts similarity index 90% rename from lib/genres.test.ts rename to server/genres.test.ts index a069dae..f8973aa 100644 --- a/lib/genres.test.ts +++ b/server/genres.test.ts @@ -1,9 +1,9 @@ import { strict as assert } from "node:assert"; import test from "node:test"; import { json } from "itty-router"; -import { FetchWithErr, NotOk, OkResponse } from "./fetch.js"; +import { FetchWithErr, NotOk, OkResponse } from "../rai/fetch.js"; +import genresJson from "../rai/test/generi.json" with { type: "json" }; import { genresHtml } from "./genres.js"; -import genresJson from "./test/generi.json" with { type: "json" }; test("genres", async (t) => { await t.test(genresHtmlSuccess); diff --git a/lib/genres.ts b/server/genres.ts similarity index 96% rename from lib/genres.ts rename to server/genres.ts index ca03045..12dddaa 100644 --- a/lib/genres.ts +++ b/server/genres.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { FetchWithErr } from "./fetch.js"; +import { FetchWithErr } from "../rai/fetch.js"; export { Conf, genresHtml }; diff --git a/lib/handler.test.ts b/server/handler.test.ts similarity index 94% rename from lib/handler.test.ts rename to server/handler.test.ts index f14042c..c7d81bc 100644 --- a/lib/handler.test.ts +++ b/server/handler.test.ts @@ -1,14 +1,14 @@ import { strict as assert } from "node:assert"; import test from "node:test"; import { error, json } from "itty-router"; -import { mkFetchHandler } from "./handler.js"; -import * as logger from "./logger.js"; -import genresJson from "./test/generi.json"; -import feedJson from "./test/lastoriaingiallo.json"; -import expectedJson from "./test/lastoriaingiallo.parsed.json" with { +import genresJson from "../rai/test/generi.json"; +import feedJson from "../rai/test/lastoriaingiallo.json"; +import expectedJson from "../rai/test/lastoriaingiallo.parsed.json" with { type: "json", }; -import { parseFeed } from "./test/parse-feed.js"; +import { parseFeed } from "../rai/test/parse-feed.js"; +import { mkFetchHandler } from "./handler.js"; +import * as logger from "./logger.js"; test("handler", async (t) => { await t.test(indexSuccess); diff --git a/lib/handler.ts b/server/handler.ts similarity index 96% rename from lib/handler.ts rename to server/handler.ts index 2e4dfac..9e5b478 100644 --- a/lib/handler.ts +++ b/server/handler.ts @@ -1,6 +1,6 @@ import { Router, createResponse, error, html, text } from "itty-router"; +import { mkFetchWithErr } from "../rai/fetch.js"; import { feedHandler } from "./feed-handler.js"; -import { mkFetchWithErr } from "./fetch.js"; import { genresHtml } from "./genres.js"; import { Logger } from "./logger.js"; diff --git a/lib/logger.ts b/server/logger.ts similarity index 100% rename from lib/logger.ts rename to server/logger.ts diff --git a/server/tsconfig.json b/server/tsconfig.json new file mode 100644 index 0000000..2bc7432 --- /dev/null +++ b/server/tsconfig.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../rai/tsconfig.json", + "include": ["*.ts"], + "exclude": ["*.test.ts", "declarations.d.ts"] +} diff --git a/server/tsconfig.test.json b/server/tsconfig.test.json new file mode 100644 index 0000000..5820e96 --- /dev/null +++ b/server/tsconfig.test.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.json", + "compilerOptions": { + "types": ["node"] + }, + "include": ["*.test.ts", "declarations.d.ts"], + "exclude": [] +}