Skip to content

Commit

Permalink
Fix check CLI fs load fallback behaviour (#6811)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Apr 11, 2023
1 parent c12ca5e commit 60c16db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-experts-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix check CLI fs load fallback behaviour
6 changes: 3 additions & 3 deletions packages/astro/src/cli/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -136,7 +136,7 @@ type CheckerConstructor = {

logging: Readonly<LogOptions>;

fileSystem: typeof fsMod;
fileSystem: typeof fs;
};

/**
Expand All @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions packages/astro/src/vite-plugin-load-fallback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 60c16db

Please sign in to comment.