Skip to content

Commit 3bb48c1

Browse files
alan-agius4dgp1130
authored andcommitted
refactor(@angular-devkit/build-angular): remove resourcesOutputPath option from application builder.
This `resourcesOutputPath` option is removed from the application builder. Instead the CSS resources will always be emitted in a directory named `media`. This is preparation to output server and browser bundles in different directories.
1 parent 3ccc96f commit 3bb48c1

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

packages/angular_devkit/build_angular/src/builders/application/options.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ export async function normalizeOptions(
9494
? '[name].[hash]'
9595
: '[name]',
9696
media:
97-
options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Media
97+
'media/' +
98+
(options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Media
9899
? '[name].[hash]'
99-
: '[name]',
100+
: '[name]'),
100101
};
101-
if (options.resourcesOutputPath) {
102-
outputNames.media = path.join(options.resourcesOutputPath, outputNames.media);
103-
}
104102

105103
let fileReplacements: Record<string, string> | undefined;
106104
if (options.fileReplacements) {

packages/angular_devkit/build_angular/src/builders/application/schema.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@
220220
"type": "string",
221221
"description": "The full path for the new output directory, relative to the current workspace.\nBy default, writes output to a folder named dist/ in the current project."
222222
},
223-
"resourcesOutputPath": {
224-
"type": "string",
225-
"description": "The path where style resources will be placed, relative to outputPath."
226-
},
227223
"aot": {
228224
"type": "boolean",
229225
"description": "Build using Ahead of Time compilation.",

packages/angular_devkit/build_angular/src/builders/application/tests/options/output-hashing_spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
3434
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeTrue();
3535
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeTrue();
3636
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeTrue();
37-
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue();
37+
expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue();
3838
});
3939

4040
it(`doesn't hash any filenames when not set`, async () => {
@@ -52,7 +52,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
5252
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse();
5353
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse();
5454
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse();
55-
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
55+
expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
5656
});
5757

5858
it(`doesn't hash any filenames when set to "none"`, async () => {
@@ -71,7 +71,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
7171
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse();
7272
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse();
7373
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse();
74-
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
74+
expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
7575
});
7676

7777
it(`hashes CSS resources filenames only when set to "media"`, async () => {
@@ -90,7 +90,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
9090
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse();
9191
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse();
9292
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse();
93-
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue();
93+
expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue();
9494
});
9595

9696
it(`hashes bundles filenames only when set to "bundles"`, async () => {
@@ -109,11 +109,10 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
109109
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeTrue();
110110
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeTrue();
111111
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeTrue();
112-
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
112+
expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
113113
});
114114

115-
// TODO: Re-enable once implemented in the esbuild builder
116-
xit('does not hash non injected styles', async () => {
115+
it('does not hash non injected styles', async () => {
117116
harness.useTarget('build', {
118117
...BASE_OPTIONS,
119118
outputHashing: OutputHashing.All,
@@ -159,8 +158,8 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
159158
const { result } = await harness.executeOnce();
160159
expect(result?.success).toBe(true);
161160

162-
harness.expectFile('dist/test.svg').toExist();
163-
harness.expectFile('dist/small-test.svg').toExist();
161+
harness.expectFile('dist/media/test.svg').toExist();
162+
harness.expectFile('dist/media/small-test.svg').toExist();
164163
});
165164
});
166165
});

packages/angular_devkit/build_angular/src/builders/browser-esbuild/builder-status-warnings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export function logBuilderStatusWarnings(options: BrowserBuilderOptions, context
5656
if (
5757
unsupportedOption === 'namedChunks' ||
5858
unsupportedOption === 'vendorChunk' ||
59+
unsupportedOption === 'resourcesOutputPath' ||
5960
unsupportedOption === 'deployUrl'
6061
) {
6162
context.logger.warn(

packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/bundle-options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface BundleStylesheetOptions {
2727
optimization: boolean;
2828
preserveSymlinks?: boolean;
2929
sourcemap: boolean | 'external' | 'inline';
30-
outputNames?: { bundles?: string; media?: string };
30+
outputNames: { bundles: string; media: string };
3131
includePaths?: string[];
3232
externalDependencies?: string[];
3333
target: string[];
@@ -57,8 +57,8 @@ export function createStylesheetBundleOptions(
5757
return {
5858
absWorkingDir: options.workspaceRoot,
5959
bundle: true,
60-
entryNames: options.outputNames?.bundles,
61-
assetNames: options.outputNames?.media,
60+
entryNames: options.outputNames.bundles,
61+
assetNames: options.outputNames.media,
6262
logLevel: 'silent',
6363
minify: options.optimization,
6464
metafile: true,

0 commit comments

Comments
 (0)