@@ -12,7 +12,7 @@ import { join } from 'pathe'
1212import { colors } from 'consola/utils'
1313import { tryUseNuxt , useNuxt } from '@nuxt/kit'
1414import { logger } from '../logger'
15- import { storage } from '../assets'
15+ import { bundleStorage } from '../assets'
1616import { isJS , isVue } from './util'
1717import type { RegistryScript } from '#nuxt-scripts'
1818
@@ -55,12 +55,13 @@ async function downloadScript(opts: {
5555 if ( src === url || ! filename ) {
5656 return
5757 }
58+ const storage = bundleStorage ( )
5859 const scriptContent = renderedScript . get ( src )
5960 let res : Buffer | undefined = scriptContent instanceof Error ? undefined : scriptContent ?. content
6061 if ( ! res ) {
6162 // Use storage to cache the font data between builds
62- if ( await storage . hasItem ( `data:scripts :${ filename } ` ) ) {
63- const res = await storage . getItemRaw < Buffer > ( `data:scripts :${ filename } ` )
63+ if ( await storage . hasItem ( `bundle :${ filename } ` ) ) {
64+ const res = await storage . getItemRaw < Buffer > ( `bundle :${ filename } ` )
6465 renderedScript . set ( url , {
6566 content : res ! ,
6667 size : res ! . length / 1024 ,
@@ -80,11 +81,12 @@ async function downloadScript(opts: {
8081 encoding = r . headers . get ( 'content-encoding' )
8182 const contentLength = r . headers . get ( 'content-length' )
8283 size = contentLength ? Number ( contentLength ) / 1024 : 0
83-
8484 return r . arrayBuffer ( )
8585 } ) . then ( r => Buffer . from ( r ) )
8686
87- storage . setItemRaw ( `data:scripts:${ filename } ` , res )
87+ await storage . setItemRaw ( `bundle:${ filename } ` , res )
88+ size = size || res ! . length / 1024
89+ logger . info ( `Downloading script ${ colors . gray ( `${ src } → ${ filename } (${ size . toFixed ( 2 ) } kB ${ encoding } )` ) } ` )
8890 renderedScript . set ( url , {
8991 content : res ! ,
9092 size,
@@ -110,7 +112,7 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
110112 logger . debug ( '[bundle-script-transformer] No scripts to bundle...' )
111113 return
112114 }
113- logger . info ( '[bundle-script-transformer] Bundling scripts...' )
115+ logger . debug ( '[bundle-script-transformer] Bundling scripts...' )
114116 // less aggressive cache clearing in dev
115117 if ( ! nuxt . options . dev ) {
116118 await fsp . rm ( cacheDir , { recursive : true , force : true } )
@@ -121,7 +123,7 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
121123 if ( content instanceof Error || ! content . filename )
122124 return
123125 await fsp . writeFile ( join ( nuxt . options . buildDir , 'cache' , 'scripts' , content . filename ) , content . content )
124- logger . info ( colors . gray ( ` ├─ ${ url } → ${ joinURL ( content . src ) } (${ content . size . toFixed ( 2 ) } kB ${ content . encoding } )` ) )
126+ logger . debug ( colors . gray ( ` ├─ ${ url } → ${ joinURL ( content . src ) } (${ content . size . toFixed ( 2 ) } kB ${ content . encoding } )` ) )
125127 } ) )
126128 } )
127129
0 commit comments