diff --git a/build/gulpfile.extensions.ts b/build/gulpfile.extensions.ts index f48738be53a..cae158ea590 100644 --- a/build/gulpfile.extensions.ts +++ b/build/gulpfile.extensions.ts @@ -166,7 +166,7 @@ const tasks = compilations.map(function (tsconfigFile) { const compileTask = task.define(`compile-extension:${name}`, task.series(cleanTask, async () => { const nonts = gulp.src(src, srcOpts).pipe(filter(['**', '!**/*.ts'], { dot: true })); const copyNonTs = util.streamToPromise(nonts.pipe(gulp.dest(out))); - const tsgo = spawnTsgo(absolutePath, { reporterId: 'extensions' }, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)); + const tsgo = spawnTsgo(absolutePath, { taskName: 'extensions' }, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)); await Promise.all([copyNonTs, tsgo]); })); @@ -175,7 +175,7 @@ const tasks = compilations.map(function (tsconfigFile) { const nonts = gulp.src(src, srcOpts).pipe(filter(['**', '!**/*.ts'], { dot: true })); const watchInput = watcher(src, { ...srcOpts, ...{ readDelay: 200 } }); const watchNonTs = watchInput.pipe(filter(['**', '!**/*.ts'], { dot: true })).pipe(gulp.dest(out)); - const tsgoStream = watchInput.pipe(util.debounce(() => createTsgoStream(absolutePath, { reporterId: 'extensions' }, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)), 200)); + const tsgoStream = watchInput.pipe(util.debounce(() => createTsgoStream(absolutePath, { taskName: 'extensions' }, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)), 200)); const watchStream = es.merge(nonts.pipe(gulp.dest(out)), watchNonTs, tsgoStream); return watchStream; @@ -276,9 +276,9 @@ gulp.task(watchWebExtensionsTask); async function buildWebExtensions(isWatch: boolean): Promise { const extensionsPath = path.join(root, 'extensions'); - // Find all esbuild-browser.ts files + // Find all esbuild.browser.mts files const esbuildConfigLocations = await nodeUtil.promisify(glob)( - path.join(extensionsPath, '**', 'esbuild-browser.ts'), + path.join(extensionsPath, '**', 'esbuild.browser.mts'), { ignore: ['**/node_modules'] } ); @@ -293,7 +293,11 @@ async function buildWebExtensions(isWatch: boolean): Promise { // Esbuild for extensions if (esbuildConfigLocations.length > 0) { - promises.push(ext.esbuildExtensions('packaging web extension (esbuild)', isWatch, esbuildConfigLocations.map(script => ({ script })))); + promises.push( + ext.esbuildExtensions('packaging web extension (esbuild)', isWatch, esbuildConfigLocations.map(script => ({ script }))), + // Also run type check on extensions + ...esbuildConfigLocations.map(script => ext.typeCheckExtension(path.dirname(script), true)) + ); } // Run webpack for remaining extensions diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts index 3e83cab64f9..fac7946fc98 100644 --- a/build/lib/extensions.ts +++ b/build/lib/extensions.ts @@ -25,7 +25,7 @@ import { getProductionDependencies } from './dependencies.ts'; import { type IExtensionDefinition, getExtensionStream } from './builtInExtensions.ts'; import { getVersion } from './getVersion.ts'; import { fetchUrls, fetchGithub } from './fetch.ts'; -import { createTsgoStream } from './tsgo.ts'; +import { createTsgoStream, spawnTsgo } from './tsgo.ts'; import vzip from 'gulp-vinyl-zip'; import { createRequire } from 'module'; @@ -85,7 +85,7 @@ function fromLocal(extensionPath: string, forWeb: boolean, disableMangle: boolea // Unlike webpack, esbuild only does bundling so we still want to run a separate type check step input = es.merge( fromLocalEsbuild(extensionPath, esbuildConfigFileName), - typeCheckExtension(extensionPath, forWeb), + typeCheckExtensionStream(extensionPath, forWeb), ); isBundled = true; } else if (hasWebpack) { @@ -110,10 +110,16 @@ function fromLocal(extensionPath: string, forWeb: boolean, disableMangle: boolea return input; } -function typeCheckExtension(extensionPath: string, forWeb: boolean): Stream { +export function typeCheckExtension(extensionPath: string, forWeb: boolean): Promise { const tsconfigFileName = forWeb ? 'tsconfig.browser.json' : 'tsconfig.json'; const tsconfigPath = path.join(extensionPath, tsconfigFileName); - return createTsgoStream(tsconfigPath, { reporterId: 'extensions', noEmit: true }); + return spawnTsgo(tsconfigPath, { taskName: 'typechecking extension (tsgo)', noEmit: true }); +} + +export function typeCheckExtensionStream(extensionPath: string, forWeb: boolean): Stream { + const tsconfigFileName = forWeb ? 'tsconfig.browser.json' : 'tsconfig.json'; + const tsconfigPath = path.join(extensionPath, tsconfigFileName); + return createTsgoStream(tsconfigPath, { taskName: 'typechecking extension (tsgo)', noEmit: true }); } function fromLocalWebpack(extensionPath: string, webpackConfigFileName: string, disableMangle: boolean): Stream { diff --git a/build/lib/tsgo.ts b/build/lib/tsgo.ts index 9427b397926..421f4c1cc1b 100644 --- a/build/lib/tsgo.ts +++ b/build/lib/tsgo.ts @@ -3,35 +3,24 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import ansiColors from 'ansi-colors'; import * as cp from 'child_process'; import es from 'event-stream'; +import fancyLog from 'fancy-log'; import * as path from 'path'; -import { createReporter } from './reporter.ts'; const root = path.dirname(path.dirname(import.meta.dirname)); const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx'; const ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; -export function spawnTsgo(projectPath: string, config: { reporterId: string; noEmit?: boolean }, onComplete?: () => Promise | void): Promise { - const reporter = createReporter(config.reporterId); - let report: NodeJS.ReadWriteStream | undefined; - - const beginReport = (emitError: boolean) => { - if (report) { - report.end(); +export function spawnTsgo(projectPath: string, config: { taskName: string; noEmit?: boolean }, onComplete?: () => Promise | void): Promise { + function reporter(stdError: string) { + const matches = (stdError || '').match(/^error \w+: (.+)?/g); + fancyLog(`Finished ${ansiColors.green(config.taskName)} ${projectPath} with ${matches ? matches.length : 0} errors.`); + for (const match of matches || []) { + fancyLog.error(match); } - report = reporter.end(emitError); - }; - - const endReport = () => { - if (!report) { - return; - } - report.end(); - report = undefined; - }; - - beginReport(false); + } const args = ['tsgo', '--project', projectPath, '--pretty', 'false']; if (config.noEmit) { @@ -52,23 +41,13 @@ export function spawnTsgo(projectPath: string, config: { reporterId: string; noE return; } if (/Starting compilation|File change detected/i.test(trimmed)) { - beginReport(false); return; } if (/Compilation complete/i.test(trimmed)) { - endReport(); return; } - const match = /(.*\(\d+,\d+\): )(.*: )(.*)/.exec(trimmed); - - if (match) { - const fullpath = path.isAbsolute(match[1]) ? match[1] : path.join(root, match[1]); - const message = match[3]; - reporter(fullpath + message); - } else { - reporter(trimmed); - } + reporter(trimmed); }; const handleData = (data: Buffer) => { @@ -89,7 +68,7 @@ export function spawnTsgo(projectPath: string, config: { reporterId: string; noE handleLine(buffer); buffer = ''; } - endReport(); + if (code === 0) { Promise.resolve(onComplete?.()).then(() => resolve(), reject); } else { @@ -98,15 +77,13 @@ export function spawnTsgo(projectPath: string, config: { reporterId: string; noE }); child.on('error', err => { - endReport(); reject(err); }); }); } -export function createTsgoStream(projectPath: string, config: { reporterId: string; noEmit?: boolean }, onComplete?: () => Promise | void): NodeJS.ReadWriteStream { +export function createTsgoStream(projectPath: string, config: { taskName: string; noEmit?: boolean }, onComplete?: () => Promise | void): NodeJS.ReadWriteStream { const stream = es.through(); - spawnTsgo(projectPath, config, onComplete).then(() => { stream.emit('end'); }).catch(() => { diff --git a/extensions/markdown-math/package.json b/extensions/markdown-math/package.json index 4a9be208ea0..19f20fcd04a 100644 --- a/extensions/markdown-math/package.json +++ b/extensions/markdown-math/package.json @@ -108,7 +108,7 @@ "scripts": { "compile": "npm run build-notebook", "watch": "npm run build-notebook", - "build-notebook": "node ./esbuild.mts" + "build-notebook": "node ./esbuild.notebook.mts" }, "devDependencies": { "@types/markdown-it": "^0.0.0", diff --git a/extensions/markdown-math/tsconfig.browser.json b/extensions/markdown-math/tsconfig.browser.json index 24f4ba27a3d..715a07ebfb8 100644 --- a/extensions/markdown-math/tsconfig.browser.json +++ b/extensions/markdown-math/tsconfig.browser.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig.json", + "extends": "./tsconfig.json", "compilerOptions": { "types": [], "typeRoots": [ diff --git a/extensions/media-preview/tsconfig.browser.json b/extensions/media-preview/tsconfig.browser.json new file mode 100644 index 00000000000..3694afc77ee --- /dev/null +++ b/extensions/media-preview/tsconfig.browser.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig" +} diff --git a/extensions/mermaid-chat-features/tsconfig.browser.json b/extensions/mermaid-chat-features/tsconfig.browser.json new file mode 100644 index 00000000000..3694afc77ee --- /dev/null +++ b/extensions/mermaid-chat-features/tsconfig.browser.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig" +} diff --git a/extensions/simple-browser/package.json b/extensions/simple-browser/package.json index 5fc5cee96f0..d372992c897 100644 --- a/extensions/simple-browser/package.json +++ b/extensions/simple-browser/package.json @@ -67,11 +67,11 @@ ] }, "scripts": { - "compile": "gulp compile-extension:simple-browser && npm run build-preview", - "watch": "npm run build-preview && gulp watch-extension:simple-browser", - "vscode:prepublish": "npm run build-ext && npm run build-preview", + "compile": "gulp compile-extension:simple-browser && npm run build-webview", + "watch": "npm run build-webview && gulp watch-extension:simple-browser", + "vscode:prepublish": "npm run build-ext && npm run build-webview", "build-ext": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.mjs compile-extension:simple-browser ./tsconfig.json", - "build-preview": "node ./esbuild-preview.mts", + "build-webview": "node ./esbuild.webview.mts", "compile-web": "npx webpack-cli --config extension-browser.webpack.config --mode none", "watch-web": "npx webpack-cli --config extension-browser.webpack.config --mode none --watch --info-verbosity verbose" },