Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved yarn support #60

Merged
merged 4 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
{
"taskName": "tsc",
"command": "node",
"args": [
"./node_modules/typescript/lib/tsc.js",
"-w",
"-p",
"."
],
"args": ["./node_modules/typescript/lib/tsc.js", "-w", "-p", "."],
"isBackground": true,
"problemMatcher": "$tsc-watch"
}]
}
}
]
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
"scripts": {
"build": "tsc",
"clean": "trash **/*.js **/*.js.map **/*.d.ts **/*.log !**/node_modules/**",
"precommit": "yalc check",
"prepublishOnly": "yarn clean && tsc && yarn test",
"test": "tsc && mocha test && yarn lint",
"watch": "mocha test --watch",
"ci": "tsc && yarn test",
"lint": "tslint -p ."
},
"husky": {
"hooks": {
"pre-commit": "yalc check && pretty-quick --staged"
}
},
"dependencies": {
"del": "^2.2.2",
"fs-extra": "^4.0.2",
Expand All @@ -44,11 +48,11 @@
"@types/npm-packlist": "^1.1.0",
"@types/yargs": "^6.6.0",
"clean-ts-built": "^1.0.0",
"husky": "^0.13.3",
"husky": "^1.3.1",
"mocha": "^5.2.0",
"prettier": "^1.14.2",
"pretty-quick": "^1.8.0",
"trash-cli": "^1.4.0",
"ts-clean-built": "^1.0.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-plugin-prettier": "^1.3.0",
Expand Down
6 changes: 4 additions & 2 deletions src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export const addPackages = async (
}
const addedAction = options.link ? 'linked' : 'added'
console.log(
`Package ${pkg.name}@${pkg.version} ${addedAction} ==> ${destModulesDir}.`
`Package ${pkg.name}@${
pkg.version
} ${addedAction} ==> ${destModulesDir}.`
)
}

Expand Down Expand Up @@ -213,6 +215,6 @@ export const addPackages = async (

if (options.yarn) {
console.log('Running yarn:')
execSync('yarn', {cwd: options.workingDir})
execSync('yarn', { cwd: options.workingDir })
}
}
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
12 changes: 5 additions & 7 deletions src/installations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export const readInstallationsFile = (): InstallationsFile => {
export const showInstallations = ({ packages }: { packages: string[] }) => {
const config = readInstallationsFile()
Object.keys(config)
.filter(
packageName =>
packages.length ? packages.indexOf(packageName) >= 0 : true
.filter(packageName =>
packages.length ? packages.indexOf(packageName) >= 0 : true
)
.map((name: PackageName) => ({ name, locations: config[name] }))
.forEach(({ name, locations }) => {
Expand All @@ -55,14 +54,13 @@ export const cleanInstallations = async ({
packages,
dry
}: {
packages: string[],
packages: string[]
dry: boolean
}) => {
const config = readInstallationsFile()
const installsToRemove = Object.keys(config)
.filter(
packageName =>
packages.length ? packages.indexOf(packageName) >= 0 : true
.filter(packageName =>
packages.length ? packages.indexOf(packageName) >= 0 : true
)
.map((name: PackageName) => ({ name, locations: config[name] }))
.reduce(
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
2 changes: 1 addition & 1 deletion test/fixture/project/nested/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"dependencies": {
"dep-package": "1.0.0"
}
}
}
14 changes: 7 additions & 7 deletions test/fixture/project/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "yalc-test-project",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"dep-package": "1.0.0"
}
"name": "yalc-test-project",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"dep-package": "1.0.0"
}
}
Loading