From 60c16db6ff583b0656bc1937814c8bbf06831294 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 11 Apr 2023 11:57:11 +0800 Subject: [PATCH] Fix check CLI fs load fallback behaviour (#6811) --- .changeset/angry-experts-compete.md | 5 +++++ packages/astro/src/cli/check/index.ts | 6 +++--- packages/astro/src/vite-plugin-load-fallback/index.ts | 11 ++++------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .changeset/angry-experts-compete.md diff --git a/.changeset/angry-experts-compete.md b/.changeset/angry-experts-compete.md new file mode 100644 index 000000000000..4abd5aad13c4 --- /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 2c7f9bb4dbe2..07648aabe0c3 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 86346421c762..7c853245be34 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);