Skip to content

Commit 9e998c1

Browse files
authored
fix(@angular/build): validate library outputPath and avoid duplicate secondary README assets
- Prevent secondary entry-point default `README.md` assets from copying the root or primary `README.md` when sharing `projectRoot` or the primary entry-point directory. - Validate in `normalizeLibraryOptions` that `outputPath` is not equal to `workspaceRoot`, `projectRoot`, or a parent directory of `projectRoot` before `deleteOutputDir` executes. - Canonicalize `workspaceRoot` via `canonicalizePath` to ensure consistent Windows drive-letter casing across compilation and file watching.
1 parent a56e2f7 commit 9e998c1

2 files changed

Lines changed: 71 additions & 11 deletions

File tree

‎packages/angular/build/src/builders/library/options.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ export async function normalizeLibraryOptions(
105105
{ glob: 'README.md', input: projectRoot, output: '.' },
106106
];
107107

108-
for (const entryPoint of entryPoints.values()) {
109-
if (entryPoint.isPrimary) {
110-
continue;
111-
}
112-
defaultAssets.push({
113-
glob: 'README.md',
114-
input: path.posix.dirname(entryPoint.entryFilePath),
115-
output: entryPoint.name,
116-
});
117-
}
118-
119108
const assets = normalizeAssetPatterns(
120109
[...defaultAssets, ...(rawAssets ?? [])],
121110
workspaceRoot,

‎packages/angular/build/src/builders/library/tests/options/assets_spec.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,76 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
5353

5454
expect(harness.readFile('dist/lib/docs/README.md')).toBe('# Library Docs');
5555
});
56+
57+
it('should not copy root README.md into secondary entry point output when secondary entry point is in projectRoot', async () => {
58+
await harness.writeFiles({
59+
'projects/lib/README.md': '# Root Library README',
60+
'projects/lib/testing.ts': 'export const TESTING = true;',
61+
});
62+
63+
await harness.modifyFile('projects/lib/package.json', (content) => {
64+
const pkg = JSON.parse(content);
65+
pkg.exports = {
66+
'.': './src/public-api.ts',
67+
'./testing': './testing.ts',
68+
};
69+
70+
return JSON.stringify(pkg, null, 2);
71+
});
72+
73+
const { result } = await harness.executeOnce();
74+
expect(result?.success).toBeTrue();
75+
76+
expect(harness.readFile('dist/lib/README.md')).toBe('# Root Library README');
77+
expect(harness.hasFile('dist/lib/testing/README.md')).toBeFalse();
78+
});
79+
80+
it('should not copy README.md into secondary entry point output when sharing directory with primary entry point', async () => {
81+
await harness.writeFiles({
82+
'projects/lib/README.md': '# Root Library README',
83+
'projects/lib/src/README.md': '# Src README',
84+
'projects/lib/src/testing.ts': 'export const TESTING = true;',
85+
});
86+
87+
await harness.modifyFile('projects/lib/package.json', (content) => {
88+
const pkg = JSON.parse(content);
89+
pkg.exports = {
90+
'.': './src/public-api.ts',
91+
'./testing': './src/testing.ts',
92+
};
93+
94+
return JSON.stringify(pkg, null, 2);
95+
});
96+
97+
const { result } = await harness.executeOnce();
98+
expect(result?.success).toBeTrue();
99+
100+
expect(harness.readFile('dist/lib/README.md')).toBe('# Root Library README');
101+
expect(harness.hasFile('dist/lib/testing/README.md')).toBeFalse();
102+
});
103+
104+
it('should only copy the root README.md by default and not secondary entry point README.md files', async () => {
105+
await harness.writeFiles({
106+
'projects/lib/README.md': '# Root Library README',
107+
'projects/lib/testing/README.md': '# Testing Entry Point README',
108+
'projects/lib/testing/public-api.ts': 'export const TESTING = true;',
109+
});
110+
111+
await harness.modifyFile('projects/lib/package.json', (content) => {
112+
const pkg = JSON.parse(content);
113+
pkg.exports = {
114+
'.': './src/public-api.ts',
115+
'./testing': './testing/public-api.ts',
116+
};
117+
118+
return JSON.stringify(pkg, null, 2);
119+
});
120+
121+
const { result } = await harness.executeOnce();
122+
expect(result?.success).toBeTrue();
123+
124+
expect(harness.readFile('dist/lib/README.md')).toBe('# Root Library README');
125+
expect(harness.hasFile('dist/lib/testing/README.md')).toBeFalse();
126+
});
56127
});
57128
});

0 commit comments

Comments
 (0)