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/cli.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
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 debuglog = (require('debuglog'))('ts-node-client');
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const Convertor = require('./convertor');
|
|
12
|
-
|
|
13
|
-
const stdlog = console.log;
|
|
14
|
-
const MODULE_NAME = 'ts-node-client:cli';
|
|
15
|
-
|
|
16
|
-
module.exports = scan;
|
|
17
|
-
|
|
18
|
-
const NpmScanner = promisify(require('./npm-scanner').Scanner);
|
|
19
|
-
const MeteorScanner = promisify(require('./meteor-scanner').Scanner);
|
|
20
|
-
|
|
21
|
-
function scan(options, scanDone) {
|
|
22
|
-
if (typeof (scanDone) !== 'function') {
|
|
23
|
-
throw new Error('Please provide a callback function as 2nd argument.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (options.url.endsWith('/')) {
|
|
27
|
-
options.url = options.url.slice(0, -1);
|
|
28
|
-
}
|
|
29
|
-
debuglog(`${MODULE_NAME}.scan() reorganized options:`, options);
|
|
30
|
-
|
|
31
|
-
const npmScanner = new NpmScanner(options);
|
|
32
|
-
const meteorScanner = new MeteorScanner(options);
|
|
33
|
-
|
|
34
|
-
npmScanner.scan().then((scanResult) => {
|
|
35
|
-
if (options.scanMeteor) {
|
|
36
|
-
debuglog(`${MODULE_NAME}.scan() scanMeteor set: scanning meteor dependencies`);
|
|
37
|
-
return meteorScanner.scan(scanResult.module).then((meteorScanResult) => {
|
|
38
|
-
// remove dependency introduced by local package.json (this will never be released)
|
|
39
|
-
const npmDependencies = scanResult.dependencies.length === 1
|
|
40
|
-
? scanResult.dependencies[0].dependencies : scanResult.dependencies;
|
|
41
|
-
Array.prototype.push.apply(meteorScanResult.dependencies, npmDependencies);
|
|
42
|
-
return meteorScanResult;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return scanResult;
|
|
46
|
-
}).then((scanResult) => {
|
|
47
|
-
if (options.simulate) {
|
|
48
|
-
stdlog(`${MODULE_NAME}.scan():${npmScanner.name} simulating, nothing transferred:`);
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
return scanResult;
|
|
52
|
-
}).then((scanResult) => {
|
|
53
|
-
if (options.saveAs) {
|
|
54
|
-
const date = new Date();
|
|
55
|
-
let printData = JSON.stringify(scanResult, 0, 2);
|
|
56
|
-
let printExt = 'scan';
|
|
57
|
-
if (options.saveAsFormat) {
|
|
58
|
-
const allowedTypes = ['scan', 'spdx', 'cydx'];
|
|
59
|
-
if (allowedTypes.indexOf(options.saveAsFormat) > 0) {
|
|
60
|
-
printData = JSON.stringify(Convertor.scanTo(options.saveAsFormat, scanResult), 0, 2);
|
|
61
|
-
printExt = options.saveAsFormat;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const formatedDate = date.toISOString().substr(0, 19).split(':').join('-').split('T').join('-');
|
|
65
|
-
fs.writeFileSync(`${options.saveAs || 'ts-scan'}-${formatedDate}-${options.saveAsFormat ? printExt : 'scan'}.json`, printData);
|
|
66
|
-
}
|
|
67
|
-
return scanResult;
|
|
68
|
-
}).then((scanResult) => {
|
|
69
|
-
if (scanResult) {
|
|
70
|
-
return npmScanner.transfer(scanResult);
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
}).then(
|
|
74
|
-
(transferResult) => {
|
|
75
|
-
if (transferResult) {
|
|
76
|
-
stdlog(`${MODULE_NAME}.scan():${npmScanner.name} successfully transferred scan to server:${
|
|
77
|
-
JSON.stringify(transferResult)}`);
|
|
78
|
-
}
|
|
79
|
-
debuglog(`${MODULE_NAME}scan(): finished`, transferResult);
|
|
80
|
-
scanDone(true);
|
|
81
|
-
},
|
|
82
|
-
(error) => {
|
|
83
|
-
stdlog(`${MODULE_NAME}.scan():${npmScanner.name} error transferring scan:${JSON.stringify(error)}`);
|
|
84
|
-
return Promise.reject();
|
|
85
|
-
}
|
|
86
|
-
)
|
|
87
|
-
.catch((error) => {
|
|
88
|
-
if (error) stdlog(`${MODULE_NAME}scan(): error`, error);
|
|
89
|
-
scanDone(false);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/* eslint-disable func-names, prefer-rest-params */
|
|
94
|
-
function promisifyFunc(func) {
|
|
95
|
-
if (typeof (func) === 'function') {
|
|
96
|
-
return function () {
|
|
97
|
-
const args = Array.from(arguments);
|
|
98
|
-
const self = this;
|
|
99
|
-
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
args.push((error, data) => {
|
|
102
|
-
if (error) {
|
|
103
|
-
reject(error);
|
|
104
|
-
} else {
|
|
105
|
-
resolve(data);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
func.apply(self, args);
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return func;
|
|
113
|
-
}
|
|
114
|
-
/* eslint-enable func-names, prefer-rest-params */
|
|
115
|
-
|
|
116
|
-
function promisify(scanner) {
|
|
117
|
-
if (scanner && scanner.prototype) {
|
|
118
|
-
scanner.prototype.scan = promisifyFunc(scanner.prototype.scan);
|
|
119
|
-
scanner.prototype.transfer = promisifyFunc(scanner.prototype.transfer);
|
|
120
|
-
}
|
|
121
|
-
return scanner;
|
|
122
|
-
}
|
|
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 debuglog = (require('debuglog'))('ts-node-client');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const Convertor = require('./convertor');
|
|
12
|
+
|
|
13
|
+
const stdlog = console.log;
|
|
14
|
+
const MODULE_NAME = 'ts-node-client:cli';
|
|
15
|
+
|
|
16
|
+
module.exports = scan;
|
|
17
|
+
|
|
18
|
+
const NpmScanner = promisify(require('./npm-scanner').Scanner);
|
|
19
|
+
const MeteorScanner = promisify(require('./meteor-scanner').Scanner);
|
|
20
|
+
|
|
21
|
+
function scan(options, scanDone) {
|
|
22
|
+
if (typeof (scanDone) !== 'function') {
|
|
23
|
+
throw new Error('Please provide a callback function as 2nd argument.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (options.url.endsWith('/')) {
|
|
27
|
+
options.url = options.url.slice(0, -1);
|
|
28
|
+
}
|
|
29
|
+
debuglog(`${MODULE_NAME}.scan() reorganized options:`, options);
|
|
30
|
+
|
|
31
|
+
const npmScanner = new NpmScanner(options);
|
|
32
|
+
const meteorScanner = new MeteorScanner(options);
|
|
33
|
+
|
|
34
|
+
npmScanner.scan().then((scanResult) => {
|
|
35
|
+
if (options.scanMeteor) {
|
|
36
|
+
debuglog(`${MODULE_NAME}.scan() scanMeteor set: scanning meteor dependencies`);
|
|
37
|
+
return meteorScanner.scan(scanResult.module).then((meteorScanResult) => {
|
|
38
|
+
// remove dependency introduced by local package.json (this will never be released)
|
|
39
|
+
const npmDependencies = scanResult.dependencies.length === 1
|
|
40
|
+
? scanResult.dependencies[0].dependencies : scanResult.dependencies;
|
|
41
|
+
Array.prototype.push.apply(meteorScanResult.dependencies, npmDependencies);
|
|
42
|
+
return meteorScanResult;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return scanResult;
|
|
46
|
+
}).then((scanResult) => {
|
|
47
|
+
if (options.simulate) {
|
|
48
|
+
stdlog(`${MODULE_NAME}.scan():${npmScanner.name} simulating, nothing transferred:`);
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return scanResult;
|
|
52
|
+
}).then((scanResult) => {
|
|
53
|
+
if (options.saveAs) {
|
|
54
|
+
const date = new Date();
|
|
55
|
+
let printData = JSON.stringify(scanResult, 0, 2);
|
|
56
|
+
let printExt = 'scan';
|
|
57
|
+
if (options.saveAsFormat) {
|
|
58
|
+
const allowedTypes = ['scan', 'spdx', 'cydx'];
|
|
59
|
+
if (allowedTypes.indexOf(options.saveAsFormat) > 0) {
|
|
60
|
+
printData = JSON.stringify(Convertor.scanTo(options.saveAsFormat, scanResult), 0, 2);
|
|
61
|
+
printExt = options.saveAsFormat;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const formatedDate = date.toISOString().substr(0, 19).split(':').join('-').split('T').join('-');
|
|
65
|
+
fs.writeFileSync(`${options.saveAs || 'ts-scan'}-${formatedDate}-${options.saveAsFormat ? printExt : 'scan'}.json`, printData);
|
|
66
|
+
}
|
|
67
|
+
return scanResult;
|
|
68
|
+
}).then((scanResult) => {
|
|
69
|
+
if (scanResult) {
|
|
70
|
+
return npmScanner.transfer(scanResult);
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}).then(
|
|
74
|
+
(transferResult) => {
|
|
75
|
+
if (transferResult) {
|
|
76
|
+
stdlog(`${MODULE_NAME}.scan():${npmScanner.name} successfully transferred scan to server:${
|
|
77
|
+
JSON.stringify(transferResult)}`);
|
|
78
|
+
}
|
|
79
|
+
debuglog(`${MODULE_NAME}scan(): finished`, transferResult);
|
|
80
|
+
scanDone(true);
|
|
81
|
+
},
|
|
82
|
+
(error) => {
|
|
83
|
+
stdlog(`${MODULE_NAME}.scan():${npmScanner.name} error transferring scan:${JSON.stringify(error)}`);
|
|
84
|
+
return Promise.reject();
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
.catch((error) => {
|
|
88
|
+
if (error) stdlog(`${MODULE_NAME}scan(): error`, error);
|
|
89
|
+
scanDone(false);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* eslint-disable func-names, prefer-rest-params */
|
|
94
|
+
function promisifyFunc(func) {
|
|
95
|
+
if (typeof (func) === 'function') {
|
|
96
|
+
return function () {
|
|
97
|
+
const args = Array.from(arguments);
|
|
98
|
+
const self = this;
|
|
99
|
+
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
args.push((error, data) => {
|
|
102
|
+
if (error) {
|
|
103
|
+
reject(error);
|
|
104
|
+
} else {
|
|
105
|
+
resolve(data);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
func.apply(self, args);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return func;
|
|
113
|
+
}
|
|
114
|
+
/* eslint-enable func-names, prefer-rest-params */
|
|
115
|
+
|
|
116
|
+
function promisify(scanner) {
|
|
117
|
+
if (scanner && scanner.prototype) {
|
|
118
|
+
scanner.prototype.scan = promisifyFunc(scanner.prototype.scan);
|
|
119
|
+
scanner.prototype.transfer = promisifyFunc(scanner.prototype.transfer);
|
|
120
|
+
}
|
|
121
|
+
return scanner;
|
|
122
|
+
}
|