diff --git a/.gitignore b/.gitignore index b1b23fd..ad40dd8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ index.html api/ !backends/github/api/ !backends/coda/api/ -lib \ No newline at end of file +_redirects \ No newline at end of file diff --git a/_build/filters.js b/_build/filters.js index f3f0432..0ba89ec 100644 --- a/_build/filters.js +++ b/_build/filters.js @@ -1,4 +1,5 @@ import path from "path"; +import packageLock from "../package-lock.json" with { type: "json" }; export function relative (page) { if (!page) { @@ -10,4 +11,13 @@ export function relative (page) { let ret = path.relative(pagePath, "/"); return ret || "."; +} + +/** + * Convert a package.json dependency version to + * @param {*} semver + * @returns + */ +export function version (module) { + return packageLock.packages[`node_modules/${module}`]?.version; } \ No newline at end of file diff --git a/_build/lib.mjs b/_build/lib.mjs deleted file mode 100644 index 9c31881..0000000 --- a/_build/lib.mjs +++ /dev/null @@ -1,28 +0,0 @@ -import { execSync } from "child_process"; -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; -import process from "process"; - -// Set the current working directory to the root of the project -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -process.chdir(path.join(__dirname, "..")); - -// Read package.json -const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf8")); - -// FIXME This will only work for modules that *either* don’t have dependencies *or* provide a bundled version -let dependencies = Object.keys(packageJson.dependencies); -console.info(`Found ${dependencies.length} dependencies: ${ dependencies.join(", ") }`); - -let modules = dependencies.map(dep => `node_modules/${dep}`); -execSync(`rm -rf lib && mkdir -p lib && cp -R ${modules.join(" ")} lib`, (err, stdout, stderr) => { - if (err) { - throw err; - } - - console.info(stdout); - console.error(stderr); -}); - -console.info(`Copied ${modules.length} dependencies to lib/`); \ No newline at end of file diff --git a/_redirects.njk b/_redirects.njk new file mode 100644 index 0000000..91306e6 --- /dev/null +++ b/_redirects.njk @@ -0,0 +1,12 @@ +--- +permalink: _redirects +layout: null +eleventyExcludeFromCollections: true +--- + +{% for module, version in pkg.dependencies -%} +node_modules/{{ module }}/* https://cdn.jsdelivr.net/npm/{{ module }}@{{ (module | version) or "latest" }}/:splat 200 +{% endfor %} + +# Catch all NPM fallback +node_modules/:modulename/* https://cdn.jsdelivr.net/npm/:modulename@latest/:splat 200 \ No newline at end of file diff --git a/formats/csv/index.js b/formats/csv/index.js index be571c0..e409e3c 100644 --- a/formats/csv/index.js +++ b/formats/csv/index.js @@ -1,5 +1,5 @@ import Format from "../../src/format.js"; -import { parse, stringify } from "../../lib/csv/dist/esm/sync.js"; +import { parse, stringify } from "../../node_modules/csv/dist/esm/sync.js"; export default class CSV extends Format { static defaultOptions = { diff --git a/formats/yaml/index.js b/formats/yaml/index.js index 6008f02..e2fe2b1 100644 --- a/formats/yaml/index.js +++ b/formats/yaml/index.js @@ -1,5 +1,5 @@ import Format from "../../src/format.js"; -import { parse, stringify } from "../../lib/yaml/browser/index.js"; +import { parse, stringify } from "../../node_modules/yaml/browser/index.js"; export default class YAML extends Format { static extensions = ["yaml", "yml"]; diff --git a/package.json b/package.json index 2192a51..fdd5737 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,8 @@ "scripts": { "test": "npx htest test/index.js", "build:html": "npx @11ty/eleventy --config=_build/eleventy.js", - "build:lib": "node _build/lib.mjs", "build:docs": "npx typedoc", - "build": "npm run build:lib && npm run build:html && npm run build:docs", + "build": "npm run build:html && npm run build:docs", "watch:html": "npx @11ty/eleventy --config=_build/eleventy.js --watch", "watch:docs": "npx typedoc --watch --preserveWatchOutput", "watch": "npx concurrently -n w: npm:watch:*", diff --git a/src/util.js b/src/util.js index 522b813..c20b584 100644 --- a/src/util.js +++ b/src/util.js @@ -81,7 +81,7 @@ export function phrase (me, id, ...args) { return id + " " + args.join(" "); } -export const URLPattern = globalThis.URLPattern ?? (await import("../lib/urlpattern-polyfill/index.js")).URLPattern; +export const URLPattern = globalThis.URLPattern ?? (await import("../node_modules/urlpattern-polyfill/index.js")).URLPattern; export function testURLs (source, urls) { if (!urls) {