mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
74510a9607
commit
380acd23de
3 changed files with 18 additions and 15 deletions
|
@ -68,7 +68,7 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg
|
||||||
filtered.add(mod);
|
filtered.add(mod);
|
||||||
files.add(mod.file);
|
files.add(mod.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const imp of mod.importers) {
|
for (const imp of mod.importers) {
|
||||||
if (imp.file && isCached(config, imp.file)) {
|
if (imp.file && isCached(config, imp.file)) {
|
||||||
filtered.add(imp);
|
filtered.add(imp);
|
||||||
|
@ -88,9 +88,9 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg
|
||||||
const mods = ctx.modules.filter((m) => !m.url.endsWith('='));
|
const mods = ctx.modules.filter((m) => !m.url.endsWith('='));
|
||||||
|
|
||||||
// Add hoisted scripts so these get invalidated
|
// Add hoisted scripts so these get invalidated
|
||||||
for(const mod of mods) {
|
for (const mod of mods) {
|
||||||
for(const imp of mod.importedModules) {
|
for (const imp of mod.importedModules) {
|
||||||
if(imp.id?.includes('?astro&type=script')) {
|
if (imp.id?.includes('?astro&type=script')) {
|
||||||
mods.push(imp);
|
mods.push(imp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,9 +127,9 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
throw new Error(`Requests for hoisted scripts must include an index`);
|
throw new Error(`Requests for hoisted scripts must include an index`);
|
||||||
}
|
}
|
||||||
// HMR hoisted script only exists to make them appear in the module graph.
|
// HMR hoisted script only exists to make them appear in the module graph.
|
||||||
if(opts?.ssr) {
|
if (opts?.ssr) {
|
||||||
return {
|
return {
|
||||||
code: `/* client hoisted script, empty in SSR: ${id} */`
|
code: `/* client hoisted script, empty in SSR: ${id} */`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,15 +190,17 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while(i < transformResult.scripts.length) {
|
while (i < transformResult.scripts.length) {
|
||||||
deps.add(`${id}?astro&type=script&index=${i}`);
|
deps.add(`${id}?astro&type=script&index=${i}`);
|
||||||
SUFFIX += `import "${id}?astro&type=script&index=${i}";`;
|
SUFFIX += `import "${id}?astro&type=script&index=${i}";`;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only need to define deps if there are any
|
// We only need to define deps if there are any
|
||||||
if(deps.size > 1) {
|
if (deps.size > 1) {
|
||||||
SUFFIX += `\nif(import.meta.hot) import.meta.hot.accept(["${id}", "${Array.from(deps).join('","')}"], (...mods) => mods);`
|
SUFFIX += `\nif(import.meta.hot) import.meta.hot.accept(["${id}", "${Array.from(
|
||||||
|
deps
|
||||||
|
).join('","')}"], (...mods) => mods);`;
|
||||||
} else {
|
} else {
|
||||||
SUFFIX += `\nif (import.meta.hot) {
|
SUFFIX += `\nif (import.meta.hot) {
|
||||||
import.meta.hot.accept(mod => mod);
|
import.meta.hot.accept(mod => mod);
|
||||||
|
@ -209,7 +211,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
if (isPage) {
|
if (isPage) {
|
||||||
SUFFIX += `\nimport "${PAGE_SSR_SCRIPT_ID}";`;
|
SUFFIX += `\nimport "${PAGE_SSR_SCRIPT_ID}";`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: `${code}${SUFFIX}`,
|
code: `${code}${SUFFIX}`,
|
||||||
map,
|
map,
|
||||||
|
|
|
@ -22,7 +22,6 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
const privateKeys = Object.keys(fullEnv).filter((key) => {
|
const privateKeys = Object.keys(fullEnv).filter((key) => {
|
||||||
|
|
||||||
// don't inject `PUBLIC_` variables, Vite handles that for us
|
// don't inject `PUBLIC_` variables, Vite handles that for us
|
||||||
for (const envPrefix of envPrefixes) {
|
for (const envPrefix of envPrefixes) {
|
||||||
if (key.startsWith(envPrefix)) return false;
|
if (key.startsWith(envPrefix)) return false;
|
||||||
|
@ -34,10 +33,12 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig
|
||||||
if (privateKeys.length === 0) {
|
if (privateKeys.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Object.fromEntries(privateKeys.map((key) => {
|
return Object.fromEntries(
|
||||||
if (typeof process.env[key] !== 'undefined') return [key, `process.env.${key}`];
|
privateKeys.map((key) => {
|
||||||
return [key, JSON.stringify(fullEnv[key])]
|
if (typeof process.env[key] !== 'undefined') return [key, `process.env.${key}`];
|
||||||
}));
|
return [key, JSON.stringify(fullEnv[key])];
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReferencedPrivateKeys(source: string, privateEnv: Record<string, any>): Set<string> {
|
function getReferencedPrivateKeys(source: string, privateEnv: Record<string, any>): Set<string> {
|
||||||
|
|
Loading…
Reference in a new issue