-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Head propagation * Adding a changeset * Fix broken build * Self review stuff * Use compiler prerelease exact version * new compiler version * Update packages/astro/src/vite-plugin-head-propagation/index.ts Co-authored-by: Bjorn Lu <[email protected]> * Use getAstroMetadata * add .js * make relative lookup work on win * Use [email protected] * PR review comments * Make renderHead an alias for a better named function Co-authored-by: Bjorn Lu <[email protected]>
- Loading branch information
Showing
36 changed files
with
804 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Low-level head propagation | ||
|
||
This adds low-level head propagation ability within the Astro runtime. This is not really useable within an Astro app at the moment, but provides the APIs necessary for `renderEntry` to do head propagation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { SSRResult } from '../../../@types/astro'; | ||
|
||
import type { ModuleInfo, ModuleLoader } from '../../module-loader/index'; | ||
|
||
import { viteID } from '../../util.js'; | ||
import { getAstroMetadata } from '../../../vite-plugin-astro/index.js'; | ||
import { crawlGraph } from './vite.js'; | ||
|
||
export async function getPropagationMap( | ||
filePath: URL, | ||
loader: ModuleLoader | ||
): Promise<SSRResult['propagation']> { | ||
const map: SSRResult['propagation'] = new Map(); | ||
|
||
const rootID = viteID(filePath); | ||
addInjection(map, loader.getModuleInfo(rootID)) | ||
for await (const moduleNode of crawlGraph(loader, rootID, true)) { | ||
const id = moduleNode.id; | ||
if (id) { | ||
addInjection(map, loader.getModuleInfo(id)); | ||
} | ||
} | ||
|
||
return map; | ||
} | ||
|
||
function addInjection(map: SSRResult['propagation'], modInfo: ModuleInfo | null) { | ||
if(modInfo) { | ||
const astro = getAstroMetadata(modInfo); | ||
if(astro && astro.propagation) { | ||
map.set(modInfo.id, astro.propagation) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { PropagationHint } from '../../@types/astro'; | ||
import type { AstroComponentFactory } from './render/index.js'; | ||
|
||
function baseCreateComponent(cb: AstroComponentFactory, moduleId?: string) { | ||
// Add a flag to this callback to mark it as an Astro component | ||
cb.isAstroComponentFactory = true; | ||
cb.moduleId = moduleId; | ||
return cb; | ||
} | ||
|
||
interface CreateComponentOptions { | ||
factory: AstroComponentFactory; | ||
moduleId?: string; | ||
propagation?: PropagationHint; | ||
} | ||
|
||
function createComponentWithOptions(opts: CreateComponentOptions) { | ||
const cb = baseCreateComponent(opts.factory, opts.moduleId); | ||
cb.propagation = opts.propagation; | ||
return cb; | ||
} | ||
// Used in creating the component. aka the main export. | ||
export function createComponent(arg1: AstroComponentFactory, moduleId: string) { | ||
if(typeof arg1 === 'function') { | ||
return baseCreateComponent(arg1, moduleId); | ||
} else { | ||
return createComponentWithOptions(arg1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.