Skip to content

Commit

Permalink
CI: Work around a weird bug in Yarn v1.x
Browse files Browse the repository at this point in the history
Certain repositories need node-gyp in order to build their native
C/C++ dependencies. Yarn has some mechanism to detect this.
I believe the ppm repo is detected as one of these special repos.

This detection happens during the 'yarn install' command's package
lifecyle script handling code, by the way. This is important later.

Yarn also has logic to detect if node-gyp is globally available on the
system, in the form of a specific 'bin/node-gyp-bin' subdirectory of
the npm package. Well, npm as of version 9.7.2 and newer has deleted
this 'bin/node-gyp-bin' sub-directory.

(NodeJS 18.18.0 and newer, as well as NodeJS 20.4.0 and newer,
bundle new enough npm to be affected by this change.)

Okay, so we are now two layers deep into edge cases.
You're still following along okay, I hope?

In this double edge case, Yarn installs its own copy of node-gyp, in a
Yarn-specific global packages dir. This works, in and of itself, but
after it installs this copy of node-gyp, Yarn doesn't properly hand
back off to the rest of its package lifecycle script handler.

So, we are left with a mostly successful repo install, minus this
repo's all-important postinstall lifecycle script ever running.

Yeah, this bug breaks ppm repo.

It's easy to work around IRL: Just run 'yarn install' again, or run
'yarn postinstall'. The copy of node-gyp Yarn successfully globally
installed means this is a one-time issue only for IRL machines.

Ths real problem is in CI, where every runner is spun up fresh or each
CI run. We need a proper workaround for CI. Hence this commit.

So here we are.

A comically complex chain of events in the NodeJS ecosystem (and to be
fair, the non-maintenance for bug-fixes of Yarn v1.x) have lead to
a skipped postinstall script in our ppm repo (and presumably in
certain other repos), if using Yarn v1.x with npm 9.7.2 or newer
installed as the global copy of npm. (As opposed to with an older
version of npm being the globally installed copy of npm,
which still works fine.)

This breaks the repo.

This commit works around it. But we should probably switch to Yarn 2.x
or newer, AKA "Yarn Berry", soon if we can.
  • Loading branch information
DeeDeeG committed Oct 23, 2023
1 parent 21faba9 commit 0da4676
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ jobs:
check-latest: true

- name: Install dependencies
run: yarn install
run: |
# Yarn v1.x needs global node-gyp available if npm 9.7.2+ is the global version,
# or else postinstall scripts for this repo won't run. It's a long story. And it's a "won't fix" bug in Yarn v1.x.
yarn global add node-gyp@9.4.0
yarn install
- if: "!contains(matrix.os, 'windows')"
name: Run tests 👩🏾‍💻
Expand Down

0 comments on commit 0da4676

Please sign in to comment.