Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add root node_modules to import commands when running pnpm #1482

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 18 additions & 1 deletion packages/cli/src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ function formatFilepath(filepath) {
return filepath;
}

function getSiblings(root) {
const siblings = [path.join(root, '..')];

// if we're in a pnpm package, add the root of the workspace node_modules to the list of siblings
if (root.includes('.pnpm')) {
// Find the index of the first occurrence of '.pnpm'
const nodeModulesIndex = root.indexOf('.pnpm');

// If 'node_modules' is found, extract the substring up to that point
if (nodeModulesIndex !== -1) {
siblings.push(path.join(root.substring(0, nodeModulesIndex), '@percy'));
}
}

return siblings;
}

// Imports and returns compatibile CLI commands from various sources
export async function importCommands() {
let root = path.resolve(url.fileURLToPath(import.meta.url), '../..');
Expand All @@ -109,7 +126,7 @@ export async function importCommands() {
// find included dependencies
root,
// find potential sibling packages
path.join(root, '..'),
...getSiblings(root),
// find any current project dependencies
process.cwd()
]), async (roots, dir) => {
Expand Down
Loading