Skip to content

Commit 58fbe75

Browse files
committed
fixup! fix(@angular/build): validate library outputPath and avoid duplicate secondary README assets
1 parent 93fa9ea commit 58fbe75

2 files changed

Lines changed: 4 additions & 69 deletions

File tree

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { supportColor } from '../../utils/color';
1313
import { assertIsError } from '../../utils/error';
1414
import { normalizeAssetPatterns } from '../../utils/normalize-asset-patterns';
1515
import { normalizeCacheOptions } from '../../utils/normalize-cache';
16-
import { canonicalizePath, isSubDirectory, toPosixPath } from '../../utils/path';
16+
import { canonicalizePath, toPosixPath } from '../../utils/path';
1717
import {
1818
generateSearchDirectories,
1919
getTailwindConfig,
@@ -47,7 +47,6 @@ export async function normalizeLibraryOptions(
4747

4848
const {
4949
tsConfig,
50-
outputPath: rawOutputPath,
5150
assets: rawAssets,
5251
stylePreprocessorOptions,
5352
inlineStyleLanguage = 'css',
@@ -63,19 +62,6 @@ export async function normalizeLibraryOptions(
6362
clearScreen,
6463
} = options;
6564

66-
const outputPath = toPosixPath(
67-
path.resolve(workspaceRoot, rawOutputPath ?? path.posix.join('dist', projectName)),
68-
);
69-
if (
70-
outputPath === workspaceRoot ||
71-
outputPath === projectRoot ||
72-
isSubDirectory(outputPath, projectRoot)
73-
) {
74-
throw new Error(
75-
`The 'outputPath' option ('${outputPath}') cannot be the workspace root, project root, or a parent directory of the project root.`,
76-
);
77-
}
78-
7965
const resolvedTsConfigPath = toPosixPath(path.resolve(workspaceRoot, tsConfig));
8066
const packageJsonPath = path.posix.join(projectRoot, 'package.json');
8167

@@ -181,7 +167,9 @@ export async function normalizeLibraryOptions(
181167
projectRoot,
182168
packageName,
183169
packageJson,
184-
outputPath,
170+
outputPath: toPosixPath(
171+
path.resolve(workspaceRoot, options.outputPath ?? path.posix.join('dist', projectName)),
172+
),
185173
deleteOutputPath,
186174
packageJsonPath,
187175
tsConfigPath: resolvedTsConfigPath,

‎packages/angular/build/src/builders/library/tests/options/output-path_spec.ts‎

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,58 +32,5 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
3232
harness.expectFile('dist/custom-output/fesm2022/lib.mjs').toExist();
3333
harness.expectFile('dist/custom-output/package.json').toExist();
3434
});
35-
36-
it('should reject outputPath equal to projectRoot', async () => {
37-
harness.useTarget('build', {
38-
...BASE_OPTIONS,
39-
outputPath: 'projects/lib',
40-
});
41-
42-
const { result, error } = await harness.executeOnce({
43-
outputLogsOnException: false,
44-
outputLogsOnFailure: false,
45-
});
46-
expect(result).toBeUndefined();
47-
expect(error).toBeDefined();
48-
expect((error as Error).message).toMatch(
49-
/The 'outputPath' option .* cannot be the workspace root, project root, or a parent directory of the project root/,
50-
);
51-
harness.expectFile('projects/lib/package.json').toExist();
52-
});
53-
54-
it('should reject outputPath equal to workspaceRoot', async () => {
55-
harness.useTarget('build', {
56-
...BASE_OPTIONS,
57-
outputPath: '.',
58-
});
59-
60-
const { result, error } = await harness.executeOnce({
61-
outputLogsOnException: false,
62-
outputLogsOnFailure: false,
63-
});
64-
expect(result).toBeUndefined();
65-
expect(error).toBeDefined();
66-
expect((error as Error).message).toMatch(
67-
/The 'outputPath' option .* cannot be the workspace root, project root, or a parent directory of the project root/,
68-
);
69-
});
70-
71-
it('should reject outputPath when it is a parent directory of projectRoot', async () => {
72-
harness.useTarget('build', {
73-
...BASE_OPTIONS,
74-
outputPath: 'projects',
75-
});
76-
77-
const { result, error } = await harness.executeOnce({
78-
outputLogsOnException: false,
79-
outputLogsOnFailure: false,
80-
});
81-
expect(result).toBeUndefined();
82-
expect(error).toBeDefined();
83-
expect((error as Error).message).toMatch(
84-
/The 'outputPath' option .* cannot be the workspace root, project root, or a parent directory of the project root/,
85-
);
86-
harness.expectFile('projects/lib/package.json').toExist();
87-
});
8835
});
8936
});

0 commit comments

Comments
 (0)