Skip to content

Commit

Permalink
refactor(@angular/pwa): use typed version of parse5-html-rewriting-st…
Browse files Browse the repository at this point in the history
…ream
  • Loading branch information
alan-agius4 authored and clydin committed Oct 5, 2020
1 parent 409247e commit b217494
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/angular/pwa/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ts_library(
"//packages/angular_devkit/schematics",
"//packages/schematics/angular",
"@npm//@types/node",
"@npm//parse5-html-rewriting-stream",
"@npm//@types/parse5-html-rewriting-stream",
"@npm//rxjs",
],
)
Expand All @@ -60,6 +60,7 @@ ts_library(
deps = [
":pwa",
"//packages/angular_devkit/schematics/testing",
"@npm//parse5-html-rewriting-stream",
],
)

Expand Down
10 changes: 4 additions & 6 deletions packages/angular/pwa/pwa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@ import { getWorkspace, updateWorkspace } from '@schematics/angular/utility/works
import { Readable, Writable } from 'stream';
import { Schema as PwaOptions } from './schema';

const RewritingStream = require('parse5-html-rewriting-stream');

function updateIndexFile(path: string): Rule {
return (host: Tree) => {
return async (host: Tree) => {
const buffer = host.read(path);
if (buffer === null) {
throw new SchematicsException(`Could not read index file: ${path}`);
}

const rewriter = new RewritingStream();
const rewriter = new (await import('parse5-html-rewriting-stream'))();
let needsNoScript = true;
rewriter.on('startTag', (startTag: { tagName: string }) => {
rewriter.on('startTag', startTag => {
if (startTag.tagName === 'noscript') {
needsNoScript = false;
}

rewriter.emitStartTag(startTag);
});

rewriter.on('endTag', (endTag: { tagName: string }) => {
rewriter.on('endTag', endTag => {
if (endTag.tagName === 'head') {
rewriter.emitRaw(' <link rel="manifest" href="manifest.webmanifest">\n');
rewriter.emitRaw(' <meta name="theme-color" content="#1976d2">\n');
Expand Down

0 comments on commit b217494

Please sign in to comment.