Skip to content

Commit bfda6e9

Browse files
committed
Add error handler for npm pkg set
1 parent e2f0fbf commit bfda6e9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/create-config/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const getPackageManager = () => {
3535
return 'npm';
3636
};
3737

38+
const getBinX = pm => {
39+
if (pm === 'npm') return 'npx';
40+
return pm;
41+
};
42+
3843
const getWorkspaceFlag = pm => {
3944
if (pm === 'pnpm') {
4045
return fileExists('pnpm-workspace.yaml') ? '-w' : undefined;
@@ -63,10 +68,14 @@ const main = () => {
6368
execSync(cmd, { stdio: 'inherit' });
6469
console.info('✓ Install Knip');
6570

66-
execSync('npm pkg set scripts.knip=knip', { stdio: 'inherit' });
67-
console.info('✓ Add knip to package.json#scripts');
68-
69-
console.info(`✓ Run "${bin} run knip" to run knip`);
71+
try {
72+
execSync('npm pkg set scripts.knip=knip', { stdio: 'inherit' });
73+
console.info('✓ Add knip to package.json#scripts');
74+
console.info(`→ Run "${bin} run knip" to run knip`);
75+
} catch {
76+
console.warn('× Failed to add knip to package.json#scripts');
77+
console.info(`→ Run "${getBinX(bin)} knip" to run knip`);
78+
}
7079
};
7180

7281
main();

0 commit comments

Comments
 (0)