Skip to content

Commit 9f3ed89

Browse files
authored
fix: prevent esm build global require pollution (#24)
1 parent 1e7dad2 commit 9f3ed89

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

tsup-require-shim.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

tsup.config.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { defineConfig, type Options } from "tsup";
1+
import { defineConfig } from "tsup";
22

3-
const defaultConfig: Options = {
3+
export default defineConfig({
44
entryPoints: ["src/main.ts"],
55
outDir: "dist",
6+
format: ["esm", "cjs"],
67
tsconfig: "./tsconfig.json",
78
target: "es2022",
89
minify: false,
@@ -11,16 +12,10 @@ const defaultConfig: Options = {
1112
minifyIdentifiers: true,
1213
clean: true,
1314
dts: true,
14-
};
15-
16-
export default defineConfig([
17-
{
18-
...defaultConfig,
19-
format: ["esm"],
20-
inject: ['tsup-require-shim.ts']
15+
banner({ format }) {
16+
if (format === "esm") {
17+
return { js: `import { createRequire as __tinyexec_cr } from "node:module";const require = __tinyexec_cr(import.meta.url);` };
18+
}
2119
},
22-
{
23-
...defaultConfig,
24-
format: ["cjs"]
25-
}
26-
]);
20+
});
21+

0 commit comments

Comments
 (0)