diff --git a/src/Chest.spec.ts b/src/Chest.spec.ts index babcbaa..e4b2562 100644 --- a/src/Chest.spec.ts +++ b/src/Chest.spec.ts @@ -6,6 +6,8 @@ import * as chaiAsPromised from 'chai-as-promised' import { Chest } from './Chest' import { Files, Project, Registry } from './Core' +const TIMEOUT = 5000 + const expect = chai.expect describe('when loading projects', () => { @@ -19,12 +21,12 @@ describe('when loading projects', () => { const directory = Files.join(process.cwd(), 'testables', 'single') const args = Object.keys(Registry.all()) return Chest.run(directory, ...args) - }) + }).timeout(TIMEOUT) it('should run scripts for workspace project', () => { const directory = Files.join(process.cwd(), 'testables', 'workspaces') const args = Object.keys(Registry.all()) return Chest.run(directory, ...args) - }) + }).timeout(TIMEOUT) }) diff --git a/src/Core/Actions/Typings.spec.ts b/src/Core/Actions/Typings.spec.ts index 8ef2e7a..08da5f9 100644 --- a/src/Core/Actions/Typings.spec.ts +++ b/src/Core/Actions/Typings.spec.ts @@ -1,7 +1,7 @@ import 'mocha' import { expect } from 'chai' -import { Files, Project, Registry, TypeScriptOptions } from '../index' +import { Files, Project, Registry, TypeScriptConfig } from '../index' const TIMEOUT = 5000 @@ -15,8 +15,8 @@ describe('when collecting type declarations', () => { const script = Registry.get('typings') return Project.load(single).then(project => script.exec(project) - .then(project => project.json('tsconfig.json')) - .then(json => expect(json.compilerOptions.types).to.contain('chalk')) + .then(project => project.json('tsconfig.json')) + .then(tsconfig => expect(tsconfig.compilerOptions.types).to.have.lengthOf(2)) ) }).timeout(TIMEOUT) @@ -24,8 +24,8 @@ describe('when collecting type declarations', () => { const script = Registry.get('typings') return Project.load(workspaces).then(project => script.exec(project) - .then(project => project.json('tsconfig.json')) - .then(json => expect(json.compilerOptions.types).to.contain('chalk')) + .then(project => project.json('tsconfig.json')) + .then(tsconfig => expect(tsconfig.compilerOptions.types).to.have.lengthOf(2)) ) }).timeout(TIMEOUT) diff --git a/src/Core/Actions/Typings.ts b/src/Core/Actions/Typings.ts index 6f568ab..3a2f7f3 100644 --- a/src/Core/Actions/Typings.ts +++ b/src/Core/Actions/Typings.ts @@ -1,4 +1,4 @@ -import { Files, NPM, Project, Registry, TypeScriptOptions, UpdateScript } from '../index' +import { Files, NPM, Project, Registry, TypeScriptConfig, UpdateScript } from '../index' /* * Updates the "types" property of "tsconfig.json" files by @@ -13,31 +13,39 @@ class Script extends UpdateScript { public exec(project: Project): Promise { return super.exec(project).then(project => - this.declarations([project, ...project.children]) + this.dependencies([project, ...project.children]) .then(typings => this.typings(project, typings)) .then(() => project) ) } - private declarations(projects: Project[]): Promise { + private dependencies(projects: Project[]): Promise { return Promise.all(projects.map(project => project.npm)) - .then(npms => npms.map(npm => this.dependencies(npm))) + .then(npms => npms.map(npm => this.mergedeps(npm))) .then(deps => deps.reduce((previous, current) => previous.concat(current), [])) - .then(deps => Array.from(new Set(deps))) + .then(deps => Array.from(new Set(deps)).sort()) } - private dependencies(npm: NPM): string[] { + private mergedeps(npm: NPM): string[] { const deps = Object.keys(npm.dependencies || {}) const devs = Object.keys(npm.devDependencies || {}) - return Array.from(new Set([...deps, ...devs])) + return Array.from(new Set([...deps, ...devs])).sort() } private typings(project: Project, typings: string[]): Promise { return Promise.all(typings.map(typing => Files.join(project.path, 'node_modules', typing, 'package.json'))) .then(typings => Promise.all(typings.map(typing => Files.json(typing)))) - .then(npms => npms.filter(npm => npm.types || npm.typings || npm.typeScriptVersion).map(npm => npm.name)) - .then(typings => project.json('tsconfig.json').then(tsconfig => { - tsconfig.compilerOptions.types = typings.sort() + .then(npms => { + npms.forEach(npm => this.log.info('dependency', npm.name)) + return npms + }) + .then(npms => npms.filter(npm => npm.types || npm.typings || npm.typeScriptVersion)) + .then(npms => { + npms.forEach(npm => this.log.task(`${npm.name} ->`, npm.types || npm.typings || npm.name)) + return npms + }) + .then(npms => project.json('tsconfig.json').then(tsconfig => { + tsconfig.compilerOptions.types = npms.map(npm => npm.name).sort() return tsconfig })) .then(tsconfig => project.save('tsconfig.json', tsconfig)) diff --git a/src/Core/Interfaces/TypeScriptOptions.ts b/src/Core/Interfaces/TypeScriptConfig.ts similarity index 69% rename from src/Core/Interfaces/TypeScriptOptions.ts rename to src/Core/Interfaces/TypeScriptConfig.ts index 2653007..a668ed5 100644 --- a/src/Core/Interfaces/TypeScriptOptions.ts +++ b/src/Core/Interfaces/TypeScriptConfig.ts @@ -1,5 +1,5 @@ import { CompilerOptions } from 'typescript' -export interface TypeScriptOptions { +export interface TypeScriptConfig { compilerOptions: CompilerOptions } diff --git a/src/Core/Interfaces/index.ts b/src/Core/Interfaces/index.ts index f38904e..1b1a977 100644 --- a/src/Core/Interfaces/index.ts +++ b/src/Core/Interfaces/index.ts @@ -1,4 +1,4 @@ export * from './Dictionary' export * from './NPM' -export * from './TypeScriptOptions' +export * from './TypeScriptConfig' export * from './Updater' diff --git a/src/Core/Project.ts b/src/Core/Project.ts index 0859f4e..a2dbb53 100644 --- a/src/Core/Project.ts +++ b/src/Core/Project.ts @@ -23,7 +23,7 @@ export class Project { this._owner = owner this._path = path - this.log = Logger(`project:${this.name}`) + this.log = Logger(`chest:project:${this.name}`) } public get children(): Project[] { diff --git a/src/Core/Registry.spec.ts b/src/Core/Registry.spec.ts index 8e02058..d7115f7 100644 --- a/src/Core/Registry.spec.ts +++ b/src/Core/Registry.spec.ts @@ -16,17 +16,9 @@ class DoesNothingGoesNowhereRoot extends UpdateScript { } } -class DoesNothingGoesNowhereProjects extends UpdateScript { - constructor() { - super(ProjectsScriptName) - } -} - describe('when using the script registry', () => { - it('should return registered script names', () => { - expect(Registry.names().length).to.be.gt(0) - }) + it('should return registered script names', () => expect(Registry.names().length).to.be.gt(0)) it('should register new script object', () => { expect(Registry.contains(RootScriptName)).to.equal(false) @@ -35,8 +27,6 @@ describe('when using the script registry', () => { expect(Registry.get(RootScriptName).name).to.equal(RootScriptName) }) - it('should throw error when calling "get" and script does not exist', () => { - expect(() => Registry.get('invalid')).to.throw() - }) + it('should throw error when calling passing invalid to "get"', () => expect(() => Registry.get('invalid')).to.throw()) }) diff --git a/testables/workspaces-invalid/package.json b/testables/workspaces-invalid/package.json index 097624d..10ca9bc 100644 --- a/testables/workspaces-invalid/package.json +++ b/testables/workspaces-invalid/package.json @@ -4,7 +4,8 @@ }, "description": "invalid workspace project", "devDependencies": { - "@types/chalk": "*" + "@types/chalk": "*", + "@types/node": "^8.0.52" }, "name": "project-single", "private": true, diff --git a/testables/workspaces-invalid/tsconfig.json b/testables/workspaces-invalid/tsconfig.json deleted file mode 100644 index 875cb60..0000000 --- a/testables/workspaces-invalid/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "compilerOptions": {} -} diff --git a/testables/workspaces/packages/simple-package/package.json b/testables/workspaces/packages/simple-package/package.json index cf97eb8..7e4eefd 100644 --- a/testables/workspaces/packages/simple-package/package.json +++ b/testables/workspaces/packages/simple-package/package.json @@ -4,7 +4,8 @@ }, "description": "project with workspaces", "devDependencies": { - "@types/chalk": "^2.2.0" + "@types/chalk": "^2.2.0", + "@types/node": "^8.0.52" }, "name": "simple-package", "version": "1.0.0" diff --git a/testables/workspaces/packages/simple-package/tsconfig.json b/testables/workspaces/packages/simple-package/tsconfig.json deleted file mode 100644 index 875cb60..0000000 --- a/testables/workspaces/packages/simple-package/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "compilerOptions": {} -} diff --git a/testables/workspaces/projects/simple-project/package.json b/testables/workspaces/projects/simple-project/package.json index 033e8b7..f395554 100644 --- a/testables/workspaces/projects/simple-project/package.json +++ b/testables/workspaces/projects/simple-project/package.json @@ -4,7 +4,8 @@ }, "description": "project with workspaces", "devDependencies": { - "@types/chalk": "^2.2.0" + "@types/chalk": "^2.2.0", + "@types/node": "^8.0.52" }, "name": "simple-project", "version": "1.0.0" diff --git a/testables/workspaces/projects/simple-project/tsconfig.json b/testables/workspaces/projects/simple-project/tsconfig.json deleted file mode 100644 index 875cb60..0000000 --- a/testables/workspaces/projects/simple-project/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "compilerOptions": {} -} diff --git a/testables/workspaces/tsconfig.json b/testables/workspaces/tsconfig.json index ba970d3..fa38149 100644 --- a/testables/workspaces/tsconfig.json +++ b/testables/workspaces/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "types": [ + "@types/node", "chalk" ] } diff --git a/testables/workspaces/yarn.lock b/testables/workspaces/yarn.lock index 4ab6260..018ae30 100644 --- a/testables/workspaces/yarn.lock +++ b/testables/workspaces/yarn.lock @@ -8,6 +8,10 @@ dependencies: chalk "*" +"@types/node@^8.0.52": + version "8.0.53" + resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.53.tgz#396b35af826fa66aad472c8cb7b8d5e277f4e6d8" + ansi-styles@^3.1.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"