🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
12
node_modules/astro/dist/vite-plugin-astro/compile.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/vite-plugin-astro/compile.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { type ESBuildTransformResult } from 'vite';
|
||||
import { type CompileProps, type CompileResult } from '../core/compile/index.js';
|
||||
import type { LogOptions } from '../core/logger/core.js';
|
||||
interface CachedFullCompilation {
|
||||
compileProps: CompileProps;
|
||||
logging: LogOptions;
|
||||
}
|
||||
interface FullCompileResult extends Omit<CompileResult, 'map'> {
|
||||
map: ESBuildTransformResult['map'];
|
||||
}
|
||||
export declare function cachedFullCompilation({ compileProps, logging, }: CachedFullCompilation): Promise<FullCompileResult>;
|
||||
export {};
|
96
node_modules/astro/dist/vite-plugin-astro/compile.js
generated
vendored
Normal file
96
node_modules/astro/dist/vite-plugin-astro/compile.js
generated
vendored
Normal file
|
@ -0,0 +1,96 @@
|
|||
import { transformWithEsbuild } from "vite";
|
||||
import { cachedCompilation } from "../core/compile/index.js";
|
||||
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
||||
const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
|
||||
async function cachedFullCompilation({
|
||||
compileProps,
|
||||
logging
|
||||
}) {
|
||||
let transformResult;
|
||||
let esbuildResult;
|
||||
try {
|
||||
transformResult = await cachedCompilation(compileProps);
|
||||
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
|
||||
loader: "ts",
|
||||
target: "esnext",
|
||||
sourcemap: "external",
|
||||
tsconfigRaw: {
|
||||
compilerOptions: {
|
||||
// Ensure client:only imports are treeshaken
|
||||
// @ts-expect-error anticipate esbuild 0.18 feature
|
||||
verbatimModuleSyntax: false,
|
||||
importsNotUsedAsValues: "remove"
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
await enhanceCompileError({
|
||||
err,
|
||||
id: compileProps.filename,
|
||||
source: compileProps.source,
|
||||
config: compileProps.astroConfig,
|
||||
logging
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
const { fileId: file, fileUrl: url } = getFileInfo(
|
||||
compileProps.filename,
|
||||
compileProps.astroConfig
|
||||
);
|
||||
let SUFFIX = "";
|
||||
SUFFIX += `
|
||||
const $$file = ${JSON.stringify(file)};
|
||||
const $$url = ${JSON.stringify(
|
||||
url
|
||||
)};export { $$file as file, $$url as url };
|
||||
`;
|
||||
if (!compileProps.viteConfig.isProduction) {
|
||||
let i = 0;
|
||||
while (i < transformResult.scripts.length) {
|
||||
SUFFIX += `import "${compileProps.filename}?astro&type=script&index=${i}&lang.ts";`;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (!compileProps.viteConfig.isProduction) {
|
||||
SUFFIX += `
|
||||
if (import.meta.hot) { import.meta.hot.decline() }`;
|
||||
}
|
||||
return {
|
||||
...transformResult,
|
||||
code: esbuildResult.code + SUFFIX,
|
||||
map: esbuildResult.map
|
||||
};
|
||||
}
|
||||
async function enhanceCompileError({
|
||||
err,
|
||||
id,
|
||||
source
|
||||
}) {
|
||||
var _a;
|
||||
const lineText = (_a = err.loc) == null ? void 0 : _a.lineText;
|
||||
const scannedFrontmatter = FRONTMATTER_PARSE_REGEXP.exec(source);
|
||||
if (scannedFrontmatter) {
|
||||
const frontmatter = scannedFrontmatter[1].replace(/\breturn\b/g, "throw");
|
||||
if (lineText && !frontmatter.includes(lineText))
|
||||
throw err;
|
||||
try {
|
||||
await transformWithEsbuild(frontmatter, id, {
|
||||
loader: "ts",
|
||||
target: "esnext",
|
||||
sourcemap: false
|
||||
});
|
||||
} catch (frontmatterErr) {
|
||||
if (frontmatterErr == null ? void 0 : frontmatterErr.message) {
|
||||
frontmatterErr.message = frontmatterErr.message.replace(
|
||||
"end of file",
|
||||
"end of frontmatter"
|
||||
);
|
||||
}
|
||||
throw frontmatterErr;
|
||||
}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
export {
|
||||
cachedFullCompilation
|
||||
};
|
11
node_modules/astro/dist/vite-plugin-astro/hmr.d.ts
generated
vendored
Normal file
11
node_modules/astro/dist/vite-plugin-astro/hmr.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
import type { HmrContext, ModuleNode } from 'vite';
|
||||
import type { AstroConfig } from '../@types/astro';
|
||||
import { cachedCompilation } from '../core/compile/index.js';
|
||||
import type { LogOptions } from '../core/logger/core.js';
|
||||
export interface HandleHotUpdateOptions {
|
||||
config: AstroConfig;
|
||||
logging: LogOptions;
|
||||
compile: () => ReturnType<typeof cachedCompilation>;
|
||||
source: string;
|
||||
}
|
||||
export declare function handleHotUpdate(ctx: HmrContext, { config, logging, compile, source }: HandleHotUpdateOptions): Promise<ModuleNode[] | undefined>;
|
112
node_modules/astro/dist/vite-plugin-astro/hmr.js
generated
vendored
Normal file
112
node_modules/astro/dist/vite-plugin-astro/hmr.js
generated
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
import { fileURLToPath } from "node:url";
|
||||
import {
|
||||
invalidateCompilation,
|
||||
isCached
|
||||
} from "../core/compile/index.js";
|
||||
import { info } from "../core/logger/core.js";
|
||||
import * as msg from "../core/messages.js";
|
||||
import { isAstroScript } from "./query.js";
|
||||
const PKG_PREFIX = fileURLToPath(new URL("../../", import.meta.url));
|
||||
const E2E_PREFIX = fileURLToPath(new URL("../../e2e", import.meta.url));
|
||||
const isPkgFile = (id) => {
|
||||
return (id == null ? void 0 : id.startsWith(PKG_PREFIX)) && !id.startsWith(E2E_PREFIX);
|
||||
};
|
||||
async function handleHotUpdate(ctx, { config, logging, compile, source }) {
|
||||
let isStyleOnlyChange = false;
|
||||
if (ctx.file.endsWith(".astro") && isCached(config, ctx.file)) {
|
||||
const oldResult = await compile();
|
||||
if (oldResult.source === source)
|
||||
return [];
|
||||
invalidateCompilation(config, ctx.file);
|
||||
const newResult = await compile();
|
||||
if (isStyleOnlyChanged(oldResult, newResult)) {
|
||||
isStyleOnlyChange = true;
|
||||
}
|
||||
} else {
|
||||
invalidateCompilation(config, ctx.file);
|
||||
}
|
||||
if (isPkgFile(ctx.file)) {
|
||||
return;
|
||||
}
|
||||
const filtered = new Set(ctx.modules);
|
||||
const files = /* @__PURE__ */ new Set();
|
||||
for (const mod of ctx.modules) {
|
||||
if (isPkgFile(mod.id ?? mod.file)) {
|
||||
filtered.delete(mod);
|
||||
continue;
|
||||
}
|
||||
if (mod.file && isCached(config, mod.file)) {
|
||||
filtered.add(mod);
|
||||
files.add(mod.file);
|
||||
}
|
||||
for (const imp of mod.importers) {
|
||||
if (imp.file && isCached(config, imp.file)) {
|
||||
filtered.add(imp);
|
||||
files.add(imp.file);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const file2 of files) {
|
||||
if (isStyleOnlyChange && file2 === ctx.file)
|
||||
continue;
|
||||
invalidateCompilation(config, file2);
|
||||
if (file2.endsWith(".astro")) {
|
||||
ctx.server.moduleGraph.onFileChange(file2);
|
||||
}
|
||||
}
|
||||
const mods = ctx.modules.filter((m) => !m.url.endsWith("="));
|
||||
const file = ctx.file.replace(config.root.pathname, "/");
|
||||
if (isStyleOnlyChange) {
|
||||
info(logging, "astro", msg.hmr({ file, style: true }));
|
||||
return mods.filter((mod) => {
|
||||
var _a;
|
||||
return mod.id !== ctx.file && !((_a = mod.id) == null ? void 0 : _a.endsWith(".ts"));
|
||||
});
|
||||
}
|
||||
for (const mod of mods) {
|
||||
for (const imp of mod.importedModules) {
|
||||
if (imp.id && isAstroScript(imp.id)) {
|
||||
mods.push(imp);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const mod of filtered) {
|
||||
if (mod.id && isAstroScript(mod.id) && mod.file) {
|
||||
const astroMod = ctx.server.moduleGraph.getModuleById(mod.file);
|
||||
if (astroMod) {
|
||||
mods.unshift(astroMod);
|
||||
}
|
||||
}
|
||||
}
|
||||
const isSelfAccepting = mods.every((m) => m.isSelfAccepting || m.url.endsWith(".svelte"));
|
||||
if (isSelfAccepting) {
|
||||
if (/astro\.config\.[cm][jt]s$/.test(file))
|
||||
return mods;
|
||||
info(logging, "astro", msg.hmr({ file }));
|
||||
} else {
|
||||
info(logging, "astro", msg.reload({ file }));
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
function isStyleOnlyChanged(oldResult, newResult) {
|
||||
return normalizeCode(oldResult.code) === normalizeCode(newResult.code) && !isArrayEqual(oldResult.css, newResult.css);
|
||||
}
|
||||
const astroStyleImportRE = /import\s*"[^"]+astro&type=style[^"]+";/g;
|
||||
const sourceMappingUrlRE = /\/\/# sourceMappingURL=[^ ]+$/gm;
|
||||
function normalizeCode(code) {
|
||||
return code.replace(astroStyleImportRE, "").replace(sourceMappingUrlRE, "").trim();
|
||||
}
|
||||
function isArrayEqual(a, b) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
export {
|
||||
handleHotUpdate
|
||||
};
|
12
node_modules/astro/dist/vite-plugin-astro/index.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/vite-plugin-astro/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import type * as vite from 'vite';
|
||||
import type { AstroSettings } from '../@types/astro';
|
||||
import type { LogOptions } from '../core/logger/core.js';
|
||||
import type { PluginMetadata as AstroPluginMetadata } from './types';
|
||||
export { getAstroMetadata } from './metadata.js';
|
||||
export type { AstroPluginMetadata };
|
||||
interface AstroPluginOptions {
|
||||
settings: AstroSettings;
|
||||
logging: LogOptions;
|
||||
}
|
||||
/** Transform .astro files for Vite */
|
||||
export default function astro({ settings, logging }: AstroPluginOptions): vite.Plugin[];
|
184
node_modules/astro/dist/vite-plugin-astro/index.js
generated
vendored
Normal file
184
node_modules/astro/dist/vite-plugin-astro/index.js
generated
vendored
Normal file
|
@ -0,0 +1,184 @@
|
|||
import { normalizePath } from "vite";
|
||||
import {
|
||||
cachedCompilation,
|
||||
getCachedCompileResult
|
||||
} from "../core/compile/index.js";
|
||||
import { isRelativePath } from "../core/path.js";
|
||||
import { normalizeFilename } from "../vite-plugin-utils/index.js";
|
||||
import { cachedFullCompilation } from "./compile.js";
|
||||
import { handleHotUpdate } from "./hmr.js";
|
||||
import { parseAstroRequest } from "./query.js";
|
||||
import { getAstroMetadata } from "./metadata.js";
|
||||
function astro({ settings, logging }) {
|
||||
const { config } = settings;
|
||||
let resolvedConfig;
|
||||
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
||||
const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
|
||||
const prePlugin = {
|
||||
name: "astro:build",
|
||||
enforce: "pre",
|
||||
// run transforms before other plugins can
|
||||
configResolved(_resolvedConfig) {
|
||||
resolvedConfig = _resolvedConfig;
|
||||
},
|
||||
async load(id, opts) {
|
||||
const parsedId = parseAstroRequest(id);
|
||||
const query = parsedId.query;
|
||||
if (!query.astro) {
|
||||
return null;
|
||||
}
|
||||
const filename = normalizePath(normalizeFilename(parsedId.filename, config.root));
|
||||
const compileResult = getCachedCompileResult(config, filename);
|
||||
if (!compileResult) {
|
||||
return null;
|
||||
}
|
||||
switch (query.type) {
|
||||
case "style": {
|
||||
if (typeof query.index === "undefined") {
|
||||
throw new Error(`Requests for Astro CSS must include an index.`);
|
||||
}
|
||||
const code = compileResult.css[query.index];
|
||||
if (!code) {
|
||||
throw new Error(`No Astro CSS at index ${query.index}`);
|
||||
}
|
||||
return {
|
||||
code,
|
||||
meta: {
|
||||
vite: {
|
||||
isSelfAccepting: true
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
case "script": {
|
||||
if (typeof query.index === "undefined") {
|
||||
throw new Error(`Requests for hoisted scripts must include an index`);
|
||||
}
|
||||
if (opts == null ? void 0 : opts.ssr) {
|
||||
return {
|
||||
code: `/* client hoisted script, empty in SSR: ${id} */`
|
||||
};
|
||||
}
|
||||
const hoistedScript = compileResult.scripts[query.index];
|
||||
if (!hoistedScript) {
|
||||
throw new Error(`No hoisted script at index ${query.index}`);
|
||||
}
|
||||
if (hoistedScript.type === "external") {
|
||||
const src = hoistedScript.src;
|
||||
if (src.startsWith("/") && !isBrowserPath(src)) {
|
||||
const publicDir = config.publicDir.pathname.replace(/\/$/, "").split("/").pop() + "/";
|
||||
throw new Error(
|
||||
`
|
||||
|
||||
<script src="${src}"> references an asset in the "${publicDir}" directory. Please add the "is:inline" directive to keep this asset from being bundled.
|
||||
|
||||
File: ${id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
const result = {
|
||||
code: "",
|
||||
meta: {
|
||||
vite: {
|
||||
lang: "ts"
|
||||
}
|
||||
}
|
||||
};
|
||||
switch (hoistedScript.type) {
|
||||
case "inline": {
|
||||
const { code, map } = hoistedScript;
|
||||
result.code = appendSourceMap(code, map);
|
||||
break;
|
||||
}
|
||||
case "external": {
|
||||
const { src } = hoistedScript;
|
||||
result.code = `import "${src}"`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
async transform(source, id) {
|
||||
const parsedId = parseAstroRequest(id);
|
||||
if (!id.endsWith(".astro") || parsedId.query.astro) {
|
||||
return;
|
||||
}
|
||||
if (isRelativePath(parsedId.filename)) {
|
||||
return;
|
||||
}
|
||||
const compileProps = {
|
||||
astroConfig: config,
|
||||
viteConfig: resolvedConfig,
|
||||
filename: normalizePath(parsedId.filename),
|
||||
source
|
||||
};
|
||||
const transformResult = await cachedFullCompilation({ compileProps, logging });
|
||||
for (const dep of transformResult.cssDeps) {
|
||||
this.addWatchFile(dep);
|
||||
}
|
||||
const astroMetadata = {
|
||||
clientOnlyComponents: transformResult.clientOnlyComponents,
|
||||
hydratedComponents: transformResult.hydratedComponents,
|
||||
scripts: transformResult.scripts,
|
||||
containsHead: transformResult.containsHead,
|
||||
propagation: "none",
|
||||
pageOptions: {}
|
||||
};
|
||||
return {
|
||||
code: transformResult.code,
|
||||
map: transformResult.map,
|
||||
meta: {
|
||||
astro: astroMetadata,
|
||||
vite: {
|
||||
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
||||
// extensions to .ts files.
|
||||
lang: "ts"
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
async handleHotUpdate(context) {
|
||||
if (context.server.config.isProduction)
|
||||
return;
|
||||
const compileProps = {
|
||||
astroConfig: config,
|
||||
viteConfig: resolvedConfig,
|
||||
filename: context.file,
|
||||
source: await context.read()
|
||||
};
|
||||
const compile = () => cachedCompilation(compileProps);
|
||||
return handleHotUpdate(context, {
|
||||
config,
|
||||
logging,
|
||||
compile,
|
||||
source: compileProps.source
|
||||
});
|
||||
}
|
||||
};
|
||||
const normalPlugin = {
|
||||
name: "astro:build:normal",
|
||||
resolveId(id) {
|
||||
const parsedId = parseAstroRequest(id);
|
||||
if (parsedId.query.astro) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
};
|
||||
return [prePlugin, normalPlugin];
|
||||
}
|
||||
function appendSourceMap(content, map) {
|
||||
if (!map)
|
||||
return content;
|
||||
return `${content}
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(
|
||||
map
|
||||
).toString("base64")}`;
|
||||
}
|
||||
export {
|
||||
astro as default,
|
||||
getAstroMetadata
|
||||
};
|
3
node_modules/astro/dist/vite-plugin-astro/metadata.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/vite-plugin-astro/metadata.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import type { ModuleInfo } from '../core/module-loader';
|
||||
import type { PluginMetadata } from './types';
|
||||
export declare function getAstroMetadata(modInfo: ModuleInfo): PluginMetadata['astro'] | undefined;
|
10
node_modules/astro/dist/vite-plugin-astro/metadata.js
generated
vendored
Normal file
10
node_modules/astro/dist/vite-plugin-astro/metadata.js
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
function getAstroMetadata(modInfo) {
|
||||
var _a;
|
||||
if ((_a = modInfo.meta) == null ? void 0 : _a.astro) {
|
||||
return modInfo.meta.astro;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
export {
|
||||
getAstroMetadata
|
||||
};
|
14
node_modules/astro/dist/vite-plugin-astro/query.d.ts
generated
vendored
Normal file
14
node_modules/astro/dist/vite-plugin-astro/query.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
export interface AstroQuery {
|
||||
astro?: boolean;
|
||||
src?: boolean;
|
||||
type?: 'script' | 'template' | 'style' | 'custom';
|
||||
index?: number;
|
||||
lang?: string;
|
||||
raw?: boolean;
|
||||
}
|
||||
export interface ParsedRequestResult {
|
||||
filename: string;
|
||||
query: AstroQuery;
|
||||
}
|
||||
export declare function parseAstroRequest(id: string): ParsedRequestResult;
|
||||
export declare function isAstroScript(id: string): boolean;
|
28
node_modules/astro/dist/vite-plugin-astro/query.js
generated
vendored
Normal file
28
node_modules/astro/dist/vite-plugin-astro/query.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
function parseAstroRequest(id) {
|
||||
const [filename, rawQuery] = id.split(`?`, 2);
|
||||
const query = Object.fromEntries(new URLSearchParams(rawQuery).entries());
|
||||
if (query.astro != null) {
|
||||
query.astro = true;
|
||||
}
|
||||
if (query.src != null) {
|
||||
query.src = true;
|
||||
}
|
||||
if (query.index != null) {
|
||||
query.index = Number(query.index);
|
||||
}
|
||||
if (query.raw != null) {
|
||||
query.raw = true;
|
||||
}
|
||||
return {
|
||||
filename,
|
||||
query
|
||||
};
|
||||
}
|
||||
function isAstroScript(id) {
|
||||
const parsed = parseAstroRequest(id);
|
||||
return parsed.query.type === "script";
|
||||
}
|
||||
export {
|
||||
isAstroScript,
|
||||
parseAstroRequest
|
||||
};
|
15
node_modules/astro/dist/vite-plugin-astro/types.d.ts
generated
vendored
Normal file
15
node_modules/astro/dist/vite-plugin-astro/types.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type { TransformResult } from '@astrojs/compiler';
|
||||
import type { PropagationHint } from '../@types/astro';
|
||||
export interface PageOptions {
|
||||
prerender?: boolean;
|
||||
}
|
||||
export interface PluginMetadata {
|
||||
astro: {
|
||||
hydratedComponents: TransformResult['hydratedComponents'];
|
||||
clientOnlyComponents: TransformResult['clientOnlyComponents'];
|
||||
scripts: TransformResult['scripts'];
|
||||
containsHead: TransformResult['containsHead'];
|
||||
propagation: PropagationHint;
|
||||
pageOptions: PageOptions;
|
||||
};
|
||||
}
|
0
node_modules/astro/dist/vite-plugin-astro/types.js
generated
vendored
Normal file
0
node_modules/astro/dist/vite-plugin-astro/types.js
generated
vendored
Normal file
Loading…
Add table
Add a link
Reference in a new issue