forked from umijs/father
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build support auto-sorting & filter for lerna project (umijs#393)
* chore: add yarn workspaces * feat: add getLernaPackages * feat: getLernaPackages replace getPackages * feat: 支持配置getLernaPackages参数 * chore: update lerna.json * feat: schema add filterPkgs * test: 修复测试报错 * feat: filterPkgs rename pkgFilter * feat: getLernaPackages remove stream option * test: 修复测试报错 * feat: showPrivate => buildPrivate * docs: add pkgFilter doc * docs: 统一文档注释格式 * style: update comment style * feat: buildPrivate >> skipPrivate Co-authored-by: Peach <scdzwyxst@gmail.com>
- Loading branch information
1 parent
a23b823
commit 206d042
Showing
40 changed files
with
467 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-pkgs/core/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-pkgs/core/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
4 changes: 3 additions & 1 deletion
4
...ages/father-build/src/fixtures/build/lerna-root-config-override/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
...ages/father-build/src/fixtures/build/lerna-root-config-override/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-root-config/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-root-config/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-root-scope/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-root-scope/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-root-tsconfig/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-root-tsconfig/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-scope-packages/packages/@hoo/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "@hoo/bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna-scope-packages/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "bar" | ||
} |
4 changes: 3 additions & 1 deletion
4
packages/father-build/src/fixtures/build/lerna/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"name": "foo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,5 +165,8 @@ export default { | |
pkgs: { | ||
type: 'array', | ||
}, | ||
pkgFilter: { | ||
type: 'object', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/father-build/src/utils/getLernaPackages/fixtures/customize/core/core1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "core1", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"foo": "1.0.0" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/father-build/src/utils/getLernaPackages/fixtures/customize/core/core1/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
console.log('bar'); |
5 changes: 5 additions & 0 deletions
5
packages/father-build/src/utils/getLernaPackages/fixtures/customize/core/core2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "core2", | ||
"private": true, | ||
"version": "1.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/father-build/src/utils/getLernaPackages/fixtures/customize/core/core2/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
console.log('foo'); |
6 changes: 6 additions & 0 deletions
6
packages/father-build/src/utils/getLernaPackages/fixtures/customize/lerna.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"packages": [ | ||
"core/*", | ||
"packages/*" | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/father-build/src/utils/getLernaPackages/fixtures/customize/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "default-packages", | ||
"private": true | ||
} |
4 changes: 4 additions & 0 deletions
4
...ages/father-build/src/utils/getLernaPackages/fixtures/customize/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "bar", | ||
"version": "1.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
...ages/father-build/src/utils/getLernaPackages/fixtures/customize/packages/bar/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
console.log('bar'); |
7 changes: 7 additions & 0 deletions
7
...ages/father-build/src/utils/getLernaPackages/fixtures/customize/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"bar": "1.0.0" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...ages/father-build/src/utils/getLernaPackages/fixtures/customize/packages/foo/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
console.log('foo'); |
1 change: 1 addition & 0 deletions
1
packages/father-build/src/utils/getLernaPackages/fixtures/default/lerna.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
4 changes: 4 additions & 0 deletions
4
packages/father-build/src/utils/getLernaPackages/fixtures/default/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "default-packages", | ||
"private": true | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/father-build/src/utils/getLernaPackages/fixtures/default/packages/bar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "bar", | ||
"version": "1.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/father-build/src/utils/getLernaPackages/fixtures/default/packages/bar/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
console.log('bar'); |
7 changes: 7 additions & 0 deletions
7
packages/father-build/src/utils/getLernaPackages/fixtures/default/packages/foo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"bar": "1.0.0" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/father-build/src/utils/getLernaPackages/fixtures/default/packages/foo/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
console.log('foo'); |
83 changes: 83 additions & 0 deletions
83
packages/father-build/src/utils/getLernaPackages/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import { getLernaPackages } from './'; | ||
|
||
export const FIXTURES_DIR = path.resolve(__dirname, 'fixtures'); | ||
|
||
export function getDirs() { | ||
return fs | ||
.readdirSync(FIXTURES_DIR) | ||
.filter(fixturePath => | ||
fs.statSync(path.resolve(FIXTURES_DIR, fixturePath)).isDirectory(), | ||
); | ||
} | ||
|
||
export function fixture(...args: string[]) { | ||
return path.join(FIXTURES_DIR, ...args) | ||
} | ||
|
||
describe('default', () => { | ||
const fixturePath = fixture('default'); | ||
|
||
it('获取所有的包', async () => { | ||
expect.assertions(1); | ||
|
||
const pkgs = await getLernaPackages(fixturePath); | ||
|
||
const pkgNames = ['bar', 'foo']; | ||
|
||
expect(pkgNames).toEqual(pkgs.map(item => item.name)); | ||
}) | ||
}); | ||
|
||
describe('customize', () => { | ||
const fixturePath = fixture('customize'); | ||
|
||
it('获取所有的包', async () => { | ||
expect.assertions(1); | ||
|
||
const pkgs = await getLernaPackages(fixturePath, {}); | ||
|
||
const pkgNames = ['core2', 'bar', 'foo', 'core1']; | ||
|
||
expect(pkgNames).toEqual(pkgs.map(item => item.name)); | ||
}); | ||
|
||
it('过滤私有的包', async () => { | ||
expect.assertions(1); | ||
|
||
const pkgs = await getLernaPackages(fixturePath, { | ||
skipPrivate: true, | ||
}); | ||
|
||
const pkgNames = ['bar', 'foo', 'core1']; | ||
|
||
expect(pkgNames).toEqual(pkgs.map(item => item.name)); | ||
}); | ||
|
||
it('设置包含部分包', async () => { | ||
expect.assertions(1); | ||
|
||
const pkgs = await getLernaPackages(fixturePath, { | ||
include: [ | ||
'core*' | ||
] | ||
}); | ||
const pkgNames = ['core1', 'core2']; | ||
|
||
expect(pkgNames).toEqual(pkgs.map(item => item.name)); | ||
}) | ||
|
||
it('设置包含部分包', async () => { | ||
expect.assertions(1); | ||
|
||
const pkgs = await getLernaPackages(fixturePath, { | ||
exclude: [ | ||
'core1' | ||
] | ||
}); | ||
const pkgNames = ['core2', 'bar', 'foo']; | ||
|
||
expect(pkgNames).toEqual(pkgs.map(item => item.name)); | ||
}) | ||
}); |
Oops, something went wrong.