Skip to content

Commit

Permalink
feat(init): drop fs-extra from runtime dependencies (#285)
Browse files Browse the repository at this point in the history
Replace `copyFile()` of `fs-extra` with Node.js standard library.

BREAKING CHANGE: drop support Node 8.4- by using `fs.copyFile()`

http://nodejs.org/api/fs.html#fs_fs_copyfile_src_dest_flags_callback
  • Loading branch information
ybiquitous committed Nov 26, 2018
1 parent 8463a47 commit 2de76eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
13 changes: 9 additions & 4 deletions lib/init.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const path = require("path");
const { EOL } = require("os");
const fs = require("fs-extra");
const { promisify } = require("util");
const fs = require("fs");
const originalPackage = require("../package.json");

const copyFile = promisify(fs.copyFile);
const writeFile = promisify(fs.writeFile);
const readFile = promisify(fs.readFile);

const packagePath = (...pathElements) =>
path.join(...[__dirname, "..", ...pathElements]);

Expand All @@ -13,7 +18,7 @@ class Init {
}

async copyFile(src, dest) {
await fs.copy(src, dest);
await copyFile(src, dest);
this.logger(`${dest} was updated.`);
}

Expand All @@ -23,12 +28,12 @@ class Init {

async writeFile(fileName, fileContent) {
const file = this.currentPath(fileName);
await fs.writeFile(file, `${fileContent}\n`);
await writeFile(file, `${fileContent}\n`);
this.logger(`${file} was updated.`);
}

readFile(fileName) {
return fs.readFile(this.currentPath(fileName), "utf8");
return readFile(this.currentPath(fileName), "utf8");
}

// eslint-disable-next-line max-statements
Expand Down
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
".markdownlint.json"
],
"engines": {
"node": ">=8.3.0"
"node": ">=8.5.0"
},
"dependencies": {
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/travis-cli": "^7.2.1",
"eslint": "^5.9.0",
"fs-extra": "^7.0.1",
"husky": "^1.1.4",
"lint-staged": "^8.0.5",
"markdownlint-cli": "^0.13.0",
Expand All @@ -38,6 +37,7 @@
},
"devDependencies": {
"eslint-config-ybiquitous": "6.2.0",
"fs-extra": "^7.0.1",
"nodemon": "1.18.6",
"nyc": "13.1.0",
"tape": "4.9.1"
Expand Down
12 changes: 6 additions & 6 deletions test/init.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const path = require("path");
const os = require("os");
const fs = require("fs-extra");
const fse = require("fs-extra");
const test = require("tape");
const pkg = require("../package.json");
const init = require("../lib/init");
const exec = require("./helpers/exec");

const readFile = file => fs.readFile(file, "utf8");
const readJSON = file => fs.readJSON(file, "utf8");
const readFile = file => fse.readFile(file, "utf8");
const readJSON = file => fse.readJSON(file, "utf8");

const sandbox = async (fn, t) => {
const workDir = path.join(os.tmpdir(), `${pkg.name}${Date.now()}`);
await fs.mkdirs(workDir);
await fse.mkdirs(workDir);

const logMsgs = [];
const logger = msg => logMsgs.push(msg);
Expand All @@ -22,7 +22,7 @@ const sandbox = async (fn, t) => {
const fixture = async name => {
const src = fixturePath(name);
const dest = path.join(workDir, "package.json");
await fs.copy(src, dest);
await fse.copy(src, dest);
return dest;
};

Expand All @@ -37,7 +37,7 @@ const sandbox = async (fn, t) => {
initArgs: { cwd: workDir, logger },
});
} finally {
await fs.remove(workDir);
await fse.remove(workDir);
}
};

Expand Down

0 comments on commit 2de76eb

Please sign in to comment.