Skip to content

Commit 9e0a6d9

Browse files
authored
fix: use yarn install if no modules to add (#1346)
1 parent b7478bf commit 9e0a6d9

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/main/npm.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ export async function addModules(
5757
...names: Array<string>
5858
): Promise<string> {
5959
let nameArgs: Array<string> = [];
60+
let installCommand: string;
6061

6162
if (packageManager === 'npm') {
63+
installCommand = 'npm install';
6264
nameArgs = names.length > 0 ? ['-S', ...names] : ['--also=dev --prod'];
6365
} else {
66+
installCommand = names.length > 0 ? 'yarn add' : 'yarn install';
6467
nameArgs = [...names];
6568
}
6669

67-
const installCommand = packageManager === 'npm' ? 'npm install' : 'yarn add';
68-
6970
return exec(dir, [installCommand].concat(nameArgs).join(' '));
7071
}
7172

src/renderer/runner.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,13 @@ export class Runner {
483483
* @memberof Runner
484484
*/
485485
public async packageInstall(options: PMOperationOptions): Promise<boolean> {
486+
const pm = options.packageManager;
486487
try {
487-
this.appState.pushOutput(`Now running "npm install..."`);
488+
this.appState.pushOutput(`Now running "${pm} install..."`);
488489
this.appState.pushOutput(await window.ElectronFiddle.addModules(options));
489490
return true;
490491
} catch (error) {
491-
this.appState.pushError('Failed to run "npm install".', error);
492+
this.appState.pushError(`Failed to run "${pm} install".`, error);
492493
}
493494

494495
return false;

tests/main/npm-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('npm', () => {
158158
it('attempts to installs all modules', async () => {
159159
addModules({ dir: '/my/directory', packageManager: 'yarn' });
160160

161-
expect(exec).toHaveBeenCalledWith<any>('/my/directory', 'yarn add');
161+
expect(exec).toHaveBeenCalledWith<any>('/my/directory', 'yarn install');
162162
});
163163
});
164164
});

0 commit comments

Comments
 (0)