Repository navigation
Update bootstrap command (fixes #11, #176) - #237
Conversation
|
this is a complete refactor of the bootstrap command. i haven't tested on Windows, but it seems like it would work with admin access. not sure the my company is using this right now, and it's working great for us (we're on Mac). i'm sure there's optimizations that can be done. please take a look at the code and let me know what you think. |
fe5e5ad to
444b938
Compare
| Object.keys(dependencies) | ||
| .forEach(dest => { | ||
| const destLocation = dest === "__ROOT__" ? | ||
| this.repository.rootPath : |
There was a problem hiding this comment.
This might be safer to put into this.repository.packagesLocation. It's possible that the repo root has a dependency on a package from within the repo, which would conflict with the symlink. If the __ROOT__ deps went into packages/ then they would have a clean directory with no potential for conflict.
There was a problem hiding this comment.
unfortunately, without a package.json in the /packages folder, NPM won't install anything there. using the --prefix and --global flags doesn't help much either as it creates /lib and /etc folders inside /packages.
|
This is awesome. It's a big change. It helps with the deep-require problem (#11), but we've got at least one module in |
|
This renders |
|
This worries me, it's completely changing how packages interact with |
|
i could take out the "optimization" part and install dependencies in each package's folder like before, then symlink the packages to |
|
@gigabo interesting that NPM doesn't traverse directories like Node to look for dependencies. i guess it would make the command a bit more complex than it needs to be. but i think it would be helpful in determining installed versions that same way as Node resolves dependencies. |
|
i'm thinking that maybe we could symlink the external dependencies to each package's |
6ea3607 to
6513b96
Compare
|
This may be the worst idea ever – I am a npm noob – and may not work for everybody but... // packages/pkg1/package.json
"dependencies": {
"lodash": "^4.0.0",
"babel": "6.0.0"
}
// packages/pkg2/package.json
"dependencies": {
"lodash": "^4.0.0",
"babel": "5.0.0"
}becomes // package.json
"dependencies": {
"lodash": "^4.0.0"
}
// packages/pkg1/package.json
"dependencies": {
"babel": "6.0.0"
}
// packages/pkg2/package.json
"dependencies": {
"babel": "5.0.0"
} |
|
Im super-keen on getting support for linked binaries(#192), as well as support for more than one entry/main file via symlinks. What is the blocker on this issue atm? |
|
@giuseppeg I think that would work, but there is one rub: binaries on which means that if we want to upgrade some packages to a new version of |
|
@doug-wade are you sure about that? ~/project/packages/my-pkg$ PATH=$PATH:../../node_modules/.bin npm run my-scriptworks for me i.e. it uses the local bin. |
|
Hi @rygine - Looks like this has diverged from master a little. Please rebase if you get a chance. |
|
@gigabo i'll work on this over the weekend. i have a few adjustments i'd like to make as well so that |
6513b96 to
003caed
Compare
|
@gigabo having issues with paths in windows. what am i missing? i thought |
|
Weird. Looks like the test expectation is |
003caed to
01236f8
Compare
|
|
|
Maybe you can look at #236 for reference, not sure either |
|
i could potentially use @laurentdesmet thoughts? edit: |
|
Okay, looks like the issues raised by @seansfkelley and @bradleyayers have been addressed. So... 👍 (again). @hzoo, @thejameskyle This is a big one. Solves a lot of problems, but probably introduces new issues we haven't thought of yet. On balance seems worth moving forward. Ready? |
|
@rygine Thanks for your patience and work on this one! Hopefully we don't have to use the proxy method anymore |
|
First of all, nice work @rygine (and others that helped with this one), having support for deep-require within Lerna is awesome :-). At work we make heavily use of Lerna and lately we're experiencing performance problems ( I saw that this PR mentioned at some point an optimization where common dependencies (or all dependencies) of each package were moved to the root of the repo. What is the exact reason of not including this optimization? Because it would definitely be helpful for big Lerna projects (actually now, we're applying this strategy by removing commonly used dependencies from all the |
This picks up: - [Enhanced bootstrap](lerna/lerna#237) - [Private module support](lerna/lerna#321) You'll neeed to `npm update` after this lands (and `npm i -g [email protected]` if you're using a global Lerna). You'll also want to re-bootstrap to get your repo up-to-date.
|
@laurentdesmet I have a similar problem with Lerna + Webpack. I figured a neat way to solve it might be to have a Webpack resolver plugin that looks at the filesystem ancestors of a particular module when that module is required, checking if any ancestor has a package that fits the desired version range (preferring those closer to the root), and using that one instead. It wouldn't help install times, but it would reduce duplication/bloat in the final distributable. To my knowledge, such a plugin doesn't exist, but I've been mulling over how to make one. |
|
@laurentdesmet - Thanks for calling that out! Hoisting common deps to the repo root would definitely be a big improvement for Lerna. Filed #334 to track. |
|
Thank you SO much for this commit. It resolves a huge slew of issues I was having with Lerna, including:
A really great improvement to the usability of Lerna, and upgrading was almost completely seamless. Again, great work. |
* Update bootstrap command (fixes lerna#11, lerna#176) * Find common external dependencies and install to root node_modules folder * Symlink all packages to root node_modules folder after installing external dependencies * Symlink all binaries to packages that depend on them * Minor refactor of bootstrap prepublish step * Update `FileSystemUtilities.symlink` to allow type * Move hasMatchingDependency and hasDependencyInstalled to Package * Removed `linkedFiles` property of Repository * Refactor bootstrap unit tests * Add unit tests for `.hasMatchingDependency` and `.runScript` methods of Package * Revert back to installing dependencies in each package's directory * Move package symlinks to `packages/node_modules` to prevent NPM issues in the repo root * Only symlink packages that are dependents * Symlink packages to each package's node_modules directory This reverts symlinking all packages to `packages/node_modules`. * Only symlink packages defined in dependencies * Update README * Add better checks for already installed dependencies * Fix logic around existing dependency checks * Add better logic, more progress. Fix test. * Unsync unlink This change was out of scope of the PR. * Update symlink check logic * Use the same path variable for the installed dependency location and symlink destination * Always use the built-in `nodeModulesLocation` on the package * Check for `false` value instead of falsy value * Add more clarity when `package.json` of a dependency is missing * Support scoped package dependencies * Get package location from Package object * Use the package graph to get dependency packages * Symlink packages with scope to proper directory * Simplify package dependency destination path logic Breathe deep... exhale
|
UPDATE: My comment below is solved by rygine's comment. Just ran into this, I loved lerna specifically because it didn't use symlinks. Symlinks make developing with webpack really hard, it'll start giving you annoying errors like I guess I'm using lerna as an edge case as I like to use it as my main way of developing peer dependent packages to avoid the side effects of the above node 'require' issue. So my main gripe is node's require which I don't think they will change, so I wanted a way to develop without using |
|
Could you provide a bit more information about the structure of your project? It's surprising to me that you are having issues with babel. |
|
So I have my website located in loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
}
// ...Now I have another package as a dependency to luna in the folder |
|
It's curious to me that you wouldn't want cms-controls to be loaded via babel. In my project all packages use roughly the same conventions and are expected to be loaded in a similar way. I'm guessing cms-controls has a different webpack loader configuration, and luna's is not adequate to be able to load modules from cms-controls? |
|
All my third party packages are pre compiled with babel. So they have a src folder but then when I do |
|
I think even if I wanted it to be consumed by babel it wouldn't work because the error says it can't find babel now, because it's using the physical path not the symlinked path. So I don't think the problem is with how I've setup my package. I think? Could be wrong |
|
The way our repo is setup, is for all packages in |
|
@AlastairTaft you may need to add a resolver to your webpack config. this is what i have in my webpack config: resolve: {
root: path.join(process.cwd(), 'node_modules'),
},
resolveLoader: {
root: path.join(process.cwd(), 'node_modules'),
},not sure if this is your issue, but this helped me. |
|
@bradleyayers Assuming the dist contents for each package are generated with webpack, how would you handle peer dependencies, say you used React, would you ignore it from the bundle? That also got me wondering say if componentA and componentB both depended on packageA, you'd end up with packageA in both component bundles? So you'd inflate your final bundle size? I just use babel for third party components so it doesn't bundle the dependencies. I guess you could do that same with webpack by telling it to ignore bundling everything in the node_modules folder. @rygine Thanks for that, that seemed to work. |
|
@AlastairTaft we have a few webpack outputs. In one of them we don't bundle any dependencies , instead we just declare We do produce other bundles that do include dependencies, and for those common dependencies are indeed duplicated. |
|
@rygine when you were experiencing trouble in Webstorm, did you file a ticket on their tracker about it? I'm running into issues with Webstorm as well (https://youtrack.jetbrains.com/issue/WEB-23488#comment=27-1638599) and got myself into a bad state that's not clear if it's caused by circular symlinks or too many |
|
@seansfkelley i didn't file a ticket as there were already a few related ones. i've added |
|
I did that too, but I use Typescript and that causes it's own host of problems. Time to switch to VS Code! |
|
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
node_modulesfolderFileSystemUtilities.symlinkto allow typelinkedFilesproperty of Repository.hasMatchingDependencyand.runScriptmethods of Package