1
- /* eslint-disable n/no-extraneous-import */
2
1
import path from 'node:path'
3
2
import crypto from 'node:crypto'
4
3
import { createRequire } from 'node:module'
@@ -10,16 +9,8 @@ import type {
10
9
HtmlTagDescriptor ,
11
10
Plugin ,
12
11
ResolvedConfig ,
12
+ Rollup ,
13
13
} from 'vite'
14
- import type {
15
- NormalizedOutputOptions ,
16
- OutputAsset ,
17
- OutputBundle ,
18
- OutputChunk ,
19
- OutputOptions ,
20
- PreRenderedChunk ,
21
- RenderedChunk ,
22
- } from 'rollup'
23
14
import type {
24
15
PluginItem as BabelPlugin ,
25
16
types as BabelTypes ,
@@ -174,7 +165,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
174
165
// When discovering polyfills in `renderChunk`, the hook may be non-deterministic, so we group the
175
166
// modern and legacy polyfills in a sorted chunks map for each rendered outputs before merging them.
176
167
const outputToChunkFileNameToPolyfills = new WeakMap <
177
- NormalizedOutputOptions ,
168
+ Rollup . NormalizedOutputOptions ,
178
169
Map < string , { modern : Set < string > ; legacy : Set < string > } > | null
179
170
> ( )
180
171
@@ -405,10 +396,10 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
405
396
const getLegacyOutputFileName = (
406
397
fileNames :
407
398
| string
408
- | ( ( chunkInfo : PreRenderedChunk ) => string )
399
+ | ( ( chunkInfo : Rollup . PreRenderedChunk ) => string )
409
400
| undefined ,
410
401
defaultFileName = '[name]-legacy-[hash].js' ,
411
- ) : string | ( ( chunkInfo : PreRenderedChunk ) => string ) => {
402
+ ) : string | ( ( chunkInfo : Rollup . PreRenderedChunk ) => string ) => {
412
403
if ( ! fileNames ) {
413
404
return path . posix . join ( config . build . assetsDir , defaultFileName )
414
405
}
@@ -437,8 +428,8 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
437
428
}
438
429
439
430
const createLegacyOutput = (
440
- options : OutputOptions = { } ,
441
- ) : OutputOptions => {
431
+ options : Rollup . OutputOptions = { } ,
432
+ ) : Rollup . OutputOptions => {
442
433
return {
443
434
...options ,
444
435
format : 'system' ,
@@ -798,11 +789,11 @@ function createBabelPresetEnvOptions(
798
789
async function buildPolyfillChunk (
799
790
mode : string ,
800
791
imports : Set < string > ,
801
- bundle : OutputBundle ,
792
+ bundle : Rollup . OutputBundle ,
802
793
facadeToChunkMap : Map < string , string > ,
803
794
buildOptions : BuildOptions ,
804
795
format : 'iife' | 'es' ,
805
- rollupOutputOptions : NormalizedOutputOptions ,
796
+ rollupOutputOptions : Rollup . NormalizedOutputOptions ,
806
797
excludeSystemJS ?: boolean ,
807
798
prependModenChunkLegacyGuard ?: boolean ,
808
799
) {
@@ -852,7 +843,7 @@ async function buildPolyfillChunk(
852
843
if ( ! ( 'output' in _polyfillChunk ) ) return
853
844
const polyfillChunk = _polyfillChunk . output . find (
854
845
( chunk ) => chunk . type === 'chunk' && chunk . isEntry ,
855
- ) as OutputChunk
846
+ ) as Rollup . OutputChunk
856
847
857
848
// associate the polyfill chunk to every entry chunk so that we can retrieve
858
849
// the polyfill filename in index html transform
@@ -870,7 +861,7 @@ async function buildPolyfillChunk(
870
861
( chunk ) =>
871
862
chunk . type === 'asset' &&
872
863
chunk . fileName === polyfillChunk . sourcemapFileName ,
873
- ) as OutputAsset | undefined
864
+ ) as Rollup . OutputAsset | undefined
874
865
if ( polyfillChunkMapAsset ) {
875
866
bundle [ polyfillChunk . sourcemapFileName ] = polyfillChunkMapAsset
876
867
}
@@ -923,13 +914,16 @@ function prependModenChunkLegacyGuardPlugin(): Plugin {
923
914
}
924
915
}
925
916
926
- function isLegacyChunk ( chunk : RenderedChunk , options : NormalizedOutputOptions ) {
917
+ function isLegacyChunk (
918
+ chunk : Rollup . RenderedChunk ,
919
+ options : Rollup . NormalizedOutputOptions ,
920
+ ) {
927
921
return options . format === 'system' && chunk . fileName . includes ( '-legacy' )
928
922
}
929
923
930
924
function isLegacyBundle (
931
- bundle : OutputBundle ,
932
- options : NormalizedOutputOptions ,
925
+ bundle : Rollup . OutputBundle ,
926
+ options : Rollup . NormalizedOutputOptions ,
933
927
) {
934
928
if ( options . format === 'system' ) {
935
929
const entryChunk = Object . values ( bundle ) . find (
0 commit comments