260129.1 · cf1e0975490823b1cf772c65c100ee82b55502c3
fix: use detected format
reading declarations
@@ -13,12 +13,10 @@ export async function load( ) { const { format } = context; if (format?.endsWith("-typescript")) {- // Use format 'module' so it returns the source as-is, without stripping the types.- // Format 'commonjs' would not return the source for historical reasons. try { const { source } = await nextLoad(url, { ...context,- format: "module",+ format, }); // biome-ignore lint/style/noNonNullAssertion: If module exists, it will have a source const { code } = transformSync(source!.toString(), {
@@ -15,11 +15,9 @@ export async function load( const { format } = context; if (format?.endsWith("-typescript")) { try {- // Use format 'module' so it returns the source as-is, without stripping the types.- // Format 'commonjs' would not return the source for historical reasons. const { source } = await nextLoad(url, { ...context,- format: "module",+ format, }); // biome-ignore lint/style/noNonNullAssertion: If module exists, it will have a source
@@ -0,0 +1,9 @@+const message: string = "Hello from CommonJS TypeScript (.cts)!";++function greet(name: string): void {+ console.log(`${message} - ${name}`);+}++module.exports = { greet };++greet("Test");
@@ -0,0 +1,9 @@+const message: string = "Hello from CommonJS TypeScript!";++function greet(name: string): void {+ console.log(`${message} - ${name}`);+}++module.exports = { greet };++greet("Test");
@@ -0,0 +1,7 @@+const message: string = "Hello from ESM TypeScript!";++export function greet(name: string): void {+ console.log(`${message} - ${name}`);+}++greet("Test");
@@ -0,0 +1,7 @@+const message: string = "Hello from ESM TypeScript!";++export function greet(name: string): void {+ console.log(`${message} - ${name}`);+}++greet("Test");
test/fixtures/esm/package.json
@@ -0,0 +1 @@+{}
@@ -99,3 +99,99 @@ test("should throw syntax error for invalid typescript", async (t) => { match(result.stderr, /await isn't allowed in non-async function/); strictEqual(result.code, 1); });++test("should work with commonjs typescript files using strip", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-strip.mjs",+ fixturesPath("commonjs.ts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from CommonJS TypeScript!/);+ strictEqual(result.code, 0);+});++test("should work with commonjs typescript files using transform", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-transform.mjs",+ fixturesPath("commonjs.ts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from CommonJS TypeScript!/);+ strictEqual(result.code, 0);+});++test("should work with .cts files using strip", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-strip.mjs",+ fixturesPath("commonjs.cts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from CommonJS TypeScript \(\.cts\)!/);+ strictEqual(result.code, 0);+});++test("should work with .cts files using transform", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-transform.mjs",+ fixturesPath("commonjs.cts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from CommonJS TypeScript \(\.cts\)!/);+ strictEqual(result.code, 0);+});++test("should work with esm typescript files using strip", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-strip.mjs",+ fixturesPath("esm/esm.ts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from ESM TypeScript!/);+ strictEqual(result.code, 0);+});++test("should work with esm typescript files using transform", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-transform.mjs",+ fixturesPath("esm/esm.ts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from ESM TypeScript!/);+ strictEqual(result.code, 0);+});++test("should work with .mts files using strip", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-strip.mjs",+ fixturesPath("esm.mts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from ESM TypeScript!/);+ strictEqual(result.code, 0);+});++test("should work with .mts files using transform", async () => {+ const result = await spawnPromisified(process.execPath, [+ "--no-warnings",+ "--import=./dist/register-transform.mjs",+ fixturesPath("esm.mts"),+ ]);++ strictEqual(result.stderr, "");+ match(result.stdout, /Hello from ESM TypeScript!/);+ strictEqual(result.code, 0);+});