Skip to content

Commit b136e56

Browse files
authored
perf(styles): use fsp.access and rethrow legitimate errors (#308)
1 parent 0382328 commit b136e56

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/vite/vuetify-styles-plugin.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import process from 'node:process'
22
import { pathToFileURL } from 'node:url'
3-
import { existsSync } from 'node:fs'
3+
import fs from 'node:fs'
4+
import fsp from 'node:fs/promises'
45
import type { Plugin } from 'vite'
56
import { isObject, normalizePath, resolveVuetifyBase } from '@vuetify/loader-shared'
67
import { isAbsolute, relative as relativePath } from 'pathe'
@@ -66,13 +67,13 @@ export function vuetifyStylesPlugin(
6667
)
6768
) {
6869
if (options.styles === 'sass')
69-
return this.resolve(resolveCss(source), importer, { skipSelf: true, custom })
70+
return this.resolve(await resolveCss(source), importer, { skipSelf: true, custom })
7071

7172
const resolution = await this.resolve(source, importer, { skipSelf: true, custom })
7273
if (!resolution)
7374
return undefined
7475

75-
const target = resolveCss(resolution.id)
76+
const target = await resolveCss(resolution.id)
7677
if (isNone) {
7778
noneFiles.add(target)
7879
return target
@@ -108,15 +109,16 @@ export function vuetifyStylesPlugin(
108109

109110
function resolveCssFactory() {
110111
const mappings = new Map<string, string>()
111-
return (source: string) => {
112+
return async (source: string) => {
112113
let mapping = mappings.get(source)
113114
if (!mapping) {
114115
try {
115116
mapping = source.replace(/\.css$/, '.sass')
116-
if (!existsSync(mapping))
117-
mapping = source.replace(/\.css$/, '.scss')
117+
await fsp.access(mapping, fs.constants.R_OK)
118118
}
119-
catch {
119+
catch (err) {
120+
if (!(err instanceof Error && 'code' in err && err.code === 'ENOENT'))
121+
throw err
120122
mapping = source.replace(/\.css$/, '.scss')
121123
}
122124
mappings.set(source, mapping)

0 commit comments

Comments
 (0)