summaryrefslogtreecommitdiff
path: root/packages/astro/src/vite-plugin-load-fallback/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/src/vite-plugin-load-fallback/index.ts')
-rw-r--r--packages/astro/src/vite-plugin-load-fallback/index.ts39
1 files changed, 19 insertions, 20 deletions
diff --git a/packages/astro/src/vite-plugin-load-fallback/index.ts b/packages/astro/src/vite-plugin-load-fallback/index.ts
index 6a6af9142..f0a983993 100644
--- a/packages/astro/src/vite-plugin-load-fallback/index.ts
+++ b/packages/astro/src/vite-plugin-load-fallback/index.ts
@@ -1,5 +1,5 @@
-import type * as vite from 'vite';
import nodeFs from 'fs';
+import type * as vite from 'vite';
type NodeFileSystemModule = typeof nodeFs;
@@ -9,30 +9,29 @@ export interface LoadFallbackPluginParams {
export default function loadFallbackPlugin({ fs }: LoadFallbackPluginParams): vite.Plugin | false {
// Only add this plugin if a custom fs implementation is provided.
- if(!fs || fs === nodeFs) {
+ if (!fs || fs === nodeFs) {
return false;
}
- return {
- name: 'astro:load-fallback',
- enforce: 'post',
- async load(id) {
- try {
- // await is necessary for the catch
- return await fs.promises.readFile(cleanUrl(id), 'utf-8')
- } catch (e) {
- try {
- return await fs.promises.readFile(id, 'utf-8');
- } catch(e2) {
- // Let fall through to the next
- }
- }
- }
- }
+ return {
+ name: 'astro:load-fallback',
+ enforce: 'post',
+ async load(id) {
+ try {
+ // await is necessary for the catch
+ return await fs.promises.readFile(cleanUrl(id), 'utf-8');
+ } catch (e) {
+ try {
+ return await fs.promises.readFile(id, 'utf-8');
+ } catch (e2) {
+ // Let fall through to the next
+ }
+ }
+ },
+ };
}
const queryRE = /\?.*$/s;
const hashRE = /#.*$/s;
-const cleanUrl = (url: string): string =>
- url.replace(hashRE, '').replace(queryRE, '');
+const cleanUrl = (url: string): string => url.replace(hashRE, '').replace(queryRE, '');