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
21 changes: 12 additions & 9 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,15 +1299,18 @@ export default async function analyze(
'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,
);
const message =
'Skipping asset emission of ' +
assetPath +
' for ' +
id +
' as it is outside the package base ' +
pkgBase;
// Also surfaced as a warning, not only under `job.log`: the file is otherwise
// simply absent from the output, so the first symptom is a runtime failure in
// the deployed application rather than anything visible at build time.
job.warnings.add(new Error(message));
if (job.log) console.log(message);
return;
}
}
Expand Down
15 changes: 14 additions & 1 deletion test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ for (const { testName, isRoot } of unitTests) {
// Ignore.
}

const { fileList, reasons } = await nodeFileTrace(
const { fileList, reasons, warnings } = await nodeFileTrace(
inputFileNames.map((file) => join(unitPath, file)),
{
conditions: testOpts.conditions,
Expand Down Expand Up @@ -216,6 +216,19 @@ for (const { testName, isRoot } of unitTests) {

const getReasonType = (f) => reasons.get(normalizeInputRoot(f)).type;

// Only on the uncached pass: the second run replays cached analysis and does not
// re-emit warnings.
if (!cached && testName === 'pkg-cwd-asset-outside-pkg-base') {
// The asset stays out of the output, but the skip has to be reported: silently
// omitting a file the package reads at runtime only surfaces once the deployed
// application fails.
expect(
[...warnings].some((warning) =>
warning.message.startsWith('Skipping asset emission of'),
),
).toBe(true);
}

if (testName === 'multi-input') {
const collectFiles = (parent, files = new Set()) => {
fileList.forEach((file) => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/pkg-cwd-asset-outside-pkg-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-cwd-asset-outside-pkg-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-cwd-asset-outside-pkg-base/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"package.json",
"test/unit/pkg-cwd-asset-outside-pkg-base/input.js",
"test/unit/pkg-cwd-asset-outside-pkg-base/node_modules/some-pkg/index.js",
"test/unit/pkg-cwd-asset-outside-pkg-base/node_modules/some-pkg/package.json"
]
1 change: 1 addition & 0 deletions test/unit/pkg-cwd-asset-outside-pkg-base/some.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { config: true };