Skip to content

Commit b2254b4

Browse files
committed
consolidate weak and strict lockfile installing logic - fixes #86
1 parent a070fce commit b2254b4

File tree

3 files changed

+42
-89
lines changed

3 files changed

+42
-89
lines changed

src/cli/commands/check.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export async function run(
3232
}
3333

3434
let lockfile = await Lockfile.fromDirectory(config.cwd, reporter, {
35-
silent: true
35+
silent: true,
36+
strict: true
3637
});
3738

3839
let install = new Install("update", flags, args, config, reporter, lockfile, true);

src/cli/commands/install.js

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -159,49 +159,6 @@ export class Install {
159159
return [deps, patterns];
160160
}
161161

162-
async fetchResolve(params: FetchResolveParams): Promise<FetchResolveReturn> {
163-
if (this.lockfile.strict) {
164-
return this.fetchResolveStrict(params);
165-
} else {
166-
return this.fetchResolveWeak(params);
167-
}
168-
}
169-
170-
async fetchResolveStrict({
171-
totalSteps,
172-
patterns,
173-
requests
174-
}: FetchResolveParams): Promise<FetchResolveReturn> {
175-
let totalStepsThis = totalSteps + 2;
176-
177-
this.reporter.step(1, totalStepsThis, "Rehydrating dependency graph", emoji.get("fast_forward"));
178-
await this.resolver.init(requests);
179-
180-
this.reporter.step(2, totalStepsThis, "Fetching packages", emoji.get("package"));
181-
await this.resolver.fetcher.init();
182-
183-
return {
184-
patterns: await this.flatten(patterns),
185-
total: totalStepsThis,
186-
step: 2
187-
};
188-
}
189-
190-
async fetchResolveWeak(
191-
{ totalSteps, patterns, requests }: FetchResolveParams
192-
): Promise<FetchResolveReturn> {
193-
let totalStepsThis = totalSteps + 1;
194-
195-
this.reporter.step(1, totalStepsThis, "Resolving and fetching packages", emoji.get("truck"));
196-
await this.resolver.init(requests);
197-
198-
return {
199-
patterns: await this.flatten(patterns),
200-
total: totalStepsThis,
201-
step: 1
202-
};
203-
}
204-
205162
async init(): Promise<void> {
206163
let [depRequests, rawPatterns] = await this.fetchRequestFromCwd(this.args);
207164

@@ -218,22 +175,20 @@ export class Install {
218175
}
219176

220177
//
221-
let { patterns, step, total } = await this.fetchResolve({
222-
totalSteps: 3,
223-
patterns: rawPatterns,
224-
requests: depRequests
225-
});
178+
this.reporter.step(1, 4, "Resolving and fetching packages", emoji.get("truck"));
179+
await this.resolver.init(depRequests);
180+
let patterns = await this.flatten(rawPatterns);
226181

227182
//
228-
this.reporter.step(++step, total, "Checking package compatibility", emoji.get("white_check_mark"));
183+
this.reporter.step(2, 4, "Checking package compatibility", emoji.get("white_check_mark"));
229184
await this.compatibility.init();
230185

231186
//
232-
this.reporter.step(++step, total, "Linking dependencies", emoji.get("link"));
187+
this.reporter.step(3, 4, "Linking dependencies", emoji.get("link"));
233188
await this.linker.init(patterns);
234189

235190
//
236-
this.reporter.step(++step, total, "Running install scripts", emoji.get("page_with_curl"));
191+
this.reporter.step(4, 4, "Running install scripts", emoji.get("page_with_curl"));
237192
await this.scripts.init();
238193

239194
// fin!

src/package-request.js

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -258,47 +258,44 @@ export default class PackageRequest {
258258
// resolution to fetch the package so we can peek inside of it for a fbkpm.lock
259259
// only do this in strict lockfile mode as otherwise we can just use our root lockfile
260260
let subLockfile = null;
261-
if (!this.resolver.lockfile.strict) {
262-
// get possible mirror path
263-
let offlineMirrorPath = this.config.getOfflineMirrorPath(ref.remote.registry, ref.remote.reference);
264-
265-
// while we're fetching the package we have some idle time to warm the cache with
266-
// registry responses for known dependencies
267-
if (!offlineMirrorPath) {
268-
for (let name in info.dependencies) {
269-
this.warmCacheIfRegistry(`${name}@${info.dependencies[name]}`);
270-
}
271-
}
272261

273-
//
274-
let { package: newInfo, hash, dest } = await this.resolver.fetchingQueue.push(
275-
info.name,
276-
() => this.resolver.fetcher.fetch(ref)
277-
);
278-
279-
// replace resolved remote URL with local path if lockfile is in save mode and we have a path
280-
if (this.resolver.lockfile.save && offlineMirrorPath) {
281-
if (await fs.exists(offlineMirrorPath)) {
282-
remote.resolved = path.relative(
283-
this.config.getOfflineMirrorPath(ref.remote.registry),
284-
offlineMirrorPath
285-
) + `#${ref.remote.hash}`;
286-
}
287-
}
288-
remote.hash = hash;
289-
newInfo.reference = ref;
290-
newInfo.remote = remote;
291-
info = newInfo;
292-
293-
// find and load in fbkpm.lock from this module if it exists
294-
let lockfileLoc = path.join(dest, constants.LOCKFILE_FILENAME);
295-
if (await fs.exists(lockfileLoc)) {
296-
let rawLockfile = await fs.readFile(lockfileLoc);
297-
let lockfileObj = parseLock(rawLockfile);
298-
subLockfile = new Lockfile(lockfileObj, false);
262+
// get possible mirror path
263+
let offlineMirrorPath = this.config.getOfflineMirrorPath(ref.remote.registry, ref.remote.reference);
264+
265+
// while we're fetching the package we have some idle time to warm the cache with
266+
// registry responses for known dependencies
267+
if (!offlineMirrorPath) {
268+
for (let name in info.dependencies) {
269+
this.warmCacheIfRegistry(`${name}@${info.dependencies[name]}`);
299270
}
300271
}
301272

273+
//
274+
let { package: newInfo, hash, dest } = await this.resolver.fetchingQueue.push(
275+
info.name,
276+
() => this.resolver.fetcher.fetch(ref)
277+
);
278+
279+
// replace resolved remote URL with local path if lockfile is in save mode and we have a path
280+
if (this.resolver.lockfile.save && offlineMirrorPath && await fs.exists(offlineMirrorPath)) {
281+
remote.resolved = path.relative(
282+
this.config.getOfflineMirrorPath(ref.remote.registry),
283+
offlineMirrorPath
284+
) + `#${ref.remote.hash}`;
285+
}
286+
remote.hash = hash;
287+
newInfo.reference = ref;
288+
newInfo.remote = remote;
289+
info = newInfo;
290+
291+
// find and load in fbkpm.lock from this module if it exists
292+
let lockfileLoc = path.join(dest, constants.LOCKFILE_FILENAME);
293+
if (await fs.exists(lockfileLoc)) {
294+
let rawLockfile = await fs.readFile(lockfileLoc);
295+
let lockfileObj = parseLock(rawLockfile);
296+
subLockfile = new Lockfile(lockfileObj, false);
297+
}
298+
302299
// start installation of dependencies
303300
let promises = [];
304301
let deps = [];

0 commit comments

Comments
 (0)