Skip to content

Commit fb993c9

Browse files
committed
feat: add --force flag to add/link/update
Tell yalc to re-install every package in its lockfile. No matter what. This will eventually be replaced by a smarter "addPackages" function that checks node_modules even if the package exists in ".yalc" already.
1 parent d8af91e commit fb993c9

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/add.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface AddPackagesOptions {
2020
dev?: boolean
2121
link?: boolean
2222
pure?: boolean
23+
force?: boolean
2324
noSave?: boolean
2425
workingDir: string
2526
}
@@ -135,7 +136,10 @@ export const addPackages = async (
135136
name
136137
)
137138

138-
if (signature === readSignatureFile(localPackageDir)) {
139+
if (
140+
!options.force &&
141+
signature === readSignatureFile(localPackageDir)
142+
) {
139143
console.log(
140144
`"${packageName}" already exists in the local ".yalc" directory`
141145
)

src/update.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
export interface UpdatePackagesOptions {
1616
workingDir: string
1717
noInstallationsRemove?: boolean
18+
force?: boolean
1819
safe?: boolean
1920
yarn?: boolean
2021
}
@@ -60,7 +61,10 @@ export const updatePackages = async (
6061
}))
6162

6263
const packagesFiles = lockPackages.filter(p => p.file).map(p => p.name)
63-
await addPackages(packagesFiles, { workingDir })
64+
await addPackages(packagesFiles, {
65+
workingDir,
66+
force: options.force
67+
})
6468

6569
const packagesLinks = lockPackages
6670
.filter(p => !p.file && !p.link && !p.pure)
@@ -70,14 +74,16 @@ export const updatePackages = async (
7074
workingDir,
7175
link: true,
7276
noSave: true,
73-
pure: false
77+
pure: false,
78+
force: options.force
7479
})
7580

7681
const packagesLinkDep = lockPackages.filter(p => p.link).map(p => p.name)
7782
await addPackages(packagesLinkDep, {
7883
workingDir,
7984
link: true,
80-
pure: false
85+
pure: false,
86+
force: options.force
8187
})
8288

8389
const packagesPure = lockPackages.filter(p => p.pure).map(p => p.name)

src/yalc.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ yargs
119119
describe: 'Add package from yalc repo to the project',
120120
builder: () => {
121121
return yargs
122-
.boolean(['link', 'dev', 'save', 'pure'])
122+
.boolean(['link', 'dev', 'save', 'pure', 'force'])
123123
.default('link', true)
124124
.default('save', true)
125125
.alias('D', 'dev')
126+
.alias('f', 'force')
126127
.help(true)
127128
},
128129
handler: argv => {
@@ -134,6 +135,7 @@ yargs
134135
dev: argv.dev,
135136
link: argv.link,
136137
pure: hasPureArg ? argv.pure : undefined,
138+
force: argv.force,
137139
noSave: !argv.save,
138140
workingDir: process.cwd()
139141
})
@@ -143,10 +145,14 @@ yargs
143145
command: 'link',
144146
describe: 'Link package from yalc repo to the project',
145147
builder: () => {
146-
return yargs.help(true)
148+
return yargs
149+
.boolean(['force'])
150+
.alias('f', 'force')
151+
.help(true)
147152
},
148153
handler: argv => {
149154
return addPackages(argv._.slice(1), {
155+
force: argv.force,
150156
link: true,
151157
noSave: true,
152158
workingDir: process.cwd()
@@ -157,11 +163,15 @@ yargs
157163
command: 'update',
158164
describe: 'Update packages from yalc repo',
159165
builder: () => {
160-
return yargs.help(true)
166+
return yargs
167+
.boolean(['force'])
168+
.alias('f', 'force')
169+
.help(true)
161170
},
162171
handler: argv => {
163172
return updatePackages(argv._.slice(1), {
164-
workingDir: process.cwd()
173+
workingDir: process.cwd(),
174+
force: argv.force
165175
})
166176
}
167177
})

0 commit comments

Comments
 (0)