Skip to content

Commit cc062eb

Browse files
committed
feat!: migrate parse5 to v7+/v8 and convert JSDoc packages to TypeScript
BREAKING CHANGE: parse5 v6 is no longer supported. parse5 v7+/v8 migration: - Update all parse5 type imports to use DefaultTreeAdapterTypes namespace - Update parse5 dependencies from ^6.0.1 to ^7.0.0 || ^8.0.0 - Remove @types/parse5 (types now bundled with parse5) - Update dom5 internal library for parse5 v8 compatibility JSDoc → TypeScript conversions: - config-loader: convert .js source files to .ts - parse5-utils: rewrite as TypeScript with parse5 v8 API - rollup-plugin-copy: convert .js source files to .ts - rollup-plugin-import-meta-assets: convert .js source files to .ts - storybook-utils: convert .js source files to .ts Additional changes: - Upgrade koa to v3.1.1 and ws to v8.18.3 in dev-server-core - Upgrade @types/koa to v3.0.1 and @types/ws to v8.5.13 - Fix WebSocketsManager for ws v8 API (WebSocketServer) - Update test-runner-mocha rollup config for ESM/nodenext Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eb87c8d commit cc062eb

69 files changed

Lines changed: 2360 additions & 1131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@
5555
"@rollup/plugin-typescript": "^11.1.5",
5656
"@types/chai": "^4.2.22",
5757
"@types/fs-extra": "^11.0.4",
58+
"@types/koa": "^3.0.1",
5859
"@types/mocha": "^10.0.1",
5960
"@types/node": "*",
61+
"@types/ws": "^8.5.13",
6062
"@typescript-eslint/eslint-plugin": "^8.48.0",
6163
"@typescript-eslint/parser": "^8.48.0",
6264
"alex": "^11.0.0",
@@ -71,6 +73,7 @@
7173
"lint-staged": "^15.2.11",
7274
"mocha": "^10.8.2",
7375
"nanocolors": "^0.2.1",
76+
"parse5": "^8.0.0",
7477
"prettier": "^3.7.1",
7578
"prettier-plugin-package": "^2.0.0",
7679
"rimraf": "^4.4.1",

packages/config-loader/src/ConfigLoaderError.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default class ConfigLoaderError extends Error {}

packages/config-loader/src/getPackageType.js renamed to packages/config-loader/src/getPackageType.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
const fs = require('fs').promises;
2-
const path = require('path');
3-
const { fileExists } = require('./utils');
1+
import fs from 'fs/promises';
2+
import path from 'path';
3+
import { fileExists } from './utils.ts';
44

