From fe45a7d21fab4d9a6bc339ac6760ffe242127712 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 2 Oct 2018 17:19:03 -0700 Subject: [PATCH] Fix remaining strict null errors in build scripts --- build/lib/compilation.js | 4 ++-- build/lib/compilation.ts | 4 ++-- build/lib/electron.js | 2 ++ build/lib/extensions.js | 4 ++-- build/lib/extensions.ts | 8 ++++---- build/lib/optimize.js | 8 ++++---- build/lib/optimize.ts | 8 ++++---- build/lib/reporter.js | 1 + build/lib/reporter.ts | 1 + build/lib/treeshaking.ts | 4 ++-- build/lib/typings/lazy.js.d.ts | 7 +++++-- 11 files changed, 29 insertions(+), 22 deletions(-) diff --git a/build/lib/compilation.js b/build/lib/compilation.js index 9fb87c0ae03..3fff4a3745b 100644 --- a/build/lib/compilation.js +++ b/build/lib/compilation.js @@ -36,7 +36,7 @@ function createCompile(src, build, emitError) { var opts = _.clone(getTypeScriptCompilerOptions(src)); opts.inlineSources = !!build; opts.noFilesystemLookup = true; - var ts = tsb.create(opts, true, null, function (err) { return reporter(err.toString()); }); + var ts = tsb.create(opts, true, undefined, function (err) { return reporter(err.toString()); }); return function (token) { var utf8Filter = util.filter(function (data) { return /(\/|\\)test(\/|\\).*utf8/.test(data.path); }); var tsFilter = util.filter(function (data) { return /\.ts$/.test(data.path); }); @@ -58,7 +58,7 @@ function createCompile(src, build, emitError) { sourceRoot: opts.sourceRoot })) .pipe(tsFilter.restore) - .pipe(reporter.end(emitError)); + .pipe(reporter.end(!!emitError)); return es.duplex(input, output); }; } diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index eb35f525ac9..2a9274df9c8 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -41,7 +41,7 @@ function createCompile(src: string, build: boolean, emitError?: boolean): (token opts.inlineSources = !!build; opts.noFilesystemLookup = true; - const ts = tsb.create(opts, true, null, err => reporter(err.toString())); + const ts = tsb.create(opts, true, undefined, err => reporter(err.toString())); return function (token?: util.ICancellationToken) { @@ -66,7 +66,7 @@ function createCompile(src: string, build: boolean, emitError?: boolean): (token sourceRoot: opts.sourceRoot })) .pipe(tsFilter.restore) - .pipe(reporter.end(emitError)); + .pipe(reporter.end(!!emitError)); return es.duplex(input, output); }; diff --git a/build/lib/electron.js b/build/lib/electron.js index 9e8a48e1858..6387133675b 100644 --- a/build/lib/electron.js +++ b/build/lib/electron.js @@ -11,6 +11,7 @@ const root = path.dirname(path.dirname(__dirname)); function getElectronVersion() { const yarnrc = fs.readFileSync(path.join(root, '.yarnrc'), 'utf8'); + // @ts-ignore const target = /^target "(.*)"$/m.exec(yarnrc)[1]; return target; @@ -19,6 +20,7 @@ function getElectronVersion() { module.exports.getElectronVersion = getElectronVersion; // returns 0 if the right version of electron is in .build/electron +// @ts-ignore if (require.main === module) { const version = getElectronVersion(); const versionFile = path.join(root, '.build', 'electron', 'version'); diff --git a/build/lib/extensions.js b/build/lib/extensions.js index e8c7840935e..72216ec2d04 100644 --- a/build/lib/extensions.js +++ b/build/lib/extensions.js @@ -211,8 +211,8 @@ function sequence(streamProviders) { pop(); return result; } -function packageExtensionsStream(opts) { - opts = opts || {}; +function packageExtensionsStream(optsIn) { + var opts = optsIn || {}; var localExtensionDescriptions = glob.sync('extensions/*/package.json') .map(function (manifestPath) { var extensionPath = path.dirname(path.join(root, manifestPath)); diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts index 6c248e20bb5..44d90badcd6 100644 --- a/build/lib/extensions.ts +++ b/build/lib/extensions.ts @@ -34,7 +34,7 @@ function fromLocal(extensionPath: string, sourceMappingURLBase?: string): Stream } } -function fromLocalWebpack(extensionPath: string, sourceMappingURLBase: string): Stream { +function fromLocalWebpack(extensionPath: string, sourceMappingURLBase: string | undefined): Stream { let result = es.through(); let packagedDependencies: string[] = []; @@ -249,7 +249,7 @@ function sequence(streamProviders: { (): Stream }[]): Stream { if (streamProviders.length === 0) { result.emit('end'); } else { - const fn = streamProviders.shift(); + const fn = streamProviders.shift()!; fn() .on('end', function () { setTimeout(pop, 0); }) .pipe(result, { end: false }); @@ -260,8 +260,8 @@ function sequence(streamProviders: { (): Stream }[]): Stream { return result; } -export function packageExtensionsStream(opts?: IPackageExtensionsOptions): NodeJS.ReadWriteStream { - opts = opts || {}; +export function packageExtensionsStream(optsIn?: IPackageExtensionsOptions): NodeJS.ReadWriteStream { + const opts = optsIn || {}; const localExtensionDescriptions = (glob.sync('extensions/*/package.json')) .map(manifestPath => { diff --git a/build/lib/optimize.js b/build/lib/optimize.js index 044780ba7fd..b86aad95d0e 100644 --- a/build/lib/optimize.js +++ b/build/lib/optimize.js @@ -124,7 +124,7 @@ function optimizeTask(opts) { var resourcesStream = es.through(); // this stream will contain the resources var bundleInfoStream = es.through(); // this stream will contain bundleInfo.json bundle.bundle(entryPoints, loaderConfig, function (err, result) { - if (err) { + if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); } toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream); @@ -163,7 +163,7 @@ function optimizeTask(opts) { var result = es.merge(loader(src, bundledFileHeader, bundleLoader), bundlesStream, otherSourcesStream, resourcesStream, bundleInfoStream); return result .pipe(sourcemaps.write('./', { - sourceRoot: null, + sourceRoot: undefined, addComment: true, includeContent: true })) @@ -219,13 +219,13 @@ function uglifyWithCopyrights() { return es.duplex(input, output); } function minifyTask(src, sourceMapBaseUrl) { - var sourceMappingURL = sourceMapBaseUrl && (function (f) { return sourceMapBaseUrl + "/" + f.relative + ".map"; }); + var sourceMappingURL = sourceMapBaseUrl ? (function (f) { return sourceMapBaseUrl + "/" + f.relative + ".map"; }) : undefined; return function (cb) { var jsFilter = filter('**/*.js', { restore: true }); var cssFilter = filter('**/*.css', { restore: true }); pump(gulp.src([src + '/**', '!' + src + '/**/*.map']), jsFilter, sourcemaps.init({ loadMaps: true }), uglifyWithCopyrights(), jsFilter.restore, cssFilter, minifyCSS({ reduceIdents: false }), cssFilter.restore, sourcemaps.write('./', { sourceMappingURL: sourceMappingURL, - sourceRoot: null, + sourceRoot: undefined, includeContent: true, addComment: true }), gulp.dest(src + '-min'), function (err) { diff --git a/build/lib/optimize.ts b/build/lib/optimize.ts index 8a35523dbe2..54c3367430a 100644 --- a/build/lib/optimize.ts +++ b/build/lib/optimize.ts @@ -188,7 +188,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr const bundleInfoStream = es.through(); // this stream will contain bundleInfo.json bundle.bundle(entryPoints, loaderConfig, function (err, result) { - if (err) { return bundlesStream.emit('error', JSON.stringify(err)); } + if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); } toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream); @@ -237,7 +237,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr return result .pipe(sourcemaps.write('./', { - sourceRoot: null, + sourceRoot: undefined, addComment: true, includeContent: true })) @@ -302,7 +302,7 @@ function uglifyWithCopyrights(): NodeJS.ReadWriteStream { } export function minifyTask(src: string, sourceMapBaseUrl?: string): (cb: any) => void { - const sourceMappingURL = sourceMapBaseUrl && (f => `${sourceMapBaseUrl}/${f.relative}.map`); + const sourceMappingURL = sourceMapBaseUrl ? ((f: any) => `${sourceMapBaseUrl}/${f.relative}.map`) : undefined; return cb => { const jsFilter = filter('**/*.js', { restore: true }); @@ -319,7 +319,7 @@ export function minifyTask(src: string, sourceMapBaseUrl?: string): (cb: any) => cssFilter.restore, sourcemaps.write('./', { sourceMappingURL, - sourceRoot: null, + sourceRoot: undefined, includeContent: true, addComment: true }), diff --git a/build/lib/reporter.js b/build/lib/reporter.js index c894171405a..e7de870d1fb 100644 --- a/build/lib/reporter.js +++ b/build/lib/reporter.js @@ -45,6 +45,7 @@ function log() { var messages = errors .map(function (err) { return regex.exec(err); }) .filter(function (match) { return !!match; }) + .map(function (x) { return x; }) .map(function (_a) { var path = _a[1], line = _a[2], column = _a[3], message = _a[4]; return ({ path: path, line: parseInt(line), column: parseInt(column), message: message }); diff --git a/build/lib/reporter.ts b/build/lib/reporter.ts index 8f345b65e0b..4e2bdf94ed9 100644 --- a/build/lib/reporter.ts +++ b/build/lib/reporter.ts @@ -55,6 +55,7 @@ function log(): void { const messages = errors .map(err => regex.exec(err)) .filter(match => !!match) + .map(x => x as string[]) .map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message })); try { diff --git a/build/lib/treeshaking.ts b/build/lib/treeshaking.ts index 28a7f1a5b2e..395699e328e 100644 --- a/build/lib/treeshaking.ts +++ b/build/lib/treeshaking.ts @@ -448,7 +448,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt } if (options.shakeLevel === ShakeLevel.ClassMembers && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration))) { - enqueue_black(declaration.name); + enqueue_black(declaration.name!); for (let j = 0; j < declaration.members.length; j++) { const member = declaration.members[j]; @@ -635,7 +635,7 @@ function generateResult(languageService: ts.LanguageService, shakeLevel: ShakeLe /** * Returns the node's symbol and the `import` node (if the symbol resolved from a different module) */ -function getRealNodeSymbol(checker: ts.TypeChecker, node: ts.Node): [ts.Symbol, ts.Declaration] { +function getRealNodeSymbol(checker: ts.TypeChecker, node: ts.Node): [ts.Symbol | null, ts.Declaration | null] { /** * Returns the containing object literal property declaration given a possible name node, e.g. "a" in x = { "a": 1 } */ diff --git a/build/lib/typings/lazy.js.d.ts b/build/lib/typings/lazy.js.d.ts index 28761b81035..f69924b4b1c 100644 --- a/build/lib/typings/lazy.js.d.ts +++ b/build/lib/typings/lazy.js.d.ts @@ -18,7 +18,7 @@ declare module Lazy { function on(eventType: string): Sequence; function readFile(path: string): StringLikeSequence; function makeHttpRequest(path: string): StringLikeSequence; - + interface StrictLazy { (value: string): StringLikeSequence; (value: T[]): ArrayLikeSequence; @@ -87,7 +87,7 @@ declare module Lazy { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - interface Iterator { - new (sequence: Sequence): Iterator; + new(sequence: Sequence): Iterator; current(): T; moveNext(): boolean; } @@ -159,6 +159,9 @@ declare module Lazy { map(mapFn: MapCallback): ArraySequence; map(mapFn: MapCallback): Sequence; + // TODO: vscode addition to workaround strict null errors + flatten(): Sequence; + max(valueFn?: NumberCallback): T; min(valueFn?: NumberCallback): T; none(valueFn?: TestCallback): boolean; -- GitLab