Skip to content

build: Yarn 4 CI hardening#4028

Merged
erickzhao merged 7 commits intomainfrom
tsc-on-prepack
Oct 11, 2025
Merged

build: Yarn 4 CI hardening#4028
erickzhao merged 7 commits intomainfrom
tsc-on-prepack

Conversation

@erickzhao
Copy link
Member

@erickzhao erickzhao commented Oct 10, 2025

Here are a few follow-up items after #4009.

Building in prepack

As an alternative to #4027, we add the build script to the prepack lifecycle script.

prepack and postpack

Those script are called right at the beginning and the end of each call to yarn pack. They are respectively meant to turn your package from development into production, and cleanup any lingering artifact. For instance, a typical prepack script would call Babel or TypeScript on the source directory to turn .ts files into .js files.

We originally had this under preversion, but that lifecycle script doesn't run anymore after the Yarn 4 upgrade.

Fixing build:watch

The Yarn 4 migration removed the old postbuild script and appended its command to the end of build. build:watch adds the --watch flag to tsc to enable watch mode for the TypeScript build.

We can't just call yarn build --watch anymore due to the added script from postbuild so now build:watch calls the full tsc invocation.

Lockfile fixture hardening

By default, Yarn 4 runs any install in CI with the --immutable flag. This causes problems in our e2e test suite, since we try to yarn install and yarn package within our tests.

The initial Yarn 4 upgrade PR got around this issue by generating lockfile test fixtures for these e2e tests and loading them into the test directory on runtime. However, this trick requires updating these fixtures every time a new release goes out. I tried to do this with the provided update script, but it failed on my machine because it kept generating a Yarn Classic lockfile.

This is because Corepack has global versions of each package manager if the repo doesn't use Corepack. This PR removes the ambiguity by initializing projects with the Yarn 2+ user agent with the correct packageManager entry in package.json.

Note

There are probably a few ways to do this, but being explicit about the package manager version is helpful to have the script run independently of the user's global corepack status.

This also removes some complexity with adding a manual resolution in the same e2e tests (no longer needed due to --immutable installs).

COREPACK_ENABLE_STRICT=0

We were already using COREPACK_ENABLE_STRICT=0 since the Forge repo uses Yarn but we have some tests that run pnpm.

We already had some COREPACK_ENABLE_STRICT workarounds in the tests but this PR disables COREPACK_ENABLE_STRICT for the entirety of the pnpm tests instead of restoring the original value at times.

@erickzhao erickzhao requested a review from a team as a code owner October 10, 2025 07:02
@erickzhao erickzhao requested a review from VerteDinde October 10, 2025 07:03
@VerteDinde VerteDinde enabled auto-merge October 10, 2025 07:04
@VerteDinde VerteDinde added this pull request to the merge queue Oct 10, 2025
@erickzhao erickzhao removed this pull request from the merge queue due to a manual request Oct 10, 2025
@erickzhao erickzhao marked this pull request as draft October 10, 2025 22:51
@erickzhao erickzhao changed the title build: run tsc on prepack build: post-Yarn 4 hardening Oct 11, 2025
@erickzhao erickzhao changed the title build: post-Yarn 4 hardening build: Yarn 4 CI hardening Oct 11, 2025
@erickzhao erickzhao marked this pull request as ready for review October 11, 2025 03:01
Comment on lines +148 to +154
} else if (
pm.executable === 'yarn' &&
typeof pm.version === 'string' &&
semver.gte(pm.version, '2.0.0')
) {
d('Detected Yarn 2+, adding packageManager field to package.json');
packageJSON.packageManager = `yarn@${pm.version}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically a semver patch or minor change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like a fix tbh if it broke before

@erickzhao erickzhao added this pull request to the merge queue Oct 11, 2025
Merged via the queue into main with commit 84f76c8 Oct 11, 2025
14 checks passed
@erickzhao erickzhao deleted the tsc-on-prepack branch October 11, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments