From f28216cb9b06bc61f8d5d37f06c57e9354cf3389 Mon Sep 17 00:00:00 2001 From: underfin Date: Mon, 5 Aug 2024 18:35:38 +0800 Subject: [PATCH] chore: rebase --- packages/vite/src/node/optimizer/scan.ts | 587 ++--------------------- 1 file changed, 53 insertions(+), 534 deletions(-) diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index da3b60d47b0453..37b6062a65af36 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -189,53 +189,6 @@ async function computeEntries(config: ResolvedConfig) { return entries } -// async function prepareEsbuildScanner( -// config: ResolvedConfig, -// entries: string[], -// deps: Record, -// missing: Record, -// scanContext?: { cancelled: boolean }, -// ): Promise { -// const container = await createPluginContainer(config) - -// if (scanContext?.cancelled) return - -// const plugin = esbuildScanPlugin(config, container, deps, missing, entries) - -// const { plugins = [], ...esbuildOptions } = -// config.optimizeDeps?.esbuildOptions ?? {} - -// // The plugin pipeline automatically loads the closest tsconfig.json. -// // But esbuild doesn't support reading tsconfig.json if the plugin has resolved the path (https://github.com/evanw/esbuild/issues/2265). -// // Due to syntax incompatibilities between the experimental decorators in TypeScript and TC39 decorators, -// // we cannot simply set `"experimentalDecorators": true` or `false`. (https://github.com/vitejs/vite/pull/15206#discussion_r1417414715) -// // Therefore, we use the closest tsconfig.json from the root to make it work in most cases. -// let tsconfigRaw = esbuildOptions.tsconfigRaw -// if (!tsconfigRaw && !esbuildOptions.tsconfig) { -// const tsconfigResult = await loadTsconfigJsonForFile( -// path.join(config.root, '_dummy.js'), -// ) -// if (tsconfigResult.compilerOptions?.experimentalDecorators) { -// tsconfigRaw = { compilerOptions: { experimentalDecorators: true } } -// } -// } - -// return await esbuild.context({ -// absWorkingDir: process.cwd(), -// write: false, -// stdin: { -// contents: entries.map((e) => `import ${JSON.stringify(e)}`).join('\n'), -// loader: 'js', -// }, -// bundle: true, -// format: 'esm', -// logLevel: 'silent', -// plugins: [...plugins, plugin], -// ...esbuildOptions, -// tsconfigRaw, -// }) -// } - async function prepareRolldownScanner( config: ResolvedConfig, entries: string[], @@ -318,392 +271,6 @@ const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i const langRE = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i const contextRE = /\bcontext\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i -// function esbuildScanPlugin( -// config: ResolvedConfig, -// container: PluginContainer, -// depImports: Record, -// missing: Record, -// entries: string[], -// ): Plugin { -// const seen = new Map() - -// const resolve = async ( -// id: string, -// importer?: string, -// options?: ResolveIdOptions, -// ) => { -// const key = id + (importer && path.dirname(importer)) -// if (seen.has(key)) { -// return seen.get(key) -// } -// const resolved = await container.resolveId( -// id, -// importer && normalizePath(importer), -// { -// ...options, -// scan: true, -// }, -// ) -// const res = resolved?.id -// seen.set(key, res) -// return res -// } - -// const include = config.optimizeDeps?.include -// const exclude = [ -// ...(config.optimizeDeps?.exclude || []), -// '@vite/client', -// '@vite/env', -// ] - -// const isUnlessEntry = (path: string) => !entries.includes(path) - -// const externalUnlessEntry = ({ path }: { path: string }) => ({ -// path, -// external: isUnlessEntry(path), -// }) - -// const doTransformGlobImport = async ( -// contents: string, -// id: string, -// loader: Loader, -// ) => { -// let transpiledContents -// // transpile because `transformGlobImport` only expects js -// if (loader !== 'js') { -// transpiledContents = (await transform(contents, { loader })).code -// } else { -// transpiledContents = contents -// } - -// const result = await transformGlobImport( -// transpiledContents, -// id, -// config.root, -// resolve, -// ) - -// return result?.s.toString() || transpiledContents -// } - -// return { -// name: 'vite:dep-scan', -// setup(build) { -// const scripts: Record = {} - -// // external urls -// build.onResolve({ filter: externalRE }, ({ path }) => ({ -// path, -// external: true, -// })) - -// // data urls -// build.onResolve({ filter: dataUrlRE }, ({ path }) => ({ -// path, -// external: true, -// })) - -// // local scripts (`