mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
68ea21214a
* fix: eslint errors * fix: rename a test * fix: broken integration test due to removing next argument in the middleware. * changeset
150 lines
4.2 KiB
TypeScript
150 lines
4.2 KiB
TypeScript
import { Package } from '@verdaccio/types';
|
|
|
|
export function generateVersion(pkgName, version) {
|
|
return {
|
|
name: pkgName,
|
|
version: version,
|
|
description: 'some foo dependency',
|
|
main: 'index.js',
|
|
scripts: {
|
|
test: 'echo "Error: no test specified" && exit 1',
|
|
},
|
|
keywords: [],
|
|
author: {
|
|
name: 'User NPM',
|
|
email: 'user@domain.com',
|
|
},
|
|
license: 'ISC',
|
|
dependencies: {
|
|
verdaccio: '^4.0.0',
|
|
},
|
|
readme: '# test',
|
|
readmeFilename: 'README.md',
|
|
_id: `${pkgName}@${version}`,
|
|
_npmVersion: '5.5.1',
|
|
_npmUser: {
|
|
name: 'foo',
|
|
},
|
|
dist: {
|
|
integrity:
|
|
'sha512-6gHiERpiDgtb3hjqpQH5/i7zRmvYi9pmCjQf2ZMy3QEa9wVk9RgdZaPWUt7ZOnWUPFjcr9c' +
|
|
'mE6dUBf+XoPoH4g==',
|
|
shasum: '2c03764f651a9f016ca0b7620421457b619151b9', // pragma: allowlist secret
|
|
tarball: `http:\/\/localhost:5555\/${pkgName}\/-\/${pkgName}-${version}.tgz`,
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* The metadata that comes from npm unpublish only contains the versions won't be removed and
|
|
* also does not includes any _attachment.
|
|
* @param pkgName
|
|
* @param _versions
|
|
*/
|
|
export function generatePackageUnpublish(
|
|
pkgName: string,
|
|
_versions: string[] = ['1.0.0']
|
|
): Package {
|
|
const latest: string = _versions[_versions.length - 1];
|
|
const versions = _versions.reduce((cat, version) => {
|
|
cat[version] = generateVersion(pkgName, version);
|
|
return cat;
|
|
}, {});
|
|
|
|
// @ts-ignore
|
|
return {
|
|
_id: pkgName,
|
|
name: pkgName,
|
|
readme: '# test',
|
|
// users usually is present when run npm star [pkg]
|
|
users: {},
|
|
'dist-tags': {
|
|
latest: latest,
|
|
},
|
|
versions: versions,
|
|
};
|
|
}
|
|
|
|
export function generateStarMedatada(pkgName: string, users): any {
|
|
return {
|
|
_id: pkgName,
|
|
_rev: '3-b0cdaefc9bdb77c8',
|
|
users: users,
|
|
};
|
|
}
|
|
|
|
export function generatePackageMetadata(pkgName: string, version = '1.0.0'): Package {
|
|
// @ts-ignore
|
|
return {
|
|
_id: pkgName,
|
|
name: pkgName,
|
|
'dist-tags': {
|
|
latest: version,
|
|
},
|
|
versions: {
|
|
[version]: {
|
|
name: pkgName,
|
|
version: version,
|
|
description: '',
|
|
main: 'index.js',
|
|
scripts: {
|
|
test: 'echo "Error: no test specified" && exit 1',
|
|
},
|
|
keywords: [],
|
|
author: {
|
|
name: 'User NPM',
|
|
email: 'user@domain.com',
|
|
},
|
|
license: 'ISC',
|
|
dependencies: {
|
|
verdaccio: '^2.7.2',
|
|
},
|
|
readme: '# test',
|
|
readmeFilename: 'README.md',
|
|
_id: `${pkgName}@${version}`,
|
|
_npmVersion: '5.5.1',
|
|
_npmUser: {
|
|
name: 'foo',
|
|
},
|
|
dist: {
|
|
integrity:
|
|
'sha512-6gHiERpiDgtb3hjqpQH5/i7zRmvYi9pmCjQf2ZMy3QEa9wVk9RgdZaPWUt7ZOnWUPFjcr' +
|
|
'9cmE6dUBf+XoPoH4g==',
|
|
shasum: '2c03764f651a9f016ca0b7620421457b619151b9', // pragma: allowlist secret
|
|
tarball: `http:\/\/localhost:5555\/${pkgName}\/-\/${pkgName}-${version}.tgz`,
|
|
},
|
|
},
|
|
},
|
|
readme: '# test',
|
|
_attachments: {
|
|
[`${pkgName}-${version}.tgz`]: {
|
|
content_type: 'application/octet-stream',
|
|
data:
|
|
'H4sIAAAAAAAAE+2W32vbMBDH85y/QnjQp9qxLEeBMsbGlocNBmN7bFdQ5WuqxJaEpGQdo//79KPeQsnI' +
|
|
'w5KUDX/9IOvurLuz/DHSjK/YAiY6jcXSKjk6sMqypHWNdtmD6hlBI0wqQmo8nVbVqMR4OsNoVB66kF1a' +
|
|
'W8eML+Vv10m9oF/jP6IfY4QyyTrILlD2eqkcm+gVzpdrJrPz4NuAsULJ4MZFWdBkbcByI7R79CRjx0Sc' +
|
|
'CdnAvf+SkjUFWu8IubzBgXUhDPidQlfZ3BhlLpBUKDiQ1cDFrYDmKkNnZwjuhUM4808+xNVW8P2bMk1Y' +
|
|
'7vJrtLC1u1MmLPjBF40+Cc4ahV6GDmI/DWygVRpMwVX3KtXUCg7Sxp7ff3nbt6TBFy65gK1iffsN41yo' +
|
|
'EHtdFbOiisWMH8bPvXUH0SP3k+KG3UBr+DFy7OGfEJr4x5iWVeS/pLQe+D+FIv/agIWI6GX66kFuIhT+' +
|
|
'1gDjrp/4d7WAvAwEJPh0u14IufWkM0zaW2W6nLfM2lybgJ4LTJ0/jWiAK8OcMjt8MW3OlfQppcuhhQ6k' +
|
|
'+2OgkK2Q8DssFPi/IHpU9fz3/+xj5NjDf8QFE39VmE4JDfzPCBn4P4X6/f88f/Pu47zomiPk2Lv/dOv8' +
|
|
'h+P/34/D/p9CL+Kp67mrGDRo0KBBp9ZPsETQegASAAA=',
|
|
length: 512,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
export function generateDeprecateMetadata(
|
|
pkgName: string,
|
|
version = '1.0.0',
|
|
deprecated: string = ''
|
|
): Package {
|
|
const res = {
|
|
...generatePackageMetadata(pkgName, version),
|
|
_attachments: {},
|
|
};
|
|
res.versions[version].deprecated = deprecated;
|
|
return res;
|
|
}
|