From 076b825d42b984ad002e2e72041bf2f15172f20b Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 20 Apr 2018 12:26:11 -0700 Subject: [PATCH] fix: improve hook debugging --- package.json | 12 ++++++------ src/config.ts | 28 +++++++++++++++------------- yarn.lock | 44 ++++++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index f2419e7c..07b4640c 100644 --- a/package.json +++ b/package.json @@ -9,23 +9,23 @@ }, "devDependencies": { "@oclif/errors": "^1.0.4", - "@oclif/parser": "^3.3.2", + "@oclif/parser": "^3.3.3", "@oclif/tslint": "^1.1.0", - "@types/chai": "^4.1.2", + "@types/chai": "^4.1.3", "@types/globby": "^6.1.0", "@types/indent-string": "^3.0.0", "@types/lodash": "^4.14.107", - "@types/mocha": "^5.0.0", - "@types/node": "^9.6.5", + "@types/mocha": "^5.2.0", + "@types/node": "^9.6.6", "@types/wrap-ansi": "^3.0.0", "chai": "^4.1.2", "fancy-test": "^1.0.5", "globby": "^8.0.1", "lodash": "^4.17.5", - "mocha": "^5.1.0", + "mocha": "^5.1.1", "ts-node": "^6.0.0", "tslint": "^5.9.1", - "typescript": "^2.8.1" + "typescript": "^2.8.3" }, "engines": { "node": ">=8.0.0" diff --git a/src/config.ts b/src/config.ts index 677b4e64..50403500 100644 --- a/src/config.ts +++ b/src/config.ts @@ -256,24 +256,25 @@ export class Config implements IConfig { async runHook(event: K, opts: T[K]) { debug('start %s hook', event) - const context: Hook.Context = { - config: this, - debug: require('debug')([this.bin, 'hooks', event].join(':')), - exit(code = 0) { exit(code) }, - log(message?: any, ...args: any[]) { - process.stdout.write(format(message, ...args) + '\n') - }, - error(message, options: {code?: string, exit?: number} = {}) { - error(message, options) - }, - warn(message: string) { warn(message) }, - } const promises = this.plugins.map(p => { + const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':')) + const context: Hook.Context = { + config: this, + debug, + exit(code = 0) { exit(code) }, + log(message?: any, ...args: any[]) { + process.stdout.write(format(message, ...args) + '\n') + }, + error(message, options: {code?: string, exit?: number} = {}) { + error(message, options) + }, + warn(message: string) { warn(message) }, + } return Promise.all((p.hooks[event] || []) .map(async hook => { try { const f = tsPath(p.root, hook) - debug('hook', event, f) + debug('start', f) const search = (m: any): Hook => { if (typeof m === 'function') return m if (m.default && typeof m.default === 'function') return m.default @@ -281,6 +282,7 @@ export class Config implements IConfig { } await search(require(f)).call(context, {...opts as any, config: this}) + debug('done') } catch (err) { if (err && err.oclif && err.oclif.exit !== undefined) throw err this.warn(err, `runHook ${event}`) diff --git a/yarn.lock b/yarn.lock index 9ac9b153..e654852a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16,12 +16,12 @@ version "1.0.0" resolved "https://registry.yarnpkg.com/@oclif/linewrap/-/linewrap-1.0.0.tgz#aedcb64b479d4db7be24196384897b5000901d91" -"@oclif/parser@^3.3.2": - version "3.3.2" - resolved "https://registry.yarnpkg.com/@oclif/parser/-/parser-3.3.2.tgz#81af56d4f97beae376abb59e461005489abd9e19" +"@oclif/parser@^3.3.3": + version "3.3.3" + resolved "https://registry.yarnpkg.com/@oclif/parser/-/parser-3.3.3.tgz#bfde499b836178eee2b6b29ccb7fb3f95851d3c6" dependencies: "@oclif/linewrap" "^1.0.0" - chalk "^2.3.2" + chalk "^2.4.0" "@oclif/tslint@^1.1.0": version "1.1.0" @@ -29,9 +29,9 @@ dependencies: tslint-xo "^0.7.0" -"@types/chai@^4.1.2": - version "4.1.2" - resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.2.tgz#f1af664769cfb50af805431c407425ed619daa21" +"@types/chai@^4.1.3": + version "4.1.3" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.3.tgz#b8a74352977a23b604c01aa784f5b793443fb7dc" "@types/events@*": version "1.1.0" @@ -63,17 +63,17 @@ version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" -"@types/mocha@^5.0.0": - version "5.0.0" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.0.0.tgz#a3014921991066193f6c8e47290d4d598dfd19e6" +"@types/mocha@^5.2.0": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.0.tgz#b3c8e69f038835db1a7fdc0b3d879fc50506e29e" "@types/node@*": version "9.4.5" resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.5.tgz#d2a90c634208173d1b1a0a6ba9f1df3de62edcf5" -"@types/node@^9.6.5": - version "9.6.5" - resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.5.tgz#ee700810fdf49ac1c399fc5980b7559b3e5a381d" +"@types/node@^9.6.6": + version "9.6.6" + resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.6.tgz#439b91f9caf3983cad2eef1e11f6bedcbf9431d2" "@types/wrap-ansi@^3.0.0": version "3.0.0" @@ -253,9 +253,9 @@ chalk@^2.3.0: escape-string-regexp "^1.0.5" supports-color "^5.2.0" -chalk@^2.3.2: - version "2.3.2" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.2.tgz#250dc96b07491bfd601e648d66ddf5f60c7a5c65" +chalk@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52" dependencies: ansi-styles "^3.2.1" escape-string-regexp "^1.0.5" @@ -800,9 +800,9 @@ mkdirp@0.5.1, mkdirp@^0.5.1: dependencies: minimist "0.0.8" -mocha@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.1.0.tgz#5ff11cc39c0bb65330ac6c41f9086634e3e3f686" +mocha@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.1.1.tgz#b774c75609dac05eb48f4d9ba1d827b97fde8a7b" dependencies: browser-stdout "1.3.1" commander "2.11.0" @@ -1179,9 +1179,9 @@ type-detect@^4.0.0: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" -typescript@^2.8.1: - version "2.8.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624" +typescript@^2.8.3: + version "2.8.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" union-value@^1.0.0: version "1.0.0"