mirror of
https://github.com/electron/electron.git
synced 2026-10-28 11:44:46 +08:00
* test: mechanically rewrite spec imports and __dirname for native ESM This is the automated half of loading spec/ as native ES modules and is not expected to pass on its own; the hand-written half follows in the next commit. A script (included in the pull request description) made three changes to spec/*.ts and spec/lib/*.ts, then oxfmt was re-run: * relative import specifiers gain their real file extension * __dirname / __filename become import.meta.dirname / .filename * files that still call require() from module code get a createRequire(import.meta.url) prelude Code inside functions that are stringified and evaluated in another process (remotely(), itremote(), template-interpolated functions and similar) is left as it was. * test: load specs as native ES modules with Node's type stripping spec/package.json declares "type": "module", so the spec runner and every spec file now load through Node's own ESM loader and built-in TypeScript type stripping; the require.extensions transpile hook is gone. A new spec/fixtures/package.json keeps fixtures in a CommonJS scope. The hand-written changes on top of the mechanical rewrite: * spec/index.js becomes an ES module and import()s its test dependencies after the app is ready, then uses mocha.loadFilesAsync(). * Functions that are stringified and sent to another process now arrive as written rather than as CommonJS transpiler output, so the remote-control and utility-process fixtures define the plain names those bodies use (chai, expect, once, setTimeout, ...) instead of the old `electron_1` style shims, and a few bodies require() what they use. * The two specs that exercise lib/ sources require() them, since lib/ is not in a "type": "module" scope. * spec-helpers resolves BrowserWindow lazily so it stays loadable from a utility process. * tsconfig.spec.json allows .ts extension imports; spec/tsconfig.json points editors at it. --------- Co-authored-by: Claude <noreply@anthropic.com>
23 lines
644 B
JSON
23 lines
644 B
JSON
{
|
|
"extends": "./tsconfig.json",
|
|
"compilerOptions": {
|
|
"skipLibCheck": true,
|
|
"module": "nodenext",
|
|
// Specs are loaded as-is by Node's built-in type stripping, so only
|
|
// erasable syntax is allowed and imports must name real files. (Type-only
|
|
// imports are enforced by oxlint rather than verbatimModuleSyntax, which
|
|
// would reject the CommonJS-scoped lib/ files a couple of specs import.)
|
|
"allowImportingTsExtensions": true,
|
|
"erasableSyntaxOnly": true,
|
|
"isolatedModules": true,
|
|
"noEmit": true
|
|
},
|
|
"include": [
|
|
"spec",
|
|
"typings"
|
|
],
|
|
"exclude": [
|
|
"spec/fixtures/type-stripping"
|
|
]
|
|
}
|