Skip to content

Commit 84c1c87

Browse files
committed
fix(@schematics/angular): warn when production configuration is missing for service worker
When adding service worker support to a project, the schematic attempts to add the `serviceWorker` option to the `production` build configuration. If the `production` configuration is missing, the schematic would previously do nothing and not inform the user. This change adds a warning message to the console when the `production` configuration is not found, making it clear to the user why the `serviceWorker` option was not added. Fixes #32399
1 parent 151b58a commit 84c1c87

File tree

1 file changed

+5
-1
lines changed
  • packages/schematics/angular/service-worker

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function getTsSourceFile(host: Tree, path: string): ts.SourceFile {
106106
}
107107

108108
const serviceWorkerSchematic: RuleFactory<ServiceWorkerOptions> = createProjectSchematic(
109-
async (options, { project, workspace, tree }) => {
109+
async (options, { project, workspace, tree, logger }) => {
110110
if (project.extensions.projectType !== 'application') {
111111
throw new SchematicsException(`Service worker requires a project type of "application".`);
112112
}
@@ -126,6 +126,10 @@ const serviceWorkerSchematic: RuleFactory<ServiceWorkerOptions> = createProjectS
126126
const productionConf = buildTarget.configurations?.production;
127127
if (productionConf) {
128128
productionConf.serviceWorker = ngswConfigPath;
129+
} else {
130+
logger.warn(
131+
'No "production" configuration found for build target. "serviceWorker" option will not be set.',
132+
);
129133
}
130134
} else {
131135
buildOptions.serviceWorker = true;

0 commit comments

Comments
 (0)