Skip to content

Commit 71946bf

Browse files
authored
Merge pull request #278893 from microsoft/dev/mjbvz/gulp-ts
Convert gulp files to ts
2 parents 874cfc3 + c3c3661 commit 71946bf

18 files changed

+229
-269
lines changed

build/gulpfile.cli.mjs renamed to build/gulpfile.cli.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ import * as cp from 'child_process';
1212
import { tmpdir } from 'os';
1313
import { existsSync, mkdirSync, rmSync } from 'fs';
1414
import * as task from './lib/task.ts';
15-
import * as watcher from './lib/watch/index.ts';
16-
import * as utilModule from './lib/util.ts';
17-
import * as reporterModule from './lib/reporter.ts';
15+
import watcher from './lib/watch/index.ts';
16+
import { debounce } from './lib/util.ts';
17+
import { createReporter } from './lib/reporter.ts';
1818
import untar from 'gulp-untar';
1919
import gunzip from 'gulp-gunzip';
20-
import { fileURLToPath } from 'url';
21-
22-
const { debounce } = utilModule;
23-
const { createReporter } = reporterModule;
2420

2521
const root = 'cli';
2622
const rootAbs = path.resolve(import.meta.dirname, '..', root);
@@ -43,8 +39,7 @@ const platformOpensslDirName =
4339
const platformOpensslDir = path.join(rootAbs, 'openssl', 'package', 'out', platformOpensslDirName);
4440

