diff --git a/.changeset/angry-experts-compete.md b/.changeset/angry-experts-compete.md new file mode 100644 index 000000000..4abd5aad1 --- /dev/null +++ b/.changeset/angry-experts-compete.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix check CLI fs load fallback behaviour diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index 2c7f9bb4d..07648aabe 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -6,7 +6,7 @@ import { } from '@astrojs/language-server'; import type { FSWatcher } from 'chokidar'; import glob from 'fast-glob'; -import fsMod, * as fs from 'fs'; +import fs from 'fs'; import { bold, dim, red, yellow } from 'kleur/colors'; import { createRequire } from 'module'; import { join } from 'node:path'; @@ -136,7 +136,7 @@ type CheckerConstructor = { logging: Readonly; - fileSystem: typeof fsMod; + fileSystem: typeof fs; }; /** @@ -153,7 +153,7 @@ export class AstroChecker { readonly #settings: AstroSettings; readonly #logging: LogOptions; - readonly #fs: typeof fsMod; + readonly #fs: typeof fs; #watcher?: FSWatcher; #filesCount: number; diff --git a/packages/astro/src/vite-plugin-load-fallback/index.ts b/packages/astro/src/vite-plugin-load-fallback/index.ts index 86346421c..7c853245b 100644 --- a/packages/astro/src/vite-plugin-load-fallback/index.ts +++ b/packages/astro/src/vite-plugin-load-fallback/index.ts @@ -15,7 +15,10 @@ export default function loadFallbackPlugin({ root, }: LoadFallbackPluginParams): vite.Plugin[] | false { // Only add this plugin if a custom fs implementation is provided. - if (!fs || fs === nodeFs) { + // Also check for `fs.default` because `import * as fs from 'fs'` will + // export as so, which only it's `.default` would === `nodeFs`. + // @ts-expect-error check default + if (!fs || fs === nodeFs || fs.default === nodeFs) { return false; } @@ -53,12 +56,6 @@ export default function loadFallbackPlugin({ } } catch {} } - - let resolved = await this.resolve(id, parent, { skipSelf: true }); - if (resolved) { - return resolved.id; - } - return slashify(id); }, async load(id) { const source = await tryLoadModule(id);