Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
bholmesdev
f6dcde653c fix: append forward slash for reasons 2022-09-06 18:09:22 -04:00
2 changed files with 6 additions and 15 deletions

View file

@ -22,6 +22,7 @@ export async function handleHotUpdate(
ctx: HmrContext,
{ config, logging, compile }: HandleHotUpdateOptions
) {
const importedModules = ctx.server.moduleGraph.getModuleById(ctx.file)?.importedModules ?? []
let isStyleOnlyChange = false;
if (ctx.file.endsWith('.astro')) {
// Get the compiled result from the cache
@ -54,9 +55,9 @@ export async function handleHotUpdate(
// go through each of these modules importers and invalidate any .astro compilation
// that needs to be rerun.
const filtered = new Set<ModuleNode>(ctx.modules);
const filtered = new Set<ModuleNode>(importedModules);
const files = new Set<string>();
for (const mod of ctx.modules) {
for (const mod of importedModules) {
// Skip monorepo files to avoid console spam
if (isPkgFile(mod.id ?? mod.file)) {
filtered.delete(mod);

View file

@ -8,7 +8,7 @@ import ancestor from 'common-ancestor-path';
import esbuild from 'esbuild';
import slash from 'slash';
import { fileURLToPath } from 'url';
import { isRelativePath, startsWithForwardSlash } from '../core/path.js';
import { isRelativePath, prependForwardSlash, startsWithForwardSlash } from '../core/path.js';
import { getFileInfo } from '../vite-plugin-utils/index.js';
import { cachedCompilation, CompileProps, getCachedSource } from './compile.js';
import { handleHotUpdate } from './hmr.js';
@ -106,7 +106,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
if (!raw) {
return null;
}
let source = getCachedSource(config, raw.id);
if (!source) {
return null;
@ -246,19 +246,9 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
)};export { $$file as file, $$url as url };\n`;
// Add HMR handling in dev mode.
if (!resolvedConfig.isProduction) {
// HACK: extract dependencies from metadata until compiler static extraction handles them
const metadata = transformResult.code.split('$$createMetadata(')[1].split('});\n')[0];
const pattern = /specifier:\s*'([^']*)'/g;
const deps = new Set();
let match;
while ((match = pattern.exec(metadata)?.[1])) {
deps.add(match);
}
let i = 0;
while (i < transformResult.scripts.length) {
deps.add(`${id}?astro&type=script&index=${i}&lang.ts`);
SUFFIX += `import "${id}?astro&type=script&index=${i}&lang.ts";`;
SUFFIX += `import "${isRelativePath(id) ? id : prependForwardSlash(id)}?astro&type=script&index=${i}&lang.ts";`;
i++;
}
}