ts-node-client 3.0.1 → 3.2.0

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 ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+
7
+ [*.{js,json,yml}]
8
+ charset = utf-8
9
+ indent_style = space
10
+ indent_size = 2
package/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ /.yarn/** linguist-vendored
2
+ /.yarn/releases/* binary
3
+ /.yarn/plugins/**/* binary
4
+ /.pnp.* binary linguist-generated
package/.yarnrc.yml ADDED
@@ -0,0 +1 @@
1
+ nodeLinker: node-modules
package/CHANGELOG.md CHANGED
@@ -8,6 +8,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
8
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
9
 
10
10
 
11
+ ## 3.2.0 - 2023-08-01
12
+
13
+ ### Added
14
+ * support package-lock.json v.3
15
+
16
+ ### Changed
17
+ * bump dependencies
18
+
19
+
20
+ ## 3.1.0 - 2023-04-20
21
+
22
+ ### Added
23
+ * support for yarn v2+ lock files
24
+
25
+ ### Changed
26
+ * project migrated to yarn 3.5
27
+
28
+
11
29
  ## 3.0.1 - 2023-02-08
12
30
 
13
31
  ### Changed
package/README.md CHANGED
@@ -9,12 +9,21 @@
9
9
 
10
10
  > TrustSource node client - node module to transfer dependency information to TrustSource server.
11
11
 
12
+ ## Release 3.2.0
13
+ Package now support package-lock.json v.3
14
+
15
+ ## Release 3.1.0
16
+ Package now support yarn v.2+
17
+
12
18
  ## Release 3.0.0
13
19
  Package now is not including `npm` anymore. The addition has been done due to missing programmatic API in npm >= 8.0.0 and in order to skip deprecated dependencies
14
20
 
15
21
  This change affects the structure of scans slightly, but it heavily improves the scanner.
16
22
 
17
23
  ## Requirements
24
+ * node >= 12.0.0 use **ts-node-client@3.1.+***
25
+
26
+ ## Older versions
18
27
  * node >= 8.9.0
19
28
  * npm < 8.0.0 use **ts-node-client@1.***
20
29
  * npm >= 8.0.0 use **ts-node-client@2.***
