diff --git a/README.md b/README.md index c85b2d0a..b61c224f 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,12 @@ import { createOAuthAppAuth } from "@octokit/auth-oauth-app"; +> [!IMPORTANT] +> 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"`. +> +> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).
+> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus) + ### Authenticate as app ```js diff --git a/scripts/build.mjs b/scripts/build.mjs index 1431e301..02eeb4c8 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -8,6 +8,9 @@ const sharedOptions = { minify: false, allowOverwrite: true, packages: "external", + platform: "neutral", + format: "esm", + target: "es2022", }; async function main() { @@ -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, }); @@ -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: "esm", - ...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"); @@ -74,22 +60,13 @@ async function main() { { ...pkg, files: ["dist-*/**", "bin/**"], - main: "./dist-node/index.js", types: "./dist-types/index.d.ts", exports: { ".": { - node: { - types: "./dist-types/index.d.ts", - import: "./dist-node/index.js", - }, - browser: { - types: "./dist-types/web.d.ts", - import: "./dist-web/index.js", - }, - default: { - types: "./dist-types/index.d.ts", - import: "./dist-node/index.js", - }, + types: "./dist-types/index.d.ts", + import: "./dist-bundle/index.js", + // Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint + default: "./dist-bundle/index.js", }, }, sideEffects: false,