MCPcopy
hub / github.com/angular/angular-cli / updateAppModule

Function updateAppModule

packages/schematics/angular/service-worker/index.ts:48–82  ·  view source on GitHub ↗
(mainPath: string)

Source from the content-addressed store, hash-verified

46}
47
48function updateAppModule(mainPath: string): Rule {
49 return (host: Tree, context: SchematicContext) => {
50 context.logger.debug('Updating appmodule');
51
52 const modulePath = getAppModulePath(host, mainPath);
53 context.logger.debug(`module path: ${modulePath}`);
54
55 addImport(host, modulePath, 'ServiceWorkerModule', '@angular/service-worker');
56 addImport(host, modulePath, 'isDevMode', '@angular/core');
57
58 // register SW in application module
59 const importText = `
60 ServiceWorkerModule.register('ngsw-worker.js', {
61 enabled: !isDevMode(),
62 // Register the ServiceWorker as soon as the application is stable
63 // or after 30 seconds (whichever comes first).
64 registrationStrategy: 'registerWhenStable:30000'
65 })
66 `;
67 const moduleSource = getTsSourceFile(host, modulePath);
68 const metadataChanges = addSymbolToNgModuleMetadata(
69 moduleSource,
70 modulePath,
71 'imports',
72 importText,
73 );
74 if (metadataChanges) {
75 const recorder = host.beginUpdate(modulePath);
76 applyToUpdateRecorder(recorder, metadataChanges);
77 host.commitUpdate(recorder);
78 }
79
80 return host;
81 };
82}
83
84function addProvideServiceWorker(projectName: string, mainPath: string): Rule {
85 return (host: Tree) => {

Callers 1

index.tsFile · 0.85

Calls 8

getAppModulePathFunction · 0.90
applyToUpdateRecorderFunction · 0.90
addImportFunction · 0.85
getTsSourceFileFunction · 0.85
debugMethod · 0.65
beginUpdateMethod · 0.65
commitUpdateMethod · 0.65

Tested by

no test coverage detected