Skip to content

Commit 0ca04ab

Browse files
committed
fix: restore all parse5 v8 type migrations from fix/node24
Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dff9b8c commit 0ca04ab

16 files changed

Lines changed: 132 additions & 630 deletions

package-lock.json

Lines changed: 47 additions & 550 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dev-server-import-maps/src/importMapsPlugin.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { Plugin, Logger, getRequestFilePath } from '@web/dev-server-core';
1+
import { getRequestFilePath } from '@web/dev-server-core';
2+
import type { Plugin, Logger } from '@web/dev-server-core';
23
import {
3-
ParsedImportMap,
44
parse as parseFromObject,
55
parseFromString,
66
resolve,
77
} from '@import-maps/resolve';
8+
import type { ParsedImportMap, ImportMap } from '@import-maps/resolve';
89
import { getHtmlPath } from '@web/dev-server-core';
9-
import { parse as parseHtml, serialize as serializeHtml, Element as ElementAst } from 'parse5';
10+
import { parse as parseHtml, serialize as serializeHtml } from 'parse5';
11+
import type { DefaultTreeAdapterTypes } from 'parse5';
12+
type ElementAst = DefaultTreeAdapterTypes.Element;
1013
import path from 'path';
1114

1215
import {
@@ -17,8 +20,7 @@ import {
1720
shouldInject,
1821
mergeImportMaps,
1922
getDocumentBaseUrl,
20-
} from './utils.js';
21-
import { ImportMap } from '@import-maps/resolve';
23+
} from './utils.ts';
2224
import {
2325
createElement,
2426
findElement,

packages/dev-server-import-maps/src/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import picoMatch from 'picomatch';
2-
import { Context, getHtmlPath } from '@web/dev-server-core';
3-
import { Element as ElementAst } from 'parse5';
2+
import { getHtmlPath } from '@web/dev-server-core';
3+
import type { Context } from '@web/dev-server-core';
4+
import type { DefaultTreeAdapterTypes } from 'parse5';
5+
type ElementAst = DefaultTreeAdapterTypes.Element;
46
import { getAttribute } from '@web/parse5-utils';
5-
import { ParsedImportMap } from '@import-maps/resolve';
7+
import type { ParsedImportMap } from '@import-maps/resolve';
68

7-
import { NormalizedInjectSetting, InjectSetting } from './importMapsPlugin.js';
9+
import type { NormalizedInjectSetting, InjectSetting } from './importMapsPlugin.ts';
810

911
export const IMPORT_MAP_PARAM = 'wds-import-map';
1012

packages/dev-server-legacy/src/findJsScripts.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { isUri } from 'valid-url';
2-
import { Document as DocumentAst, Node as NodeAst } from 'parse5';
1+
import validUrl from 'valid-url';
2+
3+
const { isUri } = validUrl;
4+
import type { DefaultTreeAdapterTypes } from 'parse5';
5+
type DocumentAst = DefaultTreeAdapterTypes.Document;
6+
type NodeAst = DefaultTreeAdapterTypes.Node;
37
import { queryAll, predicates, getAttribute, hasAttribute } from '@web/dev-server-core/dist/dom5';
48

59
function isDeferred(script: NodeAst) {

packages/dev-server-legacy/src/injectPolyfillsLoader.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { Context } from '@web/dev-server-core';
1+
import type { Context } from '@web/dev-server-core';
22
import { getAttribute, getTextContent, remove } from '@web/dev-server-core/dist/dom5';
3-
import { parse, serialize, Document as DocumentAst, Node as NodeAst } from 'parse5';
3+
import { parse, serialize } from 'parse5';
4+
import type { DefaultTreeAdapterTypes } from 'parse5';
5+
type DocumentAst = DefaultTreeAdapterTypes.Document;
6+
type NodeAst = DefaultTreeAdapterTypes.Node;
47
import {
58
injectPolyfillsLoader as originalInjectPolyfillsLoader,
6-
PolyfillsConfig,
79
fileTypes,
810
getScriptFileType,
11+
} from '@web/polyfills-loader';
12+
import type {
13+
PolyfillsConfig,
914
GeneratedFile,
1015
File,
1116
} from '@web/polyfills-loader';
12-
import { PARAM_TRANSFORM_SYSTEMJS } from './constants.js';
13-
import { findJsScripts } from './findJsScripts.js';
17+
import { PARAM_TRANSFORM_SYSTEMJS } from './constants.ts';
18+
import { findJsScripts } from './findJsScripts.ts';
1419

1520
function findScripts(indexUrl: string, documentAst: DocumentAst) {
1621
const scriptNodes = findJsScripts(documentAst);

packages/rollup-plugin-html/src/RollupPluginHTMLOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { OutputChunk, OutputOptions, OutputBundle } from 'rollup';
2-
import type { Attribute } from 'parse5';
2+
import type { Token } from 'parse5';
3+
type Attribute = Token.Attribute;
34

45
// Ensure this file is evaluated as an ES module
56
export const __esModule = true;

packages/rollup-plugin-html/src/assets/utils.ts

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
import { Document, Element } from 'parse5';
1+
import type { DefaultTreeAdapterTypes } from 'parse5';
2+
type Document = DefaultTreeAdapterTypes.Document;
3+
type Element = DefaultTreeAdapterTypes.Element;
24
import path from 'path';
35
import picomatch from 'picomatch';
46
import { findElements, getTagName, getAttribute } from '@web/parse5-utils';
5-
import { createError } from '../utils.js';
7+
import { createError } from '../utils.ts';
68
import { serialize } from 'v8';
79

8-
const assetLinkRels = [
9-
'icon',
10-
'apple-touch-icon',
11-
'mask-icon',
12-
'stylesheet',
13-
'manifest',
14-
'preload',
15-
'prefetch',
16-
'modulepreload',
17-
];
18-
const legacyHashedLinkRels = ['stylesheet'];
19-
const assetMetaProperties = ['og:image'];
10+
const hashedLinkRels = ['stylesheet'];
11+
const linkRels = [...hashedLinkRels, 'icon', 'manifest', 'apple-touch-icon', 'mask-icon'];
2012

2113
function getSrcSetUrls(srcset: string) {
2214
if (!srcset) {
@@ -51,14 +43,13 @@ function isAsset(node: Element) {
5143
path = extractFirstUrlOfSrcSet(node) ?? '';
5244
}
5345
break;
54-
case 'link': {
55-
if (assetLinkRels.includes(getAttribute(node, 'rel') ?? '')) {
46+
case 'link':
47+
if (linkRels.includes(getAttribute(node, 'rel') ?? '')) {
5648
path = getAttribute(node, 'href') ?? '';
5749
}
5850
break;
59-
}
6051
case 'meta':
61-
if (assetMetaProperties.includes(getAttribute(node, 'property') ?? '')) {
52+
if (getAttribute(node, 'property') === 'og:image' && getAttribute(node, 'content')) {
6253
path = getAttribute(node, 'content') ?? '';
6354
}
6455
break;
@@ -81,24 +72,16 @@ function isAsset(node: Element) {
8172
}
8273
}
8374

84-
export function isHashedAsset(
85-
node: Element,
86-
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css',
87-
) {
75+
export function isHashedAsset(node: Element) {
8876
switch (getTagName(node)) {
8977
case 'img':
9078
return true;
9179
case 'source':
9280
return true;
9381
case 'script':
9482
return true;
95-
case 'link': {
96-
if (extractAssets === 'legacy-html' || extractAssets === 'legacy-html-and-css') {
97-
return legacyHashedLinkRels.includes(getAttribute(node, 'rel') ?? '');
98-
} else {
99-
return true;
100-
}
101-
}
83+
case 'link':
84+
return hashedLinkRels.includes(getAttribute(node, 'rel')!);
10285
case 'meta':
10386
return true;
10487
default:
@@ -160,7 +143,7 @@ export function getSourcePaths(node: Element) {
160143
return paths;
161144
}
162145

163-
export function findAssets(document: Document) {
146+
export function findAssets(document: Document): Element[] {
164147
return findElements(document, isAsset);
165148
}
166149

packages/rollup-plugin-html/src/input/extract/extractAssets.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import { Document, serialize } from 'parse5';
1+
import type { DefaultTreeAdapterTypes } from 'parse5';
2+
type Document = DefaultTreeAdapterTypes.Document;
3+
import { serialize } from 'parse5';
24
import fs from 'fs';
35
import path from 'path';
4-
import { InputAsset } from '../InputData.js';
6+
import type { InputAsset } from '../InputData.ts';
57
import {
68
findAssets,
79
getSourcePaths,
810
isHashedAsset,
911
resolveAssetFilePath,
1012
createAssetPicomatchMatcher,
11-
} from '../../assets/utils.js';
13+
} from '../../assets/utils.ts';
1214

1315
export interface ExtractAssetsParams {
1416
document: Document;
1517
htmlFilePath: string;
1618
htmlDir: string;
1719
rootDir: string;
18-
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css';
1920
externalAssets?: string | string[];
2021
absolutePathPrefix?: string;
2122
}
@@ -36,7 +37,7 @@ export function extractAssets(params: ExtractAssetsParams): InputAsset[] {
3637
params.rootDir,
3738
params.absolutePathPrefix,
3839
);
39-
const hashed = isHashedAsset(node, params.extractAssets);
40+
const hashed = isHashedAsset(node);
4041
const alreadyHandled = allAssets.find(a => a.filePath === filePath && a.hashed === hashed);
4142
if (!alreadyHandled) {
4243
try {
@@ -50,7 +51,7 @@ export function extractAssets(params: ExtractAssetsParams): InputAsset[] {
5051
}
5152

5253
const content = fs.readFileSync(filePath);
53-
allAssets.push({ filePath, hashed: hashed, content });
54+
allAssets.push({ filePath, hashed, content });
5455
}
5556
}
5657
}

packages/rollup-plugin-html/src/input/extract/extractModules.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { findElements, getAttribute, getTagName, getTextContent, remove } from '@web/parse5-utils';
2-
import { Document, Attribute } from 'parse5';
2+
import type { DefaultTreeAdapterTypes, Token } from 'parse5';
3+
type Document = DefaultTreeAdapterTypes.Document;
4+
type Attribute = Token.Attribute;
35
import path from 'path';
46
import crypto from 'crypto';
5-
import { resolveAssetFilePath } from '../../assets/utils.js';
7+
import { resolveAssetFilePath } from '../../assets/utils.ts';
68
import { getAttributes } from '@web/parse5-utils';
7-
import { ScriptModuleTag } from '../../RollupPluginHTMLOptions.js';
9+
import type { ScriptModuleTag } from '../../RollupPluginHTMLOptions.ts';
810

911
export interface ExtractModulesParams {
1012
document: Document;

packages/rollup-plugin-html/src/input/extract/extractModulesAndAssets.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface ExtractParams {
77
html: string;
88
htmlFilePath: string;
99
rootDir: string;
10-
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css';
10+
extractAssets: boolean;
1111
externalAssets?: string | string[];
1212
absolutePathPrefix?: string;
1313
}
@@ -30,7 +30,6 @@ export function extractModulesAndAssets(params: ExtractParams) {
3030
htmlDir,
3131
htmlFilePath,
3232
rootDir,
33-
extractAssets: params.extractAssets,
3433
externalAssets,
3534
absolutePathPrefix,
3635
})

0 commit comments

Comments
 (0)