Skip to content

Commit d9fed6a

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
build: update parse5-html-rewriting-stream to version 7
This fixes an issue were the HTML is truncated if it's 128Kb or greater. Closes #24707
1 parent 522463c commit d9fed6a

File tree

9 files changed

+57
-23
lines changed

9 files changed

+57
-23
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
"@types/node-fetch": "^2.1.6",
115115
"@types/npm-package-arg": "^6.1.0",
116116
"@types/pacote": "^11.1.3",
117-
"@types/parse5-html-rewriting-stream": "^5.1.2",
118117
"@types/pidusage": "^2.0.1",
119118
"@types/progress": "^2.0.3",
120119
"@types/resolve": "^1.17.1",
@@ -183,7 +182,7 @@
183182
"open": "8.4.1",
184183
"ora": "5.4.1",
185184
"pacote": "15.0.8",
186-
"parse5-html-rewriting-stream": "6.0.1",
185+
"parse5-html-rewriting-stream": "7.0.0",
187186
"pidtree": "^0.6.0",
188187
"pidusage": "^3.0.0",
189188
"piscina": "3.2.0",

packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ function shouldWrapSchematic(schematicFile: string, schematicEncapsulation: bool
4444
return false;
4545
}
4646

47+
// @angular/pwa uses dynamic imports which causes `[1] 2468039 segmentation fault` when wrapped.
48+
// We should remove this when make `importModuleDynamically` work.
49+
// See: https://nodejs.org/docs/latest-v14.x/api/vm.html
50+
if (normalizedSchematicFile.includes('@angular/pwa')) {
51+
return false;
52+
}
53+
4754
// Check for first-party Angular schematic packages
4855
// Angular schematics are safe to use in the wrapped VM context
4956
if (/\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile)) {

packages/angular/pwa/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ts_library(
4242
"//packages/angular_devkit/schematics",
4343
"//packages/schematics/angular",
4444
"@npm//@types/node",
45-
"@npm//@types/parse5-html-rewriting-stream",
45+
"@npm//parse5-html-rewriting-stream",
4646
],
4747
)
4848

@@ -58,7 +58,6 @@ ts_library(
5858
deps = [
5959
":pwa",
6060
"//packages/angular_devkit/schematics/testing",
61-
"@npm//parse5-html-rewriting-stream",
6261
],
6362
)
6463

