From a84fdd99c8fd6a3640e3d182e131cf326858c70e Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Tue, 19 Feb 2019 16:10:44 +0100 Subject: [PATCH] fix: remove implicit use of Q ... when Q is not even in the dependency list --- handlebars/helpers/index.js | 30 +++++++++++++++--------------- index.js | 13 +++++-------- test/cli-spec.js | 4 ++-- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/handlebars/helpers/index.js b/handlebars/helpers/index.js index 40e49eb..5df6092 100644 --- a/handlebars/helpers/index.js +++ b/handlebars/helpers/index.js @@ -11,7 +11,6 @@ const { resolvePackageRoot } = require('../../lib/utils/resolve-package-root') const Handlebars = require('handlebars') const fs = require('fs-extra') const util = require('util') -const Q = require('q') /** * Default Handlebars-helpers for Thought @@ -285,7 +284,7 @@ function htmlId (value) { * and return true if any of them exists and contains the string. * We expect coveralls to be configured then. * - * @return {boolean} true, if coveralls is configured + * @return {Promise} true, if coveralls is configured * * @access public * @memberOf helpers @@ -301,32 +300,33 @@ function hasCoveralls () { * and return true if any of them exists and contains the string. * We expect coveralls to be configured then. * - * @return {boolean} true, if coveralls is configured + * @return {Promise boolean} true, if coveralls is configured * * @access public * @memberOf helpers */ -function hasCodecov () { +async function hasCodecov () { return _searchCiConfig('codecov') } /** * Internal function to look for a given string in popular CI config files (like .travis.yml and appveyor.yml) - * @param searchString + * @param {string} searchString the string to search for within the ci files + * @return {Promise} true, if the given string is either part of .travis.yml or appveyor.yml * @private */ -function _searchCiConfig (searchString) { - const travis = fs.readFile('.travis.yml', 'utf-8') - const appveyor = fs.readFile('appveyor.yml', 'utf-8') - return Q.allSettled([travis, appveyor]).then(function (files) { - let i - for (i = 0; i < files.length; i++) { - if (files[i].state === 'fulfilled' && files[i].value.indexOf(searchString) >= 0) { - return true +async function _searchCiConfig (searchString) { + const ciConfigs = await Promise.all(['.travis.yml', 'appveyor.yml'].map(async (filename) => { + try { + return await fs.readFile(filename, 'utf-8') + } catch (e) { + if (e.code === 'ENOENT') { + return '' } + throw e } - return false - }) + })) + return ciConfigs.findIndex((contents) => contents.includes(searchString)) >= 0 } /** diff --git a/index.js b/index.js index 721eab3..f93b4e1 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,6 @@ 'use strict' var customize = require('customize') -var Q = require('q') var debug = require('debug')('thought:run') var write = require('customize-write-files') @@ -32,13 +31,11 @@ function thought (options) { .then(function (filenames) { if (options.addToGit) { // Add computed files to the git index. - var git = require('simple-git')() - var deferred = Q.defer() - debug('Adding ' + filenames.join(', ') + ' to git index') - git.add(filenames, deferred.makeNodeResolver()) - // Wait for git-add to finish, but return the filenames. - return deferred.promise.then(function () { - return filenames + return new Promise((resolve, reject) => { + var git = require('simple-git')() + debug('Adding ' + filenames.join(', ') + ' to git index') + // Wait for git-add to finish, but return the filenames. + git.add(filenames, (err) => err ? reject(err) : resolve(filenames)) }) } return filenames diff --git a/test/cli-spec.js b/test/cli-spec.js index 78c4025..49072c6 100644 --- a/test/cli-spec.js +++ b/test/cli-spec.js @@ -30,9 +30,9 @@ describe('The cli script', function () { it('should report missing hooks in package.json', function () { return scenario.prepareAndRun(() => runMockThought('run')) .then(result => { - expect(result.code).to.equal(0) - expect(result.stdout).to.match(/Not registered in package.json yet/) expect(result.stderr).to.equal('') + expect(result.stdout).to.match(/Not registered in package.json yet/) + expect(result.code).to.equal(0) expect(scenario.readActual('README.md')).to.equal(scenario.readExpected('README.md')) }) })