diff --git a/packages/astro/src/vite-plugin-load-fallback/index.ts b/packages/astro/src/vite-plugin-load-fallback/index.ts index f77f35152..372ca2d9d 100644 --- a/packages/astro/src/vite-plugin-load-fallback/index.ts +++ b/packages/astro/src/vite-plugin-load-fallback/index.ts @@ -1,8 +1,7 @@ -import type { AstroSettings } from '../@types/astro'; -import type * as vite from 'vite'; import nodeFs from 'fs'; import npath from 'path'; - +import type * as vite from 'vite'; +import type { AstroSettings } from '../@types/astro'; type NodeFileSystemModule = typeof nodeFs; @@ -11,7 +10,10 @@ export interface LoadFallbackPluginParams { settings: AstroSettings; } -export default function loadFallbackPlugin({ fs, settings }: LoadFallbackPluginParams): vite.Plugin[] | false { +export default function loadFallbackPlugin({ + fs, + settings, +}: LoadFallbackPluginParams): vite.Plugin[] | false { // Only add this plugin if a custom fs implementation is provided. if (!fs || fs === nodeFs) { return false; @@ -35,31 +37,34 @@ export default function loadFallbackPlugin({ fs, settings }: LoadFallbackPluginP } }; - return [{ - name: 'astro:load-fallback', - enforce: 'post', - resolveId(id, parent) { - if(id.startsWith('.') && parent && fs.existsSync(parent)) { - return npath.posix.join(npath.posix.dirname(parent), id); - } + return [ + { + name: 'astro:load-fallback', + enforce: 'post', + resolveId(id, parent) { + if (id.startsWith('.') && parent && fs.existsSync(parent)) { + return npath.posix.join(npath.posix.dirname(parent), id); + } + }, + async load(id) { + const source = await tryLoadModule(id); + return source; + }, }, - async load(id) { - const source = await tryLoadModule(id); - return source; - } - }, { - name: 'astro:load-fallback-hmr', - enforce: 'pre', - handleHotUpdate(context) { - // Wrap context.read so it checks our filesystem first. - const read = context.read; - context.read = async () => { - const source = await tryLoadModule(context.file); - if(source) return source; - return read.call(context); - }; - } - }]; + { + name: 'astro:load-fallback-hmr', + enforce: 'pre', + handleHotUpdate(context) { + // Wrap context.read so it checks our filesystem first. + const read = context.read; + context.read = async () => { + const source = await tryLoadModule(context.file); + if (source) return source; + return read.call(context); + }; + }, + }, + ]; } const queryRE = /\?.*$/s; diff --git a/packages/astro/test/units/dev/dev.test.js b/packages/astro/test/units/dev/dev.test.js index 2d45eb354..b8159e5b7 100644 --- a/packages/astro/test/units/dev/dev.test.js +++ b/packages/astro/test/units/dev/dev.test.js @@ -70,12 +70,17 @@ describe('dev container', () => { let $ = cheerio.load(html); expect($('body.one')).to.have.a.lengthOf(1); - fs.writeFileFromRootSync('/src/components/Header.astro', ` + fs.writeFileFromRootSync( + '/src/components/Header.astro', + `