1- import type { Rollup } from 'vite' ;
2-
31import type {
42 Diagnostic ,
53 EntryStrategy ,
@@ -18,6 +16,9 @@ import {
1816 type QwikPlugin ,
1917 type QwikPluginOptions ,
2018} from './plugin' ;
19+ import type { OutputOptions , Plugin , PreRenderedChunk , RollupError } from 'rollup' ;
20+ import { version as rollupVersion } from 'rollup/package.json' ;
21+ import semver from 'semver' ;
2122
2223type QwikRollupPluginApi = {
2324 getOptimizer : ( ) => Optimizer ;
@@ -129,10 +130,10 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
129130
130131export function normalizeRollupOutputOptions (
131132 qwikPlugin : QwikPlugin ,
132- rollupOutputOpts : Rollup . OutputOptions | Rollup . OutputOptions [ ] | undefined ,
133+ rollupOutputOpts : OutputOptions | OutputOptions [ ] | undefined ,
133134 useAssetsDir : boolean ,
134135 outDir ?: string
135- ) : Rollup . OutputOptions | Rollup . OutputOptions [ ] {
136+ ) : OutputOptions | OutputOptions [ ] {
136137 if ( Array . isArray ( rollupOutputOpts ) ) {
137138 // make sure at least one output is present in every case
138139 if ( ! rollupOutputOpts . length ) {
@@ -153,10 +154,10 @@ export function normalizeRollupOutputOptions(
153154
154155export function normalizeRollupOutputOptionsObject (
155156 qwikPlugin : QwikPlugin ,
156- rollupOutputOptsObj : Rollup . OutputOptions | undefined ,
157+ rollupOutputOptsObj : OutputOptions | undefined ,
157158 useAssetsDir : boolean
158- ) : Rollup . OutputOptions {
159- const outputOpts : Rollup . OutputOptions = { ...rollupOutputOptsObj } ;
159+ ) : OutputOptions {
160+ const outputOpts : OutputOptions = { ...rollupOutputOptsObj } ;
160161 const opts = qwikPlugin . getOptions ( ) ;
161162 const optimizer = qwikPlugin . getOptimizer ( ) ;
162163 const manualChunks = qwikPlugin . manualChunks ;
@@ -170,7 +171,7 @@ export function normalizeRollupOutputOptionsObject(
170171 : assetFileNames ;
171172 }
172173
173- let fileName : string | ( ( chunkInfo : Rollup . PreRenderedChunk ) => string ) | undefined ;
174+ let fileName : string | ( ( chunkInfo : PreRenderedChunk ) => string ) | undefined ;
174175 if ( opts . buildMode === 'production' && ! opts . debug ) {
175176 fileName = 'build/q-[hash].js' ;
176177 } else {
@@ -199,15 +200,14 @@ export function normalizeRollupOutputOptionsObject(
199200 } ;
200201 }
201202 // client development/debug output
202- const getFilePath = ( fileNamePattern : string | ( ( info : Rollup . PreRenderedChunk ) => string ) ) =>
203+ const getFilePath = ( fileNamePattern : string | ( ( info : PreRenderedChunk ) => string ) ) =>
203204 typeof fileNamePattern === 'string'
204205 ? useAssetsDir
205206 ? `${ opts . assetsDir } /${ fileNamePattern } `
206207 : fileNamePattern
207208 : useAssetsDir
208- ? ( chunkInfo : Rollup . PreRenderedChunk ) =>
209- `${ opts . assetsDir } /${ fileNamePattern ( chunkInfo ) } `
210- : ( chunkInfo : Rollup . PreRenderedChunk ) => fileNamePattern ( chunkInfo ) ;
209+ ? ( chunkInfo : PreRenderedChunk ) => `${ opts . assetsDir } /${ fileNamePattern ( chunkInfo ) } `
210+ : ( chunkInfo : PreRenderedChunk ) => fileNamePattern ( chunkInfo ) ;
211211
212212 if ( ! outputOpts . entryFileNames ) {
213213 outputOpts . entryFileNames = getFilePath ( fileName ) ;
@@ -253,12 +253,20 @@ export function normalizeRollupOutputOptionsObject(
253253 */
254254 outputOpts . hoistTransitiveImports = false ;
255255
256+ if ( 'onlyExplicitManualChunks' in outputOpts ) {
257+ outputOpts . onlyExplicitManualChunks = true ;
258+ } else {
259+ console . warn (
260+ `⚠️ Outdated rollup version detected. For the latest and greatest, we recommend to update to rollup@^4.52.0. This can improve preloading performance and reduce cache invalidation for a snappier user experience.`
261+ ) ;
262+ }
263+
256264 return outputOpts ;
257265}
258266
259267export function createRollupError ( id : string , diagnostic : Diagnostic ) {
260268 const loc = diagnostic . highlights [ 0 ] ?? { } ;
261- const err : Rollup . RollupError = Object . assign ( new Error ( diagnostic . message ) , {
269+ const err : RollupError = Object . assign ( new Error ( diagnostic . message ) , {
262270 id,
263271 plugin : 'qwik' ,
264272 loc : {
@@ -352,5 +360,5 @@ export interface QwikRollupPluginOptions {
352360 experimental ?: ( keyof typeof ExperimentalFeatures ) [ ] ;
353361}
354362export { ExperimentalFeatures } from './plugin' ;
355- type P < T > = Rollup . Plugin < T > & { api : T } ;
363+ type P < T > = Plugin < T > & { api : T } ;
356364export interface QwikRollupPlugin extends P < QwikRollupPluginApi > { }
0 commit comments