npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@react-native-windows/fs

v0.74.0

Published

A minimal-dependency drop-in replacement to `fs` with changes for resiliency, promises, and convenience.

Downloads

94,064

Readme

@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:

| Method | Return 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`'
      }
    ],
  }
}