From 31e075206505da25b37a613a87b3b0e2affc8b0d Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 2 Oct 2018 17:04:37 -0700 Subject: [PATCH] Fixing strict null checks in build util --- build/lib/util.js | 15 ++++++++------- build/lib/util.ts | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/build/lib/util.js b/build/lib/util.js index dd6f0b56992..904135b508e 100644 --- a/build/lib/util.js +++ b/build/lib/util.js @@ -20,13 +20,13 @@ function incremental(streamProvider, initial, supportsCancellation) { var output = es.through(); var state = 'idle'; var buffer = Object.create(null); - var token = !supportsCancellation ? null : { isCancellationRequested: function () { return Object.keys(buffer).length > 0; } }; + var token = !supportsCancellation ? undefined : { isCancellationRequested: function () { return Object.keys(buffer).length > 0; } }; var run = function (input, isCancellable) { state = 'running'; var stream = !supportsCancellation ? streamProvider() : streamProvider(isCancellable ? token : NoCancellationToken); input .pipe(stream) - .pipe(es.through(null, function () { + .pipe(es.through(undefined, function () { state = 'idle'; eventuallyRun(); })) @@ -119,7 +119,7 @@ function loadSourcemaps() { var output = input .pipe(es.map(function (f, cb) { if (f.sourceMap) { - cb(null, f); + cb(undefined, f); return; } if (!f.contents) { @@ -128,7 +128,8 @@ function loadSourcemaps() { } var contents = f.contents.toString('utf8'); var reg = /\/\/# sourceMappingURL=(.*)$/g; - var lastMatch = null, match = null; + var lastMatch = null; + var match = null; while (match = reg.exec(contents)) { lastMatch = match; } @@ -140,7 +141,7 @@ function loadSourcemaps() { sources: [f.relative.replace(/\//g, '/')], sourcesContent: [contents] }; - cb(null, f); + cb(undefined, f); return; } f.contents = Buffer.from(contents.replace(/\/\/# sourceMappingURL=(.*)$/g, ''), 'utf8'); @@ -149,7 +150,7 @@ function loadSourcemaps() { return cb(err); } f.sourceMap = JSON.parse(contents); - cb(null, f); + cb(undefined, f); }); })); return es.duplex(input, output); @@ -192,7 +193,7 @@ function getVersion(root) { exports.getVersion = getVersion; function rebase(count) { return rename(function (f) { - var parts = f.dirname.split(/[\/\\]/); + var parts = f.dirname ? f.dirname.split(/[\/\\]/) : []; f.dirname = parts.slice(count).join(path.sep); }); } diff --git a/build/lib/util.ts b/build/lib/util.ts index e1393b86c5b..9ad42b48efc 100644 --- a/build/lib/util.ts +++ b/build/lib/util.ts @@ -34,7 +34,7 @@ export function incremental(streamProvider: IStreamProvider, initial: NodeJS.Rea let state = 'idle'; let buffer = Object.create(null); - const token: ICancellationToken = !supportsCancellation ? null : { isCancellationRequested: () => Object.keys(buffer).length > 0 }; + const token: ICancellationToken | undefined = !supportsCancellation ? undefined : { isCancellationRequested: () => Object.keys(buffer).length > 0 }; const run = (input, isCancellable) => { state = 'running'; @@ -43,7 +43,7 @@ export function incremental(streamProvider: IStreamProvider, initial: NodeJS.Rea input .pipe(stream) - .pipe(es.through(null, () => { + .pipe(es.through(undefined, () => { state = 'idle'; eventuallyRun(); })) @@ -122,7 +122,7 @@ export function toFileUri(filePath: string): string { } export function skipDirectories(): NodeJS.ReadWriteStream { - return es.mapSync(f => { + return es.mapSync(f => { if (!f.isDirectory()) { return f; } @@ -157,9 +157,9 @@ export function loadSourcemaps(): NodeJS.ReadWriteStream { const input = es.through(); const output = input - .pipe(es.map((f, cb): FileSourceMap => { + .pipe(es.map((f, cb): FileSourceMap | undefined => { if (f.sourceMap) { - cb(null, f); + cb(undefined, f); return; } @@ -171,7 +171,8 @@ export function loadSourcemaps(): NodeJS.ReadWriteStream { const contents = (f.contents).toString('utf8'); const reg = /\/\/# sourceMappingURL=(.*)$/g; - let lastMatch = null, match = null; + let lastMatch: RegExpMatchArray | null = null; + let match: RegExpMatchArray | null = null; while (match = reg.exec(contents)) { lastMatch = match; @@ -186,7 +187,7 @@ export function loadSourcemaps(): NodeJS.ReadWriteStream { sourcesContent: [contents] }; - cb(null, f); + cb(undefined, f); return; } @@ -196,7 +197,7 @@ export function loadSourcemaps(): NodeJS.ReadWriteStream { if (err) { return cb(err); } f.sourceMap = JSON.parse(contents); - cb(null, f); + cb(undefined, f); }); })); @@ -236,7 +237,7 @@ export function rimraf(dir: string): (cb: any) => void { return cb => retry(cb); } -export function getVersion(root: string): string { +export function getVersion(root: string): string | undefined { let version = process.env['BUILD_SOURCEVERSION']; if (!version || !/^[0-9a-f]{40}$/i.test(version)) { @@ -248,7 +249,7 @@ export function getVersion(root: string): string { export function rebase(count: number): NodeJS.ReadWriteStream { return rename(f => { - const parts = f.dirname.split(/[\/\\]/); + const parts = f.dirname ? f.dirname.split(/[\/\\]/) : []; f.dirname = parts.slice(count).join(path.sep); }); }