Skip to content

Commit f725158

Browse files
authored
fix: actually output only ESM (#178)
1 parent 56abe9e commit f725158

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1111
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1212
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
13-
"pretest": "npm run -s lint",
13+
"pretest": "npm run -s lint && npm run build",
1414
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
15-
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict test/typescript-validate.ts",
15+
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --module node16 --moduleResolution node16 test/typescript-validate.ts",
1616
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch",
1717
"test:e2e": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --testRegex test/*.e2e.ts"
1818
},
@@ -59,7 +59,8 @@
5959
]
6060
},
6161
"coveragePathIgnorePatterns": [
62-
"./test/testHelpers"
62+
"./test/testHelpers",
63+
"./pkg"
6364
],
6465
"coverageThreshold": {
6566
"global": {

scripts/build.mjs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const sharedOptions = {
88
minify: false,
99
allowOverwrite: true,
1010
packages: "external",
11+
platform: "neutral",
12+
format: "esm",
13+
target: "es2022",
1114
};
1215

1316
async function main() {
@@ -18,8 +21,6 @@ async function main() {
1821
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
1922
outdir: "pkg/dist-src",
2023
bundle: false,
21-
platform: "neutral",
22-
format: "esm",
2324
...sharedOptions,
2425
sourcemap: false,
2526
});
@@ -35,27 +36,12 @@ async function main() {
3536

3637
const entryPoints = ["./pkg/dist-src/index.js"];
3738

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

6046
// Copy the README, LICENSE to the pkg folder
6147
await copyFile("LICENSE", "pkg/LICENSE");
@@ -74,12 +60,12 @@ async function main() {
7460
{
7561
...pkg,
7662
files: ["dist-*/**", "bin/**"],
77-
main: "dist-node/index.js",
63+
main: "dist-bundle/index.js",
7864
types: "dist-types/index.d.ts",
7965
exports: {
8066
".": {
8167
types: "./dist-types/index.d.ts",
82-
import: "./dist-node/index.js",
68+
import: "./dist-bundle/index.js",
8369
}
8470
},
8571
sideEffects: false,

test/smoke.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { paginateGraphQL } from "../pkg/dist-bundle/index.js";
2+
3+
describe("Test package exports", () => {
4+
it("should export the paginateGraphQL function", () => {
5+
expect(paginateGraphQL).toBeInstanceOf(Function);
6+
});
7+
});

0 commit comments

Comments
 (0)