Registry / devops / premove

premove

JSON →
library4.0.0jsnpmunverified

premove is a lightweight, cross-platform utility for Node.js that recursively removes files and directories, functioning as a programmatic `rm -rf`. It offers both `Promise`-based asynchronous (`premove`) and synchronous (`premove/sync`) APIs. The current stable version is 4.0.0. Releases are generally infrequent but address breaking changes or add features, as seen with v3.0.0's migration to named exports and v4.0.0's consistent boolean return for non-existent paths. Key differentiators include its tiny footprint (208B-260B), explicit support for both async/await and synchronous operations, and a built-in CLI. It's an alternative to `fs.rm` (or `fs.rmdir` with `recursive` option), providing a simpler, focused API for recursive deletion with safeguards against deleting critical system paths.

npm install premove
INSTALL
IMPORT
SIG · PREMOVE
P
premove
devopsjavascriptv4.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

premove
import { premove } from 'premove'
import premove from 'premove'
Since v3.0.0, `premove` is a named export for both ESM and CommonJS. The default export was removed.
premove (sync)
import { premove } from 'premove/sync'
import premove from 'premove/sync'
To use the synchronous version, you must import from the 'premove/sync' submodule. It's also a named export.
premove (CJS)
const { premove } = require('premove')
const premove = require('premove')
For CommonJS, use destructuring assignment to access the named export since v3.0.0.

Demonstrates asynchronous recursive deletion of files and directories using `premove`, including the `cwd` option, and shows the boolean return value for existing and non-existing paths. Also includes cleanup using the sync version.

import { premove } from 'premove'; import { resolve, join } from 'path'; import { mkdir, writeFile } from 'fs/promises'; async function runExample() { const baseDir = resolve(__dirname, 'temp_premove_test'); const targetDir = join(baseDir, 'foo', 'bar'); const targetFile = join(baseDir, 'hello.txt'); try { // Setup: Create directories and a file for deletion await mkdir(targetDir, { recursive: true }); await writeFile(targetFile, 'temporary content'); console.log(`Created test directory: ${targetDir}`); console.log(`Created test file: ${targetFile}`); // Example 1: Remove a directory recursively let removedFoo = await premove(join(baseDir, 'foo')); console.log(`'${join(baseDir, 'foo')}' existed and was removed: ${removedFoo}`); // Example 2: Remove a file using cwd option let removedFile = await premove('hello.txt', { cwd: baseDir }); console.log(`'hello.txt' in '${baseDir}' existed and was removed: ${removedFile}`); // Example 3: Attempt to remove a non-existent path let removedNonExistent = await premove(join(baseDir, 'non-existent-path')); console.log(`'non-existent-path' existed and was removed: ${removedNonExistent} (expected false)`); } catch (err) { console.error('Error during premove example:', err); } finally { // Clean up if baseDir still exists (e.g., if an error occurred early) try { const { premove: premoveSync } = await import('premove/sync'); premoveSync(baseDir); console.log(`Cleaned up base directory: ${baseDir}`); } catch (cleanupErr) { console.warn('Failed to clean up base directory:', cleanupErr.message); } } } runExample();
premove --version
Debug
Known issues
breakingThe `premove` utility migrated from a default export to a named export. This affects both ESM `import` statements and CommonJS `require()` calls.
fix
Update your import/require statements: `import { premove } from 'premove'` or `const { premove } = require('premove')`.
affects: >=3.0.0
breakingThe `premove` (async) function now consistently returns a `Promise<boolean>`, even if the path does not exist. Previously, it would synchronously return `false` if the path was not found. The `premove/sync` version always returns `boolean`.
fix
Ensure your async code correctly `await`s the result of `premove` and expects a `Promise<boolean>`.
affects: >=4.0.0
gotchaThe `premove` CLI and underlying utility by default refuse to delete critical system paths such as the OS home directory (`os.homedir`), the system root (`/` or `C:\`), or items not contained within the `--cwd` path for safety.
fix
Always specify target paths relative to a safe `cwd` or ensure they are within intended deletion scope. Do not attempt to use `premove` for deleting system-level directories like `/` directly.
affects: >=3.0.0
gotchaFor synchronous operations, you must explicitly import `premove` from `'premove/sync'`. The default import (`'premove'`) is always asynchronous and Promise-based.
fix
Use `import { premove } from 'premove/sync'` or `const { premove } = require('premove/sync')` for synchronous usage.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: premove is not a function
Attempting to call `premove` after importing it as a default export (e.g., `import premove from 'premove'`) when it should be a named export.
fix
Change your import statement to `import { premove } from 'premove';` (ESM) or `const { premove } = require('premove');` (CommonJS).
Property 'then' does not exist on type 'boolean'. Did you mean the instance member 'trim'?
Trying to use `.then()` or `await` on the result of `premove` from the `premove/sync` submodule, which returns a synchronous boolean, not a Promise.
fix
If you need `Promise`-based behavior, import `premove` from the main package (`'premove'`). If you intend synchronous behavior, simply use the boolean return value directly without `await` or `.then()`.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
premove — npm install premove · libregistry