55
/**
66
* Gets the package type for a given directory. Walks up the file system, looking
77
* for a package.json file and returns the package type.
8-
* @param {string} basedir
9-
* @returns {Promise<string>}
108
*/
11-
async function getPackageType(basedir) {
9+
async function getPackageType(basedir: string): Promise<string> {
1210
let currentPath = basedir;
1311
try {
1412
while (await fileExists(currentPath)) {
@@ -28,4 +26,4 @@ async function getPackageType(basedir) {
2826
return 'commonjs';
2927
}
3028

31-
module.exports = getPackageType;
29+
export default getPackageType;

packages/config-loader/src/importConfig.js renamed to packages/config-loader/src/importConfig.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { pathToFileURL } = require('url');
2-
const ConfigLoaderError = require('./ConfigLoaderError');
1+
import { pathToFileURL } from 'url';
2+
import ConfigLoaderError from './ConfigLoaderError.ts';
33

44
// These strings may be node-version dependent and need updating over time
55
// They're just to display a helpful error message
@@ -9,10 +9,7 @@ const CJS_ERRORS = [
99
'ReferenceError: exports is not defined',
1010
];
1111

12-
/**
13-
* @param {string} path
14-
*/
15-
async function importConfig(path) {
12+
async function importConfig(path: string): Promise<object> {
1613
try {
1714
const config = await import(pathToFileURL(path).href);
1815

@@ -24,7 +21,7 @@ async function importConfig(path) {
2421

2522
return config.default;
2623
} catch (e) {
27-
if (CJS_ERRORS.some(msg => /** @type {Error} */(e).stack?.includes(msg))) {
24+
if (CJS_ERRORS.some(msg => (e as Error).stack?.includes(msg))) {
2825
throw new ConfigLoaderError(
2926
'You are using CommonJS syntax such as "require" or "module.exports" in a config loaded as es module. ' +
3027
'Use import/export syntax, or load the file as a CommonJS module by ' +
@@ -35,4 +32,4 @@ async function importConfig(path) {
3532
}
3633
}
3734

38-
module.exports = importConfig;
35+
export default importConfig;

packages/config-loader/src/importOrRequireConfig.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import getPackageType from './getPackageType.ts';
2+
import path from 'path';
3+
import requireConfig from './requireConfig.ts';
4+
import importConfigFunction from './importConfig.ts';
5+
6+
async function importOrRequireConfig(configPath: string, basedir: string): Promise<object> {
7+
const ext = path.extname(configPath);
8+
9+
switch (ext) {
10+
case '.mjs':
11+
return importConfigFunction(configPath);
12+
case '.cjs':
13+
return requireConfig(configPath);
14+
default:
15+
const packageType = await getPackageType(basedir);
16+
return packageType === 'module' ? importConfigFunction(configPath) : requireConfig(configPath);
17+
}
18+
}
19+
20+
export default importOrRequireConfig;
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
const path = require('path');
2-
const { fileExists } = require('./utils');
3-
const ConfigLoaderError = require('./ConfigLoaderError.js');
4-
const importOrRequireConfig = require('./importOrRequireConfig');
1+
import path from 'path';
2+
import { fileExists } from './utils.ts';
3+
import ConfigLoaderError from './ConfigLoaderError.ts';
4+
import importOrRequireConfig from './importOrRequireConfig.ts';
55

66
const EXTENSIONS = ['.mjs', '.cjs', '.js'];
77

8-
/**
9-
* @param {string} name
10-
* @param {string} [customPath]
11-
* @param {string} [basedir]
12-
*/
13-
async function readConfig(name, customPath, basedir = process.cwd()) {
8+
async function readConfig(name: string, customPath?: string, basedir: string = process.cwd()): Promise<any> {
149
const resolvedCustomPath = customPath ? path.resolve(basedir, customPath) : undefined;
1510
if (resolvedCustomPath && !(await fileExists(resolvedCustomPath))) {
1611
throw new ConfigLoaderError(`Could not find a config file at ${resolvedCustomPath}`);
@@ -32,4 +27,4 @@ async function readConfig(name, customPath, basedir = process.cwd()) {
3227
return null;
3328
}
3429

35-
module.exports = { readConfig, ConfigLoaderError };
30+
export { readConfig, ConfigLoaderError };
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const ConfigLoaderError = require('./ConfigLoaderError');
1+
import { createRequire } from 'module';
2+
import ConfigLoaderError from './ConfigLoaderError.ts';
3+
4+
const require = createRequire(import.meta.url);
25

36
// These strings may be node-version dependent and need updating over time
47
// They're just to display a helpful error message
@@ -7,14 +10,11 @@ const ESM_ERRORS = [
710
'SyntaxError: Cannot use import statement outside a module',
811
];
912

10-
/**
11-
* @param {string} path
12-
*/
13-
function requireConfig(path) {
13+
function requireConfig(path: string): object {
1414
try {
1515
return require(path);
1616
} catch (e) {
17-
if (ESM_ERRORS.some(msg => /** @type {Error} **/(e).stack?.includes(msg))) {
17+
if (ESM_ERRORS.some(msg => (e as Error).stack?.includes(msg))) {
1818
throw new ConfigLoaderError(
1919
'You are using es module syntax in a config loaded as CommonJS module. ' +
2020
'Use require/module.exports syntax, or load the file as es module by using the .mjs ' +
@@ -25,4 +25,4 @@ function requireConfig(path) {
2525
}
2626
}
2727

28-
module.exports = requireConfig;
28+
export default requireConfig;

0 commit comments

Comments
 (0)