Skip to content

Commit 7532ec5

Browse files
committed
fixup! fix(@angular/build): re-analyze exports on package.json change in library builder
1 parent 354dbbf commit 7532ec5

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,10 @@ async function* runWatchLoop(
276276
try {
277277
const packageJson = await loadPackageJson(packageJsonPath);
278278
options.packageJson = packageJson;
279-
if (packageJson.name) {
280-
options.packageName = packageJson.name;
279+
if (!packageJson.name) {
280+
throw new Error(`The package.json at '${packageJsonPath}' must contain a 'name'.`);
281281
}
282+
options.packageName = packageJson.name;
282283

283284
updateWatchedEntryPoints(
284285
packageJson,

‎packages/angular/build/src/builders/library/pipeline/entry-points.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export function haveEntryPointsChanged(
215215
export function updateWatchedEntryPoints(
216216
packageJson: { exports?: unknown; name?: string },
217217
options: {
218-
entryPoints: ReadonlyMap<string, NormalizedEntryPoint>;
218+
entryPoints: Map<string, NormalizedEntryPoint>;
219219
projectRoot: string;
220220
packageName: string;
221221
},

‎packages/angular/build/src/builders/library/tests/behavior/watch_spec.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,36 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
309309
]);
310310
});
311311

312+
it('should fail with error when name is removed from package.json in watch mode', async () => {
313+
harness.useTarget('build', {
314+
...BASE_OPTIONS,
315+
watch: true,
316+
});
317+
318+
await harness.executeWithCases([
319+
async ({ result }) => {
320+
expect(result?.success).toBeTrue();
321+
322+
// Remove name from package.json
323+
const pkg = JSON.parse(harness.readFile('projects/lib/package.json'));
324+
delete pkg.name;
325+
await harness.writeFile('projects/lib/package.json', JSON.stringify(pkg, null, 2));
326+
},
327+
async ({ result }) => {
328+
expect(result?.success).toBeFalse();
329+
expect(result?.error).toContain("must contain a 'name'");
330+
331+
// Restore name in package.json
332+
const pkg = JSON.parse(harness.readFile('projects/lib/package.json'));
333+
pkg.name = 'lib';
334+
await harness.writeFile('projects/lib/package.json', JSON.stringify(pkg, null, 2));
335+
},
336+
async ({ result }) => {
337+
expect(result?.success).toBeTrue();
338+
},
339+
]);
340+
});
341+
312342
it('should recover from compilation errors in watch mode', async () => {
313343
await harness.writeFile(
314344
'projects/lib/src/public-api.ts',

0 commit comments

Comments
 (0)