Skip to content

Commit

Permalink
fix: actually output only ESM (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Mar 8, 2024
1 parent 56abe9e commit f725158
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"pretest": "npm run -s lint && npm run build",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict test/typescript-validate.ts",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --module node16 --moduleResolution node16 test/typescript-validate.ts",
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch",
"test:e2e": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --testRegex test/*.e2e.ts"
},
Expand Down Expand Up @@ -59,7 +59,8 @@
]
},
"coveragePathIgnorePatterns": [
"./test/testHelpers"
"./test/testHelpers",
"./pkg"
],
"coverageThreshold": {
"global": {
Expand Down
36 changes: 11 additions & 25 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const sharedOptions = {
minify: false,
allowOverwrite: true,
packages: "external",
platform: "neutral",
format: "esm",
target: "es2022",
};

async function main() {
Expand All @@ -18,8 +21,6 @@ async function main() {
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
outdir: "pkg/dist-src",
bundle: false,
platform: "neutral",
format: "esm",
...sharedOptions,
sourcemap: false,
});
Expand All @@ -35,27 +36,12 @@ async function main() {

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

await Promise.all([
// Build the a CJS Node.js bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node18",
format: "cjs",
...sharedOptions,
}),
// Build an ESM browser bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-web",
bundle: true,
platform: "browser",
format: "esm",
...sharedOptions,
}),
]);
await esbuild.build({
entryPoints,
outdir: "pkg/dist-bundle",
bundle: true,
...sharedOptions,
});

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
Expand All @@ -74,12 +60,12 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
main: "dist-bundle/index.js",
types: "dist-types/index.d.ts",
exports: {
".": {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
import: "./dist-bundle/index.js",
}
},
sideEffects: false,
Expand Down
7 changes: 7 additions & 0 deletions test/smoke.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { paginateGraphQL } from "../pkg/dist-bundle/index.js";

describe("Test package exports", () => {
it("should export the paginateGraphQL function", () => {
expect(paginateGraphQL).toBeInstanceOf(Function);
});
});

0 comments on commit f725158

Please sign in to comment.