Skip to content

Commit 59fe855

Browse files
committed
feat: smartly detect the dependencies installation client
1 parent c498177 commit 59fe855

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

commands/Build.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10+
import hasYarn from 'has-yarn'
1011
import { BaseCommand, flags } from '@adonisjs/ace'
1112

1213
/**
@@ -31,8 +32,8 @@ export default class Build extends BaseCommand {
3132
/**
3233
* Use yarn when building for production to install dependencies
3334
*/
34-
@flags.boolean({ description: 'Use yarn for installing dependencies. Defaults to npm' })
35-
public yarn: boolean
35+
@flags.string({ description: 'Select between npm or yarn for installing dependencies' })
36+
public client: string
3637

3738
/**
3839
* Invoked automatically by ace
@@ -62,10 +63,18 @@ export default class Build extends BaseCommand {
6263
this.logger.info('--watch and --production flags cannot be used together. Skipping --watch')
6364
}
6465

66+
/**
67+
* Deciding the client to use for installing dependencies
68+
*/
69+
this.client = this.client || hasYarn(cwd) ? 'yarn' : 'npm'
70+
if (this.client !== 'npm' && this.client !== 'yarn') {
71+
this.logger.warn('--client must be set to "npm" or "yarn"')
72+
return
73+
}
74+
6575
try {
6676
if (this.production) {
67-
const client = this.yarn ? 'yarn' : 'npm'
68-
await new Compiler(cwd, false, [], this.logger).compileForProduction(client)
77+
await new Compiler(cwd, false, [], this.logger).compileForProduction(this.client)
6978
} else if (this.watch) {
7079
await new Watcher(cwd, false, [], this.logger).watch()
7180
} else {

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"emittery": "^0.5.1",
9999
"execa": "^4.0.0",
100100
"fs-extra": "^8.1.0",
101+
"has-yarn": "^2.1.0",
101102
"import-fresh": "^3.2.1",
102103
"mem": "^6.0.1",
103104
"picomatch": "^2.2.1",

0 commit comments

Comments
 (0)