diff --git a/package.json b/package.json index 617b7d8f9..a5681247b 100644 --- a/package.json +++ b/package.json @@ -373,7 +373,7 @@ "./dist/index.mjs" ], "scripts": { - "build": "node --max-old-space-size=12288 node_modules/tsup/dist/cli-default.js", + "build": "node scripts/patch-tsup.mjs && node --max-old-space-size=12288 node_modules/tsup/dist/cli-default.js", "dev": "node --max-old-space-size=12288 node_modules/tsup/dist/cli-default.js --watch", "pre-release": "npm version prerelease --preid=alpha --no-git-tag-version && node scripts/sync-version.mjs && npm publish --access public --tag alpha", "pre-release:create-lousho": "npm version prerelease --preid=alpha --no-git-tag-version -w create-lousho && npm run build -w create-lousho && npm publish -w create-lousho --access public --tag alpha", diff --git a/scripts/patch-tsup.mjs b/scripts/patch-tsup.mjs new file mode 100644 index 000000000..1a1be60bb --- /dev/null +++ b/scripts/patch-tsup.mjs @@ -0,0 +1,10 @@ +import { readFileSync, writeFileSync } from 'node:fs'; + +const file = 'node_modules/tsup/dist/rollup.js'; +const anchor = 'logCache("HIT", cacheKey);'; +const fix = 'if (overrideConfigPath) dirName = path__namespace.dirname(path__namespace.resolve(process.cwd(), overrideConfigPath));'; +const src = readFileSync(file, 'utf8'); +if (!src.includes(fix)) { + if (!src.includes(anchor)) throw new Error(`patch-tsup: anchor not found in ${file}; tsup changed, re-check the dts cache bug`); + writeFileSync(file, src.replace(anchor, `${anchor}\n ${fix}`)); +}