🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

6
node_modules/astro/dist/core/compile/cache.d.ts generated vendored Normal file
View file

@ -0,0 +1,6 @@
import type { AstroConfig } from '../../@types/astro';
import { type CompileProps, type CompileResult } from './compile.js';
export declare function isCached(config: AstroConfig, filename: string): boolean;
export declare function getCachedCompileResult(config: AstroConfig, filename: string): CompileResult | null;
export declare function invalidateCompilation(config: AstroConfig, filename: string): void;
export declare function cachedCompilation(props: CompileProps): Promise<CompileResult>;

38
node_modules/astro/dist/core/compile/cache.js generated vendored Normal file
View file

@ -0,0 +1,38 @@
import { compile } from "./compile.js";
const configCache = /* @__PURE__ */ new WeakMap();
function isCached(config, filename) {
return configCache.has(config) && configCache.get(config).has(filename);
}
function getCachedCompileResult(config, filename) {
if (!isCached(config, filename))
return null;
return configCache.get(config).get(filename);
}
function invalidateCompilation(config, filename) {
if (configCache.has(config)) {
const cache = configCache.get(config);
cache.delete(filename);
}
}
async function cachedCompilation(props) {
const { astroConfig, filename } = props;
let cache;
if (!configCache.has(astroConfig)) {
cache = /* @__PURE__ */ new Map();
configCache.set(astroConfig, cache);
} else {
cache = configCache.get(astroConfig);
}
if (cache.has(filename)) {
return cache.get(filename);
}
const compileResult = await compile(props);
cache.set(filename, compileResult);
return compileResult;
}
export {
cachedCompilation,
getCachedCompileResult,
invalidateCompilation,
isCached
};

14
node_modules/astro/dist/core/compile/compile.d.ts generated vendored Normal file
View file

@ -0,0 +1,14 @@
import type { TransformResult } from '@astrojs/compiler';
import type { ResolvedConfig } from 'vite';
import type { AstroConfig } from '../../@types/astro';
export interface CompileProps {
astroConfig: AstroConfig;
viteConfig: ResolvedConfig;
filename: string;
source: string;
}
export interface CompileResult extends TransformResult {
cssDeps: Set<string>;
source: string;
}
export declare function compile({ astroConfig, viteConfig, filename, source, }: CompileProps): Promise<CompileResult>;

92
node_modules/astro/dist/core/compile/compile.js generated vendored Normal file
View file

@ -0,0 +1,92 @@
import { transform } from "@astrojs/compiler";
import { fileURLToPath } from "node:url";
import { normalizePath } from "vite";
import { AggregateError, CompilerError } from "../errors/errors.js";
import { AstroErrorData } from "../errors/index.js";
import { resolvePath } from "../util.js";
import { createStylePreprocessor } from "./style.js";
async function compile({
astroConfig,
viteConfig,
filename,
source
}) {
const cssDeps = /* @__PURE__ */ new Set();
const cssTransformErrors = [];
let transformResult;
try {
transformResult = await transform(source, {
compact: astroConfig.compressHTML,
filename,
normalizedFilename: normalizeFilename(filename, astroConfig.root),
sourcemap: "both",
internalURL: "astro/server/index.js",
astroGlobalArgs: JSON.stringify(astroConfig.site),
scopedStyleStrategy: astroConfig.scopedStyleStrategy,
resultScopedSlot: true,
preprocessStyle: createStylePreprocessor({
filename,
viteConfig,
cssDeps,
cssTransformErrors
}),
async resolvePath(specifier) {
return resolvePath(specifier, filename);
}
});
} catch (err) {
throw new CompilerError({
...AstroErrorData.UnknownCompilerError,
message: err.message ?? "Unknown compiler error",
stack: err.stack,
location: {
file: filename
}
});
}
handleCompileResultErrors(transformResult, cssTransformErrors);
return {
...transformResult,
cssDeps,
source
};
}
function handleCompileResultErrors(result, cssTransformErrors) {
const compilerError = result.diagnostics.find((diag) => diag.severity === 1);
if (compilerError) {
throw new CompilerError({
message: compilerError.text,
location: {
line: compilerError.location.line,
column: compilerError.location.column,
file: compilerError.location.file
},
hint: compilerError.hint
});
}
switch (cssTransformErrors.length) {
case 0:
break;
case 1: {
throw cssTransformErrors[0];
}
default: {
throw new AggregateError({
...cssTransformErrors[0],
errors: cssTransformErrors
});
}
}
}
function normalizeFilename(filename, root) {
const normalizedFilename = normalizePath(filename);
const normalizedRoot = normalizePath(fileURLToPath(root));
if (normalizedFilename.startsWith(normalizedRoot)) {
return normalizedFilename.slice(normalizedRoot.length - 1);
} else {
return normalizedFilename;
}
}
export {
compile
};

