Skip to content
Open
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
35 changes: 17 additions & 18 deletions utils/src/remove-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync } from 'node:child_process';
import { spawn } from 'node:child_process';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth adding some unit tests with JSSG? (both to confirm the execSync error and the expected spawn behaviour`?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in next pr, because now it's just a patch. also codemod team propose to use json ast on package.json to remove dep & then run install command. I'm going to explore that.

import { existsSync, readFileSync, writeFileSync } from 'node:fs';

/**
Expand Down Expand Up @@ -91,24 +91,23 @@ function detectPackageManager(): 'npm' | 'yarn' | 'pnpm' {
function runPackageManagerInstall(
packageManager: 'npm' | 'yarn' | 'pnpm',
): void {
try {
console.log(`Running ${packageManager} install to update dependencies...`);

switch (packageManager) {
case 'npm':
execSync('npm install', { stdio: 'inherit' });
break;
case 'yarn':
execSync('yarn install', { stdio: 'inherit' });
break;
case 'pnpm':
execSync('pnpm install', { stdio: 'inherit' });
break;
}
console.log(`Running ${packageManager} install to update dependencies...`);

console.log(`Successfully updated dependencies with ${packageManager}`);
} catch (error) {
const command = packageManager;
const args = ['install'];

const child = spawn(command, args, { stdio: 'inherit' });

child.on('error', (error) => {
console.error(`Error running ${packageManager} install:`, error);
// Don't throw - dependency removal was successful, install failure shouldn't break the codemod
}
});

child.on('close', (code) => {
if (code === 0) {
console.log(`Successfully updated dependencies with ${packageManager}`);
} else {
console.error(`${packageManager} install exited with code ${code}`);
}
});
}
Loading