Skip to content

Commit 479d617

Browse files
authored
fix(pkg): only build one bundle and add default fallback export (#442)
* fix(pkg): simplify build Remove distinct Node/Browser builds * fix(pkg): add a default fallback export * docs: add note on needed config changes for TypeScript * style: prettier
1 parent fc0a9cb commit 479d617

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
6666
</tbody>
6767
</table>
6868

69+
> [!IMPORTANT]
70+
> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`.
71+
>
72+
> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>
73+
> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)
74+
6975
### Authenticate as app
7076

7177
```js

scripts/build.mjs

Lines changed: 13 additions & 36 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: "esm",
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,22 +60,13 @@ async function main() {
7460
{
7561
...pkg,
7662
files: ["dist-*/**", "bin/**"],
77-
main: "./dist-node/index.js",
7863
types: "./dist-types/index.d.ts",
7964
exports: {
8065
".": {
81-
node: {
82-
types: "./dist-types/index.d.ts",
83-
import: "./dist-node/index.js",
84-
},
85-
browser: {
86-
types: "./dist-types/web.d.ts",
87-
import: "./dist-web/index.js",
88-
},
89-
default: {
90-
types: "./dist-types/index.d.ts",
91-
import: "./dist-node/index.js",
92-
},
66+
types: "./dist-types/index.d.ts",
67+
import: "./dist-bundle/index.js",
68+
// Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint
69+
default: "./dist-bundle/index.js",
9370
},
9471
},
9572
sideEffects: false,

0 commit comments

Comments
 (0)