Skip to content

Commit d57b6c7

Browse files
committed
some minor fix
1 parent d5bc6e1 commit d57b6c7

File tree

9 files changed

+1321
-1379
lines changed

9 files changed

+1321
-1379
lines changed

jsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"noEmit": false,
4+
"target": "esnext",
5+
"module": "esnext",
6+
"declaration": true,
7+
"allowJs": true,
8+
"checkJs": true,
9+
"removeComments": true,
10+
"emitDeclarationOnly": true,
11+
"outDir": "./types/"
12+
},
13+
"exclude": ["node_modules"],
14+
"include": ["mod.js"]
15+
}

tsconfig.json renamed to old-tsconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"moduleResolution": "node",
34
"noEmit": false,
45
"target": "esnext",
56
"module": "esnext",

package-lock.json

Lines changed: 1255 additions & 1044 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test:deno": "deno run --allow-read --allow-write --allow-net test/test-deno.js",
1616
"test:wpt-in-deno": "deno run --allow-read --allow-write --allow-net test/test-wpt-in-deno.js",
1717
"build": "rm -rf dist && rollup -c rollup.config.js",
18-
"prepublishOnly": "rm -rf types && tsc"
18+
"prepublishOnly": "rm -rf types && tsc -p jsconfig.json"
1919
},
2020
"repository": {
2121
"type": "git",
@@ -55,15 +55,6 @@
5555
"fetch-blob": "^3.1.4",
5656
"node-domexception": "^1.0.0"
5757
},
58-
"devDependencies": {
59-
"@types/filesystem": "^0.0.30",
60-
"rollup": "^2.51.1",
61-
"rollup-plugin-multi-input": "^1.3.1",
62-
"rollup-plugin-terser": "^7.0.2",
63-
"standard": "^16.0.3",
64-
"tape": "^5.2.2",
65-
"typescript": "^4.4.4"
66-
},
6758
"standard": {
6859
"globals": [
6960
"File",
@@ -87,5 +78,14 @@
8778
"type": "paypal",
8879
"url": "https://paypal.me/jimmywarting"
8980
}
90-
]
81+
],
82+
"devDependencies": {
83+
"@types/filesystem": "^0.0.32",
84+
"rollup": "^2.67.3",
85+
"rollup-plugin-multi-input": "^1.3.1",
86+
"rollup-plugin-terser": "^7.0.2",
87+
"standard": "^16.0.4",
88+
"tape": "^5.5.2",
89+
"typescript": "^4.5.5"
90+
}
9191
}

src/FileSystemDirectoryHandle.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,35 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
1818
* @returns {Promise<FileSystemDirectoryHandle>}
1919
*/
2020
async getDirectoryHandle (name, options = {}) {
21-
if (name === '') throw new TypeError(`Name can't be an empty string.`)
22-
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`)
21+
if (name === '') {
22+
throw new TypeError(`Name can't be an empty string.`)
23+
}
24+
if (name === '.' || name === '..' || name.includes('/')) {
25+
throw new TypeError(`Name contains invalid characters.`)
26+
}
2327
options.create = !!options.create
24-
return new FileSystemDirectoryHandle(await this[kAdapter].getDirectoryHandle(name, options))
28+
const handle = await this[kAdapter].getDirectoryHandle(name, options)
29+
return new FileSystemDirectoryHandle(handle)
2530
}
2631

2732
/** @returns {AsyncGenerator<[string, FileSystemHandle | FileSystemDirectoryHandle]>} */
2833
async * entries () {
2934
const {FileSystemFileHandle} = await import('./FileSystemFileHandle.js')
3035

3136
for await (const [_, entry] of this[kAdapter].entries())
32-
yield [entry.name, entry.kind === 'file' ? new FileSystemFileHandle(entry) : new FileSystemDirectoryHandle(entry)]
37+
yield [entry.name, entry.kind === 'file'
38+
? new FileSystemFileHandle(entry)
39+
: new FileSystemDirectoryHandle(entry)]
3340
}
3441

3542
/** @deprecated use .entries() instead */
3643
async * getEntries() {
3744
const {FileSystemFileHandle} = await import('./FileSystemFileHandle.js')
3845
console.warn('deprecated, use .entries() instead')
3946
for await (let entry of this[kAdapter].entries())
40-
yield entry.kind === 'file' ? new FileSystemFileHandle(entry) : new FileSystemDirectoryHandle(entry)
47+
yield entry.kind === 'file'
48+
? new FileSystemFileHandle(entry)
49+
: new FileSystemDirectoryHandle(entry)
4150
}
4251

4352
/**
@@ -48,9 +57,12 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
4857
async getFileHandle (name, options = {}) {
4958
const {FileSystemFileHandle} = await import('./FileSystemFileHandle.js')
5059
if (name === '') throw new TypeError(`Name can't be an empty string.`)
51-
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`)
60+
if (name === '.' || name === '..' || name.includes('/')) {
61+
throw new TypeError(`Name contains invalid characters.`)
62+
}
5263
options.create = !!options.create
53-
return new FileSystemFileHandle(await this[kAdapter].getFileHandle(name, options))
64+
const handle = await this[kAdapter].getFileHandle(name, options)
65+
return new FileSystemFileHandle(handle)
5466
}
5567

5668
/**
@@ -59,13 +71,16 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
5971
* @param {boolean} [options.recursive]
6072
*/
6173
async removeEntry (name, options = {}) {
62-
if (name === '') throw new TypeError(`Name can't be an empty string.`)
63-
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`)
74+
if (name === '') {
75+
throw new TypeError(`Name can't be an empty string.`)
76+
}
77+
if (name === '.' || name === '..' || name.includes('/')) {
78+
throw new TypeError(`Name contains invalid characters.`)
79+
}
6480
options.recursive = !!options.recursive // cuz node's fs.rm require boolean
6581
return this[kAdapter].removeEntry(name, options)
6682
}
6783

68-
// TODO: jsdoc
6984
async resolve (possibleDescendant) {
7085
if (await possibleDescendant.isSameEntry(this)) {
7186
return []

src/adapters/indexeddb.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,12 @@ class FolderHandle {
186186

187187
/** @returns {AsyncGenerator<[string, FileHandle | FolderHandle]>} */
188188
async * entries () {
189-
const entries = await new Promise(resolve => {
190-
store(this._db)[1].get(this._id).onsuccess = evt => resolve(evt.target.result)
189+
const req = store(this._db)[1].get(this._id);
190+
await new Promise((rs, rj) => {
191+
req.onsuccess = () => rs()
192+
req.onerror = () => rj(req.error)
191193
})
194+
const entries = req.result
192195
if (!entries) throw new DOMException(...GONE)
193196
for (const [name, [id, isFile]] of Object.entries(entries)) {
194197
yield [name, isFile

src/adapters/sandbox.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class FileHandle {
8181
return this.file.name
8282
}
8383

84+
/**
85+
* @param {{ file: { toURL: () => string; }; }} other
86+
*/
8487
isSameEntry (other) {
8588
return this.file.toURL() === other.file.toURL()
8689
}

0 commit comments

Comments
 (0)