Skip to content

Commit 64b83e2

Browse files
Alanhansl
Alan
authored andcommitted
feat(@schematics/angular): relocate ng g service-worker files
This is a follow up on #13811, with this now all application have the same structure and hence `ng g service-worker` should follow suit and have the same folder strucute if generated in a root app, or an app inside the projects.
1 parent f06493c commit 64b83e2

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

packages/schematics/angular/service-worker/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function updateConfigFile(options: ServiceWorkerOptions, root: string): Rule {
6060

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

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

177-
const root = project.root || project.sourceRoot || '';
178177
const templateSource = apply(url('./files'), [
179178
applyTemplates({ ...options, resourcesOutputPath }),
180-
move(root),
179+
move(project.root),
181180
]);
182181

183182
context.addTask(new NodePackageInstallTask());
184183

185184
return chain([
186185
mergeWith(templateSource),
187-
updateConfigFile(options, root),
186+
updateConfigFile(options, project.root),
188187
addDependencies(),
189188
updateAppModule(options),
190189
]);

packages/schematics/angular/service-worker/index_spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('Service Worker Schematic', () => {
120120
.toContain('/outDir/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)');
121121
});
122122

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

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

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

144144
});

0 commit comments

Comments
 (0)