Skip to content

Commit

Permalink
Fix esm imports in cjs (close #557)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Mar 22, 2023
1 parent 3535f6b commit 1d9aef0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ esbuild:
}
}
// if the dependency is an es module without `default` export, then use star import
if !marked && depNpm.Module != "" {
if !marked && depNpm.Module != "" && !depESM.ExportDefault {
cjsImports.Add("*")
marked = true
}
Expand Down
16 changes: 10 additions & 6 deletions test/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function startServer(onStart: () => void, single: boolean) {
stderr: "inherit",
});
addEventListener("unload", (e) => {
console.log("closing esm.sh server...");
console.log("%cClosing esm.sh server...", "color: grey");
p.kill("SIGINT");
});
while (true) {
Expand Down Expand Up @@ -57,7 +57,7 @@ async function runTest(name: string, retry?: boolean): Promise<number> {
Deno.exit(code);
}
}
return Date.now() - execBegin
return Date.now() - execBegin;
}

async function runCliTest() {
Expand Down Expand Up @@ -142,18 +142,22 @@ async function existsFile(path: string): Promise<boolean> {
if (import.meta.main) {
const [testDir] = Deno.args;
startServer(async () => {
let spentTimeCount = 0;
let timeUsed = 0;
if (testDir) {
spentTimeCount += await runTest(testDir, true);
timeUsed += await runTest(testDir, true);
} else {
await runCliTest();
for await (const entry of Deno.readDir("./test")) {
if (entry.isDirectory && !entry.name.startsWith("_")) {
spentTimeCount += await runTest(entry.name);
timeUsed += await runTest(entry.name);
}
}
}
console.log(`Done! Total time spent: ${spentTimeCount}`);
timeUsed = Math.ceil(timeUsed / 1000);
console.log(
`Done! Total time spent: %c${Math.floor(timeUsed / 60)}m${timeUsed}s`,
"color: blue",
);
Deno.exit(0);
}, Boolean(testDir));
}
7 changes: 7 additions & 0 deletions test/issue-557/issue-557.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";

import Asciidoctor from "http://localhost:8080/[email protected]";

Deno.test("issue #557", () => {
assertEquals(typeof Asciidoctor, "function");
});

0 comments on commit 1d9aef0

Please sign in to comment.