infinitered / gluegun

A delightful toolkit for building TypeScript-powered command-line apps.
MIT License
2.96k stars 147 forks source link

Scope Package #440

Open abstractFlo opened 5 years ago

abstractFlo commented 5 years ago

Hey guys, there is a problem while loading plugins from scoped packages. Is there a solution for this scenario?

Kind Regards

jthegedus commented 5 years ago

I tried this and it doesn't appear to work

.plugins("./node_modules", { matching: "?(*/)packagename-*" })

Parcel-bundler matches scoped plugin packages but it uses a different matching tool. const pattern = /^(@.*\/)?parcel-plugin-.+/; For reference: https://github.com/parcel-bundler/parcel/blob/060db2e2c56f08e223e9a9075035f0998e249763/packages/core/parcel-bundler/src/Bundler.js#L206

If someone finds a working matching pattern, please share!

It would be really handy if there was a flag to print out the directories that are checked so we could even see which dirs are matching which patterns.

morgandonze commented 5 years ago

@abstractFlo what is the relative path to your scoped package?

morgandonze commented 5 years ago

I have identified why scoped packages aren't being found. On this line, recursive is set to false, so jetpack isn't looking in lower directories. (I changed this to true and my scoped commands appeared.

I shouldn't change this to true though, that will cause unexpected behavior. I'll need to think of a safe solution. Maybe another boolean parameter to addPlugins. I'll think about it and post again.

jamonholmgren commented 5 years ago

I really like the idea of printing out what directories are checked.

jamonholmgren commented 5 years ago

@abstractFlo and @jthegedus , is it a limited number of scopes or any arbitrary scoped package? For example, you could do this:

.plugins("./node_modules", { matching: "packagename-*" })
.plugins("./node_modules", { matching: "scope1/packagename-*" })
.plugins("./node_modules", { matching: "scope2/packagename-*" })

To support any arbitrary scoped package, though, we'll need to build something into Gluegun.

jamonholmgren commented 5 years ago

I do like Parcel's discoverability through the package.json devDependencies and dependencies. We could easily support that same thing, perhaps with something like:

.dependencyPlugins({ matching: /^(@.*\/)?packagename-.+/ })

This would search dependencies and devDependencies and use a similar mechanism to Parcel to load up the plugins that match.

Any thoughts on this?

abstractFlo commented 5 years ago

@jamonholmgren i have a bunch of scoped packages. I write a foundation for all of our services with vuejs. I will let our developers the freedom to create a package with own commands. I think it is the best way for an modular system. The option with recusive: true is a good point. I think it would be nice if we can set the parameter as an option for the plugins method.

jthegedus commented 5 years ago

@jamonholmgren In this instance I want the same plugin discoverability as Parcel. I want users of my base tool to be able to compose other peoples plugins. So I need support for arbitrary scopes. A solution looking at package.json deps and devDeps will allow this without the headaches that recursively traversing node_modules creates (as @mlaco mentions).

.addDependencyPlugins({ matching: /^(@.*\/)?packagename-.+/ }) would be a good solution instead of messing with the existing addPlugins which caters to a different need.

morgandonze commented 5 years ago

@jthegedus You have the right idea, but check out fs-jetpack's matching patterns to see the exact way to use matching.

jthegedus commented 5 years ago

I truly tried before posting here. I spent hours going between gluegun, fs-jetpack and minimatch docs, source code and many different variations of patterns, none of which gave me the same result as the Parcel regex.

I eliminated it being an issue with my plugin by adding it directly as such:

plugin(process.cwd() + "/node_modules/@jthegedus/packagename-pluginname")

and so now am at the point where I have not been able to get the

.plugins(process.cwd() + "/node_moduels", { matching: "" })

method to work at all with scoped packages.

I was sure +(packagename-*|*/packagename-*) would match something but got nothing with it too.

If someone could produce a working example that would be great, because unfortunately I cannot invest more time trying to get this to work, nor can I move forward with my tool until this is resolved.

jamonholmgren commented 5 years ago

@jthegedus Can you do:

.plugins(process.cwd() + "/node_modules/@jthegedus", { matching: "packagename-*" })

... for now?

jthegedus commented 5 years ago

@jamonholmgren This will be sufficient for testing my own plugins, but not for others to build and use their own with my tool. My use of gluegun is for a novel tool, not some critical business use case like aws/amplify or anything, it's just for fun. I didn't mean to sound like this was urgent, it's just a pain-point.

I still very strongly want an addDependencyPlugins function

jamonholmgren commented 5 years ago

I do too, this is something we should add.