diff --git a/src/resolver.ts b/src/resolver.ts index 7750c81..9e1b896 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -31,6 +31,11 @@ interface NpmResolvedInfo { npmPackage: string; } +interface ExternalResolvedInfo { + kind: "external"; + specifier: string; +} + interface ResolveError { specifier: string; error: string; @@ -40,7 +45,9 @@ interface DenoInfoJsonV1 { version: 1; redirects: Record; roots: string[]; - modules: Array; + modules: Array< + NpmResolvedInfo | ResolvedInfo | ExternalResolvedInfo | ResolveError + >; } export interface DenoResolveResult { @@ -51,7 +58,7 @@ export interface DenoResolveResult { } function isResolveError( - info: NpmResolvedInfo | ResolvedInfo | ResolveError, + info: NpmResolvedInfo | ResolvedInfo | ExternalResolvedInfo | ResolveError, ): info is ResolveError { return "error" in info && typeof info.error === "string"; } @@ -118,6 +125,9 @@ export async function resolveDeno( loader: null, dependencies: [], }; + } else if (mod.kind === "external") { + // Let vite handle this + return null; } throw new Error(`Unsupported: ${JSON.stringify(mod, null, 2)}`); diff --git a/tests/fixture/inlineExternal.ts b/tests/fixture/inlineExternal.ts new file mode 100644 index 0000000..553c0ba --- /dev/null +++ b/tests/fixture/inlineExternal.ts @@ -0,0 +1,5 @@ +import * as helper from "\0vite/preload-helper.js"; + +if (helper !== undefined) { + console.log("it works"); +} diff --git a/tests/fixture/vite.config.ts b/tests/fixture/vite.config.ts index 64686c6..30abf8a 100644 --- a/tests/fixture/vite.config.ts +++ b/tests/fixture/vite.config.ts @@ -12,6 +12,7 @@ export default defineConfig({ importMapNpm: "npm.ts", importMapJsr: "jsr.ts", importMapHttp: "http.ts", + inlineExternal: "inlineExternal.ts", inlineNpm: "inlineNpm.ts", inlineJsr: "inlineJsr.ts", inlineHttp: "inlineHttp.ts", diff --git a/tests/plugin.test.ts b/tests/plugin.test.ts index 5b95f66..dec1957 100644 --- a/tests/plugin.test.ts +++ b/tests/plugin.test.ts @@ -41,6 +41,10 @@ describe("Deno plugin", () => { }); describe("inline", () => { + it("resolves external:", async () => { + await runTest(`inlineExternal.js`); + }); + it("resolves npm:", async () => { await runTest(`inlineNpm.js`); });