diff --git a/package.json b/package.json index b0be1d3..4e3d395 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "./lib/CLI.js", "typings": "./lib/index.d.ts", - "version": "2.0.0-alpha-11", + "version": "2.0.0-alpha-14", "dependencies": { "chalk": "^2.3.0" }, diff --git a/src/Core/Actions/Typings.ts b/src/Core/Actions/Typings.ts index 9055c93..69a7abd 100644 --- a/src/Core/Actions/Typings.ts +++ b/src/Core/Actions/Typings.ts @@ -28,34 +28,33 @@ class Script extends UpdateScript { } public async exec(rootpath: string): Promise { - try { - this.log.task('exec', rootpath) - const project = await Project.load(rootpath) + this.log.task('exec', rootpath) + const project = await Project.load(rootpath) - if (project === Project.InvalidProject) { - this.log.error(`failed to load any projects at ${rootpath}`) - return - } + if (project === Project.InvalidProject) { + this.log.error(`failed to load any projects at ${rootpath}`) + return + } - const tsconfig = await project.json('tsconfig.json') - const declarations: string[] = [] + const tsconfig = await project.json('tsconfig.json') + const definitions: string[] = [] + const deps = project.children.map(async child => { + this.log.debug('child project', child.name) + const dependencies = await this.gatherTypeDefinitions(child) + dependencies.forEach(dependency => definitions.push(dependency)) + }) - await Promise.all(project.children.map(async child => { - const dependencies = await this.gatherTypeDefinitions(child) - dependencies.forEach(dependency => declarations.push(dependency)) - })).then(async () => { - tsconfig.compilerOptions.types = declarations.sort() + return Promise.all(deps) + .then(async () => { + tsconfig.compilerOptions.types = Array.from(new Set(definitions)).sort() if (this.testing) { - this.log.task('tsconfig', JSON.stringify(tsconfig, null, 2)) + this.log.task('tsconfig', project.path, JSON.stringify(tsconfig, null, 2)) } else { await project.save('tsconfig.json', tsconfig) - this.log.task('tsconfig') + this.log.task('tsconfig', project.path) } }) - } catch (error) { - this.log.error(error) - } } private async gatherTypeDefinitions(project: Project): Promise { @@ -70,20 +69,28 @@ class Script extends UpdateScript { dependencies = dependencies.concat(Object.keys(npm.devDependencies)) } - const modulesPath = Files.join(project.path, 'node_modules') + const owner = project.owner || project + const modulesPath = Files.join(owner.path, 'node_modules') - return Promise.all(dependencies.map(async dependency => { + const deps = dependencies.map(async dependency => { const dependencyPath = Files.join(modulesPath, dependency, 'package.json') this.log.debug('dependencies', dependencyPath) + if (await Files.exists(dependencyPath)) { const npm = await Files.json(dependencyPath) if (npm.types || npm.typings) { this.log.debug('found dependency', dependency) return dependency } + } else { + this.log.debug('failed to find', dependencyPath) } return '' - })).then(values => values.filter(value => value)) + }) + + return Promise.all(deps) + .then(values => values.filter(value => value)) + .then(values => Array.from(new Set(values))) } } diff --git a/src/Core/Files.spec.ts b/src/Core/Files.spec.ts index 9d17dff..0025f9d 100644 --- a/src/Core/Files.spec.ts +++ b/src/Core/Files.spec.ts @@ -33,7 +33,6 @@ describe('when working with files', () => { it('should list files', async () => { const filepaths = await Files.listfiles(Files.join(process.cwd(), 'testables/single')) - expect(filepaths.length).to.equal(2) expect(filepaths).to.contain(Files.join(process.cwd(), 'testables/single/package.json')) expect(filepaths).to.contain(Files.join(process.cwd(), 'testables/single/tsconfig.json')) }) diff --git a/src/Core/Interfaces/NPM.ts b/src/Core/Interfaces/NPM.ts index c4db253..6f56998 100644 --- a/src/Core/Interfaces/NPM.ts +++ b/src/Core/Interfaces/NPM.ts @@ -16,5 +16,5 @@ export interface NPM { typeScriptVersion: string, typings?: string version: string - workspace?: string[] + workspaces?: string[] } diff --git a/src/Core/Logger.ts b/src/Core/Logger.ts index 69e1026..ba58c8c 100644 --- a/src/Core/Logger.ts +++ b/src/Core/Logger.ts @@ -14,9 +14,7 @@ export function Logger(name: string, category?: string): Log { const bold = (name: string) => chalk.default.bold(`[${name}${cat}]`) const log = (...args: any[]) => { - if (['production', 'test', 'testing'].every(env => env !== process.env.NODE_ENV)) { - console.log(...args) - } + console.log(...args) } return { diff --git a/src/Core/Project.ts b/src/Core/Project.ts index 4e6a316..7ffd632 100644 --- a/src/Core/Project.ts +++ b/src/Core/Project.ts @@ -56,7 +56,7 @@ export class Project { const npm = await Files.json(npmfile) const project = new Project(npm.name, rootpath) - if (npm.private && npm.workspace) { + if (npm.private && npm.workspaces) { const result = await project.loadChildProjects(npm) return result } @@ -98,8 +98,8 @@ export class Project { private async loadYarnWorkspaces(project: Project): Promise { const npm = await this.package - if (npm.workspace) { - return Promise.all(npm.workspace.map(async workspace => { + if (npm.workspaces) { + return Promise.all(npm.workspaces.map(async workspace => { const workspaceName = workspace.substring(0, workspace.indexOf('/*')) const workspacePath = Files.join(project.path, workspaceName) const children = await this.loadProjects(workspacePath) diff --git a/testables/single/package.json b/testables/single/package.json index a6cd6e0..9d2f952 100644 --- a/testables/single/package.json +++ b/testables/single/package.json @@ -3,9 +3,6 @@ "chalk": "*" }, "description": "single project", - "devDependencies": { - "@types/chalk": "*" - }, "name": "project-single", "version": "1.0.0" } diff --git a/testables/single/yarn.lock b/testables/single/yarn.lock new file mode 100644 index 0000000..d23afa2 --- /dev/null +++ b/testables/single/yarn.lock @@ -0,0 +1,47 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/chalk@*": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-2.2.0.tgz#b7f6e446f4511029ee8e3f43075fb5b73fbaa0ba" + dependencies: + chalk "*" + +ansi-styles@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88" + dependencies: + color-convert "^1.9.0" + +chalk@*: + version "2.3.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" + dependencies: + ansi-styles "^3.1.0" + escape-string-regexp "^1.0.5" + supports-color "^4.0.0" + +color-convert@^1.9.0: + version "1.9.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed" + dependencies: + color-name "^1.1.1" + +color-name@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + +escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +has-flag@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" + +supports-color@^4.0.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" + dependencies: + has-flag "^2.0.0" diff --git a/testables/workspaces/package.json b/testables/workspaces/package.json index fc4e478..53315b2 100644 --- a/testables/workspaces/package.json +++ b/testables/workspaces/package.json @@ -2,7 +2,7 @@ "description": "project with workspaces", "name": "project-workspaces", "private": true, - "workspace": [ + "workspaces": [ "packages/*", "projects/*" ], diff --git a/testables/workspaces/yarn.lock b/testables/workspaces/yarn.lock new file mode 100644 index 0000000..d23afa2 --- /dev/null +++ b/testables/workspaces/yarn.lock @@ -0,0 +1,47 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/chalk@*": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-2.2.0.tgz#b7f6e446f4511029ee8e3f43075fb5b73fbaa0ba" + dependencies: + chalk "*" + +ansi-styles@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88" + dependencies: + color-convert "^1.9.0" + +chalk@*: + version "2.3.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" + dependencies: + ansi-styles "^3.1.0" + escape-string-regexp "^1.0.5" + supports-color "^4.0.0" + +color-convert@^1.9.0: + version "1.9.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed" + dependencies: + color-name "^1.1.1" + +color-name@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + +escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +has-flag@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" + +supports-color@^4.0.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" + dependencies: + has-flag "^2.0.0"