Skip to content

Commit

Permalink
fix: fix package installation with yarn 4 (#38)
Browse files Browse the repository at this point in the history
* fix: fix package installation with yarn 4

* refactor: reformat files
  • Loading branch information
Kabir-Ivan authored Jul 24, 2024
1 parent 499c908 commit 694c6cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/constants/packageManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ export const DEFAULT_PM = "npm";

export type PackageManager = "npm" | "yarn" | "pnpm";

export const PMS: Record<PackageManager, { lock: string; init: string; install: 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",
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}`,
},
};

Expand Down
6 changes: 4 additions & 2 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export const installPackages = async (
const spinner = ora("Installing packages (this may take a while)").start();

const pluginsPackages = pluginsToInstall.map(packageNameFromPlugin).join(" ");

return new Promise<string>((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,
Expand Down

0 comments on commit 694c6cd

Please sign in to comment.