0.0.8 • Published 5 years ago
ymultirepo v0.0.8
ymultirepo
Local package manager. A small tool to help manage your multi-repo work.
What is multi-repo? Why not mono repo?
Not mine article but I totally agree with it https://medium.com/@PepsRyuu/monorepos-in-javascript-anti-pattern-917603da59c8
Requirements
For now ymultirepo works with pnpm package manager only.
Setup
- Projects that consume local modules should have
ymultirepoinstalled to node_modules. So
npm i -g ymultirepoAND setNODE_PATHto global modules folder (recommended). You can use the following snippet to set NODE_PATH permanently on Windows:
npm config get prefix > node_path.txt
setx /m /p NODE_PATH= < node_path.txt
setx NODE_PATH %NODE_PATH% /m
erase node_path.txt- OR
- Just use
npm i ymultirepo --saveDevin each consumer (not recommended, because this would force all contributors to installymultirepoeven when they don't use it)
Use
npm configto setlocal_packages_folderto the folder where you store your projects:npm config set local_packages_folder YOUR_PATH_TO_PROJECTS_FOLDERAdd
pnpminit.jsto your project root with contentsconst {ymultirepoRemap, ymultirepoScan} = require('ymultirepo'); ymultirepoScan(); // This line refreshes YOUR_PATH_TO_PROJECTS_FOLDER/local_packages_list.json module.exports = { hooks: { readPackage:ymultirepoRemap, }, };If you already using
pnpmfile.jsfor some other needs, than just add a call toremapLocal(package, context)at the top of readPackage handler.Use
YOUR_PATH_TO_PROJECTS_FOLDER/local_packages_list.jsonto fine tune which local packages you want/don't want to use for the moment.
Functions (Developer guide)
caseInsensitiveCompare(a, b)- case insensitive string comparisiongetLocalPackagesPathsObj()- reads setting fromnpm configwriteFileSyncIfChanged(fileName, content, encoding = "utf-8")- writes file only if supplied content differs from existing contentgetLocalPackagesList(localPackagesPaths = getLocalPackagesPathsObj())- readslocal_packages_list.jsonto object.ymultirepoScan(localPackagesPaths = getLocalPackagesPathsObj())- scans folders set by setup(1) and refresheslocal_packages_list.jsongetLocalPackages(localPackagesPaths = getLocalPackagesPathsObj())- readslocal_packages_list.jsonand makes effective set of local packages in packageName -> package form/ymultirepoRemap(p, context, effectiveLocalPackages = getLocalPackages())- a convinien function to use withpnpmfile.js- TODO Maybe package version should also be checked inside
remapLocal.
- TODO Maybe package version should also be checked inside
TODOs and notes
- TODO Maybe package version should also be checked inside
remapLocal. - Note Setup.1 doesn't seem as a good solution to me. But I haven't found any other way. That would be great if all this gets implemented as a part of pnpm someday