@@ -1,196 +1,196 @@
1
- #!/usr/bin/env node
2
-
3
- /* eslint-disable */
4
- /**************************************************************
5
- * Copyright (c) 2017. Enterprise Architecture Group, EACG GmbH
6
- *
7
- * SPDX-License-Identifier: Apache-2.0
8
- *************************************************************/
9
- /* eslint-enable */
10
- const fs = require('fs');
11
- const yargs = require('yargs');
12
- const pckgJson = require('../package.json');
13
-
14
- const URL = 'https://app.trustsource.io';
15
- const CRED_FILENAME = '/.tsrc.json';
16
- const FILL = ' ';
17
- const execute = require('../lib/cli');
18
-
19
- const getOptions = () => {
20
- let options = yargs
21
- .options({
22
- apiKey: {
23
- alias: 'k',
24
- default: null,
25
- describe: 'apiKey'
26
- },
27
- project: {
28
- alias: 'p',
29
- default: null,
30
- describe: 'Project name'
31
- },
32
- branch: {
33
- alias: 'b',
34
- default: null,
35
- describe: 'Scan branch'
36
- },
37
- tag: {
38
- alias: 't',
39
- default: null,
40
- describe: 'Scan tag'
41
- },
42
- binaryLinks: {
43
- default: null,
44
- describe: 'Binary links separated by comma'
45
- },
46
- url: {
47
- default: null,
48
- describe: 'url'
49
- },
50
- config: {
51
- alias: 'c',
52
- default: null,
53
- describe: 'Config path'
54
- },
55
- proxy: {
56
- default: null,
57
- describe: 'Proxy url like \'https://user:password@host:port\''
58
- },
59
- saveAs: {
60
- alias: 'o',
61
- default: null,
62
- describe: 'Save as file (file name prefix)'
63
- },
64
- saveAsFormat: {
65
- alias: 'f',
66
- default: null,
67
- describe: 'Save as format (scan / cydx / spdx)'
68
- },
69
- debug: {
70
- default: null,
71
- describe: 'debug'
72
- },
73
- simulate: {
74
- default: null,
75
- describe: 'simulate'
76
- },
77
- meteor: {
78
- default: null,
79
- describe: 'meteor'
80
- },
81
- breakOnWarnings: {
82
- default: null,
83
- describe: 'breakOnWarnings'
84
- },
85
- breakOnViolations: {
86
- default: null,
87
- describe: 'breakOnViolations'
88
- },
89
- includeDevDependencies: {
90
- default: null,
91
- describe: 'includeDevDependencies'
92
- }
93
- })
94
- .version()
95
- .usage(pckgJson.description)
96
- .help('help', 'Prints a usage statement')
97
- .fail((msg, err, yargsObject) => {
98
- if (err) throw err; // preserve stack
99
- console.error('Please check', yargsObject.help());
100
- process.exit(1);
101
- })
102
- .argv;
103
- if (options.version) {
104
- console.info(`${pckgJson.name} version ${pckgJson.version}`);
105
- process.exit(0);
106
- }
107
- options = (({
108
- // eslint-disable-next-line max-len
109
- apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
110
- }) => ({
111
- // eslint-disable-next-line max-len
112
- apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, scanMeteor: meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
113
- }))(options);
114
- Object.keys(options).forEach((key) => options[key] === null && delete options[key]);
115
- return options;
116
- };
117
-
118
- const loadConfig = (options) => {
119
- const values = [
120
- options.config ? options.config.replace('~', process.env.HOME) : null,
121
- process.cwd(),
122
- ((process.env.USERPROFILE || process.env.HOME) + CRED_FILENAME)
123
- ].map((value) => {
124
- let result = null;
125
- if (fs.existsSync(value) && fs.lstatSync(value).isDirectory() && fs.existsSync(`${value}${CRED_FILENAME}`)) {
126
- result = `${value}${CRED_FILENAME}`;
127
- } else if (fs.existsSync(value) && fs.lstatSync(value).isFile()) {
128
- result = value;
129
- }
130
- return !result || result.match(/^([a-zA-Z]:)?(\/|\\)/) ? result : `../../../${result}`;
131
- }).filter((value) => value);
132
- /* eslint-disable global-require, import/no-dynamic-require */
133
- return values[0] ? require(values[0]) : {};
134
- /* eslint-enable global-require, import/no-dynamic-require */
135
- };
136
-
137
- const validateOptions = (options) => {
138
- if (!options.apiKey) {
139
- throw new Error('Please provide a \'apiKey\' property in credentials file.');
140
- }
141
-
142
- if (!options.project) {
143
- throw new Error('Please provide a \'project\' property in credentials file.');
144
- }
145
- };
146
-
147
- let options = getOptions();
148
- options = { url: URL, ...loadConfig(options), ...options };
149
- validateOptions(options);
150
-
151
- if (options.debug) {
152
- console.log('invoking ts-node-client: ');
153
- console.log(`${FILL}debug = %s`, options.debug);
154
- console.log(`${FILL}simulate = %s`, options.simulate);
155
- console.log(`${FILL}includeDevDependencies = %s`, options.includeDevDependencies);
156
- console.log(`${FILL}scanMeteor = %s`, options.scanMeteor);
157
- console.log(`${FILL}saveAs = %s`, options.saveAs);
158
- console.log(`${FILL}saveAsFormat = %s`, options.saveAsFormat);
159
- console.log(`${FILL}breakOnViolations = %s`, options.breakOnViolations);
160
- console.log(`${FILL}breakOnWarnings = %s`, options.breakOnWarnings);
161
- console.log(`${FILL}apiKey = %s`, options.apiKey);
162
- console.log(`${FILL}project = %s`, options.project);
163
- console.log(`${FILL}branch = %s`, options.branch);
164
- console.log(`${FILL}tag = %s`, options.tag);
165
- console.log(`${FILL}binaryLinks = %s`, options.binaryLinks);
166
- console.log(`${FILL}url = %s`, options.url);
167
- console.log(`${FILL}proxy = %s`, options.proxy);
168
- }
169
-
170
- let exitCode = 0;
171
-
172
- process.on('uncaughtException', (err) => {
173
- console.error('Oops! Something went wrong! :(', err, options.debug ? err.stack : '');
174
- process.exit(1);
175
- });
176
-
177
- process.on('SIGINT', () => {
178
- console.error('Oops! SIGINT received! :( -> exiting...');
179
- process.exit(1);
180
- });
181
-
182
- process.on('exit', (code) => {
183
- console.log('Exitting normal exitCode=', code || exitCode);
184
- process.exit(code || exitCode);
185
- });
186
-
187
-
188
- try {
189
- execute(options, (ok) => {
190
- exitCode = ok ? 0 : 1;
191
- });
192
- console.log('cli.execute()', exitCode);
193
- } catch (error) {
194
- console.error('Error catched by cmdline interface:', error);
195
- exitCode = 1;
196
- }
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint-disable */
4
+ /**************************************************************
5
+ * Copyright (c) 2017. Enterprise Architecture Group, EACG GmbH
6
+ *
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ *************************************************************/
9
+ /* eslint-enable */
10
+ const fs = require('fs');
11
+ const yargs = require('yargs');
12
+ const pckgJson = require('../package.json');
13
+
14
+ const URL = 'https://app.trustsource.io';
15
+ const CRED_FILENAME = '/.tsrc.json';
16
+ const FILL = ' ';
17
+ const execute = require('../lib/cli');
18
+
19
+ const getOptions = () => {
20
+ let options = yargs
21
+ .options({
22
+ apiKey: {
23
+ alias: 'k',
24
+ default: null,
25
+ describe: 'apiKey'
26
+ },
27
+ project: {
28
+ alias: 'p',
29
+ default: null,
30
+ describe: 'Project name'
31
+ },
32
+ branch: {
33
+ alias: 'b',
34
+ default: null,
35
+ describe: 'Scan branch'
36
+ },
37
+ tag: {
38
+ alias: 't',
39
+ default: null,
40
+ describe: 'Scan tag'
41
+ },
42
+ binaryLinks: {
43
+ default: null,
44
+ describe: 'Binary links separated by comma'
45
+ },
46
+ url: {
47
+ default: null,
48
+ describe: 'url'
49
+ },
50
+ config: {
51
+ alias: 'c',
52
+ default: null,
53
+ describe: 'Config path'
54
+ },
55
+ proxy: {
56
+ default: null,
57
+ describe: 'Proxy url like \'https://user:password@host:port\''
58
+ },
59
+ saveAs: {
60
+ alias: 'o',
61
+ default: null,
62
+ describe: 'Save as file (file name prefix)'
63
+ },
64
+ saveAsFormat: {
65
+ alias: 'f',
66
+ default: null,
67
+ describe: 'Save as format (scan / cydx / spdx)'
68
+ },
69
+ debug: {
70
+ default: null,
71
+ describe: 'debug'
72
+ },
73
+ simulate: {
74
+ default: null,
75
+ describe: 'simulate'
76
+ },
77
+ meteor: {
78
+ default: null,
79
+ describe: 'meteor'
80
+ },
81
+ breakOnWarnings: {
82
+ default: null,
83
+ describe: 'breakOnWarnings'
84
+ },
85
+ breakOnViolations: {
86
+ default: null,
87
+ describe: 'breakOnViolations'
88
+ },
89
+ includeDevDependencies: {
90
+ default: null,
91
+ describe: 'includeDevDependencies'
92
+ }
93
+ })
94
+ .version()
95
+ .usage(pckgJson.description)
96
+ .help('help', 'Prints a usage statement')
97
+ .fail((msg, err, yargsObject) => {
98
+ if (err) throw err; // preserve stack
99
+ console.error('Please check', yargsObject.help());
100
+ process.exit(1);
101
+ })
102
+ .argv;
103
+ if (options.version) {
104
+ console.info(`${pckgJson.name} version ${pckgJson.version}`);
105
+ process.exit(0);
106
+ }
107
+ options = (({
108
+ // eslint-disable-next-line max-len
109
+ apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
110
+ }) => ({
111
+ // eslint-disable-next-line max-len
112
+ apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, scanMeteor: meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
113
+ }))(options);
114
+ Object.keys(options).forEach((key) => options[key] === null && delete options[key]);
115
+ return options;
116
+ };
117
+
118
+ const loadConfig = (options) => {
119
+ const values = [
120
+ options.config ? options.config.replace('~', process.env.HOME) : null,
121
+ process.cwd(),
122
+ ((process.env.USERPROFILE || process.env.HOME) + CRED_FILENAME)
123
+ ].map((value) => {
124
+ let result = null;
125
+ if (fs.existsSync(value) && fs.lstatSync(value).isDirectory() && fs.existsSync(`${value}${CRED_FILENAME}`)) {
126
+ result = `${value}${CRED_FILENAME}`;
127
+ } else if (fs.existsSync(value) && fs.lstatSync(value).isFile()) {
128
+ result = value;
129
+ }
130
+ return !result || result.match(/^([a-zA-Z]:)?(\/|\\)/) ? result : `../../../${result}`;
131
+ }).filter((value) => value);
132
+ /* eslint-disable global-require, import/no-dynamic-require */
133
+ return values[0] ? require(values[0]) : {};
134
+ /* eslint-enable global-require, import/no-dynamic-require */
135
+ };
136
+
137
+ const validateOptions = (options) => {
138
+ if (!options.apiKey) {
139
+ throw new Error('Please provide a \'apiKey\' property in credentials file.');
140
+ }
141
+
142
+ if (!options.project) {
143
+ throw new Error('Please provide a \'project\' property in credentials file.');
144
+ }
145
+ };
146
+
147
+ let options = getOptions();
148
+ options = { url: URL, ...loadConfig(options), ...options };
149
+ validateOptions(options);
150
+
151
+ if (options.debug) {
152
+ console.log('invoking ts-node-client: ');
153
+ console.log(`${FILL}debug = %s`, options.debug);
154
+ console.log(`${FILL}simulate = %s`, options.simulate);
155
+ console.log(`${FILL}includeDevDependencies = %s`, options.includeDevDependencies);
156
+ console.log(`${FILL}scanMeteor = %s`, options.scanMeteor);
157
+ console.log(`${FILL}saveAs = %s`, options.saveAs);
158
+ console.log(`${FILL}saveAsFormat = %s`, options.saveAsFormat);
159
+ console.log(`${FILL}breakOnViolations = %s`, options.breakOnViolations);
160
+ console.log(`${FILL}breakOnWarnings = %s`, options.breakOnWarnings);
161
+ console.log(`${FILL}apiKey = %s`, options.apiKey);
162
+ console.log(`${FILL}project = %s`, options.project);
163
+ console.log(`${FILL}branch = %s`, options.branch);
164
+ console.log(`${FILL}tag = %s`, options.tag);
165
+ console.log(`${FILL}binaryLinks = %s`, options.binaryLinks);
166
+ console.log(`${FILL}url = %s`, options.url);
167
+ console.log(`${FILL}proxy = %s`, options.proxy);
168
+ }
169
+
170
+ let exitCode = 0;
171
+
172
+ process.on('uncaughtException', (err) => {
173
+ console.error('Oops! Something went wrong! :(', err, options.debug ? err.stack : '');
174
+ process.exit(1);
175
+ });
176
+
177
+ process.on('SIGINT', () => {
178
+ console.error('Oops! SIGINT received! :( -> exiting...');
179
+ process.exit(1);
180
+ });
181
+
182
+ process.on('exit', (code) => {
183
+ console.log('Exitting normal exitCode=', code || exitCode);
184
+ process.exit(code || exitCode);
185
+ });
186
+
187
+
188
+ try {
189
+ execute(options, (ok) => {
190
+ exitCode = ok ? 0 : 1;
191
+ });
192
+ console.log('cli.execute()', exitCode);
193
+ } catch (error) {
194
+ console.error('Error catched by cmdline interface:', error);
195
+ exitCode = 1;
196
+ }
@@ -10,6 +10,7 @@ const fs = require('fs');
10
10
  const path = require('path');
