Removes files and directories like the rm
command.
There are multi-platform file-system commands compatible with rm
from UN*X implemented for Node.js in JavaScript, like rimraf, del-cli or del, but they have a different interface and a different behaviour than the rm
command. Instead of reusing the knowledge of the rm
command, you would have to learn their new interface. This project aims to provide the well-known interface of the rm
command.
This package offers only command-line interface, because programmatic interface is provided by rm
and rmdir
from node:fs. See also other commands compatible with their counterparts from UN*X - cat.js, cp.js, ln.js, mkdir.js and mv.js.
The following scripts from package.json
won't work on Windows:
rm -rf dist
mkdir -p dist
cat src/umd-prolog.txt src/code.js src/umd-epilog.txt > dist/index.umd.js
cp src/index.d.ts dist
mv LICENSE doc
ln -s ../src src
Replace them with the following ones, which run on any operating system which is supported by Node.js:
rm-j -rf dist
mkdir-j -p dist
cat-j src/umd-prolog.txt src/code.js src/umd-epilog.txt > dist/index.umd.js
cp-j src/index.d.ts dist
mv-j LICENSE doc
ln-j -s ../src src
Notice that the only difference is the suffix -j
behind the command names.
This module can be installed in your project using NPM, PNPM or Yarn. Make sure, that you use Node.js version 14.18 or newer.
$ npm i -D @unixcompat/rm.js
$ pnpm i -D @unixcompat/rm.js
$ yarn add -D @unixcompat/rm.js
See also man rm
for the original POSIX documentation or for the extended Linux implementation.
Usage: rm-j [-Ddfrv] [--] dir...
Options:
-c|--cwd <dir> directory to start looking for the source patterns
-D|--dry-run only print path of each file or directory
-d|--dir remove files and empty directories as well
-f|--force ignore non-existent files and directories
-R|--recursive remove files and directories recursively
-r the same as -R
-v|--verbose print path of each removed file or directory
-V|--version print version number
-h|--help print usage instructions
Examples:
$ rm-j a
$ rm-j -fr /tmp/a
The following options are specific to this command:
-c|--cwd <dir> directory to start looking for the source patterns
-D|--dry-run only print path of each file or directory
Also, the arguments may be BASH patterns. The pattern matching will ignore symbolic links.
The following options from the POSIX version are not supported:
-i write a prompt to the standard error before copying
a file that would overwrite an existing file
The following options from the Linux version are not supported:
-I prompt once before removing more than three files, or when removing
recursively
--interactive[=WHEN]
prompt according to WHEN: never, once (-I), or always (-i);
without WHEN, prompt always
--one-file-system
when removing a hierarchy recursively, skip any directory that is
on a file system different from that of the corresponding command
line argument
--no-preserve-root
do not treat '/' specially
--preserve-root[=all]
do not remove '/' (default); with 'all', reject any command line
argument on a separate device from its parent
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using npm test
.
Copyright (c) 2022-2023 Ferdinand Prantl
Licensed under the MIT license.