Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
51 changes: 29 additions & 22 deletions src/Core/Actions/Typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,33 @@ class Script extends UpdateScript {
}

public async exec(rootpath: string): Promise<void> {
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>('tsconfig.json')
const declarations: string[] = []
const tsconfig = await project.json<TsConfig>('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<string[]> {
Expand All @@ -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<NPM>(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<string>(values)))
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Core/Files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Interfaces/NPM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface NPM {
typeScriptVersion: string,
typings?: string
version: string
workspace?: string[]
workspaces?: string[]
}
4 changes: 1 addition & 3 deletions src/Core/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Project {
const npm = await Files.json<NPM>(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
}
Expand Down Expand Up @@ -98,8 +98,8 @@ export class Project {

private async loadYarnWorkspaces(project: Project): Promise<Project> {
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)
Expand Down
3 changes: 0 additions & 3 deletions testables/single/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"chalk": "*"
},
"description": "single project",
"devDependencies": {
"@types/chalk": "*"
},
"name": "project-single",
"version": "1.0.0"
}
47 changes: 47 additions & 0 deletions testables/single/yarn.lock
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion testables/workspaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "project with workspaces",
"name": "project-workspaces",
"private": true,
"workspace": [
"workspaces": [
"packages/*",
"projects/*"
],
Expand Down
47 changes: 47 additions & 0 deletions testables/workspaces/yarn.lock
Original file line number Diff line number Diff line change
@@ -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"