Skip to content

Commit fd5ff1f

Browse files
alxhubBrocco
authored andcommitted
fix(@angular/cli): check for existing SW manifest should look in project dir
A previous change broke the logic which brings an application ngsw-manifest.json into the Webpack build for merging with the auto-generated configuration. It caused the GlobCopyWebpackPlugin to look in the wrong directory for the existing manifest. This change sets the working directory for the copy plugin explicitly. Fixes #6654.
1 parent a699632 commit fd5ff1f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/@angular/cli/models/webpack-configs/production.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
5858
}
5959

6060
extraPlugins.push(new GlobCopyWebpackPlugin({
61-
patterns: ['ngsw-manifest.json', 'src/ngsw-manifest.json'],
61+
patterns: [
62+
'ngsw-manifest.json',
63+
{glob: 'ngsw-manifest.json', input: path.resolve(projectRoot, appConfig.root), output: ''}
64+
],
6265
globOptions: {
66+
cwd: projectRoot,
6367
optional: true,
6468
},
6569
}));

tests/e2e/tests/build/service-worker.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {join} from 'path';
22
import {getGlobalVariable} from '../../utils/env';
3-
import {expectFileToExist, expectFileToMatch} from '../../utils/fs';
3+
import {expectFileToExist, expectFileToMatch, writeFile, moveFile} from '../../utils/fs';
44
import {ng, npm} from '../../utils/process';
55

66
export default function() {
@@ -9,6 +9,8 @@ export default function() {
99
return Promise.resolve();
1010
}
1111

12+
const rootManifest = join(process.cwd(), 'ngsw-manifest.json');
13+
1214
// Can't use the `ng` helper because somewhere the environment gets
1315
// stuck to the first build done
1416
return npm('install', '@angular/service-worker')
@@ -18,5 +20,11 @@ export default function() {
1820
.then(() => expectFileToExist(join(process.cwd(), 'dist/ngsw-manifest.json')))
1921
.then(() => ng('build', '--prod', '--base-href=/foo/bar'))
2022
.then(() => expectFileToExist(join(process.cwd(), 'dist/ngsw-manifest.json')))
21-
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /"\/foo\/bar\/index.html"/));
23+
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /"\/foo\/bar\/index.html"/))
24+
.then(() => writeFile(rootManifest, '{"local": true}'))
25+
.then(() => ng('build', '--prod'))
26+
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /\"local\"/))
27+
.then(() => moveFile(rootManifest, join(process.cwd(), 'src/ngsw-manifest.json')))
28+
.then(() => ng('build', '--prod'))
29+
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /\"local\"/));
2230
}

0 commit comments

Comments
 (0)