Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,33 @@ 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;
assets.add(assetPath);
} else if (stats.isDirectory()) {
// do not emit directory assets outside job.base
if (job.ignoreFn(path.relative(job.base, assetPath))) return;
if (validWildcard(assetPath)) emitAssetDirectory(assetPath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ast-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function isIdentifierRead(node: Node, parent: Node) {
return parent.id !== node;
// disregard the `bar` in `export { foo as bar }`
case 'ExportSpecifier':
return false;
return node.name === parent.exported.name;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a drive-by fix. Seems to be more in line with the comment above which checks if it's just export { foo } or aliased

// disregard the `bar` in `function (bar) {}`
case 'FunctionExpression':
case 'FunctionDeclaration':
Expand Down
1 change: 1 addition & 0 deletions test/unit/pkg-dir-outside-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
1 change: 1 addition & 0 deletions test/unit/pkg-dir-outside-base/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('some-pkg');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/unit/pkg-dir-outside-base/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"package.json",
"test/unit/pkg-dir-outside-base/input.js",
"test/unit/pkg-dir-outside-base/node_modules/some-pkg/index.js",
"test/unit/pkg-dir-outside-base/node_modules/some-pkg/package.json"
]
1 change: 1 addition & 0 deletions test/unit/pkg-dir-outside-base/secret-dir/secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secret
1 change: 1 addition & 0 deletions test/unit/pkg-file-outside-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
1 change: 1 addition & 0 deletions test/unit/pkg-file-outside-base/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('some-pkg');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/unit/pkg-file-outside-base/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"package.json",
"test/unit/pkg-file-outside-base/input.js",
"test/unit/pkg-file-outside-base/node_modules/some-pkg/index.js",
"test/unit/pkg-file-outside-base/node_modules/some-pkg/package.json"
]
1 change: 1 addition & 0 deletions test/unit/pkg-file-outside-base/secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secret content