Skip to content

Commit 9604674

Browse files
authored
fix(build): actually output ESM (#2678)
1 parent c99ff62 commit 9604674

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"license": "MIT",
1515
"scripts": {
1616
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
17-
"lint": "prettier --check \"{src,test}/**/*.{js,json,ts}\" \"*.{md,json}\"",
18-
"lint:fix": "prettier --write \"{src,test}/**/*.{js,json,ts}\" \"*.{md,json}\"",
17+
"lint": "prettier --check \"{src,test,scripts}/**/*.{js,json,ts}\" \"*.{md,json}\"",
18+
"lint:fix": "prettier --write \"{src,test,scripts}/**/*.{js,json,ts,mjs}\" \"*.{md,json}\"",
1919
"pretest": "npm run -s lint",
2020
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --coverage",
2121
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --module node16 --strict --allowImportingTsExtensions test/typescript-validate.ts"

Diff for: scripts/build.mjs

+20-29
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const sharedOptions = {
1212
minify: false,
1313
allowOverwrite: true,
1414
packages: "external",
15+
platform: "neutral",
16+
format: "esm",
17+
target: "es2022",
1518
};
1619

1720
async function main() {
@@ -22,8 +25,6 @@ async function main() {
2225
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
2326
outdir: "pkg/dist-src",
2427
bundle: false,
25-
platform: "neutral",
26-
format: "esm",
2728
...sharedOptions,
2829
sourcemap: false,
2930
});
@@ -39,27 +40,13 @@ async function main() {
3940

4041
const entryPoints = ["./pkg/dist-src/index.js"];
4142

42-
await Promise.all([
43-
// Build the a CJS Node.js bundle
44-
esbuild.build({
45-
entryPoints,
46-
outdir: "pkg/dist-node",
47-
bundle: true,
48-
platform: "node",
49-
target: "node18",
50-
format: "cjs",
51-
...sharedOptions,
52-
}),
53-
// Build an ESM browser bundle
54-
esbuild.build({
55-
entryPoints,
56-
outdir: "pkg/dist-web",
57-
bundle: true,
58-
platform: "browser",
59-
format: "esm",
60-
...sharedOptions,
61-
}),
62-
]);
43+
// Build an ESM bundle
44+
await esbuild.build({
45+
entryPoints,
46+
outdir: "pkg/dist-bundle",
47+
bundle: true,
48+
...sharedOptions,
49+
});
6350

6451
// Copy the README, LICENSE to the pkg folder
6552
await copyFile("LICENSE", "pkg/LICENSE");
@@ -78,15 +65,19 @@ async function main() {
7865
{
7966
...pkg,
8067
files: ["dist-*/**", "bin/**"],
81-
main: "dist-node/index.js",
82-
module: "dist-web/index.js",
83-
types: "dist-types/index.d.ts",
84-
source: "dist-src/index.js",
68+
types: "./dist-types/index.d.ts",
69+
exports: {
70+
".": {
71+
types: "./dist-types/index.d.ts",
72+
import: "./dist-bundle/index.js",
73+
default: "./dist-bundle/index.js",
74+
},
75+
},
8576
sideEffects: false,
8677
},
8778
null,
88-
2
89-
)
79+
2,
80+
),
9081
);
9182
}
9283
main();

0 commit comments

Comments
 (0)