Skip to content
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

feat: support pnpm #3574

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7fd5708
feat: support pnpm and bun
Sep 14, 2023
054382d
chore(ci): install pnpm and bun in circleci
Sep 14, 2023
c1c0bfb
feat: resuse `getInstallDevDepsOption` and `getInstallExactDepsOption…
Sep 15, 2023
f8a6fe9
fix: add `exe-icon-extractor` to fix ci failture on window
Sep 15, 2023
a065e3f
feat: remove support of bun
Sep 15, 2023
b0042e7
fix: remove unnecessary functions and reuse existing logic
Sep 20, 2023
031e7da
chore: remove code for logging
Sep 20, 2023
7076320
test: pnpm workspace
Sep 20, 2023
be36e72
fix: change installer order to fix deps issue
Sep 20, 2023
8e29535
style: yaml
Sep 20, 2023
c31ef7a
feat: package manager checking logic and real user agent data for tes…
Sep 21, 2023
95477e7
Merge branch 'electron:main' into feat/package-manager-support
Oct 8, 2023
4406281
feat: use `detect-package-manager`
Oct 19, 2023
b11d4cd
fix(test): install deps test
Oct 20, 2023
2f92eef
Merge branch 'main' into feat/pnpm-support
goosewobbler Apr 24, 2024
e74eb8c
chore: update lockfiles
goosewobbler Apr 24, 2024
11394f6
Merge remote-tracking branch 'origin/main' into feat/pnpm-support
goosewobbler Apr 24, 2024
caf9878
chore: update lockfile
goosewobbler Apr 24, 2024
f250296
chore: delete package-lock.json
goosewobbler Apr 24, 2024
8ee7126
fix: remove duplicate import
goosewobbler Apr 24, 2024
a98a8a4
fix: TS error
goosewobbler Apr 24, 2024
d334388
fix: linting errors
goosewobbler Apr 24, 2024
cf43b13
Merge branch 'main' into feat/pnpm-support
erickzhao Apr 27, 2024
6eccd7c
chore: add `detect-package-manager`
goosewobbler May 1, 2024
c9d1a68
Merge branch 'main' into feat/pnpm-support
goosewobbler May 2, 2024
aaf8a08
Merge branch 'main' into feat/pnpm-support
goosewobbler May 2, 2024
ad865a2
Merge branch 'main' into feat/pnpm-support
goosewobbler May 3, 2024
8eb86a8
Merge branch 'main' into feat/pnpm-support
goosewobbler May 16, 2024
203705a
debug: add more debugging
goosewobbler Jun 11, 2024
5552124
fix: install devdeps correctly, add debug
goosewobbler Jun 11, 2024
05b43c8
refactor: remove caching as `detect-package-manager` handles this
goosewobbler Jun 11, 2024
21fad0f
fix: `getPackageManager` is async
goosewobbler Jun 11, 2024
af21d3e
fix: slow test issues, add logs
goosewobbler Jun 11, 2024
11e3772
Merge branch 'main' into feat/pnpm-support
goosewobbler Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ commands:
- run: git config --global core.autocrlf input
- node/install:
node-version: '18.15.0'
- run:
name: Install pnpm package manager
command: |
corepack enable
corepack prepare pnpm@latest-8 --activate
- checkout
run-lint-and-build:
steps:
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@
"which": "^2.0.2",
"xterm": "^4.9.0",
"xterm-addon-fit": "^0.5.0",
"xterm-addon-search": "^0.8.0",
"yarn-or-npm": "^3.0.1"
"xterm-addon-search": "^0.8.0"
goosewobbler marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@electron/fuses": ">=1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-make.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { api, MakeOptions } from '@electron-forge/core';
import { initializeProxy } from '@electron/get';
import { api, MakeOptions } from '@electron-forge/core';
import program from 'commander';
import fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-package.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { api, PackageOptions } from '@electron-forge/core';
import { initializeProxy } from '@electron/get';
import { api, PackageOptions } from '@electron-forge/core';
import program from 'commander';
import fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-publish.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { api, PublishOptions } from '@electron-forge/core';
import { initializeProxy } from '@electron/get';
import { api, PublishOptions } from '@electron-forge/core';
import program from 'commander';
import fs from 'fs-extra';

Expand Down
12 changes: 9 additions & 3 deletions packages/api/cli/src/util/check-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ function warnIfPackageManagerIsntAKnownGoodVersion(packageManager: string, versi
}

async function checkPackageManagerVersion() {
const version = await forgeUtils.yarnOrNpmSpawn(['--version']);
const version = await forgeUtils.packageManagerSpawn(['--version']);
const versionString = version.toString().trim();
if (forgeUtils.hasYarn()) {
const _isNpm = await forgeUtils.isNpm();
const _isYarn = await forgeUtils.isYarn();
if (_isYarn) {
warnIfPackageManagerIsntAKnownGoodVersion('Yarn', versionString, YARN_ALLOWLISTED_VERSIONS);
return `yarn@${versionString}`;
} else {
} else if (_isNpm) {
warnIfPackageManagerIsntAKnownGoodVersion('NPM', versionString, NPM_ALLOWLISTED_VERSIONS);
return `npm@${versionString}`;
} else {
// I think we don't need to check version of pnpm since 2023
const pm = await forgeUtils.getPackageManager();
return `${pm}@${versionString}`;
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/api/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
"semver": "^7.2.1",
"source-map-support": "^0.5.13",
"sudo-prompt": "^9.1.1",
"username": "^5.1.0",
"yarn-or-npm": "^3.0.1"
"username": "^5.1.0"
},
"engines": {
"node": ">= 16.4.0"
Expand Down
12 changes: 6 additions & 6 deletions packages/api/core/src/api/import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { safeYarnOrNpm, updateElectronDependency } from '@electron-forge/core-utils';
import { getPackageManager, updateElectronDependency } from '@electron-forge/core-utils';
import { ForgeListrOptions, ForgeListrTaskFn } from '@electron-forge/shared-types';
import baseTemplate from '@electron-forge/template-base';
import { autoTrace } from '@electron-forge/tracer';
Expand Down Expand Up @@ -193,23 +193,23 @@ export default autoTrace(
{
title: 'Installing dependencies',
task: async (_, task) => {
const packageManager = safeYarnOrNpm();
const packageManager = getPackageManager();
await writeChanges();

d('deleting old dependencies forcefully');
await fs.remove(path.resolve(dir, 'node_modules/.bin/electron'));
await fs.remove(path.resolve(dir, 'node_modules/.bin/electron.cmd'));

d('installing dependencies');
task.output = `${packageManager} install ${importDeps.join(' ')}`;
task.output = `${packageManager} add ${importDeps.join(' ')}`;
await installDepList(dir, importDeps);

d('installing devDependencies');
task.output = `${packageManager} install --dev ${importDevDeps.join(' ')}`;
task.output = `${packageManager} add -D ${importDevDeps.join(' ')}`;
await installDepList(dir, importDevDeps, DepType.DEV);

d('installing exactDevDependencies');
task.output = `${packageManager} install --dev --exact ${importExactDevDeps.join(' ')}`;
task.output = `${packageManager} add -D -E ${importExactDevDeps.join(' ')}`;
await installDepList(dir, importExactDevDeps, DepType.DEV, DepVersionRestriction.EXACT);
},
},
Expand Down Expand Up @@ -257,7 +257,7 @@ export default autoTrace(
},
task: childTrace<Parameters<ForgeListrTaskFn>>({ name: 'finalize-import', category: '@electron-forge/core' }, (_, __, task) => {
task.output = `We have attempted to convert your app to be in a format that Electron Forge understands.

