Package managers in SAO templates

EGOIST
⚔️ SAO
Published in
2 min readAug 2, 2017

SAO works seamlessly with both npm and yarn.

You can use the npmInstall option in config file to install node modules after generating a new project.

// sao.js
module.exports = {
npmInstall: true
}

SAO prefers npm 5 over yarn over npm 4 in this case.

If you want to give yarn the highest priority, use yarnInstall instead:

// sao.js
module.exports = {
yarnInstall: true
}

There’s also a CLI option --force-npm so SAO will always give npm 5 the highest priority even if you’re using yarnInstall option.

Sometimes you might also want to know what exact package manager the user is using while generating a new project, for instance, you might need to write some markdown code in your template file like this:

## Development```bash
<%= _.pm %> test
```

Then it will be either npm test or yarn test depending on the actual package manager the user is using to generate this project.

For more about the underscore _ in template files, please refer to https://sao.js.org/#/create?id=context, _ is actually a subset of context which you can access in post hook:

// sao.js
module.exports = {
post(context) {
console.log(context.pm)
// npm or yarn
}
}

And yarnInstall: true and npmInstall: true are just two short-hands to call context.yarnInstall() and context.npmInstall() in post hook.

--

--