Skip to content

Commit

Permalink
fix(@angular/cli): check for existing SW manifest should look in proj…
Browse files Browse the repository at this point in the history
…ect 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.
  • Loading branch information
alxhub authored and hansl committed Jun 21, 2017
1 parent b2ade63 commit 220e59d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/@angular/cli/models/webpack-configs/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
}

extraPlugins.push(new GlobCopyWebpackPlugin({
patterns: ['ngsw-manifest.json', 'src/ngsw-manifest.json'],
patterns: [
'ngsw-manifest.json',
{glob: 'ngsw-manifest.json', input: path.resolve(projectRoot, appConfig.root), output: ''}
],
globOptions: {
cwd: projectRoot,
optional: true,
},
}));
Expand Down
12 changes: 10 additions & 2 deletions tests/e2e/tests/build/service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {join} from 'path';
import {getGlobalVariable} from '../../utils/env';
import {expectFileToExist, expectFileToMatch} from '../../utils/fs';
import {expectFileToExist, expectFileToMatch, writeFile, moveFile} from '../../utils/fs';
import {ng, npm} from '../../utils/process';

export default function() {
Expand All @@ -9,6 +9,8 @@ export default function() {
return Promise.resolve();
}

const rootManifest = join(process.cwd(), 'ngsw-manifest.json');

// Can't use the `ng` helper because somewhere the environment gets
// stuck to the first build done
return npm('install', '@angular/service-worker')
Expand All @@ -18,5 +20,11 @@ export default function() {
.then(() => expectFileToExist(join(process.cwd(), 'dist/ngsw-manifest.json')))
.then(() => ng('build', '--prod', '--base-href=/foo/bar'))
.then(() => expectFileToExist(join(process.cwd(), 'dist/ngsw-manifest.json')))
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /"\/foo\/bar\/index.html"/));
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /"\/foo\/bar\/index.html"/))
.then(() => writeFile(rootManifest, '{"local": true}'))
.then(() => ng('build', '--prod'))
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /\"local\"/))
.then(() => moveFile(rootManifest, join(process.cwd(), 'src/ngsw-manifest.json')))
.then(() => ng('build', '--prod'))
.then(() => expectFileToMatch('dist/ngsw-manifest.json', /\"local\"/));
}

0 comments on commit 220e59d

Please sign in to comment.