FormidableLabs / builder

An npm-based task runner
https://github.com/FormidableLabs/builder
MIT License
319 stars 26 forks source link

Builder cannot resolve shared dependencies #145

Open dusura opened 7 years ago

dusura commented 7 years ago

Perhaps this is against the general philosophy of builder but it would be nice if builder could resolve "shared" dependencies by adding any local "node_modules" folders to its path.

For example, builder will not run commands in a monorepo that uses the lerna hoist feature because it doesn't know about the monorepo's base "node_modules".

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.01%) to 93.675% when pulling 85fe27d9e296d4c3d39600c0e8788056ba800b54 on dusura:shared-dependencies into 390eaa4618200d20a65752045ba2762e104c70c3 on FormidableLabs:master.

ryan-roemer commented 7 years ago

Thanks for the PR @dusura !

Can you give me a little more background here -- an example of a file layout that current builder can't handle would be a great accelerator for me to wrap my head around the problem we're solving here...

dusura commented 7 years ago

Hi @ryan-roemer. Thanks for the interest. I created a small demo so you can understand the issue.

ryan-roemer commented 6 years ago

Thanks for the repository!

So everything works when I do:

npm install
npm run create-component
npm run bootstrap
cd component/YOUR-COMPONENT-HERE
npm install # <== I ADDED THIS
npm run figlet
[builder:config:environment] {"cwd":"/Users/rye/scm/vendor/builder-shared-dependencies-pr145/component/whiz-bang","dir":"/Users/rye/scm/vendor/builder-shared-dependencies-pr145/component/whiz-bang/node_modules/builder/lib"}
[builder:builder-core:start:91603] Started: run figlet
[builder:run] figlet - builder run figlet-cmd
[builder:proc:start] Command: builder run figlet-cmd
[builder:config:environment] {"cwd":"/Users/rye/scm/vendor/builder-shared-dependencies-pr145/component/whiz-bang","dir":"/Users/rye/scm/vendor/builder-shared-dependencies-pr145/component/whiz-bang/node_modules/builder/lib"}
[builder:builder-core:start:91604] Started: run figlet-cmd
[builder:run] figlet-cmd - figlet "my builder script!"
[builder:proc:start] Command: figlet "my builder script!"
                    _           _ _     _                           _       _   _ 
  _ __ ___  _   _  | |__  _   _(_) | __| | ___ _ __   ___  ___ _ __(_)_ __ | |_| |
 | '_ ` _ \| | | | | '_ \| | | | | |/ _` |/ _ \ '__| / __|/ __| '__| | '_ \| __| |
 | | | | | | |_| | | |_) | |_| | | | (_| |  __/ |    \__ \ (__| |  | | |_) | |_|_|
 |_| |_| |_|\__, | |_.__/ \__,_|_|_|\__,_|\___|_|    |___/\___|_|  |_| .__/ \__(_)
            |___/                                                    |_|          
[builder:proc:end:0] Command: figlet "my builder script!"
[builder:builder-core:end:91604] Task: run figlet-cmd ended normally
[builder:proc:end:0] Command: builder run figlet-cmd
[builder:builder-core:end:91603] Task: run figlet ended normally

So you're saying that normally I should be able to not add that extra npm install and still have everything work using npm CLI? I can't see how that would work as even builder isn't available in component/NAME_HERE/node_modules/.bin/builder -- it seems maybe there's an install step or maybe a "use a wrapper command to execute provided by lerna or something"?

(Separately, we have a tool to do just that -- exec commands with extra NODE_PATH to deal with non-standard installations / requires, but I'll wait on chatting more about that until if/when I'm sure it would be appropriate to discuss here).

trusktr commented 6 years ago

Interesting! I would've ran into this eventually, as I'm looking to start using builder in a monorepo. Related issue: https://github.com/FormidableLabs/builder/issues/150