Skip to content
Merged
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: 22 additions & 2 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ function calculateResolveMappings(
);
return dependencies.reduce((m, c) => {
if (c.node.type !== 'npm' && c.outputs[0] != null) {
m[c.name] = joinPathFragments(context.root, c.outputs[0]);
// `outputs` are cache patterns and may contain globs (e.g. from the
// inferred `@nx/js/typescript` build target). Strip the glob portion
// so the runtime require overrides resolve to the actual output dir.
const outputDir = stripGlobToBaseDir(c.outputs[0]);
m[c.name] = joinPathFragments(context.root, outputDir);
}
return m;
}, {});
Expand Down Expand Up @@ -453,7 +457,13 @@ function getFileToRun(
projectRoot: project.data.root,
workspaceRoot: context.root,
});
return path.join(outputFilePath, 'main.js');
// `outputs` are cache patterns and may contain globs (e.g. the inferred
// `@nx/js/typescript` build target scopes its output to
// `{projectRoot}/dist/**/*.{js,...}` to avoid caching non-tsc files).
// Strip the glob portion back to the last path separator before it to
// recover the base output directory.
const outputDir = stripGlobToBaseDir(outputFilePath);
return path.join(outputDir, 'main.js');
}
const fallbackFile = path.join('dist', project.data.root, 'main.js');

Expand Down Expand Up @@ -485,6 +495,16 @@ function getFileToRun(
return join(context.root, buildOptions.outputPath, outputFileName);
}

function stripGlobToBaseDir(pathWithGlob: string): string {
const globIdx = pathWithGlob.search(/[*?[{(]/);
if (globIdx === -1) {
return pathWithGlob.replace(/[\\/]+$/, '');
}
const prefix = pathWithGlob.slice(0, globIdx);
const lastSep = Math.max(prefix.lastIndexOf('/'), prefix.lastIndexOf('\\'));
return lastSep === -1 ? '' : prefix.slice(0, lastSep);
}

function fileToRunCorrectPath(fileToRun: string): string {
if (fileExists(fileToRun)) return fileToRun;

Expand Down
Loading