Thanks for using ${chalk.green('Electron Forge')}!`;
}),
},
Expand Down
22 changes: 16 additions & 6 deletions packages/api/core/src/api/init-scripts/init-link.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { safeYarnOrNpm, yarnOrNpmSpawn } from '@electron-forge/core-utils';
import { getPackageManager, isPnpm, packageManagerSpawn } from '@electron-forge/core-utils';
import { ForgeListrTask } from '@electron-forge/shared-types';
import debug from 'debug';

Expand All @@ -22,14 +22,24 @@ export async function initLink<T>(dir: string, task?: ForgeListrTask<T>) {
if (shouldLink) {
d('Linking forge dependencies');
const packageJson = await readRawPackageJson(dir);
const packageManager = safeYarnOrNpm();
const packageManager = getPackageManager();
const linkFolder = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', '.links');
for (const packageName of Object.keys(packageJson.devDependencies)) {
if (packageName.startsWith('@electron-forge/')) {
if (task) task.output = `${packageManager} link --link-folder ${linkFolder} ${packageName}`;
await yarnOrNpmSpawn(['link', '--link-folder', linkFolder, packageName], {
cwd: dir,
});
if (task) {
const _isPnpm = await isPnpm();
if (_isPnpm) {
task.output = `${packageManager} link ${linkFolder}/${packageName}`;
await packageManagerSpawn(['link', `${linkFolder}/${packageName}`], {
cwd: dir,
});
} else {
task.output = `${packageManager} link --link-folder ${linkFolder} ${packageName}`;
await packageManagerSpawn(['link', '--link-folder', linkFolder, packageName], {
cwd: dir,
});
}
}
}
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions packages/api/core/src/api/init-scripts/init-npm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { safeYarnOrNpm } from '@electron-forge/core-utils';
import { getPackageManager } from '@electron-forge/core-utils';
import { ForgeListrTask } from '@electron-forge/shared-types';
import debug from 'debug';
import fs from 'fs-extra';
Expand Down Expand Up @@ -29,17 +29,17 @@ export const exactDevDeps = ['electron'];

export const initNPM = async <T>(dir: string, task: ForgeListrTask<T>): Promise<void> => {
d('installing dependencies');
const packageManager = safeYarnOrNpm();
task.output = `${packageManager} install ${deps.join(' ')}`;
const packageManager = getPackageManager();
task.output = `${packageManager} add ${deps.join(' ')}`;
await installDepList(dir, deps);

d('installing devDependencies');
task.output = `${packageManager} install --dev ${deps.join(' ')}`;
task.output = `${packageManager} add -D ${deps.join(' ')}`;
await installDepList(dir, devDeps, DepType.DEV);

d('installing exact devDependencies');
for (const packageName of exactDevDeps) {
task.output = `${packageManager} install --dev --exact ${packageName}`;
task.output = `${packageManager} add -D -E ${packageName}`;
await installDepList(dir, [packageName], DepType.DEV, DepVersionRestriction.EXACT);
}
};
8 changes: 4 additions & 4 deletions packages/api/core/src/api/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { safeYarnOrNpm } from '@electron-forge/core-utils';
import { getPackageManager } from '@electron-forge/core-utils';
import { ForgeTemplate } from '@electron-forge/shared-types';
import debug from 'debug';
import { Listr } from 'listr2';
Expand Down Expand Up @@ -56,7 +56,7 @@ async function validateTemplate(template: string, templateModule: ForgeTemplate)
export default async ({ dir = process.cwd(), interactive = false, copyCIFiles = false, force = false, template = 'base' }: InitOptions): Promise<void> => {
d(`Initializing in: ${dir}`);

const packageManager = safeYarnOrNpm();
const packageManager = getPackageManager();

const runner = new Listr<{
templateModule: ForgeTemplate;
Expand Down Expand Up @@ -103,7 +103,7 @@ export default async ({ dir = process.cwd(), interactive = false, copyCIFiles =
task: async (_, task) => {
d('installing dependencies');
if (templateModule.dependencies?.length) {
task.output = `${packageManager} install ${templateModule.dependencies.join(' ')}`;
task.output = `${packageManager} add ${templateModule.dependencies.join(' ')}`;
}
return await installDepList(dir, templateModule.dependencies || [], DepType.PROD, DepVersionRestriction.RANGE);
},
Expand All @@ -114,7 +114,7 @@ export default async ({ dir = process.cwd(), interactive = false, copyCIFiles =
task: async (_, task) => {
d('installing devDependencies');
if (templateModule.devDependencies?.length) {
task.output = `${packageManager} install --dev ${templateModule.devDependencies.join(' ')}`;
task.output = `${packageManager} add -D ${templateModule.devDependencies.join(' ')}`;
}
await installDepList(dir, templateModule.devDependencies || [], DepType.DEV);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';

import { getHostArch } from '@electron/get';
import { getElectronVersion } from '@electron-forge/core-utils';
import { MakerBase } from '@electron-forge/maker-base';
import {
Expand All @@ -13,7 +14,6 @@ import {
ResolvedForgeConfig,
} from '@electron-forge/shared-types';
import { autoTrace, delayTraceTillSignal } from '@electron-forge/tracer';
import { getHostArch } from '@electron/get';
import chalk from 'chalk';
import filenamify from 'filenamify';
import fs from 'fs-extra';
Expand Down Expand Up @@ -294,7 +294,7 @@ export const listrMake = (
arch: targetArch,
});
} catch (err) {
if (err) {
if (err instanceof Error) {
throw err;
} else {
throw new Error(`An unknown error occurred while making for target: ${uniqMaker.name}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/api/package.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path';
import { promisify } from 'util';

