From fbeb94d06c87a171b81bb42390e09f24f16484cc Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Wed, 2 Sep 2026 12:23:13 +0100 Subject: [PATCH] fix: revert packageBase constraint of asset emission Reverts half of #568. Closes #607. Basically, #568 does two things while stating it does one: 1. Ignore any paths outside the job's root 2. Ignore any paths emitted by a `node_modules` file which sit outside that same `node_modules` These were both introduced to fix some problems with sveltekit including things like `/bin` and what not. However, only the first is needed for that. The second change seems unnecessary and breaks a lot of common patterns (e.g. the `dotenv` one in the newly added test). --- src/analyze.ts | 20 ------------------- test/unit/env-file-from-pkg/.env | 1 + test/unit/env-file-from-pkg/.gitignore | 1 + test/unit/env-file-from-pkg/input.js | 1 + .../node_modules/some-pkg/index.js | 4 ++++ .../node_modules/some-pkg/package.json | 5 +++++ test/unit/env-file-from-pkg/output.js | 7 +++++++ 7 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 test/unit/env-file-from-pkg/.env create mode 100644 test/unit/env-file-from-pkg/.gitignore create mode 100644 test/unit/env-file-from-pkg/input.js create mode 100644 test/unit/env-file-from-pkg/node_modules/some-pkg/index.js create mode 100644 test/unit/env-file-from-pkg/node_modules/some-pkg/package.json create mode 100644 test/unit/env-file-from-pkg/output.js diff --git a/src/analyze.ts b/src/analyze.ts index a4ba9862..ed8b8b6c 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -1291,26 +1291,6 @@ export default async function analyze( return; } if (wildcardIndex !== -1 && stats.isFile()) return; - // do not emit assets outside the package boundary if inside node_modules - if (pkgBase) { - const nodeModulesBase = - id.substring(0, id.indexOf(path.sep + 'node_modules')) + - path.sep + - 'node_modules' + - path.sep; - if (!assetPath.startsWith(nodeModulesBase)) { - if (job.log) - console.log( - 'Skipping asset emission of ' + - assetPath + - ' for ' + - id + - ' as it is outside the package base ' + - pkgBase, - ); - return; - } - } if (stats.isFile()) { // do not emit file assets outside job.base if (job.ignoreFn(path.relative(job.base, assetPath))) return; diff --git a/test/unit/env-file-from-pkg/.env b/test/unit/env-file-from-pkg/.env new file mode 100644 index 00000000..3dd9dc77 --- /dev/null +++ b/test/unit/env-file-from-pkg/.env @@ -0,0 +1 @@ +MY_SECRET=value diff --git a/test/unit/env-file-from-pkg/.gitignore b/test/unit/env-file-from-pkg/.gitignore new file mode 100644 index 00000000..cf4bab9d --- /dev/null +++ b/test/unit/env-file-from-pkg/.gitignore @@ -0,0 +1 @@ +!node_modules diff --git a/test/unit/env-file-from-pkg/input.js b/test/unit/env-file-from-pkg/input.js new file mode 100644 index 00000000..878bb5e0 --- /dev/null +++ b/test/unit/env-file-from-pkg/input.js @@ -0,0 +1 @@ +require('some-pkg'); diff --git a/test/unit/env-file-from-pkg/node_modules/some-pkg/index.js b/test/unit/env-file-from-pkg/node_modules/some-pkg/index.js new file mode 100644 index 00000000..e155a4ee --- /dev/null +++ b/test/unit/env-file-from-pkg/node_modules/some-pkg/index.js @@ -0,0 +1,4 @@ +const fs = require('fs'); +const path = require('path'); + +fs.readFileSync(path.resolve(process.cwd(), '.env')); diff --git a/test/unit/env-file-from-pkg/node_modules/some-pkg/package.json b/test/unit/env-file-from-pkg/node_modules/some-pkg/package.json new file mode 100644 index 00000000..d234a264 --- /dev/null +++ b/test/unit/env-file-from-pkg/node_modules/some-pkg/package.json @@ -0,0 +1,5 @@ +{ + "name": "some-pkg", + "version": "1.0.0", + "main": "index.js" +} diff --git a/test/unit/env-file-from-pkg/output.js b/test/unit/env-file-from-pkg/output.js new file mode 100644 index 00000000..335f6f2b --- /dev/null +++ b/test/unit/env-file-from-pkg/output.js @@ -0,0 +1,7 @@ +[ + "package.json", + "test/unit/env-file-from-pkg/.env", + "test/unit/env-file-from-pkg/input.js", + "test/unit/env-file-from-pkg/node_modules/some-pkg/index.js", + "test/unit/env-file-from-pkg/node_modules/some-pkg/package.json" +]