Skip to content

Commit

Permalink
build: update parse5-html-rewriting-stream to version 7
Browse files Browse the repository at this point in the history
This fixes an issue were the HTML is truncated if it's 128Kb or greater.

Closes angular#24707
  • Loading branch information
alan-agius4 authored and angular-robot[bot] committed Feb 14, 2023
1 parent 522463c commit d9fed6a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 23 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
"@types/node-fetch": "^2.1.6",
"@types/npm-package-arg": "^6.1.0",
"@types/pacote": "^11.1.3",
"@types/parse5-html-rewriting-stream": "^5.1.2",
"@types/pidusage": "^2.0.1",
"@types/progress": "^2.0.3",
"@types/resolve": "^1.17.1",
Expand Down Expand Up @@ -183,7 +182,7 @@
"open": "8.4.1",
"ora": "5.4.1",
"pacote": "15.0.8",
"parse5-html-rewriting-stream": "6.0.1",
"parse5-html-rewriting-stream": "7.0.0",
"pidtree": "^0.6.0",
"pidusage": "^3.0.0",
"piscina": "3.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ function shouldWrapSchematic(schematicFile: string, schematicEncapsulation: bool
return false;
}

// @angular/pwa uses dynamic imports which causes `[1] 2468039 segmentation fault` when wrapped.
// We should remove this when make `importModuleDynamically` work.
// See: https://nodejs.org/docs/latest-v14.x/api/vm.html
if (normalizedSchematicFile.includes('@angular/pwa')) {
return false;
}

// Check for first-party Angular schematic packages
// Angular schematics are safe to use in the wrapped VM context
if (/\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile)) {
Expand Down
3 changes: 1 addition & 2 deletions 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//@types/parse5-html-rewriting-stream",
"@npm//parse5-html-rewriting-stream",
],
)

Expand All @@ -58,7 +58,6 @@ ts_library(
deps = [
":pwa",
"//packages/angular_devkit/schematics/testing",
"@npm//parse5-html-rewriting-stream",
],
)

