Skip to content

build: upgrade to Lerna 9 and Yarn 4 - #4009

Merged
georgexu99 merged 26 commits into
mainfrom
gxu-yarn-upgrade
Oct 9, 2025
Merged

build: upgrade to Lerna 9 and Yarn 4#4009
georgexu99 merged 26 commits into
mainfrom
gxu-yarn-upgrade

Conversation

@georgexu99

@georgexu99 georgexu99 commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

This PR upgrades Yarn to v4, and Lerna to v9.

This sets the stage for configuring trusted publishing on npm.

Yarn upgrades

Yarn Berry comes with a few important upgrades:

Disables lifecycle scripts to minimize chance of supply chain security attacks (with allowlist)
Adds cooldown time for dependencies to reduce chance of supply chain security attacks (set to 1 week)
Built-in yarn patch command means we can get rid of patch-package
Yarn version is now on a per-workspace basis instead of installed globally

Lerna v9

  • The versions of node supported by lerna are now ^20.19.0 || ^22.12.0 || >=24.0.0.
  • support OIDC trusted publishing (d51e344)

Workarounds

  • moved assetrelocator test to a temp directory to avoid yarn shenanigans

@georgexu99
georgexu99 requested a review from a team as a code owner September 25, 2025 19:26
@socket-security

socket-security Bot commented Sep 25, 2025

Copy link
Copy Markdown

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@georgexu99

Copy link
Copy Markdown
Contributor Author

tests won't pass until lerna v9 reaches 7 day release maturity

Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread packages/template/webpack-typescript/package.json
Comment thread .yarnrc.yml Outdated
Comment thread .yarnrc.yml Outdated
@erickzhao

Copy link
Copy Markdown
Member

Also there seems to be a lockfile update required:

➤ YN0000: Yarn detected that the current workflow is executed from a public pull request. For safety the hardened mode has been enabled.
➤ YN0000: It will prevent malicious lockfile manipulations, in exchange for a slower install time. You can opt-out if necessary; check our documentation for more details.

➤ YN0000: · Yarn 4.10.2
➤ YN0000: ┌ Resolution step
Resolution step
➤ YN0000: └ Completed in 11s 677ms
➤ YN0000: ┌ Post-resolution validation
Post-resolution validation
➤ YN0028: -  resolution: "@electron-forge/template-fixture@file:./spec/fixture/electron-forge-template-fixture#./spec/fixture/electron-forge-template-fixture::hash=1aaf8d&locator=%40electron-forge%2Fcore%40workspace%3Apackages%2Fapi%2Fcore"
➤ YN0028: -  checksum: 10c0/1fe8a48bb01714be15ab86101675e52440d7dc6b55d7e3ecc0e7ffd790c64d03355afd452742cf1b89640ca0208cb4761a5c38bbbcb7965eb82953bffea48d1e
➤ YN0028: +  resolution: "@electron-forge/template-fixture@file:./spec/fixture/electron-forge-template-fixture#./spec/fixture/electron-forge-template-fixture::hash=3dc1fb&locator=%40electron-forge%2Fcore%40workspace%3Apackages%2Fapi%2Fcore"
➤ YN0028: -  resolution: "electron-forge-template-fixture-two@file:./spec/fixture/electron-forge-template-fixture#./spec/fixture/electron-forge-template-fixture::hash=b40bee&locator=%40electron-forge%2Fcore%40workspace%3Apackages%2Fapi%2Fcore"
➤ YN0028: -  checksum: 10c0/d54e6c7d5c0d060647043f9d704a1a2138248d324d4271b494b06d4ee9d403056b7c33f53065db78989744f7e157f51948c070ccdaf93f23117f1518e71ee08b
➤ YN0028: +  resolution: "electron-forge-template-fixture-two@file:./spec/fixture/electron-forge-template-fixture#./spec/fixture/electron-forge-template-fixture::hash=f3bac0&locator=%40electron-forge%2Fcore%40workspace%3Apackages%2Fapi%2Fcore"
➤ YN0028: The lockfile would have been modified by this install, which is explicitly forbidden.
➤ YN0000: └ Completed
➤ YN0000: · Failed with errors in 11s 806ms

Comment thread .yarnrc.yml
Comment thread package.json Outdated
'..',
'.links',
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

to resolve linking issues, we must custom retrieve each workspace's path and link them with yarn 4 syntax

@georgexu99
georgexu99 requested a review from erickzhao October 7, 2025 18:25
Comment thread .github/workflows/ci.yml Outdated
'.links',
);

const getWorkspacePath = (packageName: string): string => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I hate how much extra work we have to do with Yarn 4 to make linking our packages is... but if it works, it works. 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep i hate this too

Comment thread packages/external/create-electron-app/package.json
const mainOut = path.join(appPath, '.webpack/main');

