Skip to content

Commit

Permalink
fix: lazy load engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 1, 2018
1 parent 0a1c3ce commit 5fd5b91
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 49 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/anycli/test/issues",
"dependencies": {
"fancy-test": "^0.6.4",
"fancy-test": "^0.6.6",
"lodash": "^4.17.4"
},
"devDependencies": {
"@anycli/config": "^0.2.3",
"@anycli/engine": "^0.1.35",
"@anycli/tslint": "^0.2.0",
"@anycli/config": "^0.2.11",
"@anycli/engine": "^0.1.42",
"@anycli/tslint": "^0.2.1",
"@anycli/version": "^0.1.19",
"@commitlint/cli": "^6.0.5",
"@commitlint/config-conventional": "^6.0.4",
Expand All @@ -23,7 +23,7 @@
"@types/node-notifier": "^0.0.28",
"@types/read-pkg": "^3.0.0",
"chai": "^4.1.2",
"cli-ux": "^3.3.10",
"cli-ux": "^3.3.12",
"eslint": "^4.16.0",
"eslint-config-anycli": "^1.3.0",
"husky": "^0.14.3",
Expand Down
3 changes: 2 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {IConfig} from '@anycli/config'
import run from '@anycli/engine'
import Run from '@anycli/engine'
import * as _ from 'lodash'

import loadConfig from './load_config'

export default (args: string[] | string | undefined) => ({
async run(ctx: {config: IConfig, expectation: string}) {
const run: typeof Run = require('@anycli/engine').default
if (!ctx.config) ctx.config = await loadConfig().run({} as any)
args = _.castArray(args)
ctx.expectation = ctx.expectation || `runs ${args.join(' ')}`
Expand Down
3 changes: 2 additions & 1 deletion src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default (event?: string, hookOpts: object = {}) => ({
async run(ctx: {config: IConfig, expectation: string}) {
if (!ctx.config) ctx.config = await loadConfig().run({} as any)
ctx.expectation = ctx.expectation || `runs ${event} hook`
const engine = new Engine()
const EEngine: typeof Engine = require('@anycli/engine').Engine
const engine = new EEngine()
await engine.load(ctx.config)
await engine.runHook(event!, hookOpts || {})
}
Expand Down
3 changes: 2 additions & 1 deletion src/load_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const _loadEngine = (opts: {root?: string} = {}) => {
return {
async run(ctx: {config: IConfig, engine: IEngine}) {
if (!ctx.config) ctx.config = await loadConfig().run(opts as any)
ctx.engine = new Engine()
const EEngine: typeof Engine = require('@anycli/engine').Engine
ctx.engine = new EEngine()
await ctx.engine.load(ctx.config)
}
}
Expand Down
94 changes: 53 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
# yarn lockfile v1


"@anycli/command@^0.2.18":
version "0.2.18"
resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.2.18.tgz#85e8de82f8f4091104cf8182781745d5492714e7"
dependencies:
"@anycli/parser" "^1.0.0"
debug "^3.1.0"
lodash "^4.17.4"
tslib "^1.9.0"

"@anycli/command@^0.2.19":
version "0.2.20"
resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.2.20.tgz#18f9c6f25a7871827af454ef05f62fd5d0b61c15"
Expand All @@ -22,6 +13,17 @@
lodash "^4.17.4"
tslib "^1.9.0"

"@anycli/config@^0.2.11":
version "0.2.11"
resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.11.tgz#1b043946b18e159e6e44195aa4fef309b79f8ede"
dependencies:
cli-ux "^3.3.10"
debug "^3.1.0"
fs-extra "^5.0.0"
load-json-file "^4.0.0"
lodash "^4.17.4"
read-pkg "^3.0.0"

"@anycli/config@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.3.tgz#2fc399d2d609c0efdf3108d240f0b557abad51dc"
Expand All @@ -33,36 +35,26 @@
lodash "^4.17.4"
read-pkg "^3.0.0"

"@anycli/engine@^0.1.35":
version "0.1.35"
resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.35.tgz#40185e6e9ef56e2864a2f381d5786d76ff1f5de0"
"@anycli/engine@^0.1.42":
version "0.1.42"
resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.42.tgz#584274b6c4c9a8b8ad5563cc3070921afbe0910d"
dependencies:
"@anycli/command" "^0.2.18"
"@anycli/config" "^0.2.3"
"@anycli/manifest-file" "^0.2.0"
cli-ux "^3.3.10"
"@anycli/manifest-file" "^0.3.3"
cli-ux "^3.3.12"
debug "^3.1.0"
fs-extra "^5.0.0"
globby "^7.1.1"
lodash "^4.17.4"

"@anycli/manifest-file@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@anycli/manifest-file/-/manifest-file-0.2.0.tgz#f9f70fd2afb44178fe907f2a35ad8746eeb1ee97"
"@anycli/manifest-file@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@anycli/manifest-file/-/manifest-file-0.3.3.tgz#9cf398b411037be01b00b0d1fd3cf2a40178dcf5"
dependencies:
debug "^3.1.0"
fs-extra "^5.0.0"
load-json-file "^4.0.0"
lodash "^4.17.4"
rwlockfile "^2.0.21"

"@anycli/parser@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-1.0.0.tgz#0ae14d75c3f66904c962ad75361d8d628509348a"
dependencies:
"@anycli/screen" "^0.0.3"
chalk "^2.3.0"
lodash "^4.17.4"
rwlockfile "^2.0.23"

"@anycli/parser@^3.0.1":
version "3.0.1"
Expand All @@ -76,9 +68,9 @@
version "0.0.3"
resolved "https://registry.yarnpkg.com/@anycli/screen/-/screen-0.0.3.tgz#f0afd970c3ed725702948a45a874ede1fdd9362e"

"@anycli/tslint@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.0.tgz#192a612e3664f7a18fe6ed693de94de6d4563882"
"@anycli/tslint@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.1.tgz#17295a3a4c579884cd3aea7ed1d8c07d11ecc624"
dependencies:
tslint "^5.9.1"
tslint-xo "^0.6.0"
Expand Down Expand Up @@ -522,6 +514,26 @@ cli-ux@^3.3.10:
strip-ansi "^4.0.0"
supports-color "^5.1.0"

cli-ux@^3.3.12:
version "3.3.12"
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.12.tgz#9bd5a2ed5c682fc22027bd32c5eb20bbe6aa2571"
dependencies:
"@anycli/screen" "^0.0.3"
"@heroku/linewrap" "^1.0.0"
ansi-styles "^3.2.0"
cardinal "^1.0.0"
chalk "^2.3.0"
clean-stack "^1.3.0"
extract-stack "^1.0.0"
fs-extra "^5.0.0"
indent-string "^3.2.0"
lodash "^4.17.4"
node-notifier "^5.2.1"
password-prompt "^1.0.4"
semver "^5.5.0"
strip-ansi "^4.0.0"
supports-color "^5.1.0"

cli-width@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
Expand Down Expand Up @@ -971,12 +983,12 @@ extract-stack@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/extract-stack/-/extract-stack-1.0.0.tgz#b97acaf9441eea2332529624b732fc5a1c8165fa"

fancy-test@^0.6.4:
version "0.6.5"
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.5.tgz#80a9dfb348fa34003ea030c3297bccc6ce825be2"
fancy-test@^0.6.6:
version "0.6.6"
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.6.tgz#cda1afbf57ea2fb05291edbff34c0bbc2600d956"
dependencies:
lodash "^4.17.4"
stdout-stderr "^0.1.4"
stdout-stderr "^0.1.6"

fast-deep-equal@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -2067,9 +2079,9 @@ run-async@^2.2.0:
dependencies:
is-promise "^2.1.0"

rwlockfile@^2.0.21:
version "2.0.21"
resolved "https://registry.yarnpkg.com/rwlockfile/-/rwlockfile-2.0.21.tgz#c2eb13d77df18dbb268dcd28017df17d5a97f8a8"
rwlockfile@^2.0.23:
version "2.0.23"
resolved "https://registry.yarnpkg.com/rwlockfile/-/rwlockfile-2.0.23.tgz#1bc2341e9d63b78a0b5399220dfcecfbc4c0edc1"
dependencies:
fs-extra "^5.0.0"
is-process-active "^1.0.1"
Expand Down Expand Up @@ -2188,9 +2200,9 @@ starts-with@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/starts-with/-/starts-with-1.0.2.tgz#16793a729d89d4cf3d4fb2eda2f908ae357f196f"

stdout-stderr@^0.1.4:
version "0.1.5"
resolved "https://registry.yarnpkg.com/stdout-stderr/-/stdout-stderr-0.1.5.tgz#adf87b96bb715b692fc62c727050d313ac832c23"
stdout-stderr@^0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/stdout-stderr/-/stdout-stderr-0.1.6.tgz#82616602f639bf029c87ab1049b02640a39a18ba"
dependencies:
debug "*"
strip-ansi "^4.0.0"
Expand Down

0 comments on commit 5fd5b91

Please sign in to comment.