From 2d7af8a4147f553ab21d1311f21c1a067e517498 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 8 Sep 2024 15:38:14 +0200 Subject: [PATCH] use pre-bundled versions of `@jsr/std__path` --- .npmrc | 1 + .../config-array/fix-std__path-imports.js | 26 +++++++++++++++++ packages/config-array/package.json | 5 ++-- .../config-array/rollup.std__path-config.js | 28 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 packages/config-array/fix-std__path-imports.js create mode 100644 packages/config-array/rollup.std__path-config.js diff --git a/.npmrc b/.npmrc index c1ca392..1b8d617 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ package-lock = false +@jsr:registry=https://npm.jsr.io diff --git a/packages/config-array/fix-std__path-imports.js b/packages/config-array/fix-std__path-imports.js new file mode 100644 index 0000000..9966e0b --- /dev/null +++ b/packages/config-array/fix-std__path-imports.js @@ -0,0 +1,26 @@ +/* + * Replace import specifiers in "dist" modules to use the bundled versions of "@jsr/std__path". + * + * In "dist/cjs/index.cjs": + * - '@jsr/std__path/posix' → './std__path/posix.cjs' + * - '@jsr/std__path/windows' → './std__path/windows.cjs' + * + * In "dist/esm/index.js": + * - '@jsr/std__path/posix' → './std__path/posix.js' + * - '@jsr/std__path/windows' → './std__path/windows.js' + */ + +import { readFile, writeFile } from "node:fs/promises"; + +async function replaceInFile(file, search, replacement) { + let text = await readFile(file, "utf-8"); + text = text.replace(search, replacement); + await writeFile(file, text); +} + +const SEARCH_REGEXP = /'@jsr\/std__path\/(.+?)'/gu; + +await Promise.all([ + replaceInFile("dist/cjs/index.cjs", SEARCH_REGEXP, "'./std__path/$1.cjs'"), + replaceInFile("dist/esm/index.js", SEARCH_REGEXP, "'./std__path/$1.js'"), +]); diff --git a/packages/config-array/package.json b/packages/config-array/package.json index 1a606cd..246ce5e 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -33,7 +33,8 @@ "scripts": { "build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js", "build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"", - "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts", + "build:std__path": "rollup -c rollup.std__path-config.js && node fix-std__path-imports", + "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path", "test:jsr": "npx jsr@latest publish --dry-run", "pretest": "npm run build", "test": "mocha tests/", @@ -47,11 +48,11 @@ "license": "Apache-2.0", "dependencies": { "@eslint/object-schema": "^2.1.4", - "@jsr/std__path": "https://npm.jsr.io/~/11/@jsr/std__path/1.0.3.tgz", "debug": "^4.3.1", "minimatch": "^3.1.2" }, "devDependencies": { + "@jsr/std__path": "^1.0.4", "@types/minimatch": "^3.0.5", "c8": "^9.1.0", "mocha": "^10.4.0", diff --git a/packages/config-array/rollup.std__path-config.js b/packages/config-array/rollup.std__path-config.js new file mode 100644 index 0000000..533d7a0 --- /dev/null +++ b/packages/config-array/rollup.std__path-config.js @@ -0,0 +1,28 @@ +export default [ + { + input: "../../node_modules/@jsr/std__path/posix/mod.js", + output: [ + { + file: "./dist/cjs/std__path/posix.cjs", + format: "cjs", + }, + { + file: "./dist/esm/std__path/posix.js", + format: "esm", + }, + ], + }, + { + input: "../../node_modules/@jsr/std__path/windows/mod.js", + output: [ + { + file: "./dist/cjs/std__path/windows.cjs", + format: "cjs", + }, + { + file: "./dist/esm/std__path/windows.js", + format: "esm", + }, + ], + }, +];