beforeAll(async () => {
await fs.promises.mkdir(appPath, { recursive: true });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you explain a bit what the root cause of the test failures was that caused this refactor?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the assetrelocator patch test creates a webpack project and tests that webpack assets are in the right place once built- the test ran npm install inside a fixture directory inside the forge monorepo, which caused yarn to lock it down and fail the test as it required native module builds (native-hello-world).

This beforeAll moves the fixture to a temp directory outside the monorepo so it can run without yarn's configuration policies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love bypassing the yarn policies in yarnrc.yml, can we do the same lockfile trick here and use a pre-generated one? (Similar to what you did below)

Comment thread .yarnrc.yml
Comment thread .prettierignore Outdated
Comment thread package.json Outdated
@erickzhao erickzhao changed the title chore: add support for trusted oidc publishing build: upgrade to Lerna 9 and Yarn 4 Oct 7, 2025
@erickzhao

Copy link
Copy Markdown
Member

@SocketSecurity ignore npm/init-package-json@8.2.2

This is a package maintained by npm and there's no suspicious activity on the package itself.

env: {
...process.env,
YARN_ENABLE_HARDENED_MODE: '0',
YARN_ENABLE_IMMUTABLE_INSTALLS: '0',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unsafe, we shouldn't do it

env: {
...process.env,
YARN_ENABLE_HARDENED_MODE: '0',
YARN_ENABLE_IMMUTABLE_INSTALLS: '0',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unsafe, we shouldn't do it

Comment thread package.json Outdated
"update:lockfile-fixtures": "ts-node tools/regenerate-lockfile-fixtures.ts",
"postinstall": "node -e \"try { fs.rmSync('node_modules/.bin/*.ps1', { recursive: true, force: true }) } catch (e) {}\" && ts-node ./tools/gen-tsconfigs.ts && ts-node ./tools/gen-ts-glue.ts",
"prepare": "husky install",
"preversion": "yarn build"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does preversion still work in Yarn 4? I don't see it documented anymore: https://yarnpkg.com/cli/version

Comment thread tools/regenerate-lockfile-fixtures.ts Outdated
Comment on lines +79 to +80
YARN_ENABLE_HARDENED_MODE: '0',
YARN_ENABLE_IMMUTABLE_INSTALLS: '0',

@erickzhao erickzhao Oct 8, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we remove these flags now that the expectation is that the developer runs this update script locally?

@georgexu99
georgexu99 force-pushed the gxu-yarn-upgrade branch 3 times, most recently from a77319b to ba56129 Compare October 8, 2025 22:56
georgexu99 and others added 11 commits October 8, 2025 16:16
- Remove unnecessary packages from npmPreapprovedPackages in .yarnrc.yml
- Change node engine requirement from ^16.4.0 to >=16.4.0

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
- Add macos-alias to npmPreapprovedPackages to enable native volume.node compilation on macOS
- Replace file: protocol with link: protocol for test fixtures to avoid platform-dependent hashes
- This should fix DMG maker tests and eliminate hash mismatch errors in CI

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
The macos-alias package contains native modules that need to be rebuilt
for the current Node.js version in CI. This was causing test failures on
macOS runners when running tests that use the DMG maker.
…neration script

The script is meant to be run locally by developers who don't have immutable installs enabled by default. Removing these overrides makes the script cleaner and doesn't disable security features unnecessarily.

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking solid, left some clean up notes, a neat trick, and one ask RE lockfile stuff

'.links',
);

const getWorkspacePath = (packageName: string): string => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This whole thing can be replaced with a sick oneliner -->

yarn workspace @electron-forge/package-name exec pwd

Comment thread packages/api/core/src/api/init-scripts/init-link.ts Outdated
Comment thread packages/api/core/src/api/init-scripts/init-link.ts Outdated
const mainOut = path.join(appPath, '.webpack/main');

beforeAll(async () => {
await fs.promises.mkdir(appPath, { recursive: true });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love bypassing the yarn policies in yarnrc.yml, can we do the same lockfile trick here and use a pre-generated one? (Similar to what you did below)

Comment thread package.json Outdated
Comment thread package.json
Comment on lines +153 to +158
"@bitdisaster/exe-icon-extractor": {
"built": true
},
"electron-winstaller": {
"built": true
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@erickzhao can we take action items somewhere to make these not require building. Seems strange to me

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I made of note of in Slack but I'll create a separate GitHub issue for it as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@georgexu99

Copy link
Copy Markdown
Contributor Author

#4009 (comment)
@MarshallOfSound

I think the test specifically uses npm to test what we're recommending users to use in the forge docs (npm). I can meet you in the middle, how about we use npm ci rather than npm install so we're not generating a new lockfile.

@georgexu99
georgexu99 added this pull request to the merge queue Oct 9, 2025
Merged via the queue into main with commit 7b4a4c0 Oct 9, 2025
11 checks passed
@georgexu99
georgexu99 deleted the gxu-yarn-upgrade branch October 9, 2025 19:06
@yilihjy

yilihjy commented Oct 10, 2025

Copy link
Copy Markdown

@georgexu99 @MarshallOfSound @erickzhao hello , #4026 Some bad things have happened after this merge.

@notion-workspace

Copy link
Copy Markdown

forge

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.

4 participants