Skip to content

Commit d7a4f56

Browse files
committed
refactor: "yalc add" flags
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"
1 parent efe5889 commit d7a4f56

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/add.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ const ensureSymlinkSync = fs.ensureSymlinkSync as typeof fs.symlinkSync
2020
export interface AddPackagesOptions {
2121
dev?: boolean
2222
link?: boolean
23-
linkDep?: boolean
2423
yarn?: boolean
25-
safe?: boolean
2624
pure?: boolean
25+
noSave?: boolean
2726
workingDir: string
2827
}
2928

@@ -71,7 +70,8 @@ export const addPackages = async (
7170
return
7271
}
7372
const doPure =
74-
options.pure === false ? false : options.pure || !!localPkg.workspaces
73+
options.pure !== undefined ? options.pure : !!localPkg.workspaces
74+
7575
const addedInstalls = packages
7676
.map(packageName => {
7777
const { name, version = '' } = parsePackageName(packageName)
@@ -127,19 +127,15 @@ export const addPackages = async (
127127
}
128128
if (!doPure) {
129129
const destModulesDir = join(workingDir, 'node_modules', name)
130-
if (options.link || options.linkDep || isSymlink(destModulesDir)) {
131-
fs.removeSync(destModulesDir)
132-
}
133-
134-
if (options.link || options.linkDep) {
130+
fs.removeSync(destModulesDir)
131+
if (options.link) {
135132
ensureSymlinkSync(destYalcCopyDir, destModulesDir, 'junction')
136133
} else {
137-
emptyDirExcludeNodeModules(destModulesDir)
138134
fs.copySync(destYalcCopyDir, destModulesDir)
139135
}
140136

141-
if (!options.link) {
142-
const protocol = options.linkDep ? 'link:' : 'file:'
137+
if (!options.noSave) {
138+
const protocol = options.link ? 'link:' : 'file:'
143139
const localAddress =
144140
protocol + values.yalcPackagesFolder + '/' + pkg.name
145141

@@ -174,7 +170,8 @@ export const addPackages = async (
174170
replacedVersion =
175171
replacedVersion == localAddress ? '' : replacedVersion
176172
}
177-
const addedAction = options.link ? 'linked' : 'added'
173+
174+
const addedAction = options.noSave ? 'linked' : 'added'
178175
console.log(
179176
`Package ${pkg.name}@${
180177
pkg.version
@@ -204,8 +201,8 @@ export const addPackages = async (
204201
version: i!.version,
205202
replaced: i!.replaced,
206203
pure: doPure,
207-
file: !options.link && !options.linkDep && !doPure,
208-
link: options.linkDep && !doPure,
204+
file: !options.link && !doPure,
205+
link: options.link && !doPure,
209206
signature: i.signature
210207
})),
211208
{ workingDir: options.workingDir }

src/update.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ export const updatePackages = async (
5959
await addPackages(packagesLinks, {
6060
workingDir: options.workingDir,
6161
link: true,
62+
noSave: true,
6263
pure: false
6364
})
6465

6566
const packagesLinkDep = lockPackages.filter(p => p.link).map(p => p.name)
6667
await addPackages(packagesLinkDep, {
67-
workingDir: options.workingDir,
68-
linkDep: true,
68+
workingDir,
69+
link: true,
6970
pure: false
7071
})
7172

src/yalc.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ yargs
122122
describe: 'Add package from yalc repo to the project',
123123
builder: () => {
124124
return yargs
125-
.default('yarn', false)
126-
.boolean(['file', 'dev', 'save-dev', 'link', 'yarn', 'pure'])
125+
.boolean(['link', 'dev', 'save', 'yarn', 'pure'])
126+
.default('link', true)
127+
.default('save', true)
127128
.help(true)
128129
},
129130
handler: argv => {
@@ -132,10 +133,10 @@ yargs
132133
false
133134
)
134135
return addPackages(argv._.slice(1), {
135-
dev: argv.dev || argv.saveDev,
136-
yarn: argv.yarn,
137-
linkDep: argv.link,
136+
dev: argv.dev,
137+
link: argv.link,
138138
pure: hasPureArg ? argv.pure : undefined,
139+
noSave: !argv.save,
139140
workingDir: process.cwd()
140141
})
141142
}
@@ -149,6 +150,7 @@ yargs
149150
handler: argv => {
150151
return addPackages(argv._.slice(1), {
151152
link: true,
153+
noSave: true,
152154
workingDir: process.cwd()
153155
})
154156
}

test/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ describe('Yalc package manager', function() {
379379
before(() => {
380380
return addPackages([values.depPackage], {
381381
workingDir: projectDir,
382-
linkDep: true
382+
link: true
383383
})
384384
})
385385
it('copies package to .yalc folder', () => {

0 commit comments

Comments
 (0)