Skip to content

feat: support custom npmClient and registry (branch next) #249

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions src/cli-scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,16 @@ function formatHrTime(hrtime: any) {
}
return time.toFixed(2) + TIME_UNITS[index];
}

export function getInstallCommand(npmClient: string): string {
switch (npmClient) {
case 'yarn':
case 'bun':
case 'pnpm':
return 'add';

case 'npm':
default:
return 'install';
}
}
18 changes: 15 additions & 3 deletions src/cli-scripts/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { copySync } from 'fs-extra';
import { join, isAbsolute, resolve, relative } from 'path';

import type { TaskInfoProvider, Plugin } from './common';
import { getPlugins, readJSON, resolveElectronPlugin, runExec } from './common';
import { getPlugins, readJSON, resolveElectronPlugin, runExec, getInstallCommand } from './common';

export async function doUpdate(taskInfoMessageProvider: TaskInfoProvider): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -108,11 +108,23 @@ export async function doUpdate(taskInfoMessageProvider: TaskInfoProvider): Promi
usersProjectCapConfigFile = configFileOptions.json;
configFileName = 'capacitor.config.json';
}
copySync(usersProjectCapConfigFile, join(usersProjectDir, 'electron', configFileName), { overwrite: true });

const usersProjectConfigFilePath = join(usersProjectDir, 'electron', configFileName);

copySync(usersProjectCapConfigFile, usersProjectConfigFilePath, { overwrite: true });

if (npmIStr.length > 0) {
taskInfoMessageProvider('installing electron plugin files');
console.log(`\n\nWill install:${npmIStr}\n\n`);
await runExec(`cd ${join(usersProjectDir, 'electron')} && npm i${npmIStr}`);

const config = readJSON(usersProjectConfigFilePath);

const npmClient = config.electron?.npmClient || 'npm';
const installCommand = getInstallCommand(npmClient);
const registryCommand = config.electron?.registry ? ` --registry ${config.electron.registry}` : '';

await runExec(
`cd ${join(usersProjectDir, 'electron')} && ${npmClient} ${installCommand}${npmIStr}${registryCommand}`
);
}
}
2 changes: 2 additions & 0 deletions src/electron-platform/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface ElectronConfig {
backgroundColor?: string;
appId?: string;
appName?: string;
npmClient?: string;
registry?: string;
}

export type CapacitorElectronConfig = CapacitorConfig & {
Expand Down