From c952203e0df20fca4780f6eed66efcd1b301dbba Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 9 Dec 2017 15:10:53 +0200 Subject: [PATCH] refactor: update package-requester to version 0.3.0 --- package.json | 2 +- shrinkwrap.yaml | 8 +-- src/api/install.ts | 24 +++------ src/install/getIsInstallable.ts | 2 - src/install/installMultiple.ts | 96 +++++++++++++++------------------ src/link/index.ts | 12 ++--- src/link/resolvePeers.ts | 4 +- 7 files changed, 63 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index 000c181d94..36b8b1b8f9 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@pnpm/default-fetcher": "^0.3.0", "@pnpm/default-resolver": "^0.1.0", - "@pnpm/package-requester": "^0.2.0", + "@pnpm/package-requester": "^0.3.0", "@pnpm/types": "^1.2.1", "@types/byline": "^4.2.31", "@types/common-tags": "^1.2.5", diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml index 004d329059..fe7cadcdb4 100644 --- a/shrinkwrap.yaml +++ b/shrinkwrap.yaml @@ -1,7 +1,7 @@ dependencies: '@pnpm/default-fetcher': 0.3.0 '@pnpm/default-resolver': 0.1.0 - '@pnpm/package-requester': 0.2.0 + '@pnpm/package-requester': 0.3.0 '@pnpm/types': 1.2.1 '@types/byline': 4.2.31 '@types/common-tags': 1.4.0 @@ -282,7 +282,7 @@ packages: '@pnpm/logger': ^1.0.0 resolution: integrity: sha512-9Ln3phdOdq0is/iVsqPQdB/JV9qtEi4Dq9kTMzHA1R898bSEsk8G3aSqbNFz6skTVYAuLMyiAdrVtJJ8FqJsgQ== - /@pnpm/package-requester/0.2.0: + /@pnpm/package-requester/0.3.0: dependencies: '@pnpm/types': 1.2.1 '@types/load-json-file': 2.0.7 @@ -309,7 +309,7 @@ packages: peerDependencies: '@pnpm/logger': ^1.0.0 resolution: - integrity: sha512-boW7hvZzg/Od8+1OAP23Tsqk8bWvt8C28am5XcSIiEnfUZk20wk4fsfa9HePA7RopX17dy7Hs7bs5lfAUnhBLg== + integrity: sha512-/yhqgFogVoYOln8vDqRXURCMXj2AeuBFKr2fH6I1+swOgfwuGk+SF28VTzcf8YU5cjvczzfvcKYQS5/t6dw4ig== /@pnpm/tarball-fetcher/0.3.1: dependencies: '@types/mem': 1.1.2 @@ -4853,7 +4853,7 @@ specifiers: '@pnpm/default-fetcher': ^0.3.0 '@pnpm/default-resolver': ^0.1.0 '@pnpm/logger': ^1.0.0 - '@pnpm/package-requester': ^0.2.0 + '@pnpm/package-requester': ^0.3.0 '@pnpm/types': ^1.2.1 '@types/byline': ^4.2.31 '@types/common-tags': ^1.2.5 diff --git a/src/api/install.ts b/src/api/install.ts index b9926919f1..6a03267db2 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -56,9 +56,10 @@ import parseWantedDependencies from '../parseWantedDependencies' import createFetcher from '@pnpm/default-fetcher' import createResolver from '@pnpm/default-resolver' import createPackageRequester, { - PackageContentInfo, + PackageFilesResponse, DirectoryResolution, Resolution, + RequestPackageFunction, } from '@pnpm/package-requester' export type InstalledPackages = { @@ -100,23 +101,13 @@ export type InstallContext = { }[], wantedShrinkwrap: Shrinkwrap, currentShrinkwrap: Shrinkwrap, - requestPackage: Function, //tslint:disable-line - fetchingLocker: { - [pkgId: string]: { - fetchingFiles: Promise, - fetchingPkg: Promise, - calculatingIntegrity: Promise, - }, - }, + requestPackage: RequestPackageFunction, // the IDs of packages that are not installable skipped: Set, tree: {[nodeId: string]: TreeNode}, - storeIndex: Store, force: boolean, prefix: string, - storePath: string, registry: string, - metaCache: Map, depth: number, engineStrict: boolean, nodeVersion: string, @@ -329,11 +320,8 @@ async function installInContext ( nodesToBuild: [], wantedShrinkwrap: ctx.wantedShrinkwrap, currentShrinkwrap: ctx.currentShrinkwrap, - fetchingLocker: {}, skipped: ctx.skipped, tree: {}, - storeIndex: ctx.storeIndex, - storePath: ctx.storePath, registry: ctx.wantedShrinkwrap.registry, force: opts.force, depth: (function () { @@ -355,7 +343,6 @@ async function installInContext ( offline: opts.offline, rawNpmConfig: opts.rawNpmConfig, nodeModules: nodeModulesPath, - metaCache: opts.metaCache, verifyStoreInegrity: opts.verifyStoreIntegrity, engineStrict: opts.engineStrict, nodeVersion: opts.nodeVersion, @@ -365,6 +352,8 @@ async function installInContext ( createFetcher(opts) as {}, // TODO: remove `as {}` { networkConcurrency: opts.networkConcurrency, + storeIndex: ctx.storeIndex, + storePath: ctx.storePath, }, ), } @@ -381,7 +370,6 @@ async function installInContext ( currentDepth: 0, readPackageHook: opts.hooks.readPackage, hasManifestInShrinkwrap, - ignoreFile: opts.ignoreFile, } const nonLinkedPkgs = await pFilter(packagesToInstall, async (wantedDependency: WantedDependency) => { @@ -609,7 +597,7 @@ async function installInContext ( ) // waiting till integrities are saved - await Promise.all(R.values(installCtx.installs).map(installed => installed.calculatingIntegrity)) + await Promise.all(R.values(installCtx.installs).map(installed => installed.generatingIntegrity)) summaryLogger.info(undefined) } diff --git a/src/install/getIsInstallable.ts b/src/install/getIsInstallable.ts index 39d8b65654..d0d70aa206 100644 --- a/src/install/getIsInstallable.ts +++ b/src/install/getIsInstallable.ts @@ -4,12 +4,10 @@ import logger from '@pnpm/logger' import {PackageManifest} from '@pnpm/types' import {installCheckLogger} from '../loggers' import {InstalledPackages} from '../api/install' -import {FetchedPackage} from '@pnpm/package-requester' export default async function getIsInstallable ( pkgId: string, pkg: PackageManifest, - fetchedPkg: FetchedPackage, options: { nodeId: string, installs: InstalledPackages, diff --git a/src/install/installMultiple.ts b/src/install/installMultiple.ts index 922bc8395e..be8a3bc2a9 100644 --- a/src/install/installMultiple.ts +++ b/src/install/installMultiple.ts @@ -6,8 +6,7 @@ import getNpmTarballUrl from 'get-npm-tarball-url' import exists = require('path-exists') import url = require('url') import { - FetchedPackage, - PackageContentInfo, + PackageFilesResponse, Resolution, } from '@pnpm/package-requester' import {InstallContext, InstalledPackages} from '../api/install' @@ -47,8 +46,8 @@ export type InstalledPackage = { prod: boolean, dev: boolean, optional: boolean, - fetchingFiles: Promise, - calculatingIntegrity: Promise, + fetchingFiles: Promise, + generatingIntegrity: Promise, path: string, specRaw: string, name: string, @@ -233,7 +232,6 @@ async function install ( proceed: boolean, readPackageHook?: ReadPackageHook, hasManifestInShrinkwrap: boolean, - ignoreFile?: (filename: string) => boolean, } ): Promise { const keypath = options.keypath || [] @@ -265,45 +263,40 @@ async function install ( pkg: loggedPkg, }) - const fetchedPkg = await ctx.requestPackage(wantedDependency, { + const pkgResponse = await ctx.requestPackage(wantedDependency, { loggedPkg, update: options.update, - fetchingLocker: ctx.fetchingLocker, registry, prefix: ctx.prefix, - storePath: ctx.storePath, - metaCache: ctx.metaCache, shrinkwrapResolution: options.shrinkwrapResolution, - pkgId: options.pkgId, + currentPkgId: options.pkgId, offline: ctx.offline, - storeIndex: ctx.storeIndex, verifyStoreIntegrity: ctx.verifyStoreInegrity, downloadPriority: -options.currentDepth, - ignore: options.ignoreFile, }) - if (fetchedPkg.isLocal) { - const pkg = fetchedPkg.pkg + if (pkgResponse.isLocal) { + const pkg = await pkgResponse.fetchingManifest if (options.currentDepth > 0) { logger.warn(`Ignoring file dependency because it is not a root dependency ${wantedDependency}`) } else { ctx.localPackages.push({ alias: wantedDependency.alias || pkg.name, - id: fetchedPkg.id, + id: pkgResponse.id, specRaw: wantedDependency.raw, name: pkg.name, version: pkg.version, dev: wantedDependency.dev, optional: wantedDependency.optional, - resolution: fetchedPkg.resolution, - normalizedPref: fetchedPkg.normalizedPref, + resolution: pkgResponse.resolution, + normalizedPref: pkgResponse.normalizedPref, }) } - logStatus({status: 'downloaded_manifest', pkgId: fetchedPkg.id, pkgVersion: pkg.version}) + logStatus({status: 'downloaded_manifest', pkgId: pkgResponse.id, pkgVersion: pkg.version}) return null } - if (options.parentNodeId.indexOf(`:${dependentId}:${fetchedPkg.id}:`) !== -1) { + if (options.parentNodeId.indexOf(`:${dependentId}:${pkgResponse.id}:`) !== -1) { return null } @@ -327,36 +320,36 @@ async function install ( } else { try { pkg = options.readPackageHook - ? options.readPackageHook(await fetchedPkg.fetchingPkg) - : await fetchedPkg.fetchingPkg + ? options.readPackageHook(await pkgResponse.fetchingManifest) + : await pkgResponse.fetchingManifest } catch (err) { // avoiding unhandled promise rejections - fetchedPkg.calculatingIntegrity.catch((err: Error) => {}) - fetchedPkg.fetchingFiles.catch((err: Error) => {}) + pkgResponse.generatingIntegrity.catch((err: Error) => {}) + pkgResponse.fetchingFiles.catch((err: Error) => {}) throw err } } - if (options.currentDepth === 0 && fetchedPkg.latest && fetchedPkg.latest !== pkg.version) { - ctx.outdatedPkgs[fetchedPkg.id] = fetchedPkg.latest + if (options.currentDepth === 0 && pkgResponse.latest && pkgResponse.latest !== pkg.version) { + ctx.outdatedPkgs[pkgResponse.id] = pkgResponse.latest } if (pkg.deprecated) { deprecationLogger.warn({ pkgName: pkg.name, pkgVersion: pkg.version, - pkgId: fetchedPkg.id, + pkgId: pkgResponse.id, deprecated: pkg.deprecated, depth: options.currentDepth, }) } - logStatus({status: 'downloaded_manifest', pkgId: fetchedPkg.id, pkgVersion: pkg.version}) + logStatus({status: 'downloaded_manifest', pkgId: pkgResponse.id, pkgVersion: pkg.version}) // using colon as it will never be used inside a package ID - const nodeId = `${options.parentNodeId}${fetchedPkg.id}:` + const nodeId = `${options.parentNodeId}${pkgResponse.id}:` const currentIsInstallable = ( ctx.force || - await getIsInstallable(fetchedPkg.id, pkg, fetchedPkg, { + await getIsInstallable(pkgResponse.id, pkg, { nodeId, installs: ctx.installs, optional: wantedDependency.optional, @@ -368,28 +361,28 @@ async function install ( const installable = parentIsInstallable && currentIsInstallable if (installable) { - ctx.skipped.delete(fetchedPkg.id) + ctx.skipped.delete(pkgResponse.id) } - if (!ctx.installs[fetchedPkg.id]) { + if (!ctx.installs[pkgResponse.id]) { if (!installable) { // optional dependencies are resolved for consistent shrinkwrap.yaml files // but installed only on machines that are supported by the package - ctx.skipped.add(fetchedPkg.id) + ctx.skipped.add(pkgResponse.id) } const peerDependencies = peerDependenciesWithoutOwn(pkg) - ctx.installs[fetchedPkg.id] = { - id: fetchedPkg.id, - resolution: fetchedPkg.resolution, + ctx.installs[pkgResponse.id] = { + id: pkgResponse.id, + resolution: pkgResponse.resolution, optional: wantedDependency.optional, name: pkg.name, version: pkg.version, prod: !wantedDependency.dev && !wantedDependency.optional, dev: wantedDependency.dev, - fetchingFiles: fetchedPkg.fetchingFiles, - calculatingIntegrity: fetchedPkg.calculatingIntegrity, - path: fetchedPkg.path, + fetchingFiles: pkgResponse.fetchingFiles, + generatingIntegrity: pkgResponse.generatingIntegrity, + path: pkgResponse.inStoreLocation, specRaw: wantedDependency.raw, peerDependencies: peerDependencies || {}, optionalDependencies: new Set(R.keys(pkg.optionalDependencies)), @@ -411,11 +404,11 @@ async function install ( parentIsInstallable: installable, currentDepth: options.currentDepth + 1, parentNodeId: nodeId, - keypath: options.keypath.concat([ fetchedPkg.id ]), - resolvedDependencies: fetchedPkg.id !== options.pkgId + keypath: options.keypath.concat([ pkgResponse.id ]), + resolvedDependencies: pkgResponse.id !== options.pkgId ? undefined : options.resolvedDependencies, - preferedDependencies: fetchedPkg.id !== options.pkgId + preferedDependencies: pkgResponse.id !== options.pkgId ? options.resolvedDependencies : undefined, optionalDependencyNames: options.optionalDependencyNames, @@ -423,15 +416,14 @@ async function install ( readPackageHook: options.readPackageHook, hasManifestInShrinkwrap: options.hasManifestInShrinkwrap, useManifestInfoFromShrinkwrap, - ignoreFile: options.ignoreFile, } ) - ctx.childrenByParentId[fetchedPkg.id] = children.map(child => ({ + ctx.childrenByParentId[pkgResponse.id] = children.map(child => ({ alias: child.alias, pkgId: child.pkgId, })) ctx.tree[nodeId] = { - pkg: ctx.installs[fetchedPkg.id], + pkg: ctx.installs[pkgResponse.id], children: children.reduce((children, child) => { children[child.alias] = child.nodeId return children @@ -440,30 +432,30 @@ async function install ( installable, } } else { - ctx.installs[fetchedPkg.id].prod = ctx.installs[fetchedPkg.id].prod || !wantedDependency.dev && !wantedDependency.optional - ctx.installs[fetchedPkg.id].dev = ctx.installs[fetchedPkg.id].dev || wantedDependency.dev - ctx.installs[fetchedPkg.id].optional = ctx.installs[fetchedPkg.id].optional && wantedDependency.optional + ctx.installs[pkgResponse.id].prod = ctx.installs[pkgResponse.id].prod || !wantedDependency.dev && !wantedDependency.optional + ctx.installs[pkgResponse.id].dev = ctx.installs[pkgResponse.id].dev || wantedDependency.dev + ctx.installs[pkgResponse.id].optional = ctx.installs[pkgResponse.id].optional && wantedDependency.optional ctx.nodesToBuild.push({ alias: wantedDependency.alias || pkg.name, nodeId, - pkg: ctx.installs[fetchedPkg.id], + pkg: ctx.installs[pkgResponse.id], depth: options.currentDepth, installable, }) } // we need this for saving to package.json if (options.currentDepth === 0) { - ctx.installs[fetchedPkg.id].specRaw = wantedDependency.raw + ctx.installs[pkgResponse.id].specRaw = wantedDependency.raw } - logStatus({status: 'dependencies_installed', pkgId: fetchedPkg.id}) + logStatus({status: 'dependencies_installed', pkgId: pkgResponse.id}) return { alias: wantedDependency.alias || pkg.name, nodeId, - pkgId: fetchedPkg.id, - normalizedPref: options.currentDepth === 0 ? fetchedPkg.normalizedPref : undefined, + pkgId: pkgResponse.id, + normalizedPref: options.currentDepth === 0 ? pkgResponse.normalizedPref : undefined, } } diff --git a/src/link/index.ts b/src/link/index.ts index c6e9434d83..936f9c5005 100644 --- a/src/link/index.ts +++ b/src/link/index.ts @@ -10,7 +10,7 @@ import {InstalledPackages, TreeNode} from '../api/install' import linkBins, {linkPkgBins} from './linkBins' import {PackageJson, Dependencies} from '@pnpm/types' import {Store} from 'package-store' -import {Resolution, PackageContentInfo} from '@pnpm/package-requester' +import {Resolution, PackageFilesResponse} from '@pnpm/package-requester' import resolvePeers, {DependencyTreeNode, DependencyTreeNodeMap} from './resolvePeers' import logStatus from '../logging/logInstallStatus' import updateShrinkwrap from './updateShrinkwrap' @@ -263,7 +263,7 @@ async function linkNewPackages ( const limitLinking = pLimit(16) async function linkAllPkgs ( - linkPkg: (fetchResult: PackageContentInfo, dependency: DependencyTreeNode, opts: { + linkPkg: (fetchResult: PackageFilesResponse, dependency: DependencyTreeNode, opts: { force: boolean, baseNodeModules: string, }) => Promise, @@ -359,7 +359,7 @@ async function linkAllModules ( } async function linkPkg ( - fetchResult: PackageContentInfo, + filesResponse: PackageFilesResponse, dependency: DependencyTreeNode, opts: { force: boolean, @@ -368,13 +368,13 @@ async function linkPkg ( ) { const pkgJsonPath = path.join(dependency.hardlinkedLocation, 'package.json') - if (fetchResult.isNew || opts.force || !await exists(pkgJsonPath) || !await pkgLinkedToStore(pkgJsonPath, dependency)) { - await linkIndexedDir(dependency.path, dependency.hardlinkedLocation, fetchResult.index) + if (!filesResponse.fromStore || opts.force || !await exists(pkgJsonPath) || !await pkgLinkedToStore(pkgJsonPath, dependency)) { + await linkIndexedDir(dependency.path, dependency.hardlinkedLocation, filesResponse.index) } } async function copyPkg ( - fetchResult: PackageContentInfo, + filesResponse: PackageFilesResponse, dependency: DependencyTreeNode, opts: { force: boolean, diff --git a/src/link/resolvePeers.ts b/src/link/resolvePeers.ts index e9f6b95107..2759889d64 100644 --- a/src/link/resolvePeers.ts +++ b/src/link/resolvePeers.ts @@ -3,7 +3,7 @@ import { } from 'package-store' import { Resolution, - PackageContentInfo, + PackageFilesResponse, } from '@pnpm/package-requester' import {Dependencies} from '@pnpm/types' import R = require('ramda') @@ -22,7 +22,7 @@ export type DependencyTreeNode = { hasBundledDependencies: boolean, path: string, modules: string, - fetchingFiles: Promise, + fetchingFiles: Promise, resolution: Resolution, hardlinkedLocation: string, children: {[alias: string]: string},