Skip to content

Commit 1019117

Browse files
authored
chore: upgrade to Prettier v3 (#997)
1 parent e0d79b5 commit 1019117

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+841
-922
lines changed

.github/workflows/checks.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ jobs:
4848
run: yarn prettier:diff
4949

5050
test-node:
51-
name:
52-
Test on Node.js v${{ matrix.node-version }}
51+
name: Test on Node.js v${{ matrix.node-version }}
5352
needs: prepare-yarn-cache
5453
strategy:
5554
fail-fast: false
@@ -92,8 +91,7 @@ jobs:
9291
env:
9392
CI: true
9493
release:
95-
if:
96-
${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/next') }}
94+
if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/next') }}
9795
name: Release new version
9896
needs: [typecheck, test-node, test-os]
9997
runs-on: ubuntu-latest

CHANGELOG.md

+666-731
Large diffs are not rendered by default.

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99

1010
JavaScript file system utilities for Node.js and browser.
1111

12-
1312
## Install
1413

1514
```shell
1615
npm i memfs
1716
```
1817

19-
2018
## Docs
2119

2220
- [In-memory Node.js `fs` API](./docs/node/index.md)
@@ -27,7 +25,6 @@ npm i memfs
2725
- [Directory `snapshot` utility](./docs/snapshot/index.md)
2826
- [`print` directory tree to terminal](./docs/print/index.md)
2927

30-
3128
## Demos
3229

3330
- [Git in browser, which writes to a real folder](demo/git-fsa/README.md)
@@ -37,7 +34,6 @@ npm i memfs
3734
- [`fs` in browser, synchronous API, writes to real folder](demo/fsa-to-node-sync-tests/README.md)
3835
- [`crudfs` and `casfs` in browser and Node.js interoperability](demo/crud-and-cas/README.md)
3936

40-
4137
## See also
4238

4339
- [`unionfs`][unionfs] - creates a union of multiple filesystem volumes
@@ -50,7 +46,6 @@ npm i memfs
5046
[linkfs]: https://github.com/streamich/linkfs
5147
[spyfs]: https://github.com/streamich/spyfs
5248

53-
5449
## License
5550

5651
Apache 2.0

demo/crud-and-cas/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ using `casfs`.
88

99
https://github.com/streamich/memfs/assets/9773803/02ba339c-6e13-4712-a02f-672674300d27
1010

11-
1211
Run:
1312

1413
```

demo/crud-and-cas/main.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,34 @@ import { CrudCas } from '../../src/crud-to-cas';
33
import type * as fsa from '../../src/fsa/types';
44

55
const hash = async (data: Uint8Array): Promise<string> => {
6-
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
6+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
77
const hashArray = Array.from(new Uint8Array(hashBuffer));
8-
const hashHex = hashArray
9-
.map((b) => b.toString(16).padStart(2, "0"))
10-
.join("");
8+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
119
return hashHex;
1210
};
1311

1412
const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
1513
try {
16-
1714
const crud = new FsaCrud(dir);
18-
const cas = new CrudCas(await crud.from(['objects']), {hash});
15+
const cas = new CrudCas(await crud.from(['objects']), { hash });
1916

2017
// Store "Hello, world!" in object storage
21-
const cid = await cas.put(new TextEncoder()
22-
.encode('Hello, world!'));
18+
const cid = await cas.put(new TextEncoder().encode('Hello, world!'));
2319

2420
// Store the CID in the refs/heads/main.txt file
25-
await crud.put(['refs', 'heads'], 'main.txt',
26-
new TextEncoder().encode(cid));
27-
21+
await crud.put(['refs', 'heads'], 'main.txt', new TextEncoder().encode(cid));
2822
} catch (error) {
2923
console.log(error);
3024
console.log((<any>error).name);
3125
}
3226
};
3327

3428
const main = async () => {
35-
const button = document.createElement("button");
36-
button.textContent = "Select an empty folder";
29+
const button = document.createElement('button');
30+
button.textContent = 'Select an empty folder';
3731
document.body.appendChild(button);
3832
button.onclick = async () => {
39-
const dir = await (window as any).showDirectoryPicker({id: 'demo', mode: 'readwrite'});
33+
const dir = await (window as any).showDirectoryPicker({ id: 'demo', mode: 'readwrite' });
4034
await demo(dir);
4135
};
4236
};

demo/crud-and-cas/node.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ const root = require('app-root-path');
77
const path = require('path');
88

99
const hash = async (data: Uint8Array): Promise<string> => {
10-
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
10+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
1111
const hashArray = Array.from(new Uint8Array(hashBuffer));
12-
const hashHex = hashArray
13-
.map((b) => b.toString(16).padStart(2, "0"))
14-
.join("");
12+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
1513
return hashHex;
1614
};
1715

1816
const main = async () => {
1917
const dir = path.resolve(root.path, 'fs-test');
20-
const crud = new NodeCrud({fs: <any>fs.promises, dir});
21-
const cas = new CrudCas(await crud.from(['objects']), {hash});
18+
const crud = new NodeCrud({ fs: <any>fs.promises, dir });
19+
const cas = new CrudCas(await crud.from(['objects']), { hash });
2220

2321
// Retrieve the CID from the refs/heads/main.txt file
2422
const cid = await crud.get(['refs', 'heads'], 'main.txt');

demo/fsa-to-node-sync-tests/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Synchronous `fs` in browser
22

3-
This demo executes tests of __synchronous__ Node.js API built on top of File
3+
This demo executes tests of **synchronous** Node.js API built on top of File
44
System Access API in browser.
55

66
There are two tests:

demo/fsa-to-node-sync-tests/main.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(window as any).process = require('process/browser');
22
(window as any).Buffer = require('buffer').Buffer;
33

4-
import {strictEqual, deepEqual} from 'assert';
4+
import { strictEqual, deepEqual } from 'assert';
55

66
import type * as fsa from '../../src/fsa/types';
7-
import {FsaNodeFs, FsaNodeSyncAdapterWorker} from '../../src/fsa-to-node';
7+
import { FsaNodeFs, FsaNodeSyncAdapterWorker } from '../../src/fsa-to-node';
88

99
const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
1010
const adapter = await FsaNodeSyncAdapterWorker.start('https://localhost:9876/worker.js', dir);
@@ -17,22 +17,22 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
1717

1818
console.log('existsSync()');
1919
strictEqual(fs.existsSync('/test.txt'), true);
20-
20+
2121
console.log('statSync() - returns correct type for file');
2222
strictEqual(fs.statSync('/test.txt').isFile(), true);
2323
strictEqual(fs.statSync('/test.txt').isDirectory(), false);
24-
24+
2525
console.log('statSync() - returns correct type for directory');
2626
strictEqual(fs.statSync('/dir').isFile(), false);
2727
strictEqual(fs.statSync('/dir').isDirectory(), true);
28-
28+
2929
console.log('readFileSync() - can read file as text');
3030
strictEqual(fs.readFileSync('/test.txt', 'utf8'), 'Hello world!');
31-
31+
3232
console.log('writeFileSync() - can write text to a new file');
3333
fs.writeFileSync('/cool.txt', 'worlds');
3434
strictEqual(fs.readFileSync('/cool.txt', 'utf8'), 'worlds');
35-
35+
3636
console.log('appendFileSync() - can append to an existing file');
3737
fs.appendFileSync('/cool.txt', '!');
3838
strictEqual(fs.readFileSync('/cool.txt', 'utf8'), 'worlds!');
@@ -58,7 +58,7 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
5858
strictEqual(fs.existsSync('/dir/tmp'), false);
5959

6060
console.log('mkdirSync() - can create a nested directory');
61-
fs.mkdirSync('/public/site/assets/img', {recursive: true});
61+
fs.mkdirSync('/public/site/assets/img', { recursive: true });
6262
strictEqual(fs.statSync('/public/site/assets/img').isDirectory(), true);
6363

6464
console.log('mkdtempSync() - can create a temporary directory');
@@ -81,7 +81,7 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
8181
deepEqual(listInDir, ['very-cool.txt']);
8282

8383
console.log('readdirSync() - can list files in a directory as Dirent[]');
84-
const listInDir2 = fs.readdirSync('/dir', {withFileTypes: true}) as any;
84+
const listInDir2 = fs.readdirSync('/dir', { withFileTypes: true }) as any;
8585
deepEqual(listInDir2[0].name, 'very-cool.txt');
8686
deepEqual(listInDir2[0].isFile(), true);
8787

@@ -108,16 +108,16 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
108108
};
109109

110110
const main = async () => {
111-
const button = document.createElement("button");
112-
button.textContent = "Select an empty folder";
111+
const button = document.createElement('button');
112+
button.textContent = 'Select an empty folder';
113113
document.body.appendChild(button);
114114
button.onclick = async () => {
115-
const dir = await (window as any).showDirectoryPicker({id: 'demo', mode: 'readwrite'});
115+
const dir = await (window as any).showDirectoryPicker({ id: 'demo', mode: 'readwrite' });
116116
await demo(dir);
117117
};
118118

119-
const button2 = document.createElement("button");
120-
button2.textContent = "Run tests in OPFS";
119+
const button2 = document.createElement('button');
120+
button2.textContent = 'Run tests in OPFS';
121121
button2.style.marginLeft = '1em';
122122
document.body.appendChild(button2);
123123
button2.onclick = async () => {
@@ -126,4 +126,4 @@ const main = async () => {
126126
};
127127
};
128128

129-
main();
129+
main();

demo/fsa-to-node-sync-tests/webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module.exports = {
4747
https: true,
4848
headers: {
4949
// These two headers are required for SharedArrayBuffer to work.
50-
"Cross-Origin-Opener-Policy": "same-origin",
51-
"Cross-Origin-Embedder-Policy": "require-corp",
50+
'Cross-Origin-Opener-Policy': 'same-origin',
51+
'Cross-Origin-Embedder-Policy': 'require-corp',
5252
},
5353
port: 9876,
5454
hot: false,

demo/fsa-to-node-sync-tests/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(self as any).process = require('process/browser');
22
(self as any).Buffer = require('buffer').Buffer;
33

4-
import {FsaNodeSyncWorker} from "../../src/fsa-to-node/worker/FsaNodeSyncWorker";
4+
import { FsaNodeSyncWorker } from '../../src/fsa-to-node/worker/FsaNodeSyncWorker';
55

66
if (typeof window === 'undefined') {
77
const worker = new FsaNodeSyncWorker();

demo/fsa-to-node-zipfile/main.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
(window as any).Buffer = require('buffer').Buffer;
33

44
import type * as fsa from '../../src/fsa/types';
5-
import {FsaNodeFs} from '../../src/fsa-to-node';
5+
import { FsaNodeFs } from '../../src/fsa-to-node';
66
const tar = require('tar-stream');
77

88
const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
99
const fs = new FsaNodeFs(dir);
1010
await fs.promises.writeFile('hello.txt', 'Hello World');
1111
await fs.promises.writeFile('cool.txt', 'Cool Worlds channel');
12-
13-
const list = await fs.promises.readdir('/') as string[];
12+
13+
const list = (await fs.promises.readdir('/')) as string[];
1414

1515
const pack = tar.pack();
1616
const tarball = fs.createWriteStream('backups.tar');
@@ -22,16 +22,16 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
2222
if (!stat.isFile()) continue;
2323
pack.entry({ name: '/backups/' + item }, await fs.promises.readFile('/' + item), () => {});
2424
}
25-
25+
2626
pack.finalize();
2727
};
2828

2929
const main = async () => {
30-
const button = document.createElement("button");
31-
button.textContent = "Select an empty folder";
30+
const button = document.createElement('button');
31+
button.textContent = 'Select an empty folder';
3232
document.body.appendChild(button);
3333
button.onclick = async () => {
34-
const dir = await (window as any).showDirectoryPicker({id: 'demo', mode: 'readwrite'});
34+
const dir = await (window as any).showDirectoryPicker({ id: 'demo', mode: 'readwrite' });
3535
await demo(dir);
3636
};
3737
};

demo/fsa-to-node-zipfile/webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ module.exports = {
4444
https: true,
4545
headers: {
4646
// These two headers are required for SharedArrayBuffer to work.
47-
"Cross-Origin-Opener-Policy": "same-origin",
48-
"Cross-Origin-Embedder-Policy": "require-corp",
47+
'Cross-Origin-Opener-Policy': 'same-origin',
48+
'Cross-Origin-Embedder-Policy': 'require-corp',
4949
},
5050
port: 9876,
5151
hot: false,

demo/fsa-to-node-zipfile/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(self as any).process = require('process/browser');
22
(self as any).Buffer = require('buffer').Buffer;
33

4-
import {FsaNodeSyncWorker} from "../../src/fsa-to-node/worker/FsaNodeSyncWorker";
4+
import { FsaNodeSyncWorker } from '../../src/fsa-to-node/worker/FsaNodeSyncWorker';
55

66
if (typeof window === 'undefined') {
77
const worker = new FsaNodeSyncWorker();

demo/git-fsa/main.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(window as any).process = require('process/browser');
22
(window as any).Buffer = require('buffer').Buffer;
33

4-
import {FsaNodeFs} from '../../src/fsa-to-node';
4+
import { FsaNodeFs } from '../../src/fsa-to-node';
55
import type * as fsa from '../../src/fsa/types';
66

77
import git from 'isomorphic-git';
@@ -12,35 +12,35 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
1212

1313
console.log('Create "/repo" folder');
1414
await fs.promises.mkdir('/repo');
15-
15+
1616
console.log('Init git repo');
17-
await git.init({fs, dir: 'repo'});
18-
17+
await git.init({ fs, dir: 'repo' });
18+
1919
console.log('Create README file');
2020
await fs.promises.writeFile('/repo/README.md', 'Hello World\n');
21-
21+
2222
console.log('Stage README file');
23-
await git.add({fs, dir: '/repo', filepath: 'README.md'});
24-
23+
await git.add({ fs, dir: '/repo', filepath: 'README.md' });
24+
2525
console.log('Commit README file');
2626
await git.commit({
27-
fs,
28-
dir: '/repo',
29-
author: {name: 'Git', email: '[email protected]'},
30-
message: 'fea: initial commit',
31-
});
27+
fs,
28+
dir: '/repo',
29+
author: { name: 'Git', email: '[email protected]' },
30+
message: 'fea: initial commit',
31+
});
3232
} catch (error) {
3333
console.log(error);
3434
console.log((<any>error).name);
3535
}
3636
};
3737

3838
const main = async () => {
39-
const button = document.createElement("button");
40-
button.textContent = "Select an empty folder";
39+
const button = document.createElement('button');
40+
button.textContent = 'Select an empty folder';
4141
document.body.appendChild(button);
4242
button.onclick = async () => {
43-
const dir = await (window as any).showDirectoryPicker({id: 'demo', mode: 'readwrite'});
43+
const dir = await (window as any).showDirectoryPicker({ id: 'demo', mode: 'readwrite' });
4444
await demo(dir);
4545
};
4646
};

demo/git-fsa/webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module.exports = {
4747
https: true,
4848
headers: {
4949
// These two headers are required for SharedArrayBuffer to work.
50-
"Cross-Origin-Opener-Policy": "same-origin",
51-
"Cross-Origin-Embedder-Policy": "require-corp",
50+
'Cross-Origin-Opener-Policy': 'same-origin',
51+
'Cross-Origin-Embedder-Policy': 'require-corp',
5252
},
5353
port: 9876,
5454
hot: false,

demo/git-fsa/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(self as any).process = require('process/browser');
22
(self as any).Buffer = require('buffer').Buffer;
33

4-
import {FsaNodeSyncWorker} from "../../src/fsa-to-node/worker/FsaNodeSyncWorker";
4+
import { FsaNodeSyncWorker } from '../../src/fsa-to-node/worker/FsaNodeSyncWorker';
55

66
if (typeof window === 'undefined') {
77
const worker = new FsaNodeSyncWorker();

0 commit comments

Comments
 (0)