mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 10:08:49 +01:00
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:
@@ -2,7 +2,7 @@
|
||||
.vscode-test/**
|
||||
out/test/**
|
||||
out/**
|
||||
extension.webpack.config.js
|
||||
esbuild*.mts
|
||||
package-lock.json
|
||||
src/**
|
||||
.gitignore
|
||||
|
||||
67
extensions/microsoft-authentication/esbuild.mts
Normal file
67
extensions/microsoft-authentication/esbuild.mts
Normal 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);
|
||||
@@ -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
|
||||
});
|
||||
Reference in New Issue
Block a user