ts-node-client 3.2.1 → 3.2.3
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/.editorconfig +10 -10
- package/.eslintrc.json +29 -29
- package/.gitattributes +4 -4
- package/.github/workflows/codeql-analysis.yml +71 -71
- package/.github/workflows/publish.yml +32 -0
- package/.travis.yml +12 -12
- package/CHANGELOG.md +67 -52
- package/LICENSE +202 -202
- package/README.md +191 -191
- package/SECURITY.md +21 -21
- package/lib/cli.js +122 -122
- package/lib/convertor.js +244 -244
- package/lib/dependency.js +169 -169
- package/lib/meteor-scanner.js +61 -61
- package/lib/npm-scanner.js +334 -334
- package/lib/pkg.js +36 -36
- package/lib/rest-client.js +129 -129
- package/lib/scanresult.js +32 -32
- package/package-lock.json +5147 -0
- package/package-lock_dev_test.json +47 -47
- package/package-lock_v1.json +863 -863
- package/package-lock_v2.json +5147 -5147
- package/package-lock_v3.json +3014 -3014
- package/package.json +55 -55
- package/test/dependency-test.js +309 -309
- package/test/error-test.js +80 -80
- package/test/rest-test.js +75 -75
- package/test/scanresult-test.js +44 -44
- package/.yarnrc.yml +0 -1
package/lib/dependency.js
CHANGED
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/**********************************************************
|
|
3
|
-
* Copyright (c) 2017. Enterprise Architecture Group, EACG
|
|
4
|
-
*
|
|
5
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
*********************************************************/
|
|
7
|
-
/* eslint-enable */
|
|
8
|
-
|
|
9
|
-
const semver = require('semver');
|
|
10
|
-
|
|
11
|
-
function Dependency(name, version, keyPrefix, description, priv, licenses, homepageUrl, repoUrl) {
|
|
12
|
-
this.name = checkStr(name, 'name');
|
|
13
|
-
const versions = [checkStr(version, 'version', this.name)];
|
|
14
|
-
|
|
15
|
-
this.key = `${checkStr(keyPrefix, 'key-prefix', this.name)}:${this.name}`;
|
|
16
|
-
this.description = description;
|
|
17
|
-
this.private = !!priv;
|
|
18
|
-
this.licenses = convertLicenses(licenses);
|
|
19
|
-
this.homepageUrl = homepageUrl;
|
|
20
|
-
this.repoUrl = convertRepoUrl(repoUrl);
|
|
21
|
-
this.dependencies = [];
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(this, 'versions', {
|
|
24
|
-
get() {
|
|
25
|
-
return versions.sort(compare);
|
|
26
|
-
},
|
|
27
|
-
enumerable: true
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
this.addVersion = function addVersion(vers) {
|
|
31
|
-
if (versions.indexOf(vers) === -1) {
|
|
32
|
-
versions.push((vers));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Dependency.prototype.toString = function toString() {
|
|
38
|
-
return `${this.name}:${this.versions}`;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
Dependency.prototype.addDependency = function addDependency(child) {
|
|
42
|
-
if (child instanceof Dependency === false) {
|
|
43
|
-
throw new TypeError('Dependency as child expected');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (this.dependencies.some((e) => e === child || (e.name === child.name && e.key === child.key)) === false) {
|
|
47
|
-
this.dependencies.push(child);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
Dependency.prototype.addDependencies = function addDependencies(arg1) {
|
|
52
|
-
let args = Array.prototype.slice.call(arguments, 1); // eslint-disable-line prefer-rest-params
|
|
53
|
-
|
|
54
|
-
if (arg1 instanceof Dependency) { // called with (Dependency, Dependency, ...)
|
|
55
|
-
args.unshift(arg1);
|
|
56
|
-
} else if (Array.isArray(arg1) && args.length === 0) { // called with ([Dependency])
|
|
57
|
-
args = arg1;
|
|
58
|
-
} else {
|
|
59
|
-
throw new Error('Invalid call syntax: call with (Dependency, Dependency, ...) or ([Dependency])');
|
|
60
|
-
}
|
|
61
|
-
args.forEach((d) => { // fail for all or no argument
|
|
62
|
-
if (d instanceof Dependency === false) {
|
|
63
|
-
throw new TypeError('instance of Dependency as argument expected');
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
args.forEach((d) => this.addDependency(d));
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
Dependency.getFirstByName = function getFirstByName(container, dependency) {
|
|
70
|
-
if (dependency instanceof Dependency) {
|
|
71
|
-
dependency = dependency.name;
|
|
72
|
-
}
|
|
73
|
-
if (Array.isArray(container)) {
|
|
74
|
-
return container.find((d) => d instanceof Dependency && d.name === dependency);
|
|
75
|
-
}
|
|
76
|
-
if (container instanceof Object && container[dependency] instanceof Dependency) {
|
|
77
|
-
return container[dependency];
|
|
78
|
-
}
|
|
79
|
-
return undefined;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
module.exports = Dependency;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function convertRepoUrl(url) {
|
|
86
|
-
const prefixes = ['git+', 'svn+'];
|
|
87
|
-
|
|
88
|
-
if (typeof url === 'string' && url.length > 0) {
|
|
89
|
-
const matchPrefix = prefixes.find((p) => url.startsWith(p));
|
|
90
|
-
if (matchPrefix) {
|
|
91
|
-
return url.substring(matchPrefix.length);
|
|
92
|
-
}
|
|
93
|
-
return url;
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function checkStr(str, name, info) {
|
|
99
|
-
if (str instanceof String) {
|
|
100
|
-
str = str.valueOf(); // convert to primitive
|
|
101
|
-
}
|
|
102
|
-
if (typeof str !== 'string' || str.length === 0) {
|
|
103
|
-
let msg = `${name || 'parameter'} should be given.`;
|
|
104
|
-
if (info) {
|
|
105
|
-
msg = `${msg} [${info}]`;
|
|
106
|
-
}
|
|
107
|
-
throw new Error(msg);
|
|
108
|
-
}
|
|
109
|
-
return str;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function convertLicenses(licenses) {
|
|
114
|
-
const lics = [];
|
|
115
|
-
if (licenses instanceof Array && licenses.length > 0) {
|
|
116
|
-
licenses.forEach((license) => {
|
|
117
|
-
pushLicenseObj(lics, license);
|
|
118
|
-
});
|
|
119
|
-
} else {
|
|
120
|
-
pushLicenseObj(lics, licenses);
|
|
121
|
-
}
|
|
122
|
-
return lics;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function pushLicenseObj(arr, license) {
|
|
126
|
-
if (license) {
|
|
127
|
-
if (license.url || license.name || license.type) {
|
|
128
|
-
const l = {};
|
|
129
|
-
if (license.name || license.type) {
|
|
130
|
-
l.name = license.name || license.type;
|
|
131
|
-
}
|
|
132
|
-
if (license.url) {
|
|
133
|
-
l.url = license.url;
|
|
134
|
-
}
|
|
135
|
-
arr.push(l);
|
|
136
|
-
} else {
|
|
137
|
-
pushLicenseStr(arr, license);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function pushLicenseStr(arr, license) {
|
|
143
|
-
if (license) {
|
|
144
|
-
if (license instanceof String) {
|
|
145
|
-
license = license.valueOf(); // convert to primitive
|
|
146
|
-
}
|
|
147
|
-
if (typeof license === 'string' && license.length) {
|
|
148
|
-
arr.push({ name: license });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater.
|
|
155
|
-
// Sorts in ascending order if passed to Array.sort().
|
|
156
|
-
// sorts valid semver version numbers before invalid ones
|
|
157
|
-
function compare(a, b) {
|
|
158
|
-
try {
|
|
159
|
-
return semver.compare(a, b);
|
|
160
|
-
} catch (err) {
|
|
161
|
-
if (semver.valid(a)) {
|
|
162
|
-
return 1;
|
|
163
|
-
}
|
|
164
|
-
if (semver.valid(b)) {
|
|
165
|
-
return -1;
|
|
166
|
-
}
|
|
167
|
-
return 0;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**********************************************************
|
|
3
|
+
* Copyright (c) 2017. Enterprise Architecture Group, EACG
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*********************************************************/
|
|
7
|
+
/* eslint-enable */
|
|
8
|
+
|
|
9
|
+
const semver = require('semver');
|
|
10
|
+
|
|
11
|
+
function Dependency(name, version, keyPrefix, description, priv, licenses, homepageUrl, repoUrl) {
|
|
12
|
+
this.name = checkStr(name, 'name');
|
|
13
|
+
const versions = [checkStr((version || '0.0.0'), 'version', this.name)];
|
|
14
|
+
|
|
15
|
+
this.key = `${checkStr(keyPrefix, 'key-prefix', this.name)}:${this.name}`;
|
|
16
|
+
this.description = description;
|
|
17
|
+
this.private = !!priv;
|
|
18
|
+
this.licenses = convertLicenses(licenses);
|
|
19
|
+
this.homepageUrl = homepageUrl;
|
|
20
|
+
this.repoUrl = convertRepoUrl(repoUrl);
|
|
21
|
+
this.dependencies = [];
|
|
22
|
+
|
|
23
|
+
Object.defineProperty(this, 'versions', {
|
|
24
|
+
get() {
|
|
25
|
+
return versions.sort(compare);
|
|
26
|
+
},
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
this.addVersion = function addVersion(vers) {
|
|
31
|
+
if (versions.indexOf(vers) === -1) {
|
|
32
|
+
versions.push((vers));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Dependency.prototype.toString = function toString() {
|
|
38
|
+
return `${this.name}:${this.versions}`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Dependency.prototype.addDependency = function addDependency(child) {
|
|
42
|
+
if (child instanceof Dependency === false) {
|
|
43
|
+
throw new TypeError('Dependency as child expected');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (this.dependencies.some((e) => e === child || (e.name === child.name && e.key === child.key)) === false) {
|
|
47
|
+
this.dependencies.push(child);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Dependency.prototype.addDependencies = function addDependencies(arg1) {
|
|
52
|
+
let args = Array.prototype.slice.call(arguments, 1); // eslint-disable-line prefer-rest-params
|
|
53
|
+
|
|
54
|
+
if (arg1 instanceof Dependency) { // called with (Dependency, Dependency, ...)
|
|
55
|
+
args.unshift(arg1);
|
|
56
|
+
} else if (Array.isArray(arg1) && args.length === 0) { // called with ([Dependency])
|
|
57
|
+
args = arg1;
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error('Invalid call syntax: call with (Dependency, Dependency, ...) or ([Dependency])');
|
|
60
|
+
}
|
|
61
|
+
args.forEach((d) => { // fail for all or no argument
|
|
62
|
+
if (d instanceof Dependency === false) {
|
|
63
|
+
throw new TypeError('instance of Dependency as argument expected');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
args.forEach((d) => this.addDependency(d));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
Dependency.getFirstByName = function getFirstByName(container, dependency) {
|
|
70
|
+
if (dependency instanceof Dependency) {
|
|
71
|
+
dependency = dependency.name;
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(container)) {
|
|
74
|
+
return container.find((d) => d instanceof Dependency && d.name === dependency);
|
|
75
|
+
}
|
|
76
|
+
if (container instanceof Object && container[dependency] instanceof Dependency) {
|
|
77
|
+
return container[dependency];
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports = Dependency;
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
function convertRepoUrl(url) {
|
|
86
|
+
const prefixes = ['git+', 'svn+'];
|
|
87
|
+
|
|
88
|
+
if (typeof url === 'string' && url.length > 0) {
|
|
89
|
+
const matchPrefix = prefixes.find((p) => url.startsWith(p));
|
|
90
|
+
if (matchPrefix) {
|
|
91
|
+
return url.substring(matchPrefix.length);
|
|
92
|
+
}
|
|
93
|
+
return url;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function checkStr(str, name, info) {
|
|
99
|
+
if (str instanceof String) {
|
|
100
|
+
str = str.valueOf(); // convert to primitive
|
|
101
|
+
}
|
|
102
|
+
if (typeof str !== 'string' || str.length === 0) {
|
|
103
|
+
let msg = `${name || 'parameter'} should be given.`;
|
|
104
|
+
if (info) {
|
|
105
|
+
msg = `${msg} [${info}]`;
|
|
106
|
+
}
|
|
107
|
+
throw new Error(msg);
|
|
108
|
+
}
|
|
109
|
+
return str;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
function convertLicenses(licenses) {
|
|
114
|
+
const lics = [];
|
|
115
|
+
if (licenses instanceof Array && licenses.length > 0) {
|
|
116
|
+
licenses.forEach((license) => {
|
|
117
|
+
pushLicenseObj(lics, license);
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
pushLicenseObj(lics, licenses);
|
|
121
|
+
}
|
|
122
|
+
return lics;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function pushLicenseObj(arr, license) {
|
|
126
|
+
if (license) {
|
|
127
|
+
if (license.url || license.name || license.type) {
|
|
128
|
+
const l = {};
|
|
129
|
+
if (license.name || license.type) {
|
|
130
|
+
l.name = license.name || license.type;
|
|
131
|
+
}
|
|
132
|
+
if (license.url) {
|
|
133
|
+
l.url = license.url;
|
|
134
|
+
}
|
|
135
|
+
arr.push(l);
|
|
136
|
+
} else {
|
|
137
|
+
pushLicenseStr(arr, license);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function pushLicenseStr(arr, license) {
|
|
143
|
+
if (license) {
|
|
144
|
+
if (license instanceof String) {
|
|
145
|
+
license = license.valueOf(); // convert to primitive
|
|
146
|
+
}
|
|
147
|
+
if (typeof license === 'string' && license.length) {
|
|
148
|
+
arr.push({ name: license });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
// Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater.
|
|
155
|
+
// Sorts in ascending order if passed to Array.sort().
|
|
156
|
+
// sorts valid semver version numbers before invalid ones
|
|
157
|
+
function compare(a, b) {
|
|
158
|
+
try {
|
|
159
|
+
return semver.compare(a, b);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
if (semver.valid(a)) {
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
if (semver.valid(b)) {
|
|
165
|
+
return -1;
|
|
166
|
+
}
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
package/lib/meteor-scanner.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/**********************************************************
|
|
3
|
-
* Copyright (c) 2017. Enterprise Architecture Group, EACG
|
|
4
|
-
*
|
|
5
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
*********************************************************/
|
|
7
|
-
/* eslint-enable */
|
|
8
|
-
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
const debuglog = (require('debuglog'))('ts-meteor-scanner');
|
|
12
|
-
const ScanResult = require('./scanresult');
|
|
13
|
-
const { RestClient } = require('./rest-client');
|
|
14
|
-
const Dependency = require('./dependency');
|
|
15
|
-
|
|
16
|
-
exports.Scanner = Scanner;
|
|
17
|
-
|
|
18
|
-
const METEOR_PREFIX = 'atm'; // short for atmosphere packages
|
|
19
|
-
|
|
20
|
-
function Scanner(options) {
|
|
21
|
-
this.options = options;
|
|
22
|
-
this.name = 'ts-meteor-scanner';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
Scanner.prototype.scan = function scan(module, cb) {
|
|
26
|
-
const self = this;
|
|
27
|
-
const { options } = self;
|
|
28
|
-
|
|
29
|
-
const meteorVersions = path.resolve(process.cwd(), '.meteor/versions');
|
|
30
|
-
|
|
31
|
-
fs.readFile(meteorVersions, (err, data) => {
|
|
32
|
-
if (err) cb(err);
|
|
33
|
-
const array = data.toString().split('\n');
|
|
34
|
-
const dependencies = self.gatherDependencies(array);
|
|
35
|
-
const result = new ScanResult(options.project, module, `${METEOR_PREFIX}:${module}`, dependencies);
|
|
36
|
-
cb(undefined, result);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
Scanner.prototype.transfer = function transfer(scan, cb) {
|
|
41
|
-
const client = new RestClient(this.options);
|
|
42
|
-
client.transfer(scan, cb);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
Scanner.prototype.gatherDependencies = function gatherDependencies(lines) {
|
|
46
|
-
// remove falsy values
|
|
47
|
-
return lines.map((l) => {
|
|
48
|
-
const parts = l.split('@');
|
|
49
|
-
if (parts.length === 2) {
|
|
50
|
-
printDependency(parts);
|
|
51
|
-
return new Dependency(parts[0], parts[1], 'atm');
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}).filter(Boolean);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function printDependency(parts) {
|
|
59
|
-
debuglog('-----------------------------------------');
|
|
60
|
-
debuglog('Name, Version: ', parts[0], parts[1]);
|
|
61
|
-
}
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**********************************************************
|
|
3
|
+
* Copyright (c) 2017. Enterprise Architecture Group, EACG
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*********************************************************/
|
|
7
|
+
/* eslint-enable */
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const debuglog = (require('debuglog'))('ts-meteor-scanner');
|
|
12
|
+
const ScanResult = require('./scanresult');
|
|
13
|
+
const { RestClient } = require('./rest-client');
|
|
14
|
+
const Dependency = require('./dependency');
|
|
15
|
+
|
|
16
|
+
exports.Scanner = Scanner;
|
|
17
|
+
|
|
18
|
+
const METEOR_PREFIX = 'atm'; // short for atmosphere packages
|
|
19
|
+
|
|
20
|
+
function Scanner(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.name = 'ts-meteor-scanner';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Scanner.prototype.scan = function scan(module, cb) {
|
|
26
|
+
const self = this;
|
|
27
|
+
const { options } = self;
|
|
28
|
+
|
|
29
|
+
const meteorVersions = path.resolve(process.cwd(), '.meteor/versions');
|
|
30
|
+
|
|
31
|
+
fs.readFile(meteorVersions, (err, data) => {
|
|
32
|
+
if (err) cb(err);
|
|
33
|
+
const array = data.toString().split('\n');
|
|
34
|
+
const dependencies = self.gatherDependencies(array);
|
|
35
|
+
const result = new ScanResult(options.project, module, `${METEOR_PREFIX}:${module}`, dependencies);
|
|
36
|
+
cb(undefined, result);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Scanner.prototype.transfer = function transfer(scan, cb) {
|
|
41
|
+
const client = new RestClient(this.options);
|
|
42
|
+
client.transfer(scan, cb);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Scanner.prototype.gatherDependencies = function gatherDependencies(lines) {
|
|
46
|
+
// remove falsy values
|
|
47
|
+
return lines.map((l) => {
|
|
48
|
+
const parts = l.split('@');
|
|
49
|
+
if (parts.length === 2) {
|
|
50
|
+
printDependency(parts);
|
|
51
|
+
return new Dependency(parts[0], parts[1], 'atm');
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}).filter(Boolean);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function printDependency(parts) {
|
|
59
|
+
debuglog('-----------------------------------------');
|
|
60
|
+
debuglog('Name, Version: ', parts[0], parts[1]);
|
|
61
|
+
}
|