Skip to content

Commit 4449b3a

Browse files
authored
fix(bundling): normalize Windows paths for additionalEntryPoints (#32336)
The additionalEntryPoints option was failing on Windows because tinyglobby expects POSIX-style paths but was receiving Windows-style paths with backslashes. This fix applies normalizePath to ensure cross-platform compatibility. Fixes #29690
1 parent 91225fe commit 4449b3a

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

packages/js/src/utils/package-json/create-entry-points.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { globSync } from 'tinyglobby';
2-
import { logger } from '@nx/devkit';
2+
import { logger, normalizePath } from '@nx/devkit';
33

44
export function createEntryPoints(
55
additionalEntryPoints: undefined | string[],
@@ -13,12 +13,13 @@ export function createEntryPoints(
1313
// Performance impact should be negligible since there shouldn't be that many entry points.
1414
// Benchmarks show only 1-3% difference in execution time.
1515
for (const pattern of additionalEntryPoints) {
16-
const matched = globSync([pattern], {
16+
const normalizedPattern = normalizePath(pattern);
17+
const matched = globSync([normalizedPattern], {
1718
cwd: root,
1819
expandDirectories: false,
1920
});
2021
if (!matched.length)
21-
logger.warn(`The pattern ${pattern} did not match any files.`);
22+
logger.warn(`The pattern ${normalizedPattern} did not match any files.`);
2223
files.push(...matched);
2324
}
2425
return files;

packages/rollup/src/plugins/with-nx/normalize-options.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,28 @@ describe('normalizeOptions', () => {
8383
tsConfig: 'pkg/tsconfig.json',
8484
});
8585
});
86+
87+
describe('Windows path handling', () => {
88+
it('should normalize Windows paths for additionalEntryPoints', () => {
89+
const windowsPath = './src\\entrypoints\\*.ts';
90+
const options = {
91+
main: './src/main.ts',
92+
additionalEntryPoints: [windowsPath],
93+
outputPath: '../dist/test-lib',
94+
tsConfig: './tsconfig.json',
95+
};
96+
97+
const result = normalizeOptions(
98+
'libs/test-lib',
99+
'libs/test-lib/src',
100+
options
101+
);
102+
103+
expect(result.additionalEntryPoints).toBeDefined();
104+
result.additionalEntryPoints.forEach((entry) => {
105+
expect(entry).not.toContain('\\');
106+
expect(entry).toMatch(/^libs\/test-lib\/src\/entrypoints\/\*\.ts$/);
107+
});
108+
});
109+
});
86110
});

packages/rollup/src/plugins/with-nx/normalize-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function normalizeRelativePaths(
9898
): void {
9999
for (const [fieldName, fieldValue] of Object.entries(options)) {
100100
if (isRelativePath(fieldValue)) {
101-
options[fieldName] = join(projectRoot, fieldValue);
101+
options[fieldName] = normalizePath(join(projectRoot, fieldValue));
102102
} else if (Array.isArray(fieldValue)) {
103103
for (let i = 0; i < fieldValue.length; i++) {
104104
if (isRelativePath(fieldValue[i])) {
105-
fieldValue[i] = join(projectRoot, fieldValue[i]);
105+
fieldValue[i] = normalizePath(join(projectRoot, fieldValue[i]));
106106
}
107107
}
108108
}

packages/rollup/src/plugins/with-nx/with-nx.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
logger,
3+
normalizePath,
34
type ProjectGraph,
45
readCachedProjectGraph,
56
readJsonFile,
@@ -353,9 +354,11 @@ function createInput(
353354
if (global.NX_GRAPH_CREATION) return {};
354355
const mainEntryFileName = options.outputFileName || options.main;
355356
const input: Record<string, string> = {};
356-
input[parse(mainEntryFileName).name] = join(workspaceRoot, options.main);
357+
input[parse(mainEntryFileName).name] = normalizePath(
358+
join(workspaceRoot, options.main)
359+
);
357360
options.additionalEntryPoints?.forEach((entry) => {
358-
input[parse(entry).name] = join(workspaceRoot, entry);
361+
input[parse(entry).name] = normalizePath(join(workspaceRoot, entry));
359362
});
360363
return input;
361364
}

0 commit comments

Comments
 (0)