From 5c75ae3f4821bb2fda17f7edef693f7578c47e69 Mon Sep 17 00:00:00 2001 From: underfin Date: Thu, 20 Jun 2024 16:24:39 +0800 Subject: [PATCH] fix: fix more typing --- .../vite/src/node/__tests__/build.spec.ts | 2 +- packages/vite/src/node/build.ts | 10 +- packages/vite/src/node/config.ts | 42 ++-- packages/vite/src/node/packages.ts | 14 +- packages/vite/src/node/plugin.ts | 1 - packages/vite/src/node/plugins/asset.ts | 4 +- .../src/node/plugins/completeSystemWrap.ts | 16 +- packages/vite/src/node/plugins/css.ts | 14 +- packages/vite/src/node/plugins/esbuild.ts | 24 +- packages/vite/src/node/plugins/reporter.ts | 124 +++++----- .../vite/src/node/plugins/splitVendorChunk.ts | 226 +++++++++--------- packages/vite/src/node/plugins/worker.ts | 36 +-- .../src/node/plugins/workerImportMetaUrl.ts | 10 +- packages/vite/src/node/publicUtils.ts | 4 +- packages/vite/src/node/server/index.ts | 2 +- .../vite/src/node/server/pluginContainer.ts | 26 +- packages/vite/src/node/server/send.ts | 4 +- packages/vite/src/node/server/sourcemap.ts | 8 +- .../vite/src/node/server/transformRequest.ts | 2 +- packages/vite/src/node/ssr/ssrTransform.ts | 4 +- packages/vite/src/node/utils.ts | 2 +- 21 files changed, 287 insertions(+), 288 deletions(-) diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 1b632a8b20fdcf..8a3e99f8fe50a2 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -2,7 +2,7 @@ import { resolve } from 'node:path' import { fileURLToPath } from 'node:url' import colors from 'picocolors' import { describe, expect, test, vi } from 'vitest' -import type { OutputChunk, OutputOptions, RollupOutput } from 'rollup' +import type { OutputChunk, OutputOptions, RollupOutput } from '@rolldown/node' import type { LibraryFormats, LibraryOptions } from '../build' import { build, resolveBuildOutputs, resolveLibFilename } from '../build' import type { Logger } from '../logger' diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 19c03ec0de8b44..c5e840667cc63d 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -45,7 +45,7 @@ import { loadFallbackPlugin } from './plugins/loadFallback' import { findNearestPackageData } from './packages' import type { PackageCache } from './packages' import { ESBUILD_MODULES_TARGET, VERSION } from './constants' -import { resolveChokidarOptions } from './watch' +// import { resolveChokidarOptions } from './watch' import { completeSystemWrapPlugin } from './plugins/completeSystemWrap' import { mergeConfig } from './publicUtils' import { webWorkerPostPlugin } from './plugins/worker' @@ -417,10 +417,10 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{ post: Plugin[] }> { const options = config.build - const { commonjsOptions } = options - const usePluginCommonjs = - !Array.isArray(commonjsOptions?.include) || - commonjsOptions?.include.length !== 0 + // const { commonjsOptions } = options + // const usePluginCommonjs = + // !Array.isArray(commonjsOptions?.include) || + // commonjsOptions?.include.length !== 0 const rollupOptionsPlugins = options.rollupOptions.plugins return { pre: [ diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 1cd153b97d9538..9a864879ca818b 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -9,7 +9,7 @@ import colors from 'picocolors' import type { Alias, AliasOptions } from 'dep-types/alias' import aliasPlugin from '@rollup/plugin-alias' import { build } from 'esbuild' -import type { RollupOptions } from 'rollup' +import type { RollupOptions } from '@rolldown/node' import type { HookHandler, Plugin, PluginWithRequiredHook } from './plugin' import type { BuildOptions, @@ -831,26 +831,26 @@ export async function resolveConfig( // Check if all assetFileNames have the same reference. // If not, display a warn for user. - const outputOption = config.build?.rollupOptions?.output ?? [] - // Use isArray to narrow its type to array - if (Array.isArray(outputOption)) { - const assetFileNamesList = outputOption.map( - (output) => output.assetFileNames, - ) - if (assetFileNamesList.length > 1) { - const firstAssetFileNames = assetFileNamesList[0] - const hasDifferentReference = assetFileNamesList.some( - (assetFileNames) => assetFileNames !== firstAssetFileNames, - ) - if (hasDifferentReference) { - resolved.logger.warn( - colors.yellow(` -assetFileNames isn't equal for every build.rollupOptions.output. A single pattern across all outputs is supported by Vite. -`), - ) - } - } - } +// const outputOption = config.build?.rollupOptions?.output ?? [] +// // Use isArray to narrow its type to array +// if (Array.isArray(outputOption)) { +// const assetFileNamesList = outputOption.map( +// (output) => output.assetFileNames, +// ) +// if (assetFileNamesList.length > 1) { +// const firstAssetFileNames = assetFileNamesList[0] +// const hasDifferentReference = assetFileNamesList.some( +// (assetFileNames) => assetFileNames !== firstAssetFileNames, +// ) +// if (hasDifferentReference) { +// resolved.logger.warn( +// colors.yellow(` +// assetFileNames isn't equal for every build.rollupOptions.output. A single pattern across all outputs is supported by Vite. +// `), +// ) +// } +// } +// } // Warn about removal of experimental features if ( diff --git a/packages/vite/src/node/packages.ts b/packages/vite/src/node/packages.ts index 9b35ecc3b82e9c..941341b2b4653e 100644 --- a/packages/vite/src/node/packages.ts +++ b/packages/vite/src/node/packages.ts @@ -241,18 +241,18 @@ export function watchPackageDataPlugin(packageCache: PackageCache): Plugin { return { name: 'vite:watch-package-data', buildStart() { - watchFile = this.addWatchFile.bind(this) - watchQueue.forEach(watchFile) + // watchFile = this.addWatchFile.bind(this) + // watchQueue.forEach(watchFile) watchQueue.clear() }, buildEnd() { watchFile = watchFileStub }, - watchChange(id) { - if (id.endsWith('/package.json')) { - invalidatePackageData(packageCache, path.normalize(id)) - } - }, + // watchChange(id) { + // if (id.endsWith('/package.json')) { + // invalidatePackageData(packageCache, path.normalize(id)) + // } + // }, handleHotUpdate({ file }) { if (file.endsWith('/package.json')) { invalidatePackageData(packageCache, path.normalize(file)) diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index b04621189250d3..bc653c9659ca35 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -8,7 +8,6 @@ import type { TransformPluginContext, TransformResult, } from '@rolldown/node' -export type { PluginContext } from 'rollup' import type { ConfigEnv, ResolvedConfig, UserConfig } from './config' import type { ServerHook } from './server' import type { IndexHtmlTransform } from './plugins/html' diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 3a850407569aff..4603af6729a9a5 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -8,7 +8,7 @@ import type { NormalizedOutputOptions, PluginContext, RenderedChunk, -} from 'rollup' +} from '@rolldown/node' import MagicString from 'magic-string' import colors from 'picocolors' import { @@ -188,7 +188,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { // raw requests, read from disk if (rawRE.test(id)) { const file = checkPublicFile(id, config) || cleanUrl(id) - this.addWatchFile(file) + // this.addWatchFile(file) // raw query, read file and return as string return `export default ${JSON.stringify( await fsp.readFile(file, 'utf-8'), diff --git a/packages/vite/src/node/plugins/completeSystemWrap.ts b/packages/vite/src/node/plugins/completeSystemWrap.ts index 700a4202c0a4e4..b3ec8d5c4e9341 100644 --- a/packages/vite/src/node/plugins/completeSystemWrap.ts +++ b/packages/vite/src/node/plugins/completeSystemWrap.ts @@ -10,14 +10,14 @@ export function completeSystemWrapPlugin(): Plugin { name: 'vite:force-systemjs-wrap-complete', renderChunk(code, chunk, opts) { - if (opts.format === 'system') { - return { - code: code.replace(SystemJSWrapRE, (s, s1) => - s.replace(s1, '(exports, module)'), - ), - map: null, - } - } + // if (opts.format === 'system') { + // return { + // code: code.replace(SystemJSWrapRE, (s, s1) => + // s.replace(s1, '(exports, module)'), + // ), + // map: null, + // } + // } }, } } diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index cb8dbbdae2188f..dce6264b514fb3 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -11,7 +11,7 @@ import type { RenderedChunk, RollupError, SourceMapInput, -} from 'rollup' +} from '@rolldown/node' import { dataToEsm } from '@rollup/pluginutils' import colors from 'picocolors' import MagicString from 'magic-string' @@ -26,7 +26,7 @@ import { formatMessages, transform } from 'esbuild' import type { RawSourceMap } from '@ampproject/remapping' import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap' import type { ModuleNode } from '../server/moduleGraph' -import type { ResolveFn, ViteDevServer } from '../' +import type { ResolveFn, ViteDevServer } from '..' import { resolveUserExternal, toOutputFilePathInCss } from '../build' import { CLIENT_PUBLIC_PATH, @@ -304,11 +304,11 @@ export function cssPlugin(config: ResolvedConfig): Plugin { } // track deps for build watch mode - if (config.command === 'build' && config.build.watch && deps) { - for (const file of deps) { - this.addWatchFile(file) - } - } + // if (config.command === 'build' && config.build.watch && deps) { + // for (const file of deps) { + // this.addWatchFile(file) + // } + // } // dev if (server) { diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 0e1554f89ac553..1e7e22ded56082 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -318,18 +318,18 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => { // We don't need to create a MagicString here because both the helpers and // the headers don't modify the sourcemap const esbuildCode = res.code - const contentIndex = - opts.format === 'iife' - ? esbuildCode.match(IIFE_BEGIN_RE)?.index || 0 - : opts.format === 'umd' - ? esbuildCode.indexOf(`(function(`) // same for minified or not - : 0 - if (contentIndex > 0) { - const esbuildHelpers = esbuildCode.slice(0, contentIndex) - res.code = esbuildCode - .slice(contentIndex) - .replace(`"use strict";`, `"use strict";` + esbuildHelpers) - } + // const contentIndex = + // opts.format === 'iife' + // ? esbuildCode.match(IIFE_BEGIN_RE)?.index || 0 + // : opts.format === 'umd' + // ? esbuildCode.indexOf(`(function(`) // same for minified or not + // : 0 + // if (contentIndex > 0) { + // const esbuildHelpers = esbuildCode.slice(0, contentIndex) + // res.code = esbuildCode + // .slice(contentIndex) + // .replace(`"use strict";`, `"use strict";` + esbuildHelpers) + // } } return res diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index 97f71590edb2af..52b574f9404f6f 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -2,11 +2,11 @@ import path from 'node:path' import { gzip } from 'node:zlib' import { promisify } from 'node:util' import colors from 'picocolors' -import type { Plugin } from 'rollup' +import type { Plugin } from '@rolldown/node' import type { ResolvedConfig } from '../config' import { isDefined, - isInNodeModules, + // isInNodeModules, normalizePath, withTrailingSlash, } from '../utils' @@ -47,7 +47,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { let transformedCount = 0 let chunkCount = 0 let compressedCount = 0 - let startTime = Date.now() + // let startTime = Date.now() async function getCompressedSize( code: string | Uint8Array, @@ -101,7 +101,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { }, options() { - startTime = Date.now() + // startTime = Date.now() }, buildStart() { @@ -124,50 +124,50 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { compressedCount = 0 }, - renderChunk(code, chunk, options) { - if (!options.inlineDynamicImports) { - for (const id of chunk.moduleIds) { - const module = this.getModuleInfo(id) - if (!module) continue - // When a dynamic importer shares a chunk with the imported module, - // warn that the dynamic imported module will not be moved to another chunk (#12850). - if (module.importers.length && module.dynamicImporters.length) { - // Filter out the intersection of dynamic importers and sibling modules in - // the same chunk. The intersecting dynamic importers' dynamic import is not - // expected to work. Note we're only detecting the direct ineffective - // dynamic import here. - const detectedIneffectiveDynamicImport = - module.dynamicImporters.some( - (id) => !isInNodeModules(id) && chunk.moduleIds.includes(id), - ) - if (detectedIneffectiveDynamicImport) { - this.warn( - `\n(!) ${ - module.id - } is dynamically imported by ${module.dynamicImporters.join( - ', ', - )} but also statically imported by ${module.importers.join( - ', ', - )}, dynamic import will not move module into another chunk.\n`, - ) - } - } - } - } + // renderChunk(code, chunk, options) { + // if (!options.inlineDynamicImports) { + // for (const id of chunk.moduleIds) { + // const module = this.getModuleInfo(id) + // if (!module) continue + // // When a dynamic importer shares a chunk with the imported module, + // // warn that the dynamic imported module will not be moved to another chunk (#12850). + // if (module.importers.length && module.dynamicImporters.length) { + // // Filter out the intersection of dynamic importers and sibling modules in + // // the same chunk. The intersecting dynamic importers' dynamic import is not + // // expected to work. Note we're only detecting the direct ineffective + // // dynamic import here. + // const detectedIneffectiveDynamicImport = + // module.dynamicImporters.some( + // (id) => !isInNodeModules(id) && chunk.moduleIds.includes(id), + // ) + // if (detectedIneffectiveDynamicImport) { + // this.warn( + // `\n(!) ${ + // module.id + // } is dynamically imported by ${module.dynamicImporters.join( + // ', ', + // )} but also statically imported by ${module.importers.join( + // ', ', + // )}, dynamic import will not move module into another chunk.\n`, + // ) + // } + // } + // } + // } - chunkCount++ - if (shouldLogInfo) { - if (!tty) { - if (!hasRenderedChunk) { - config.logger.info('rendering chunks...') - } - } else { - writeLine(`rendering chunks (${chunkCount})...`) - } - hasRenderedChunk = true - } - return null - }, + // chunkCount++ + // if (shouldLogInfo) { + // if (!tty) { + // if (!hasRenderedChunk) { + // config.logger.info('rendering chunks...') + // } + // } else { + // writeLine(`rendering chunks (${chunkCount})...`) + // } + // hasRenderedChunk = true + // } + // return null + // }, generateBundle() { if (shouldLogInfo && tty) clearLine() @@ -337,22 +337,22 @@ function throttle(fn: Function) { } } -function displayTime(time: number) { - // display: {X}ms - if (time < 1000) { - return `${time}ms` - } +// function displayTime(time: number) { +// // display: {X}ms +// if (time < 1000) { +// return `${time}ms` +// } - time = time / 1000 +// time = time / 1000 - // display: {X}s - if (time < 60) { - return `${time.toFixed(2)}s` - } +// // display: {X}s +// if (time < 60) { +// return `${time.toFixed(2)}s` +// } - const mins = parseInt((time / 60).toString()) - const seconds = time % 60 +// const mins = parseInt((time / 60).toString()) +// const seconds = time % 60 - // display: {X}m {Y}s - return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}` -} +// // display: {X}m {Y}s +// return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}` +// } diff --git a/packages/vite/src/node/plugins/splitVendorChunk.ts b/packages/vite/src/node/plugins/splitVendorChunk.ts index 034b8c2ee5231e..d9d47f6333b82f 100644 --- a/packages/vite/src/node/plugins/splitVendorChunk.ts +++ b/packages/vite/src/node/plugins/splitVendorChunk.ts @@ -1,12 +1,12 @@ -import type { - GetManualChunk, - GetModuleInfo, - ManualChunkMeta, - OutputOptions, -} from 'rollup' -import { isInNodeModules } from '../utils' -import type { UserConfig } from '../../node' -import type { Plugin } from '../plugin' +// import type { +// // GetManualChunk, +// // GetModuleInfo, +// // ManualChunkMeta, +// OutputOptions, +// } from '@rolldown/node' +// import { isInNodeModules } from '../utils' +// import type { UserConfig } from '../../node' +// import type { Plugin } from '../plugin' // This file will be built for both ESM and CJS. Avoid relying on other modules as possible. @@ -36,110 +36,110 @@ export class SplitVendorChunkCache { } } -export function splitVendorChunk( - options: { cache?: SplitVendorChunkCache } = {}, -): GetManualChunk { - const cache = options.cache ?? new SplitVendorChunkCache() - return (id, { getModuleInfo }) => { - if ( - isInNodeModules(id) && - !isCSSRequest(id) && - staticImportedByEntry(id, getModuleInfo, cache.cache) - ) { - return 'vendor' - } - } -} +// export function splitVendorChunk( +// options: { cache?: SplitVendorChunkCache } = {}, +// ): GetManualChunk { +// const cache = options.cache ?? new SplitVendorChunkCache() +// return (id, { getModuleInfo }) => { +// if ( +// isInNodeModules(id) && +// !isCSSRequest(id) && +// staticImportedByEntry(id, getModuleInfo, cache.cache) +// ) { +// return 'vendor' +// } +// } +// } -function staticImportedByEntry( - id: string, - getModuleInfo: GetModuleInfo, - cache: Map, - importStack: string[] = [], -): boolean { - if (cache.has(id)) { - return cache.get(id) as boolean - } - if (importStack.includes(id)) { - // circular deps! - cache.set(id, false) - return false - } - const mod = getModuleInfo(id) - if (!mod) { - cache.set(id, false) - return false - } +// function staticImportedByEntry( +// id: string, +// getModuleInfo: GetModuleInfo, +// cache: Map, +// importStack: string[] = [], +// ): boolean { +// if (cache.has(id)) { +// return cache.get(id) as boolean +// } +// if (importStack.includes(id)) { +// // circular deps! +// cache.set(id, false) +// return false +// } +// const mod = getModuleInfo(id) +// if (!mod) { +// cache.set(id, false) +// return false +// } - if (mod.isEntry) { - cache.set(id, true) - return true - } - const someImporterIs = mod.importers.some((importer) => - staticImportedByEntry( - importer, - getModuleInfo, - cache, - importStack.concat(id), - ), - ) - cache.set(id, someImporterIs) - return someImporterIs -} +// if (mod.isEntry) { +// cache.set(id, true) +// return true +// } +// const someImporterIs = mod.importers.some((importer) => +// staticImportedByEntry( +// importer, +// getModuleInfo, +// cache, +// importStack.concat(id), +// ), +// ) +// cache.set(id, someImporterIs) +// return someImporterIs +// } -export function splitVendorChunkPlugin(): Plugin { - const caches: SplitVendorChunkCache[] = [] - function createSplitVendorChunk(output: OutputOptions, config: UserConfig) { - const cache = new SplitVendorChunkCache() - caches.push(cache) - const build = config.build ?? {} - const format = output?.format - if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') { - return splitVendorChunk({ cache }) - } - } - return { - name: 'vite:split-vendor-chunk', - config(config) { - let outputs = config?.build?.rollupOptions?.output - if (outputs) { - outputs = Array.isArray(outputs) ? outputs : [outputs] - for (const output of outputs) { - const viteManualChunks = createSplitVendorChunk(output, config) - if (viteManualChunks) { - if (output.manualChunks) { - if (typeof output.manualChunks === 'function') { - const userManualChunks = output.manualChunks - output.manualChunks = (id: string, api: ManualChunkMeta) => { - return userManualChunks(id, api) ?? viteManualChunks(id, api) - } - } else { - // else, leave the object form of manualChunks untouched, as - // we can't safely replicate rollup handling. - // eslint-disable-next-line no-console - console.warn( - "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead.", - ) - } - } else { - output.manualChunks = viteManualChunks - } - } - } - } else { - return { - build: { - rollupOptions: { - output: { - manualChunks: createSplitVendorChunk({}, config), - }, - }, - }, - } - } - }, - buildStart() { - caches.forEach((cache) => cache.reset()) - }, - } -} +// export function splitVendorChunkPlugin(): Plugin { +// const caches: SplitVendorChunkCache[] = [] +// function createSplitVendorChunk(output: OutputOptions, config: UserConfig) { +// const cache = new SplitVendorChunkCache() +// caches.push(cache) +// const build = config.build ?? {} +// const format = output?.format +// if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') { +// return splitVendorChunk({ cache }) +// } +// } +// return { +// name: 'vite:split-vendor-chunk', +// config(config) { +// let outputs = config?.build?.rollupOptions?.output +// if (outputs) { +// outputs = Array.isArray(outputs) ? outputs : [outputs] +// for (const output of outputs) { +// const viteManualChunks = createSplitVendorChunk(output, config) +// if (viteManualChunks) { +// if (output.manualChunks) { +// if (typeof output.manualChunks === 'function') { +// const userManualChunks = output.manualChunks +// output.manualChunks = (id: string, api: ManualChunkMeta) => { +// return userManualChunks(id, api) ?? viteManualChunks(id, api) +// } +// } else { +// // else, leave the object form of manualChunks untouched, as +// // we can't safely replicate rollup handling. +// // eslint-disable-next-line no-console +// console.warn( +// "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead.", +// ) +// } +// } else { +// output.manualChunks = viteManualChunks +// } +// } +// } +// } else { +// return { +// build: { +// rollupOptions: { +// output: { +// manualChunks: createSplitVendorChunk({}, config), +// }, +// }, +// }, +// } +// } +// }, +// buildStart() { +// caches.forEach((cache) => cache.reset()) +// }, +// } +// } diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index 0df6f9d843e99c..f2624460191a23 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -1,6 +1,6 @@ import path from 'node:path' import MagicString from 'magic-string' -import type { EmittedAsset, OutputChunk } from 'rollup' +import type { EmittedAsset, OutputChunk } from '@rolldown/node' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' import type { ViteDevServer } from '../server' @@ -47,16 +47,16 @@ async function bundleWorkerEntry( query: Record | null, ): Promise { // bundle the file as entry to support imports - const { rollup } = await import('rollup') + const { rolldown } = await import('@rolldown/node') const { plugins, rollupOptions, format } = config.worker - const bundle = await rollup({ + const bundle = await rolldown({ ...rollupOptions, input: cleanUrl(id), plugins: await plugins(), onwarn(warning, warn) { onRollupWarning(warning, warn, config) }, - preserveEntrySignatures: false, + // preserveEntrySignatures: false, }) let chunk: OutputChunk try { @@ -98,7 +98,7 @@ async function bundleWorkerEntry( } }) } finally { - await bundle.close() + // await bundle.close() } return emitSourcemapForWorkerEntry(config, query, chunk) } @@ -165,14 +165,14 @@ export async function workerFileToUrl( export function webWorkerPostPlugin(): Plugin { return { name: 'vite:worker-post', - resolveImportMeta(property, { chunkId, format }) { - // document is undefined in the worker, so we need to avoid it in iife - if (property === 'url' && format === 'iife') { - return 'self.location.href' - } - - return null - }, + // resolveImportMeta(property, { chunkId, format }) { + // // document is undefined in the worker, so we need to avoid it in iife + // if (property === 'url' && format === 'iife') { + // return 'self.location.href' + // } + + // return null + // }, } } @@ -217,11 +217,11 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin { } }, - shouldTransformCachedModule({ id }) { - if (isBuild && config.build.watch && isWorkerQueryId(id)) { - return true - } - }, + // shouldTransformCachedModule({ id }) { + // if (isBuild && config.build.watch && isWorkerQueryId(id)) { + // return true + // } + // }, async transform(raw, id, options) { const ssr = options?.ssr === true diff --git a/packages/vite/src/node/plugins/workerImportMetaUrl.ts b/packages/vite/src/node/plugins/workerImportMetaUrl.ts index e88d1ac3362a43..14b91c91f236a1 100644 --- a/packages/vite/src/node/plugins/workerImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/workerImportMetaUrl.ts @@ -124,11 +124,11 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin { return { name: 'vite:worker-import-meta-url', - shouldTransformCachedModule({ code }) { - if (isBuild && config.build.watch && isIncludeWorkerImportMetaUrl(code)) { - return true - } - }, + // shouldTransformCachedModule({ code }) { + // if (isBuild && config.build.watch && isIncludeWorkerImportMetaUrl(code)) { + // return true + // } + // }, async transform(code, id, options) { const ssr = options?.ssr === true diff --git a/packages/vite/src/node/publicUtils.ts b/packages/vite/src/node/publicUtils.ts index 8a9ab56559815b..ea95abad7fa94f 100644 --- a/packages/vite/src/node/publicUtils.ts +++ b/packages/vite/src/node/publicUtils.ts @@ -7,8 +7,8 @@ export { VERSION as version } from './constants' export { version as esbuildVersion } from 'esbuild' export { VERSION as rollupVersion } from 'rollup' export { - splitVendorChunkPlugin, - splitVendorChunk, + // splitVendorChunkPlugin, + // splitVendorChunk, isCSSRequest, } from './plugins/splitVendorChunk' export { normalizePath, mergeConfig, mergeAlias, createFilter } from './utils' diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 13be3ad0d9561a..d4de4877ba297c 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -11,7 +11,7 @@ import chokidar from 'chokidar' import type { FSWatcher, WatchOptions } from 'dep-types/chokidar' import type { Connect } from 'dep-types/connect' import launchEditorMiddleware from 'launch-editor-middleware' -import type { SourceMap } from 'rollup' +import type { SourceMap } from '@rolldown/node' import picomatch from 'picomatch' import type { Matcher } from 'picomatch' import type { InvalidatePayload } from 'types/customEvent' diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index b71e4e991d168e..64bfde1b777292 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -32,7 +32,7 @@ SOFTWARE. import fs from 'node:fs' import { join } from 'node:path' import { performance } from 'node:perf_hooks' -import { VERSION as rollupVersion } from 'rollup' +// import { VERSION as rollupVersion } from 'rollup' import { parseAst as rollupParseAst } from 'rollup/parseAst' import type { AsyncPluginHooks, @@ -56,7 +56,7 @@ import type { SourceDescription, SourceMap, TransformResult, -} from 'rollup' +} from '@rolldown/node' import type { RawSourceMap } from '@ampproject/remapping' import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping' import MagicString from 'magic-string' @@ -185,7 +185,7 @@ export async function createPluginContainer( const minimalContext: MinimalPluginContext = { meta: { - rollupVersion, + // rollupVersion, watchMode: true, }, debug: noop, @@ -776,11 +776,11 @@ export async function createPluginContainer( async watchChange(id, change) { const ctx = new Context() - await hookParallel( - 'watchChange', - () => ctx, - () => [id, change], - ) + // await hookParallel( + // 'watchChange', + // () => ctx, + // () => [id, change], + // ) }, async close() { @@ -793,11 +793,11 @@ export async function createPluginContainer( () => ctx, () => [], ) - await hookParallel( - 'closeBundle', - () => ctx, - () => [], - ) + // await hookParallel( + // 'closeBundle', + // () => ctx, + // () => [], + // ) }, [ASYNC_DISPOSE]() { return this.close() diff --git a/packages/vite/src/node/server/send.ts b/packages/vite/src/node/server/send.ts index 033b9f317a60d3..8dfd4312675cbe 100644 --- a/packages/vite/src/node/server/send.ts +++ b/packages/vite/src/node/server/send.ts @@ -6,7 +6,7 @@ import type { import path from 'node:path' import convertSourceMap from 'convert-source-map' import getEtag from 'etag' -import type { SourceMap } from 'rollup' +import type { SourceMap } from '@rolldown/node' import MagicString from 'magic-string' import { createDebugger, removeTimestampQuery } from '../utils' import { getCodeWithSourcemap } from './sourcemap' @@ -86,7 +86,7 @@ export function send( source: path.basename(urlWithoutTimestamp), hires: 'boundary', includeContent: true, - }), + }) as SourceMap, ) } } diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index c8f2c8d88fdacd..8fdefefebddf65 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -1,6 +1,6 @@ import path from 'node:path' import fsp from 'node:fs/promises' -import type { ExistingRawSourceMap, SourceMap } from 'rollup' +import type { ExistingRawSourceMap, SourceMap } from '@rolldown/node' import type { Logger } from '../logger' import { createDebugger } from '../utils' @@ -96,16 +96,16 @@ export function applySourcemapIgnoreList( sourcemapIgnoreList: (sourcePath: string, sourcemapPath: string) => boolean, logger?: Logger, ): void { - let { x_google_ignoreList } = map + let { x_google_ignoreList, sources = [] } = map if (x_google_ignoreList === undefined) { x_google_ignoreList = [] } for ( let sourcesIndex = 0; - sourcesIndex < map.sources.length; + sourcesIndex < sources.length; ++sourcesIndex ) { - const sourcePath = map.sources[sourcesIndex] + const sourcePath = sources[sourcesIndex] if (!sourcePath) continue const ignoreList = sourcemapIgnoreList( diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index 1f359ebd8cbbe8..e585c66a4e8bae 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -5,7 +5,7 @@ import getEtag from 'etag' import convertSourceMap from 'convert-source-map' import MagicString from 'magic-string' import { init, parse as parseImports } from 'es-module-lexer' -import type { PartialResolvedId, SourceDescription, SourceMap } from 'rollup' +import type { PartialResolvedId, SourceDescription, SourceMap } from '@rolldown/node' import colors from 'picocolors' import type { ModuleNode, ViteDevServer } from '..' import { diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index 450890af8d0765..788906acc10d27 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -1,6 +1,6 @@ import path from 'node:path' import MagicString from 'magic-string' -import type { SourceMap } from 'rollup' +import type { SourceMap } from '@rolldown/node' import type { Function as FunctionNode, Identifier, @@ -292,7 +292,7 @@ async function ssrTransformScript( }, }) - let map = s.generateMap({ hires: 'boundary' }) + let map = s.generateMap({ hires: 'boundary' }) as SourceMap if ( inMap && inMap.mappings && diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 1e039d9beced7e..92103a33735f43 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -16,7 +16,7 @@ import debug from 'debug' import type { Alias, AliasOptions } from 'dep-types/alias' import type MagicString from 'magic-string' -import type { TransformResult } from 'rollup' +import type { TransformResult } from '@rolldown/node' import { createFilter as _createFilter } from '@rollup/pluginutils' import { CLIENT_ENTRY,