From 3d5600b08b86650513768073b0cc9d0300dcd40a Mon Sep 17 00:00:00 2001 From: Mike Pham Date: Mon, 27 Nov 2017 15:41:42 -0500 Subject: [PATCH 1/2] fix: disable lerna support for now --- src/Core/Files.spec.ts | 12 +++-- src/Core/Project.spec.ts | 9 ++++ src/Core/Project.ts | 34 +++++-------- testables/workspaces-lerna/.yarnrc | 1 + testables/workspaces-lerna/package.json | 10 ++++ .../packages/simple-package/package.json | 12 +++++ .../projects/simple-project/package.json | 12 +++++ testables/workspaces-lerna/tsconfig.json | 8 +++ testables/workspaces-lerna/yarn.lock | 51 +++++++++++++++++++ 9 files changed, 123 insertions(+), 26 deletions(-) create mode 100644 testables/workspaces-lerna/.yarnrc create mode 100644 testables/workspaces-lerna/package.json create mode 100644 testables/workspaces-lerna/packages/simple-package/package.json create mode 100644 testables/workspaces-lerna/projects/simple-project/package.json create mode 100644 testables/workspaces-lerna/tsconfig.json create mode 100644 testables/workspaces-lerna/yarn.lock diff --git a/src/Core/Files.spec.ts b/src/Core/Files.spec.ts index 3801f85..6aad7ec 100644 --- a/src/Core/Files.spec.ts +++ b/src/Core/Files.spec.ts @@ -14,6 +14,9 @@ describe('when working with files', () => { const invalidFile = Files.join(artifacts, 'invalid', 'invalid.json') const nonexistant = Files.join(process.cwd(), 'nonexistant') const testables = Files.join(process.cwd(), 'testables') + const invalid = Files.join(testables, 'workspaces-invalid') + const lerna = Files.join(testables, 'workspaces-lerna') + const single = Files.join(testables, 'single') const workspaces = Files.join(testables, 'workspaces') before(async () => { @@ -27,10 +30,11 @@ describe('when working with files', () => { it('should list directories', async () => { const directories = await Files.listdirs(testables) - expect(directories.length).to.equal(3) - expect(directories).to.contain(Files.join(process.cwd(), 'testables/single')) - expect(directories).to.contain(Files.join(process.cwd(), 'testables/workspaces')) - expect(directories).to.contain(Files.join(process.cwd(), 'testables/workspaces-invalid')) + expect(directories.length).to.equal(4) + expect(directories).to.contain(lerna) + expect(directories).to.contain(invalid) + expect(directories).to.contain(single) + expect(directories).to.contain(workspaces) }) it('should throw error when listing directories', (done) => { diff --git a/src/Core/Project.spec.ts b/src/Core/Project.spec.ts index 27a0bd6..00e50de 100644 --- a/src/Core/Project.spec.ts +++ b/src/Core/Project.spec.ts @@ -10,6 +10,7 @@ const expect = chai.expect const testables = Files.join(process.cwd(), 'testables') const single = Files.join(testables, 'single') +const lerna = Files.join(testables, 'workspaces-lerna') const workspaces = Files.join(testables, 'workspaces') const TIMEOUT = 10000 @@ -29,6 +30,14 @@ describe('when loading projects', () => { }) }).timeout(TIMEOUT) + it('should load yarn lerna project', () => { + return Project.load(lerna).then(project => { + expect(project.children.length).to.equal(2) + expect(project.children[0].owner).to.not.equal(undefined) + expect(project.children[1].owner).to.not.equal(undefined) + }) + }).timeout(TIMEOUT) + it('should load yarn workspace project', () => { return Project.load(workspaces).then(project => { expect(project.children.length).to.equal(2) diff --git a/src/Core/Project.ts b/src/Core/Project.ts index 09db40f..2e4795a 100644 --- a/src/Core/Project.ts +++ b/src/Core/Project.ts @@ -40,22 +40,10 @@ export class Project { return this._path } - public static async load(rootpath: string): Promise { - const npmfile = Files.join(rootpath, 'package.json') - - if (await Files.exists(npmfile) === false) { - return Project.InvalidProject - } - - const npm = await Files.json(npmfile) - const project = new Project(npm.name, rootpath) - - if (npm.private && npm.workspaces) { - const result = await project.loadChildProjects(npm) - return result - } - - return project + public static load(rootpath: string): Promise { + return Files.json(Files.join(rootpath, 'package.json')) + .then(npm => ({ npm, project: new Project(npm.name, rootpath) })) + .then(load => load.project.workspaces(load.npm).then(() => load.project)) } public json(filename: string): Promise { @@ -66,17 +54,19 @@ export class Project { return Files.save(Files.join(this.path, filename), data) } - private async loadChildProjects(npm: NPM): Promise { + private workspaces(npm: NPM): Promise { + /* const lernafile = Files.join(this.path, 'lerna.json') + if (await Files.exists(lernafile)) { this.log.debug('lerna-packages', this.path) - return this.loadLernaPackages(lernafile, this) + return this.lerna(lernafile, this) } - this.log.debug('yarn-workspaces', this.path) - return this.loadYarnWorkspaces(this) + */ + return this.yarn(this) } - private async loadLernaPackages(filepath: string, project: Project): Promise { + private async lerna(filepath: string, project: Project): Promise { const lerna = await Files.json(filepath) if (lerna.packages && lerna.useWorkspaces) { lerna.packages.forEach(async workspace => { @@ -90,7 +80,7 @@ export class Project { return this } - private async loadYarnWorkspaces(project: Project): Promise { + private async yarn(project: Project): Promise { const npm = await this.npm if (npm.workspaces) { return Promise.all(npm.workspaces.map(async workspace => { diff --git a/testables/workspaces-lerna/.yarnrc b/testables/workspaces-lerna/.yarnrc new file mode 100644 index 0000000..19daaca --- /dev/null +++ b/testables/workspaces-lerna/.yarnrc @@ -0,0 +1 @@ +workspaces-experimental true diff --git a/testables/workspaces-lerna/package.json b/testables/workspaces-lerna/package.json new file mode 100644 index 0000000..53315b2 --- /dev/null +++ b/testables/workspaces-lerna/package.json @@ -0,0 +1,10 @@ +{ + "description": "project with workspaces", + "name": "project-workspaces", + "private": true, + "workspaces": [ + "packages/*", + "projects/*" + ], + "version": "1.0.0" +} diff --git a/testables/workspaces-lerna/packages/simple-package/package.json b/testables/workspaces-lerna/packages/simple-package/package.json new file mode 100644 index 0000000..7e4eefd --- /dev/null +++ b/testables/workspaces-lerna/packages/simple-package/package.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "chalk": "^2.3.0" + }, + "description": "project with workspaces", + "devDependencies": { + "@types/chalk": "^2.2.0", + "@types/node": "^8.0.52" + }, + "name": "simple-package", + "version": "1.0.0" +} \ No newline at end of file diff --git a/testables/workspaces-lerna/projects/simple-project/package.json b/testables/workspaces-lerna/projects/simple-project/package.json new file mode 100644 index 0000000..f395554 --- /dev/null +++ b/testables/workspaces-lerna/projects/simple-project/package.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "chalk": "^2.3.0" + }, + "description": "project with workspaces", + "devDependencies": { + "@types/chalk": "^2.2.0", + "@types/node": "^8.0.52" + }, + "name": "simple-project", + "version": "1.0.0" +} \ No newline at end of file diff --git a/testables/workspaces-lerna/tsconfig.json b/testables/workspaces-lerna/tsconfig.json new file mode 100644 index 0000000..fa38149 --- /dev/null +++ b/testables/workspaces-lerna/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "types": [ + "@types/node", + "chalk" + ] + } +} \ No newline at end of file diff --git a/testables/workspaces-lerna/yarn.lock b/testables/workspaces-lerna/yarn.lock new file mode 100644 index 0000000..018ae30 --- /dev/null +++ b/testables/workspaces-lerna/yarn.lock @@ -0,0 +1,51 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/chalk@^2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-2.2.0.tgz#b7f6e446f4511029ee8e3f43075fb5b73fbaa0ba" + 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" + dependencies: + color-convert "^1.9.0" + +chalk@*, chalk@^2.3.0: + 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" From ac230eaf221970d444ec90d03611f6e16f47c37c Mon Sep 17 00:00:00 2001 From: Mike Pham Date: Mon, 27 Nov 2017 15:44:20 -0500 Subject: [PATCH 2/2] feat: disable lerna support --- src/Core/Project.ts | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/Core/Project.ts b/src/Core/Project.ts index 2e4795a..952b26b 100644 --- a/src/Core/Project.ts +++ b/src/Core/Project.ts @@ -1,5 +1,5 @@ import { Files } from './Files' -import { LernaConfig, NPM } from './Interfaces' +import { NPM } from './Interfaces' import { Log, Logger } from './Logger' export class Project { @@ -55,31 +55,9 @@ export class Project { } private workspaces(npm: NPM): Promise { - /* - const lernafile = Files.join(this.path, 'lerna.json') - - if (await Files.exists(lernafile)) { - this.log.debug('lerna-packages', this.path) - return this.lerna(lernafile, this) - } - */ return this.yarn(this) } - private async lerna(filepath: string, project: Project): Promise { - const lerna = await Files.json(filepath) - if (lerna.packages && lerna.useWorkspaces) { - lerna.packages.forEach(async workspace => { - const workspaceName = workspace.substring(0, workspace.indexOf('/*')) - const workspacePath = Files.join(project.path, workspaceName) - const children = await this.loadProjects(workspacePath) - children.forEach(child => this.children.push(child)) - this.log.debug('lerna-package', workspaceName) - }) - } - return this - } - private async yarn(project: Project): Promise { const npm = await this.npm if (npm.workspaces) {