Expand Down
2 changes: 1 addition & 1 deletion packages/angular/pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@angular-devkit/schematics": "0.0.0-PLACEHOLDER",
"@schematics/angular": "0.0.0-PLACEHOLDER",
"parse5-html-rewriting-stream": "6.0.1"
"parse5-html-rewriting-stream": "7.0.0"
},
"peerDependencies": {
"@angular/cli": "^15.0.0 || ^15.2.0-next"
Expand Down
22 changes: 21 additions & 1 deletion packages/angular/pwa/pwa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function updateIndexFile(path: string): Rule {
throw new SchematicsException(`Could not read index file: ${path}`);
}

const rewriter = new (await import('parse5-html-rewriting-stream')).default();
const { RewritingStream } = await loadEsmModule<typeof import('parse5-html-rewriting-stream')>(
'parse5-html-rewriting-stream',
);

const rewriter = new RewritingStream();
let needsNoScript = true;
rewriter.on('startTag', (startTag) => {
if (startTag.tagName === 'noscript') {
Expand Down Expand Up @@ -173,3 +177,19 @@ export default function (options: PwaOptions): Rule {
]);
};
}

/**
* This uses a dynamic import to load a module which may be ESM.
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
* will currently, unconditionally downlevel dynamic import into a require call.
* require calls cannot load ESM code and will result in a runtime error. To workaround
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
* Once TypeScript provides support for keeping the dynamic import this workaround can
* be dropped.
*
* @param modulePath The path of the module to load.
* @returns A Promise that resolves to the dynamically imported module.
*/
function loadEsmModule<T>(modulePath: string | URL): Promise<T> {
return new Function('modulePath', `return import(modulePath);`)(modulePath) as Promise<T>;
}
1 change: 0 additions & 1 deletion packages/angular_devkit/build_angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ ts_library(
"@npm//@types/less",
"@npm//@types/loader-utils",
"@npm//@types/node",
"@npm//@types/parse5-html-rewriting-stream",
"@npm//@types/semver",
"@npm//@types/text-table",
"@npm//ajv",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"mini-css-extract-plugin": "2.7.2",
"open": "8.4.1",
"ora": "5.4.1",
"parse5-html-rewriting-stream": "6.0.1",
"parse5-html-rewriting-stream": "7.0.0",
"piscina": "3.2.0",
"postcss": "8.4.21",
"postcss-loader": "7.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
*/

import { Readable, Writable } from 'stream';
import { loadEsmModule } from '../load-esm';

export async function htmlRewritingStream(content: string): Promise<{
rewriter: import('parse5-html-rewriting-stream');
rewriter: import('parse5-html-rewriting-stream').RewritingStream;
transformedContent: () => Promise<string>;
}> {
const { RewritingStream } = await loadEsmModule<typeof import('parse5-html-rewriting-stream')>(
'parse5-html-rewriting-stream',
);
const chunks: Buffer[] = [];
const rewriter = new (await import('parse5-html-rewriting-stream')).default();
const rewriter = new RewritingStream();

return {
rewriter,
Expand Down
32 changes: 19 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@

"@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#3e4d95e36cbb0230de1f3eabed91d260caa7ddde":
version "0.0.0-7ed99e1d1b65cfc98021691d1c2ac92f44076190"
uid "3e4d95e36cbb0230de1f3eabed91d260caa7ddde"
resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#3e4d95e36cbb0230de1f3eabed91d260caa7ddde"
dependencies:
"@angular-devkit/build-angular" "15.2.0-next.3"
Expand Down Expand Up @@ -307,7 +306,6 @@

"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#8a87efa35da0ff50d7515511617d4ce5ac5cea2f":
version "0.0.0-7ed99e1d1b65cfc98021691d1c2ac92f44076190"
uid "8a87efa35da0ff50d7515511617d4ce5ac5cea2f"
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#8a87efa35da0ff50d7515511617d4ce5ac5cea2f"
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
Expand Down Expand Up @@ -3178,14 +3176,7 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/parse5-html-rewriting-stream@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/parse5-html-rewriting-stream/-/parse5-html-rewriting-stream-5.1.2.tgz#919d5bbf69ef61e11d873e7195891c3811491a03"
integrity sha512-7CHY6QlayurvYRST5xatE/ipIueph5V+EW2xU12P0CsNucuwygnuiE4foYsdQUEkhnKrTU62KmikANPnoxiGrg==
dependencies:
"@types/parse5-sax-parser" "*"

"@types/parse5-sax-parser@*", "@types/parse5-sax-parser@^5.0.2":
"@types/parse5-sax-parser@^5.0.2":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@types/parse5-sax-parser/-/parse5-sax-parser-5.0.2.tgz#4cdca0f8bc0ce71b17e27b96e7ca9b5f79e861ff"
integrity sha512-EQtGoduLbdMmS4N27g6wcXdCCJ70dWYemfogWuumYg+JmzRqwYvTRAbGOYFortSHtS/qRzRCFwcP3ixy62RsdA==
Expand Down Expand Up @@ -5407,7 +5398,7 @@ entities@^2.0.0:
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==

entities@^4.4.0:
entities@^4.3.0, entities@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-4.4.0.tgz#97bdaba170339446495e653cfd2db78962900174"
integrity sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==
Expand Down Expand Up @@ -8975,6 +8966,15 @@ parse5-html-rewriting-stream@6.0.1:
parse5 "^6.0.1"
parse5-sax-parser "^6.0.1"

parse5-html-rewriting-stream@7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/parse5-html-rewriting-stream/-/parse5-html-rewriting-stream-7.0.0.tgz#e376d3e762d2950ccbb6bb59823fc1d7e9fdac36"
integrity sha512-mazCyGWkmCRWDI15Zp+UiCqMp/0dgEmkZRvhlsqqKYr4SsVm/TvnSpD9fCvqCA2zoWJcfRym846ejWBBHRiYEg==
dependencies:
entities "^4.3.0"
parse5 "^7.0.0"
parse5-sax-parser "^7.0.0"

parse5-htmlparser2-tree-adapter@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz#2cdf9ad823321140370d4dbf5d3e92c7c8ddc6e6"
Expand All @@ -8989,7 +8989,14 @@ parse5-sax-parser@^6.0.1:
dependencies:
parse5 "^6.0.1"

parse5@*, parse5@^7.1.2:
parse5-sax-parser@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/parse5-sax-parser/-/parse5-sax-parser-7.0.0.tgz#4c05064254f0488676aca75fb39ca069ec96dee5"
integrity sha512-5A+v2SNsq8T6/mG3ahcz8ZtQ0OUFTatxPbeidoMB7tkJSGDY3tdfl4MHovtLQHkEn5CGxijNWRQHhRQ6IRpXKg==
dependencies:
parse5 "^7.0.0"

parse5@*, parse5@^7.0.0, parse5@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-7.1.2.tgz#0736bebbfd77793823240a23b7fc5e010b7f8e32"
integrity sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==
Expand Down Expand Up @@ -9976,7 +9983,6 @@ sass@1.58.0, sass@^1.55.0:

"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz":
version "0.0.0"
uid "9c16682e4c9716734432789884f868212f95f563"
resolved "https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz#9c16682e4c9716734432789884f868212f95f563"

saucelabs@^1.5.0:
Expand Down

0 comments on commit d9fed6a

Please sign in to comment.