Switch most remaining extensions to use esbuild

Just 3 left:

- git and github. These are doing weird stuff with d.ts imports and const enums

- github-authentication  which has some tricky path mapping stuff
This commit is contained in:
Matt Bierner
2026-02-19 11:12:46 -08:00
parent e80ddbf450
commit 2d9e484c8e
24 changed files with 234 additions and 193 deletions

View File

@@ -2,7 +2,7 @@
.vscode-test/**
out/test/**
out/**
extension.webpack.config.js
esbuild*.mts
package-lock.json
src/**
.gitignore

View File

@@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import { run } from '../esbuild-extension-common.mts';
const srcDir = path.join(import.meta.dirname, 'src');
const outDir = path.join(import.meta.dirname, 'dist');
const isWindows = process.platform === 'win32';
const isMacOS = process.platform === 'darwin';
const isLinux = !isWindows && !isMacOS;
const windowsArches = ['x64'];
const linuxArches = ['x64'];
let platformFolder: string;
switch (process.platform) {
case 'win32': platformFolder = 'windows'; break;
case 'darwin': platformFolder = 'macos'; break;
case 'linux': platformFolder = 'linux'; break;
default: platformFolder = '';
}
const arch = process.env.VSCODE_ARCH || process.arch;
/**
* Copy native MSAL runtime binaries to the output directory.
*/
async function copyNativeMsalFiles(outDir: string): Promise<void> {
if (
!(isWindows && windowsArches.includes(arch)) &&
!isMacOS &&
!(isLinux && linuxArches.includes(arch))
) {
return;
}
const msalRuntimeDir = path.join(import.meta.dirname, 'node_modules', '@azure', 'msal-node-runtime', 'dist', platformFolder, arch);
try {
const files = await fs.promises.readdir(msalRuntimeDir);
for (const file of files) {
if (/^(lib)?msal.*\.(node|dll|dylib|so)$/.test(file)) {
await fs.promises.copyFile(path.join(msalRuntimeDir, file), path.join(outDir, file));
}
}
} catch {
// Skip if directory doesn't exist (unsupported platform/arch)
}
}
run({
platform: 'node',
entryPoints: {
'extension': path.join(srcDir, 'extension.ts'),
},
srcDir,
outdir: outDir,
additionalOptions: {
external: ['vscode', './msal-node-runtime'],
alias: {
'keytar': path.resolve(import.meta.dirname, 'packageMocks', 'keytar', 'index.js'),
},
},
}, process.argv, copyNativeMsalFiles);

View File

@@ -1,69 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
import withDefaults, { nodePlugins } from '../shared.webpack.config.mjs';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import path from 'path';
const isWindows = process.platform === 'win32';
const isMacOS = process.platform === 'darwin';
const isLinux = !isWindows && !isMacOS;
const windowsArches = ['x64'];
const linuxArches = ['x64'];
let platformFolder;
switch (process.platform) {
case 'win32':
platformFolder = 'windows';
break;
case 'darwin':
platformFolder = 'macos';
break;
case 'linux':
platformFolder = 'linux';
break;
default:
throw new Error(`Unsupported platform: ${process.platform}`);
}
const arch = process.env.VSCODE_ARCH || process.arch;
console.log(`Building Microsoft Authentication Extension for ${process.platform} (${arch})`);
const plugins = [...nodePlugins(import.meta.dirname)];
if (
(isWindows && windowsArches.includes(arch)) ||
isMacOS ||
(isLinux && linuxArches.includes(arch))
) {
plugins.push(new CopyWebpackPlugin({
patterns: [
{
// The native files we need to ship with the extension
from: `**/dist/${platformFolder}/${arch}/(lib|)msal*.(node|dll|dylib|so)`,
to: '[name][ext]'
}
]
}));
}
export default withDefaults({
context: import.meta.dirname,
entry: {
extension: './src/extension.ts'
},
externals: {
// The @azure/msal-node-runtime package requires this native node module (.node).
// It is currently only included on Windows, but the package handles unsupported platforms
// gracefully.
'./msal-node-runtime': 'commonjs ./msal-node-runtime'
},
resolve: {
alias: {
'keytar': path.resolve(import.meta.dirname, 'packageMocks', 'keytar', 'index.js')
}
},
plugins
});