@@ -5,45 +5,48 @@ import { BuildInternals, getPageDataByViteID } from '../core/build/internal.js';
55import type { ModuleLoader } from '../core/module-loader/loader.js' ;
66import { createViteLoader } from '../core/module-loader/vite.js' ;
77import { getStylesForURL } from '../core/render/dev/css.js' ;
8+ import { getScriptsForURL } from '../core/render/dev/scripts.js' ;
89import {
910 contentFileExts ,
10- DELAYED_ASSET_FLAG ,
11+ PROPAGATED_ASSET_FLAG ,
1112 LINKS_PLACEHOLDER ,
13+ SCRIPTS_PLACEHOLDER ,
1214 STYLES_PLACEHOLDER ,
1315} from './consts.js' ;
1416
15- function isDelayedAsset ( viteId : string ) : boolean {
17+ function isPropagatedAsset ( viteId : string ) : boolean {
1618 const url = new URL ( viteId , 'file://' ) ;
1719 return (
18- url . searchParams . has ( DELAYED_ASSET_FLAG ) &&
20+ url . searchParams . has ( PROPAGATED_ASSET_FLAG ) &&
1921 contentFileExts . some ( ( ext ) => url . pathname . endsWith ( ext ) )
2022 ) ;
2123}
2224
23- export function astroDelayedAssetPlugin ( { mode } : { mode : string } ) : Plugin {
25+ export function astroContentAssetPropagationPlugin ( { mode } : { mode : string } ) : Plugin {
2426 let devModuleLoader : ModuleLoader ;
2527 return {
26- name : 'astro-delayed- asset-plugin ' ,
28+ name : 'astro:content- asset-propagation ' ,
2729 enforce : 'pre' ,
2830 configureServer ( server ) {
2931 if ( mode === 'dev' ) {
3032 devModuleLoader = createViteLoader ( server ) ;
3133 }
3234 } ,
3335 load ( id ) {
34- if ( isDelayedAsset ( id ) ) {
36+ if ( isPropagatedAsset ( id ) ) {
3537 const basePath = id . split ( '?' ) [ 0 ] ;
3638 const code = `
3739 export { Content, getHeadings, frontmatter } from ${ JSON . stringify ( basePath ) } ;
3840 export const collectedLinks = ${ JSON . stringify ( LINKS_PLACEHOLDER ) } ;
3941 export const collectedStyles = ${ JSON . stringify ( STYLES_PLACEHOLDER ) } ;
42+ export const collectedScripts = ${ JSON . stringify ( SCRIPTS_PLACEHOLDER ) } ;
4043 ` ;
4144 return { code } ;
4245 }
4346 } ,
4447 async transform ( code , id , options ) {
4548 if ( ! options ?. ssr ) return ;
46- if ( devModuleLoader && isDelayedAsset ( id ) ) {
49+ if ( devModuleLoader && isPropagatedAsset ( id ) ) {
4750 const basePath = id . split ( '?' ) [ 0 ] ;
4851 if ( ! devModuleLoader . getModuleById ( basePath ) ?. ssrModule ) {
4952 await devModuleLoader . import ( basePath ) ;
@@ -54,23 +57,22 @@ export function astroDelayedAssetPlugin({ mode }: { mode: string }): Plugin {
5457 'development'
5558 ) ;
5659
60+ const hoistedScripts = await getScriptsForURL ( pathToFileURL ( basePath ) , devModuleLoader ) ;
61+
5762 return {
5863 code : code
5964 . replace ( JSON . stringify ( LINKS_PLACEHOLDER ) , JSON . stringify ( [ ...urls ] ) )
60- . replace ( JSON . stringify ( STYLES_PLACEHOLDER ) , JSON . stringify ( [ ...stylesMap . values ( ) ] ) ) ,
65+ . replace ( JSON . stringify ( STYLES_PLACEHOLDER ) , JSON . stringify ( [ ...stylesMap . values ( ) ] ) )
66+ . replace ( JSON . stringify ( SCRIPTS_PLACEHOLDER ) , JSON . stringify ( [ ...hoistedScripts ] ) ) ,
6167 } ;
6268 }
6369 } ,
6470 } ;
6571}
6672
67- export function astroBundleDelayedAssetPlugin ( {
68- internals,
69- } : {
70- internals : BuildInternals ;
71- } ) : Plugin {
73+ export function astroContentProdBundlePlugin ( { internals } : { internals : BuildInternals } ) : Plugin {
7274 return {
73- name : 'astro-bundle-delayed-asset-plugin ' ,
75+ name : 'astro:content-prod-bundle ' ,
7476 async generateBundle ( _options , bundle ) {
7577 for ( const [ _ , chunk ] of Object . entries ( bundle ) ) {
7678 if ( chunk . type === 'chunk' && chunk . code . includes ( LINKS_PLACEHOLDER ) ) {
0 commit comments