Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): extractLicenses didn't have an …
Browse files Browse the repository at this point in the history
…effect when using server builder

(cherry picked from commit 9a04975)
  • Loading branch information
alan-agius4 authored and filipesilva committed Jul 12, 2021
1 parent 1a5c592 commit 08c317d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { execute } from '../../index';
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';

describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
describe('Option: "extractLicenses"', () => {
it(`should generate '3rdpartylicenses.txt' when 'extractLicenses' is true`, async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
extractLicenses: true,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').content.toContain('MIT');
});

it(`should not generate '3rdpartylicenses.txt' when 'extractLicenses' is false`, async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
extractLicenses: false,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
});

it(`should generate '3rdpartylicenses.txt' when 'extractLicenses' is not set`, async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').content.toContain('MIT');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
harness.expectFile('dist/main.js').content.not.toContain('sourceMappingURL=main.js.map');
});

it(`should not generate scripts sourceMaps when "scripts" option is true`, async () => {
it(`should generate scripts sourceMaps when "scripts" option is true`, async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
sourceMap: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
);
}

if (extractLicenses) {
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
extraPlugins.push(
new LicenseWebpackPlugin({
stats: {
warnings: false,
errors: false,
},
perChunkOutput: false,
outputFilename: '3rdpartylicenses.txt',
skipChildCompilers: true,
}),
);
}

if (scriptsSourceMap || stylesSourceMap) {
extraPlugins.push(
getSourceMapDevTool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
);
}

if (buildOptions.extractLicenses) {
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
extraPlugins.push(
new LicenseWebpackPlugin({
stats: {
warnings: false,
errors: false,
},
perChunkOutput: false,
outputFilename: '3rdpartylicenses.txt',
skipChildCompilers: true,
}),
);
}

if (buildOptions.statsJson) {
extraPlugins.push(
new (class {
Expand Down

0 comments on commit 08c317d

Please sign in to comment.