From d3b9dbbd6a4114261951bfae6996df0319ddb106 Mon Sep 17 00:00:00 2001 From: Ivan Kabir Date: Wed, 24 Jul 2024 14:05:34 +0300 Subject: [PATCH 1/2] fix: fix package installation with yarn 4 --- src/constants/packageManagement.ts | 5 ++++- src/package.ts | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/constants/packageManagement.ts b/src/constants/packageManagement.ts index 786ce04..88a9fa0 100644 --- a/src/constants/packageManagement.ts +++ b/src/constants/packageManagement.ts @@ -11,21 +11,24 @@ export const DEFAULT_PM = "npm"; export type PackageManager = "npm" | "yarn" | "pnpm"; -export const PMS: Record = { +export const PMS: Record string }> = { npm: { lock: "package-lock.json", init: "init -y", install: "install --save-dev", + withRegistry: (command, registry) => `${command} --registry ${registry}`, }, yarn: { lock: "yarn.lock", init: "init -y", install: "add -D", + withRegistry: (command, registry) => `export YARN_REGISTRY=${registry} && export YARN_NPM_REGISTRY_SERVER=${registry} && ${command}`, }, pnpm: { lock: "pnpm-lock.yml", init: "init", install: "add --save-dev", + withRegistry: (command, registry) => `${command} --registry ${registry}`, }, }; diff --git a/src/package.ts b/src/package.ts index 1cdcfc8..377a57e 100644 --- a/src/package.ts +++ b/src/package.ts @@ -91,10 +91,9 @@ export const installPackages = async ( const spinner = ora("Installing packages (this may take a while)").start(); const pluginsPackages = pluginsToInstall.map(packageNameFromPlugin).join(" "); - return new Promise((resolve, reject) => { exec( - `${packageManager} ${PMS[packageManager].install} testplane ${pluginsPackages} --registry "${registry}"`, + PMS[packageManager].withRegistry(`${packageManager} ${PMS[packageManager].install} testplane ${pluginsPackages}`, registry), { cwd: dirPath, env: process.env, From 4c7d435bcfc211add438d5adb9da199d37818dd0 Mon Sep 17 00:00:00 2001 From: Ivan Kabir Date: Wed, 24 Jul 2024 14:10:47 +0300 Subject: [PATCH 2/2] refactor: reformat files --- src/constants/packageManagement.ts | 8 ++++++-- src/package.ts | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/constants/packageManagement.ts b/src/constants/packageManagement.ts index 88a9fa0..359c860 100644 --- a/src/constants/packageManagement.ts +++ b/src/constants/packageManagement.ts @@ -11,7 +11,10 @@ export const DEFAULT_PM = "npm"; export type PackageManager = "npm" | "yarn" | "pnpm"; -export const PMS: Record string }> = { +export const PMS: Record< + PackageManager, + { lock: string; init: string; install: string; withRegistry: (command: string, registry: string) => string } +> = { npm: { lock: "package-lock.json", init: "init -y", @@ -22,7 +25,8 @@ export const PMS: Record `export YARN_REGISTRY=${registry} && export YARN_NPM_REGISTRY_SERVER=${registry} && ${command}`, + withRegistry: (command, registry) => + `export YARN_REGISTRY=${registry} && export YARN_NPM_REGISTRY_SERVER=${registry} && ${command}`, }, pnpm: { lock: "pnpm-lock.yml", diff --git a/src/package.ts b/src/package.ts index 377a57e..c79bb68 100644 --- a/src/package.ts +++ b/src/package.ts @@ -93,7 +93,10 @@ export const installPackages = async ( const pluginsPackages = pluginsToInstall.map(packageNameFromPlugin).join(" "); return new Promise((resolve, reject) => { exec( - PMS[packageManager].withRegistry(`${packageManager} ${PMS[packageManager].install} testplane ${pluginsPackages}`, registry), + PMS[packageManager].withRegistry( + `${packageManager} ${PMS[packageManager].install} testplane ${pluginsPackages}`, + registry, + ), { cwd: dirPath, env: process.env,