full site update
This commit is contained in:
34
node_modules/astro/dist/env/sync.js
generated
vendored
34
node_modules/astro/dist/env/sync.js
generated
vendored
@@ -1,15 +1,10 @@
|
||||
import fsMod from "node:fs";
|
||||
import { TYPES_TEMPLATE_URL } from "./constants.js";
|
||||
import { ENV_TYPES_FILE } from "./constants.js";
|
||||
import { getEnvFieldType } from "./validators.js";
|
||||
function syncAstroEnv(settings, fs = fsMod) {
|
||||
if (!settings.config.experimental.env) {
|
||||
return;
|
||||
}
|
||||
const schema = settings.config.experimental.env.schema ?? {};
|
||||
function syncAstroEnv(settings) {
|
||||
let client = "";
|
||||
let server = "";
|
||||
for (const [key, options] of Object.entries(schema)) {
|
||||
const str = `export const ${key}: ${getEnvFieldType(options)};
|
||||
for (const [key, options] of Object.entries(settings.config.env.schema)) {
|
||||
const str = ` export const ${key}: ${getEnvFieldType(options)};
|
||||
`;
|
||||
if (options.context === "client") {
|
||||
client += str;
|
||||
@@ -17,12 +12,21 @@ function syncAstroEnv(settings, fs = fsMod) {
|
||||
server += str;
|
||||
}
|
||||
}
|
||||
const template = fs.readFileSync(TYPES_TEMPLATE_URL, "utf-8");
|
||||
const content = template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
|
||||
settings.injectedTypes.push({
|
||||
filename: "astro/env.d.ts",
|
||||
content
|
||||
});
|
||||
let content = "";
|
||||
if (client !== "") {
|
||||
content = `declare module 'astro:env/client' {
|
||||
${client}}`;
|
||||
}
|
||||
if (server !== "") {
|
||||
content += `declare module 'astro:env/server' {
|
||||
${server}}`;
|
||||
}
|
||||
if (content !== "") {
|
||||
settings.injectedTypes.push({
|
||||
filename: ENV_TYPES_FILE,
|
||||
content
|
||||
});
|
||||
}
|
||||
}
|
||||
export {
|
||||
syncAstroEnv
|
||||
|
Reference in New Issue
Block a user