Skip to content

Commit 84f76c8

Browse files
authored
build: Yarn 4 CI hardening (#4028)
* build: run tsc on `prepack` * chore: update. lockfiles on postpack * Revert "chore: update. lockfiles on postpack" This reverts commit 3588cc9. * test * remove hack due to immutable * test again * update deps
1 parent af12ba0 commit 84f76c8

File tree

11 files changed

+1046
-487
lines changed

11 files changed

+1046
-487
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ This guide is for maintainers who have:
146146
- Check that the latest CI run passed on `main` on [GitHub](https://github.com/electron/forge/actions?query=workflow:CI).
147147
- Remove all untracked files and directories from your checkout with `git clean -fdx`.
148148
- Install dependencies with `yarn install`.
149-
- Build packages with `yarn build`.
150149

151150
### 2. Publish all npm packages
152151

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"clean": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && lerna exec -- \"node -e \\\"fs.rmSync('dist', { recursive: true, force: true })\\\" && node -e \\\"fs.rmSync('tsconfig.tsbuildinfo', { recursive: true, force: true })\\\"\"",
1111
"build": "tsc -b packages && ts-node tools/test-dist",
12-
"build:watch": "yarn build --watch",
12+
"build:watch": "tsc -b packages --watch",
1313
"docs": "yarn build && typedoc",
1414
"lerna:publish": "lerna publish --force-publish --conventional-commits --no-changelog --exact",
1515
"lint:js": "prettier --check . --experimental-cli && eslint . --cache",
@@ -18,6 +18,7 @@
1818
"lint:markdown-links": "electron-lint-markdown-links --root . --ignore-path .markdownlintignore \"**/*.md\"",
1919
"lint": "npm run lint:js && npm run lint:markdown && npm run lint:markdown-js && npm run lint:markdown-links",
2020
"lint:fix": "prettier --write . --experimental-cli && eslint --fix . --cache",
21+
"prepack": "yarn build",
2122
"test": "xvfb-maybe vitest run --project fast --project slow",
2223
"test:fast": "xvfb-maybe vitest run --project fast",
2324
"test:slow": "xvfb-maybe vitest run --project slow",
@@ -35,6 +36,8 @@
3536
"@electron/packager": "^18.3.5",
3637
"@electron/rebuild": "^3.7.0",
3738
"@google-cloud/storage": "^7.5.0",
39+
"@inquirer/prompts": "^6.0.1",
40+
"@listr2/prompt-adapter-inquirer": "^2.0.22",
3841
"@malept/cross-spawn-promise": "^2.0.0",
3942
"@octokit/core": "^5.2.1",
4043
"@octokit/plugin-retry": "^6.1.0",

packages/api/core/spec/slow/api.slow.spec.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,15 @@ describe.each([
5353
let dir: string;
5454

5555
beforeAll(async () => {
56+
const originalCorepackStrict = process.env.COREPACK_ENABLE_STRICT;
5657
if (pm.executable === 'pnpm') {
5758
// temporarily disable corepack to enable pnpm to set links
58-
const originalCorepackStrict = process.env.COREPACK_ENABLE_STRICT;
5959
process.env.COREPACK_ENABLE_STRICT = '0';
60-
try {
61-
await spawnPackageManager(
62-
pm,
63-
'config set node-linker hoisted'.split(' '),
64-
);
65-
} finally {
66-
if (originalCorepackStrict === undefined) {
67-
delete process.env.COREPACK_ENABLE_STRICT;
68-
} else {
69-
process.env.COREPACK_ENABLE_STRICT = originalCorepackStrict;
70-
}
71-
}
60+
61+
await spawnPackageManager(
62+
pm,
63+
'config set node-linker hoisted'.split(' '),
64+
);
7265
}
7366

7467
return async () => {
@@ -78,19 +71,14 @@ describe.each([
7871
await spawnPackageManager(pm, ['unlink', '--all']);
7972
} else if (pm.executable === 'pnpm') {
8073
// pnpm doesn't support --all, and requires Corepack bypass
81-
const originalCorepackStrict = process.env.COREPACK_ENABLE_STRICT;
82-
process.env.COREPACK_ENABLE_STRICT = '0';
83-
try {
84-
await spawnPackageManager(pm, ['unlink']);
85-
} finally {
86-
if (originalCorepackStrict === undefined) {
87-
delete process.env.COREPACK_ENABLE_STRICT;
88-
} else {
89-
process.env.COREPACK_ENABLE_STRICT = originalCorepackStrict;
90-
}
91-
}
74+
await spawnPackageManager(pm, ['unlink']);
9275
}
9376
delete process.env.NODE_INSTALLER;
77+
if (originalCorepackStrict === undefined) {
78+
delete process.env.COREPACK_ENABLE_STRICT;
79+
} else {
80+
process.env.COREPACK_ENABLE_STRICT = originalCorepackStrict;
81+
}
9482
};
9583
});
9684

packages/api/core/src/api/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default async ({
8787
title: `Resolving package manager`,
8888
task: async (ctx, task) => {
8989
ctx.pm = await resolvePackageManager();
90-
task.title = `Resolving package manager: ${chalk.cyan(ctx.pm.executable)}`;
90+
task.title = `Resolving package manager: ${chalk.cyan(ctx.pm.executable)} v${ctx.pm.version}`;
9191
},
9292
},
9393
{

packages/template/base/src/BaseTemplate.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,18 @@ export class BaseTemplate implements ForgeTemplate {
140140

141141
const pm = await resolvePackageManager();
142142

143-
// As of pnpm v10, no postinstall scripts will run unless allowlisted through `onlyBuiltDependencies`
144143
if (pm.executable === 'pnpm') {
144+
d('Adding Electron dependencies to `onlyBuiltDependencies`');
145145
packageJSON.pnpm = {
146146
onlyBuiltDependencies: ['electron', 'electron-winstaller'],
147147
};
148+
} else if (
149+
pm.executable === 'yarn' &&
150+
typeof pm.version === 'string' &&
151+
semver.gte(pm.version, '2.0.0')
152+
) {
153+
d('Detected Yarn 2+, adding packageManager field to package.json');
154+
packageJSON.packageManager = `yarn@${pm.version}`;
148155
}
149156

150157
packageJSON.scripts.lint = 'echo "No linting configured"';

packages/template/vite-typescript/spec/ViteTypeScriptTemplate.slow.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,6 @@ describe('ViteTypeScriptTemplate', () => {
7575
// Vite resolves plugins via cwd
7676
cwd = process.cwd();
7777
process.chdir(dir);
78-
// We need the version of vite to match exactly during development due to a quirk in
79-
// typescript type-resolution. In prod no one has to worry about things like this
80-
const pj = JSON.parse(
81-
await fs.promises.readFile(path.resolve(dir, 'package.json'), 'utf-8'),
82-
);
83-
pj.resolutions = {
84-
// eslint-disable-next-line @typescript-eslint/no-require-imports
85-
vite: `${require('../../../../node_modules/vite/package.json').version}`,
86-
};
87-
await fs.promises.writeFile(
88-
path.resolve(dir, 'package.json'),
89-
JSON.stringify(pj),
90-
);
91-
9278
/**
9379
* LOCKFILE FIXTURE USAGE:
9480
* We use a pre-generated lockfile to avoid needing to disable Yarn's security features.

0 commit comments

Comments
 (0)