11
11
  // eslint-disable-next-line import/no-extraneous-dependencies
12
12
  const lockfile = require('@yarnpkg/lockfile');
13
+ const yaml = require('js-yaml');
13
14
  const debuglog = (require('debuglog'))('ts-npm-scanner');
14
15
  const ScanResult = require('./scanresult');
15
16
  const { RestClient } = require('./rest-client');
@@ -64,25 +65,45 @@ function getYarnLock(self, packageData) {
64
65
  debuglog('npm.fs.yarn-lock - error:', data);
65
66
  return null;
66
67
  }
67
- const jsonFile = lockfile.parse(data.toString());
68
- if (jsonFile.type === 'success') {
69
- const base = {
70
- name: (packageData && packageData.root && packageData.root.name) || 'root',
71
- version: (packageData && packageData.root && packageData.root.version) || '1',
72
- dependencies: jsonFile.object
73
- };
74
- debuglog('Project: ', base.name, base.version);
75
- const dependencies = self.walkYarn(base, 0, base);
76
- return { root: jsonFile, dependencies };
68
+ // yarn 1
69
+ try {
70
+ const jsonFile = lockfile.parse(data.toString());
71
+ if (jsonFile && jsonFile.type === 'success') {
72
+ const dependencies = yarnToResults(self, jsonFile.object, packageData);
73
+ return { root: jsonFile, dependencies };
74
+ }
75
+ } catch (e) {
76
+ debuglog('npm.fs.yarn-v1-lock - error:', e);
77
+ }
78
+ // yarn 2+
79
+ try {
80
+ const json = yaml.load(data.toString());
81
+ // eslint-disable-next-line no-underscore-dangle
82
+ if (json && json.__metadata) {
83
+ // eslint-disable-next-line no-underscore-dangle
84
+ delete json.__metadata;
85
+ const dependencies = yarnToResults(self, json, packageData);
86
+ return { root: json, dependencies };
87
+ }
88
+ } catch (e) {
89
+ debuglog('npm.fs.yarn-v2-lock - error:', e);
77
90
  }
78
- debuglog('npm.fs.yarn-lock - error:', jsonFile);
91
+ debuglog('npm.fs.yarn-lock - error: Failed to parse file');
79
92
  return null;
80
93
  } catch (e) {
81
94
  debuglog('npm.fs.yarn-lock - error:', e);
82
95
  return null;
83
96
  }
84
97
  }
85
-
98
+ function yarnToResults(self, json, packageData) {
99
+ const base = {
100
+ name: (packageData && packageData.root && packageData.root.name) || 'root',
101
+ version: (packageData && packageData.root && packageData.root.version) || '1',
102
+ dependencies: json
103
+ };
104
+ debuglog('Project: ', base.name, base.version);
105
+ return self.walkYarn(base, 0, base);
106
+ }
86
107
  function saveResults(cb, options, root, dependencies) {
87
108
  const result = new ScanResult(options.project, root.name, `npm:${root.name}`, dependencies);
88
109
  debuglog('result: ', JSON.stringify(result));
@@ -152,6 +173,15 @@ Scanner.prototype.walk = function walk(npmDependency, level, root) {
152
173
  }
153
174
  checkForChild(self, opts, dependency, childDependency, val, level, root);
154
175
  });
176
+ } else if (npmDependency.packages) {
177
+ Object.getOwnPropertyNames(npmDependency.packages).forEach((val) => {
178
+ const childDependency = npmDependency.packages[val];
179
+ if (childDependency) {
180
+ const parts = val.split('node_modules/');
181
+ childDependency.name = parts.length > 1 ? parts.slice(1).join('node_modules/') : parts[0];
182
+ }
183
+ checkForChild(self, opts, dependency, childDependency, val, level, root);
184
+ });
155
185
  }
156
186
  return dependency;
157
187
  }