Skip to content

Commit 8fb8034

Browse files
Update build scripts to use a strict TS config (#21164)
* Update build scripts to use a strict TS config * Move performing audit before packages installation * Handle and pass additional arguments to tsc
1 parent 20e9f76 commit 8fb8034

File tree

5 files changed

+3194
-1096
lines changed

5 files changed

+3194
-1096
lines changed

make-util.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ var getCommonPackInfo = function (modOutDir) {
159159
}
160160
exports.getCommonPackInfo = getCommonPackInfo;
161161

162+
/**
163+
* Performs npm audit on the specified task path.
164+
* @param {string} taskPath - The path to the task directory where npm audit should be performed.
165+
*/
162166
function performNpmAudit(taskPath) {
163167
console.log('\n🛫 Running npm audit...');
164168

@@ -179,12 +183,12 @@ function performNpmAudit(taskPath) {
179183
shell: true
180184
});
181185

182-
if (auditResult.error) {
186+
if (auditResult.status) {
183187
console.log(`\x1b[A\x1b[K❌ npm audit failed because the build task at "${taskPath}" has vulnerable dependencies.`);
184188
console.log('👉 Please see details by running the command');
185189
console.log(`\tnpm audit --prefix ${taskPath}`);
186190
console.log('or execute the command with --BypassNpmAudit argument to skip the auditing');
187-
console.log(`\tnode make.js --build --task ${args.task} --BypassNpmAudit`);
191+
console.log(`\tnode make.js build --task ${args.task} --BypassNpmAudit`);
188192
process.exit(1);
189193
} else {
190194
console.log('\x1b[A\x1b[K✅ npm audit completed successfully.');
@@ -196,11 +200,24 @@ function performNpmAudit(taskPath) {
196200
}
197201
}
198202

203+
function getAdditionalTypeScriptArguments() {
204+
const tsArgs = [];
205+
206+
if (process.argv.includes("--include-sourcemap")) {
207+
tsArgs.push('--sourceMap');
208+
}
209+
210+
return tsArgs.join('');
211+
}
212+
199213
var buildNodeTask = function (taskPath, outDir, isServerBuild) {
200214
var originalDir = shell.pwd().toString();
201215
cd(taskPath);
202216
var packageJsonPath = rp('package.json');
203217
var overrideTscPath;
218+
219+
performNpmAudit(taskPath);
220+
204221
if (test('-f', packageJsonPath)) {
205222
// verify no dev dependencies
206223
// we allow only two dev dependencies: typescript and @tsconfig/node10
@@ -233,16 +250,14 @@ var buildNodeTask = function (taskPath, outDir, isServerBuild) {
233250
cd(taskPath);
234251
}
235252

236-
performNpmAudit(taskPath);
237-
238253
// Use the tsc version supplied by the task if it is available, otherwise use the global default.
239254
if (overrideTscPath) {
240255
var tscExec = path.join(overrideTscPath, "bin", "tsc");
241-
run("node " + tscExec + ' --outDir "' + outDir + '" --rootDir "' + taskPath + '"');
256+
run(`node ${tscExec} --outDir "${outDir}" --rootDir "${taskPath}" ${getAdditionalTypeScriptArguments()}`);
242257
// Don't include typescript in node_modules
243258
rm("-rf", overrideTscPath);
244259
} else {
245-
run('tsc --outDir "' + outDir + '" --rootDir "' + taskPath + '"');
260+
run(`tsc --outDir "${outDir}" --rootDir "${taskPath}" ${getAdditionalTypeScriptArguments()}`);
246261
}
247262

248263
cd(originalDir);

make.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ var rm = util.rm;
2121
var test = util.test;
2222
var run = util.run;
2323
var banner = util.banner;
24-
var rp = util.rp;
2524
var fail = util.fail;
2625
var ensureExists = util.ensureExists;
27-
var pathExists = util.pathExists;
2826
var buildNodeTask = util.buildNodeTask;
2927
var addPath = util.addPath;
3028
var copyTaskResources = util.copyTaskResources;

0 commit comments

Comments
 (0)