From a83b0d187ba29c61e9e5fcf4e0490022e2086677 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Fri, 6 Nov 2026 00:07:39 +0600 Subject: [PATCH] fix(@angular/pwa): add the manifest link when the index option is an object The application and browser builders accept the `index` option either as a string or as an `{ input, output }` object. `ng add @angular/pwa` only collects string values when looking for index files to update, so a project using the object form gets no `` tag. The failure is silent: when the object points at a custom file such as `src/app-index.html`, no index file is updated at all, and the installed application never loads the web app manifest. Collect the `input` path of an object-form `index` alongside the string form, for both the target options and each configuration. The new spec fails without the fix: with `"index": { "input": "projects/bar/src/app-index.html", "output": "index.html" }`, the schematic left `app-index.html` without the manifest link. --- packages/angular/pwa/pwa/index.ts | 27 +++++++++++++++++--------- packages/angular/pwa/pwa/index_spec.ts | 15 ++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/angular/pwa/pwa/index.ts b/packages/angular/pwa/pwa/index.ts index a3a2b2847c78..1aaea15da4a3 100644 --- a/packages/angular/pwa/pwa/index.ts +++ b/packages/angular/pwa/pwa/index.ts @@ -108,23 +108,32 @@ export default function (options: PwaOptions): Rule { // Find all index.html files in build targets const indexFiles = new Set(); let checkForDefaultIndex = false; - for (const target of buildTargets) { - if (typeof target.options?.index === 'string') { - indexFiles.add(target.options.index); - } else if (target.options?.index === undefined) { + const collectIndexFile = (index: unknown): void => { + if (typeof index === 'string') { + indexFiles.add(index); + } else if (index === undefined) { checkForDefaultIndex = true; + } else if ( + typeof index === 'object' && + index !== null && + 'input' in index && + typeof index.input === 'string' + ) { + // The `index` option also accepts an `{ input, output }` object; the manifest + // link belongs in the source file referenced by `input`. + indexFiles.add(index.input); } + }; + + for (const target of buildTargets) { + collectIndexFile(target.options?.index); if (!target.configurations) { continue; } for (const options of Object.values(target.configurations)) { - if (typeof options?.index === 'string') { - indexFiles.add(options.index); - } else if (options?.index === undefined) { - checkForDefaultIndex = true; - } + collectIndexFile(options?.index); } } diff --git a/packages/angular/pwa/pwa/index_spec.ts b/packages/angular/pwa/pwa/index_spec.ts index 42d698ce8f8f..d8393d405623 100644 --- a/packages/angular/pwa/pwa/index_spec.ts +++ b/packages/angular/pwa/pwa/index_spec.ts @@ -117,6 +117,21 @@ describe('PWA Schematic', () => { ); }); + it('should update the index file when it is specified as an object', async () => { + const config = JSON.parse(appTree.readContent('/angular.json')); + config.projects.bar.architect.build.options.index = { + input: 'projects/bar/src/app-index.html', + output: 'index.html', + }; + appTree.overwrite('/angular.json', JSON.stringify(config, null, 2)); + appTree.rename('/projects/bar/src/index.html', '/projects/bar/src/app-index.html'); + + const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); + const content = tree.readContent('projects/bar/src/app-index.html'); + + expect(content).toMatch(//); + }); + it('should not add noscript element to the index file if already present', async () => { let index = appTree.readContent('projects/bar/src/index.html'); index = index.replace('', '');