fix(cli): link and unlink extensions/modes with pnpm instead of yarn (#6144)

This commit is contained in:
Alireza 2026-07-14 19:10:49 -04:00 committed by GitHub
parent b880d2acf9
commit 125a174298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 23 deletions

View File

@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
import { execa } from 'execa'; import { execa } from 'execa';
import { keywords } from './enums/index.js'; import { keywords } from './enums/index.js';
import { validateYarn, addExtensionToConfig, addModeToConfig } from './utils/index.js'; import { validatePnpm, addExtensionToConfig, addModeToConfig } from './utils/index.js';
async function linkPackage(packageDir, options, addToConfig, keyword) { async function linkPackage(packageDir, options, addToConfig, keyword) {
const { viewerDirectory } = options; const { viewerDirectory } = options;
@ -22,19 +22,18 @@ async function linkPackage(packageDir, options, addToConfig, keyword) {
const version = packageJSON.version; const version = packageJSON.version;
// make sure yarn is installed // make sure pnpm is installed
await validateYarn(); await validatePnpm();
// change directory to packageDir and execute yarn link // resolve the package directory before changing the working directory
process.chdir(packageDir); const resolvedPackageDir = path.resolve(packageDir);
let results; // change directory to the OHIF Platform root and link the local package there.
results = await execa(`yarn`, ['link']); // Linking mutates the lockfile, so disable the workspace's frozen-lockfile
// default for this call (pnpm link rejects --no-frozen-lockfile).
// change directory to OHIF Platform root and execute yarn link
process.chdir(`${viewerDirectory}/../..`); process.chdir(`${viewerDirectory}/../..`);
results = await execa(`yarn`, ['link', packageName]); let results = await execa('pnpm', ['link', resolvedPackageDir, '--config.frozen-lockfile=false']);
console.log(results.stdout); console.log(results.stdout);
// Add the node_modules of the linked package so that webpack // Add the node_modules of the linked package so that webpack
@ -63,7 +62,7 @@ async function linkPackage(packageDir, options, addToConfig, keyword) {
}); });
// run prettier on the webpack config // run prettier on the webpack config
results = await execa(`yarn`, ['prettier', '--write', webpackPwaPath]); results = await execa('pnpm', ['exec', 'prettier', '--write', webpackPwaPath]);
} }
function linkExtension(packageDir, options) { function linkExtension(packageDir, options) {

View File

@ -1,18 +1,20 @@
import { execa } from 'execa'; import { execa } from 'execa';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { validateYarn, removeExtensionFromConfig, removeModeFromConfig } from './utils/index.js'; import { validatePnpm, removeExtensionFromConfig, removeModeFromConfig } from './utils/index.js';
const linkPackage = async (packageName, options, removeFromConfig) => { const linkPackage = async (packageName, options, removeFromConfig) => {
const { viewerDirectory } = options; const { viewerDirectory } = options;
// make sure yarn is installed // make sure pnpm is installed
await validateYarn(); await validatePnpm();
// change directory to OHIF Platform root and execute yarn link // change directory to the OHIF Platform root, where the package was linked.
process.chdir(viewerDirectory); // Unlinking mutates the lockfile, so disable the workspace's frozen-lockfile
// default for this call (pnpm unlink rejects --no-frozen-lockfile).
process.chdir(`${viewerDirectory}/../..`);
const results = await execa(`yarn`, ['unlink', packageName]); const results = await execa('pnpm', ['unlink', packageName, '--config.frozen-lockfile=false']);
console.log(results.stdout); console.log(results.stdout);
const webpackPwaPath = path.join(viewerDirectory, '.webpack', 'webpack.pwa.js'); const webpackPwaPath = path.join(viewerDirectory, '.webpack', 'webpack.pwa.js');
@ -23,7 +25,7 @@ const linkPackage = async (packageName, options, removeFromConfig) => {
removeFromConfig(packageName); removeFromConfig(packageName);
// run prettier on the webpack config // run prettier on the webpack config
await execa(`yarn`, ['prettier', '--write', webpackPwaPath]); await execa('pnpm', ['exec', 'prettier', '--write', webpackPwaPath]);
}; };
async function removePathFromWebpackConfig(webpackConfigPath, packageName) { async function removePathFromWebpackConfig(webpackConfigPath, packageName) {

View File

@ -19,7 +19,7 @@ import editPackageJson from './editPackageJson.js';
import createLicense from './createLicense.js'; import createLicense from './createLicense.js';
import createReadme from './createReadme.js'; import createReadme from './createReadme.js';
import prettyPrint from './prettyPrint.js'; import prettyPrint from './prettyPrint.js';
import validateYarn from './validateYarn.js'; import validatePnpm from './validatePnpm.js';
export { export {
getYarnInfo, getYarnInfo,
@ -43,5 +43,5 @@ export {
createLicense, createLicense,
createReadme, createReadme,
prettyPrint, prettyPrint,
validateYarn, validatePnpm,
}; };

View File

@ -1,12 +1,12 @@
import chalk from 'chalk'; import chalk from 'chalk';
import { execa } from 'execa'; import { execa } from 'execa';
export default async function validateYarn() { export default async function validatePnpm() {
try { try {
await execa('yarn', ['--version']); await execa('pnpm', ['--version']);
} catch (err) { } catch (err) {
console.log( console.log(
'%s Yarn is not installed, please install it before linking your extension', '%s pnpm is not installed, please install it before linking your extension',
chalk.red.bold('ERROR') chalk.red.bold('ERROR')
); );
process.exit(1); process.exit(1);