Skip to content

Commit

Permalink
Add support for pnpm (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mheob authored Dec 6, 2022
1 parent 0827f89 commit 8961529
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"url": "https://github.com/go-task/go-npm.git"
},
"homepage": "https://github.com/go-task/go-npm",
"dependencies": {
"used-pm": "^1.0.0"
},
"devDependencies": {
"esbuild": "^0.12.17",
"jest": "^24.5.0",
Expand Down
7 changes: 7 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { join } = require('path');
const { exec } = require('child_process');
const { existsSync, readFileSync } = require('fs');
const mkdirp = require('mkdirp');
const usedPM =require('used-pm');

// Mapping from Node's `process.arch` to Golang's `$GOARCH`
const ARCH_MAPPING = {
Expand Down Expand Up @@ -33,10 +34,16 @@ function getInstallationPath(callback) {
// Ex: /Users/foo/.nvm/versions/node/v4.3.0
const env = process.env;

// Get the package manager who is running the script
// This is needed since PNPM works in a different way than NPM or YARN.
const packageManager = usedPM();

if (env && env.npm_config_prefix) {
dir = join(env.npm_config_prefix, 'bin');
} else if (env && env.npm_config_local_prefix) {
dir = join(env.npm_config_local_prefix, join('node_modules', '.bin'));
} else if (packageManager.name.toLowerCase() === 'pnpm') {
dir = join(process.cwd(), 'node_modules', '.bin');
} else {
return callback(new Error('Error finding binary installation directory'));
}
Expand Down

0 comments on commit 8961529

Please sign in to comment.