Open elliot-nelson opened 12 months ago
You should just be able to use the rush-pnpm
link
command: https://pnpm.io/cli/link
You should just be able to use the
rush-pnpm
link
command: https://pnpm.io/cli/link
@dmichon-msft i couldn't get rush-pnpm link to work
I did pnpm link --global
in the package (outside monorepo) folder.
I then did rush-pnpm link --global package-name
inside the folder consuming the package in the monorepo.
I then did rush update
per instructions.
But every time, the package installed is from npm and not from local package.
Summary
An issue we've encountered in our repo is that we are consuming a package that lives outside the repo, and sometimes we need to test out a potential update to that package locally.
We've developed a custom script and mapped it to
rush symlink
, to make it easy for folks in our monorepo to perform this action. Perhaps this script could become the basis of a built-in feature of Rush, for mapping/unmapping a specific package/version locally to the specified target directory.Details
Here is the current version of our script in its entirety, as a baseline:
*/
const fs = require('fs'); const path = require('path'); const process = require("process");
process.exitCode = 1;
let args; try { args = parseArgs(process.argv) } catch (error) { console.error(error.message); console.error(); console.error(getHelpMessage()); return; }
try { program(args); process.exitCode = 0; } catch (error) { console.error(error.message); console.info('\nTo unlink or fix issues with your Rush pnpm store:
rush install --purge
'); }/**
@param {string} args.version Module version to link (otherwise all are linked) */ function program(args) { if (args.help || !args.path) { console.log(getHelpMessage()); return; }
if (!fs.existsSync(args.path)) { throw new Error(
${args.path} not found
); }// Get linked module package const pkgPath = path.join(args.path, 'package.json'); const pkg = JSON.parse(fs.readFileSync(pkgPath).toString()); const pkgMatch = pkg.name.replace('/', '+') + '@';
// Find Rush pnpm store const storePath = findStoreModules();
// Find matching installed modules const pnpmModules = fs.readdirSync(storePath).filter(m => m.startsWith(pkgMatch));
// Do the linking let linked = false; for (const moduleName of pnpmModules) { if (!args.version || moduleName ===
${pkgMatch}${args.version}
) { const modulePath = path.join(storePath, moduleName, 'node_modules', pkg.name); link(modulePath, args.path, args.dry); linked = true; } } if (!linked) { if (args.version) { throw new Error(No matching module found with version ${args.version}
); } else { throw new Error('No matching module found'); } } }/**
/**
/**
sourcePath
attargetPath
ln -s ${targetPath} ${sourcePath}
); if (!dry) { try { fs.symlinkSync(targetPath, sourcePath); } catch (error) { throw new Error(Unable to create symlink: ${error.message}
); } } }/**
rm -rf ${targetPath}
); if (targetPath.indexOf('/common/temp/') > 0) { if (!dry) { try { fs.rmdirSync(targetPath, { recursive: true, force: true }); } catch (error) { throw new Error(Unable to delete ${targetPath}
); } } } else { throw new Error('Script will not delete folders outside of Rush pnpm store'); } } else { console.log(rm ${targetPath}
); if (!dry) { try { fs.unlinkSync(targetPath); } catch (error) { throw new Error(Unable to delete ${targetPath}
); } } } }/**
/**
} */ function parseArgs(argv) { // We are hand rolling our own command line parsing to cut down on the overhead of dependencies // And because the command line syntax of this program has been designed to be simple. const result = {};
let switchName = undefined; let switchValueExpected = false; let pathProvided = false; for (let i = 2; i < argv.length; i++) { const arg = argv[i];
} return result; }
And here is the command definition:
Standard questions
Please answer these questions to help us investigate your issue more quickly:
@microsoft/rush
globally installed version?rushVersion
from rush.json?useWorkspaces
from rush.json?node -v
)?