{"xo":{"rules":{"unicorn/prefer-event-target":"off"}},"_id":"cpy@13.2.3","bugs":{"url":"https://github.com/sindresorhus/cpy/issues"},"dist":{"shasum":"2d7b3d586bafbdc27b0d0e57e87a8ecbe3468ff2","tarball":"http://registry-npm.ywwl.com/cpy/download/cpy-13.2.3.tgz","fileCount":7,"integrity":"sha512-N+jPR8ODTJIzAKmCtUglRSCQzMuDkB/saH1ZJfY1MDfXYMZbfsuih3GhpUEYeuTCDQLBr4GvKyHDwV0Y2Sd0gQ==","signatures":[{"sig":"MEQCIH3SKx6cO8rd8LYAuG3h0aDpozwsNhjIMqyGmp81TGTbAiBa1+25+B/JBvAHc09hhAQjtE19Jg6VR1VZ+rGwB8ciXQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCSblwL7tr/dX1m6uPFzQTnssAdOpNGeCuJ1/fv9WxH4AIga7u97n4HKR7iapoHvopykgQNzbtSyhh37H7bbwXjAGA="}],"unpackedSize":50280,"size":13134,"noattachment":false,"key":"/cpy/-/cpy-13.2.3.tgz"},"name":"cpy","type":"module","types":"./index.d.ts","author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"fc45cf03f8400d0a3fa6040c2f391cc7ddf630c8","license":"MIT","scripts":{"test":"xo && node --test test.js && tsd"},"version":"13.2.3","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"homepage":"https://github.com/sindresorhus/cpy#readme","keywords":["copy","cp","cpy","file","files","clone","fs","stream","glob","file-system","ncp","fast","quick","data","content","contents","cpx","directory","directories"],"repository":{"url":"git+https://github.com/sindresorhus/cpy.git","type":"git"},"_npmVersion":"12.0.1","description":"Copy files","directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"sideEffects":false,"_nodeVersion":"22.23.1","dependencies":{"junk":"^4.0.1","p-map":"^7.0.4","globby":"^16.1.0","p-filter":"^4.1.0","copy-file":"^11.1.0","micromatch":"^4.0.8"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^1.2.3","tsd":"^0.33.0","tempy":"^3.1.2","rimraf":"^6.1.2","proxyquire":"^2.1.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cpy_13.2.3_1788289220563_0.27479812541981863"},"readme":"# cpy\n\n> Copy files\n\n## Why\n\n- Fast by [cloning](https://stackoverflow.com/questions/71629903/node-js-why-we-should-use-copyfile-ficlone-and-copyfile-ficlone-force-what-is) the files whenever possible.\n- Resilient by using [graceful-fs](https://github.com/isaacs/node-graceful-fs).\n- User-friendly by accepting [globs](https://github.com/sindresorhus/globby#globbing-patterns) and creating non-existent destination directories.\n- User-friendly error messages.\n- Progress reporting.\n\n## Install\n\n```sh\nnpm install cpy\n```\n\n## Usage\n\n```js\nimport cpy from 'cpy';\n\nawait cpy([\n\t'source/*.png', // Copy all .png files\n\t'!source/goat.png', // Ignore goat.png\n], 'destination');\n\n// Copy node_modules to destination/node_modules\nawait cpy('node_modules', 'destination');\n\n// Copy node_modules content to destination\nawait cpy('node_modules/**', 'destination');\n\n// Copy node_modules structure but skip all files except .json files\nawait cpy('node_modules/**/*.json', 'destination');\n\n// Copy all png files into destination without keeping directory structure\nawait cpy('**/*.png', 'destination', {flat: true});\n\n// Progress reporting\nawait cpy('source/**', 'destination', {\n\tonProgress: progress => {\n\t\tconsole.log(`Progress: ${Math.round(progress.percent * 100)}%`);\n\t}\n});\n\nconsole.log('Files copied!');\n```\n\n## API\n\n### cpy(source, destination, options?)\n\nReturns a `Promise<string[]>` with the destination file paths.\n\n#### source\n\nType: `string | string[]`\n\nFiles to copy.\n\nIf any of the files do not exist, an error will be thrown (does not apply to globs).\n\nWhen multiple source files resolve to the same destination path, for example with overlapping globs, `flat`, or `rename`, the destination is written once and the last source wins. The `ignoreExisting` option keeps the first source instead, and `update` keeps the newest unless `overwrite` is `false`, which disables `update`.\n\n#### destination\n\nType: `string`\n\nDestination directory.\n\n#### options\n\nType: `object`\n\nOptions are passed to [globby](https://github.com/sindresorhus/globby#options).\n\nNote: Dotfiles are excluded by default. Set `dot: true` to include them.\n\nIn addition, you can specify the below options.\n\n##### cwd\n\nType: `string`\\\nDefault: `process.cwd()`\n\nWorking directory to find source files.\n\n##### overwrite\n\nType: `boolean`\\\nDefault: `true`\n\nOverwrite existing files.\n\n##### ignoreExisting\n\nType: `boolean`\\\nDefault: `false`\n\nSkip files when the destination path already exists.\n\nThis option takes precedence over `overwrite`.\n\n##### update\n\nType: `boolean`\\\nDefault: `false`\n\nOnly overwrite when the source is newer, or when sizes differ with the same modification time. Ignored when `overwrite` is `false` or `ignoreExisting` is `true`.\n\n##### flat\n\nType: `boolean`\\\nDefault: `false`\n\nFlatten directory structure. All copied files will be put in the same directory.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('src/**/*.js', 'destination', {\n\tflat: true\n});\n```\n\n##### base\n\nType: `'cwd' | 'pattern'`\\\nDefault: `undefined`\n\nChoose how destination paths are calculated for patterns. By default, globs are resolved relative to their parent and explicit paths are resolved relative to `cwd`. Set to `'pattern'` to make explicit paths behave like globs, or `'cwd'` to make globs behave like explicit paths.\n\n##### rename\n\nType: `string | Function`\n\nFilename or function used to rename every file in `source`. Use a two-argument function to receive a frozen `source` file object and a mutable `destination` file object. The destination path must stay within the original destination directory. The legacy single-argument form is deprecated, emits a warning, and will be removed in the next major release.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('foo.js', 'destination', {\n\trename: (source, destination) => {\n\t\tif (source.nameWithoutExtension === 'foo') {\n\t\t\tdestination.nameWithoutExtension = 'bar';\n\t\t}\n\t}\n});\n\nawait cpy('foo.js', 'destination', {\n\trename: (source, destination) => {\n\t\tif (source.nameWithoutExtension === 'foo') {\n\t\t\tdestination.extension = 'ts';\n\t\t}\n\n\t\tconsole.log(destination.name);\n\t\t//=> 'foo.ts'\n\t}\n});\n\nawait cpy('foo.js', 'destination', {\n\trename: 'new-name'\n});\n```\n\n##### concurrency\n\nType: `number`\\\nDefault: `os.availableParallelism()`\n\nNumber of files being copied concurrently.\n\n##### ignoreJunk\n\nType: `boolean`\\\nDefault: `true`\n\nIgnores [junk](https://github.com/sindresorhus/junk) files.\n\n##### filter\n\nType: `Function`\n\nFunction to filter files to copy.\n\nReceives a source file object and a context object with the resolved destination path.\n\nReturn true to include, false to exclude. You can also return a Promise that resolves to true or false.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('foo', 'destination', {\n\tfilter: (file, {destinationPath}) => file.extension !== 'nocopy'\n});\n```\n\n##### onProgress\n\nType: `Function`\n\nThe given function is called whenever there is measurable progress.\n\nNote: Progress reporting makes copying slower, as it bypasses the faster filesystem copy path. Only pass this when you use it.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('foo', 'destination', {\n\tonProgress: progress => {\n\t\t// …\n\t}\n});\n```\n\n##### signal\n\nType: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\nAbort signal to cancel the copy operation.\n\n##### followSymbolicLinks\n\nType: `boolean`\\\nDefault: `true`\n\nWhether to follow symbolic links.\n\n##### preserveTimestamps\n\nType: `boolean`\\\nDefault: `false`\n\nPreserve file access and modification timestamps when copying.\n\n##### dryRun\n\nType: `boolean`\\\nDefault: `false`\n\nSkip copying and return the resolved destination paths.\n\n##### Source file object\n\n###### path\n\nType: `string`\\\nExample: `'/tmp/dir/foo.js'`\n\nResolved path to the file.\n\n###### relativePath\n\nType: `string`\\\nExample: `'dir/foo.js'` if `cwd` was `'/tmp'`\n\nRelative path to the file from `cwd`.\n\n###### name\n\nType: `string`\\\nExample: `'foo.js'`\n\nFilename with extension.\n\n###### nameWithoutExtension\n\nType: `string`\\\nExample: `'foo'`\n\nFilename without extension.\n\n###### extension\n\nType: `string`\\\nExample: `'js'`\n\nFile extension.\n\n##### Destination file object\n\n###### path\n\nType: `string`\\\nExample: `'/tmp/dir/foo.js'`\n\nResolved destination path for the file. The directory part must stay within the original destination directory.\n\n###### name\n\nType: `string`\\\nExample: `'foo.js'`\n\nFilename with extension.\n\n###### nameWithoutExtension\n\nType: `string`\\\nExample: `'foo'`\n\nFilename without extension.\n\n###### extension\n\nType: `string`\\\nExample: `'js'`\n\nFile extension.\n\n## Progress reporting\n\nThe `onProgress` option provides progress information during file copying:\n\n```js\nimport cpy from 'cpy';\n\nawait cpy(source, destination, {\n\tonProgress: progress => {\n\t\tconsole.log(`Progress: ${Math.round(progress.percent * 100)}%`);\n\t}\n});\n```\n\n> [!NOTE]\n> Progress reporting makes copying slower, as it bypasses the faster filesystem copy path. Only add a progress handler when you use it.\n\n### Progress object\n\n```js\n{\n\tcompletedFiles: number,\n\ttotalFiles: number,\n\tcompletedSize: number,\n\tpercent: number,\n\tsourcePath: string,\n\tdestinationPath: string,\n}\n```\n\n- `completedFiles` - Number of files copied so far.\n- `totalFiles` - Total number of files to copy.\n- `completedSize` - Number of bytes copied so far.\n- `percent` - Progress percentage as a value between `0` and `1`.\n- `sourcePath` - Absolute source path of the current file being copied.\n- `destinationPath` - Absolute destination path of the current file being copied.\n\n#### handler(progress)\n\nType: `Function`\n\nNote that the `.on()` method is available only right after the initial `cpy` call, so make sure you add a `handler` before awaiting the promise:\n\n```js\nimport cpy from 'cpy';\n\nawait cpy(source, destination).on('progress', progress => {\n\t// …\n});\n```\n\n## Related\n\n- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - CLI for this module\n- [copy-file](https://github.com/sindresorhus/copy-file) - Copy a single file\n- [move-file](https://github.com/sindresorhus/move-file) - Move a file\n- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed\n","publish_time":1788289220651,"_cnpm_publish_time":1788289220651,"dist-tags":{"latest":"13.2.3"}}