-
Notifications
You must be signed in to change notification settings - Fork 451
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
fix: upgrade to @sanity/pkg-utils
v5 and use updated ESM best practices
#5983
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/@sanity/[email protected], npm/@sanity/[email protected], npm/@sanity/[email protected], npm/@sanity/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected] |
5020cde
to
c5eb92c
Compare
No changes to documentation |
Component Testing Report Updated Apr 8, 2024 9:36 PM (UTC)
|
c5eb92c
to
c03bbb7
Compare
c03bbb7
to
cea05c9
Compare
cea05c9
to
1856525
Compare
1856525
to
77290e9
Compare
@sanity/pkg-utils
v5 and use updated ESM best practices
77290e9
to
b2b9eb1
Compare
b2b9eb1
to
de4c97e
Compare
de4c97e
to
69728b6
Compare
e510973
to
9a0e28f
Compare
9a0e28f
to
2a5cd07
Compare
93130c7
to
a5e1623
Compare
Description
This PR started off as a mission to update all packages to
@sanity/pkg-utils
v5
, and implement its updated best practices:.d.ts
that fully pass publint.dev (@sanity/ui
before / after) and Are the types wrong? (@sanity/ui
before / after) while still supporting generating legacy exports (thelegacyExports: true
setting inpackage.config
, see@sanity/client
for an example that only ship modern code).5.4
and make use of the newmodule: "Preserve"
option.exports[*].types
conditions as they are now generated following TSC file ending conventions that fully supports the newcustomConditions
feature inmoduleResolution: "Bundler"
.However it turned out that
@sanity/tsdoc
was on@sanity/pkg-utils
v2, and on TS v5.1. Upgrading@sanity/tsdoc
to v5.4 and fully support the changes in pkg-utils v5 was a significant effort.Upgrading the monorepo to be able to use
module: "Preserve"
was also easier said than done, due to the usage ofreferences
and the large amount of spread outtsconfig.json
files. Thus the monorepo is updated to followturbo
andpnpm
best practices for using@repo
prefixed packages for sharedtsconfig.json
settings, as well as the basepackage.config.ts
file.What to review
module: "Preserve"
(deep dive on what it means) which makes TS typecheck with support forpackage.json
export
conditions, and checking that npm packages work with Node.js in native ESM mode, modern CJS mode, and how bundlers (like@sanity/pkg-utils
) expects you to write import statements.moduleResolution: "Bundler"
mode, which is enabled by default when usingmodule: "Preserve"
. I'm not super familiar witheslint-plugin-import
, so I'm not sure if this is the best way to do this, but it seems to work.pnpm build
locally is set tooutputMode: 'new-only'
, this makes it much less noisy. While the CI uses--output-logs=full --log-order=grouped
to allow viewing the full logs on GitHub Actions. This means that when you runpnpm build
you'll only see the build log for packages that weren't cached, try it and let me know if it's confusing or makes sense.tsconfig.json
andtsconfig.lib.json
now extends@repo/tsconfig/monorepo.json
and@repo/tsconfig/base.
package.config.ts
that used to be on the root level is moved to./packages/@repo/tsconfig
and./packages/@repo/package.config
. The@repo
namespace is a convention inturborepo
projects for when you have packages that shouldn't be published tonpm
, and when you don't want to use package names that could collide with actual npm packages. The main benefit of private workspaces is that they "just work" with tooling likepnpm
andturbo
(no need to specifyglobalDependencies
inturbo.json
for them).tsc
check if anycompilerOptions.paths
options are missing requiredinclude
statements, or if they're pointing to non-existing files.pre*
andpost*
scripts out of the box, thepostbuild
andprebuild
scripts have been refactored. Theprebuild
script now runs duringbuild
, a future version of@sanity/pkg-utils
will add the ability torimraf
youroutDir
automatically and we'll be able to removerun-s clean &&
frombuild
scripts. Thepostbuild
script is replaced with acheck:types
command.pnpm dev
,pnpm test
, and editing files in your IDE should see typings without first having to runpnpm build
to generate.d.ts
files. This can be tested by runningbuild:clean
to remove any generated output from a previouspnpm build
run.references
has been replaced withpaths
. For an IDE like VS Code the performance should be the same, whiletsc
cli is slower. You should be able to edit any files indev/**/*
orpackages/**/*
and see typings for any package (like@sanity/types
,sanity
) without having to runpnpm build
first.pnpm build:types
command is replaced withpnpm check:types
, test it and see if its output makes sense. It'll truncate the output unless there's type errors. To see the full output you can runpnpm check:types --output-logs=full
.pnpm check:package
command that works aspnpm build
, but with@sanity/pkg-utils
output validation ensuring that files thatpackage.json
are pointing to exists on the filesystem. This is howpnpm build
used to work before we started usingturbo run build
, as lerna would runpostbuild
scripts. The fact thatpostbuild
haven't been running since we moved to turborepo managed to slip under the radar. It's generally not necessary to runpnpm check:package
locally since the CI handles it, but it's useful when setting up new packages, or adding/removing exports.Testing
references
is replaced withpaths
and causingtsc
to be much slower thepnpm build:dts
command is replaced with a turborepo-enabledpnpm check:types
command. It's not necessary to run this locally in the day-to-day as the CIType check
action will run this for you. SincerootDir: "."
is used it also makes sure that allpaths
intsconfig.json
files are correct and up to date, ensuring that someone doesn't accidentally rely onpnpm build
generating typings for all monorepo packages to be able to type check.Type check
CI action is updated to also run thecheck:types
command, which used to be run aspostbuild
scripts on each package that uses@sanity/pkg-utils
to bundle.Notes for release
Masquerading as CJS
and ESM type errors.mjs
exports for full support of Node.js' native ESM mode, while still oferring.esm.js
exports for legacy bundlers supportsideEffects: false
conditions topackage.json
files, improving tree-shaking and reducing bundle sizes for embedded Sanity Studio projects