import { getHostArch } from '@electron/get';
import { FinalizePackageTargetsHookFunction, HookFunction, Options, packager, TargetDefinition } from '@electron/packager';
import { getElectronVersion, listrCompatibleRebuildHook } from '@electron-forge/core-utils';
import { ForgeArch, ForgeListrTask, ForgeListrTaskDefinition, ForgeListrTaskFn, ForgePlatform, ResolvedForgeConfig } from '@electron-forge/shared-types';
import { autoTrace, delayTraceTillSignal } from '@electron-forge/tracer';
import { getHostArch } from '@electron/get';
import { FinalizePackageTargetsHookFunction, HookFunction, Options, packager, TargetDefinition } from '@electron/packager';
import chalk from 'chalk';
import debug from 'debug';
import glob from 'fast-glob';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/util/forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const proxify = <T extends ProxiedObject>(buildIdentifier: string | (() => strin
const envValue = process.env[`${envPrefix}_${underscoreCase(name)}`];
if (envValue) return envValue;
}
const value = Reflect.get(target, name, receiver);
const value = Reflect.get(target, name, receiver) as BuildIdentifierConfig<string>;

if (value && typeof value === 'object' && value.__isMagicBuildIdentifierMap) {
const identifier = typeof buildIdentifier === 'function' ? buildIdentifier() : buildIdentifier;
Expand Down
12 changes: 9 additions & 3 deletions packages/api/core/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getElectronVersion, hasYarn, yarnOrNpmSpawn } from '@electron-forge/core-utils';
import { getElectronVersion, getPackageManager, isNpm, isPnpm, isYarn, packageManagerSpawn } from '@electron-forge/core-utils';

import { BuildIdentifierConfig, BuildIdentifierMap, fromBuildIdentifier } from './forge-config';

Expand All @@ -16,7 +16,13 @@ export default class ForgeUtils {

getElectronVersion = getElectronVersion;

hasYarn = hasYarn;
getPackageManager = getPackageManager;

yarnOrNpmSpawn = yarnOrNpmSpawn;
packageManagerSpawn = packageManagerSpawn;

isNpm = isNpm;

isYarn = isYarn;

isPnpm = isPnpm;
}
34 changes: 21 additions & 13 deletions packages/api/core/src/util/install-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasYarn, yarnOrNpmSpawn } from '@electron-forge/core-utils';
import { isNpm, isPnpm, isYarn, packageManagerSpawn } from '@electron-forge/core-utils';
import { ExitError } from '@malept/cross-spawn-promise';
import debug from 'debug';

