Skip to content

Commit 868e61d

Browse files
authored
fix: updated ionic start to update lock files when the --no-deps arg is passed (#4706)
1 parent 7c49d5c commit 868e61d

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

packages/@ionic/cli/src/commands/start.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,17 @@ Use the ${input('--type')} option to start projects using older versions of Ioni
592592

593593
const [installer, ...installerArgs] = await pkgManagerArgs(this.env.config.get('npmClient'), { command: 'install' });
594594
await this.env.shell.run(installer, installerArgs, shellOptions);
595+
} else {
596+
// --no-deps flag was used so skip installing dependencies, but update the lock file so that it's in sync with the package.json
597+
this.env.log.msg('Updating lockfile.');
598+
if (this.env.config.get('npmClient') === 'yarn') {
599+
// Yarn doesn't have an out of the box way to update the lock file without performing an install so warn the user that the lockfile might be out of date
600+
this.env.log.warn('Unable to update `yarn.lock` without installing dependencies. `yarn.lock` may be out of sync.');
601+
} else {
602+
// Perform an install that updates the lockfile without installing dependencies.
603+
const [installer, ...installerArgs] = await pkgManagerArgs(this.env.config.get('npmClient'), { command: 'install', lockFileOnly: true });
604+
await this.env.shell.run(installer, installerArgs, shellOptions);
605+
}
595606
}
596607

597608
if (!this.schema.cloned) {

packages/@ionic/cli/src/lib/utils/__tests__/npm.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ describe('@ionic/cli', () => {
7777
expect(result).toEqual(['npm', 'info', '@ionic/cli', '--json']);
7878
});
7979

80+
it('should include lockFileOnly flag', async () => {
81+
const result = await pkgManagerArgs('npm', { command: 'install', lockFileOnly: true });
82+
expect(result).toEqual(['npm', 'i', '--package-lock-only']);
83+
});
84+
8085
describe('yarn', () => {
8186

8287
jest.resetModules();
@@ -229,6 +234,10 @@ describe('@ionic/cli', () => {
229234
expect(result).toEqual(['pnpm', 'info', '@ionic/cli', '--json']);
230235
});
231236

237+
it('should include lockFileOnly flag', async () => {
238+
const result = await pkgManagerArgs('pnpm', { command: 'install', lockFileOnly: true });
239+
expect(result).toEqual(['pnpm', 'install', '--lockfile-only']);
240+
});
232241
});
233242

234243
});

packages/@ionic/cli/src/lib/utils/npm.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface PkgManagerVocabulary {
1818
saveDev: string;
1919
saveExact: string;
2020
nonInteractive: string;
21+
lockFileOnly: string;
2122
}
2223

2324
export type PkgManagerCommand = 'dedupe' | 'rebuild' | 'install' | 'uninstall' | 'run' | 'info';
@@ -32,6 +33,7 @@ export interface PkgManagerOptions {
3233
saveDev?: boolean;
3334
saveExact?: boolean;
3435
json?: boolean;
36+
lockFileOnly?: boolean;
3537
}
3638

3739
/**
@@ -78,16 +80,16 @@ export async function pkgManagerArgs(npmClient: NpmClient, options: PkgManagerOp
7880

7981
switch (npmClient) {
8082
case 'npm':
81-
vocab = { run: 'run', install: 'i', bareInstall: 'i', uninstall: 'uninstall', dedupe: 'dedupe', rebuild: 'rebuild', global: '-g', save: '--save', saveDev: '-D', saveExact: '-E', nonInteractive: '' };
83+
vocab = { run: 'run', install: 'i', bareInstall: 'i', uninstall: 'uninstall', dedupe: 'dedupe', rebuild: 'rebuild', global: '-g', save: '--save', saveDev: '-D', saveExact: '-E', nonInteractive: '', lockFileOnly: '--package-lock-only' };
8284
break;
8385
case 'yarn':
84-
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'install', global: '', save: '', saveDev: '--dev', saveExact: '--exact', nonInteractive: '--non-interactive' };
86+
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'install', global: '', save: '', saveDev: '--dev', saveExact: '--exact', nonInteractive: '--non-interactive', lockFileOnly: '' };
8587
if (options.global) { // yarn installs packages globally under the 'global' prefix, instead of having a flag
8688
installerArgs.push('global');
8789
}
8890
break;
8991
case 'pnpm':
90-
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'rebuild', global: '--global', save: '', saveDev: '--save-dev', saveExact: '--save-exact', nonInteractive: '' };
92+
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'rebuild', global: '--global', save: '', saveDev: '--save-dev', saveExact: '--save-exact', nonInteractive: '', lockFileOnly: '--lockfile-only' };
9193
break;
9294
default:
9395
throw new Error(`unknown installer: ${npmClient}`);
@@ -99,6 +101,9 @@ export async function pkgManagerArgs(npmClient: NpmClient, options: PkgManagerOp
99101
} else {
100102
installerArgs.push(vocab.bareInstall);
101103
}
104+
if (options.lockFileOnly) {
105+
installerArgs.push(vocab.lockFileOnly)
106+
}
102107
} else if (cmd === 'uninstall') {
103108
installerArgs.push(vocab.uninstall);
104109
} else if (cmd === 'dedupe') {

0 commit comments

Comments
 (0)