Skip to content

Commit e9665b3

Browse files
committed
Refactor
1 parent 43f9000 commit e9665b3

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import glob from 'fast-glob'
2+
import os from 'node:os'
3+
4+
interface SearchFilesOptions {
5+
/** The directory to search in */
6+
root: string
7+
8+
/** A list of patterns to include */
9+
include: string[]
10+
11+
/** A list of patterns to exclude */
12+
exclude: string[]
13+
}
14+
15+
export async function searchFiles(opts: SearchFilesOptions) {
16+
let results = await glob(opts.include, {
17+
cwd: opts.root,
18+
ignore: opts.exclude,
19+
onlyFiles: true,
20+
absolute: true,
21+
suppressErrors: true,
22+
dot: true,
23+
concurrency: Math.max(os.cpus().length, 1),
24+
})
25+
26+
return results
27+
}

packages/tailwindcss-language-server/src/project-locator.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import * as os from 'node:os'
21
import * as path from 'node:path'
32
import * as fs from 'node:fs/promises'
4-
import glob from 'fast-glob'
53
import picomatch from 'picomatch'
64
import type { Settings } from '@tailwindcss/language-service/src/util/state'
75
import { CONFIG_GLOB, CSS_GLOB } from './lib/constants'
@@ -17,6 +15,7 @@ import { normalizeDriveLetter, normalizePath, pathToFileURL } from './utils'
1715
import postcss from 'postcss'
1816
import * as oxide from './oxide'
1917
import { analyzeStylesheet, TailwindStylesheet } from './version-guesser'
18+
import { searchFiles } from './glob'
2019

2120
export interface ProjectConfig {
2221
/** The folder that contains the project */
@@ -276,14 +275,10 @@ export class ProjectLocator {
276275

277276
private async findConfigs(): Promise<ConfigEntry[]> {
278277
// Look for config files and CSS files
279-
let files = await glob([`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`], {
280-
cwd: this.base,
281-
ignore: this.settings.tailwindCSS.files.exclude,
282-
onlyFiles: true,
283-
absolute: true,
284-
suppressErrors: true,
285-
dot: true,
286-
concurrency: Math.max(os.cpus().length, 1),
278+
let files = await searchFiles({
279+
root: this.base,
280+
include: [`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`],
281+
exclude: this.settings.tailwindCSS.files.exclude,
287282
})
288283

289284
let realpaths = await Promise.all(files.map((file) => fs.realpath(file)))

0 commit comments

Comments
 (0)