diff --git a/.gitignore b/.gitignore index 9ac3e03..7f2942d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,10 @@ node_modules/ target/ +transpiled/ +types/ +bundled/ out/ -out-*/ coverage/ obj/ bin/ diff --git a/package-lock.json b/package-lock.json index fee1ed4..05bd2d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -645,6 +645,175 @@ "node": ">= 8" } }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.12.1.tgz", + "integrity": "sha512-iU2Sya8hNn1LhsYyf0N+L4Gf9Qc+9eBTJJJsaOGUp+7x4n2M9dxTt8UvhJl3oeftSjblSlpCfvjA/IfP3g5VjQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.12.1.tgz", + "integrity": "sha512-wlzcWiH2Ir7rdMELxFE5vuM7D6TsOcJ2Yw0c3vaBR3VOsJFVTx9xvwnAvhgU5Ii8Gd6+I11qNHwndDscIm0HXg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.12.1.tgz", + "integrity": "sha512-YRXa1+aZIFN5BaImK+84B3uNK8C6+ynKLPgvn29X9s0LTVCByp54TB7tdSMHDR7GTV39bz1lOmlLDuedgTwwHg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.12.1.tgz", + "integrity": "sha512-opjWJ4MevxeA8FhlngQWPBOvVWYNPFkq6/25rGgG+KOy0r8clYwL1CFd+PGwRqqMFVQ4/Qd3sQu5t7ucP7C/Uw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.12.1.tgz", + "integrity": "sha512-uBkwaI+gBUlIe+EfbNnY5xNyXuhZbDSx2nzzW8tRMjUmpScd6lCQYKY2V9BATHtv5Ef2OBq6SChEP8h+/cxifQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.12.1.tgz", + "integrity": "sha512-0bK9aG1kIg0Su7OcFTlexkVeNZ5IzEsnz1ept87a0TUgZ6HplSgkJAnFpEVRW7GRcikT4GlPV0pbtVedOaXHQQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.12.1.tgz", + "integrity": "sha512-qB6AFRXuP8bdkBI4D7UPUbE7OQf7u5OL+R94JE42Z2Qjmyj74FtDdLGeriRyBDhm4rQSvqAGCGC01b8Fu2LthQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.12.1.tgz", + "integrity": "sha512-sHig3LaGlpNgDj5o8uPEoGs98RII8HpNIqFtAI8/pYABO8i0nb1QzT0JDoXF/pxzqO+FkxvwkHZo9k0NJYDedg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.12.1.tgz", + "integrity": "sha512-nD3YcUv6jBJbBNFvSbp0IV66+ba/1teuBcu+fBBPZ33sidxitc6ErhON3JNavaH8HlswhWMC3s5rgZpM4MtPqQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.12.1.tgz", + "integrity": "sha512-7/XVZqgBby2qp/cO0TQ8uJK+9xnSdJ9ct6gSDdEr4MfABrjTyrW6Bau7HQ73a2a5tPB7hno49A0y1jhWGDN9OQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.12.1.tgz", + "integrity": "sha512-CYc64bnICG42UPL7TrhIwsJW4QcKkIt9gGlj21gq3VV0LL6XNb1yAdHVp1pIi9gkts9gGcT3OfUYHjGP7ETAiw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.12.1.tgz", + "integrity": "sha512-LN+vnlZ9g0qlHGlS920GR4zFCqAwbv2lULrR29yGaWP9u7wF5L7GqWu9Ah6/kFZPXPUkpdZwd//TNR+9XC9hvA==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.12.1.tgz", + "integrity": "sha512-n+vkrSyphvmU0qkQ6QBNXCGr2mKjhP08mPRM/Xp5Ck2FV4NrHU+y6axzDeixUrCBHVUS51TZhjqrKBBsHLKb2Q==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@sindresorhus/slugify": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@sindresorhus/slugify/-/slugify-1.1.2.tgz", @@ -698,6 +867,12 @@ "integrity": "sha512-cKio2eFB3v7qmKcvIHLUMw/dIx/8bhWPuzpzRT4unCPRTD8VdA9Zb0afxpcxOqR4PixRS7yT42FqGS8BYL8g1w==", "dev": true }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, "node_modules/@types/minimatch": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", @@ -3201,6 +3376,38 @@ "rimraf": "bin.js" } }, + "node_modules/rollup": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.12.1.tgz", + "integrity": "sha512-ggqQKvx/PsB0FaWXhIvVkSWh7a/PCLQAsMjBc+nA2M8Rv2/HG0X6zvixAB7KyZBRtifBUhy5k8voQX/mRnABPg==", + "dev": true, + "dependencies": { + "@types/estree": "1.0.5" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.12.1", + "@rollup/rollup-android-arm64": "4.12.1", + "@rollup/rollup-darwin-arm64": "4.12.1", + "@rollup/rollup-darwin-x64": "4.12.1", + "@rollup/rollup-linux-arm-gnueabihf": "4.12.1", + "@rollup/rollup-linux-arm64-gnu": "4.12.1", + "@rollup/rollup-linux-arm64-musl": "4.12.1", + "@rollup/rollup-linux-riscv64-gnu": "4.12.1", + "@rollup/rollup-linux-x64-gnu": "4.12.1", + "@rollup/rollup-linux-x64-musl": "4.12.1", + "@rollup/rollup-win32-arm64-msvc": "4.12.1", + "@rollup/rollup-win32-ia32-msvc": "4.12.1", + "@rollup/rollup-win32-x64-msvc": "4.12.1", + "fsevents": "~2.3.2" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -3662,6 +3869,7 @@ "itertools": "^2.2.5", "microtime": "^3.1.1", "prettier": "^3.2.5", + "rollup": "^4.12.1", "typescript": "^5.4.2" } }, @@ -3671,6 +3879,7 @@ "@11ty/eleventy": "^2.0.1", "github-markdown-css": "^5.5.1", "prettier": "^3.2.5", + "rollup": "^4.12.1", "typescript": "^5.4.2" } } diff --git a/packages/npm/goodrouter/package.json b/packages/npm/goodrouter/package.json index 188a1ef..ed864b1 100644 --- a/packages/npm/goodrouter/package.json +++ b/packages/npm/goodrouter/package.json @@ -3,27 +3,26 @@ "version": "2.1.4", "description": "a good router", "type": "module", - "main": "./out-commonjs/main.js", - "module": "./out/main.js", - "types": "./out/main.d.ts", + "main": "./bundled/main.cjs", + "module": "./bundled/main.js", + "types": "./types/main.d.ts", "exports": { ".": { - "require": "./out-commonjs/main.js", - "import": "./out/main.js", - "types": "./out/main.d.ts", - "browser": "./out/browser.js" + "require": "./bundled/main.cjs", + "import": "./bundled/main.js", + "types": "./types/main.d.ts" } }, "files": [ - "./out/**", - "./out-commonjs/**" + "./types/**", + "./bundled/**" ], "scripts": { - "prepack": "tsc --composite false; tsc --composite false --outDir out-commonjs --declaration false --module commonjs --moduleResolution Node10 ; echo {\\\"type\\\":\\\"commonjs\\\"}> out-commonjs/package.json", + "prepack": "./scripts/build.js", "pretest": "tsc --build", "build": "tsc --build", - "clean": "rm -rf out out-* ; tsc --build --clean", - "test": "node --test ./out/**/*.test.js" + "clean": "./scripts/clean.js", + "test": "node --test ./out/*.test.js ./out/*/*.test.js ./out/*/*/*.test.js" }, "repository": { "type": "git", @@ -48,6 +47,7 @@ "itertools": "^2.2.5", "microtime": "^3.1.1", "prettier": "^3.2.5", + "rollup": "^4.12.1", "typescript": "^5.4.2" }, "dependencies": { diff --git a/packages/npm/goodrouter/scripts/build.js b/packages/npm/goodrouter/scripts/build.js new file mode 100755 index 0000000..1b1cb3c --- /dev/null +++ b/packages/npm/goodrouter/scripts/build.js @@ -0,0 +1,34 @@ +#!/usr/bin/env node + +import cp from "child_process"; +import path from "path"; + +cp.spawnSync("tsc", [], { stdio: "inherit" }); + +cp.spawnSync( + "rollup", + [ + "--input", + path.resolve("transpiled", "main.js"), + "--file", + path.resolve("bundled", "main.js"), + "--sourcemap", + "--format", + "es", + ], + { stdio: "inherit" }, +); + +cp.spawnSync( + "rollup", + [ + "--input", + path.resolve("transpiled", "main.js"), + "--file", + path.resolve("bundled", "main.cjs"), + "--sourcemap", + "--format", + "cjs", + ], + { stdio: "inherit" }, +); diff --git a/packages/npm/goodrouter/scripts/clean.js b/packages/npm/goodrouter/scripts/clean.js new file mode 100755 index 0000000..d4cb073 --- /dev/null +++ b/packages/npm/goodrouter/scripts/clean.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +import fs from "fs"; +import path from "path"; + +fs.rmSync(path.resolve("transpiled"), { recursive: true, force: true }); +fs.rmSync(path.resolve("types"), { recursive: true, force: true }); +fs.rmSync(path.resolve("bundled"), { recursive: true, force: true }); diff --git a/packages/npm/goodrouter/src/root.ts b/packages/npm/goodrouter/src/root.ts new file mode 100644 index 0000000..dc655d6 --- /dev/null +++ b/packages/npm/goodrouter/src/root.ts @@ -0,0 +1,8 @@ +import path from "path"; + +export const projectRoot = getProjectRoot(); + +function getProjectRoot() { + const dirname = import.meta.dirname ?? __dirname; + return path.resolve(dirname, ".."); +} diff --git a/packages/npm/goodrouter/src/testing/templates.ts b/packages/npm/goodrouter/src/testing/templates.ts index 602cb83..fb049fb 100644 --- a/packages/npm/goodrouter/src/testing/templates.ts +++ b/packages/npm/goodrouter/src/testing/templates.ts @@ -1,6 +1,6 @@ import * as fs from "fs"; import * as path from "path"; -import { projectRoot } from "../utils/root.js"; +import { projectRoot } from "../root.js"; export function loadTemplates(name: string) { const filePath = path.join( diff --git a/packages/npm/goodrouter/src/utils/root.ts b/packages/npm/goodrouter/src/utils/root.ts deleted file mode 100644 index 0abd364..0000000 --- a/packages/npm/goodrouter/src/utils/root.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as path from "path"; -import { fileURLToPath } from "url"; - -export const projectRoot = makeProjectRoot(); - -function makeProjectRoot() { - const dirname = path.dirname(fileURLToPath(new URL(import.meta.url))); - return path.resolve(dirname, "..", ".."); -} diff --git a/packages/npm/goodrouter/tsconfig.json b/packages/npm/goodrouter/tsconfig.json index 461aed9..bc6207e 100644 --- a/packages/npm/goodrouter/tsconfig.json +++ b/packages/npm/goodrouter/tsconfig.json @@ -2,10 +2,11 @@ "extends": "@tsconfig/node20", "compilerOptions": { "rootDir": "./src", - "outDir": "./out", + "outDir": "./transpiled", + "declarationDir": "./types", "sourceMap": true, "declaration": true, - "composite": true + "lib": ["es2023", "DOM"] }, "include": ["src/**/*"] } diff --git a/packages/npm/www/package.json b/packages/npm/www/package.json index 6f9d11c..874eb72 100644 --- a/packages/npm/www/package.json +++ b/packages/npm/www/package.json @@ -9,6 +9,7 @@ "@11ty/eleventy": "^2.0.1", "github-markdown-css": "^5.5.1", "prettier": "^3.2.5", + "rollup": "^4.12.1", "typescript": "^5.4.2" } }