4541
const hasLocalRust = (() => {
46-
/** @type boolean | undefined */
47-
let result = undefined;
42+
let result: boolean | undefined = undefined;
4843
return () => {
4944
if (result !== undefined) {
5045
return result;
@@ -61,15 +56,14 @@ const hasLocalRust = (() => {
6156
};
6257
})();
6358

64-
const compileFromSources = (callback) => {
59+
const compileFromSources = (callback: (err?: string) => void) => {
6560
const proc = cp.spawn('cargo', ['--color', 'always', 'build'], {
6661
cwd: root,
6762
stdio: ['ignore', 'pipe', 'pipe'],
6863
env: existsSync(platformOpensslDir) ? { OPENSSL_DIR: platformOpensslDir, ...process.env } : process.env
6964
});
7065

71-
/** @type Buffer[] */
72-
const stdoutErr = [];
66+
const stdoutErr: Buffer[] = [];
7367
proc.stdout.on('data', d => stdoutErr.push(d));
7468
proc.stderr.on('data', d => stdoutErr.push(d));
7569
proc.on('error', callback);
@@ -82,7 +76,7 @@ const compileFromSources = (callback) => {
8276
});
8377
};
8478

85-
const acquireBuiltOpenSSL = (callback) => {
79+
const acquireBuiltOpenSSL = (callback: (err?: unknown) => void) => {
8680
const dir = path.join(tmpdir(), 'vscode-openssl-download');
8781
mkdirSync(dir, { recursive: true });
8882

@@ -103,29 +97,28 @@ const acquireBuiltOpenSSL = (callback) => {
10397
});
10498
};
10599

106-
const compileWithOpenSSLCheck = (/** @type import('./lib/reporter').IReporter */ reporter) => es.map((_, callback) => {
100+
const compileWithOpenSSLCheck = (reporter: import('./lib/reporter.ts').IReporter) => es.map((_, callback) => {
107101
compileFromSources(err => {
108102
if (!err) {
109103
// no-op
110104
} else if (err.toString().includes('Could not find directory of OpenSSL installation') && !existsSync(platformOpensslDir)) {
111105
fancyLog(ansiColors.yellow(`[cli]`), 'OpenSSL libraries not found, acquiring prebuilt bits...');
112106
acquireBuiltOpenSSL(err => {
113107
if (err) {
114-
callback(err);
108+
callback(err as Error);
115109
} else {
116110
compileFromSources(err => {
117111
if (err) {
118112
reporter(err.toString());
119113
}
120-
callback(null, '');
114+
callback(undefined, '');
121115
});
122116
}
123117
});
124118
} else {
125119
reporter(err.toString());
126120
}
127-
128-
callback(null, '');
121+
callback(undefined, '');
129122
});
130123
});
131124

@@ -148,7 +141,7 @@ const compileCliTask = task.define('compile-cli', () => {
148141
const watchCliTask = task.define('watch-cli', () => {
149142
warnIfRustNotInstalled();
150143
return watcher(`${src}/**`, { read: false })
151-
.pipe(debounce(compileCliTask));
144+
.pipe(debounce(compileCliTask as task.StreamTask));
152145
});
153146

154147
gulp.task(compileCliTask);

build/gulpfile.compile.mjs renamed to build/gulpfile.compile.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
//@ts-check
5+
66
import gulp from 'gulp';
77
import * as util from './lib/util.ts';
88
import * as date from './lib/date.ts';
99
import * as task from './lib/task.ts';
1010
import * as compilation from './lib/compilation.ts';
1111

12-
/**
13-
* @param {boolean} disableMangle
14-
*/
15-
function makeCompileBuildTask(disableMangle) {
12+
function makeCompileBuildTask(disableMangle: boolean) {
1613
return task.series(
1714
util.rimraf('out-build'),
1815
date.writeISODate('out-build'),

build/gulpfile.editor.mjs renamed to build/gulpfile.editor.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
//@ts-check
5+
66
import gulp from 'gulp';
77
import path from 'path';
88
import * as util from './lib/util.ts';
@@ -84,10 +84,7 @@ const compileEditorESMTask = task.define('compile-editor-esm', () => {
8484
);
8585
});
8686

87-
/**
88-
* @param {string} contents
89-
*/
90-
function toExternalDTS(contents) {
87+
function toExternalDTS(contents: string) {
9188
const lines = contents.split(/\r\n|\r|\n/);
9289
let killNextCloseCurlyBrace = false;
9390
for (let i = 0; i < lines.length; i++) {
@@ -230,10 +227,7 @@ gulp.task('monacodts', task.define('monacodts', () => {
230227

231228
//#region monaco type checking
232229

233-
/**
234-
* @param {boolean} watch
235-
*/
236-
function createTscCompileTask(watch) {
230+
function createTscCompileTask(watch: boolean) {
237231
return () => {
238232
return new Promise((resolve, reject) => {
239233
const args = ['./node_modules/.bin/tsc', '-p', './src/tsconfig.monaco.json', '--noEmit'];
@@ -244,11 +238,10 @@ function createTscCompileTask(watch) {
244238
cwd: path.join(import.meta.dirname, '..'),
245239
// stdio: [null, 'pipe', 'inherit']
246240
});
247-
const errors = [];
241+
const errors: string[] = [];
248242
const reporter = createReporter('monaco');
249243

250-
/** @type {NodeJS.ReadWriteStream | undefined} */
251-
let report;
244+
let report: NodeJS.ReadWriteStream | undefined;
252245
const magic = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; // https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings
253246

254247
child.stdout.on('data', data => {
@@ -286,14 +279,13 @@ export const monacoTypecheckWatchTask = task.define('monaco-typecheck-watch', cr
286279
export const monacoTypecheckTask = task.define('monaco-typecheck', createTscCompileTask(false));
287280

288281
//#endregion
289-
290282
/**
291283
* Sets a field on an object only if it's not already set, otherwise throws an error
292-
* @param {any} obj - The object to modify
293-
* @param {string} field - The field name to set
294-
* @param {any} value - The value to set
284+
* @param obj The object to modify
285+
* @param field The field name to set
286+
* @param value The value to set
295287
*/
296-
function setUnsetField(obj, field, value) {
288+
function setUnsetField(obj: Record<string, unknown>, field: string, value: unknown) {
297289
if (obj[field] !== undefined) {
298290
throw new Error(`Field "${field}" is already set (but was expected to not be).`);
299291
}

build/gulpfile.extensions.mjs renamed to build/gulpfile.extensions.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import plumber from 'gulp-plumber';
2222
import * as ext from './lib/extensions.ts';
2323
import * as tsb from './lib/tsb/index.ts';
2424
import sourcemaps from 'gulp-sourcemaps';
25-
import { fileURLToPath } from 'url';
2625

2726
const { getVersion } = getVersionModule;
2827
const { createReporter } = reporterModule;
@@ -79,13 +78,13 @@ const compilations = [
7978
'.vscode/extensions/vscode-selfhost-import-aid/tsconfig.json',
8079
];
8180

82-
const getBaseUrl = out => `https://main.vscode-cdn.net/sourcemaps/${commit}/${out}`;
81+
const getBaseUrl = (out: string) => `https://main.vscode-cdn.net/sourcemaps/${commit}/${out}`;
8382

8483
const tasks = compilations.map(function (tsconfigFile) {
8584
const absolutePath = path.join(root, tsconfigFile);
8685
const relativeDirname = path.dirname(tsconfigFile.replace(/^(.*\/)?extensions\//i, ''));
8786

88-
const overrideOptions = {};
87+
const overrideOptions: { sourceMap?: boolean; inlineSources?: boolean; base?: string } = {};
8988
overrideOptions.sourceMap = true;
9089

9190
const name = relativeDirname.replace(/\//g, '-');
@@ -98,7 +97,7 @@ const tasks = compilations.map(function (tsconfigFile) {
9897
const out = path.join(srcRoot, 'out');
9998
const baseUrl = getBaseUrl(out);
10099

101-
function createPipeline(build, emitError, transpileOnly) {
100+
function createPipeline(build: boolean, emitError?: boolean, transpileOnly?: boolean) {
102101
const reporter = createReporter('extensions');
103102

104103
overrideOptions.inlineSources = Boolean(build);
@@ -122,14 +121,14 @@ const tasks = compilations.map(function (tsconfigFile) {
122121
.pipe(compilation())
123122
.pipe(build ? util.stripSourceMappingURL() : es.through())
124123
.pipe(sourcemaps.write('.', {
125-
sourceMappingURL: !build ? null : f => `${baseUrl}/${f.relative}.map`,
124+
sourceMappingURL: !build ? undefined : f => `${baseUrl}/${f.relative}.map`,
126125
addComment: !!build,
127126
includeContent: !!build,
128127
// note: trailing slash is important, else the source URLs in V8's file coverage are incorrect
129128
sourceRoot: '../src/',
130129
}))
131130
.pipe(tsFilter.restore)
132-
.pipe(reporter.end(emitError));
131+
.pipe(reporter.end(!!emitError));
133132

134133
return es.duplex(input, output);
135134
};
@@ -266,10 +265,7 @@ gulp.task(compileWebExtensionsTask);
266265
export const watchWebExtensionsTask = task.define('watch-web', () => buildWebExtensions(true));
267266
gulp.task(watchWebExtensionsTask);
268267

269-
/**
270-
* @param {boolean} isWatch
271-
*/
272-
async function buildWebExtensions(isWatch) {
268+
async function buildWebExtensions(isWatch: boolean) {
273269
const extensionsPath = path.join(root, 'extensions');
274270
const webpackConfigLocations = await nodeUtil.promisify(glob)(
275271
path.join(extensionsPath, '**', 'extension-browser.webpack.config.js'),

build/gulpfile.hygiene.mjs renamed to build/gulpfile.hygiene.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ import { hygiene } from './hygiene.ts';
1111

1212
const dirName = path.dirname(new URL(import.meta.url).pathname);
1313

14-
/**
15-
* @param {string} actualPath
16-
*/
17-
function checkPackageJSON(actualPath) {
14+
function checkPackageJSON(this: NodeJS.ReadWriteStream, actualPath: string) {
1815
const actual = JSON.parse(fs.readFileSync(path.join(dirName, '..', actualPath), 'utf8'));
1916
const rootPackageJSON = JSON.parse(fs.readFileSync(path.join(dirName, '..', 'package.json'), 'utf8'));
20-
const checkIncluded = (set1, set2) => {
17+
const checkIncluded = (set1: Record<string, string>, set2: Record<string, string>) => {
2118
for (const depName in set1) {
2219
const depVersion = set1[depName];
2320
const rootDepVersion = set2[depName];

0 commit comments

Comments
 (0)