0.74.0 • Published 21 hours ago

@react-native-windows/fs v0.74.0

Weekly downloads
-
License
MIT
Repository
github
Last release
21 hours ago

@react-native-windows/fs

@react-native-windows/fs is a minimal-dependency drop-in replacement to fs with changes for resiliency, promises, and convenience. It has several opinionated changes, targeted towards CLI applications handling JavaScript-oriented files.

Usage Thumbnail

Async Usage (Default)

@react-native-windows/fs exposes a Promise-based API, mostly matching that of fs.promises, with several methods added extra methods.

// import {promises as fs} from 'fs'
import fs from '@react-native-windows/fs';

const fileContent = await fs.readFile('foo.txt');

Sync Usage

@react-native-windows/fs exports all fs.*Sync Where an async version has a graceful implementation, and the synchronous version does not, the method is marked as deprecated.

// import fs from 'fs'
import fs from '@react-native-windows/fs';

const fileContent = fs.readFileSync('foo.txt');

Extra Methods

exists

NodeJS deprecated fs.exists, and removed fs.promises.exists. The recommendation is to instead acquire a lock to the file via fs.open for the duration of file-use. One-shot existence checks are still useful, and because fs.existsSyncis not deprecated, more likely means usage of blocking synchronous APIs.

import fs from '@react-native-windows/fs';

const fooExists = await fs.exists('foo.txt');

readJsonFile and readJsonFileSync

@react-native-windows/fs provides convenience methods to handle JSON files. The following methods are added:

MethodReturn type
readJsonFile<T>Promise<T> or Promise<Record<string, unknown>>
readJsonFileSync<T>T or Record<string, unknown>
import fs from '@react-native-windows/fs';

// foo is type: Record<string, unknown> by default
const foo = await fs.readJsonFile('foo.json');

// foo is type: FooProps
type FooProps = { name: string, version: string };
const foo = await fs.readJsonFile<FooProps>('foo.json');

Resiliency

@react-native-windows/fs uses graceful-fs to gracefully handle transient filesystem conditions, at the cost of extra latency. This includes transient EPERM, EACCESS, EMFILE, ENFILE. This can be important when handling files that a subject to antivirus, which may temporarily lock mutation of files on Windows.

eslint

We reccomend adding the following rules to your eslint config if you would like to use @react-native-windows/fs everywhere:

module.exports = {
  rules: {
    'no-restricted-imports': [
      'error', {
        name: 'fs',
        message: 'Please use `@react-native-windows/fs` instead of `fs`'
      }
    ],
  }
}
0.0.0-canary.43

21 hours ago

0.0.0-canary.42

3 days ago

0.74.0

14 days ago

0.73.1

15 days ago

0.0.0-canary.41

16 days ago

0.0.1-0

17 days ago

0.0.0-canary.40

1 month ago

0.74.0-preview.1

1 month ago

0.0.0-canary.39

1 month ago

0.0.0-canary.38

2 months ago

0.0.0-canary.37

2 months ago

0.0.0-canary.36

2 months ago

0.0.0-canary.35

2 months ago

0.0.0-canary.34

3 months ago

0.0.0-canary.33

3 months ago

0.0.0-canary.32

3 months ago

0.0.0-canary.31

3 months ago

0.72.1

5 months ago

0.73.0

5 months ago

0.0.0-canary.24

11 months ago

0.0.0-canary.30

7 months ago

0.73.0-preview.1

7 months ago

0.0.0-canary.29

7 months ago

0.0.0-canary.28

8 months ago

0.0.0-canary.27

10 months ago

0.0.0-canary.26

10 months ago

0.0.0-canary.25

10 months ago

0.0.0-canary.23

11 months ago

0.0.0-canary.22

11 months ago

0.0.0-canary.21

11 months ago

0.0.0-canary.20

12 months ago

0.0.0-canary.19

1 year ago

0.71.3

11 months ago

0.72.0

11 months ago

0.0.0-canary.18

1 year ago

0.0.0-canary.17

1 year ago

0.0.0-canary.16

1 year ago

0.71.2

1 year ago

0.70.2

1 year ago

0.69.2

1 year ago

0.0.0-canary.15

1 year ago

0.0.0-canary.14

1 year ago

0.71.1

1 year ago

0.0.0-canary.6

2 years ago

0.0.0-canary.7

2 years ago

0.0.0-canary.8

2 years ago

0.0.0-canary.9

1 year ago

0.0.0-canary.13

1 year ago

0.0.0-canary.12

1 year ago

0.0.0-canary.11

1 year ago

0.0.0-canary.10

1 year ago

0.71.0

1 year ago

0.70.1

1 year ago

0.70.0

2 years ago

0.69.1

2 years ago

0.69.0

2 years ago

0.68.1

2 years ago

0.70.0-preview.1

2 years ago

0.0.0-canary.5

2 years ago

0.69.0-preview.1

2 years ago

0.0.0-canary.4

2 years ago

0.68.0

2 years ago

0.0.0-canary.1

2 years ago

0.0.0-canary.2

2 years ago

0.0.0-canary.3

2 years ago

1.0.2

2 years ago

0.68.0-preview.1

2 years ago

0.68.0-preview.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago