|
1 |
| -var check = require('validator').default; |
2 |
| -var fs = require('fs'); |
3 |
| -var makeOptions = require('./make-options.json'); |
4 |
| -var minimatch = require('minimatch'); |
5 |
| -var ncp = require('child_process'); |
6 |
| -var os = require('os'); |
7 |
| -var path = require('path'); |
8 |
| -var process = require('process'); |
9 |
| -var semver = require('semver'); |
10 |
| -var shell = require('shelljs'); |
11 |
| -const { XMLParser } = require("fast-xml-parser"); |
12 |
| -const Downloader = require("nodejs-file-downloader"); |
| 1 | +const ncp = require('child_process'); |
| 2 | +const fs = require('fs'); |
| 3 | +const os = require('os'); |
| 4 | +const path = require('path'); |
| 5 | +const process = require('process'); |
| 6 | + |
| 7 | +const { XMLParser } = require('fast-xml-parser'); |
| 8 | +const minimatch = require('minimatch'); |
| 9 | +const minimist = require('minimist'); |
| 10 | +const Downloader = require('nodejs-file-downloader'); |
| 11 | +const check = require('validator').default; |
| 12 | +const semver = require('semver'); |
| 13 | +const shell = require('shelljs'); |
| 14 | + |
| 15 | +const makeOptions = require('./make-options.json'); |
| 16 | + |
| 17 | +const args = minimist(process.argv.slice(2)); |
13 | 18 |
|
14 | 19 | // global paths
|
15 | 20 | var repoPath = __dirname;
|
@@ -154,6 +159,42 @@ var getCommonPackInfo = function (modOutDir) {
|
154 | 159 | }
|
155 | 160 | exports.getCommonPackInfo = getCommonPackInfo;
|
156 | 161 |
|
| 162 | +function performNpmAudit(taskPath) { |
| 163 | + console.log('\n🛫 Running npm audit...'); |
| 164 | + |
| 165 | + if (process.env['TF_BUILD']) { |
| 166 | + console.log(`\x1b[A\x1b[K⏭️ Skipping npm audit in build pipeline because it is not supported in the pipeline.`); |
| 167 | + return; |
| 168 | + } |
| 169 | + |
| 170 | + if (args.BypassNpmAudit) { |
| 171 | + console.log(`\x1b[A\x1b[K⏭️ Skipping npm audit because --BypassNpmAudit argument is set.`); |
| 172 | + return; |
| 173 | + } |
| 174 | + |
| 175 | + try { |
| 176 | + const auditResult = ncp.spawnSync('npm', ['audit', '--prefix', taskPath, '--audit-level=high'], { |
| 177 | + stdio: 'pipe', |
| 178 | + encoding: 'utf8', |
| 179 | + }); |
| 180 | + |
| 181 | + if (auditResult.error) { |
| 182 | + console.log(`\x1b[A\x1b[K❌ npm audit failed because the build task at "${taskPath}" has vulnerable dependencies.`); |
| 183 | + console.log('👉 Please see details by running the command'); |
| 184 | + console.log(`\tnpm audit --prefix ${taskPath}`); |
| 185 | + console.log('or execute the command with --BypassNpmAudit argument to skip the auditing'); |
| 186 | + console.log(`\tnode make.js --build --task ${args.task} --BypassNpmAudit`); |
| 187 | + process.exit(1); |
| 188 | + } else { |
| 189 | + console.log('\x1b[A\x1b[K✅ npm audit completed successfully.'); |
| 190 | + } |
| 191 | + } catch (error) { |
| 192 | + console.error('\x1b[A\x1b[K❌ "performNpmAudit" failed.'); |
| 193 | + console.error(error.message); |
| 194 | + process.exit(1); |
| 195 | + } |
| 196 | +} |
| 197 | + |
157 | 198 | var buildNodeTask = function (taskPath, outDir, isServerBuild) {
|
158 | 199 | var originalDir = shell.pwd().toString();
|
159 | 200 | cd(taskPath);
|
@@ -191,6 +232,8 @@ var buildNodeTask = function (taskPath, outDir, isServerBuild) {
|
191 | 232 | cd(taskPath);
|
192 | 233 | }
|
193 | 234 |
|
| 235 | + performNpmAudit(taskPath); |
| 236 | + |
194 | 237 | // Use the tsc version supplied by the task if it is available, otherwise use the global default.
|
195 | 238 | if (overrideTscPath) {
|
196 | 239 | var tscExec = path.join(overrideTscPath, "bin", "tsc");
|
|
0 commit comments