diff --git a/src/utils.ts b/src/utils.ts index 2f7a3349..dbd9df8d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -113,6 +113,11 @@ function interopDefault(mod: any): any { const defIsNil = def === null || def === undefined; const defIsObj = defType === "object" || defType === "function"; + if (defIsNil && mod instanceof Promise) { + // Hotfix for #388 + return mod; + } + return new Proxy(mod, { get(target, prop, receiver) { if (prop === "__esModule") { diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 22cf118b..ca4579d5 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -127,5 +127,6 @@ Decorator called with 1 arguments. normalizeUserEntity: [Function: normalizeUserEntity] } } -child" +child +promise resolved" `; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 07652f61..546dac0b 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -47,6 +47,7 @@ describe("fixtures", async () => { ) .replace("internal/errors:496", "events:276") .replace(" ^", " ^") + .replace(/ExperimentalWarning: CommonJS module/, "") // eslint-disable-next-line no-control-regex .replace(/\u001B\[[\d;]*m/gu, "") .trim() diff --git a/test/fixtures/typescript/def-promise.cts b/test/fixtures/typescript/def-promise.cts new file mode 100644 index 00000000..41019023 --- /dev/null +++ b/test/fixtures/typescript/def-promise.cts @@ -0,0 +1,2 @@ +// https://github.com/unjs/jiti/issues/388 +export = Promise.resolve("promise resolved"); diff --git a/test/fixtures/typescript/index.ts b/test/fixtures/typescript/index.ts index 66f44a8a..029c4269 100644 --- a/test/fixtures/typescript/index.ts +++ b/test/fixtures/typescript/index.ts @@ -2,9 +2,12 @@ import test, { type FeedService as _FeedService } from "./test"; import Clazz from "./decorators"; import { test as satisfiesTest } from "./satisfies"; import { child } from "./parent.mjs"; +// @ts-expect-error (needs allowImportingTsExtensions) +import defPromise from "./def-promise.cts"; export type { Test } from "./types"; console.log(test(), Clazz); console.log(satisfiesTest()); console.log(child()); +console.log(await defPromise);