@verdaccio/store 6.0.0-6-next.23 → 6.0.0-6-next.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # @verdaccio/store
2
2
 
3
+ ## 6.0.0-6-next.26
4
+
5
+ ### Patch Changes
6
+
7
+ - b849128d: fix: handle upload scoped tarball
8
+ - Updated dependencies [b849128d]
9
+ - @verdaccio/core@6.0.0-6-next.8
10
+ - @verdaccio/config@6.0.0-6-next.17
11
+ - @verdaccio/tarball@11.0.0-6-next.15
12
+ - @verdaccio/url@11.0.0-6-next.12
13
+ - @verdaccio/hooks@6.0.0-6-next.16
14
+ - @verdaccio/loaders@6.0.0-6-next.15
15
+ - @verdaccio/logger@6.0.0-6-next.14
16
+ - @verdaccio/local-storage@11.0.0-6-next.16
17
+ - @verdaccio/proxy@6.0.0-6-next.24
18
+ - @verdaccio/utils@6.0.0-6-next.14
19
+
20
+ ## 6.0.0-6-next.25
21
+
22
+ ### Patch Changes
23
+
24
+ - 351aeeaa: fix(deps): @verdaccio/utils should be a prod dep of local-storage
25
+ - Updated dependencies [351aeeaa]
26
+ - @verdaccio/core@6.0.0-6-next.7
27
+ - @verdaccio/tarball@11.0.0-6-next.14
28
+ - @verdaccio/url@11.0.0-6-next.11
29
+ - @verdaccio/hooks@6.0.0-6-next.15
30
+ - @verdaccio/loaders@6.0.0-6-next.14
31
+ - @verdaccio/logger@6.0.0-6-next.13
32
+ - @verdaccio/local-storage@11.0.0-6-next.15
33
+ - @verdaccio/proxy@6.0.0-6-next.23
34
+ - @verdaccio/config@6.0.0-6-next.16
35
+ - @verdaccio/utils@6.0.0-6-next.13
36
+
37
+ ## 6.0.0-6-next.24
38
+
39
+ ### Minor Changes
40
+
41
+ - 37274e4c: feat: implement abbreviated manifest
42
+
43
+ Enable abbreviated manifest data by adding the header:
44
+
45
+ ```
46
+ curl -H "Accept: application/vnd.npm.install-v1+json" https://registry.npmjs.org/verdaccio
47
+ ```
48
+
49
+ It returns a filtered manifest, additionally includes the [time](https://github.com/pnpm/rfcs/pull/2) field by request.
50
+
51
+ Current support for packages managers:
52
+
53
+ - npm: yes
54
+ - pnpm: yes
55
+ - yarn classic: yes
56
+ - yarn modern (+2.x): [no](https://github.com/yarnpkg/berry/pull/3981#issuecomment-1076566096)
57
+
58
+ https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-metadata-format
59
+
60
+ ### Patch Changes
61
+
62
+ - Updated dependencies [37274e4c]
63
+ - @verdaccio/local-storage@11.0.0-6-next.14
64
+ - @verdaccio/core@6.0.0-6-next.6
65
+ - @verdaccio/tarball@11.0.0-6-next.13
66
+ - @verdaccio/url@11.0.0-6-next.10
67
+ - @verdaccio/hooks@6.0.0-6-next.14
68
+ - @verdaccio/loaders@6.0.0-6-next.13
69
+ - @verdaccio/logger@6.0.0-6-next.12
70
+ - @verdaccio/proxy@6.0.0-6-next.22
71
+
3
72
  ## 6.0.0-6-next.23
4
73
 
5
74
  ### Major Changes
@@ -49,6 +49,7 @@ export declare function updateUpLinkMetadata(uplinkId: any, manifest: Manifest,
49
49
  directory?: string | undefined;
50
50
  } | undefined;
51
51
  keywords?: string[] | undefined;
52
+ author?: string | import("@verdaccio/types").Author | undefined;
52
53
  _attachments: AttachMents;
53
54
  };
54
55
  export declare function prepareSearchPackage(data: Manifest): any;
@@ -280,7 +280,8 @@ function mergeVersions(cacheManifest, remoteManifest) {
280
280
  let _cacheManifest = { ...cacheManifest
281
281
  };
282
282
  const {
283
- versions
283
+ versions,
284
+ time
284
285
  } = remoteManifest; // copy new versions to a cache
285
286
  // NOTE: if a certain version was updated, we can't refresh it reliably
286
287
 
@@ -290,6 +291,12 @@ function mergeVersions(cacheManifest, remoteManifest) {
290
291
  }
291
292
  }
292
293
 
294
+ for (const i in time) {
295
+ if (typeof cacheManifest.time[i] === 'undefined') {
296
+ _cacheManifest.time[i] = time[i];
297
+ }
298
+ }
299
+
293
300
  for (const distTag in remoteManifest[_core.DIST_TAGS]) {
294
301
  if (_cacheManifest[_core.DIST_TAGS][distTag] !== remoteManifest[_core.DIST_TAGS][distTag]) {
295
302
  if (!_cacheManifest[_core.DIST_TAGS][distTag] || _semver.default.lte(_cacheManifest[_core.DIST_TAGS][distTag], remoteManifest[_core.DIST_TAGS][distTag])) {
@@ -1 +1 @@
1
- {"version":3,"file":"storage-utils.js","names":["STORAGE","PACKAGE_FILE_NAME","FILE_EXIST_ERROR","NO_SUCH_FILE_ERROR","DEFAULT_REVISION","generatePackageTemplate","name","versions","time","USERS","DIST_TAGS","_uplinks","_distfiles","_attachments","_rev","normalizePackage","pkg","pkgProperties","forEach","key","pkgProp","isNil","validatioUtils","isObject","_id","normalizeDistTags","generateRevision","rev","split","generateRandomHexString","getLatestReadme","distTags","latestVersion","readme","_","trim","readmeDistTagsPriority","tag","version","cleanUpReadme","WHITELIST","cleanUpLinksRef","result","keepUpLinkData","propertyToKeep","push","i","indexOf","checkPackageRemote","isAllowPublishOffline","syncMetadata","Promise","resolve","reject","err","packageJsonLocal","upLinksErrors","status","HTTP_STATUS","NOT_FOUND","errorUtils","getConflict","API_ERROR","PACKAGE_EXIST","errorItem","length","getServiceUnavailable","UPLINK_OFFLINE_PUBLISH","mergeUplinkTimeIntoLocal","localMetadata","remoteMetadata","Object","assign","mergeUplinkTimeIntoLocalNext","cacheManifest","remoteManifest","updateUpLinkMetadata","uplinkId","manifest","etag","fetched","Date","now","prepareSearchPackage","data","latest","pkgUtils","getLatest","description","maintainers","author","filter","Boolean","repository","readmeFilename","homepage","keywords","bugs","license","isDifferentThanOne","keys","hasInvalidPublishBody","res","mergeVersions","_cacheManifest","distTag","semver","lte","sorted","sortVersionsAndFilterInvalid","pop","isArray","isString","parse","hasDeprecatedVersions","pkgInfo","prototype","hasOwnProperty","call","isDeprecatedManifest"],"sources":["../../src/lib/storage-utils.ts"],"sourcesContent":["import _ from 'lodash';\nimport semver from 'semver';\n\nimport { errorUtils, pkgUtils, validatioUtils } from '@verdaccio/core';\nimport { API_ERROR, DIST_TAGS, HTTP_STATUS, USERS } from '@verdaccio/core';\nimport { AttachMents, Manifest, Version, Versions } from '@verdaccio/types';\nimport { generateRandomHexString, isNil, isObject } from '@verdaccio/utils';\n\nimport { sortVersionsAndFilterInvalid } from './versions-utils';\n\nexport const STORAGE = {\n PACKAGE_FILE_NAME: 'package.json',\n FILE_EXIST_ERROR: 'EEXISTS',\n NO_SUCH_FILE_ERROR: 'ENOENT',\n DEFAULT_REVISION: '0-0000000000000000',\n};\n\n/**\n * Create a new package in the storage, return a boilerplate package\n * @param name package name\n * @returns {Manifest}\n */\nexport function generatePackageTemplate(name: string): Manifest {\n return {\n // standard things\n name,\n versions: {},\n time: {},\n [USERS]: {},\n [DIST_TAGS]: {},\n _uplinks: {},\n _distfiles: {},\n _attachments: {},\n _rev: '',\n };\n}\n\n/**\n * Normalize package properties, tags, revision id.\n * @param {Object} pkg package reference.\n */\nexport function normalizePackage(pkg: Manifest): Manifest {\n const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];\n\n pkgProperties.forEach((key): void => {\n const pkgProp = pkg[key];\n\n if (isNil(pkgProp) || validatioUtils.isObject(pkgProp) === false) {\n pkg[key] = {};\n }\n });\n\n if (typeof pkg?._rev !== 'string') {\n pkg._rev = STORAGE.DEFAULT_REVISION;\n }\n\n if (typeof pkg?._id !== 'string') {\n pkg._id = pkg.name;\n }\n\n // normalize dist-tags\n return normalizeDistTags(pkg);\n}\n\nexport function generateRevision(rev: string): string {\n const _rev = rev.split('-');\n\n return (+_rev[0] || 0) + 1 + '-' + generateRandomHexString();\n}\n\nexport function getLatestReadme(pkg: Manifest): string {\n const versions = pkg['versions'] || {};\n const distTags = pkg[DIST_TAGS] || {};\n // FIXME: here is a bit tricky add the types\n const latestVersion: Version | any = distTags['latest'] ? versions[distTags['latest']] || {} : {};\n let readme = _.trim(pkg.readme || latestVersion.readme || '');\n if (readme) {\n return readme;\n }\n\n // In case of empty readme - trying to get ANY readme in the following order:\n // 'next','beta','alpha','test','dev','canary'\n const readmeDistTagsPriority = ['next', 'beta', 'alpha', 'test', 'dev', 'canary'];\n readmeDistTagsPriority.forEach(function (tag): string | void {\n if (readme) {\n return readme;\n }\n const version: Version | any = distTags[tag] ? versions[distTags[tag]] || {} : {};\n readme = _.trim(version.readme || readme);\n });\n return readme;\n}\n\n// FIXME: type any due this\nexport function cleanUpReadme(version: any): Version {\n if (isNil(version) === false) {\n delete version.readme;\n }\n\n return version;\n}\n\nexport const WHITELIST = [\n '_rev',\n 'name',\n 'versions',\n 'dist-tags',\n 'readme',\n 'time',\n '_id',\n 'users',\n];\n\nexport function cleanUpLinksRef(result: Manifest, keepUpLinkData?: boolean): Manifest {\n const propertyToKeep = [...WHITELIST];\n if (keepUpLinkData === true) {\n propertyToKeep.push('_uplinks');\n }\n\n for (const i in result) {\n if (propertyToKeep.indexOf(i) === -1) {\n // Remove sections like '_uplinks' from response\n delete result[i];\n }\n }\n\n return result;\n}\n\n// TODO: move to abstract storage\n// @deprecated use abstract.storage.ts:checkPackageRemote\nexport function checkPackageRemote(\n name: string,\n isAllowPublishOffline: boolean,\n syncMetadata: Function\n): Promise<any> {\n return new Promise<void>((resolve, reject): void => {\n syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors): void => {\n // something weird\n if (err && err.status !== HTTP_STATUS.NOT_FOUND) {\n return reject(err);\n }\n\n // checking package exist already\n if (isNil(packageJsonLocal) === false) {\n return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST));\n }\n\n for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {\n // checking error\n // if uplink fails with a status other than 404, we report failure\n if (isNil(upLinksErrors[errorItem][0]) === false) {\n if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {\n if (isAllowPublishOffline) {\n return resolve();\n }\n\n return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH));\n }\n }\n }\n\n return resolve();\n });\n });\n}\n\n// @deprecated use export function mergeUplinkTimeIntoLocalNext\nexport function mergeUplinkTimeIntoLocal(localMetadata: Manifest, remoteMetadata: Manifest): any {\n if ('time' in remoteMetadata) {\n return Object.assign({}, localMetadata.time, remoteMetadata.time);\n }\n\n return localMetadata.time;\n}\n\nexport function mergeUplinkTimeIntoLocalNext(\n cacheManifest: Manifest,\n remoteManifest: Manifest\n): Manifest {\n if ('time' in remoteManifest) {\n // remote override cache time conflicts\n return { ...cacheManifest, time: { ...cacheManifest.time, ...remoteManifest.time } };\n }\n\n return cacheManifest;\n}\n\nexport function updateUpLinkMetadata(uplinkId, manifest: Manifest, etag: string) {\n const _uplinks = {\n ...manifest._uplinks,\n [uplinkId]: {\n etag,\n fetched: Date.now(),\n },\n };\n return {\n ...manifest,\n _uplinks,\n };\n}\n\nexport function prepareSearchPackage(data: Manifest): any {\n const latest = pkgUtils.getLatest(data);\n\n if (latest && data.versions[latest]) {\n const version: Version = data.versions[latest];\n const versions: any = { [latest]: 'latest' };\n const pkg: any = {\n name: version.name,\n description: version.description,\n [DIST_TAGS]: { latest },\n maintainers: version.maintainers || [version.author].filter(Boolean),\n author: version.author,\n repository: version.repository,\n readmeFilename: version.readmeFilename || '',\n homepage: version.homepage,\n keywords: version.keywords,\n bugs: version.bugs,\n license: version.license,\n // time: {\n // modified: time,\n // },\n versions,\n };\n\n return pkg;\n }\n}\n\nexport function isDifferentThanOne(versions: Versions | AttachMents): boolean {\n return Object.keys(versions).length !== 1;\n}\n\n// @deprecated use validationUtils.validatePublishNewPackage\nexport function hasInvalidPublishBody(manifest: Pick<Manifest, '_attachments' | 'versions'>) {\n if (!manifest) {\n return false;\n }\n\n const { _attachments, versions } = manifest;\n const res =\n isObject(_attachments) === false ||\n isDifferentThanOne(_attachments) ||\n isObject(versions) === false ||\n isDifferentThanOne(versions);\n return res;\n}\n\n/**\n * Function gets a local info and an info from uplinks and tries to merge it\n exported for unit tests only.\n * @param {*} local\n * @param {*} remoteManifest\n * @param {*} config configuration file\n */\nexport function mergeVersions(cacheManifest: Manifest, remoteManifest: Manifest): Manifest {\n let _cacheManifest = { ...cacheManifest };\n const { versions } = remoteManifest;\n // copy new versions to a cache\n // NOTE: if a certain version was updated, we can't refresh it reliably\n for (const i in versions) {\n if (typeof cacheManifest.versions[i] === 'undefined') {\n _cacheManifest.versions[i] = versions[i];\n }\n }\n\n for (const distTag in remoteManifest[DIST_TAGS]) {\n if (_cacheManifest[DIST_TAGS][distTag] !== remoteManifest[DIST_TAGS][distTag]) {\n if (\n !_cacheManifest[DIST_TAGS][distTag] ||\n semver.lte(_cacheManifest[DIST_TAGS][distTag], remoteManifest[DIST_TAGS][distTag])\n ) {\n _cacheManifest[DIST_TAGS][distTag] = remoteManifest[DIST_TAGS][distTag];\n }\n if (\n distTag === 'latest' &&\n _cacheManifest[DIST_TAGS][distTag] === remoteManifest[DIST_TAGS][distTag]\n ) {\n // NOTE: this override the latest publish readme from local cache with\n // the remote one\n cacheManifest = { ..._cacheManifest, readme: remoteManifest.readme };\n }\n }\n }\n\n return cacheManifest;\n}\n\n/**\n * Normalize dist-tags.\n *\n * There is a legacy behaviour where the dist-tags could be an array, in such\n * case, the array is orderded and the highest version becames the\n * latest.\n *\n * The dist-tag tags must be plain strigs, if the latest is empty (for whatever reason) is\n * normalized to be the highest version available.\n *\n * This function cleans up every invalid version on dist-tags, but does not remove\n * invalid versions from the manifest.\n *\n * @param {*} data\n */\nexport function normalizeDistTags(manifest: Manifest): Manifest {\n let sorted;\n // handle missing latest dist-tag\n if (!manifest[DIST_TAGS].latest) {\n // if there is no latest tag, set the highest known version based on semver sort\n sorted = sortVersionsAndFilterInvalid(Object.keys(manifest.versions));\n if (sorted?.length) {\n // get the highest published version\n manifest[DIST_TAGS].latest = sorted.pop();\n }\n }\n\n for (const tag in manifest[DIST_TAGS]) {\n // deprecated (will be removed un future majors)\n // this should not happen, tags should be plain strings, legacy fallback\n if (_.isArray(manifest[DIST_TAGS][tag])) {\n if (manifest[DIST_TAGS][tag].length) {\n // sort array\n // FIXME: this is clearly wrong, we need to research why this is like this.\n // @ts-ignore\n sorted = sortVersionsAndFilterInvalid(manifest[DIST_TAGS][tag]);\n if (sorted.length) {\n // use highest version based on semver sort\n manifest[DIST_TAGS][tag] = sorted.pop();\n }\n } else {\n delete manifest[DIST_TAGS][tag];\n }\n } else if (_.isString(manifest[DIST_TAGS][tag])) {\n if (!semver.parse(manifest[DIST_TAGS][tag], true)) {\n // if the version is invalid, delete the dist-tag entry\n delete manifest[DIST_TAGS][tag];\n }\n }\n }\n\n return manifest;\n}\n\nexport function hasDeprecatedVersions(pkgInfo: Manifest): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n\nexport function isDeprecatedManifest(manifest: Manifest): boolean {\n return hasDeprecatedVersions(manifest) && Object.keys(manifest._attachments).length === 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAGA;;AAEA;;;;AAEO,MAAMA,OAAO,GAAG;EACrBC,iBAAiB,EAAE,cADE;EAErBC,gBAAgB,EAAE,SAFG;EAGrBC,kBAAkB,EAAE,QAHC;EAIrBC,gBAAgB,EAAE;AAJG,CAAhB;AAOP;AACA;AACA;AACA;AACA;;;;AACO,SAASC,uBAAT,CAAiCC,IAAjC,EAAyD;EAC9D,OAAO;IACL;IACAA,IAFK;IAGLC,QAAQ,EAAE,EAHL;IAILC,IAAI,EAAE,EAJD;IAKL,CAACC,WAAD,GAAS,EALJ;IAML,CAACC,eAAD,GAAa,EANR;IAOLC,QAAQ,EAAE,EAPL;IAQLC,UAAU,EAAE,EARP;IASLC,YAAY,EAAE,EATT;IAULC,IAAI,EAAE;EAVD,CAAP;AAYD;AAED;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA0BC,GAA1B,EAAmD;EACxD,MAAM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ACjD;QACA,OAAOyC,QAAQ,CAACpE,eAAD,CAAR,CAAoB2B,GAApB,CAAP;MACD;IACF;EACF;;EAED,OAAOyC,QAAP;AACD;;AAEM,SAASoC,qBAAT,CAA+BC,OAA/B,EAA2D;EAChE,MAAM;IAAE5G;EAAF,IAAe4G,OAArB;;EACA,KAAK,MAAM7E,OAAX,IAAsB/B,QAAtB,EAAgC;IAC9B,IAAIgE,MAAM,CAAC6C,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqC/G,QAAQ,CAAC+B,OAAD,CAA7C,EAAwD,YAAxD,CAAJ,EAA2E;MACzE,OAAO,IAAP;IACD;EACF;;EACD,OAAO,KAAP;AACD;;AAEM,SAASiF,oBAAT,CAA8BzC,QAA9B,EAA2D;EAChE,OAAOoC,qBAAqB,CAACpC,QAAD,CAArB,IAAmCP,MAAM,CAAC6B,IAAP,CAAYtB,QAAQ,CAACjE,YAArB,EAAmCoD,MAAnC,KAA8C,CAAxF;AACD"}
1
+ {"version":3,"file":"storage-utils.js","names":["STORAGE","PACKAGE_FILE_NAME","FILE_EXIST_ERROR","NO_SUCH_FILE_ERROR","DEFAULT_REVISION","generatePackageTemplate","name","versions","time","USERS","DIST_TAGS","_uplinks","_distfiles","_attachments","_rev","normalizePackage","pkg","pkgProperties","forEach","key","pkgProp","isNil","validatioUtils","isObject","_id","normalizeDistTags","generateRevision","rev","split","generateRandomHexString","getLatestReadme","distTags","latestVersion","readme","_","trim","readmeDistTagsPriority","tag","version","cleanUpReadme","WHITELIST","cleanUpLinksRef","result","keepUpLinkData","propertyToKeep","push","i","indexOf","checkPackageRemote","isAllowPublishOffline","syncMetadata","Promise","resolve","reject","err","packageJsonLocal","upLinksErrors","status","HTTP_STATUS","NOT_FOUND","errorUtils","getConflict","API_ERROR","PACKAGE_EXIST","errorItem","length","getServiceUnavailable","UPLINK_OFFLINE_PUBLISH","mergeUplinkTimeIntoLocal","localMetadata","remoteMetadata","Object","assign","mergeUplinkTimeIntoLocalNext","cacheManifest","remoteManifest","updateUpLinkMetadata","uplinkId","manifest","etag","fetched","Date","now","prepareSearchPackage","data","latest","pkgUtils","getLatest","description","maintainers","author","filter","Boolean","repository","readmeFilename","homepage","keywords","bugs","license","isDifferentThanOne","keys","hasInvalidPublishBody","res","mergeVersions","_cacheManifest","distTag","semver","lte","sorted","sortVersionsAndFilterInvalid","pop","isArray","isString","parse","hasDeprecatedVersions","pkgInfo","prototype","hasOwnProperty","call","isDeprecatedManifest"],"sources":["../../src/lib/storage-utils.ts"],"sourcesContent":["import _ from 'lodash';\nimport semver from 'semver';\n\nimport { errorUtils, pkgUtils, validatioUtils } from '@verdaccio/core';\nimport { API_ERROR, DIST_TAGS, HTTP_STATUS, USERS } from '@verdaccio/core';\nimport { AttachMents, Manifest, Version, Versions } from '@verdaccio/types';\nimport { generateRandomHexString, isNil, isObject } from '@verdaccio/utils';\n\nimport { sortVersionsAndFilterInvalid } from './versions-utils';\n\nexport const STORAGE = {\n PACKAGE_FILE_NAME: 'package.json',\n FILE_EXIST_ERROR: 'EEXISTS',\n NO_SUCH_FILE_ERROR: 'ENOENT',\n DEFAULT_REVISION: '0-0000000000000000',\n};\n\n/**\n * Create a new package in the storage, return a boilerplate package\n * @param name package name\n * @returns {Manifest}\n */\nexport function generatePackageTemplate(name: string): Manifest {\n return {\n // standard things\n name,\n versions: {},\n time: {},\n [USERS]: {},\n [DIST_TAGS]: {},\n _uplinks: {},\n _distfiles: {},\n _attachments: {},\n _rev: '',\n };\n}\n\n/**\n * Normalize package properties, tags, revision id.\n * @param {Object} pkg package reference.\n */\nexport function normalizePackage(pkg: Manifest): Manifest {\n const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];\n\n pkgProperties.forEach((key): void => {\n const pkgProp = pkg[key];\n\n if (isNil(pkgProp) || validatioUtils.isObject(pkgProp) === false) {\n pkg[key] = {};\n }\n });\n\n if (typeof pkg?._rev !== 'string') {\n pkg._rev = STORAGE.DEFAULT_REVISION;\n }\n\n if (typeof pkg?._id !== 'string') {\n pkg._id = pkg.name;\n }\n\n // normalize dist-tags\n return normalizeDistTags(pkg);\n}\n\nexport function generateRevision(rev: string): string {\n const _rev = rev.split('-');\n\n return (+_rev[0] || 0) + 1 + '-' + generateRandomHexString();\n}\n\nexport function getLatestReadme(pkg: Manifest): string {\n const versions = pkg['versions'] || {};\n const distTags = pkg[DIST_TAGS] || {};\n // FIXME: here is a bit tricky add the types\n const latestVersion: Version | any = distTags['latest'] ? versions[distTags['latest']] || {} : {};\n let readme = _.trim(pkg.readme || latestVersion.readme || '');\n if (readme) {\n return readme;\n }\n\n // In case of empty readme - trying to get ANY readme in the following order:\n // 'next','beta','alpha','test','dev','canary'\n const readmeDistTagsPriority = ['next', 'beta', 'alpha', 'test', 'dev', 'canary'];\n readmeDistTagsPriority.forEach(function (tag): string | void {\n if (readme) {\n return readme;\n }\n const version: Version | any = distTags[tag] ? versions[distTags[tag]] || {} : {};\n readme = _.trim(version.readme || readme);\n });\n return readme;\n}\n\n// FIXME: type any due this\nexport function cleanUpReadme(version: any): Version {\n if (isNil(version) === false) {\n delete version.readme;\n }\n\n return version;\n}\n\nexport const WHITELIST = [\n '_rev',\n 'name',\n 'versions',\n 'dist-tags',\n 'readme',\n 'time',\n '_id',\n 'users',\n];\n\nexport function cleanUpLinksRef(result: Manifest, keepUpLinkData?: boolean): Manifest {\n const propertyToKeep = [...WHITELIST];\n if (keepUpLinkData === true) {\n propertyToKeep.push('_uplinks');\n }\n\n for (const i in result) {\n if (propertyToKeep.indexOf(i) === -1) {\n // Remove sections like '_uplinks' from response\n delete result[i];\n }\n }\n\n return result;\n}\n\n// TODO: move to abstract storage\n// @deprecated use abstract.storage.ts:checkPackageRemote\nexport function checkPackageRemote(\n name: string,\n isAllowPublishOffline: boolean,\n syncMetadata: Function\n): Promise<any> {\n return new Promise<void>((resolve, reject): void => {\n syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors): void => {\n // something weird\n if (err && err.status !== HTTP_STATUS.NOT_FOUND) {\n return reject(err);\n }\n\n // checking package exist already\n if (isNil(packageJsonLocal) === false) {\n return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST));\n }\n\n for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {\n // checking error\n // if uplink fails with a status other than 404, we report failure\n if (isNil(upLinksErrors[errorItem][0]) === false) {\n if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {\n if (isAllowPublishOffline) {\n return resolve();\n }\n\n return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH));\n }\n }\n }\n\n return resolve();\n });\n });\n}\n\n// @deprecated use export function mergeUplinkTimeIntoLocalNext\nexport function mergeUplinkTimeIntoLocal(localMetadata: Manifest, remoteMetadata: Manifest): any {\n if ('time' in remoteMetadata) {\n return Object.assign({}, localMetadata.time, remoteMetadata.time);\n }\n\n return localMetadata.time;\n}\n\nexport function mergeUplinkTimeIntoLocalNext(\n cacheManifest: Manifest,\n remoteManifest: Manifest\n): Manifest {\n if ('time' in remoteManifest) {\n // remote override cache time conflicts\n return { ...cacheManifest, time: { ...cacheManifest.time, ...remoteManifest.time } };\n }\n\n return cacheManifest;\n}\n\nexport function updateUpLinkMetadata(uplinkId, manifest: Manifest, etag: string) {\n const _uplinks = {\n ...manifest._uplinks,\n [uplinkId]: {\n etag,\n fetched: Date.now(),\n },\n };\n return {\n ...manifest,\n _uplinks,\n };\n}\n\nexport function prepareSearchPackage(data: Manifest): any {\n const latest = pkgUtils.getLatest(data);\n\n if (latest && data.versions[latest]) {\n const version: Version = data.versions[latest];\n const versions: any = { [latest]: 'latest' };\n const pkg: any = {\n name: version.name,\n description: version.description,\n [DIST_TAGS]: { latest },\n maintainers: version.maintainers || [version.author].filter(Boolean),\n author: version.author,\n repository: version.repository,\n readmeFilename: version.readmeFilename || '',\n homepage: version.homepage,\n keywords: version.keywords,\n bugs: version.bugs,\n license: version.license,\n // time: {\n // modified: time,\n // },\n versions,\n };\n\n return pkg;\n }\n}\n\nexport function isDifferentThanOne(versions: Versions | AttachMents): boolean {\n return Object.keys(versions).length !== 1;\n}\n\n// @deprecated use validationUtils.validatePublishNewPackage\nexport function hasInvalidPublishBody(manifest: Pick<Manifest, '_attachments' | 'versions'>) {\n if (!manifest) {\n return false;\n }\n\n const { _attachments, versions } = manifest;\n const res =\n isObject(_attachments) === false ||\n isDifferentThanOne(_attachments) ||\n isObject(versions) === false ||\n isDifferentThanOne(versions);\n return res;\n}\n\n/**\n * Function gets a local info and an info from uplinks and tries to merge it\n exported for unit tests only.\n * @param {*} local\n * @param {*} remoteManifest\n * @param {*} config configuration file\n */\nexport function mergeVersions(cacheManifest: Manifest, remoteManifest: Manifest): Manifest {\n let _cacheManifest = { ...cacheManifest };\n const { versions, time } = remoteManifest;\n // copy new versions to a cache\n // NOTE: if a certain version was updated, we can't refresh it reliably\n for (const i in versions) {\n if (typeof cacheManifest.versions[i] === 'undefined') {\n _cacheManifest.versions[i] = versions[i];\n }\n }\n\n for (const i in time) {\n if (typeof cacheManifest.time[i] === 'undefined') {\n _cacheManifest.time[i] = time[i];\n }\n }\n\n for (const distTag in remoteManifest[DIST_TAGS]) {\n if (_cacheManifest[DIST_TAGS][distTag] !== remoteManifest[DIST_TAGS][distTag]) {\n if (\n !_cacheManifest[DIST_TAGS][distTag] ||\n semver.lte(_cacheManifest[DIST_TAGS][distTag], remoteManifest[DIST_TAGS][distTag])\n ) {\n _cacheManifest[DIST_TAGS][distTag] = remoteManifest[DIST_TAGS][distTag];\n }\n if (\n distTag === 'latest' &&\n _cacheManifest[DIST_TAGS][distTag] === remoteManifest[DIST_TAGS][distTag]\n ) {\n // NOTE: this override the latest publish readme from local cache with\n // the remote one\n cacheManifest = { ..._cacheManifest, readme: remoteManifest.readme };\n }\n }\n }\n\n return cacheManifest;\n}\n\n/**\n * Normalize dist-tags.\n *\n * There is a legacy behaviour where the dist-tags could be an array, in such\n * case, the array is orderded and the highest version becames the\n * latest.\n *\n * The dist-tag tags must be plain strigs, if the latest is empty (for whatever reason) is\n * normalized to be the highest version available.\n *\n * This function cleans up every invalid version on dist-tags, but does not remove\n * invalid versions from the manifest.\n *\n * @param {*} data\n */\nexport function normalizeDistTags(manifest: Manifest): Manifest {\n let sorted;\n // handle missing latest dist-tag\n if (!manifest[DIST_TAGS].latest) {\n // if there is no latest tag, set the highest known version based on semver sort\n sorted = sortVersionsAndFilterInvalid(Object.keys(manifest.versions));\n if (sorted?.length) {\n // get the highest published version\n manifest[DIST_TAGS].latest = sorted.pop();\n }\n }\n\n for (const tag in manifest[DIST_TAGS]) {\n // deprecated (will be removed un future majors)\n // this should not happen, tags should be plain strings, legacy fallback\n if (_.isArray(manifest[DIST_TAGS][tag])) {\n if (manifest[DIST_TAGS][tag].length) {\n // sort array\n // FIXME: this is clearly wrong, we need to research why this is like this.\n // @ts-ignore\n sorted = sortVersionsAndFilterInvalid(manifest[DIST_TAGS][tag]);\n if (sorted.length) {\n // use highest version based on semver sort\n manifest[DIST_TAGS][tag] = sorted.pop();\n }\n } else {\n delete manifest[DIST_TAGS][tag];\n }\n } else if (_.isString(manifest[DIST_TAGS][tag])) {\n if (!semver.parse(manifest[DIST_TAGS][tag], true)) {\n // if the version is invalid, delete the dist-tag entry\n delete manifest[DIST_TAGS][tag];\n }\n }\n }\n\n return manifest;\n}\n\nexport function hasDeprecatedVersions(pkgInfo: Manifest): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n\nexport function isDeprecatedManifest(manifest: Manifest): boolean {\n return hasDeprecatedVersions(manifest) && Object.keys(manifest._attachments).length === 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAGA;;AAEA;;;;AAEO,MAAMA,OAAO,GAAG;EACrBC,iBAAiB,EAAE,cADE;EAErBC,gBAAgB,EAAE,SAFG;EAGrBC,kBA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B,QAAQ,CAACjE,YAArB,EAAmCoD,MAAnC,KAA8C,CAAxF;AACD"}
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { PassThrough, Readable } from 'stream';
3
3
  import { searchUtils } from '@verdaccio/core';
4
- import { IProxy, ISyncUplinksOptions, ProxySearchParams } from '@verdaccio/proxy';
5
- import { Config, Logger, Manifest, MergeTags, StringValue, Token, TokenFilter, Version } from '@verdaccio/types';
4
+ import { ISyncUplinksOptions, ProxySearchParams } from '@verdaccio/proxy';
5
+ import { AbbreviatedManifest, Config, Logger, Manifest, MergeTags, StringValue, Token, TokenFilter, Version } from '@verdaccio/types';
6
6
  import { UpdateManifestOptions } from '.';
7
7
  import { ProxyInstanceList } from './lib/uplink-util';
8
8
  import { LocalStorage } from './local-storage';
@@ -17,6 +17,7 @@ declare class Storage {
17
17
  readonly logger: Logger;
18
18
  readonly uplinks: ProxyInstanceList;
19
19
  constructor(config: Config);
20
+ static ABBREVIATED_HEADER: string;
20
21
  /**
21
22
  * Change an existing package (i.e. unpublish one version)
22
23
  Function changes a package info from local storage and all uplinks with write access./
@@ -52,18 +53,19 @@ declare class Storage {
52
53
  }): Promise<PassThrough>;
53
54
  getPackageByVersion(options: IGetPackageOptionsNext): Promise<Version>;
54
55
  getPackageManifest(options: IGetPackageOptionsNext): Promise<Manifest>;
56
+ private convertAbbreviatedManifest;
55
57
  /**
56
58
  * Return a manifest or version based on the options.
57
59
  * @param options {Object}
58
60
  * @returns A package manifest or specific version
59
61
  */
60
- getPackageByOptions(options: IGetPackageOptionsNext): Promise<Manifest | Version>;
62
+ getPackageByOptions(options: IGetPackageOptionsNext): Promise<Manifest | AbbreviatedManifest | Version>;
61
63
  getLocalDatabaseNext(): Promise<Version[]>;
62
64
  saveToken(token: Token): Promise<any>;
63
65
  deleteToken(user: string, tokenKey: string): Promise<any>;
64
66
  readTokens(filter: TokenFilter): Promise<Token[]>;
65
67
  /**
66
- * Initialize the storage asyncronously.
68
+ * Initialize the storage asynchronously.
67
69
  * @param config Config
68
70
  * @param filters IPluginFilters
69
71
  * @returns Storage instance
@@ -158,9 +160,7 @@ declare class Storage {
158
160
  uploadTarball(name: string, fileName: string, contentReadable: Readable, { signal }: {
159
161
  signal: any;
160
162
  }): Promise<void>;
161
- uploadTarballAsStream(pkgName: string, filename: string, { signal }: {
162
- signal: any;
163
- }): Promise<PassThrough>;
163
+ private uploadTarballAsStream;
164
164
  /**
165
165
  * Add a new version to a package.
166
166
  * @param name package name
@@ -175,7 +175,6 @@ declare class Storage {
175
175
  * @returns
176
176
  */
177
177
  private createNewLocalCachePackage;
178
- private isAllowPublishOffline;
179
178
  /**
180
179
  *
181
180
  * @param name package name
@@ -217,8 +216,8 @@ declare class Storage {
217
216
 
218
217
  A package requires uplinks syncronization if enables the proxy section, uplinks
219
218
  can be more than one, the more are the most slow request will take, the request
220
- are made in serie and if 1st call fails, the second will be triggered, otherwise
221
- the 1st will reply and others will be discareded. The order is important.
219
+ are made in serial and if 1st call fails, the second will be triggered, otherwise
220
+ the 1st will reply and others will be discarded. The order is important.
222
221
 
223
222
  Errors on upkinks are considered are, time outs, connection fails and http status 304,
224
223
  in that case the request returns empty body and we want ask next on the list if has fresh
@@ -237,7 +236,7 @@ declare class Storage {
237
236
  * @param options options
238
237
  * @returns Returns a promise that resolves with the merged manifest.
239
238
  */
240
- mergeCacheRemoteMetadata(uplink: IProxy, cachedManifest: Manifest, options: ISyncUplinksOptions): Promise<Manifest>;
239
+ private mergeCacheRemoteMetadata;
241
240
  /**
242
241
  * Apply filters to manifest.
243
242
  * @param manifest
package/build/storage.js CHANGED
@@ -11,6 +11,8 @@ var _debug = _interopRequireDefault(require("debug"));
11
11
 
12
12
  var _lodash = _interopRequireWildcard(require("lodash"));
13
13
 
14
+ var _path = require("path");
15
+
14
16
  var _stream = require("stream");
15
17
 
16
18
  var _promises = require("stream/promises");
@@ -71,13 +73,14 @@ class Storage {
71
73
  this.localStorage = null;
72
74
  debug('uplinks available %o', Object.keys(this.uplinks));
73
75
  }
76
+
77
+ static ABBREVIATED_HEADER = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*';
74
78
  /**
75
79
  * Change an existing package (i.e. unpublish one version)
76
80
  Function changes a package info from local storage and all uplinks with write access./
77
81
  Used storages: local (write)
78
82
  */
79
83
 
80
-
81
84
  async changePackageNext(name, metadata, revision) {
82
85
  debug('change existing package for package %o revision %o', name, revision);
83
86
  debug(`change manifest tags for %o revision %s`, name, revision);
@@ -508,6 +511,44 @@ class Storage {
508
511
  const convertedManifest = (0, _tarball.convertDistRemoteToLocalTarballUrls)(manifest, options.requestOptions, this.config.url_prefix);
509
512
  return convertedManifest;
510
513
  }
514
+
515
+ convertAbbreviatedManifest(manifest) {
516
+ const abbreviatedVersions = Object.keys(manifest.versions).reduce((acc, version) => {
517
+ const _version = manifest.versions[version]; // This should be align with this document
518
+ // https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object
519
+
520
+ const _version_abbreviated = {
521
+ name: _version.name,
522
+ version: _version.version,
523
+ description: _version.description,
524
+ deprecated: _version.deprecated,
525
+ bin: _version.bin,
526
+ dist: _version.dist,
527
+ engines: _version.engines,
528
+ funding: _version.funding,
529
+ directories: _version.directories,
530
+ dependencies: _version.dependencies,
531
+ devDependencies: _version.devDependencies,
532
+ peerDependencies: _version.peerDependencies,
533
+ optionalDependencies: _version.optionalDependencies,
534
+ bundleDependencies: _version.bundleDependencies,
535
+ // npm cli specifics
536
+ _hasShrinkwrap: _version._hasShrinkwrap,
537
+ hasInstallScript: _version.hasInstallScript
538
+ };
539
+ acc[version] = _version_abbreviated;
540
+ return acc;
541
+ }, {});
542
+ const convertedManifest = {
543
+ name: manifest['name'],
544
+ [_core.DIST_TAGS]: manifest[_core.DIST_TAGS],
545
+ versions: abbreviatedVersions,
546
+ modified: manifest.time.modified,
547
+ // NOTE: special case for pnpm https://github.com/pnpm/rfcs/pull/2
548
+ time: manifest.time
549
+ };
550
+ return convertedManifest;
551
+ }
511
552
  /**
512
553
  * Return a manifest or version based on the options.
513
554
  * @param options {Object}
@@ -520,7 +561,14 @@ class Storage {
520
561
  if (_lodash.default.isNil(options.version) === false) {
521
562
  return this.getPackageByVersion(options);
522
563
  } else {
523
- return this.getPackageManifest(options);
564
+ const manifest = await this.getPackageManifest(options);
565
+
566
+ if (options.abbreviated === true) {
567
+ debug('abbreviated manifest');
568
+ return this.convertAbbreviatedManifest(manifest);
569
+ }
570
+
571
+ return manifest;
524
572
  }
525
573
  }
526
574
 
@@ -579,7 +627,7 @@ class Storage {
579
627
  return this.localStorage.getStoragePlugin().readTokens(filter);
580
628
  }
581
629
  /**
582
- * Initialize the storage asyncronously.
630
+ * Initialize the storage asynchronously.
583
631
  * @param config Config
584
632
  * @param filters IPluginFilters
585
633
  * @returns Storage instance
@@ -927,7 +975,7 @@ class Storage {
927
975
  // if (typeof storage === 'undefined') {
928
976
  // throw errorUtils.getNotFound();
929
977
  // }
930
- throw _core.errorUtils.getInternalError('no implemenation ready for npm deprecate');
978
+ throw _core.errorUtils.getInternalError('no implementation ready for npm deprecate');
931
979
  } // eslint-disable-next-line @typescript-eslint/no-unused-vars
932
980
 
933
981
 
@@ -936,7 +984,7 @@ class Storage {
936
984
  // if (typeof storage === 'undefined') {
937
985
  // throw errorUtils.getNotFound();
938
986
  // }
939
- throw _core.errorUtils.getInternalError('no implemenation ready for npm star');
987
+ throw _core.errorUtils.getInternalError('no implementation ready for npm star');
940
988
  }
941
989
  /**
942
990
  * Get local package, on fails return null.
@@ -1025,16 +1073,19 @@ class Storage {
1025
1073
  const buffer = this.getBufferManifest(body._attachments[firstAttachmentKey].data);
1026
1074
 
1027
1075
  try {
1076
+ var _this$config, _this$config$publish;
1077
+
1028
1078
  // we check if package exist already locally
1029
1079
  const manifest = await this.getPackagelocalByNameNext(name); // if continue, the version to be published does not exist
1030
1080
 
1031
1081
  if ((manifest === null || manifest === void 0 ? void 0 : manifest.versions[versionToPublish]) != null) {
1032
1082
  debug('%s version %s already exists', name, versionToPublish);
1033
1083
  throw _core.errorUtils.getConflict();
1034
- } // if execution get here, package does not exist locally, we search upstream
1084
+ }
1035
1085
 
1086
+ const uplinksLook = ((_this$config = this.config) === null || _this$config === void 0 ? void 0 : (_this$config$publish = _this$config.publish) === null || _this$config$publish === void 0 ? void 0 : _this$config$publish.allow_offline) === false; // if execution get here, package does not exist locally, we search upstream
1036
1087
 
1037
- const remoteManifest = await this.checkPackageRemote(name, this.isAllowPublishOffline());
1088
+ const remoteManifest = await this.checkPackageRemote(name, uplinksLook);
1038
1089
 
1039
1090
  if ((remoteManifest === null || remoteManifest === void 0 ? void 0 : remoteManifest.versions[versionToPublish]) != null) {
1040
1091
  debug('%s version %s already exists', name, versionToPublish);
@@ -1097,7 +1148,7 @@ class Storage {
1097
1148
  try {
1098
1149
  const readable = _stream.Readable.from(buffer);
1099
1150
 
1100
- await this.uploadTarball(name, firstAttachmentKey, readable, {
1151
+ await this.uploadTarball(name, (0, _path.basename)(firstAttachmentKey), readable, {
1101
1152
  signal: options.signal
1102
1153
  });
1103
1154
  } catch (err) {
@@ -1136,14 +1187,13 @@ class Storage {
1136
1187
  */
1137
1188
 
1138
1189
 
1139
- async uploadTarball(name, fileName, contentReadable, {
1190
+ uploadTarball(name, fileName, contentReadable, {
1140
1191
  signal
1141
1192
  }) {
1142
1193
  return new Promise((resolve, reject) => {
1143
- (async () => {
1144
- const stream = await this.uploadTarballAsStream(name, fileName, {
1145
- signal
1146
- });
1194
+ this.uploadTarballAsStream(name, fileName, {
1195
+ signal
1196
+ }).then(stream => {
1147
1197
  stream.on('error', err => {
1148
1198
  debug('error on stream a tarball %o for %o with error %o', 'foo.tar.gz', name, err.message);
1149
1199
  reject(err);
@@ -1152,14 +1202,16 @@ class Storage {
1152
1202
  this.logger.debug({
1153
1203
  fileName,
1154
1204
  name
1155
- }, 'file @{fileName} for package @{name} has been succesfully uploaded');
1205
+ }, 'file @{fileName} for package @{name} has been successfully uploaded');
1156
1206
  resolve();
1157
1207
  });
1158
- await (0, _promises.pipeline)(contentReadable, stream, {
1208
+ return stream;
1209
+ }).then(stream => {
1210
+ (0, _promises.pipeline)(contentReadable, stream, {
1159
1211
  signal
1160
- });
1161
- })().catch(err => {
1162
- reject(err);
1212
+ }).then(() => {
1213
+ debug('success pipe upload tarball');
1214
+ }).catch(reject);
1163
1215
  });
1164
1216
  });
1165
1217
  }
@@ -1367,10 +1419,6 @@ class Storage {
1367
1419
  return;
1368
1420
  }
1369
1421
  }
1370
-
1371
- isAllowPublishOffline() {
1372
- return typeof this.config.publish !== 'undefined' && _lodash.default.isBoolean(this.config.publish.allow_offline) && this.config.publish.allow_offline;
1373
- }
1374
1422
  /**
1375
1423
  *
1376
1424
  * @param name package name
@@ -1533,8 +1581,8 @@ class Storage {
1533
1581
  proxy: npmjs
1534
1582
  A package requires uplinks syncronization if enables the proxy section, uplinks
1535
1583
  can be more than one, the more are the most slow request will take, the request
1536
- are made in serie and if 1st call fails, the second will be triggered, otherwise
1537
- the 1st will reply and others will be discareded. The order is important.
1584
+ are made in serial and if 1st call fails, the second will be triggered, otherwise
1585
+ the 1st will reply and others will be discarded. The order is important.
1538
1586
  Errors on upkinks are considered are, time outs, connection fails and http status 304,
1539
1587
  in that case the request returns empty body and we want ask next on the list if has fresh
1540
1588
  updates.
@@ -1652,7 +1700,7 @@ class Storage {
1652
1700
  const [remoteManifest, etag] = await uplink.getRemoteMetadataNext(_cacheManifest.name, remoteOptions);
1653
1701
 
1654
1702
  try {
1655
- _cacheManifest = _core.validatioUtils.normalizeMetadata(remoteManifest, _cacheManifest.name);
1703
+ _cacheManifest = _core.validatioUtils.normalizeMetadata(_cacheManifest, _cacheManifest.name);
1656
1704
  } catch (err) {
1657
1705
  this.logger.error({
1658
1706
  err: err
@@ -1665,7 +1713,7 @@ class Storage {
1665
1713
 
1666
1714
  _cacheManifest = (0, _storageUtils.mergeUplinkTimeIntoLocalNext)(_cacheManifest, remoteManifest); // update the _uplinks field in the cache
1667
1715
 
1668
- _cacheManifest = (0, _uplinkUtil.updateVersionsHiddenUpLinkNext)(cachedManifest, uplink);
1716
+ _cacheManifest = (0, _uplinkUtil.updateVersionsHiddenUpLinkNext)(_cacheManifest, uplink);
1669
1717
 
1670
1718
  try {
1671
1719
  // merge versions from remote into the cache
@@ -1674,7 +1722,7 @@ class Storage {
1674
1722
  } catch (err) {
1675
1723
  this.logger.error({
1676
1724
  err: err
1677
- }, 'package.json mergin has failed @{!err?.message}\n@{err.stack}');
1725
+ }, 'package.json merge has failed @{!err?.message}\n@{err.stack}');
1678
1726
  throw err;
1679
1727
  }
1680
1728
  }
@@ -1799,7 +1847,7 @@ class Storage {
1799
1847
  for (const versionId in remoteManifest.versions) {
1800
1848
  // if detect a new remote version does not exist cache
1801
1849
  if (_lodash.default.isNil(cacheManifest.versions[versionId])) {
1802
- var _version, _version$dist;
1850
+ var _version2, _version2$dist;
1803
1851
 
1804
1852
  debug('new version from upstream %o', versionId);
1805
1853
  let version = remoteManifest.versions[versionId]; // we don't keep readme for package versions,
@@ -1812,7 +1860,7 @@ class Storage {
1812
1860
  change = true;
1813
1861
  cacheManifest.versions[versionId] = version;
1814
1862
 
1815
- if ((_version = version) !== null && _version !== void 0 && (_version$dist = _version.dist) !== null && _version$dist !== void 0 && _version$dist.tarball) {
1863
+ if ((_version2 = version) !== null && _version2 !== void 0 && (_version2$dist = _version2.dist) !== null && _version2$dist !== void 0 && _version2$dist.tarball) {
1816
1864
  const filename = _core.pkgUtils.extractTarballName(version.dist.tarball); // store a fast access to the dist file by tarball name
1817
1865
  // it does NOT overwrite any existing records
1818
1866