[ci] format

This commit is contained in:
matthewp 2022-05-11 15:25:30 +00:00 committed by github-actions[bot]
parent 74510a9607
commit 380acd23de
3 changed files with 18 additions and 15 deletions

View file

@ -88,9 +88,9 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg
const mods = ctx.modules.filter((m) => !m.url.endsWith('='));
// Add hoisted scripts so these get invalidated
for(const mod of mods) {
for(const imp of mod.importedModules) {
if(imp.id?.includes('?astro&type=script')) {
for (const mod of mods) {
for (const imp of mod.importedModules) {
if (imp.id?.includes('?astro&type=script')) {
mods.push(imp);
}
}

View file

@ -127,9 +127,9 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
throw new Error(`Requests for hoisted scripts must include an index`);
}
// HMR hoisted script only exists to make them appear in the module graph.
if(opts?.ssr) {
if (opts?.ssr) {
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;
while(i < transformResult.scripts.length) {
while (i < transformResult.scripts.length) {
deps.add(`${id}?astro&type=script&index=${i}`);
SUFFIX += `import "${id}?astro&type=script&index=${i}";`;
i++;
}
// We only need to define deps if there are any
if(deps.size > 1) {
SUFFIX += `\nif(import.meta.hot) import.meta.hot.accept(["${id}", "${Array.from(deps).join('","')}"], (...mods) => mods);`
if (deps.size > 1) {
SUFFIX += `\nif(import.meta.hot) import.meta.hot.accept(["${id}", "${Array.from(
deps
).join('","')}"], (...mods) => mods);`;
} else {
SUFFIX += `\nif (import.meta.hot) {
import.meta.hot.accept(mod => mod);

View file

@ -22,7 +22,6 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig
''
);
const privateKeys = Object.keys(fullEnv).filter((key) => {
// don't inject `PUBLIC_` variables, Vite handles that for us
for (const envPrefix of envPrefixes) {
if (key.startsWith(envPrefix)) return false;
@ -34,10 +33,12 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig
if (privateKeys.length === 0) {
return null;
}
return Object.fromEntries(privateKeys.map((key) => {
if (typeof process.env[key] !== 'undefined') return [key, `process.env.${key}`];
return [key, JSON.stringify(fullEnv[key])]
}));
return Object.fromEntries(
privateKeys.map((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> {