Skip to content

Commit

Permalink
use pre-bundled versions of @jsr/std__path
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Sep 8, 2024
1 parent a73982e commit 2d7af8a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock = false
@jsr:registry=https://npm.jsr.io
26 changes: 26 additions & 0 deletions packages/config-array/fix-std__path-imports.js
Original file line number Diff line number Diff line change
@@ -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'"),
]);
5 changes: 3 additions & 2 deletions packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions packages/config-array/rollup.std__path-config.js
Original file line number Diff line number Diff line change
@@ -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",
},
],
},
];

0 comments on commit 2d7af8a

Please sign in to comment.