Skip to content

Commit

Permalink
chore: use types from rolldown
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 26, 2024
1 parent 53d03ed commit ff51646
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 61 deletions.
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/environment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import { describe, expect, onTestFinished, test } from 'vitest'
import type { RollupOutput } from 'rollup'
import type { RolldownOutput } from 'rolldown'
import { createServer } from '../server'
import type { InlineConfig } from '../config'
import { createBuilder } from '../build'
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('custom environment conditions', () => {
const results: Record<string, unknown> = {}
for (const key of ['ssr', 'worker', 'custom1', 'custom1_2']) {
const output = await builder.build(builder.environments[key])
const chunk = (output as RollupOutput).output[0]
const chunk = (output as RolldownOutput).output[0]
const mod = await import(
path.join(
import.meta.dirname,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/plugins/terser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, test } from 'vitest'
import { build } from 'vite'
import type { RollupOutput } from 'rollup'
import type { RolldownOutput } from 'rolldown'
import type { TerserOptions } from '../../plugins/terser'

const __dirname = resolve(fileURLToPath(import.meta.url), '..')
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('terser', () => {
},
},
],
})) as RollupOutput
})) as RolldownOutput
return result.output[0].code
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { parseAst } from 'rollup/parseAst'
import type { StaticImport } from 'mlly'
import { ESM_STATIC_IMPORT_RE, parseStaticImport } from 'mlly'
import { makeLegalIdentifier } from '@rollup/pluginutils'
import type { PartialResolvedId, RollupError } from 'rollup'
import type { PartialResolvedId, RollupError } from 'rolldown'
import type { Identifier, Literal } from 'estree'
import {
CLIENT_DIR,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/oxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type {
} from 'rolldown/experimental'
import { transform } from 'rolldown/experimental'
import type { RawSourceMap } from '@ampproject/remapping'
import { type InternalModuleFormat, type SourceMap, rolldown } from 'rolldown'
import type { InternalModuleFormat, RollupError, SourceMap } from 'rolldown'
import { rolldown } from 'rolldown'
import type { FSWatcher } from 'dep-types/chokidar'
import { TSConfckParseError } from 'tsconfck'
import type { RollupError } from 'rollup'
import {
combineSourcemaps,
createFilter,
Expand Down
106 changes: 53 additions & 53 deletions packages/vite/src/node/plugins/splitVendorChunk.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type {
GetManualChunk,
GetModuleInfo,
// ManualChunkMeta,
// OutputOptions,
} from 'rollup'
import { /* arraify, */ isInNodeModules } from '../utils'
import type {} from // GetManualChunk,
// GetModuleInfo,
// ManualChunkMeta,
// OutputOptions,
'rolldown'
// import { arraify, isInNodeModules } from '../utils'
// import type { UserConfig } from '../../node'
import type { Plugin } from '../plugin'

Expand Down Expand Up @@ -43,55 +42,56 @@ export class SplitVendorChunkCache {
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
*/
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'
}
}
_options: { cache?: SplitVendorChunkCache } = {},
): () => null /* : GetManualChunk */ {
// const cache = options.cache ?? new SplitVendorChunkCache()
// return (id, { getModuleInfo }) => {
// if (
// isInNodeModules(id) &&
// !isCSSRequest(id) &&
// staticImportedByEntry(id, getModuleInfo, cache.cache)
// ) {
// return 'vendor'
// }
// }
return () => null
}

function staticImportedByEntry(
id: string,
getModuleInfo: GetModuleInfo,
cache: Map<string, boolean>,
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<string, boolean>,
// 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
// }

/**
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/types/alias.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import type { PluginHooks } from 'rollup'
import type { PluginHooks } from 'rolldown'

export interface Alias {
find: string | RegExp
Expand Down

0 comments on commit ff51646

Please sign in to comment.