/*--------------------------------------------------------------------------------------------- * 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 type * as esbuild from 'esbuild'; import { run } from '../esbuild-extension-common.mts'; const extensionRoot = import.meta.dirname; /** * An esbuild plugin that replaces the `javascriptLibs` module with inlined TypeScript * library definitions for the browser build. This is the esbuild equivalent of the * webpack `javaScriptLibraryLoader.js`. */ function javaScriptLibsPlugin(): esbuild.Plugin { return { name: 'javascript-libs', setup(build) { build.onLoad({ filter: /javascriptLibs\.ts$/ }, () => { const TYPESCRIPT_LIB_SOURCE = path.dirname(import.meta.resolve('typescript').replace('file://', '')); const JQUERY_DTS = path.join(extensionRoot, 'server', 'lib', 'jquery.d.ts'); function getFileName(name: string): string { return name === '' ? 'lib.d.ts' : `lib.${name}.d.ts`; } function readLibFile(name: string): string { return fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, getFileName(name)), 'utf8'); } const queue: string[] = []; const inQueue: Record = {}; function enqueue(name: string): void { if (inQueue[name]) { return; } inQueue[name] = true; queue.push(name); } enqueue('es2020.full'); const result: { name: string; content: string }[] = []; while (queue.length > 0) { const name = queue.shift()!; const contents = readLibFile(name); const lines = contents.split(/\r\n|\r|\n/); const outputLines: string[] = []; for (const line of lines) { const m = line.match(/\/\/\/\s*