@statewalker/webrun-files-browser 0.7.1 → 0.9.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-2026 statewalker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1 @@
1
- {"version":3,"file":"browser-files-api.d.ts","sourceRoot":"","sources":["../src/browser-files-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAQnC,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,UAAU,EAAE,yBAAyB,CAAC;CACvC;AAED;;;;;;GAMG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAC9C,OAAO,CAAC,UAAU,CAA4B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AMG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAC9C,OAAO,CAAC,UAAU,CAA4B;IAE9C,YAAY,OAAO,EAAE,sBAAsB,EAE1C;YAEa,kBAAkB;YAkBlB,aAAa;IAkBpB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,UAAU,CAAC,CA2B1E;IAEK,KAAK,CACT,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAoBf;IAEK,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvC;IAEM,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,CA0CxE;IAEK,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CA6BxD;IAEK,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG3C;IAEK,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAc3C;IAEK,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA8B3D;IAEK,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA2E3D;CACF;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,eAAe,CAAC,CAGhE"}
@@ -83,27 +83,34 @@ var BrowserFilesApi = class {
83
83
  for await (const [name, handle] of dirHandle.entries()) {
84
84
  const entryPath = (0, _statewalker_webrun_files.joinPath)(normalized, name);
85
85
  const isDirectory = handle.kind === "directory";
86
- const info = {
87
- kind: isDirectory ? "directory" : "file",
86
+ let info;
87
+ if (isDirectory) info = {
88
+ kind: "directory",
88
89
  name,
89
- path: entryPath,
90
- lastModified: 0
90
+ path: entryPath
91
91
  };
92
- if (!isDirectory) try {
93
- const file = await handle.getFile();
94
- info.size = file.size;
95
- info.lastModified = file.lastModified;
96
- } catch {}
92
+ else {
93
+ let file;
94
+ try {
95
+ file = await handle.getFile();
96
+ } catch {
97
+ continue;
98
+ }
99
+ info = {
100
+ kind: "file",
101
+ name,
102
+ path: entryPath,
103
+ size: file.size,
104
+ lastModified: file.lastModified
105
+ };
106
+ }
97
107
  yield info;
98
108
  if (recursive && isDirectory) yield* this.list(entryPath, options);
99
109
  }
100
110
  }
101
111
  async stats(path) {
102
112
  const normalized = (0, _statewalker_webrun_files.normalizePath)(path);
103
- if (normalized === "/") return {
104
- kind: "directory",
105
- lastModified: 0
106
- };
113
+ if (normalized === "/") return { kind: "directory" };
107
114
  const fileHandle = await this.getFileHandle(normalized);
108
115
  if (fileHandle) try {
109
116
  const f = await fileHandle.getFile();
@@ -115,10 +122,7 @@ var BrowserFilesApi = class {
115
122
  } catch {
116
123
  return;
117
124
  }
118
- if (await this.getDirectoryHandle(normalized)) return {
119
- kind: "directory",
120
- lastModified: 0
121
- };
125
+ if (await this.getDirectoryHandle(normalized)) return { kind: "directory" };
122
126
  }
123
127
  async exists(path) {
124
128
  return await this.stats(path) !== void 0;
package/dist/esm/index.js CHANGED
@@ -82,27 +82,34 @@ var BrowserFilesApi = class {
82
82
  for await (const [name, handle] of dirHandle.entries()) {
83
83
  const entryPath = joinPath(normalized, name);
84
84
  const isDirectory = handle.kind === "directory";
85
- const info = {
86
- kind: isDirectory ? "directory" : "file",
85
+ let info;
86
+ if (isDirectory) info = {
87
+ kind: "directory",
87
88
  name,
88
- path: entryPath,
89
- lastModified: 0
89
+ path: entryPath
90
90
  };
91
- if (!isDirectory) try {
92
- const file = await handle.getFile();
93
- info.size = file.size;
94
- info.lastModified = file.lastModified;
95
- } catch {}
91
+ else {
92
+ let file;
93
+ try {
94
+ file = await handle.getFile();
95
+ } catch {
96
+ continue;
97
+ }
98
+ info = {
99
+ kind: "file",
100
+ name,
101
+ path: entryPath,
102
+ size: file.size,
103
+ lastModified: file.lastModified
104
+ };
105
+ }
96
106
  yield info;
97
107
  if (recursive && isDirectory) yield* this.list(entryPath, options);
98
108
  }
99
109
  }
100
110
  async stats(path) {
101
111
  const normalized = normalizePath(path);
102
- if (normalized === "/") return {
103
- kind: "directory",
104
- lastModified: 0
105
- };
112
+ if (normalized === "/") return { kind: "directory" };
106
113
  const fileHandle = await this.getFileHandle(normalized);
107
114
  if (fileHandle) try {
108
115
  const f = await fileHandle.getFile();
@@ -114,10 +121,7 @@ var BrowserFilesApi = class {
114
121
  } catch {
115
122
  return;
116
123
  }
117
- if (await this.getDirectoryHandle(normalized)) return {
118
- kind: "directory",
119
- lastModified: 0
120
- };
124
+ if (await this.getDirectoryHandle(normalized)) return { kind: "directory" };
121
125
  }
122
126
  async exists(path) {
123
127
  return await this.stats(path) !== void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/webrun-files-browser",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Browser File System Access API implementation for webrun-files",
@@ -28,26 +28,25 @@
28
28
  "dist",
29
29
  "src"
30
30
  ],
31
- "scripts": {
32
- "build": "rimraf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
33
- "test": "vitest run",
34
- "lint": "biome lint src tests",
35
- "prepublishOnly": "pnpm run build"
36
- },
37
31
  "dependencies": {
38
- "@statewalker/webrun-files": "workspace:*"
32
+ "@statewalker/webrun-files": "^0.9.0"
39
33
  },
40
34
  "devDependencies": {
41
- "@statewalker/webrun-files-tests": "workspace:*",
42
- "@types/node": "catalog:",
35
+ "@types/node": "^26.2.0",
43
36
  "native-file-system-adapter": "^3.0.1",
44
- "rimraf": "catalog:",
45
- "rolldown": "catalog:",
46
- "typescript": "catalog:",
47
- "vitest": "catalog:"
37
+ "rimraf": "^6.1.3",
38
+ "rolldown": "^1.2.4",
39
+ "typescript": "^7.0.2",
40
+ "vitest": "^4.1.10",
41
+ "@statewalker/webrun-files-tests": "2.0.0"
48
42
  },
49
43
  "sideEffects": false,
50
44
  "publishConfig": {
51
45
  "access": "public"
46
+ },
47
+ "scripts": {
48
+ "build": "rimraf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
49
+ "test": "vitest run",
50
+ "lint": "biome lint src tests"
52
51
  }
53
- }
52
+ }
@@ -147,22 +147,29 @@ export class BrowserFilesApi implements FilesApi {
147
147
  const entryPath = joinPath(normalized, name);
148
148
  const isDirectory = handle.kind === "directory";
149
149
 
150
- const info: FileInfo = {
151
- kind: isDirectory ? "directory" : "file",
152
- name,
153
- path: entryPath,
154
- lastModified: 0,
155
- };
156
-
157
- if (!isDirectory) {
150
+ let info: FileInfo;
151
+ if (isDirectory) {
152
+ info = { kind: "directory", name, path: entryPath };
153
+ } else {
154
+ // A file must report both a size and a time, so the `File` behind the
155
+ // handle has to be obtained before the entry can be yielded at all.
156
+ // `getFile()` rejects when the entry was removed between the directory
157
+ // read and this call, or when permission was revoked mid-iteration;
158
+ // either way there is no file left to describe, and skipping it is
159
+ // the same answer a listing taken a moment later would have given.
160
+ let file: File;
158
161
  try {
159
- const fileHandle = handle as FileSystemFileHandle;
160
- const file = await fileHandle.getFile();
161
- info.size = file.size;
162
- info.lastModified = file.lastModified;
162
+ file = await (handle as FileSystemFileHandle).getFile();
163
163
  } catch {
164
- // Ignore errors getting file metadata
164
+ continue;
165
165
  }
166
+ info = {
167
+ kind: "file",
168
+ name,
169
+ path: entryPath,
170
+ size: file.size,
171
+ lastModified: file.lastModified,
172
+ };
166
173
  }
167
174
 
168
175
  yield info;
@@ -177,10 +184,7 @@ export class BrowserFilesApi implements FilesApi {
177
184
  const normalized = normalizePath(path);
178
185
 
179
186
  if (normalized === "/") {
180
- return {
181
- kind: "directory",
182
- lastModified: 0,
183
- };
187
+ return { kind: "directory" };
184
188
  }
185
189
 
186
190
  // Try as file first
@@ -201,10 +205,7 @@ export class BrowserFilesApi implements FilesApi {
201
205
  // Try as directory
202
206
  const dirHandle = await this.getDirectoryHandle(normalized);
203
207
  if (dirHandle) {
204
- return {
205
- kind: "directory",
206
- lastModified: 0,
207
- };
208
+ return { kind: "directory" };
208
209
  }
209
210
 
210
211
  return undefined;