Skip to content

Commit

Permalink
feat: improved yarn support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aleclarson committed Dec 29, 2018
1 parent efe5889 commit 5f304a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as fs from 'fs-extra'
import * as path from 'path'
import { join } from 'path'
import { PackageName } from './installations'

const userHome = require('user-home')

const { join } = path

export const values = {
myNameIs: 'yalc',
ignoreFileName: '.yalcignore',
Expand Down Expand Up @@ -56,7 +54,7 @@ export function getStorePackagesDir(): string {
}

export const getPackageStoreDir = (packageName: string, version = '') =>
path.join(getStorePackagesDir(), packageName, version)
join(getStorePackagesDir(), packageName, version)

export type PackageScripts = Partial<{
preinstall: string
Expand All @@ -83,8 +81,8 @@ export interface PackageManifest {
__JSONSpaces: number
}

export const getPackageManager = (workingDir: string) =>
fs.existsSync('yarn.lock') ? 'yarn' : 'npm'
export const getPackageManager = (cwd: string) =>
fs.existsSync(join(cwd, 'yarn.lock')) ? 'yarn' : 'npm'

export const execLoudOptions = { stdio: 'inherit' }

Expand Down
15 changes: 9 additions & 6 deletions src/yalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
addPackages,
updatePackages,
removePackages,
getStoreMainDir
getStoreMainDir,
getPackageManager
} from '.'

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

const showVersion = () => {
console.log(getVersionMessage())
}
const isYarn = (cwd: string = process.cwd()) =>
getPackageManager(cwd) === 'yarn'

/* tslint:disable-next-line */
yargs
Expand Down Expand Up @@ -53,6 +53,7 @@ yargs
builder: () => {
return yargs
.default('sig', true)
.default('yarn', isYarn())
.boolean(['push', 'push-safe'].concat(publishFlags))
},
handler: argv => {
Expand Down Expand Up @@ -100,6 +101,7 @@ yargs
return yargs
.default('force', undefined)
.default('sig', true)
.default('yarn', isYarn())
.boolean(['safe'].concat(publishFlags))
},
handler: argv => {
Expand All @@ -122,7 +124,7 @@ yargs
describe: 'Add package from yalc repo to the project',
builder: () => {
return yargs
.default('yarn', false)
.default('yarn', isYarn())
.boolean(['file', 'dev', 'save-dev', 'link', 'yarn', 'pure'])
.help(true)
},
Expand All @@ -144,11 +146,12 @@ yargs
command: 'link',
describe: 'Link package from yalc repo to the project',
builder: () => {
return yargs.default('yarn', true).help(true)
return yargs.default('yarn', isYarn()).help(true)
},
handler: argv => {
return addPackages(argv._.slice(1), {
link: true,
yarn: argv.yarn,
workingDir: process.cwd()
})
}
Expand Down

0 comments on commit 5f304a3

Please sign in to comment.