mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
module: use sync cjs when importing cts
PR-URL: https://github.com/nodejs/node/pull/60072 Fixes: https://github.com/nodejs/node/issues/59963 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This commit is contained in:
parent
23b834058c
commit
69144e96c2
|
|
@ -504,7 +504,9 @@ class ModuleLoader {
|
||||||
const loadResult = this.#loadSync(url, { format, importAttributes });
|
const loadResult = this.#loadSync(url, { format, importAttributes });
|
||||||
|
|
||||||
// Use the synchronous commonjs translator which can deal with cycles.
|
// Use the synchronous commonjs translator which can deal with cycles.
|
||||||
const finalFormat = loadResult.format === 'commonjs' ? 'commonjs-sync' : loadResult.format;
|
const finalFormat =
|
||||||
|
loadResult.format === 'commonjs' ||
|
||||||
|
loadResult.format === 'commonjs-typescript' ? 'commonjs-sync' : loadResult.format;
|
||||||
|
|
||||||
if (finalFormat === 'wasm') {
|
if (finalFormat === 'wasm') {
|
||||||
assert.fail('WASM is currently unsupported by require(esm)');
|
assert.fail('WASM is currently unsupported by require(esm)');
|
||||||
|
|
|
||||||
|
|
@ -174,3 +174,13 @@ test('expect failure of a .cts file requiring esm in node_modules', async () =>
|
||||||
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
|
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
|
||||||
strictEqual(result.code, 1);
|
strictEqual(result.code, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cts -> require mts -> import cts', async () => {
|
||||||
|
const result = await spawnPromisified(process.execPath, [
|
||||||
|
fixtures.path('typescript/cts/issue-59963/a.cts'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
strictEqual(result.stderr, '');
|
||||||
|
strictEqual(result.stdout, 'Hello from c.cts\n');
|
||||||
|
strictEqual(result.code, 0);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -98,3 +98,14 @@ test('execute .ts file importing a module', async () => {
|
||||||
strictEqual(result.stdout, 'Hello, TypeScript!\n');
|
strictEqual(result.stdout, 'Hello, TypeScript!\n');
|
||||||
strictEqual(result.code, 0);
|
strictEqual(result.code, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('mts -> import cts -> require mts', async () => {
|
||||||
|
const result = await spawnPromisified(process.execPath, [
|
||||||
|
'--no-warnings',
|
||||||
|
fixtures.path('typescript/mts/issue-59963/a.mts'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
strictEqual(result.stderr, '');
|
||||||
|
strictEqual(result.stdout, 'Hello from c.mts\n');
|
||||||
|
strictEqual(result.code, 0);
|
||||||
|
});
|
||||||
|
|
|
||||||
3
test/fixtures/typescript/cts/issue-59963/a.cts
vendored
Normal file
3
test/fixtures/typescript/cts/issue-59963/a.cts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
const { message } = require("./b.mts");
|
||||||
|
interface Foo {};
|
||||||
|
console.log(message);
|
||||||
2
test/fixtures/typescript/cts/issue-59963/b.mts
vendored
Normal file
2
test/fixtures/typescript/cts/issue-59963/b.mts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
interface Foo {};
|
||||||
|
export { message } from "./c.cts";
|
||||||
2
test/fixtures/typescript/cts/issue-59963/c.cts
vendored
Normal file
2
test/fixtures/typescript/cts/issue-59963/c.cts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
const message: string = "Hello from c.cts";
|
||||||
|
module.exports = { message };
|
||||||
3
test/fixtures/typescript/mts/issue-59963/a.mts
vendored
Normal file
3
test/fixtures/typescript/mts/issue-59963/a.mts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { message } from "./b.cts";
|
||||||
|
interface Foo {};
|
||||||
|
console.log(message);
|
||||||
3
test/fixtures/typescript/mts/issue-59963/b.cts
vendored
Normal file
3
test/fixtures/typescript/mts/issue-59963/b.cts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
const { message } = require("./c.mts");
|
||||||
|
interface Foo {};
|
||||||
|
module.exports = { message };
|
||||||
1
test/fixtures/typescript/mts/issue-59963/c.mts
vendored
Normal file
1
test/fixtures/typescript/mts/issue-59963/c.mts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export const message: string = "Hello from c.mts";
|
||||||
Loading…
Reference in New Issue
Block a user