Skip to content

feat(@schematics/angular): relocate ng g service-worker files #13830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/schematics/angular/service-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function updateConfigFile(options: ServiceWorkerOptions, root: string): Rule {

const config = getProjectConfiguration(workspace, options);
config.serviceWorker = true;
config.ngswConfigPath = `${root.endsWith('/') ? root : root + '/'}ngsw-config.json`;
config.ngswConfigPath = `${root && !root.endsWith('/') ? root + '/' : root}ngsw-config.json`;

return updateWorkspace(workspace);
};
Expand Down Expand Up @@ -174,17 +174,16 @@ export default function (options: ServiceWorkerOptions): Rule {
resourcesOutputPath = '/' + resourcesOutputPath.split('/').filter(x => !!x).join('/');
}

const root = project.root || project.sourceRoot || '';
const templateSource = apply(url('./files'), [
applyTemplates({ ...options, resourcesOutputPath }),
move(root),
move(project.root),
]);

context.addTask(new NodePackageInstallTask());

return chain([
mergeWith(templateSource),
updateConfigFile(options, root),
updateConfigFile(options, project.root),
addDependencies(),
updateAppModule(options),
]);
Expand Down
6 changes: 3 additions & 3 deletions packages/schematics/angular/service-worker/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Service Worker Schematic', () => {
.toContain('/outDir/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)');
});

it('should generate ngsw-config.json in src when the application is at root level', () => {
it('should generate ngsw-config.json in root when the application is at root level', () => {
const name = 'foo';
const rootAppOptions: ApplicationOptions = {
...appOptions,
Expand All @@ -134,11 +134,11 @@ describe('Service Worker Schematic', () => {

let tree = schematicRunner.runSchematic('application', rootAppOptions, appTree);
tree = schematicRunner.runSchematic('service-worker', rootSWOptions, tree);
expect(tree.exists('/src/ngsw-config.json')).toBe(true);
expect(tree.exists('/ngsw-config.json')).toBe(true);

const { projects } = JSON.parse(tree.readContent('/angular.json'));
expect(projects.foo.architect.build.configurations.production.ngswConfigPath)
.toBe('src/ngsw-config.json');
.toBe('ngsw-config.json');
});

});