Skip to content

Commit 99adaaa

Browse files
committed
fix: resolve remaining TS 5.9 + nodenext compilation issues
- Restore JSDoc packages (config-loader, parse5-utils, rollup-plugin-copy, rollup-plugin-import-meta-assets, storybook-utils) to master .js sources (JSDoc→TS conversion belongs in PR4) - Restore parse5 v6 type imports (parse5 v8 migration belongs in PR4) - Restore ws v7 API in WebSocketsManager (ws v8 belongs in PR4) - Fix Token → Attribute import for parse5 v6 compat in rollup-plugin-html - Fix Object.values(bundle) unknown type with explicit cast - Add CJS interop for saucelabs and internal-ip (needed for nodenext) - Add CJS interop for rollup plugins in storybook-builder (needed for nodenext) - Restore master test scripts (test migration belongs in PR2) Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b7b1354 commit 99adaaa

88 files changed

Lines changed: 875 additions & 855 deletions

File tree

Some content is hidden

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

packages/browser-logs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
"scripts": {
2828
"build": "tsc",
29-
"test:node": "node --test test/**/*.test.ts",
30-
"test:watch": "node --test --watch test/**/*.test.ts"
29+
"test:node": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --reporter dot",
30+
"test:watch": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --watch --watch-files src,test"
3131
},
3232
"files": [
3333
"*.d.ts",

packages/browser-logs/src/browserScript.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import path from 'path';
44
const REGEXP_SOURCE_MAP = /\/\/# sourceMappingURL=.*/;
55

66
const serializeScript = fs
7-
.readFileSync(path.resolve(import.meta.dirname, 'serialize.js'), 'utf-8')
7+
.readFileSync(path.resolve(__dirname, 'serialize.js'), 'utf-8')
88
.replace(REGEXP_SOURCE_MAP, '');
99
const logUncaughtErrorsScript = fs
10-
.readFileSync(path.resolve(import.meta.dirname, 'logUncaughtErrors.js'), 'utf-8')
10+
.readFileSync(path.resolve(__dirname, 'logUncaughtErrors.js'), 'utf-8')
1111
.replace(REGEXP_SOURCE_MAP, '');
1212

1313
/**
14-
* Create the browser script as an IIFE wrapper.
15-
* It can't be ESM because it should work on older browsers as well.
14+
* Create the browser script. This project is compiled as CJS because it also needs to run in node, so
15+
* we create a small wrapper.
16+
*
17+
* It can't be ESM anyway, because it should work on older browsers as well.
1618
*/
1719
export const browserScript =
1820
'(function () { var module={};var exports={};\n' +

packages/config-loader/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"scripts": {
2222
"build": "tsc",
23-
"test:node": "node --test 'test/**/*.test.mjs'",
24-
"test:watch": "node --test --watch 'test/**/*.test.mjs'"
23+
"test:node": "mocha test/**/*.test.js --reporter dot",
24+
"test:watch": "mocha test/**/*.test.js --watch --watch-files .,src,test --reporter dot"
2525
},
2626
"files": [
2727
"*.d.ts",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = class ConfigLoaderError extends Error {};

packages/config-loader/src/ConfigLoaderError.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import fs from 'fs/promises';
2-
import path from 'path';
3-
import { fileExists } from './utils.ts';
1+
const fs = require('fs').promises;
2+
const path = require('path');
3+
const { fileExists } = require('./utils');
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>}
810
*/
9-
async function getPackageType(basedir: string): Promise<string> {
11+
async function getPackageType(basedir) {
1012
let currentPath = basedir;
1113
try {
1214
while (await fileExists(currentPath)) {
@@ -26,4 +28,4 @@ async function getPackageType(basedir: string): Promise<string> {
2628
return 'commonjs';
2729
}
2830

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

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { pathToFileURL } from 'url';
2-
import ConfigLoaderError from './ConfigLoaderError.ts';
1+
const { pathToFileURL } = require('url');
2+
const ConfigLoaderError = require('./ConfigLoaderError');
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,7 +9,10 @@ const CJS_ERRORS = [
99
'ReferenceError: exports is not defined',
1010
];
1111

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

@@ -21,7 +24,7 @@ async function importConfig(path: string): Promise<object> {
2124

2225
return config.default;
2326
} catch (e) {
24-
if (CJS_ERRORS.some(msg => (e as Error).stack?.includes(msg))) {
27+
if (CJS_ERRORS.some(msg => /** @type {Error} */(e).stack?.includes(msg))) {
2528
throw new ConfigLoaderError(
2629
'You are using CommonJS syntax such as "require" or "module.exports" in a config loaded as es module. ' +
2730
'Use import/export syntax, or load the file as a CommonJS module by ' +
@@ -32,4 +35,4 @@ async function importConfig(path: string): Promise<object> {
3235
}
3336
}
3437

35-
export default importConfig;
38+
module.exports = importConfig;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const getPackageType = require('./getPackageType');
2+
const path = require('path');
3+
const requireConfig = require('./requireConfig');
4+
5+
/**
6+
* @param {string} configPath
7+
*/
8+
function importConfig(configPath) {
9+
// Conditionally requires importConfig function to avoid logging a warning on node v12
10+
// when not using an es modules
11+
const importConfigFunction = require('./importConfig');
12+
return importConfigFunction(configPath);
13+
}
14+
15+
/**
16+
* @param {string} configPath
17+
* @param {string} basedir
18+
*/
19+
async function importOrRequireConfig(configPath, basedir) {
20+
const ext = path.extname(configPath);
21+
22+
switch (ext) {
23+
case '.mjs':
24+
return importConfig(configPath);
25+
case '.cjs':
26+
return requireConfig(configPath);
27+
default:
28+
const packageType = await getPackageType(basedir);
29+
return packageType === 'module' ? importConfig(configPath) : requireConfig(configPath);
30+
}
31+
}
32+
33+
module.exports = importOrRequireConfig;

packages/config-loader/src/importOrRequireConfig.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import path from 'path';
2-
import { fileExists } from './utils.ts';
3-
import ConfigLoaderError from './ConfigLoaderError.ts';
4-
import importOrRequireConfig from './importOrRequireConfig.ts';
1+
const path = require('path');
2+
const { fileExists } = require('./utils');
3+
const ConfigLoaderError = require('./ConfigLoaderError.js');
4+
const importOrRequireConfig = require('./importOrRequireConfig');
55

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

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

30-
export { readConfig, ConfigLoaderError };
35+
module.exports = { readConfig, ConfigLoaderError };

0 commit comments

Comments
 (0)