-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
New Options (dev, peerDependencies) #13
Conversation
Great request! What about this as well? cli: (somethign) => ({
const save = ...;
const saveDev = ...;
return { save, saveDev };
}), Maybe that's what you meant by by the last suggestion? (I haven't used |
I may have this in #5. This is especially useful with the |
Even though it's repetitious, I think following the same format as
|
Going to save this for after 2.0.0. It should be pretty easy, but there was enough movement for #5 alone :) |
I would love to see this happen. To quote from #22:
I think this would be possible with two rules. In pseudocode "If in ./app do save else do save-dev". I would be totally happy with a callback where I get access to the path and can return |
I gave it a quick go. Something like this would work for me: plugin.js ...
NpmInstallPlugin.prototype.resolve = function(request, path) {
var options = this.options;
var dep = installer.check(request);
var resolve = options.resolve || function() {return {};}
if (dep) {
installer.install(dep, Object.assign({}, options, resolve(path)));
}
return dep;
};
NpmInstallPlugin.prototype.resolveModule = function(result, next) {
// Only install direct dependencies, not sub-dependencies
if (!result.path.match("node_modules")) {
this.resolve(result.request, result.path);
}
next();
};
// probably pass path for loaders too?
...
Now the paths passed to the callback are full. Maybe it would make sense to resolve them against the project root. I'm not sure about this. This is something that can be done on the user side, though. |
I agree, the callback is clearer IMO, since you explicitly get a method FYI, there's some major re-archtecting happening for Thanks for the working example! That shaved off lots of time for me :) |
I gave this some extra thought. It feels like returning paths resolved against cwd would be neatest. Then you could match the path against a regex like
Ok, cool. Let me know if I can be of any help. I would love to see these features land soon. 👍 This plugin is going to cut tons of |
v3.0.0 is out with |
@ericclemmons Do you want a PR? |
Yes, this is quite useful. I want to wait for #29 to land, which is top priority for me. That single PR may change a lot of the code behind the scenes, and I hate merge conflicts ;) |
This will be the last feature added for |
Ok, I'm going to implement a RegExp for matching In For reference, see how I'm considering making this a breaking change. ( @insin's example using Also, passing the CLI options is actually best handled in Instead, we'll probably do something like: new NpmInstallPlugin({
// Plugin noops in other environments
install: process.env.NODE_ENV === "development",
// Choose `save` or `save-dev`
dev: /test/, // defaults to false
}); |
Ugh, this also means doing the RegExp checking before calling |
I think I'd rather release v3.1.0, and put this into v4. |
Thinking about this some more today:
I think the best solution, AFAIK is:
I'm sure there's some dilemma when a dependency is saved in both spots, but at some point the user is in charge of their project's This project is to help simplify things, not replace them. |
Shoot. In the interest of having this added sooner, I may opt for: dev: function(module) {
return module.match(/ava|mocha|eslint|babel/);
} Why? Because currently the Again, I'm interested primarily in preventing the errors that users have with cyclical installs because they're not passing Then adding utility. |
Nevermind. I think I got it. Sorry for the spam. |
Ok, this was easier than I thought :) Stupid simple example: new NpmInstallPlugin({
dev: function(module, path) {
return [
"babel-preset-react-hmre",
"webpack-dev-middleware",
"webpack-hot-middleware",
].indexOf(module) !== -1;
},
peerDependencies: true,
}), Defaults are: { dev: false, peerDependencies: true }; Next up:
|
Use case: allowing configuration of the
npm install
options used to vary based on the module missing dependencies were detected in.This is pretty niche, but would be neat DX touch for tooling which can auto-configure it for you.
e.g. if installation is triggered by a module under
src/
, use--save
; a module undertest/
, use--save-dev
Potential API (which suits a plugin, as it would otherwise need to be top-levelled in webpack config for a loader): pass a RegExp as
save
/saveDev
config which is tested against the relative path fromprocess.cwd()
to the module the current install is being triggered from:Alternatively, allow
cli
or any of its props to be a Function which would take amodule
arg similar to theminChunks
option forCommonsChunkPlugin
. Seems a bit overkilly, but you never know.