Repository: jprichardson/node-fs-extra
Pull request #491 (2017-09-12 20:32:05)

Developments for patch release
This is slated for a patch release, hopefully today, but I want some peer review beforehand.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/13241578/badge)](https://coveralls.io/builds/13241578)

Coverage increased (+0.01%) to 87.377% when pulling **67a2c7eea0cfb9597cb0d349e4e524362ad99d83 on develop** into **bcc1986140e7a1b5891d9975fd044464b5d13074 on master**.


Patch:
diff --git a/docs/outputJson-sync.md b/docs/outputJson-sync.md
index 13c214d..ef78f80 100644
--- a/docs/outputJson-sync.md
+++ b/docs/outputJson-sync.md
@@ -8,6 +8,7 @@ Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the dire
 - `object` `<Object>`
 - `options` `<Object>`
   - `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
+  - `EOL` `<String>` Set EOL character. Default is `\n`.
   - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
   - Also accepts [`fs.writeFileSync` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
 
diff --git a/docs/outputJson.md b/docs/outputJson.md
index d3fbe67..7156991 100644
--- a/docs/outputJson.md
+++ b/docs/outputJson.md
@@ -8,6 +8,7 @@ Almost the same as [`writeJson`](writeJson.md), except that if the directory doe
 - `object` `<Object>`
 - `options` `<Object>`
   - `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
+  - `EOL` `<String>` Set EOL character. Default is `\n`.
   - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
   - Also accepts [`fs.writeFile` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)
 - `callback` `<Function>`
diff --git a/docs/writeJson-sync.md b/docs/writeJson-sync.md
index d2a3ef6..c22459d 100644
--- a/docs/writeJson-sync.md
+++ b/docs/writeJson-sync.md
@@ -8,6 +8,7 @@ Writes an object to a JSON file.
 - `object` `<Object>`
 - `options` `<Object>`
   - `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
+  - `EOL` `<String>` Set EOL character. Default is `\n`.
   - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
   - Also accepts [`fs.writeFileSync` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
 
diff --git a/docs/writeJson.md b/docs/writeJson.md
index af94ffc..8e35271 100644
--- a/docs/writeJson.md
+++ b/docs/writeJson.md
@@ -8,6 +8,7 @@ Writes an object to a JSON file.
 - `object` `<Object>`
 - `options` `<Object>`
   - `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
+  - `EOL` `<String>` Set EOL character. Default is `\n`.
   - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
   - Also accepts [`fs.writeFile` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)
 - `callback` `<Function>`
diff --git a/lib/fs/index.js b/lib/fs/index.js
index 551ca6a..4352965 100644
--- a/lib/fs/index.js
+++ b/lib/fs/index.js
@@ -34,7 +34,10 @@ const api = [
   'utimes',
   'writeFile'
 ]
-// fs.mkdtemp() was added in Node.js v5.10.0, so check if it exists
+// Add methods that are only in some Node.js versions
+// fs.copyFile was added in Node.js v8.5.0
+typeof fs.copyFile === 'function' && api.push('copyFile')
+// fs.mkdtemp() was added in Node.js v5.10.0
 typeof fs.mkdtemp === 'function' && api.push('mkdtemp')
 
 // Export all keys:
diff --git a/package.json b/package.json
index 6690627..ce93067 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,7 @@
   "license": "MIT",
   "dependencies": {
     "graceful-fs": "^4.1.2",
-    "jsonfile": "^3.0.0",
+    "jsonfile": "^4.0.0",
     "universalify": "^0.1.0"
   },
   "devDependencies": {


Test patch:
diff --git a/lib/__tests__/promise.test.js b/lib/__tests__/promise.test.js
index 80aeca5..724dbad 100644
--- a/lib/__tests__/promise.test.js
+++ b/lib/__tests__/promise.test.js
@@ -13,9 +13,7 @@ const methods = [
   'move',
   'readJson',
   'readJSON',
-  'remove',
-  'writeJson',
-  'writeJSON'
+  'remove'
 ]
 
 describe('promise support', () => {
diff --git a/lib/fs/__tests__/copyFile.test.js b/lib/fs/__tests__/copyFile.test.js
new file mode 100644
index 0000000..704bc53
--- /dev/null
+++ b/lib/fs/__tests__/copyFile.test.js
@@ -0,0 +1,33 @@
+'use strict'
+
+const os = require('os')
+const fs = require('fs')
+const fse = require('../..')
+const path = require('path')
+const assert = require('assert')
+
+/* eslint-env mocha */
+
+// Only availible in Node 8.5+
+if (typeof fs.copyFile === 'function') {
+  describe('fs.copyFile', () => {
+    let TEST_DIR
+
+    beforeEach(done => {
+      TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'fs-copyfile')
+      fse.emptyDir(TEST_DIR, done)
+    })
+
+    afterEach(done => fse.remove(TEST_DIR, done))
+
+    it('supports promises', () => {
+      const src = path.join(TEST_DIR, 'init.txt')
+      const dest = path.join(TEST_DIR, 'copy.txt')
+      fse.writeFileSync(src, 'hello')
+      return fse.copyFile(src, dest).then(() => {
+        const data = fse.readFileSync(dest, 'utf8')
+        assert.equal(data, 'hello')
+      })
+    })
+  })
+}
diff --git a/lib/json/__tests__/jsonfile-integration.test.js b/lib/json/__tests__/jsonfile-integration.test.js
index 64177de..15abe9f 100644
--- a/lib/json/__tests__/jsonfile-integration.test.js
+++ b/lib/json/__tests__/jsonfile-integration.test.js
@@ -31,4 +31,21 @@ describe('jsonfile-integration', () => {
       assert.strictEqual(data, JSON.stringify(obj1) + '\n')
     })
   })
+
+  describe('+ writeJsonSync / EOL', () => {
+    it('should read a file and parse the json', () => {
+      const obj1 = {
+        firstName: 'JP',
+        lastName: 'Richardson'
+      }
+
+      const file = path.join(TEST_DIR, 'file.json')
+      fse.writeJsonSync(file, obj1, { spaces: 2, EOL: '\r\n' })
+      const data = fs.readFileSync(file, 'utf8')
+      assert.strictEqual(
+        data,
+        JSON.stringify(obj1, null, 2).replace(/\n/g, '\r\n') + '\r\n'
+      )
+    })
+  })
 })
diff --git a/lib/json/__tests__/promise-support.test.js b/lib/json/__tests__/promise-support.test.js
new file mode 100644
index 0000000..f688f06
--- /dev/null
+++ b/lib/json/__tests__/promise-support.test.js
@@ -0,0 +1,38 @@
+'use strict'
+
+const fs = require('fs')
+const os = require('os')
+const fse = require(process.cwd())
+const path = require('path')
+const assert = require('assert')
+
+/* global afterEach, beforeEach, describe, it */
+
+describe('json promise support', () => {
+  let TEST_DIR
+
+  beforeEach(done => {
+    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'json')
+    fse.emptyDir(TEST_DIR, done)
+  })
+
+  afterEach(done => fse.remove(TEST_DIR, done))
+
+  ;['writeJson', 'writeJSON'].forEach(method => {
+    describe(method, () => {
+      it('should support promises', () => {
+        const obj1 = {
+          firstName: 'JP',
+          lastName: 'Richardson'
+        }
+
+        const file = path.join(TEST_DIR, 'promise.json')
+        return fse[method](file, obj1)
+          .then(() => {
+            const data = fs.readFileSync(file, 'utf8')
+            assert.strictEqual(data, JSON.stringify(obj1) + '\n')
+          })
+      })
+    })
+  })
+})