🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
5
node_modules/astro/dist/vite-plugin-head/index.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/vite-plugin-head/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import type * as vite from 'vite';
|
||||
import type { AstroBuildPlugin } from '../core/build/plugin.js';
|
||||
import type { BuildInternals } from '../core/build/internal.js';
|
||||
export default function configHeadVitePlugin(): vite.Plugin;
|
||||
export declare function astroHeadBuildPlugin(internals: BuildInternals): AstroBuildPlugin;
|
93
node_modules/astro/dist/vite-plugin-head/index.js
generated
vendored
Normal file
93
node_modules/astro/dist/vite-plugin-head/index.js
generated
vendored
Normal file
|
@ -0,0 +1,93 @@
|
|||
import { getTopLevelPages, walkParentInfos } from "../core/build/graph.js";
|
||||
import { getAstroMetadata } from "../vite-plugin-astro/index.js";
|
||||
const injectExp = /(^\/\/|\/\/!)\s*astro-head-inject/;
|
||||
function configHeadVitePlugin() {
|
||||
let server;
|
||||
function propagateMetadata(id, prop, value, seen = /* @__PURE__ */ new Set()) {
|
||||
if (seen.has(id))
|
||||
return;
|
||||
seen.add(id);
|
||||
const mod = server.moduleGraph.getModuleById(id);
|
||||
const info = this.getModuleInfo(id);
|
||||
if (info == null ? void 0 : info.meta.astro) {
|
||||
const astroMetadata = getAstroMetadata(info);
|
||||
if (astroMetadata) {
|
||||
Reflect.set(astroMetadata, prop, value);
|
||||
}
|
||||
}
|
||||
for (const parent of (mod == null ? void 0 : mod.importers) || []) {
|
||||
if (parent.id) {
|
||||
propagateMetadata.call(this, parent.id, prop, value, seen);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "astro:head-metadata",
|
||||
configureServer(_server) {
|
||||
server = _server;
|
||||
},
|
||||
transform(source, id) {
|
||||
var _a;
|
||||
if (!server) {
|
||||
return;
|
||||
}
|
||||
let info = this.getModuleInfo(id);
|
||||
if (info && ((_a = getAstroMetadata(info)) == null ? void 0 : _a.containsHead)) {
|
||||
propagateMetadata.call(this, id, "containsHead", true);
|
||||
}
|
||||
if (injectExp.test(source)) {
|
||||
propagateMetadata.call(this, id, "propagation", "in-tree");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function astroHeadBuildPlugin(internals) {
|
||||
return {
|
||||
build: "ssr",
|
||||
hooks: {
|
||||
"build:before"() {
|
||||
return {
|
||||
vitePlugin: {
|
||||
name: "astro:head-metadata-build",
|
||||
generateBundle(_opts, bundle) {
|
||||
var _a;
|
||||
const map = internals.componentMetadata;
|
||||
function getOrCreateMetadata(id) {
|
||||
if (map.has(id))
|
||||
return map.get(id);
|
||||
const metadata = {
|
||||
propagation: "none",
|
||||
containsHead: false
|
||||
};
|
||||
map.set(id, metadata);
|
||||
return metadata;
|
||||
}
|
||||
for (const [, output] of Object.entries(bundle)) {
|
||||
if (output.type !== "chunk")
|
||||
continue;
|
||||
for (const [id, mod] of Object.entries(output.modules)) {
|
||||
const modinfo = this.getModuleInfo(id);
|
||||
if (modinfo && ((_a = getAstroMetadata(modinfo)) == null ? void 0 : _a.containsHead)) {
|
||||
for (const [pageInfo] of getTopLevelPages(id, this)) {
|
||||
let metadata = getOrCreateMetadata(pageInfo.id);
|
||||
metadata.containsHead = true;
|
||||
}
|
||||
}
|
||||
if (mod.code && injectExp.test(mod.code)) {
|
||||
for (const [info] of walkParentInfos(id, this)) {
|
||||
getOrCreateMetadata(info.id).propagation = "in-tree";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
astroHeadBuildPlugin,
|
||||
configHeadVitePlugin as default
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue