From 2cab46eadf83ae9bbee29151e2f884a6dd48f501 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 12 Feb 2017 04:33:55 +0700 Subject: [PATCH] Get rid of some dependencies --- lib/index.js | 13 ++++++------- package.json | 4 ---- test/base.js | 11 ++++------- test/storage.js | 3 +-- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/index.js b/lib/index.js index f7479cf2..012c4583 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,8 @@ 'use strict'; const util = require('util'); +const fs = require('fs'); const path = require('path'); +const os = require('os'); const EventEmitter = require('events'); const assert = require('assert'); const _ = require('lodash'); @@ -11,10 +13,7 @@ const mkdirp = require('mkdirp'); const minimist = require('minimist'); const runAsync = require('run-async'); const through = require('through2'); -const userHome = require('user-home'); const FileEditor = require('mem-fs-editor'); -const pathIsAbsolute = require('path-is-absolute'); -const pathExists = require('path-exists'); const debug = require('debug')('yeoman:generator'); const Conflicter = require('./util/conflicter'); const Storage = require('./util/storage'); @@ -575,7 +574,7 @@ Base.prototype._getStorage = function () { */ Base.prototype._getGlobalStorage = function () { - const storePath = path.join(userHome, '.yo-rc-global.json'); + const storePath = path.join(os.homedir(), '.yo-rc-global.json'); const storeName = util.format('%s:%s', this.rootGeneratorName(), this.rootGeneratorVersion()); return new Storage(storeName, this.fs, storePath); }; @@ -592,7 +591,7 @@ Base.prototype.destinationRoot = function (rootPath) { if (_.isString(rootPath)) { this._destinationRoot = path.resolve(rootPath); - if (!pathExists.sync(rootPath)) { + if (!fs.existsSync(rootPath)) { mkdirp.sync(rootPath); } @@ -630,7 +629,7 @@ Base.prototype.sourceRoot = function (rootPath) { Base.prototype.templatePath = function () { let filepath = path.join.apply(path, arguments); - if (!pathIsAbsolute(filepath)) { + if (!path.isAbsolute(filepath)) { filepath = path.join(this.sourceRoot(), filepath); } @@ -646,7 +645,7 @@ Base.prototype.templatePath = function () { Base.prototype.destinationPath = function () { let filepath = path.join.apply(path, arguments); - if (!pathIsAbsolute(filepath)) { + if (!path.isAbsolute(filepath)) { filepath = path.join(this.destinationRoot(), filepath); } diff --git a/package.json b/package.json index 4fcc4373..9c2c080f 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,6 @@ "mem-fs-editor": "^3.0.0", "minimist": "^1.2.0", "mkdirp": "^0.5.0", - "path-exists": "^3.0.0", - "path-is-absolute": "^1.0.0", "pretty-bytes": "^4.0.2", "read-chunk": "^2.0.0", "read-pkg-up": "^2.0.0", @@ -59,7 +57,6 @@ "shelljs": "^0.7.0", "text-table": "^0.2.0", "through2": "^2.0.0", - "user-home": "^2.0.0", "yeoman-environment": "^1.1.0" }, "devDependencies": { @@ -73,7 +70,6 @@ "jsdoc": "^3.3.0-beta1", "mockery": "^2.0.0", "nock": "^9.0.5", - "pinkie-promise": "^2.0.0", "proxyquire": "^1.0.0", "sinon": "^1.9.1", "tui-jsdoc-template": "^1.0.4", diff --git a/test/base.js b/test/base.js index 139d25d8..b7c08fda 100644 --- a/test/base.js +++ b/test/base.js @@ -9,10 +9,7 @@ const mkdirp = require('mkdirp'); const mockery = require('mockery'); const rimraf = require('rimraf'); const through = require('through2'); -const pathExists = require('path-exists'); -const Promise = require('pinkie-promise'); const yeoman = require('yeoman-environment'); -const userHome = require('user-home'); mockery.enable({ warnOnReplace: false, @@ -458,7 +455,7 @@ describe('Base', () => { }; this.testGen.run(() => { - assert(pathExists.sync(filepath)); + assert(fs.existsSync(filepath)); done(); }); }); @@ -466,7 +463,7 @@ describe('Base', () => { it('allow skipping file writes to disk', function (done) { const action = {action: 'skip'}; const filepath = path.join(__dirname, '/fixtures/conflict.js'); - assert(pathExists.sync(filepath)); + assert(fs.existsSync(filepath)); this.TestGenerator.prototype.writing = function () { this.fs.write(filepath, 'some new content'); @@ -521,7 +518,7 @@ describe('Base', () => { it('does not pass config file to conflicter', function (done) { this.TestGenerator.prototype.writing = function () { fs.writeFileSync(this.destinationPath('.yo-rc.json'), '{"foo": 3}'); - fs.writeFileSync(path.join(userHome, '.yo-rc-global.json'), '{"foo": 3}'); + fs.writeFileSync(path.join(os.homedir(), '.yo-rc-global.json'), '{"foo": 3}'); this.config.set('bar', 1); this._globalConfig.set('bar', 1); }; @@ -535,7 +532,7 @@ describe('Base', () => { }; this.testGen.run(() => { - assert(pathExists.sync(this.testGen.destinationPath('foo.txt'))); + assert(fs.existsSync(this.testGen.destinationPath('foo.txt'))); done(); }); }); diff --git a/test/storage.js b/test/storage.js index 092c483c..f5b1f6d1 100644 --- a/test/storage.js +++ b/test/storage.js @@ -4,7 +4,6 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const FileEditor = require('mem-fs-editor'); -const pathExists = require('path-exists'); const env = require('yeoman-environment'); const helpers = require('yeoman-test'); const Storage = require('../lib/util/storage'); @@ -12,7 +11,7 @@ const Storage = require('../lib/util/storage'); const tmpdir = path.join(os.tmpdir(), 'yeoman-storage'); function rm(filepath) { - if (pathExists.sync(filepath)) { + if (fs.existsSync(filepath)) { fs.unlinkSync(path); } }