mrm icon indicating copy to clipboard operation
mrm copied to clipboard

customize commands

Open ackvf opened this issue 6 years ago • 5 comments

So I have encountered an interesting issue while trying to run a task and I have no idea how to name it or even what to ask for. I guess I will just leave it here for your consideration.

The problem is that I am using yarn workspaces and in order to install something to root, I must explicitly call yarn with -W flag.

$ npx mrm lint-staged
npx: installed 173 in 14.685s
Running lint-staged...
Update package.json
Installing lint-staged...
error Running this command will add the dependency to the workspace root rather than the workspace itself, which might not be what you want - if you really meant it, make it explicit by running this command again with the -W flag (or --ignore-workspace-root-check).

Maybe perhaps if I could set an alias for yarn to yarn -W temporarily..? No idea what would be the best solution, but I think cases like this may happen not only with yarn.

ackvf avatar Nov 06 '19 09:11 ackvf

Can we detect that a project is using workspaces and run yarn -W in that case? Would it be the right solution?

sapegin avatar Nov 06 '19 10:11 sapegin

Yes, workspaces are actually detectable from root package.json and it would solve this particular issue with yarn. Cool,

// package.json
{
  "workspaces": [
    "packages/*"
  ]
}

Anyway, what about the problem in general, do you not think these cases might happen with any arbitrary command that wouldn't work on user's machine for any reason - be it aliases, etc. Being able to map a task's command to a "different" one could maybe come handy.

ackvf avatar Nov 06 '19 11:11 ackvf

Not many tasks run shell commands and I think aliasing them shouldn't be in the scope of Mrm. But supporting Yarn workspaces makes a lot of sense, since installing packages is a core feature.

Mind sending a pull request with a fix?

sapegin avatar Nov 07 '19 09:11 sapegin

Can you point me to an appropriate file? I think I will just check package.json for the workspaces property and if it's there, run yarn with -W, does that sound OK?

ackvf avatar Nov 07 '19 14:11 ackvf

Sounds like a good plan!

https://github.com/sapegin/mrm-core/blob/6e622ef62b492edc296b95a479cfffa8030b8eee/src/npm.js#L85-L106

sapegin avatar Nov 07 '19 15:11 sapegin