Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: updated deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Sep 13, 2018
1 parent 6f997c6 commit 01f51e6
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 112 deletions.
6 changes: 3 additions & 3 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/oclif/config/issues",
"dependencies": {
"debug": "^3.1.0",
"debug": "^4.0.1",
"tslib": "^1.9.3"
},
"devDependencies": {
"@oclif/errors": "^1.2.0",
"@oclif/parser": "^3.6.1",
"@oclif/tslint": "^2.0.0",
"@oclif/tslint": "^3.1.0",
"@types/chai": "^4.1.4",
"@types/globby": "^8.0.0",
"@types/indent-string": "^3.0.0",
Expand All @@ -22,7 +22,7 @@
"chai": "^4.1.2",
"fancy-test": "^1.4.0",
"globby": "^8.0.1",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
Expand Down
32 changes: 16 additions & 16 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,23 @@ export class Config implements IConfig {
warn(message: string) { warn(message) },
}
return Promise.all((p.hooks[event] || [])
.map(async hook => {
try {
const f = tsPath(p.root, hook)
debug('start', f)
const search = (m: any): Hook<K> => {
if (typeof m === 'function') return m
if (m.default && typeof m.default === 'function') return m.default
return Object.values(m).find((m: any) => typeof m === 'function') as Hook<K>
.map(async hook => {
try {
const f = tsPath(p.root, hook)
debug('start', f)
const search = (m: any): Hook<K> => {
if (typeof m === 'function') return m
if (m.default && typeof m.default === 'function') return m.default
return Object.values(m).find((m: any) => typeof m === 'function') as Hook<K>
}

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}`)
}

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}`)
}
}))
}))
})
await Promise.all(promises)
debug('%s hook done', event)
Expand Down
10 changes: 5 additions & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ export class Plugin implements IPlugin {
else throw this.addErrorScope(err, scope)
}
})
.filter((f): f is [string, Command] => !!f)
.reduce((commands, [id, c]) => {
commands[id] = c
return commands
}, {} as {[k: string]: Command})
.filter((f): f is [string, Command] => !!f)
.reduce((commands, [id, c]) => {
commands[id] = c
return commands
}, {} as {[k: string]: Command})
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export function flatMap<T, U>(arr: T[], fn: (i: T) => U[]): U[] {

export function mapValues<T extends object, TResult>(obj: {[P in keyof T]: T[P]}, fn: (i: T[keyof T], k: keyof T) => TResult): {[P in keyof T]: TResult} {
return Object.entries(obj)
.reduce((o, [k, v]) => {
o[k] = fn(v as any, k as any)
return o
}, {} as any)
.reduce((o, [k, v]) => {
o[k] = fn(v as any, k as any)
return o
}, {} as any)
}

export function loadJSONSync(path: string): any {
Expand Down
114 changes: 57 additions & 57 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {expect, fancy} from './test'
interface Options {
pjson?: any,
homedir?: string,
platform?: string,
env?: {[k: string]: string},
platform?: string,
env?: {[k: string]: string},
}

describe('Config', () => {
Expand All @@ -28,91 +28,91 @@ describe('Config', () => {
return {
hasS3Key(k: keyof PJSON.S3.Templates, expected: string, extra: any = {}) {
return this
.it(`renders ${k} template as ${expected}`, config => {
let {ext, ...options} = extra
options = {
bin: 'oclif-cli',
version: '1.0.0',
ext: '.tar.gz',
...options,
}
const o = ext ? config.s3Key(k as any, ext, options) : config.s3Key(k, options)
expect(o).to.equal(expected)
})
.it(`renders ${k} template as ${expected}`, config => {
let {ext, ...options} = extra
options = {
bin: 'oclif-cli',
version: '1.0.0',
ext: '.tar.gz',
...options,
}
const o = ext ? config.s3Key(k as any, ext, options) : config.s3Key(k, options)
expect(o).to.equal(expected)
})
},
hasProperty<K extends keyof IConfig>(k: K | undefined, v: IConfig[K] | undefined) {
return this
.it(`has ${k}=${v}`, config => expect(config).to.have.property(k!, v))
.it(`has ${k}=${v}`, config => expect(config).to.have.property(k!, v))
},
it(expectation: string, fn: (config: IConfig) => any) {
test
.do(({config}) => fn(config))
.it(expectation)
.do(({config}) => fn(config))
.it(expectation)
return this
}
}
}

describe('darwin', () => {
testConfig()
.hasProperty('cacheDir', path.join('/my/home/Library/Caches/@oclif/config'))
.hasProperty('configDir', path.join('/my/home/.config/@oclif/config'))
.hasProperty('errlog', path.join('/my/home/Library/Caches/@oclif/config/error.log'))
.hasProperty('dataDir', path.join('/my/home/.local/share/@oclif/config'))
.hasProperty('home', path.join('/my/home'))
.hasProperty('cacheDir', path.join('/my/home/Library/Caches/@oclif/config'))
.hasProperty('configDir', path.join('/my/home/.config/@oclif/config'))
.hasProperty('errlog', path.join('/my/home/Library/Caches/@oclif/config/error.log'))
.hasProperty('dataDir', path.join('/my/home/.local/share/@oclif/config'))
.hasProperty('home', path.join('/my/home'))
})

describe('linux', () => {
testConfig({platform: 'linux'})
.hasProperty('cacheDir', path.join('/my/home/.cache/@oclif/config'))
.hasProperty('configDir', path.join('/my/home/.config/@oclif/config'))
.hasProperty('errlog', path.join('/my/home/.cache/@oclif/config/error.log'))
.hasProperty('dataDir', path.join('/my/home/.local/share/@oclif/config'))
.hasProperty('home', path.join('/my/home'))
.hasProperty('cacheDir', path.join('/my/home/.cache/@oclif/config'))
.hasProperty('configDir', path.join('/my/home/.config/@oclif/config'))
.hasProperty('errlog', path.join('/my/home/.cache/@oclif/config/error.log'))
.hasProperty('dataDir', path.join('/my/home/.local/share/@oclif/config'))
.hasProperty('home', path.join('/my/home'))
})

describe('win32', () => {
testConfig({
platform: 'win32',
env: {LOCALAPPDATA: '/my/home/localappdata'},
})
.hasProperty('cacheDir', path.join('/my/home/localappdata/@oclif\\config'))
.hasProperty('configDir', path.join('/my/home/localappdata/@oclif\\config'))
.hasProperty('errlog', path.join('/my/home/localappdata/@oclif\\config/error.log'))
.hasProperty('dataDir', path.join('/my/home/localappdata/@oclif\\config'))
.hasProperty('home', path.join('/my/home'))
.hasProperty('cacheDir', path.join('/my/home/localappdata/@oclif\\config'))
.hasProperty('configDir', path.join('/my/home/localappdata/@oclif\\config'))
.hasProperty('errlog', path.join('/my/home/localappdata/@oclif\\config/error.log'))
.hasProperty('dataDir', path.join('/my/home/localappdata/@oclif\\config'))
.hasProperty('home', path.join('/my/home'))
})

describe('s3Key', () => {
const target = {platform: 'darwin', arch: 'x64'}
const beta = {version: '2.0.0-beta', channel: 'beta'}
testConfig()
.hasS3Key('baseDir', 'oclif-cli')
.hasS3Key('manifest', 'version')
.hasS3Key('manifest', 'channels/beta/version', beta)
.hasS3Key('manifest', 'darwin-x64', target)
.hasS3Key('manifest', 'channels/beta/darwin-x64', {...beta, ...target})
.hasS3Key('unversioned', 'oclif-cli.tar.gz')
.hasS3Key('unversioned', 'oclif-cli.tar.gz')
.hasS3Key('unversioned', 'channels/beta/oclif-cli.tar.gz', beta)
.hasS3Key('unversioned', 'channels/beta/oclif-cli.tar.gz', beta)
.hasS3Key('unversioned', 'oclif-cli-darwin-x64.tar.gz', target)
.hasS3Key('unversioned', 'oclif-cli-darwin-x64.tar.gz', target)
.hasS3Key('unversioned', 'channels/beta/oclif-cli-darwin-x64.tar.gz', {...beta, ...target})
.hasS3Key('unversioned', 'channels/beta/oclif-cli-darwin-x64.tar.gz', {...beta, ...target})
.hasS3Key('versioned', 'oclif-cli-v1.0.0/oclif-cli-v1.0.0.tar.gz')
.hasS3Key('versioned', 'oclif-cli-v1.0.0/oclif-cli-v1.0.0-darwin-x64.tar.gz', target)
.hasS3Key('versioned', 'channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta.tar.gz', beta)
.hasS3Key('versioned', 'channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta-darwin-x64.tar.gz', {...beta, ...target})
.hasS3Key('baseDir', 'oclif-cli')
.hasS3Key('manifest', 'version')
.hasS3Key('manifest', 'channels/beta/version', beta)
.hasS3Key('manifest', 'darwin-x64', target)
.hasS3Key('manifest', 'channels/beta/darwin-x64', {...beta, ...target})
.hasS3Key('unversioned', 'oclif-cli.tar.gz')
.hasS3Key('unversioned', 'oclif-cli.tar.gz')
.hasS3Key('unversioned', 'channels/beta/oclif-cli.tar.gz', beta)
.hasS3Key('unversioned', 'channels/beta/oclif-cli.tar.gz', beta)
.hasS3Key('unversioned', 'oclif-cli-darwin-x64.tar.gz', target)
.hasS3Key('unversioned', 'oclif-cli-darwin-x64.tar.gz', target)
.hasS3Key('unversioned', 'channels/beta/oclif-cli-darwin-x64.tar.gz', {...beta, ...target})
.hasS3Key('unversioned', 'channels/beta/oclif-cli-darwin-x64.tar.gz', {...beta, ...target})
.hasS3Key('versioned', 'oclif-cli-v1.0.0/oclif-cli-v1.0.0.tar.gz')
.hasS3Key('versioned', 'oclif-cli-v1.0.0/oclif-cli-v1.0.0-darwin-x64.tar.gz', target)
.hasS3Key('versioned', 'channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta.tar.gz', beta)
.hasS3Key('versioned', 'channels/beta/oclif-cli-v2.0.0-beta/oclif-cli-v2.0.0-beta-darwin-x64.tar.gz', {...beta, ...target})
})

testConfig()
.it('has s3Url', config => {
const orig = config.pjson.oclif.update.s3.host
config.pjson.oclif.update.s3.host = 'https://bar.com/a/'
expect(config.s3Url('/b/c')).to.equal('https://bar.com/a/b/c')
config.pjson.oclif.update.s3.host = orig
})
.it('has s3Url', config => {
const orig = config.pjson.oclif.update.s3.host
config.pjson.oclif.update.s3.host = 'https://bar.com/a/'
expect(config.s3Url('/b/c')).to.equal('https://bar.com/a/b/c')
config.pjson.oclif.update.s3.host = orig
})

testConfig({
pjson: {
Expand All @@ -139,7 +139,7 @@ describe('Config', () => {
}
}
})
.it('has subtopics', config => {
expect(config.topics.map(t => t.name)).to.have.members(['t1', 't1:t1-1', 't1:t1-1:t1-1-1', 't1:t1-1:t1-1-2'])
})
.it('has subtopics', config => {
expect(config.topics.map(t => t.name)).to.have.members(['t1', 't1:t1-1', 't1:t1-1:t1-1-1', 't1:t1-1:t1-1-2'])
})
})
28 changes: 14 additions & 14 deletions test/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ const withConfig = fancy

describe('typescript', () => {
withConfig
.it('has commandsDir', ({config}) => {
expect(config.plugins[0]).to.deep.include({
commandsDir: p('src/commands'),
.it('has commandsDir', ({config}) => {
expect(config.plugins[0]).to.deep.include({
commandsDir: p('src/commands'),
})
})
})

withConfig
.stdout()
.it('runs ts command and prerun hooks', async ctx => {
await ctx.config.runCommand('foo:bar:baz')
expect(ctx.stdout).to.equal('running ts prerun hook\nit works!\n')
})
.stdout()
.it('runs ts command and prerun hooks', async ctx => {
await ctx.config.runCommand('foo:bar:baz')
expect(ctx.stdout).to.equal('running ts prerun hook\nit works!\n')
})

withConfig
.stdout()
.it('runs init hook', async ctx => {
await ctx.config.runHook('init', {id: 'myid', argv: ['foo']})
expect(ctx.stdout).to.equal('running ts init hook\n')
})
.stdout()
.it('runs init hook', async ctx => {
await ctx.config.runHook('init', {id: 'myid', argv: ['foo']})
expect(ctx.stdout).to.equal('running ts init hook\n')
})
})
Loading

0 comments on commit 01f51e6

Please sign in to comment.