mrm icon indicating copy to clipboard operation
mrm copied to clipboard

Setting `yarn` as the default

Open af-mikecrowe opened this issue 5 years ago • 7 comments

OK, this may be another easy one I'm missing, but here goes: Assume you have a new project with this as your ~/.mrm/config.json:

{
    "yarn": true,
    "aliases": {
        "default": ["package", "prettier", "typescript", "eslint"]
    }
}

If you run mrm default, prettier begins installing using npm.

It seems like getTaskOptions in mrm/packages/mrm/src/index.js is only using the default options if there are no parameters to the task.

Or, should mrm/packages/mrm-core/src/npm.js re-read the global config.json to get the yarn flag?

af-mikecrowe avatar Nov 05 '20 19:11 af-mikecrowe

Looks like it's not possible now but would be a nice addition so feel free to send a pull request 👾

One note though: mrm-core doesn't know anything about the config file but also there's no easy way to pass config options to the core right now.

What if make a yarn option for the package task that would create an empty yarn.lock or package-lock.json file? Then all the other tasks would work as expected without any changes.

sapegin avatar Nov 06 '20 07:11 sapegin

Yeah, I thought about that. However, if we call:

install([], {yarn: true});

it doesn't actually call yarn. I'd have to also put logic into npm.js that checked for empty dependencies and run npm i or yarn with no args to create those files.

If this is OK, I'll see if I can do that...

af-mikecrowe avatar Nov 06 '20 12:11 af-mikecrowe

This sounds like a bug or we don't really need this parameter there ;-)

sapegin avatar Nov 06 '20 13:11 sapegin

So, here's a couple of work-arounds:

First

{
    "yarn": true,
    "aliases": {
        "default": ["package", "custom-task-with-install", "prettier", "typescript", "eslint"]
    }
}

where custom-task-with-install calls install(..., {yarn: true})

Second

mrm package
yarn 
mrm default    <-- alias above w/o the package

af-mikecrowe avatar Nov 06 '20 18:11 af-mikecrowe

This might work as well as a workaround:

touch yarn.lock
mrm default

sapegin avatar Nov 07 '20 07:11 sapegin

I'm using mrm task with programming api

Currently isUsingYarn use yarn.lock existence internally, in some case it's not enough( e.g. create a new project from template, no 'yarn' ran, directly ran mrm )

To solve this issue, can we officially add an env variable, then in isUsingYarn method fetch this env variable ?

for example

with programming api

process.env.MRM_INSTALL_USE_YARN = '1'

// ...then invoke mrm task

with cli

MRM_INSTALL_USE_YARN=1 mrm [task]

I can send a PR if needed

fengzilong avatar Apr 29 '21 09:04 fengzilong

Just flying by this issue and would like to comment that we should not have yarn be the default, IMHO....

Defaulting to a tool that is not always available on a users system seems like a wrong direction.

I would suggest that a smart resolution of package manager be used or stick with defaulting to npm.

For instance, I have adopted pnpm and find it much more useful than yarn. I used to be a yarn advocate and used it daily too.

Just my $0.02 as a casual mrm user

kevinkhill avatar Aug 18 '22 13:08 kevinkhill