Skip to content

Commit

Permalink
refactor: "yalc add" flags
Browse files Browse the repository at this point in the history
Changes affecting "yalc add":
- use --link by default
- remove the --file flag (use --no-link instead)
- remove the --save-dev flag (use --dev instead)
- add --no-save flag

Changes affecting the `addPackages` function:
- rename "link" option to "noSave"
- rename "linkDep" option to "link"
  • Loading branch information
aleclarson committed Jan 3, 2019
1 parent efe5889 commit d7a4f56
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
25 changes: 11 additions & 14 deletions src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ const ensureSymlinkSync = fs.ensureSymlinkSync as typeof fs.symlinkSync
export interface AddPackagesOptions {
dev?: boolean
link?: boolean
linkDep?: boolean
yarn?: boolean
safe?: boolean
pure?: boolean
noSave?: boolean
workingDir: string
}

Expand Down Expand Up @@ -71,7 +70,8 @@ export const addPackages = async (
return
}
const doPure =
options.pure === false ? false : options.pure || !!localPkg.workspaces
options.pure !== undefined ? options.pure : !!localPkg.workspaces

const addedInstalls = packages
.map(packageName => {
const { name, version = '' } = parsePackageName(packageName)
Expand Down Expand Up @@ -127,19 +127,15 @@ export const addPackages = async (
}
if (!doPure) {
const destModulesDir = join(workingDir, 'node_modules', name)
if (options.link || options.linkDep || isSymlink(destModulesDir)) {
fs.removeSync(destModulesDir)
}

if (options.link || options.linkDep) {
fs.removeSync(destModulesDir)
if (options.link) {
ensureSymlinkSync(destYalcCopyDir, destModulesDir, 'junction')
} else {
emptyDirExcludeNodeModules(destModulesDir)
fs.copySync(destYalcCopyDir, destModulesDir)
}

if (!options.link) {
const protocol = options.linkDep ? 'link:' : 'file:'
if (!options.noSave) {
const protocol = options.link ? 'link:' : 'file:'
const localAddress =
protocol + values.yalcPackagesFolder + '/' + pkg.name

Expand Down Expand Up @@ -174,7 +170,8 @@ export const addPackages = async (
replacedVersion =
replacedVersion == localAddress ? '' : replacedVersion
}
const addedAction = options.link ? 'linked' : 'added'

const addedAction = options.noSave ? 'linked' : 'added'
console.log(
`Package ${pkg.name}@${
pkg.version
Expand Down Expand Up @@ -204,8 +201,8 @@ export const addPackages = async (
version: i!.version,
replaced: i!.replaced,
pure: doPure,
file: !options.link && !options.linkDep && !doPure,
link: options.linkDep && !doPure,
file: !options.link && !doPure,
link: options.link && !doPure,
signature: i.signature
})),
{ workingDir: options.workingDir }
Expand Down
5 changes: 3 additions & 2 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ export const updatePackages = async (
await addPackages(packagesLinks, {
workingDir: options.workingDir,
link: true,
noSave: true,
pure: false
})

const packagesLinkDep = lockPackages.filter(p => p.link).map(p => p.name)
await addPackages(packagesLinkDep, {
workingDir: options.workingDir,
linkDep: true,
workingDir,
link: true,
pure: false
})

Expand Down
12 changes: 7 additions & 5 deletions src/yalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ yargs
describe: 'Add package from yalc repo to the project',
builder: () => {
return yargs
.default('yarn', false)
.boolean(['file', 'dev', 'save-dev', 'link', 'yarn', 'pure'])
.boolean(['link', 'dev', 'save', 'yarn', 'pure'])
.default('link', true)
.default('save', true)
.help(true)
},
handler: argv => {
Expand All @@ -132,10 +133,10 @@ yargs
false
)
return addPackages(argv._.slice(1), {
dev: argv.dev || argv.saveDev,
yarn: argv.yarn,
linkDep: argv.link,
dev: argv.dev,
link: argv.link,
pure: hasPureArg ? argv.pure : undefined,
noSave: !argv.save,
workingDir: process.cwd()
})
}
Expand All @@ -149,6 +150,7 @@ yargs
handler: argv => {
return addPackages(argv._.slice(1), {
link: true,
noSave: true,
workingDir: process.cwd()
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('Yalc package manager', function() {
before(() => {
return addPackages([values.depPackage], {
workingDir: projectDir,
linkDep: true
link: true
})
})
it('copies package to .yalc folder', () => {
Expand Down

0 comments on commit d7a4f56

Please sign in to comment.