@spyglassmc/core 0.4.13 → 0.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,9 +80,6 @@ class BrowserFileSystem {
80
80
  async chmod(_location, _mode) {
81
81
  return;
82
82
  }
83
- async getAllFiles(_location) {
84
- return [];
85
- }
86
83
  async mkdir(location, _options) {
87
84
  location = fileUtil.ensureEndingSlash(location.toString());
88
85
  if (this.states[location]) {
@@ -91,6 +88,10 @@ class BrowserFileSystem {
91
88
  this.states[location] = { type: 'directory' };
92
89
  this.saveStates();
93
90
  }
91
+ async readdir(_location) {
92
+ // Not implemented
93
+ return [];
94
+ }
94
95
  async readFile(location) {
95
96
  location = location.toString();
96
97
  const entry = this.states[location];
@@ -2,7 +2,6 @@
2
2
  import chokidar from 'chokidar';
3
3
  import decompress from 'decompress';
4
4
  import followRedirects from 'follow-redirects';
5
- import globby from 'globby';
6
5
  import { Buffer } from 'node:buffer';
7
6
  import cp from 'node:child_process';
8
7
  import crypto from 'node:crypto';
@@ -72,14 +71,12 @@ export const NodeJsExternals = {
72
71
  chmod(location, mode) {
73
72
  return fsp.chmod(toFsPathLike(location), mode);
74
73
  },
75
- async getAllFiles(location, depth) {
76
- const path = toPath(location).replaceAll('\\', '/') + '**/*';
77
- const files = await globby(path, { absolute: true, dot: true, deep: depth });
78
- return files.map(uriFromPath);
79
- },
80
74
  async mkdir(location, options) {
81
75
  return void (await fsp.mkdir(toFsPathLike(location), options));
82
76
  },
77
+ readdir(location) {
78
+ return fsp.readdir(toFsPathLike(location), { encoding: 'utf-8', withFileTypes: true });
79
+ },
83
80
  readFile(location) {
84
81
  return fsp.readFile(toFsPathLike(location));
85
82
  },
@@ -106,7 +103,10 @@ export const NodeJsExternals = {
106
103
  return fsp.unlink(toFsPathLike(location));
107
104
  },
108
105
  watch(locations, { usePolling = false } = {}) {
109
- return new ChokidarWatcherWrapper(chokidar.watch(locations.map(toPath), { usePolling }));
106
+ return new ChokidarWatcherWrapper(chokidar.watch(locations.map(toPath), {
107
+ usePolling,
108
+ disableGlobbing: true,
109
+ }));
110
110
  },
111
111
  writeFile(location, data, options) {
112
112
  return fsp.writeFile(toFsPathLike(location), data, options);
@@ -49,10 +49,6 @@ export interface ExternalFileSystem {
49
49
  * @param mode File mode bit mask (e.g. `0o775`).
50
50
  */
51
51
  chmod(location: FsLocation, mode: number): Promise<void>;
52
- /**
53
- * @returns an array of file URIs under the given `location`.
54
- */
55
- getAllFiles(location: FsLocation, depth?: number): Promise<string[]>;
56
52
  /**
57
53
  * @param options `mode` - File mode bit mask (e.g. `0o775`).
58
54
  */
@@ -60,6 +56,12 @@ export interface ExternalFileSystem {
60
56
  mode?: number;
61
57
  recursive?: boolean;
62
58
  }): Promise<void>;
59
+ readdir(location: FsLocation): Promise<{
60
+ name: string;
61
+ isDirectory(): boolean;
62
+ isFile(): boolean;
63
+ isSymbolicLink(): boolean;
64
+ }[]>;
63
65
  readFile(location: FsLocation): Promise<Uint8Array>;
64
66
  /**
65
67
  * Show the file/directory in the platform-specific explorer program.
@@ -142,7 +142,7 @@ export class FileUriSupporter {
142
142
  if (fileUtil.isFileUri(uri) && (await externals.fs.stat(uri)).isDirectory()) {
143
143
  uri = fileUtil.ensureEndingSlash(uri);
144
144
  roots.push(uri);
145
- files.set(uri, await externals.fs.getAllFiles(uri));
145
+ files.set(uri, await fileUtil.getAllFiles(externals, uri));
146
146
  }
147
147
  }
148
148
  catch (e) {
@@ -34,9 +34,6 @@ export declare namespace fileUtil {
34
34
  function isRootUri(uri: string): uri is RootUriString;
35
35
  function ensureEndingSlash(uri: string): RootUriString;
36
36
  function join(fromUri: string, toUri: string): string;
37
- /**
38
- * @throws If `uri` is not a valid URI.
39
- */
40
37
  function isFileUri(uri: string): boolean;
41
38
  /**
42
39
  * @returns The part from the last `.` to the end of the URI, or `undefined` if no dots exist. No special treatment for leading dots.
@@ -63,6 +60,10 @@ export declare namespace fileUtil {
63
60
  function ensureParentOfFile(externals: Externals, path: FsLocation, mode?: number): Promise<void>;
64
61
  function chmod(externals: Externals, path: FsLocation, mode: number): Promise<void>;
65
62
  function ensureWritable(externals: Externals, path: FsLocation): Promise<void>;
63
+ /**
64
+ * @returns An array of file URI strings.
65
+ */
66
+ function getAllFiles(externals: Externals, root: FsLocation, depth?: number): Promise<string[]>;
66
67
  function markReadOnly(externals: Externals, path: FsLocation): Promise<void>;
67
68
  function unlink(externals: Externals, path: FsLocation): Promise<void>;
68
69
  function readFile(externals: Externals, path: FsLocation): Promise<Uint8Array>;
@@ -72,9 +72,6 @@ export var fileUtil;
72
72
  return (ensureEndingSlash(fromUri) + (toUri.startsWith('/') ? toUri.slice(1) : toUri));
73
73
  }
74
74
  fileUtil.join = join;
75
- /**
76
- * @throws If `uri` is not a valid URI.
77
- */
78
75
  function isFileUri(uri) {
79
76
  return uri.startsWith('file:');
80
77
  }
@@ -144,6 +141,31 @@ export var fileUtil;
144
141
  }
145
142
  }
146
143
  fileUtil.ensureWritable = ensureWritable;
144
+ /**
145
+ * @returns An array of file URI strings.
146
+ */
147
+ async function getAllFiles(externals, root, depth = Number.POSITIVE_INFINITY) {
148
+ async function walk(path, level) {
149
+ if (level > depth) {
150
+ return [];
151
+ }
152
+ const entries = await externals.fs.readdir(path);
153
+ return (await Promise.all(entries.map(async (e) => {
154
+ const entryPath = fileUtil.join(path.toString(), e.name);
155
+ if (e.isDirectory()) {
156
+ return await walk(entryPath, level + 1);
157
+ }
158
+ else if (e.isFile()) {
159
+ return entryPath;
160
+ }
161
+ else {
162
+ return [];
163
+ }
164
+ }))).flat();
165
+ }
166
+ return walk(root, 0);
167
+ }
168
+ fileUtil.getAllFiles = getAllFiles;
147
169
  async function markReadOnly(externals, path) {
148
170
  return chmod(externals, path, 0o444);
149
171
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/core",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,7 +19,6 @@
19
19
  "chokidar": "^3.5.2",
20
20
  "decompress": "^4.2.1",
21
21
  "follow-redirects": "^1.14.8",
22
- "globby": "^11.0.4",
23
22
  "ignore": "^5.3.1",
24
23
  "pako": "^2.0.4",
25
24
  "rfdc": "^1.3.0",