Expand All @@ -15,24 +15,32 @@ export enum DepVersionRestriction {
}

export default async (dir: string, deps: string[], depType = DepType.PROD, versionRestriction = DepVersionRestriction.RANGE): Promise<void> => {
d('installing', JSON.stringify(deps), 'in:', dir, `depType=${depType},versionRestriction=${versionRestriction},withYarn=${hasYarn()}`);
const _isNpm = await isNpm();
const _isYarn = await isYarn();
const _isPnpm = await isPnpm();
d(
'installing',
JSON.stringify(deps),
'in:',
dir,
`depType=${depType},versionRestriction=${versionRestriction}},withNpm=${_isNpm},withYarn=${_isYarn},withPnpm=${_isPnpm}`
);
if (deps.length === 0) {
d('nothing to install, stopping immediately');
return Promise.resolve();
}
let cmd = ['install'].concat(deps);
if (hasYarn()) {
cmd = ['add'].concat(deps);
if (depType === DepType.DEV) cmd.push('--dev');
if (versionRestriction === DepVersionRestriction.EXACT) cmd.push('--exact');
} else {
if (versionRestriction === DepVersionRestriction.EXACT) cmd.push('--save-exact');
if (depType === DepType.DEV) cmd.push('--save-dev');
if (depType === DepType.PROD) cmd.push('--save');
}
/**
* To install the specified packages as dependencies
* yarn and pnpm use `add` command
* npm use `add` as an alias command of `install`
* for consistency, we use `add` command here
*/
const cmd = ['add'].concat(deps);
if (depType === DepType.DEV) cmd.push('-D');
if (versionRestriction === DepVersionRestriction.EXACT) cmd.push('-E');
d('executing', JSON.stringify(cmd), 'in:', dir);
try {
await yarnOrNpmSpawn(cmd, {
await packageManagerSpawn(cmd, {
cwd: dir,
stdio: 'pipe',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/util/parse-archs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ForgeArch, ForgePlatform } from '@electron-forge/shared-types';
import { allOfficialArchsForPlatformAndVersion, SupportedPlatform } from '@electron/packager';
import { ForgeArch, ForgePlatform } from '@electron-forge/shared-types';

export default function parseArchs(platform: ForgePlatform | string, declaredArch: ForgeArch | 'all' | string, electronVersion: string): ForgeArch[] {
if (declaredArch === 'all') {
Expand Down
Loading