3
node_modules/astro/dist/core/compile/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,3 @@
export { cachedCompilation, getCachedCompileResult, invalidateCompilation, isCached, } from './cache.js';
export type { CompileProps, CompileResult } from './compile';
export type { TransformStyle } from './types';

12
node_modules/astro/dist/core/compile/index.js generated vendored Normal file
View file

@ -0,0 +1,12 @@
import {
cachedCompilation,
getCachedCompileResult,
invalidateCompilation,
isCached
} from "./cache.js";
export {
cachedCompilation,
getCachedCompileResult,
invalidateCompilation,
isCached
};

8
node_modules/astro/dist/core/compile/style.d.ts generated vendored Normal file
View file

@ -0,0 +1,8 @@
import type { TransformOptions } from '@astrojs/compiler';
import { type ResolvedConfig } from 'vite';
export declare function createStylePreprocessor({ filename, viteConfig, cssDeps, cssTransformErrors, }: {
filename: string;
viteConfig: ResolvedConfig;
cssDeps: Set<string>;
cssTransformErrors: Error[];
}): TransformOptions['preprocessStyle'];

83
node_modules/astro/dist/core/compile/style.js generated vendored Normal file
View file

@ -0,0 +1,83 @@
import fs from "node:fs";
import { preprocessCSS } from "vite";
import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
function createStylePreprocessor({
filename,
viteConfig,
cssDeps,
cssTransformErrors
}) {
return async (content, attrs) => {
var _a;
const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
const id = `${filename}?astro&type=style&lang${lang}`;
try {
const result = await preprocessCSS(content, id, viteConfig);
(_a = result.deps) == null ? void 0 : _a.forEach((dep) => {
cssDeps.add(dep);
});
let map;
if (result.map) {
if (typeof result.map === "string") {
map = result.map;
} else if (result.map.mappings) {
map = result.map.toString();
}
}
return { code: result.code, map };
} catch (err) {
try {
err = enhanceCSSError(err, filename, content);
} catch {
}
cssTransformErrors.push(err);
return { error: err + "" };
}
};
}
function enhanceCSSError(err, filename, cssContent) {
const fileContent = fs.readFileSync(filename).toString();
const styleTagBeginning = fileContent.indexOf(cssContent);
if (err.name === "CssSyntaxError") {
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
return new CSSError({
...AstroErrorData.CSSSyntaxError,
message: err.reason,
location: {
file: filename,
line: errorLine,
column: err.column
},
stack: err.stack
});
}
if (err.line && err.column) {
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
return new CSSError({
...AstroErrorData.UnknownCSSError,
message: err.message,
location: {
file: filename,
line: errorLine,
column: err.column
},
frame: err.frame,
stack: err.stack
});
}
const errorPosition = positionAt(styleTagBeginning, fileContent);
errorPosition.line += 1;
return new CSSError({
message: err.message,
location: {
file: filename,
line: errorPosition.line,
column: 0
},
frame: err.frame,
stack: err.stack
});
}
export {
createStylePreprocessor
};

7
node_modules/astro/dist/core/compile/types.d.ts generated vendored Normal file
View file

@ -0,0 +1,7 @@
import type { SourceMap } from 'rollup';
export type TransformStyleResult = null | {
code: string;
map: SourceMap | null;
deps: Set<string>;
};
export type TransformStyle = (source: string, lang: string) => TransformStyleResult | Promise<TransformStyleResult>;

0
node_modules/astro/dist/core/compile/types.js generated vendored Normal file
View file