packages/angular/pwa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"@angular-devkit/schematics": "0.0.0-PLACEHOLDER",
1616
"@schematics/angular": "0.0.0-PLACEHOLDER",
17-
"parse5-html-rewriting-stream": "6.0.1"
17+
"parse5-html-rewriting-stream": "7.0.0"
1818
},
1919
"peerDependencies": {
2020
"@angular/cli": "^15.0.0 || ^15.2.0-next"

packages/angular/pwa/pwa/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ function updateIndexFile(path: string): Rule {
3030
throw new SchematicsException(`Could not read index file: ${path}`);
3131
}
3232

33-
const rewriter = new (await import('parse5-html-rewriting-stream')).default();
33+
const { RewritingStream } = await loadEsmModule<typeof import('parse5-html-rewriting-stream')>(
34+
'parse5-html-rewriting-stream',
35+
);
36+
37+
const rewriter = new RewritingStream();
3438
let needsNoScript = true;
3539
rewriter.on('startTag', (startTag) => {
3640
if (startTag.tagName === 'noscript') {
@@ -173,3 +177,19 @@ export default function (options: PwaOptions): Rule {
173177
]);
174178
};
175179
}
180+
181+
/**
182+
* This uses a dynamic import to load a module which may be ESM.
183+
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
184+
* will currently, unconditionally downlevel dynamic import into a require call.
185+
* require calls cannot load ESM code and will result in a runtime error. To workaround
186+
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
187+
* Once TypeScript provides support for keeping the dynamic import this workaround can
188+
* be dropped.
189+
*
190+
* @param modulePath The path of the module to load.
191+
* @returns A Promise that resolves to the dynamically imported module.
192+
*/
193+
function loadEsmModule<T>(modulePath: string | URL): Promise<T> {
194+
return new Function('modulePath', `return import(modulePath);`)(modulePath) as Promise<T>;
195+
}

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ ts_library(
129129
"@npm//@types/less",
130130
"@npm//@types/loader-utils",
131131
"@npm//@types/node",
132-
"@npm//@types/parse5-html-rewriting-stream",
133132
"@npm//@types/semver",
134133
"@npm//@types/text-table",
135134
"@npm//ajv",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"mini-css-extract-plugin": "2.7.2",
4747
"open": "8.4.1",
4848
"ora": "5.4.1",
49-
"parse5-html-rewriting-stream": "6.0.1",
49+
"parse5-html-rewriting-stream": "7.0.0",
5050
"piscina": "3.2.0",
5151
"postcss": "8.4.21",
5252
"postcss-loader": "7.0.2",

packages/angular_devkit/build_angular/src/utils/index-file/html-rewriting-stream.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
*/
88

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

1112
export async function htmlRewritingStream(content: string): Promise<{
12-
rewriter: import('parse5-html-rewriting-stream');
13+
rewriter: import('parse5-html-rewriting-stream').RewritingStream;
1314
transformedContent: () => Promise<string>;
1415
}> {
16+
const { RewritingStream } = await loadEsmModule<typeof import('parse5-html-rewriting-stream')>(
17+
'parse5-html-rewriting-stream',
18+
);
1519
const chunks: Buffer[] = [];
16-
const rewriter = new (await import('parse5-html-rewriting-stream')).default();
20+
const rewriter = new RewritingStream();
1721

1822
return {
1923
rewriter,

yarn.lock

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121

122122
"@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#3e4d95e36cbb0230de1f3eabed91d260caa7ddde":
123123
version "0.0.0-7ed99e1d1b65cfc98021691d1c2ac92f44076190"
124-
uid "3e4d95e36cbb0230de1f3eabed91d260caa7ddde"
125124
resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#3e4d95e36cbb0230de1f3eabed91d260caa7ddde"
126125
dependencies:
127126
"@angular-devkit/build-angular" "15.2.0-next.3"
@@ -307,7 +306,6 @@
307306

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

3181-
"@types/parse5-html-rewriting-stream@^5.1.2":
3182-
version "5.1.2"
3183-
resolved "https://registry.yarnpkg.com/@types/parse5-html-rewriting-stream/-/parse5-html-rewriting-stream-5.1.2.tgz#919d5bbf69ef61e11d873e7195891c3811491a03"
3184-
integrity sha512-7CHY6QlayurvYRST5xatE/ipIueph5V+EW2xU12P0CsNucuwygnuiE4foYsdQUEkhnKrTU62KmikANPnoxiGrg==
3185-
dependencies:
3186-
"@types/parse5-sax-parser" "*"
3187-
3188-
"@types/parse5-sax-parser@*", "@types/parse5-sax-parser@^5.0.2":
3179+
"@types/parse5-sax-parser@^5.0.2":
31893180
version "5.0.2"
31903181
resolved "https://registry.yarnpkg.com/@types/parse5-sax-parser/-/parse5-sax-parser-5.0.2.tgz#4cdca0f8bc0ce71b17e27b96e7ca9b5f79e861ff"
31913182
integrity sha512-EQtGoduLbdMmS4N27g6wcXdCCJ70dWYemfogWuumYg+JmzRqwYvTRAbGOYFortSHtS/qRzRCFwcP3ixy62RsdA==
@@ -5407,7 +5398,7 @@ entities@^2.0.0:
54075398
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
54085399
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
54095400

5410-
entities@^4.4.0:
5401+
entities@^4.3.0, entities@^4.4.0:
54115402
version "4.4.0"
54125403
resolved "https://registry.yarnpkg.com/entities/-/entities-4.4.0.tgz#97bdaba170339446495e653cfd2db78962900174"
54135404
integrity sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==
@@ -8975,6 +8966,15 @@ parse5-html-rewriting-stream@6.0.1:
89758966
parse5 "^6.0.1"
89768967
parse5-sax-parser "^6.0.1"
89778968

8969+
parse5-html-rewriting-stream@7.0.0:
8970+
version "7.0.0"
8971+
resolved "https://registry.yarnpkg.com/parse5-html-rewriting-stream/-/parse5-html-rewriting-stream-7.0.0.tgz#e376d3e762d2950ccbb6bb59823fc1d7e9fdac36"
8972+
integrity sha512-mazCyGWkmCRWDI15Zp+UiCqMp/0dgEmkZRvhlsqqKYr4SsVm/TvnSpD9fCvqCA2zoWJcfRym846ejWBBHRiYEg==
8973+
dependencies:
8974+
entities "^4.3.0"
8975+
parse5 "^7.0.0"
8976+
parse5-sax-parser "^7.0.0"
8977+
89788978
parse5-htmlparser2-tree-adapter@^6.0.1:
89798979
version "6.0.1"
89808980
resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz#2cdf9ad823321140370d4dbf5d3e92c7c8ddc6e6"
@@ -8989,7 +8989,14 @@ parse5-sax-parser@^6.0.1:
89898989
dependencies:
89908990
parse5 "^6.0.1"
89918991

8992-
parse5@*, parse5@^7.1.2:
8992+
parse5-sax-parser@^7.0.0:
8993+
version "7.0.0"
8994+
resolved "https://registry.yarnpkg.com/parse5-sax-parser/-/parse5-sax-parser-7.0.0.tgz#4c05064254f0488676aca75fb39ca069ec96dee5"
8995+
integrity sha512-5A+v2SNsq8T6/mG3ahcz8ZtQ0OUFTatxPbeidoMB7tkJSGDY3tdfl4MHovtLQHkEn5CGxijNWRQHhRQ6IRpXKg==
8996+
dependencies:
8997+
parse5 "^7.0.0"
8998+
8999+
parse5@*, parse5@^7.0.0, parse5@^7.1.2:
89939000
version "7.1.2"
89949001
resolved "https://registry.yarnpkg.com/parse5/-/parse5-7.1.2.tgz#0736bebbfd77793823240a23b7fc5e010b7f8e32"
89959002
integrity sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==
@@ -9976,7 +9983,6 @@ sass@1.58.0, sass@^1.55.0:
99769983

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

99829988
saucelabs@^1.5.0:

0 commit comments

Comments
 (0)