{"id":15290141,"url":"https://github.com/npm/fs","last_synced_at":"2025-05-16T05:06:25.675Z","repository":{"id":40534048,"uuid":"392829655","full_name":"npm/fs","owner":"npm","description":"filesystem helper functions, wrappers, and promisification for the npm cli","archived":false,"fork":false,"pushed_at":"2025-04-28T18:53:20.000Z","size":241,"stargazers_count":29,"open_issues_count":3,"forks_count":9,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-03T08:08:28.751Z","etag":null,"topics":["npm-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-04T21:33:31.000Z","updated_at":"2025-04-28T18:53:22.000Z","dependencies_parsed_at":"2023-01-26T11:16:42.297Z","dependency_job_id":"f5a4ed20-1cdf-46bc-a083-f7bd7a0ec5fb","html_url":"https://github.com/npm/fs","commit_stats":{"total_commits":94,"total_committers":8,"mean_commits":11.75,"dds":0.6170212765957447,"last_synced_commit":"70bf80857da6c8c79b927e53027fa9e38504ed70"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Ffs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Ffs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Ffs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Ffs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/fs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254078635,"owners_count":22011009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm-cli"],"created_at":"2024-09-30T16:05:32.533Z","updated_at":"2025-05-16T05:06:25.597Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @npmcli/fs\n\npolyfills, and extensions, of the core `fs` module.\n\n## Features\n\n- `fs.cp` polyfill for node \u003c 16.7.0\n- `fs.withTempDir` added\n- `fs.readdirScoped` added\n- `fs.moveFile` added\n\n## `fs.withTempDir(root, fn, options) -\u003e Promise`\n\n### Parameters\n\n- `root`: the directory in which to create the temporary directory\n- `fn`: a function that will be called with the path to the temporary directory\n- `options`\n  - `tmpPrefix`: a prefix to be used in the generated directory name\n\n### Usage\n\nThe `withTempDir` function creates a temporary directory, runs the provided\nfunction (`fn`), then removes the temporary directory and resolves or rejects\nbased on the result of `fn`.\n\n```js\nconst fs = require('@npmcli/fs')\nconst os = require('os')\n\n// this function will be called with the full path to the temporary directory\n// it is called with `await` behind the scenes, so can be async if desired.\nconst myFunction = async (tempPath) =\u003e {\n  return 'done!'\n}\n\nconst main = async () =\u003e {\n  const result = await fs.withTempDir(os.tmpdir(), myFunction)\n  // result === 'done!'\n}\n\nmain()\n```\n\n## `fs.readdirScoped(root) -\u003e Promise`\n\n### Parameters\n\n- `root`: the directory to read\n\n### Usage\n\nLike `fs.readdir` but handling `@org/module` dirs as if they were\na single entry.\n\n```javascript\nconst { readdirScoped } = require('@npmcli/fs')\nconst entries = await readdirScoped('node_modules')\n// entries will be something like: ['a', '@org/foo', '@org/bar']\n```\n\n## `fs.moveFile(source, dest, options) -\u003e Promise`\n\nA fork of [move-file](https://github.com/sindresorhus/move-file) with\nsupport for Common JS.\n\n### Highlights\n\n- Promise API.\n- Supports moving a file across partitions and devices.\n- Optionally prevent overwriting an existing file.\n- Creates non-existent destination directories for you.\n- Automatically recurses when source is a directory.\n\n### Parameters\n\n- `source`: File, or directory, you want to move.\n- `dest`: Where you want the file or directory moved.\n- `options`\n  - `overwrite` (`boolean`, default: `true`): Overwrite existing destination file(s).\n\n### Usage\n\nThe built-in\n[`fs.rename()`](https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback)\nis just a JavaScript wrapper for the C `rename(2)` function, which doesn't\nsupport moving files across partitions or devices. This module is what you\nwould have expected `fs.rename()` to be.\n\n```js\nconst { moveFile } = require('@npmcli/fs');\n\n(async () =\u003e {\n\tawait moveFile('source/unicorn.png', 'destination/unicorn.png');\n\tconsole.log('The file has been moved');\n})();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Ffs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Ffs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Ffs/lists"}