MCPcopy Index your code
hub / github.com/angular/angular-cli / updateIndexFile

Function updateIndexFile

packages/angular/pwa/pwa/index.ts:27–63  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

25import { Schema as PwaOptions } from './schema';
26
27function updateIndexFile(path: string): Rule {
28 return async (host: Tree) => {
29 const originalContent = host.readText(path);
30
31 const { RewritingStream } = await import('parse5-html-rewriting-stream');
32
33 const rewriter = new RewritingStream();
34 let needsNoScript = true;
35 rewriter.on('startTag', (startTag) => {
36 if (startTag.tagName === 'noscript') {
37 needsNoScript = false;
38 }
39
40 rewriter.emitStartTag(startTag);
41 });
42
43 rewriter.on('endTag', (endTag) => {
44 if (endTag.tagName === 'head') {
45 rewriter.emitRaw(' <link rel="manifest" href="manifest.webmanifest">\n');
46 } else if (endTag.tagName === 'body' && needsNoScript) {
47 rewriter.emitRaw(
48 ' <noscript>Please enable JavaScript to continue using this application.</noscript>\n',
49 );
50 }
51
52 rewriter.emitEndTag(endTag);
53 });
54
55 return pipeline(Readable.from(originalContent), rewriter, async function (source) {
56 const chunks = [];
57 for await (const chunk of source) {
58 chunks.push(Buffer.from(chunk));
59 }
60 host.overwrite(path, Buffer.concat(chunks));
61 });
62 };
63}
64
65export default function (options: PwaOptions): Rule {
66 return async (host) => {

Callers 1

index.tsFile · 0.85

Calls 5

onMethod · 0.80
fromMethod · 0.80
readTextMethod · 0.65
overwriteMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected