Skip to content

Commit 5f304a3

Browse files
committed
feat: improved yarn support
Any commands with a --yarn flag will look for a "yarn.lock" file in the working directory. When a lockfile exists, the --yarn flag will be true by default. Other fixes: - actually use argv.yarn for the "link" command - actually use the `getPackageManager` function's argument - remove unused `showVersion` function
1 parent efe5889 commit 5f304a3

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/index.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import * as fs from 'fs-extra'
2-
import * as path from 'path'
2+
import { join } from 'path'
33
import { PackageName } from './installations'
44

55
const userHome = require('user-home')
66

7-
const { join } = path
8-
97
export const values = {
108
myNameIs: 'yalc',
119
ignoreFileName: '.yalcignore',
@@ -56,7 +54,7 @@ export function getStorePackagesDir(): string {
5654
}
5755

5856
export const getPackageStoreDir = (packageName: string, version = '') =>
59-
path.join(getStorePackagesDir(), packageName, version)
57+
join(getStorePackagesDir(), packageName, version)
6058

6159
export type PackageScripts = Partial<{
6260
preinstall: string
@@ -83,8 +81,8 @@ export interface PackageManifest {
8381
__JSONSpaces: number
8482
}
8583

86-
export const getPackageManager = (workingDir: string) =>
87-
fs.existsSync('yarn.lock') ? 'yarn' : 'npm'
84+
export const getPackageManager = (cwd: string) =>
85+
fs.existsSync(join(cwd, 'yarn.lock')) ? 'yarn' : 'npm'
8886

8987
export const execLoudOptions = { stdio: 'inherit' }
9088

src/yalc.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
addPackages,
88
updatePackages,
99
removePackages,
10-
getStoreMainDir
10+
getStoreMainDir,
11+
getPackageManager
1112
} from '.'
1213

1314
import { showInstallations, cleanInstallations } from './installations'
@@ -23,9 +24,8 @@ const getVersionMessage = () => {
2324
return pkg.version
2425
}
2526

26-
const showVersion = () => {
27-
console.log(getVersionMessage())
28-
}
27+
const isYarn = (cwd: string = process.cwd()) =>
28+
getPackageManager(cwd) === 'yarn'
2929

3030
/* tslint:disable-next-line */
3131
yargs
@@ -53,6 +53,7 @@ yargs
5353
builder: () => {
5454
return yargs
5555
.default('sig', true)
56+
.default('yarn', isYarn())
5657
.boolean(['push', 'push-safe'].concat(publishFlags))
5758
},
5859
handler: argv => {
@@ -100,6 +101,7 @@ yargs
100101
return yargs
101102
.default('force', undefined)
102103
.default('sig', true)
104+
.default('yarn', isYarn())
103105
.boolean(['safe'].concat(publishFlags))
104106
},
105107
handler: argv => {
@@ -122,7 +124,7 @@ yargs
122124
describe: 'Add package from yalc repo to the project',
123125
builder: () => {
124126
return yargs
125-
.default('yarn', false)
127+
.default('yarn', isYarn())
126128
.boolean(['file', 'dev', 'save-dev', 'link', 'yarn', 'pure'])
127129
.help(true)
128130
},
@@ -144,11 +146,12 @@ yargs
144146
command: 'link',
145147
describe: 'Link package from yalc repo to the project',
146148
builder: () => {
147-
return yargs.default('yarn', true).help(true)
149+
return yargs.default('yarn', isYarn()).help(true)
148150
},
149151
handler: argv => {
150152
return addPackages(argv._.slice(1), {
151153
link: true,
154+
yarn: argv.yarn,
152155
workingDir: process.cwd()
153156
})
154157
}

0 commit comments

Comments
 (0)