@verdaccio/core 8.0.0-next-8.11 → 8.0.0-next-8.13
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/LICENSE +1 -1
- package/README.md +73 -12
- package/build/constants.d.ts +3 -0
- package/build/constants.js +6 -1
- package/build/constants.js.map +1 -1
- package/build/plugin-utils.d.ts +2 -2
- package/build/plugin-utils.js.map +1 -1
- package/package.json +3 -3
- package/.babelrc +0 -14
- package/.eslintignore +0 -6
- package/.eslintrc.json +0 -5
- package/CHANGELOG.md +0 -565
- package/src/constants.ts +0 -134
- package/src/error-utils.ts +0 -106
- package/src/file-utils.ts +0 -31
- package/src/index.ts +0 -46
- package/src/path-utils.ts +0 -0
- package/src/pkg-utils.ts +0 -68
- package/src/plugin-utils.ts +0 -205
- package/src/schemes/publish-manifest.ts +0 -38
- package/src/schemes/unpublish-manifest.ts +0 -69
- package/src/search-utils.ts +0 -81
- package/src/stream-utils.ts +0 -28
- package/src/string-utils.ts +0 -36
- package/src/tarball-utils.ts +0 -43
- package/src/validation-utils.ts +0 -128
- package/src/warning-utils.ts +0 -69
- package/test/errors.spec.ts +0 -109
- package/test/merge.dist.tags.spec.ts +0 -64
- package/test/mystreams.spec.ts +0 -18
- package/test/pkg-utils.spec.ts +0 -28
- package/test/publish-manifest.spec.ts +0 -61
- package/test/string-utils.spec.ts +0 -42
- package/test/tarball-utils.spec.ts +0 -81
- package/test/unpublish-manifest.spec.ts +0 -71
- package/test/validation-utilts.spec.ts +0 -182
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -12
- package/typedoc.json +0 -5
package/src/string-utils.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Quality values, or q-values and q-factors, are used to describe the order
|
|
3
|
-
* of priority of values in a comma-separated list.
|
|
4
|
-
* It is a special syntax allowed in some HTTP headers and in HTML.
|
|
5
|
-
* https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
|
|
6
|
-
* @param headerValue
|
|
7
|
-
*/
|
|
8
|
-
export function getByQualityPriorityValue(headerValue: string | undefined | null): string {
|
|
9
|
-
if (typeof headerValue !== 'string') {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const split = headerValue.split(',');
|
|
14
|
-
|
|
15
|
-
if (split.length <= 1) {
|
|
16
|
-
const qList = split[0].split(';');
|
|
17
|
-
return qList[0];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let [header] = split
|
|
21
|
-
.reduce((acc, item: string) => {
|
|
22
|
-
const qList = item.split(';');
|
|
23
|
-
if (qList.length > 1) {
|
|
24
|
-
const [accept, q] = qList;
|
|
25
|
-
const [, query] = q.split('=');
|
|
26
|
-
acc.push([accept.trim(), query ? query : 0]);
|
|
27
|
-
} else {
|
|
28
|
-
acc.push([qList[0], 0]);
|
|
29
|
-
}
|
|
30
|
-
return acc;
|
|
31
|
-
}, [] as any)
|
|
32
|
-
.sort(function (a: number[], b: number[]) {
|
|
33
|
-
return b[1] - a[1];
|
|
34
|
-
});
|
|
35
|
-
return header[0];
|
|
36
|
-
}
|
package/src/tarball-utils.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { URL } from 'url';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return package version from tarball name
|
|
5
|
-
*
|
|
6
|
-
* test-1.2.4.tgz -> 1.2.4
|
|
7
|
-
* @param {String} fileName
|
|
8
|
-
* @returns {String}
|
|
9
|
-
*/
|
|
10
|
-
export function getVersionFromTarball(fileName: string): string | void {
|
|
11
|
-
const groups = fileName.replace(/\.tgz$/, '').match(/^[^/]+-(\d+\.\d+\.\d+.*)/);
|
|
12
|
-
|
|
13
|
-
return groups !== null ? groups[1] : undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Extract the tarball name from a registry dist url
|
|
18
|
-
*
|
|
19
|
-
* https://registry.npmjs.org/test/-/test-0.0.2.tgz -> test-0.0.2.tgz
|
|
20
|
-
* @param tarball tarball url
|
|
21
|
-
* @returns tarball filename
|
|
22
|
-
*/
|
|
23
|
-
export function extractTarballFromUrl(url: string): string {
|
|
24
|
-
const urlObject = new URL(url);
|
|
25
|
-
return urlObject.pathname.replace(/^.*\//, '');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Build the tarball filename from paackage name and version
|
|
30
|
-
*
|
|
31
|
-
* test, 1.2.4 -> test-1.2.4.tgz
|
|
32
|
-
* @scope/name, 1.2.4 -> name-1.2.4.tgz
|
|
33
|
-
* @param name package name
|
|
34
|
-
* @param version package version
|
|
35
|
-
* @returns tarball filename
|
|
36
|
-
*/
|
|
37
|
-
export function composeTarballFromPackage(name: string, version: string): string {
|
|
38
|
-
if (name.includes('/')) {
|
|
39
|
-
return `${name.split('/')[1]}-${version}.tgz`;
|
|
40
|
-
} else {
|
|
41
|
-
return `${name}-${version}.tgz`;
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/validation-utils.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
|
|
3
|
-
import { Manifest } from '@verdaccio/types';
|
|
4
|
-
|
|
5
|
-
import { DEFAULT_PASSWORD_VALIDATION, DIST_TAGS, MAINTAINERS } from './constants';
|
|
6
|
-
|
|
7
|
-
export { validatePublishSingleVersion } from './schemes/publish-manifest';
|
|
8
|
-
export { validateUnPublishSingleVersion } from './schemes/unpublish-manifest';
|
|
9
|
-
|
|
10
|
-
export function isPackageNameScoped(name: string): boolean {
|
|
11
|
-
return name.startsWith('@');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* From normalize-package-data/lib/fixer.js
|
|
16
|
-
* @param {*} name the package name
|
|
17
|
-
* @return {Boolean} whether is valid or not
|
|
18
|
-
*/
|
|
19
|
-
export function validateName(name: string): boolean {
|
|
20
|
-
if (typeof name !== 'string') {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let normalizedName: string = name.toLowerCase();
|
|
25
|
-
|
|
26
|
-
const isScoped: boolean = isPackageNameScoped(name);
|
|
27
|
-
const scopedName = name.split('/', 2)[1];
|
|
28
|
-
|
|
29
|
-
if (isScoped && typeof scopedName !== 'undefined') {
|
|
30
|
-
normalizedName = scopedName.toLowerCase();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Some context about the first regex
|
|
35
|
-
* - npm used to have a different tarball naming system.
|
|
36
|
-
* eg: http://registry.npmjs.com/thirty-two
|
|
37
|
-
* https://registry.npmjs.org/thirty-two/-/thirty-two@0.0.1.tgz
|
|
38
|
-
* The file name thirty-two@0.0.1.tgz, the version and the pkg name was separated by an at (@)
|
|
39
|
-
* while nowadays the naming system is based in dashes
|
|
40
|
-
* https://registry.npmjs.org/verdaccio/-/verdaccio-1.4.0.tgz
|
|
41
|
-
*
|
|
42
|
-
* more info here: https://github.com/rlidwka/sinopia/issues/75
|
|
43
|
-
*/
|
|
44
|
-
return !(
|
|
45
|
-
!normalizedName.match(/^[-a-zA-Z0-9_.!~*'()@]+$/) ||
|
|
46
|
-
normalizedName.startsWith('.') || // ".bin", etc.
|
|
47
|
-
['node_modules', '__proto__', 'favicon.ico'].includes(normalizedName)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Validate a package.
|
|
53
|
-
* @return {Boolean} whether the package is valid or not
|
|
54
|
-
*/
|
|
55
|
-
export function validatePackage(name: string): boolean {
|
|
56
|
-
const nameList = name.split('/', 2);
|
|
57
|
-
if (nameList.length === 1) {
|
|
58
|
-
// normal package
|
|
59
|
-
return validateName(nameList[0]);
|
|
60
|
-
}
|
|
61
|
-
// scoped package
|
|
62
|
-
return nameList[0][0] === '@' && validateName(nameList[0].slice(1)) && validateName(nameList[1]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Validate the package metadata, add additional properties whether are missing within
|
|
67
|
-
* the metadata properties.
|
|
68
|
-
* @param {*} manifest
|
|
69
|
-
* @param {*} name
|
|
70
|
-
* @return {Object} the object with additional properties as dist-tags ad versions
|
|
71
|
-
*/
|
|
72
|
-
export function normalizeMetadata(manifest: Manifest, name: string): Manifest {
|
|
73
|
-
assert.strictEqual(manifest.name, name);
|
|
74
|
-
const _manifest = { ...manifest };
|
|
75
|
-
|
|
76
|
-
if (!isObject(manifest[DIST_TAGS])) {
|
|
77
|
-
_manifest[DIST_TAGS] = {};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!Array.isArray(manifest[MAINTAINERS])) {
|
|
81
|
-
_manifest[MAINTAINERS] = [];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// This may not be needed
|
|
85
|
-
if (!isObject(manifest['versions'])) {
|
|
86
|
-
_manifest['versions'] = {};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!isObject(manifest['time'])) {
|
|
90
|
-
_manifest['time'] = {};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return _manifest;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Check whether an element is an Object
|
|
98
|
-
* @param {*} obj the element
|
|
99
|
-
* @return {Boolean}
|
|
100
|
-
*/
|
|
101
|
-
export function isObject(obj: any): boolean {
|
|
102
|
-
// if (obj === null || typeof obj === 'undefined' || typeof obj === 'string') {
|
|
103
|
-
// return false;
|
|
104
|
-
// }
|
|
105
|
-
|
|
106
|
-
// return (
|
|
107
|
-
// (typeof obj === 'object' || typeof obj.prototype === 'undefined') &&
|
|
108
|
-
// Array.isArray(obj) === false
|
|
109
|
-
// );
|
|
110
|
-
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function validatePassword(
|
|
114
|
-
password: string,
|
|
115
|
-
validation: RegExp = DEFAULT_PASSWORD_VALIDATION
|
|
116
|
-
): boolean {
|
|
117
|
-
return typeof password === 'string' && validation instanceof RegExp
|
|
118
|
-
? password.match(validation) !== null
|
|
119
|
-
: false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function validateUserName(userName: any, expectedName: string): boolean {
|
|
123
|
-
return (
|
|
124
|
-
typeof userName === 'string' &&
|
|
125
|
-
userName.split(':')[0] === 'org.couchdb.user' &&
|
|
126
|
-
userName.split(':')[1] === expectedName
|
|
127
|
-
);
|
|
128
|
-
}
|
package/src/warning-utils.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import warning from 'process-warning';
|
|
2
|
-
|
|
3
|
-
const warningInstance = warning();
|
|
4
|
-
const verdaccioWarning = 'VerdaccioWarning';
|
|
5
|
-
const verdaccioDeprecation = 'VerdaccioDeprecation';
|
|
6
|
-
|
|
7
|
-
export enum Codes {
|
|
8
|
-
VERWAR001 = 'VERWAR001',
|
|
9
|
-
VERWAR002 = 'VERWAR002',
|
|
10
|
-
VERWAR003 = 'VERWAR003',
|
|
11
|
-
VERWAR004 = 'VERWAR004',
|
|
12
|
-
// deprecation warnings
|
|
13
|
-
VERDEP003 = 'VERDEP003',
|
|
14
|
-
VERWAR006 = 'VERWAR006',
|
|
15
|
-
VERWAR007 = 'VERWAR007',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* general warnings */
|
|
19
|
-
|
|
20
|
-
warningInstance.create(
|
|
21
|
-
verdaccioWarning,
|
|
22
|
-
Codes.VERWAR001,
|
|
23
|
-
`Verdaccio doesn't need superuser privileges. don't run it under root`
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
warningInstance.create(
|
|
27
|
-
verdaccioWarning,
|
|
28
|
-
Codes.VERWAR002,
|
|
29
|
-
`The configuration property "logs" has been deprecated, please rename to "log" for future compatibility`
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
warningInstance.create(
|
|
33
|
-
verdaccioWarning,
|
|
34
|
-
Codes.VERWAR003,
|
|
35
|
-
'rotating-file type is not longer supported, consider use [logrotate] instead'
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
warningInstance.create(
|
|
39
|
-
verdaccioWarning,
|
|
40
|
-
Codes.VERWAR004,
|
|
41
|
-
`invalid address - %s, we expect a port (e.g. "4873"),
|
|
42
|
-
host:port (e.g. "localhost:4873") or full url '(e.g. "http://localhost:4873/")
|
|
43
|
-
https://verdaccio.org/docs/en/configuration#listen-port`
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
warningInstance.create(
|
|
47
|
-
verdaccioDeprecation,
|
|
48
|
-
Codes.VERWAR006,
|
|
49
|
-
'the auth plugin method "add_user" in the auth plugin is deprecated and will be removed in next major release, rename to "adduser"'
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
warningInstance.create(
|
|
53
|
-
verdaccioDeprecation,
|
|
54
|
-
Codes.VERWAR007,
|
|
55
|
-
`the secret length is too long, it must be 32 characters long, please consider generate a new one
|
|
56
|
-
Learn more at https://verdaccio.org/docs/configuration/#.verdaccio-db`
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
/* deprecation warnings */
|
|
60
|
-
|
|
61
|
-
warningInstance.create(
|
|
62
|
-
verdaccioDeprecation,
|
|
63
|
-
Codes.VERDEP003,
|
|
64
|
-
'multiple addresses will be deprecated in the next major, only use one'
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
export function emit(code: string, a?: string, b?: string, c?: string) {
|
|
68
|
-
warningInstance.emit(code, a, b, c);
|
|
69
|
-
}
|
package/test/errors.spec.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { HTTP_STATUS } from '../src/constants';
|
|
5
|
-
import {
|
|
6
|
-
API_ERROR,
|
|
7
|
-
VerdaccioError,
|
|
8
|
-
getBadData,
|
|
9
|
-
getCode,
|
|
10
|
-
getConflict,
|
|
11
|
-
getForbidden,
|
|
12
|
-
getInternalError,
|
|
13
|
-
getNotFound,
|
|
14
|
-
getServiceUnavailable,
|
|
15
|
-
getUnauthorized,
|
|
16
|
-
} from '../src/error-utils';
|
|
17
|
-
|
|
18
|
-
describe('testing errors', () => {
|
|
19
|
-
test('should qualify as an native error', () => {
|
|
20
|
-
expect(_.isError(getNotFound())).toBeTruthy();
|
|
21
|
-
expect(_.isError(getConflict())).toBeTruthy();
|
|
22
|
-
expect(_.isError(getBadData())).toBeTruthy();
|
|
23
|
-
expect(_.isError(getInternalError())).toBeTruthy();
|
|
24
|
-
expect(_.isError(getUnauthorized())).toBeTruthy();
|
|
25
|
-
expect(_.isError(getForbidden())).toBeTruthy();
|
|
26
|
-
expect(_.isError(getServiceUnavailable())).toBeTruthy();
|
|
27
|
-
expect(_.isError(getCode(400, 'fooError'))).toBeTruthy();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('should test not found', () => {
|
|
31
|
-
const err: VerdaccioError = getNotFound('foo');
|
|
32
|
-
|
|
33
|
-
expect(err.code).toBeDefined();
|
|
34
|
-
expect(err.code).toEqual(HTTP_STATUS.NOT_FOUND);
|
|
35
|
-
expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND);
|
|
36
|
-
expect(err.message).toEqual('foo');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should test conflict', () => {
|
|
40
|
-
const err: VerdaccioError = getConflict('foo');
|
|
41
|
-
|
|
42
|
-
expect(err.code).toBeDefined();
|
|
43
|
-
expect(err.code).toEqual(HTTP_STATUS.CONFLICT);
|
|
44
|
-
expect(err.message).toEqual('foo');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should test bad data', () => {
|
|
48
|
-
const err: VerdaccioError = getBadData('foo');
|
|
49
|
-
|
|
50
|
-
expect(err.code).toBeDefined();
|
|
51
|
-
expect(err.code).toEqual(HTTP_STATUS.BAD_DATA);
|
|
52
|
-
expect(err.message).toEqual('foo');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('should test internal error custom message', () => {
|
|
56
|
-
const err: VerdaccioError = getInternalError('foo');
|
|
57
|
-
|
|
58
|
-
expect(err.code).toBeDefined();
|
|
59
|
-
expect(err.code).toEqual(HTTP_STATUS.INTERNAL_ERROR);
|
|
60
|
-
expect(err.message).toEqual('foo');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('should test internal error', () => {
|
|
64
|
-
const err: VerdaccioError = getInternalError();
|
|
65
|
-
|
|
66
|
-
expect(err.code).toBeDefined();
|
|
67
|
-
expect(err.code).toEqual(HTTP_STATUS.INTERNAL_ERROR);
|
|
68
|
-
expect(err.message).toEqual(API_ERROR.UNKNOWN_ERROR);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('should test Unauthorized message', () => {
|
|
72
|
-
const err: VerdaccioError = getUnauthorized('foo');
|
|
73
|
-
|
|
74
|
-
expect(err.code).toBeDefined();
|
|
75
|
-
expect(err.code).toEqual(HTTP_STATUS.UNAUTHORIZED);
|
|
76
|
-
expect(err.message).toEqual('foo');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('should test forbidden message', () => {
|
|
80
|
-
const err: VerdaccioError = getForbidden('foo');
|
|
81
|
-
|
|
82
|
-
expect(err.code).toBeDefined();
|
|
83
|
-
expect(err.code).toEqual(HTTP_STATUS.FORBIDDEN);
|
|
84
|
-
expect(err.message).toEqual('foo');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('should test service unavailable message', () => {
|
|
88
|
-
const err: VerdaccioError = getServiceUnavailable('foo');
|
|
89
|
-
|
|
90
|
-
expect(err.code).toBeDefined();
|
|
91
|
-
expect(err.code).toEqual(HTTP_STATUS.SERVICE_UNAVAILABLE);
|
|
92
|
-
expect(err.message).toEqual('foo');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('should test custom code error message', () => {
|
|
96
|
-
const err: VerdaccioError = getCode(HTTP_STATUS.NOT_FOUND, 'foo');
|
|
97
|
-
|
|
98
|
-
expect(err.code).toBeDefined();
|
|
99
|
-
expect(err.code).toEqual(HTTP_STATUS.NOT_FOUND);
|
|
100
|
-
expect(err.message).toEqual('foo');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('should test custom code ok message', () => {
|
|
104
|
-
const err: VerdaccioError = getCode(HTTP_STATUS.OK, 'foo');
|
|
105
|
-
|
|
106
|
-
expect(err.code).toBeDefined();
|
|
107
|
-
expect(err.code).toEqual(HTTP_STATUS.OK);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { mergeVersions, semverSort } from '../src/pkg-utils';
|
|
4
|
-
|
|
5
|
-
describe('Storage._merge_versions versions', () => {
|
|
6
|
-
test('simple', () => {
|
|
7
|
-
let pkg = {
|
|
8
|
-
versions: { a: 1, b: 1, c: 1 },
|
|
9
|
-
'dist-tags': {},
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
mergeVersions(pkg, { versions: { a: 2, q: 2 } });
|
|
14
|
-
|
|
15
|
-
expect(pkg).toStrictEqual({
|
|
16
|
-
versions: { a: 1, b: 1, c: 1, q: 2 },
|
|
17
|
-
'dist-tags': {},
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('dist-tags - compat', () => {
|
|
22
|
-
let pkg = {
|
|
23
|
-
versions: {},
|
|
24
|
-
'dist-tags': { q: '1.1.1', w: '2.2.2' },
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
mergeVersions(pkg, { 'dist-tags': { q: '2.2.2', w: '3.3.3', t: '4.4.4' } });
|
|
29
|
-
|
|
30
|
-
expect(pkg).toStrictEqual({
|
|
31
|
-
versions: {},
|
|
32
|
-
'dist-tags': { q: '2.2.2', w: '3.3.3', t: '4.4.4' },
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('dist-tags - staging', () => {
|
|
37
|
-
let pkg = {
|
|
38
|
-
versions: {},
|
|
39
|
-
// we've been locally publishing 1.1.x in preparation for the next
|
|
40
|
-
// public release
|
|
41
|
-
'dist-tags': { q: '1.1.10', w: '2.2.2' },
|
|
42
|
-
};
|
|
43
|
-
// 1.1.2 is the latest public release, but we want to continue testing
|
|
44
|
-
// against our local 1.1.10, which may end up published as 1.1.3 in the
|
|
45
|
-
// future
|
|
46
|
-
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
mergeVersions(pkg, { 'dist-tags': { q: '1.1.2', w: '3.3.3', t: '4.4.4' } });
|
|
49
|
-
|
|
50
|
-
expect(pkg).toStrictEqual({
|
|
51
|
-
versions: {},
|
|
52
|
-
'dist-tags': { q: '1.1.10', w: '3.3.3', t: '4.4.4' },
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('semverSort', () => {
|
|
57
|
-
expect(semverSort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b'])).toStrictEqual([
|
|
58
|
-
'1.2.3a',
|
|
59
|
-
'1.2.3-b',
|
|
60
|
-
'1.2.3c',
|
|
61
|
-
'1.2.3',
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
});
|
package/test/mystreams.spec.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Stream } from 'stream';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { readableToString } from '../src/stream-utils';
|
|
5
|
-
|
|
6
|
-
describe('mystreams', () => {
|
|
7
|
-
test('readableToString single string', async () => {
|
|
8
|
-
expect(await readableToString(Stream.Readable.from('foo'))).toEqual('foo');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('readableToString single object', async () => {
|
|
12
|
-
expect(
|
|
13
|
-
JSON.parse(await readableToString(Stream.Readable.from(JSON.stringify({ foo: 1 }))))
|
|
14
|
-
).toEqual({
|
|
15
|
-
foo: 1,
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
package/test/pkg-utils.spec.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { DIST_TAGS, pkgUtils } from '../src';
|
|
4
|
-
|
|
5
|
-
describe('pkg-utils', () => {
|
|
6
|
-
test('getLatest fails if no versions', () => {
|
|
7
|
-
expect(() =>
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
pkgUtils.getLatest({
|
|
10
|
-
versions: {},
|
|
11
|
-
})
|
|
12
|
-
).toThrow('cannot get lastest version of none');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('getLatest get latest', () => {
|
|
16
|
-
expect(
|
|
17
|
-
pkgUtils.getLatest({
|
|
18
|
-
versions: {
|
|
19
|
-
// @ts-expect-error
|
|
20
|
-
'1.0.0': {},
|
|
21
|
-
},
|
|
22
|
-
[DIST_TAGS]: {
|
|
23
|
-
latest: '1.0.0',
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
).toBe('1.0.0');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { validatePublishSingleVersion } from '../src/schemes/publish-manifest';
|
|
4
|
-
|
|
5
|
-
describe('validatePublishSingleVersion', () => {
|
|
6
|
-
describe('valid cases', () => {
|
|
7
|
-
test('should validate a manifest when name and versions are present, even with extra properties', () => {
|
|
8
|
-
const manifest = {
|
|
9
|
-
name: 'foo-pkg',
|
|
10
|
-
_attachments: { '2': {} },
|
|
11
|
-
versions: { '1': {} },
|
|
12
|
-
something: 'else',
|
|
13
|
-
};
|
|
14
|
-
expect(validatePublishSingleVersion(manifest)).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('invalid cases', () => {
|
|
19
|
-
test('should invalidate a manifest when name is missing', () => {
|
|
20
|
-
const manifest = {
|
|
21
|
-
_attachments: { '2': {} },
|
|
22
|
-
versions: { '1': {} },
|
|
23
|
-
};
|
|
24
|
-
expect(validatePublishSingleVersion(manifest)).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('should invalidate a manifest when _attachments is missing', () => {
|
|
28
|
-
const manifest = {
|
|
29
|
-
name: 'foo-pkg',
|
|
30
|
-
versions: { '1': {} },
|
|
31
|
-
};
|
|
32
|
-
expect(validatePublishSingleVersion(manifest)).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('should invalidate a manifest when versions is missing', () => {
|
|
36
|
-
const manifest = {
|
|
37
|
-
name: 'foo-pkg',
|
|
38
|
-
_attachments: { '1': {} },
|
|
39
|
-
};
|
|
40
|
-
expect(validatePublishSingleVersion(manifest)).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('should invalidate a manifest when versions contains more than one entry', () => {
|
|
44
|
-
const manifest = {
|
|
45
|
-
name: 'foo-pkg',
|
|
46
|
-
versions: { '1': {}, '2': {} },
|
|
47
|
-
_attachments: { '1': {} },
|
|
48
|
-
};
|
|
49
|
-
expect(validatePublishSingleVersion(manifest)).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('should invalidate a manifest when _attachments contains more than one entry', () => {
|
|
53
|
-
const manifest = {
|
|
54
|
-
name: 'foo-pkg',
|
|
55
|
-
_attachments: { '1': {}, '2': {} },
|
|
56
|
-
versions: { '1': {} },
|
|
57
|
-
};
|
|
58
|
-
expect(validatePublishSingleVersion(manifest)).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { stringUtils } from '../src';
|
|
4
|
-
|
|
5
|
-
describe('string-utils', () => {
|
|
6
|
-
test('getByQualityPriorityValue', () => {
|
|
7
|
-
expect(stringUtils.getByQualityPriorityValue('')).toEqual('');
|
|
8
|
-
expect(stringUtils.getByQualityPriorityValue(null)).toEqual('');
|
|
9
|
-
expect(stringUtils.getByQualityPriorityValue(undefined)).toEqual('');
|
|
10
|
-
expect(stringUtils.getByQualityPriorityValue('something')).toEqual('something');
|
|
11
|
-
expect(stringUtils.getByQualityPriorityValue('something,')).toEqual('something');
|
|
12
|
-
expect(stringUtils.getByQualityPriorityValue('0,')).toEqual('0');
|
|
13
|
-
expect(stringUtils.getByQualityPriorityValue('application/json')).toEqual('application/json');
|
|
14
|
-
expect(stringUtils.getByQualityPriorityValue('application/json; q=1')).toEqual(
|
|
15
|
-
'application/json'
|
|
16
|
-
);
|
|
17
|
-
expect(stringUtils.getByQualityPriorityValue('application/json; q=')).toEqual(
|
|
18
|
-
'application/json'
|
|
19
|
-
);
|
|
20
|
-
expect(stringUtils.getByQualityPriorityValue('application/json;')).toEqual('application/json');
|
|
21
|
-
expect(
|
|
22
|
-
stringUtils.getByQualityPriorityValue(
|
|
23
|
-
'application/json; q=1.0, application/vnd.npm.install-v1+json; q=0.9, */*'
|
|
24
|
-
)
|
|
25
|
-
).toEqual('application/json');
|
|
26
|
-
expect(
|
|
27
|
-
stringUtils.getByQualityPriorityValue(
|
|
28
|
-
'application/json; q=1.0, application/vnd.npm.install-v1+json; q=, */*'
|
|
29
|
-
)
|
|
30
|
-
).toEqual('application/json');
|
|
31
|
-
expect(
|
|
32
|
-
stringUtils.getByQualityPriorityValue(
|
|
33
|
-
'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.9, */*'
|
|
34
|
-
)
|
|
35
|
-
).toEqual('application/vnd.npm.install-v1+json');
|
|
36
|
-
expect(
|
|
37
|
-
stringUtils.getByQualityPriorityValue(
|
|
38
|
-
'application/vnd.npm.install-v1+json; q=, application/json; q=0.9, */*'
|
|
39
|
-
)
|
|
40
|
-
).toEqual('application/json');
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
composeTarballFromPackage,
|
|
5
|
-
extractTarballFromUrl,
|
|
6
|
-
getVersionFromTarball,
|
|
7
|
-
} from '../src/tarball-utils';
|
|
8
|
-
|
|
9
|
-
describe('Utilities', () => {
|
|
10
|
-
describe('getVersionFromTarball', () => {
|
|
11
|
-
test('should get the right version', () => {
|
|
12
|
-
const simpleName = 'test-name-4.2.12.tgz';
|
|
13
|
-
const complexName = 'test-5.6.4-beta.2.tgz';
|
|
14
|
-
const otherComplexName = 'test-3.5.0-6.tgz';
|
|
15
|
-
expect(getVersionFromTarball(simpleName)).toEqual('4.2.12');
|
|
16
|
-
expect(getVersionFromTarball(complexName)).toEqual('5.6.4-beta.2');
|
|
17
|
-
expect(getVersionFromTarball(otherComplexName)).toEqual('3.5.0-6');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('should fail at incorrect tarball name', () => {
|
|
21
|
-
expect(getVersionFromTarball('incorrectName')).toBeUndefined();
|
|
22
|
-
expect(getVersionFromTarball('test-1.2.tgz')).toBeUndefined();
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('extractTarballFromUrl', () => {
|
|
28
|
-
const metadata: any = {
|
|
29
|
-
name: 'npm_test',
|
|
30
|
-
versions: {
|
|
31
|
-
'1.0.0': {
|
|
32
|
-
dist: {
|
|
33
|
-
tarball: 'http://registry.org/npm_test/-/npm_test-1.0.0.tgz',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
'1.0.1': {
|
|
37
|
-
dist: {
|
|
38
|
-
tarball: 'https://localhost:4873/npm_test/-/npm_test-1.0.1.tgz',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
'1.0.2': {
|
|
42
|
-
dist: {
|
|
43
|
-
tarball: 'https://localhost/npm_test-1.0.2.tgz',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
'1.0.3': {
|
|
47
|
-
dist: {
|
|
48
|
-
tarball: 'http://registry.org/@org/npm_test/-/npm_test-1.0.3.tgz',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
test('should return only name of tarball', () => {
|
|
55
|
-
expect(extractTarballFromUrl(metadata.versions['1.0.0'].dist.tarball)).toEqual(
|
|
56
|
-
'npm_test-1.0.0.tgz'
|
|
57
|
-
);
|
|
58
|
-
expect(extractTarballFromUrl(metadata.versions['1.0.1'].dist.tarball)).toEqual(
|
|
59
|
-
'npm_test-1.0.1.tgz'
|
|
60
|
-
);
|
|
61
|
-
expect(extractTarballFromUrl(metadata.versions['1.0.2'].dist.tarball)).toEqual(
|
|
62
|
-
'npm_test-1.0.2.tgz'
|
|
63
|
-
);
|
|
64
|
-
expect(extractTarballFromUrl(metadata.versions['1.0.3'].dist.tarball)).toEqual(
|
|
65
|
-
'npm_test-1.0.3.tgz'
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('without tarball should not fails', () => {
|
|
70
|
-
expect(extractTarballFromUrl('https://registry.npmjs.org/')).toBe('');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('fails with incomplete URL', () => {
|
|
74
|
-
expect(() => extractTarballFromUrl('xxxxregistry.npmjs.org/test/-/test-0.0.2.tgz')).toThrow();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('composeTarballFromPackage - should return filename of tarball', () => {
|
|
79
|
-
expect(composeTarballFromPackage('npm_test', '1.0.0')).toEqual('npm_test-1.0.0.tgz');
|
|
80
|
-
expect(composeTarballFromPackage('@mbtools/npm_test', '1.0.1')).toEqual('npm_test-1.0.1.tgz');
|
|
81
|
-
});
|