Skip to content

Commit 85148da

Browse files
committed
fix: 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 a0db191 commit 85148da

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
6060
extraPlugins.push(new GlobCopyWebpackPlugin({
6161
patterns: ['ngsw-manifest.json', 'src/ngsw-manifest.json'],
6262
globOptions: {
63+
cwd: projectRoot,
6364
optional: true,
6465
},
6566
}));

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

Lines changed: 10 additions & 2 deletions
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)