diff --git a/scripts/esbuild/cli.ts b/scripts/esbuild/cli.ts index 14ceaf64ca9..f5691f25e32 100644 --- a/scripts/esbuild/cli.ts +++ b/scripts/esbuild/cli.ts @@ -5,7 +5,7 @@ import { join } from 'path'; import { getBanner } from '../utils/banner'; import { BuildOptions } from '../utils/options'; import { writePkgJson } from '../utils/write-pkg-json'; -import { getBaseEsbuildOptions, getEsbuildAliases, getEsbuildExternalModules, runBuilds } from './utils'; +import { externalNodeModules, getBaseEsbuildOptions, getEsbuildAliases, runBuilds } from './utils'; /** * Runs esbuild to bundle the `cli` submodule @@ -30,7 +30,7 @@ export async function buildCli(opts: BuildOptions) { // this isn't strictly necessary to alias - however, this minimizes cuts down the bundle size by ~70kb. cliAliases['prompts'] = 'prompts/lib/index.js'; - const external = [...getEsbuildExternalModules(opts, opts.output.cliDir), '../testing/*']; + const external = [...externalNodeModules, '../testing/*']; const cliEsbuildOptions = { ...getBaseEsbuildOptions(), diff --git a/scripts/esbuild/compiler.ts b/scripts/esbuild/compiler.ts index 500acf56c9a..49147c9b522 100644 --- a/scripts/esbuild/compiler.ts +++ b/scripts/esbuild/compiler.ts @@ -6,7 +6,7 @@ import { join } from 'path'; import { getBanner } from '../utils/banner'; import { BuildOptions, createReplaceData } from '../utils/options'; import { writePkgJson } from '../utils/write-pkg-json'; -import { getBaseEsbuildOptions, getEsbuildAliases, getEsbuildExternalModules, runBuilds } from './utils'; +import { externalNodeModules, getBaseEsbuildOptions, getEsbuildAliases, runBuilds } from './utils'; import { bundleParse5 } from './utils/parse5'; import { bundleTerser } from './utils/terser'; import { bundleTypeScriptSource, tsCacheFilePath } from './utils/typescript-source'; @@ -51,7 +51,7 @@ export async function buildCompiler(opts: BuildOptions) { }; const external = [ - ...getEsbuildExternalModules(opts, opts.output.compilerDir), + ...externalNodeModules, '../mock-doc/index.cjs', '../sys/node/autoprefixer.js', '../sys/node/index.js', diff --git a/scripts/esbuild/internal-platform-client.ts b/scripts/esbuild/internal-platform-client.ts index 7168d7a1b0e..685cf10f785 100644 --- a/scripts/esbuild/internal-platform-client.ts +++ b/scripts/esbuild/internal-platform-client.ts @@ -7,7 +7,7 @@ import { join } from 'path'; import { getBanner } from '../utils/banner'; import { BuildOptions, createReplaceData } from '../utils/options'; import { writePkgJson } from '../utils/write-pkg-json'; -import { externalAlias, getBaseEsbuildOptions, getEsbuildAliases, getEsbuildExternalModules } from './utils'; +import { externalAlias, externalNodeModules, getBaseEsbuildOptions, getEsbuildAliases } from './utils'; /** * Create objects containing ESbuild options for the two bundles which need to @@ -41,7 +41,7 @@ export async function getInternalClientBundles(opts: BuildOptions): Promise { * as side-effect-free, which allows imports from them to be properly * tree-shaken. */ -const externalNodeModules = [ +export const externalNodeModules = [ '@jest/core', '@jest/reporters', '@microsoft/typescript-etw', @@ -55,39 +55,6 @@ const externalNodeModules = [ 'yargs', ]; -/** - * Get a manifest of modules which should be marked as external for a given - * esbuild bundle - * - * @param opts options for the current build - * @param ownEntryPoint the entry point alias of the current module - * @returns a list of modules which should be marked as external - */ -export function getEsbuildExternalModules(opts: BuildOptions, ownEntryPoint: string): string[] { - const root = path.resolve(__dirname, '..', '..', '..'); - const bundles = Object.values(opts.output) - /** - * Filter out the `internal`, `cli`, and `compiler` directories, as they we intend to import - * these primitives directly from these packages. - */ - .filter((bundle) => !bundle.endsWith('internal') && !bundle.endsWith('cli') && !bundle.endsWith('compiler') && !bundle.endsWith('screenshot') && !bundle.endsWith('mock-doc')) - .filter((outdir) => outdir !== ownEntryPoint) - /** - * transform the absolute path to a relative one - */ - .map((p) => [ - '..' + path.sep + 'src' + path.sep + path.relative(root, path.join(p, '*')), - '.' + path.sep + 'src' + path.sep + path.relative(root, path.join(p, '*')), - ]) - .flat() - /** - * replace path separators with forward slashes - */ - .map((p) => p.replaceAll(path.sep, '/')); - - return [...externalNodeModules, ...bundles]; -} - /** * A helper which runs an array of esbuild, uh, _builds_ *