Skip to content

Commit

Permalink
feat: don't skip checking of available packages
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Feb 14, 2017
1 parent bcf5958 commit 0bf7c24
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 85 deletions.
31 changes: 0 additions & 31 deletions src/install/fetch.ts
Expand Up @@ -7,7 +7,6 @@ import resolve, {Resolution, PackageSpec} from '../resolve'
import mkdirp from '../fs/mkdirp'
import readPkg from '../fs/readPkg'
import exists = require('exists-file')
import isAvailable from './isAvailable'
import memoize, {MemoizedFunc} from '../memoize'
import {Package} from '../types'
import {Got} from '../network/got'
Expand All @@ -24,14 +23,12 @@ export type FetchedPackage = {
path: string,
srcPath?: string,
id: string,
fromCache: boolean,
abort(): Promise<void>,
}

export default async function fetch (
ctx: InstallContext,
spec: PackageSpec,
modules: string,
options: {
linkLocal: boolean,
force: boolean,
Expand All @@ -56,12 +53,6 @@ export default async function fetch (
let fetchingPkg = null
let resolution = options.shrinkwrapResolution
let pkgId = options.pkgId
if (!resolution && !options.force) {
// it might be a bundleDependency, in which case, don't bother
if (await isAvailable(spec, modules)) {
return await saveCachedResolution()
}
}
if (!resolution || options.update) {
const resolveResult = await resolve(spec, {
loggedPkg,
Expand Down Expand Up @@ -103,7 +94,6 @@ export default async function fetch (
fetchingPkg,
fetchingFiles,
id,
fromCache: false,
path: target,
srcPath: resolution.type == 'directory'
? resolution.root
Expand All @@ -120,27 +110,6 @@ export default async function fetch (
logStatus({status: 'error', pkg: loggedPkg})
throw err
}

async function saveCachedResolution (): Promise<FetchedPackage> {
const target = path.join(modules, spec.name)
const stat: Stats = await fs.lstat(target)
if (stat.isSymbolicLink()) {
const linkPath = await fs.readlink(target)
return save(path.resolve(linkPath, target))
}
return save(target)

async function save (fullpath: string): Promise<FetchedPackage> {
return {
fetchingPkg: readPkg(fullpath),
fetchingFiles: Promise.resolve(false), // this property can be ignored by cached packages at all
id: path.basename(fullpath),
fromCache: true,
path: fullpath,
abort: () => Promise.resolve(),
}
}
}
}

async function fetchToStore (opts: {
Expand Down
20 changes: 9 additions & 11 deletions src/install/installMultiple.ts
Expand Up @@ -68,8 +68,8 @@ export default async function installAll (
}, {})

const installedPkgs: InstalledPackage[] = Array.prototype.concat.apply([], await Promise.all([
installMultiple(ctx, nonOptionalDependencies, modules, Object.assign({}, options, {optional: false})),
installMultiple(ctx, optionalDependencies, modules, Object.assign({}, options, {optional: true})),
installMultiple(ctx, nonOptionalDependencies, Object.assign({}, options, {optional: false})),
installMultiple(ctx, optionalDependencies, Object.assign({}, options, {optional: true})),
]))

if (options.fetchingFiles) {
Expand All @@ -79,11 +79,7 @@ export default async function installAll (
await mkdirp(modules)
await Promise.all(
installedPkgs
.filter(subdep => !subdep.fromCache)
.map(async function (subdep) {
if (ctx.installationSequence.indexOf(subdep.id) === -1) {
ctx.installationSequence.push(subdep.id)
}
const dest = path.join(modules, subdep.pkg.name)
await symlinkDir(subdep.hardlinkedLocation, dest)
})
Expand All @@ -95,7 +91,6 @@ export default async function installAll (
async function installMultiple (
ctx: InstallContext,
pkgsMap: Dependencies,
modules: string,
options: {
linkLocal: boolean,
force: boolean,
Expand Down Expand Up @@ -131,7 +126,7 @@ async function installMultiple (
options.resolvedDependencies[spec.name]
const dependencyShrinkwrap = pkgId && ctx.shrinkwrap.packages[pkgId]
try {
const pkg = await install(spec, modules, ctx, Object.assign({}, options, {
const pkg = await install(spec, ctx, Object.assign({}, options, {
pkgId,
dependencyShrinkwrap,
}))
Expand Down Expand Up @@ -159,7 +154,6 @@ async function installMultiple (

async function install (
spec: PackageSpec,
modules: string,
ctx: InstallContext,
options: {
linkLocal: boolean,
Expand All @@ -184,7 +178,7 @@ async function install (
const keypath = options.keypath || []
const update = keypath.length <= options.depth

const fetchedPkg = await fetch(ctx, spec, modules, Object.assign({}, options, {
const fetchedPkg = await fetch(ctx, spec, Object.assign({}, options, {
update,
shrinkwrapResolution: options.dependencyShrinkwrap && options.dependencyShrinkwrap.resolution,
}))
Expand All @@ -206,7 +200,7 @@ async function install (
modules: realModules,
})

if (dependency.fromCache || keypath.indexOf(dependency.id) !== -1) {
if (keypath.indexOf(dependency.id) !== -1) {
return dependency
}

Expand Down Expand Up @@ -244,6 +238,10 @@ async function install (
await rimraf(stage)
await hardlinkDir(dependency.path, stage)
await fs.rename(stage, dependency.hardlinkedLocation)

if (ctx.installationSequence.indexOf(dependency.id) === -1) {
ctx.installationSequence.push(dependency.id)
}
}

async function pkgLinkedToStore () {
Expand Down
42 changes: 0 additions & 42 deletions src/install/isAvailable.ts

This file was deleted.

1 change: 0 additions & 1 deletion tsconfig.json
Expand Up @@ -61,7 +61,6 @@
"src/install/fetch.ts",
"src/install/fetchResolution.ts",
"src/install/installMultiple.ts",
"src/install/isAvailable.ts",
"src/install/linkBins.ts",
"src/install/linkPeers.ts",
"src/install/postInstall.ts",
Expand Down

0 comments on commit 0bf7c24

Please sign in to comment.