Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

@npmcli/fs

Package Overview
Dependencies
1
Maintainers
5
Versions
10
Issues
File Explorer

Advanced tools

@npmcli/fs

filesystem utilities for the npm cli

    3.1.0latest

Version published
Maintainers
5
Weekly downloads
11,899,039
decreased by-8.02%

Weekly downloads

Changelog

Source

3.1.0 (2022-11-03)

Features

Readme

Source

@npmcli/fs

polyfills, and extensions, of the core fs module.

Features

  • fs.cp polyfill for node < 16.7.0
  • fs.withTempDir added
  • fs.readdirScoped added
  • fs.moveFile added

fs.withTempDir(root, fn, options) -> Promise

Parameters

  • root: the directory in which to create the temporary directory
  • fn: a function that will be called with the path to the temporary directory
  • options
    • tmpPrefix: a prefix to be used in the generated directory name

Usage

The withTempDir function creates a temporary directory, runs the provided function (fn), then removes the temporary directory and resolves or rejects based on the result of fn.

const fs = require('@npmcli/fs') const os = require('os') // this function will be called with the full path to the temporary directory // it is called with `await` behind the scenes, so can be async if desired. const myFunction = async (tempPath) => { return 'done!' } const main = async () => { const result = await fs.withTempDir(os.tmpdir(), myFunction) // result === 'done!' } main()

fs.readdirScoped(root) -> Promise

Parameters

  • root: the directory to read

Usage

Like fs.readdir but handling @org/module dirs as if they were a single entry.

const readdir = require('readdir-scoped-modules') const entries = await readdir('node_modules') // entries will be something like: ['a', '@org/foo', '@org/bar']

fs.moveFile(source, dest, options) -> Promise

A fork of move-file with support for Common JS.

Highlights

  • Promise API.
  • Supports moving a file across partitions and devices.
  • Optionally prevent overwriting an existing file.
  • Creates non-existent destination directories for you.
  • Automatically recurses when source is a directory.

Parameters

  • source: File, or directory, you want to move.
  • dest: Where you want the file or directory moved.
  • options
    • overwrite (boolean, default: true): Overwrite existing destination file(s).

Usage

The built-in fs.rename() is just a JavaScript wrapper for the C rename(2) function, which doesn't support moving files across partitions or devices. This module is what you would have expected fs.rename() to be.

const { moveFile } = require('@npmcli/fs'); (async () => { await moveFile('source/unicorn.png', 'destination/unicorn.png'); console.log('The file has been moved'); })();

Keywords

FAQs

What is @npmcli/fs?

filesystem utilities for the npm cli

Is @npmcli/fs popular?

The npm package @npmcli/fs receives a total of 11,319,903 weekly downloads. As such, @npmcli/fs popularity was classified as popular.

Is @npmcli/fs well maintained?

We found that @npmcli/fs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 5 open source maintainers collaborating on the project.

Last updated on 03 Nov 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc