Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/copy-file
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 25a50ffffce4a91e289474cec0c33d541c1b0d72
Choose a base ref
...
head repository: sindresorhus/copy-file
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 642f50d10c2f55360f61a497e8dd2184d201787c
Choose a head ref

Commits on Apr 19, 2019

  1. Copy the full SHA
    5e42b4a View commit details
  2. Also test on macOS

    sindresorhus committed Apr 19, 2019
    Copy the full SHA
    8ba01e6 View commit details
  3. Fix EACCES test for macOS (#34)

    coreyfarrell authored and sindresorhus committed Apr 19, 2019
    Copy the full SHA
    bfc90db View commit details
  4. 7.0.0

    sindresorhus committed Apr 19, 2019
    Copy the full SHA
    9899ddb View commit details

Commits on Apr 29, 2019

  1. Add Node.js 12 to testing (#35)

    coreyfarrell authored and sindresorhus committed Apr 29, 2019
    Copy the full SHA
    82a5286 View commit details

Commits on May 28, 2019

  1. Create funding.yml

    sindresorhus authored May 28, 2019
    Copy the full SHA
    d3ed7b9 View commit details

Commits on Jun 11, 2019

  1. Meta tweaks

    sindresorhus committed Jun 11, 2019
    Copy the full SHA
    edcc055 View commit details
  2. Test on Windows too

    sindresorhus committed Jun 11, 2019
    Copy the full SHA
    4e1367f View commit details

Commits on Feb 24, 2020

  1. Copy the full SHA
    4668c5a View commit details
  2. Require Node.js 10

    sindresorhus committed Feb 24, 2020
    Copy the full SHA
    df050ac View commit details
  3. Copy the full SHA
    6d92d5c View commit details
  4. Copy the full SHA
    1b5e072 View commit details
  5. 8.0.0

    sindresorhus committed Feb 24, 2020
    Copy the full SHA
    11b236d View commit details
  6. Copy the full SHA
    d7fab4c View commit details
  7. 8.0.1

    sindresorhus committed Feb 24, 2020
    Copy the full SHA
    1cda1f2 View commit details

Commits on Mar 5, 2020

  1. Stop preserving ownership, stop performing chmod after copyFileSync (

    …#39)
    
    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    sindresorhus authored Mar 5, 2020
    Copy the full SHA
    4e536d5 View commit details
  2. Meta tweaks

    sindresorhus committed Mar 5, 2020
    Copy the full SHA
    5f5151d View commit details
  3. 9.0.0

    sindresorhus committed Mar 5, 2020
    Copy the full SHA
    8c7ac33 View commit details

Commits on Jan 1, 2021

  1. Copy the full SHA
    694ddb2 View commit details

Commits on Jun 13, 2021

  1. Add directoryMode option (#44)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    dittyroma and sindresorhus authored Jun 13, 2021
    Copy the full SHA
    4eb8f47 View commit details
  2. Meta tweaks

    sindresorhus committed Jun 13, 2021
    Copy the full SHA
    bedd8ce View commit details
  3. 9.1.0

    sindresorhus committed Jun 13, 2021
    Copy the full SHA
    589c637 View commit details

Commits on Apr 7, 2022

  1. Copy the full SHA
    778ecdb View commit details
  2. Copy the full SHA
    5dbf6dc View commit details

Commits on May 8, 2022

  1. Add cwd option (#46)

    jopemachine authored May 8, 2022
    Copy the full SHA
    3fe6ab4 View commit details

Commits on Jun 21, 2022

  1. Add onProgress option (#52)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    fitiskin and sindresorhus authored Jun 21, 2022
    Copy the full SHA
    cf322af View commit details
  2. Copy the full SHA
    176d12f View commit details
  3. 10.0.0

    sindresorhus committed Jun 21, 2022
    Copy the full SHA
    642f50d View commit details
Showing with 741 additions and 838 deletions.
  1. +26 −0 .github/workflows/main.yml
  2. +0 −7 .travis.yml
  3. +10 −0 copy-file-error.js
  4. +0 −12 cp-file-error.js
  5. +40 −109 fs.js
  6. +89 −62 index.d.ts
  7. +100 −128 index.js
  8. +40 −23 index.test-d.ts
  9. +1 −1 license
  10. +30 −28 package.json
  11. +0 −34 progress-emitter.js
  12. +49 −42 readme.md
  13. +155 −98 test/async.js
  14. +19 −0 test/helpers/_assert.js
  15. +30 −0 test/helpers/_fs-errors.js
  16. +0 −18 test/helpers/assert.js
  17. +0 −28 test/helpers/fs-errors.js
  18. +49 −35 test/progress.js
  19. +103 −213 test/sync.js
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version:
- 18
- 16
- 14
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions copy-file-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import NestedError from 'nested-error-stacks';

// TODO: Use `Error#cause`.
export default class CopyFileError extends NestedError {
constructor(message, nested) {
super(message, nested);
Object.assign(this, nested);
this.name = 'CopyFileError';
}
}
12 changes: 0 additions & 12 deletions cp-file-error.js

This file was deleted.

149 changes: 40 additions & 109 deletions fs.js
Original file line number Diff line number Diff line change
@@ -1,146 +1,77 @@
'use strict';
const fs = require('graceful-fs');
const makeDir = require('make-dir');
const pify = require('pify');
const CpFileError = require('./cp-file-error');
import {promisify} from 'node:util';
import fs from 'graceful-fs';
import {pEvent} from 'p-event';
import CopyFileError from './copy-file-error.js';

const fsP = pify(fs);
const statP = promisify(fs.stat);
const lstatP = promisify(fs.lstat);
const utimesP = promisify(fs.utimes);
const chmodP = promisify(fs.chmod);
const makeDirectoryP = promisify(fs.mkdir);

exports.closeSync = fs.closeSync.bind(fs);
exports.createWriteStream = fs.createWriteStream.bind(fs);
export const closeSync = fs.closeSync.bind(fs);
export const createWriteStream = fs.createWriteStream.bind(fs);

exports.createReadStream = (path, options) => new Promise((resolve, reject) => {
export async function createReadStream(path, options) {
const read = fs.createReadStream(path, options);

read.once('error', error => {
reject(new CpFileError(`Cannot read from \`${path}\`: ${error.message}`, error));
});

read.once('readable', () => {
resolve(read);
});

read.once('end', () => {
resolve(read);
});
});
try {
await pEvent(read, ['readable', 'end']);
} catch (error) {
throw new CopyFileError(`Cannot read from \`${path}\`: ${error.message}`, error);
}

exports.stat = path => fsP.stat(path).catch(error => {
throw new CpFileError(`Cannot stat path \`${path}\`: ${error.message}`, error);
});
return read;
}

exports.lstat = path => fsP.lstat(path).catch(error => {
throw new CpFileError(`lstat \`${path}\` failed: ${error.message}`, error);
export const stat = path => statP(path).catch(error => {
throw new CopyFileError(`Cannot stat path \`${path}\`: ${error.message}`, error);
});

exports.utimes = (path, atime, mtime) => fsP.utimes(path, atime, mtime).catch(error => {
throw new CpFileError(`utimes \`${path}\` failed: ${error.message}`, error);
export const lstat = path => lstatP(path).catch(error => {
throw new CopyFileError(`lstat \`${path}\` failed: ${error.message}`, error);
});

exports.chmod = (path, mode) => fsP.chmod(path, mode).catch(error => {
throw new CpFileError(`chmod \`${path}\` failed: ${error.message}`, error);
export const utimes = (path, atime, mtime) => utimesP(path, atime, mtime).catch(error => {
throw new CopyFileError(`utimes \`${path}\` failed: ${error.message}`, error);
});

exports.chown = (path, uid, gid) => fsP.chown(path, uid, gid).catch(error => {
throw new CpFileError(`chown \`${path}\` failed: ${error.message}`, error);
export const chmod = (path, mode) => chmodP(path, mode).catch(error => {
throw new CopyFileError(`chmod \`${path}\` failed: ${error.message}`, error);
});

exports.openSync = (path, flags, mode) => {
try {
return fs.openSync(path, flags, mode);
} catch (error) {
if (flags.includes('w')) {
throw new CpFileError(`Cannot write to \`${path}\`: ${error.message}`, error);
}

throw new CpFileError(`Cannot open \`${path}\`: ${error.message}`, error);
}
};

// eslint-disable-next-line max-params
exports.readSync = (fileDescriptor, buffer, offset, length, position, path) => {
try {
return fs.readSync(fileDescriptor, buffer, offset, length, position);
} catch (error) {
throw new CpFileError(`Cannot read from \`${path}\`: ${error.message}`, error);
}
};

// eslint-disable-next-line max-params
exports.writeSync = (fileDescriptor, buffer, offset, length, position, path) => {
try {
return fs.writeSync(fileDescriptor, buffer, offset, length, position);
} catch (error) {
throw new CpFileError(`Cannot write to \`${path}\`: ${error.message}`, error);
}
};

exports.statSync = path => {
export const statSync = path => {
try {
return fs.statSync(path);
} catch (error) {
throw new CpFileError(`stat \`${path}\` failed: ${error.message}`, error);
throw new CopyFileError(`stat \`${path}\` failed: ${error.message}`, error);
}
};

exports.fstatSync = (fileDescriptor, path) => {
try {
return fs.fstatSync(fileDescriptor);
} catch (error) {
throw new CpFileError(`fstat \`${path}\` failed: ${error.message}`, error);
}
};

exports.futimesSync = (fileDescriptor, atime, mtime, path) => {
try {
return fs.futimesSync(fileDescriptor, atime, mtime, path);
} catch (error) {
throw new CpFileError(`futimes \`${path}\` failed: ${error.message}`, error);
}
};

exports.utimesSync = (path, atime, mtime) => {
export const utimesSync = (path, atime, mtime) => {
try {
return fs.utimesSync(path, atime, mtime);
} catch (error) {
throw new CpFileError(`utimes \`${path}\` failed: ${error.message}`, error);
throw new CopyFileError(`utimes \`${path}\` failed: ${error.message}`, error);
}
};

exports.chmodSync = (path, mode) => {
try {
return fs.chmodSync(path, mode);
} catch (error) {
throw new CpFileError(`chmod \`${path}\` failed: ${error.message}`, error);
}
};
export const makeDirectory = (path, options) => makeDirectoryP(path, {...options, recursive: true}).catch(error => {
throw new CopyFileError(`Cannot create directory \`${path}\`: ${error.message}`, error);
});

exports.chownSync = (path, uid, gid) => {
export const makeDirectorySync = (path, options) => {
try {
return fs.chownSync(path, uid, gid);
fs.mkdirSync(path, {...options, recursive: true});
} catch (error) {
throw new CpFileError(`chown \`${path}\` failed: ${error.message}`, error);
throw new CopyFileError(`Cannot create directory \`${path}\`: ${error.message}`, error);
}
};

exports.makeDir = path => makeDir(path, {fs}).catch(error => {
throw new CpFileError(`Cannot create directory \`${path}\`: ${error.message}`, error);
});

exports.makeDirSync = path => {
export const copyFileSync = (source, destination, flags) => {
try {
makeDir.sync(path, {fs});
fs.copyFileSync(source, destination, flags);
} catch (error) {
throw new CpFileError(`Cannot create directory \`${path}\`: ${error.message}`, error);
throw new CopyFileError(`Cannot copy from \`${source}\` to \`${destination}\`: ${error.message}`, error);
}
};

if (fs.copyFileSync) {
exports.copyFileSync = (source, destination, flags) => {
try {
fs.copyFileSync(source, destination, flags);
} catch (error) {
throw new CpFileError(`Cannot copy from \`${source}\` to \`${destination}\`: ${error.message}`, error);
}
};
}
Loading