Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Use custom file tree walker instead of globby #1599

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"chokidar": "^3.5.2",
"decompress": "^4.2.1",
"follow-redirects": "^1.14.8",
"globby": "^11.0.4",
"ignore": "^5.3.1",
"pako": "^2.0.4",
"rfdc": "^1.3.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/common/externals/BrowserExternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ class BrowserFileSystem implements ExternalFileSystem {
async chmod(_location: FsLocation, _mode: number): Promise<void> {
return
}
async getAllFiles(_location: FsLocation): Promise<string[]> {
return []
}
async mkdir(
location: FsLocation,
_options?: { mode?: number | undefined; recursive?: boolean | undefined } | undefined,
Expand All @@ -118,6 +115,10 @@ class BrowserFileSystem implements ExternalFileSystem {
this.states[location] = { type: 'directory' }
this.saveStates()
}
async readdir(_location: FsLocation) {
// Not implemented
return []
}
async readFile(location: FsLocation): Promise<Uint8Array> {
location = location.toString()
const entry = this.states[location]
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/common/externals/NodeJsExternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import chokidar from 'chokidar'
import decompress from 'decompress'
import followRedirects from 'follow-redirects'
import globby from 'globby'
import { Buffer } from 'node:buffer'
import cp from 'node:child_process'
import crypto from 'node:crypto'
Expand Down Expand Up @@ -84,14 +83,12 @@ export const NodeJsExternals: Externals = {
chmod(location, mode) {
return fsp.chmod(toFsPathLike(location), mode)
},
async getAllFiles(location, depth) {
const path = toPath(location).replaceAll('\\', '/') + '**/*'
const files = await globby(path, { absolute: true, dot: true, deep: depth })
return files.map(uriFromPath)
},
async mkdir(location, options) {
return void (await fsp.mkdir(toFsPathLike(location), options))
},
readdir(location) {
return fsp.readdir(toFsPathLike(location), { encoding: 'utf-8', withFileTypes: true })
},
readFile(location) {
return fsp.readFile(toFsPathLike(location))
},
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/common/externals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ export interface ExternalFileSystem {
* @param mode File mode bit mask (e.g. `0o775`).
*/
chmod(location: FsLocation, mode: number): Promise<void>
/**
* @returns an array of file URIs under the given `location`.
*/
getAllFiles(location: FsLocation, depth?: number): Promise<string[]>
/**
* @param options `mode` - File mode bit mask (e.g. `0o775`).
*/
mkdir(location: FsLocation, options?: { mode?: number; recursive?: boolean }): Promise<void>
readdir(
location: FsLocation,
): Promise<
{ name: string; isDirectory(): boolean; isFile(): boolean; isSymbolicLink(): boolean }[]
>
readFile(location: FsLocation): Promise<Uint8Array>
/**
* Show the file/directory in the platform-specific explorer program.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/service/FileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class FileUriSupporter implements UriProtocolSupporter {
if (fileUtil.isFileUri(uri) && (await externals.fs.stat(uri)).isDirectory()) {
uri = fileUtil.ensureEndingSlash(uri)
roots.push(uri as RootUriString)
files.set(uri, await externals.fs.getAllFiles(uri))
files.set(uri, await fileUtil.getAllFiles(externals, uri))
}
} catch (e) {
logger.error(`[FileUriSupporter#create] Bad dependency ${uri}`, e)
Expand Down
Loading
Loading