refactor: remove prefix from store-controller-types
This commit is contained in:
18 files changed
+138
-142
No files matched your search
@@ -3,7 +3,7 @@ import { IntegrityMap } from 'ssri'
|
||||
|
||||
export interface FetchOptions {
|
||||
cachedTarballLocation: string,
|
||||
prefix: string,
|
||||
lockfileDir: string,
|
||||
onStart?: (totalSize: number | null, attempt: number) => void,
|
||||
onProgress?: (downloaded: number) => void,
|
||||
}
|
||||
|
||||
@@ -206,7 +206,6 @@ export default async (opts: HeadlessOptions) => {
|
||||
...opts,
|
||||
importerIds: opts.importers.map(({ id }) => id),
|
||||
lockfileDir,
|
||||
prefix: lockfileDir,
|
||||
skipped,
|
||||
virtualStoreDir,
|
||||
} as LockfileToDepGraphOptions,
|
||||
@@ -263,11 +262,11 @@ export default async (opts: HeadlessOptions) => {
|
||||
|
||||
await Promise.all(opts.importers.map(async ({ id, manifest, modulesDir, prefix }) => {
|
||||
await linkRootPackages(filteredLockfile, {
|
||||
importerDir: prefix,
|
||||
importerId: id,
|
||||
importerModulesDir: modulesDir,
|
||||
importers: opts.importers,
|
||||
lockfileDir,
|
||||
prefix,
|
||||
registries: opts.registries,
|
||||
rootDependencies: directDependenciesByImporterId[id],
|
||||
})
|
||||
@@ -387,11 +386,11 @@ async function linkRootPackages (
|
||||
lockfile: Lockfile,
|
||||
opts: {
|
||||
registries: Registries,
|
||||
importerDir: string,
|
||||
importerId: string,
|
||||
importerModulesDir: string,
|
||||
importers: Array<{ id: string, manifest: ImporterManifest }>,
|
||||
lockfileDir: string,
|
||||
prefix: string,
|
||||
rootDependencies: {[alias: string]: string},
|
||||
},
|
||||
) {
|
||||
@@ -411,7 +410,7 @@ async function linkRootPackages (
|
||||
if (allDeps[alias].startsWith('link:')) {
|
||||
const isDev = lockfileImporter.devDependencies?.[alias]
|
||||
const isOptional = lockfileImporter.optionalDependencies?.[alias]
|
||||
const packageDir = path.join(opts.prefix, allDeps[alias].substr(5))
|
||||
const packageDir = path.join(opts.importerDir, allDeps[alias].substr(5))
|
||||
const linkedPackage = await (async () => {
|
||||
const importerId = getLockfileImporterId(opts.lockfileDir, packageDir)
|
||||
if (importerManifestsByImporterId[importerId]) {
|
||||
@@ -425,7 +424,7 @@ async function linkRootPackages (
|
||||
isOptional && 'optionalDependencies' ||
|
||||
'dependencies',
|
||||
linkedPackage,
|
||||
prefix: opts.prefix,
|
||||
prefix: opts.importerDir,
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -456,7 +455,7 @@ async function linkRootPackages (
|
||||
realName: pkgInfo.name,
|
||||
version: pkgInfo.version,
|
||||
},
|
||||
prefix: opts.prefix,
|
||||
prefix: opts.importerDir,
|
||||
})
|
||||
}),
|
||||
)
|
||||
@@ -471,7 +470,6 @@ interface LockfileToDepGraphOptions {
|
||||
skipped: Set<string>,
|
||||
storeController: StoreController,
|
||||
storeDir: string,
|
||||
prefix: string,
|
||||
registries: Registries,
|
||||
sideEffectsCacheRead: boolean,
|
||||
virtualStoreDir: string,
|
||||
@@ -524,8 +522,8 @@ async function lockfileToDepGraph (
|
||||
})
|
||||
let fetchResponse = opts.storeController.fetchPackage({
|
||||
force: false,
|
||||
lockfileDir: opts.lockfileDir,
|
||||
pkgId: packageId,
|
||||
prefix: opts.prefix,
|
||||
resolution,
|
||||
})
|
||||
if (fetchResponse instanceof Promise) fetchResponse = await fetchResponse
|
||||
@@ -569,7 +567,7 @@ async function lockfileToDepGraph (
|
||||
independentLeaves: opts.independentLeaves,
|
||||
lockfileDir: opts.lockfileDir,
|
||||
pkgSnapshotsByRelDepPaths: lockfile.packages,
|
||||
prefix: opts.prefix,
|
||||
prefix: opts.lockfileDir,
|
||||
registries: opts.registries,
|
||||
sideEffectsCacheRead: opts.sideEffectsCacheRead,
|
||||
skipped: opts.skipped,
|
||||
|
||||
@@ -16,7 +16,7 @@ import parsePref from './parsePref'
|
||||
export default async function resolveLocal (
|
||||
wantedDependency: {pref: string},
|
||||
opts: {
|
||||
prefix: string,
|
||||
importerDir: string,
|
||||
lockfileDir?: string,
|
||||
},
|
||||
): Promise<
|
||||
@@ -32,7 +32,7 @@ export default async function resolveLocal (
|
||||
)
|
||||
) | null
|
||||
> {
|
||||
const spec = parsePref(wantedDependency.pref, opts.prefix, opts.lockfileDir || opts.prefix)
|
||||
const spec = parsePref(wantedDependency.pref, opts.importerDir, opts.lockfileDir || opts.importerDir)
|
||||
if (!spec) return null
|
||||
|
||||
if (spec.type === 'file') {
|
||||
|
||||
@@ -19,11 +19,11 @@ export interface LocalPackageSpec {
|
||||
|
||||
export default function parsePref (
|
||||
pref: string,
|
||||
importerPrefix: string,
|
||||
importerDir: string,
|
||||
lockfileDir: string,
|
||||
): LocalPackageSpec | null {
|
||||
if (pref.startsWith('link:')) {
|
||||
return fromLocal(pref, importerPrefix, lockfileDir, 'directory')
|
||||
return fromLocal(pref, importerDir, lockfileDir, 'directory')
|
||||
}
|
||||
if (pref.endsWith('.tgz')
|
||||
|| pref.endsWith('.tar.gz')
|
||||
@@ -33,7 +33,7 @@ export default function parsePref (
|
||||
|| isFilespec.test(pref)
|
||||
) {
|
||||
const type = isFilename.test(pref) ? 'file' : 'directory'
|
||||
return fromLocal(pref, importerPrefix, lockfileDir, type)
|
||||
return fromLocal(pref, importerDir, lockfileDir, type)
|
||||
}
|
||||
if (pref.startsWith('path:')) {
|
||||
const err = new PnpmError('PATH_IS_UNSUPPORTED_PROTOCOL', 'Local dependencies via `path:` protocol are not supported. ' +
|
||||
@@ -49,12 +49,10 @@ export default function parsePref (
|
||||
|
||||
function fromLocal (
|
||||
pref: string,
|
||||
importerPrefix: string,
|
||||
importerDir: string,
|
||||
lockfileDir: string,
|
||||
type: 'file' | 'directory',
|
||||
): LocalPackageSpec {
|
||||
if (!importerPrefix) importerPrefix = process.cwd()
|
||||
|
||||
const spec = pref.replace(/\\/g, '/')
|
||||
.replace(/^(file|link):[/]*([A-Za-z]:)/, '$2') // drive name paths on windows
|
||||
.replace(/^(file|link):(?:[/]*([~./]))?/, '$2')
|
||||
@@ -67,16 +65,16 @@ function fromLocal (
|
||||
fetchSpec = resolvePath(os.homedir(), spec.slice(2))
|
||||
normalizedPref = `${protocol}${spec}`
|
||||
} else {
|
||||
fetchSpec = resolvePath(importerPrefix, spec)
|
||||
fetchSpec = resolvePath(importerDir, spec)
|
||||
if (isAbsolute(spec)) {
|
||||
normalizedPref = `${protocol}${spec}`
|
||||
} else {
|
||||
normalizedPref = `${protocol}${path.relative(importerPrefix, fetchSpec)}`
|
||||
normalizedPref = `${protocol}${path.relative(importerDir, fetchSpec)}`
|
||||
}
|
||||
}
|
||||
|
||||
const dependencyPath = normalize(path.relative(importerPrefix, fetchSpec))
|
||||
const id = type === 'directory' || importerPrefix === lockfileDir
|
||||
const dependencyPath = normalize(path.relative(importerDir, fetchSpec))
|
||||
const id = type === 'directory' || importerDir === lockfileDir
|
||||
? `${protocol}${dependencyPath}`
|
||||
: `${protocol}${normalize(path.relative(lockfileDir, fetchSpec))}`
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import path = require('path')
|
||||
import test = require('tape')
|
||||
|
||||
test('resolve directory', async t => {
|
||||
const resolveResult = await resolveFromLocal({ pref: '..' }, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal({ pref: '..' }, { importerDir: __dirname })
|
||||
t.equal(resolveResult!.id, 'link:..')
|
||||
t.equal(resolveResult!.normalizedPref, 'link:..')
|
||||
t.equal(resolveResult!['manifest']!.name, '@pnpm/local-resolver')
|
||||
@@ -14,7 +14,7 @@ test('resolve directory', async t => {
|
||||
})
|
||||
|
||||
test('resolve directory specified using the file: protocol', async t => {
|
||||
const resolveResult = await resolveFromLocal({ pref: 'file:..' }, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal({ pref: 'file:..' }, { importerDir: __dirname })
|
||||
t.equal(resolveResult!.id, 'link:..')
|
||||
t.equal(resolveResult!.normalizedPref, 'link:..')
|
||||
t.equal(resolveResult!['manifest']!.name, '@pnpm/local-resolver')
|
||||
@@ -24,7 +24,7 @@ test('resolve directory specified using the file: protocol', async t => {
|
||||
})
|
||||
|
||||
test('resolve directoty specified using the link: protocol', async t => {
|
||||
const resolveResult = await resolveFromLocal({ pref: 'link:..' }, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal({ pref: 'link:..' }, { importerDir: __dirname })
|
||||
t.equal(resolveResult!.id, 'link:..')
|
||||
t.equal(resolveResult!.normalizedPref, 'link:..')
|
||||
t.equal(resolveResult!['manifest']!.name, '@pnpm/local-resolver')
|
||||
@@ -35,7 +35,7 @@ test('resolve directoty specified using the link: protocol', async t => {
|
||||
|
||||
test('resolve file', async t => {
|
||||
const wantedDependency = { pref: './pnpm-local-resolver-0.1.1.tgz' }
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { importerDir: __dirname })
|
||||
|
||||
t.deepEqual(resolveResult, {
|
||||
id: 'file:pnpm-local-resolver-0.1.1.tgz',
|
||||
@@ -53,8 +53,8 @@ test('resolve file', async t => {
|
||||
test("resolve file when lockfile directory differs from the package's dir", async t => {
|
||||
const wantedDependency = { pref: './pnpm-local-resolver-0.1.1.tgz' }
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, {
|
||||
importerDir: __dirname,
|
||||
lockfileDir: path.join(__dirname, '..'),
|
||||
prefix: __dirname,
|
||||
})
|
||||
|
||||
t.deepEqual(resolveResult, {
|
||||
@@ -72,7 +72,7 @@ test("resolve file when lockfile directory differs from the package's dir", asyn
|
||||
|
||||
test('resolve tarball specified with file: protocol', async t => {
|
||||
const wantedDependency = { pref: 'file:./pnpm-local-resolver-0.1.1.tgz' }
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { importerDir: __dirname })
|
||||
|
||||
t.deepEqual(resolveResult, {
|
||||
id: 'file:pnpm-local-resolver-0.1.1.tgz',
|
||||
@@ -90,7 +90,7 @@ test('resolve tarball specified with file: protocol', async t => {
|
||||
test('fail when resolving tarball specified with the link: protocol', async t => {
|
||||
try {
|
||||
const wantedDependency = { pref: 'link:./pnpm-local-resolver-0.1.1.tgz' }
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { importerDir: __dirname })
|
||||
t.fail()
|
||||
} catch (err) {
|
||||
t.ok(err)
|
||||
@@ -102,7 +102,7 @@ test('fail when resolving tarball specified with the link: protocol', async t =>
|
||||
test('fail when resolving from not existing directory', async t => {
|
||||
try {
|
||||
const wantedDependency = { pref: 'link:./dir-does-not-exist' }
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { prefix: __dirname })
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { importerDir: __dirname })
|
||||
t.fail()
|
||||
} catch (err) {
|
||||
t.ok(err)
|
||||
@@ -113,7 +113,7 @@ test('fail when resolving from not existing directory', async t => {
|
||||
|
||||
test('throw error when the path: protocol is used', async t => {
|
||||
try {
|
||||
await resolveFromLocal({ pref: 'path:..' }, { prefix: __dirname })
|
||||
await resolveFromLocal({ pref: 'path:..' }, { importerDir: __dirname })
|
||||
t.fail()
|
||||
} catch (err) {
|
||||
t.ok(err)
|
||||
|
||||
@@ -119,10 +119,10 @@ export type ResolveFromNpmOptions = {
|
||||
},
|
||||
},
|
||||
} & ({
|
||||
prefix?: string,
|
||||
importerDir?: string,
|
||||
localPackages?: undefined,
|
||||
} | {
|
||||
prefix: string,
|
||||
importerDir: string,
|
||||
localPackages: LocalPackages,
|
||||
})
|
||||
|
||||
@@ -137,8 +137,8 @@ async function resolveNpm (
|
||||
const defaultTag = opts.defaultTag || 'latest'
|
||||
const resolvedFromWorkspace = tryResolveFromWorkspace(wantedDependency, {
|
||||
defaultTag,
|
||||
importerDir: opts.importerDir,
|
||||
localPackages: opts.localPackages,
|
||||
prefix: opts.prefix,
|
||||
registry: opts.registry,
|
||||
})
|
||||
if (resolvedFromWorkspace) {
|
||||
@@ -160,7 +160,7 @@ async function resolveNpm (
|
||||
})
|
||||
} catch (err) {
|
||||
if (opts.localPackages) {
|
||||
const resolvedFromLocal = tryResolveFromLocalPackages(opts.localPackages, spec, opts.prefix)
|
||||
const resolvedFromLocal = tryResolveFromLocalPackages(opts.localPackages, spec, opts.importerDir)
|
||||
if (resolvedFromLocal) return resolvedFromLocal
|
||||
}
|
||||
throw err
|
||||
@@ -169,7 +169,7 @@ async function resolveNpm (
|
||||
const meta = pickResult.meta
|
||||
if (!pickedPackage) {
|
||||
if (opts.localPackages) {
|
||||
const resolvedFromLocal = tryResolveFromLocalPackages(opts.localPackages, spec, opts.prefix)
|
||||
const resolvedFromLocal = tryResolveFromLocalPackages(opts.localPackages, spec, opts.importerDir)
|
||||
if (resolvedFromLocal) return resolvedFromLocal
|
||||
}
|
||||
throw new NoMatchingVersionError({ spec, packageMeta: meta })
|
||||
@@ -178,14 +178,14 @@ async function resolveNpm (
|
||||
if (opts.localPackages?.[pickedPackage.name]) {
|
||||
if (opts.localPackages[pickedPackage.name][pickedPackage.version]) {
|
||||
return {
|
||||
...resolveFromLocalPackage(opts.localPackages[pickedPackage.name][pickedPackage.version], spec.normalizedPref, opts.prefix),
|
||||
...resolveFromLocalPackage(opts.localPackages[pickedPackage.name][pickedPackage.version], spec.normalizedPref, opts.importerDir),
|
||||
latest: meta['dist-tags'].latest,
|
||||
}
|
||||
}
|
||||
const localVersion = pickMatchingLocalVersionOrNull(opts.localPackages[pickedPackage.name], spec)
|
||||
if (localVersion && semver.gt(localVersion, pickedPackage.version)) {
|
||||
return {
|
||||
...resolveFromLocalPackage(opts.localPackages[pickedPackage.name][localVersion], spec.normalizedPref, opts.prefix),
|
||||
...resolveFromLocalPackage(opts.localPackages[pickedPackage.name][localVersion], spec.normalizedPref, opts.importerDir),
|
||||
latest: meta['dist-tags'].latest,
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ function tryResolveFromWorkspace (
|
||||
opts: {
|
||||
defaultTag: string,
|
||||
localPackages?: LocalPackages,
|
||||
prefix?: string,
|
||||
importerDir?: string,
|
||||
registry: string,
|
||||
}
|
||||
) {
|
||||
@@ -225,10 +225,10 @@ function tryResolveFromWorkspace (
|
||||
if (!opts.localPackages) {
|
||||
throw new Error('Cannot resolve package from workspace because opts.localPackages is not defined')
|
||||
}
|
||||
if (!opts.prefix) {
|
||||
throw new Error('Cannot resolve package from workspace because opts.prefix is not defined')
|
||||
if (!opts.importerDir) {
|
||||
throw new Error('Cannot resolve package from workspace because opts.importerDir is not defined')
|
||||
}
|
||||
const resolvedFromLocal = tryResolveFromLocalPackages(opts.localPackages, spec, opts.prefix)
|
||||
const resolvedFromLocal = tryResolveFromLocalPackages(opts.localPackages, spec, opts.importerDir)
|
||||
if (!resolvedFromLocal) {
|
||||
throw new PnpmError(
|
||||
'NO_MATCHING_VERSION_INSIDE_WORKSPACE',
|
||||
@@ -241,12 +241,12 @@ function tryResolveFromWorkspace (
|
||||
function tryResolveFromLocalPackages (
|
||||
localPackages: LocalPackages,
|
||||
spec: RegistryPackageSpec,
|
||||
prefix: string,
|
||||
importerDir: string,
|
||||
) {
|
||||
if (!localPackages[spec.name]) return null
|
||||
const localVersion = pickMatchingLocalVersionOrNull(localPackages[spec.name], spec)
|
||||
if (!localVersion) return null
|
||||
return resolveFromLocalPackage(localPackages[spec.name][localVersion], spec.normalizedPref, prefix)
|
||||
return resolveFromLocalPackage(localPackages[spec.name][localVersion], spec.normalizedPref, importerDir)
|
||||
}
|
||||
|
||||
function pickMatchingLocalVersionOrNull (
|
||||
@@ -277,10 +277,10 @@ function resolveFromLocalPackage (
|
||||
manifest: DependencyManifest,
|
||||
},
|
||||
normalizedPref: string | undefined,
|
||||
prefix: string,
|
||||
importerDir: string,
|
||||
) {
|
||||
return {
|
||||
id: `link:${normalize(path.relative(prefix, localPackage.dir))}`,
|
||||
id: `link:${normalize(path.relative(importerDir, localPackage.dir))}`,
|
||||
manifest: localPackage.manifest,
|
||||
normalizedPref,
|
||||
resolution: {
|
||||
|
||||
@@ -899,6 +899,7 @@ test('resolve from local directory when it matches the latest version of the pac
|
||||
storeDir,
|
||||
})
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
importerDir: '/home/istvan/src',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'1.0.0': {
|
||||
@@ -910,7 +911,6 @@ test('resolve from local directory when it matches the latest version of the pac
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -945,6 +945,7 @@ test('use version from the registry if it is newer than the local one', async t
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
importerDir: '/home/istvan/src',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'3.0.0': {
|
||||
@@ -956,7 +957,6 @@ test('use version from the registry if it is newer than the local one', async t
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -992,6 +992,7 @@ test('use local version if it is newer than the latest in the registry', async t
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
importerDir: '/home/istvan/src',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'3.2.0': {
|
||||
@@ -1003,7 +1004,6 @@ test('use local version if it is newer than the latest in the registry', async t
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -1033,6 +1033,7 @@ test('resolve from local directory when package is not found in the registry', a
|
||||
storeDir,
|
||||
})
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '1' }, {
|
||||
importerDir: '/home/istvan/src/foo',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'1.0.0': {
|
||||
@@ -1058,7 +1059,6 @@ test('resolve from local directory when package is not found in the registry', a
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src/foo',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -1088,6 +1088,7 @@ test('resolve from local directory when package is not found in the registry and
|
||||
storeDir,
|
||||
})
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: 'latest' }, {
|
||||
importerDir: '/home/istvan/src',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'1.0.0': {
|
||||
@@ -1113,7 +1114,6 @@ test('resolve from local directory when package is not found in the registry and
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -1143,6 +1143,7 @@ test('resolve from local directory when package is not found in the registry and
|
||||
storeDir,
|
||||
})
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '1.1.0' }, {
|
||||
importerDir: '/home/istvan/src/foo',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'1.0.0': {
|
||||
@@ -1168,7 +1169,6 @@ test('resolve from local directory when package is not found in the registry and
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src/foo',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -1198,6 +1198,7 @@ test('resolve from local directory when the requested version is not found in th
|
||||
storeDir,
|
||||
})
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '100.0.0' }, {
|
||||
importerDir: '/home/istvan/src/foo',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'100.0.0': {
|
||||
@@ -1209,7 +1210,6 @@ test('resolve from local directory when the requested version is not found in th
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src/foo',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -1235,6 +1235,7 @@ test('workspace protocol: resolve from local directory even when it does not mat
|
||||
storeDir,
|
||||
})
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: 'workspace:^3.0.0' }, {
|
||||
importerDir: '/home/istvan/src',
|
||||
localPackages: {
|
||||
'is-positive': {
|
||||
'3.0.0': {
|
||||
@@ -1246,7 +1247,6 @@ test('workspace protocol: resolve from local directory even when it does not mat
|
||||
},
|
||||
},
|
||||
},
|
||||
prefix: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
|
||||
@@ -1275,8 +1275,8 @@ test('workspace protocol: resolution fails if there is no matching local package
|
||||
let err!: Error
|
||||
try {
|
||||
await resolve({ alias: 'is-positive', pref: 'workspace:^3.0.0' }, {
|
||||
importerDir: '/home/istvan/src',
|
||||
localPackages: {},
|
||||
prefix: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
} catch (_err) {
|
||||
@@ -1301,7 +1301,7 @@ test('workspace protocol: resolution fails if there are no local packages', asyn
|
||||
let err!: Error
|
||||
try {
|
||||
await resolve({ alias: 'is-positive', pref: 'workspace:^3.0.0' }, {
|
||||
prefix: '/home/istvan/src',
|
||||
importerDir: '/home/istvan/src',
|
||||
registry,
|
||||
})
|
||||
} catch (_err) {
|
||||
|
||||
@@ -132,10 +132,10 @@ async function resolveAndFetch (
|
||||
if (!skipResolution || options.skipFetch || pkgId?.startsWith('file:')) {
|
||||
const resolveResult = await ctx.requestsQueue.add<ResolveResult>(() => ctx.resolve(wantedDependency, {
|
||||
defaultTag: options.defaultTag,
|
||||
importerDir: options.importerDir,
|
||||
localPackages: options.localPackages,
|
||||
lockfileDir: options.lockfileDir,
|
||||
preferredVersions: options.preferredVersions,
|
||||
prefix: options.prefix,
|
||||
registry: options.registry,
|
||||
}), { priority: options.downloadPriority })
|
||||
|
||||
@@ -204,9 +204,9 @@ async function resolveAndFetch (
|
||||
const fetchResult = ctx.fetchPackageToStore({
|
||||
fetchRawManifest: updated || !manifest,
|
||||
force: forceFetch,
|
||||
lockfileDir: options.lockfileDir,
|
||||
pkgId: id,
|
||||
pkgName: manifest?.name,
|
||||
prefix: options.lockfileDir,
|
||||
resolution: resolution,
|
||||
})
|
||||
|
||||
@@ -256,7 +256,7 @@ function fetchToStore (
|
||||
force: boolean,
|
||||
pkgName?: string,
|
||||
pkgId: string,
|
||||
prefix: string,
|
||||
lockfileDir: string,
|
||||
resolution: Resolution,
|
||||
},
|
||||
): {
|
||||
@@ -265,7 +265,7 @@ function fetchToStore (
|
||||
finishing: () => Promise<void>,
|
||||
inStoreLocation: string,
|
||||
} {
|
||||
const targetRelative = pkgIdToFilename(opts.pkgId, opts.prefix)
|
||||
const targetRelative = pkgIdToFilename(opts.pkgId, opts.lockfileDir)
|
||||
const target = path.join(ctx.storeDir, targetRelative)
|
||||
|
||||
if (!ctx.fetchingLocker.has(opts.pkgId)) {
|
||||
@@ -373,7 +373,7 @@ function fetchToStore (
|
||||
!opts.force && targetExists &&
|
||||
(
|
||||
isLocalTarballDep === false ||
|
||||
await tarballIsUpToDate(opts.resolution as any, target, opts.prefix) // tslint:disable-line
|
||||
await tarballIsUpToDate(opts.resolution as any, target, opts.lockfileDir) // tslint:disable-line
|
||||
)
|
||||
) {
|
||||
// if target exists and it wasn't modified, then no need to refetch it
|
||||
@@ -395,7 +395,7 @@ function fetchToStore (
|
||||
}
|
||||
packageRequestLogger.warn({
|
||||
message: `Refetching ${target} to store. It was either modified or had no integrity checksums`,
|
||||
prefix: opts.prefix,
|
||||
prefix: opts.lockfileDir,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -418,6 +418,7 @@ function fetchToStore (
|
||||
target,
|
||||
{
|
||||
cachedTarballLocation: path.join(ctx.storeDir, opts.pkgId, 'packed.tgz'),
|
||||
lockfileDir: opts.lockfileDir,
|
||||
onProgress: (downloaded) => {
|
||||
fetchingProgressLogger.debug({
|
||||
downloaded,
|
||||
@@ -433,7 +434,6 @@ function fetchToStore (
|
||||
status: 'started',
|
||||
})
|
||||
},
|
||||
prefix: opts.prefix,
|
||||
},
|
||||
), { priority })
|
||||
|
||||
@@ -519,7 +519,7 @@ async function tarballIsUpToDate (
|
||||
tarball: string,
|
||||
},
|
||||
pkgInStoreLocation: string,
|
||||
prefix: string,
|
||||
lockfileDir: string,
|
||||
) {
|
||||
let currentIntegrity!: string
|
||||
try {
|
||||
@@ -529,7 +529,7 @@ async function tarballIsUpToDate (
|
||||
}
|
||||
if (resolution.integrity && currentIntegrity !== resolution.integrity) return false
|
||||
|
||||
const tarball = path.join(prefix, resolution.tarball.slice(5))
|
||||
const tarball = path.join(lockfileDir, resolution.tarball.slice(5))
|
||||
const tarballStream = fs.createReadStream(tarball)
|
||||
try {
|
||||
return Boolean(await ssri.checkStream(tarballStream, currentIntegrity))
|
||||
@@ -577,7 +577,7 @@ async function fetcher (
|
||||
} catch (err) {
|
||||
packageRequestLogger.warn({
|
||||
message: `Fetching ${packageId} failed!`,
|
||||
prefix: opts.prefix,
|
||||
prefix: opts.lockfileDir,
|
||||
})
|
||||
throw err
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ test('request package', async t => {
|
||||
})
|
||||
t.equal(typeof requestPackage, 'function')
|
||||
|
||||
const prefix = tempy.directory()
|
||||
const importerDir = tempy.directory()
|
||||
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
}) as PackageResponse & {
|
||||
body: {inStoreLocation: string, latest: string, manifest: {name: string}},
|
||||
@@ -98,12 +98,12 @@ test('request package but skip fetching', async t => {
|
||||
})
|
||||
t.equal(typeof requestPackage, 'function')
|
||||
|
||||
const prefix = tempy.directory()
|
||||
const importerDir = tempy.directory()
|
||||
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
skipFetch: true,
|
||||
}) as PackageResponse & {
|
||||
@@ -142,7 +142,7 @@ test('request package but skip fetching, when resolution is already available',
|
||||
})
|
||||
t.equal(typeof requestPackage, 'function')
|
||||
|
||||
const prefix = tempy.directory()
|
||||
const importerDir = tempy.directory()
|
||||
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
currentPackageId: 'registry.npmjs.org/is-positive/1.0.0',
|
||||
currentResolution: {
|
||||
@@ -151,9 +151,9 @@ test('request package but skip fetching, when resolution is already available',
|
||||
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
||||
},
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
skipFetch: true,
|
||||
update: false,
|
||||
@@ -189,9 +189,9 @@ test('request package but skip fetching, when resolution is already available',
|
||||
})
|
||||
|
||||
test('refetch local tarball if its integrity has changed', async t => {
|
||||
const prefix = tempy.directory()
|
||||
const tarballPath = path.join(prefix, 'tarball.tgz')
|
||||
const tarballRelativePath = path.relative(prefix, tarballPath)
|
||||
const importerDir = tempy.directory()
|
||||
const tarballPath = path.join(importerDir, 'tarball.tgz')
|
||||
const tarballRelativePath = path.relative(importerDir, tarballPath)
|
||||
await ncp(path.join(__dirname, 'pnpm-package-requester-0.8.1.tgz'), tarballPath)
|
||||
const tarball = `file:${tarballRelativePath}`
|
||||
const wantedPackage = { pref: tarball }
|
||||
@@ -200,9 +200,9 @@ test('refetch local tarball if its integrity has changed', async t => {
|
||||
const requestPackageOpts = {
|
||||
currentPackageId: pkgId,
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
skipFetch: true,
|
||||
update: false,
|
||||
@@ -288,17 +288,17 @@ test('refetch local tarball if its integrity has changed', async t => {
|
||||
})
|
||||
|
||||
test('refetch local tarball if its integrity has changed. The requester does not know the correct integrity', async t => {
|
||||
const prefix = tempy.directory()
|
||||
const tarballPath = path.join(prefix, 'tarball.tgz')
|
||||
const importerDir = tempy.directory()
|
||||
const tarballPath = path.join(importerDir, 'tarball.tgz')
|
||||
await ncp(path.join(__dirname, 'pnpm-package-requester-0.8.1.tgz'), tarballPath)
|
||||
const tarball = `file:${tarballPath}`
|
||||
const wantedPackage = { pref: tarball }
|
||||
const storeDir = path.join(__dirname, '..', '.store')
|
||||
const requestPackageOpts = {
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
update: false,
|
||||
}
|
||||
@@ -377,8 +377,8 @@ test('fetchPackageToStore()', async (t) => {
|
||||
const pkgId = 'registry.npmjs.org/is-positive/1.0.0'
|
||||
const fetchResult = await packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -399,8 +399,8 @@ test('fetchPackageToStore()', async (t) => {
|
||||
const fetchResult2 = await packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: true,
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -433,13 +433,13 @@ test('fetchPackageToStore() concurrency check', async (t) => {
|
||||
})
|
||||
|
||||
const pkgId = 'registry.npmjs.org/is-positive/1.0.0'
|
||||
const prefix1 = tempy.directory()
|
||||
const prefix2 = tempy.directory()
|
||||
const importerDir1 = tempy.directory()
|
||||
const importerDir2 = tempy.directory()
|
||||
const fetchResults = await Promise.all([
|
||||
packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
lockfileDir: importerDir1,
|
||||
pkgId,
|
||||
prefix: prefix1,
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -448,8 +448,8 @@ test('fetchPackageToStore() concurrency check', async (t) => {
|
||||
}),
|
||||
packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
lockfileDir: importerDir2,
|
||||
pkgId,
|
||||
prefix: prefix2,
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -523,8 +523,8 @@ test('fetchPackageToStore() does not cache errors', async (t) => {
|
||||
try {
|
||||
const badRequest = await packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -539,8 +539,8 @@ test('fetchPackageToStore() does not cache errors', async (t) => {
|
||||
|
||||
const fetchResult = await packageRequester.fetchPackageToStore({
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -568,14 +568,14 @@ test('always return a package manifest in the response', async t => {
|
||||
verifyStoreIntegrity: true,
|
||||
})
|
||||
t.equal(typeof requestPackage, 'function')
|
||||
const prefix = tempy.directory()
|
||||
const importerDir = tempy.directory()
|
||||
|
||||
{
|
||||
const pkgResponse = await requestPackage({ alias: 'is-positive', pref: '1.0.0' }, {
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
}) as PackageResponse & {body: {manifest: {name: string}}}
|
||||
|
||||
@@ -592,9 +592,9 @@ test('always return a package manifest in the response', async t => {
|
||||
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
||||
},
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
}) as PackageResponse & {bundledManifest: () => Promise<DependencyManifest>}
|
||||
|
||||
@@ -636,15 +636,15 @@ test('fetchPackageToStore() fetch raw manifest of cached package', async (t) =>
|
||||
packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: false,
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution,
|
||||
}),
|
||||
packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: true,
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution,
|
||||
})
|
||||
])
|
||||
@@ -676,8 +676,8 @@ test('refetch package to store if it has been modified', async (t) => {
|
||||
const fetchResult = await packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: false,
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution,
|
||||
})
|
||||
|
||||
@@ -694,7 +694,7 @@ test('refetch package to store if it has been modified', async (t) => {
|
||||
|
||||
const reporter = sinon.spy()
|
||||
streamParser.on('data', reporter)
|
||||
const prefix = tempy.directory()
|
||||
const importerDir = tempy.directory()
|
||||
|
||||
{
|
||||
const packageRequester = createPackageRequester(resolve, fetch, {
|
||||
@@ -707,8 +707,8 @@ test('refetch package to store if it has been modified', async (t) => {
|
||||
const fetchResult = await packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: false,
|
||||
force: false,
|
||||
lockfileDir: importerDir,
|
||||
pkgId,
|
||||
prefix,
|
||||
resolution,
|
||||
})
|
||||
|
||||
@@ -723,7 +723,7 @@ test('refetch package to store if it has been modified', async (t) => {
|
||||
level: 'warn',
|
||||
message: `Refetching ${path.join(storeDir, pkgId)} to store. It was either modified or had no integrity checksums`,
|
||||
name: 'pnpm:package-requester',
|
||||
prefix,
|
||||
prefix: importerDir,
|
||||
}), 'refetch logged')
|
||||
|
||||
t.end()
|
||||
@@ -752,8 +752,8 @@ test('refetch package to store if it has no integrity checksums and verification
|
||||
const fetchResult = await packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: false,
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution,
|
||||
})
|
||||
|
||||
@@ -765,7 +765,7 @@ test('refetch package to store if it has no integrity checksums and verification
|
||||
|
||||
const reporter = sinon.spy()
|
||||
streamParser.on('data', reporter)
|
||||
const prefix = tempy.directory()
|
||||
const importerDir = tempy.directory()
|
||||
|
||||
{
|
||||
const packageRequester = createPackageRequester(resolve, fetch, {
|
||||
@@ -778,8 +778,8 @@ test('refetch package to store if it has no integrity checksums and verification
|
||||
const fetchResult = await packageRequester.fetchPackageToStore({
|
||||
fetchRawManifest: false,
|
||||
force: false,
|
||||
lockfileDir: importerDir,
|
||||
pkgId,
|
||||
prefix,
|
||||
resolution,
|
||||
})
|
||||
|
||||
@@ -795,7 +795,7 @@ test('refetch package to store if it has no integrity checksums and verification
|
||||
level: 'warn',
|
||||
message: `Refetching ${path.join(storeDir, pkgId)} to store. It was either modified or had no integrity checksums`,
|
||||
name: 'pnpm:package-requester',
|
||||
prefix,
|
||||
prefix: importerDir,
|
||||
}), 'refetch logged')
|
||||
|
||||
t.end()
|
||||
|
||||
@@ -33,8 +33,8 @@ test('store.importPackage()', async (t) => {
|
||||
const pkgId = 'registry.npmjs.org/is-positive/1.0.0'
|
||||
const fetchResponse = await storeController.fetchPackage({
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -72,8 +72,8 @@ test('store.importPackage() by copying', async (t) => {
|
||||
const pkgId = 'registry.npmjs.org/is-positive/1.0.0'
|
||||
const fetchResponse = await storeController.fetchPackage({
|
||||
force: false,
|
||||
lockfileDir: tempy.directory(),
|
||||
pkgId,
|
||||
prefix: tempy.directory(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
|
||||
@@ -47,9 +47,9 @@ export async function getLatestManifest (
|
||||
packageName: string,
|
||||
) {
|
||||
const resolution = await resolve({ alias: packageName, pref: 'latest' }, {
|
||||
importerDir: opts.dir,
|
||||
lockfileDir: opts.lockfileDir,
|
||||
preferredVersions: {},
|
||||
prefix: opts.dir,
|
||||
registry: pickRegistryForPackage(opts.registries, packageName),
|
||||
})
|
||||
return resolution && resolution.manifest || null
|
||||
|
||||
@@ -534,10 +534,10 @@ async function resolveDependency (
|
||||
currentResolution: options.currentResolution,
|
||||
defaultTag: ctx.defaultTag,
|
||||
downloadPriority: -options.currentDepth,
|
||||
importerDir: ctx.prefix,
|
||||
localPackages: options.localPackages,
|
||||
lockfileDir: ctx.lockfileDir,
|
||||
preferredVersions: options.preferredVersions,
|
||||
prefix: ctx.prefix,
|
||||
registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias) || ctx.registries.default,
|
||||
sideEffectsCache: ctx.sideEffectsCache,
|
||||
// Unfortunately, even when run with --lockfile-only, we need the *real* package.json
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface LocalPackages {
|
||||
|
||||
export interface ResolveOptions {
|
||||
defaultTag?: string,
|
||||
importerDir: string,
|
||||
localPackages?: LocalPackages,
|
||||
lockfileDir: string,
|
||||
preferredVersions: {
|
||||
@@ -54,7 +55,6 @@ export interface ResolveOptions {
|
||||
type: 'version' | 'range' | 'tag',
|
||||
},
|
||||
},
|
||||
prefix: string,
|
||||
registry: string,
|
||||
}
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@ test('server', async t => {
|
||||
port,
|
||||
})
|
||||
const storeCtrl = await connectStoreController({ remotePrefix, concurrency: 100 })
|
||||
const prefix = process.cwd()
|
||||
const importerDir = process.cwd()
|
||||
const response = await storeCtrl.requestPackage(
|
||||
{ alias: 'is-positive', pref: '1.0.0' },
|
||||
{
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
sideEffectsCache: false,
|
||||
}
|
||||
@@ -92,8 +92,8 @@ test('fetchPackage', async t => {
|
||||
const response = await storeCtrl.fetchPackage({
|
||||
fetchRawManifest: true,
|
||||
force: false,
|
||||
lockfileDir: process.cwd(),
|
||||
pkgId,
|
||||
prefix: process.cwd(),
|
||||
resolution: {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
@@ -141,14 +141,14 @@ test('server errors should arrive to the client', async t => {
|
||||
const storeCtrl = await connectStoreController({ remotePrefix, concurrency: 100 })
|
||||
let caught = false
|
||||
try {
|
||||
const prefix = process.cwd()
|
||||
const importerDir = process.cwd()
|
||||
await storeCtrl.requestPackage(
|
||||
{ alias: 'not-an-existing-package', pref: '1.0.0' },
|
||||
{
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
sideEffectsCache: false,
|
||||
}
|
||||
@@ -309,15 +309,15 @@ test('find package usages', async t => {
|
||||
|
||||
const dependency = { alias: 'is-positive', pref: '1.0.0' }
|
||||
|
||||
const prefix = process.cwd()
|
||||
const importerDir = process.cwd()
|
||||
// First install a dependency
|
||||
const requestResponse = await storeCtrl.requestPackage(
|
||||
dependency,
|
||||
{
|
||||
downloadPriority: 0,
|
||||
lockfileDir: prefix,
|
||||
importerDir,
|
||||
lockfileDir: importerDir,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
registry,
|
||||
sideEffectsCache: false,
|
||||
}
|
||||
|
||||
@@ -68,9 +68,9 @@ export type FetchPackageToStoreFunction = (
|
||||
export interface FetchPackageToStoreOptions {
|
||||
fetchRawManifest?: boolean,
|
||||
force: boolean,
|
||||
pkgName?: string,
|
||||
lockfileDir: string,
|
||||
pkgId: string,
|
||||
prefix: string,
|
||||
pkgName?: string,
|
||||
resolution: Resolution,
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ export interface RequestPackageOptions {
|
||||
currentResolution?: Resolution,
|
||||
defaultTag?: string,
|
||||
downloadPriority: number,
|
||||
lockfileDir: string,
|
||||
importerDir: string,
|
||||
localPackages?: LocalPackages,
|
||||
prefix: string,
|
||||
lockfileDir: string,
|
||||
preferredVersions: {
|
||||
[packageName: string]: {
|
||||
selector: string,
|
||||
|
||||
@@ -42,7 +42,7 @@ export default async function (
|
||||
downloadPriority: 1,
|
||||
lockfileDir: prefix,
|
||||
preferredVersions: {},
|
||||
prefix,
|
||||
importerDir: prefix,
|
||||
registry: dep.alias && pickRegistryForPackage(registries, dep.alias) || registries.default,
|
||||
})
|
||||
await pkgResponse.files!()
|
||||
|
||||
@@ -98,7 +98,7 @@ function fetchFromTarball (
|
||||
opts: FetchOptions,
|
||||
) {
|
||||
if (resolution.tarball.startsWith('file:')) {
|
||||
const tarball = path.join(opts.prefix, resolution.tarball.slice(5))
|
||||
const tarball = path.join(opts.lockfileDir, resolution.tarball.slice(5))
|
||||
return fetchFromLocalTarball(tarball, target, {
|
||||
ignore: ctx.ignore,
|
||||
integrity: resolution.integrity,
|
||||
|
||||
@@ -49,7 +49,7 @@ test('fail when tarball size does not match content-length', async t => {
|
||||
try {
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
t.fail('should have failed')
|
||||
} catch (err) {
|
||||
@@ -97,7 +97,7 @@ test('redownload the tarball when the one in cache does not satisfy integrity',
|
||||
streamParser.on('data', reporter as any) // tslint:disable-line:no-any
|
||||
const { tempLocation } = await fetch.tarball(resolution, path.join(cacheDir, 'unpacked'), {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
streamParser.removeListener('data', reporter as any) // tslint:disable-line:no-any
|
||||
|
||||
@@ -136,7 +136,7 @@ test('fail when the tarball in the cache does not pass integrity check in offlin
|
||||
})
|
||||
await fetch.tarball(resolution, path.join(cacheDir, 'unpacked'), {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
} catch (_err) {
|
||||
err = _err
|
||||
@@ -169,7 +169,7 @@ test('retry when tarball size does not match content-length', async t => {
|
||||
|
||||
const result = await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
|
||||
t.equal(typeof result.tempLocation, 'string')
|
||||
@@ -219,7 +219,7 @@ test('redownload incomplete cached tarballs', async t => {
|
||||
try {
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
} catch (err) {
|
||||
nock.cleanAll()
|
||||
@@ -252,7 +252,7 @@ test('fail when integrity check fails two times in a row', async t => {
|
||||
try {
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
t.fail('should have failed')
|
||||
} catch (err) {
|
||||
@@ -291,7 +291,7 @@ test('retry when integrity check fails', async t => {
|
||||
const params: Array<[number | null, number]> = []
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
onStart (size, attempts) {
|
||||
params.push([size, attempts])
|
||||
},
|
||||
@@ -321,7 +321,7 @@ test('fail when integrity check of local file fails', async (t) => {
|
||||
try {
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
} catch (_err) {
|
||||
err = _err
|
||||
@@ -352,7 +352,7 @@ test("don't fail when integrity check of local file succeeds", async (t) => {
|
||||
|
||||
const { filesIndex, tempLocation } = await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
|
||||
t.equal(typeof filesIndex['package.json'], 'object', 'files index returned')
|
||||
@@ -382,7 +382,7 @@ test("don't fail when the cache tarball does not exist", async (t) => {
|
||||
|
||||
const { filesIndex, tempLocation } = await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
|
||||
t.equal(typeof filesIndex['package.json'], 'object', 'files index returned')
|
||||
@@ -417,7 +417,7 @@ test('fail when the cache tarball does not exist in offline mode', async (t) =>
|
||||
})
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
} catch (_err) {
|
||||
err = _err
|
||||
@@ -450,7 +450,7 @@ test('retry on server error', async t => {
|
||||
|
||||
const index = await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
|
||||
t.ok(index)
|
||||
@@ -479,7 +479,7 @@ test('throw error when accessing private package w/o authorization', async t =>
|
||||
try {
|
||||
await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
} catch (_err) {
|
||||
err = _err
|
||||
@@ -535,7 +535,7 @@ test('accessing private packages', async t => {
|
||||
|
||||
const index = await fetch.tarball(resolution, unpackTo, {
|
||||
cachedTarballLocation,
|
||||
prefix: process.cwd(),
|
||||
lockfileDir: process.cwd(),
|
||||
})
|
||||
|
||||
t.ok(index)
|
||||
|
||||
Reference in new issue
Block a user