From 36ed9dabb6e16043a342543a7032eb3554017837 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 15 Apr 2024 20:27:06 -0400 Subject: [PATCH 1/5] docs: add note on needed config changes for TypeScript --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 779c6f15..9044eb77 100644 --- a/README.md +++ b/README.md @@ -672,6 +672,9 @@ In addition to these types, `@octokit/webhooks` exports 2 types specific to itse Note that changes to the exported types are not considered breaking changes, as the changes will not impact production code, but only fail locally or during CI at build time. +> [!IMPORTANT] +> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json`. See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports). + **⚠️ Caution ⚠️**: Webhooks Types are expected to be used with the [`strictNullChecks` option](https://www.typescriptlang.org/tsconfig#strictNullChecks) enabled in your `tsconfig`. If you don't have this option enabled, there's the possibility that you get `never` as the inferred type in some use cases. See [octokit/webhooks#395](https://github.com/octokit/webhooks/issues/395) for details. ### `EmitterWebhookEventName` From c223c9989c50f15752cb74174470337b82cf02ec Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 15 Apr 2024 20:55:26 -0400 Subject: [PATCH 2/5] fix(build): simplify builds --- scripts/build.mjs | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 4b151d4f..705490d1 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.md", "pkg/LICENSE.md"); @@ -73,8 +59,8 @@ async function main() { { ...pkg, files: ["dist-*/**", "bin/**"], - main: "dist-node/index.js", - browser: "dist-web/index.js", + types: "dist-types/index.d.ts", + main: "dist-bundle/index.js", types: "dist-types/index.d.ts", module: "dist-src/index.js", sideEffects: false, From d5ea5648f9f07542b1a1278126c6a5b5a09a87fe Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 15 Apr 2024 20:56:09 -0400 Subject: [PATCH 3/5] fix(pkg): use `exports` in `package.json` --- scripts/build.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 705490d1..e4f87ca2 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -60,8 +60,14 @@ async function main() { ...pkg, files: ["dist-*/**", "bin/**"], types: "dist-types/index.d.ts", - main: "dist-bundle/index.js", - types: "dist-types/index.d.ts", + exports: { + ".": { + 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", + }, + }, module: "dist-src/index.js", sideEffects: false, }, From db0561ba7ab1e060b800811538cad82f8ebd5c35 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 15 Apr 2024 21:09:29 -0400 Subject: [PATCH 4/5] style: prettier --- scripts/build.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index e4f87ca2..ec10a401 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -10,7 +10,7 @@ const sharedOptions = { packages: "external", platform: "neutral", format: "esm", - target: "es2022" + target: "es2022", }; async function main() { From ae69b861aae325992980f349d2de4119975d6bc3 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Tue, 16 Apr 2024 14:11:02 -0400 Subject: [PATCH 5/5] docs: update info on typescript config --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7aeacdf..5b11c06e 100644 --- a/README.md +++ b/README.md @@ -673,7 +673,10 @@ In addition to these types, `@octokit/webhooks` exports 2 types specific to itse Note that changes to the exported types are not considered breaking changes, as the changes will not impact production code, but only fail locally or during CI at build time. > [!IMPORTANT] -> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json`. See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports). +> 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) **⚠️ Caution ⚠️**: Webhooks Types are expected to be used with the [`strictNullChecks` option](https://www.typescriptlang.org/tsconfig#strictNullChecks) enabled in your `tsconfig`. If you don't have this option enabled, there's the possibility that you get `never` as the inferred type in some use cases. See [octokit/webhooks#395](https://github.com/octokit/webhooks/issues/395) for details.