mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 04:21:39 -04:00
feat: use relative tarball URL in shrinkwrap.yaml when possible
This commit is contained in:
@@ -3,6 +3,7 @@ import logger, {deprecationLogger} from 'pnpm-logger'
|
||||
import R = require('ramda')
|
||||
import getNpmTarballUrl from 'get-npm-tarball-url'
|
||||
import exists = require('path-exists')
|
||||
import url = require('url')
|
||||
import {
|
||||
Got,
|
||||
fetch,
|
||||
@@ -138,13 +139,18 @@ function dependencyShrToResolution (
|
||||
depShr: DependencyShrinkwrap,
|
||||
registry: string
|
||||
): Resolution {
|
||||
if (!depShr.resolution['type'] && !depShr.resolution['tarball']) {
|
||||
if (depShr.resolution['type']) {
|
||||
return depShr.resolution as Resolution
|
||||
}
|
||||
if (!depShr.resolution['tarball']) {
|
||||
return Object.assign({}, depShr.resolution, {
|
||||
tarball: getTarball(),
|
||||
registry: depShr.resolution['registry'] || registry,
|
||||
})
|
||||
}
|
||||
return depShr.resolution as Resolution
|
||||
return Object.assign({}, depShr.resolution, {
|
||||
tarball: url.resolve(registry, depShr.resolution['tarball'])
|
||||
})
|
||||
|
||||
function getTarball () {
|
||||
const parts = dependencyPath.split('/')
|
||||
|
||||
@@ -58,7 +58,7 @@ function toShrDependency (
|
||||
optional: boolean,
|
||||
}
|
||||
): DependencyShrinkwrap {
|
||||
const shrResolution = toShrResolution(opts.dependencyPath, opts.resolution)
|
||||
const shrResolution = toShrResolution(opts.dependencyPath, opts.resolution, opts.registry)
|
||||
const newResolvedDeps = updateResolvedDeps(opts.prevResolvedDeps, opts.updatedDeps, opts.registry, opts.pkgsToLink)
|
||||
const newResolvedOptionalDeps = updateResolvedDeps(opts.prevResolvedOptionalDeps, opts.updatedOptionalDeps, opts.registry, opts.pkgsToLink)
|
||||
const result = {
|
||||
@@ -104,7 +104,11 @@ function updateResolvedDeps (
|
||||
)
|
||||
}
|
||||
|
||||
function toShrResolution (dependencyPath: string, resolution: Resolution): ShrinkwrapResolution {
|
||||
function toShrResolution (
|
||||
dependencyPath: string,
|
||||
resolution: Resolution,
|
||||
registry: string
|
||||
): ShrinkwrapResolution {
|
||||
if (dp.isAbsolute(dependencyPath) || resolution.type !== undefined || !resolution.integrity) {
|
||||
return resolution
|
||||
}
|
||||
@@ -113,10 +117,17 @@ function toShrResolution (dependencyPath: string, resolution: Resolution): Shrin
|
||||
if (!resolution.tarball.includes('/-/')) {
|
||||
return {
|
||||
integrity: resolution.integrity,
|
||||
tarball: resolution.tarball,
|
||||
tarball: relativeTarball(resolution.tarball, registry),
|
||||
}
|
||||
}
|
||||
return {
|
||||
integrity: resolution.integrity,
|
||||
}
|
||||
}
|
||||
|
||||
function relativeTarball (tarball: string, registry: string) {
|
||||
if (tarball.substr(0, registry.length) === registry) {
|
||||
return tarball.substr(registry.length - 1)
|
||||
}
|
||||
return tarball
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ test('installing from shrinkwrap when using npm enterprise', async (t: tape.Test
|
||||
'/is-positive/3.1.0': {
|
||||
resolution: {
|
||||
integrity: 'sha1-hX21hKG6XRyymAUn/DtsQ103sP0=',
|
||||
tarball: 'https://npm-registry.compass.com/i/is-positive/_attachments/is-positive-3.1.0.tgz'
|
||||
tarball: '/i/is-positive/_attachments/is-positive-3.1.0.tgz'
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user