-
Notifications
You must be signed in to change notification settings - Fork 36
Add build-package patch #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add build-package patch #2194
Changes from all commits
bc1f6c8
f0a6f3a
ac5507b
c601ef1
e812e3a
0173ea8
45f5038
c2f9c2d
bdeb718
57e026a
81fd6d9
2e7685b
b0f47d8
7bb70d9
656d831
a62123b
86b09e7
1906142
dc8098c
3d67fda
a9b9248
782aba1
148a946
431cadd
53a0724
f6058e1
3e4c578
30b6d10
92e8481
26b812d
3c5e661
29a4a42
0c09491
706fa28
c7e02e4
a29c0ab
4a27167
792d385
de3f7a9
117653b
ec643b7
d890add
8d664ac
bb041c9
872ceec
0abebab
f1cb906
4067a91
abfe8ed
0078580
4f61f16
e1bedcd
4c6a861
6a07691
fa5a274
ba5e164
492b311
32ed3db
94d4a56
cc4602f
38aaa77
72fbcff
b62396d
682dc06
4f97399
f25aebc
c45e556
505661d
873d0ef
0b44f66
9446aec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| 'skuba': major | ||
| --- | ||
|
|
||
| build-package: Migrate to tsdown | ||
|
|
||
| As part of our [migration to ESM](https://seek-oss.github.io/skuba/docs/deep-dives/esm.html), we are updating our package build process to support generating both CJS and ESM outputs, regardless of whether projects use CJS or ESM. Since our current tsc-based build does not support this, we are switching to [tsdown](https://tsdown.dev/) for package builds. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| --- | ||
| 'skuba': major | ||
| --- | ||
|
|
||
| lint: Migrate `skuba build-package` usage to use [tsdown](https://tsdown.dev/) for building packages | ||
|
|
||
| This patch will attempt to do a best effort migration of your `skuba build-package` usage to use [tsdown](https://tsdown.dev/) for building packages. This includes: | ||
|
|
||
| 1. Adding a `tsdown.config.mts` file to your package directories with a basic configuration | ||
| 2. Adding a `customConditions` entry to your root `tsconfig.json` file | ||
| 3. Adding `skipLibCheck` to your package `tsconfig.json` files to work around issues with type checking against `tsdown`. | ||
| 4. Updating your package `package.json` files to point to the new build outputs | ||
| 5. Removing redundant `tsconfig.build.json` files | ||
|
|
||
| ## File changes | ||
|
|
||
| The output between what `skuba build-package` generates before and after this change will be different, so you may need to update any references to the output files in your project. | ||
|
|
||
| For example the output for a simple `src/index.ts` file produces the following outputs: | ||
|
|
||
| ```diff | ||
| -lib-commonjs/index.js | ||
| -lib-es2015/index.js | ||
| -lib-types/index.d.ts | ||
| +lib/index.cjs | ||
| +lib/index.mjs | ||
| +lib/index.d.cts | ||
| +lib/index.d.mts | ||
| ``` | ||
|
|
||
| This change may break consumers who directly access these output paths. | ||
|
|
||
| To check if your consumers are affected, search GitHub with: `org:SEEK-Jobs content:"@seek/MY_PACKAGE/"` | ||
|
|
||
| If needed, export those references from your package entry point to help consumers migrate to the new build outputs. | ||
|
|
||
| Note: if you choose to remove the `unbundle: true` option from `tsdown.config.mts`, tsdown may emit bundled/chunked outputs and internal `lib/...` file paths can change between builds. Consumers should avoid importing from build output files directly, and instead import from the package entry point (or explicitly exported sub paths) | ||
|
|
||
| ## Format changes | ||
|
|
||
| `tsdown` selects what ECMAScript target version to build for based on the `engines.node` field in your `package.json`. | ||
|
|
||
| This means that for consumers previously relying on the `lib-es2015` output may need to update their runtime to match your package's `engines.node` field. | ||
|
|
||
| An example changeset you may want to include for a package: | ||
|
|
||
| ````md | ||
| --- | ||
| 'my-package': major | ||
| --- | ||
|
|
||
| Update npm package build outputs | ||
|
|
||
| This release changes published build output paths. If you were previously importing from nested paths within the build output you will need to update imports to use the package entry point (for example, `@seek/my-package`). | ||
|
|
||
| ```diff | ||
| -import type { SomeType } from '@seek/my-package/lib-types/...'; | ||
| +import type { SomeType } from '@seek/my-package'; | ||
| ``` | ||
| ```` | ||
|
|
||
| ## Debugging | ||
|
|
||
| If your project utilises a `main` field which points to a `.ts` file within a monorepo setup, eg. | ||
|
|
||
| ```json | ||
| "main": "src/index.ts", | ||
| ``` | ||
|
|
||
| You may need to create a `moduleNameMapper` entry in your Jest config files to point to the source file, eg. | ||
|
|
||
| ```json | ||
| { | ||
| "moduleNameMapper": { | ||
| "^@seek/my-package": "<rootDir>/packages/my-package/src/index.ts" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This will work natively with custom conditions when we migrate to `vitest` in the future, but is required for Jest to continue working with the new build outputs. | ||
|
|
||
| ```ts | ||
| import { defineConfig } from 'vitest/config'; | ||
|
|
||
| export default defineConfig({ | ||
| ssr: { | ||
| resolve: { | ||
| conditions: ['@seek/my-repo/source'], | ||
| }, | ||
| }, | ||
| }); | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'eslint-plugin-skuba': patch | ||
| --- | ||
|
|
||
| build: Export type declarations |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,37 +84,37 @@ In this example, all `*.vocab/*translations.json` files found within `src` will | |
|
|
||
| ## skuba build-package | ||
|
|
||
| Compiles your project for compatibility with CommonJS and ES2015 modules. | ||
| Compiles your project with [tsdown] to produce CJS, ESM, and type declaration outputs. | ||
|
|
||
| This is useful for building isomorphic npm packages. | ||
|
|
||
| `tsdown` selects what ECMAScript target version to build for based on the `engines.node` field in your `package.json`. | ||
|
|
||
| ```shell | ||
| skuba build-package | ||
|
|
||
| # commonjs │ TSFILE: ... | ||
| # commonjs │ tsc exited with code 0 | ||
| # es2015 │ TSFILE: ... | ||
| # es2015 │ tsc exited with code 0 | ||
| # types │ TSFILE: ... | ||
| # types │ tsc exited with code 0 | ||
| # ℹ entry: src/index.ts | ||
| # ℹ target: node22.14.0 | ||
| # ℹ [CJS] lib/index.cjs | ||
| # ℹ [CJS] lib/index.d.cts | ||
| # ℹ [ESM] lib/index.mjs | ||
| # ℹ [ESM] lib/index.d.mts | ||
| ``` | ||
|
|
||
| `skuba build-package` runs operations concurrently up to your [CPU core count]. | ||
| On a resource-constrained Buildkite agent, | ||
| you can limit this with the `--serial` flag. | ||
| See our [Buildkite guide] for more information. | ||
|
|
||
| To bundle additional assets alongside your package, view the [bundling assets](#bundling-assets) section above. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we replace this with a link on how to |
||
| Assets can be bundled by configuring the [copy] field in the `tsdown.config.mts` file. Depending on your how your application interprets asset paths, the `unbundle` option may need to be set to `true`. | ||
|
|
||
| These files will be copied into the corresponding `lib-commonjs` and `lib-es2015` directories. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this well-intentioned move from So I think we should be very upfront about this change in behaviour, and encourage all package authors to release a new version to the same effect. Maybe we could even provide a little excerpt that they can copy-paste into their changeset 🤔 |
||
| ```ts | ||
| import { defineConfig } from 'tsdown/config'; | ||
|
|
||
| | Option | Description | | ||
| | :--------- | :----------------------------------------------- | | ||
| | `--serial` | Force serial execution of compilation operations | | ||
| export default defineConfig({ | ||
| unbundle: true, | ||
| copy: ['**/*.vocab/*translations.json'], | ||
| }); | ||
| ``` | ||
|
|
||
| [`skuba configure`]: ./configure.md#skuba-configure | ||
| [buildkite guide]: ../deep-dives/buildkite.md | ||
| [compiler option]: https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options | ||
| [cpu core count]: https://nodejs.org/api/os.html#os_os_cpus | ||
| [copy]: https://tsdown.dev/reference/api/Interface.UserConfig#copy | ||
| [esbuild]: ../deep-dives/esbuild.md | ||
| [tsc]: https://www.typescriptlang.org/docs/handbook/compiler-options.html | ||
| [tsdown]: https://tsdown.dev/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| "url": "git+ssh://[email protected]/seek-oss/skuba.git", | ||
| "directory": "packages/api" | ||
| }, | ||
| "license": "MIT", | ||
| "exports": { | ||
| ".": { | ||
| "@seek/skuba/source": "./src/index.ts", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| import { defineConfig } from 'tsdown/config'; | ||
|
|
||
| export default defineConfig({ | ||
| dts: true, | ||
| entry: ['src/index.ts'], | ||
| exports: { | ||
| devExports: '@seek/skuba/source', | ||
| }, | ||
| format: ['cjs', 'esm'], | ||
| outDir: 'lib', | ||
| failOnWarn: false, | ||
| checks: { | ||
| legacyCjs: false, | ||
| }, | ||
| publint: true, | ||
| attw: true, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a good idea of how the output of these outdated targets compare to the modern output that tsdown now gives us? Does it include "good" improvements that are nonetheless a breaking change to the least discerning consumer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, definitely worth a call-out. It reads your
package.jsonengine and sets the format appropriately according to that!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the behaviour if there's no engine set (which is also unfortunately a thing 🥹)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it just preserves the syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're now patching an engine into the package.json if it does not have one