Fix check CLI fs load fallback behaviour (#6811)

This commit is contained in:
Bjorn Lu 2023-04-11 11:57:11 +08:00 committed by GitHub
parent c12ca5ece3
commit 60c16db6ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix check CLI fs load fallback behaviour

View file

@ -6,7 +6,7 @@ import {
} from '@astrojs/language-server'; } from '@astrojs/language-server';
import type { FSWatcher } from 'chokidar'; import type { FSWatcher } from 'chokidar';
import glob from 'fast-glob'; import glob from 'fast-glob';
import fsMod, * as fs from 'fs'; import fs from 'fs';
import { bold, dim, red, yellow } from 'kleur/colors'; import { bold, dim, red, yellow } from 'kleur/colors';
import { createRequire } from 'module'; import { createRequire } from 'module';
import { join } from 'node:path'; import { join } from 'node:path';
@ -136,7 +136,7 @@ type CheckerConstructor = {
logging: Readonly<LogOptions>; logging: Readonly<LogOptions>;
fileSystem: typeof fsMod; fileSystem: typeof fs;
}; };
/** /**
@ -153,7 +153,7 @@ export class AstroChecker {
readonly #settings: AstroSettings; readonly #settings: AstroSettings;
readonly #logging: LogOptions; readonly #logging: LogOptions;
readonly #fs: typeof fsMod; readonly #fs: typeof fs;
#watcher?: FSWatcher; #watcher?: FSWatcher;
#filesCount: number; #filesCount: number;

View file

@ -15,7 +15,10 @@ export default function loadFallbackPlugin({
root, root,
}: LoadFallbackPluginParams): vite.Plugin[] | false { }: LoadFallbackPluginParams): vite.Plugin[] | false {
// Only add this plugin if a custom fs implementation is provided. // 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; return false;
} }
@ -53,12 +56,6 @@ export default function loadFallbackPlugin({
} }
} catch {} } catch {}
} }
let resolved = await this.resolve(id, parent, { skipSelf: true });
if (resolved) {
return resolved.id;
}
return slashify(id);
}, },
async load(id) { async load(id) {
const source = await tryLoadModule(id); const source = await tryLoadModule(id);