我有一个用于前端应用程序和库的lerna和yarn工作区的monorepo。我在根package.json处添加了一系列npm脚本,以像本文末尾的代码一样管理每个软件包(应用程序,lib,插件)。问题是我的根package.json越来越大,我才刚刚开始。另一个问题是,如果我需要在CRM中使用i18n lib的组件库中开发一个组件,则需要在3个单独的终端窗口中启动3个程序包,并且可能同时开发更多依赖程序包。 / p>
例如,我认为在CRM中安装的每个软件包(使用--parallel)中都放置start:crm
,这不是一个好主意。
我看到一个示例,该文件是通过文件系统从另一个软件包中导入文件(成为正在运行的应用程序的文件监视的一部分),而忽略了软件包的根文件夹,我担心这种方法,因为它破坏了版本控制
你们如何处理这些问题?
"/** CRM SCRIPTS */": "",
"start:crm": "npx lerna run start --scope @kovi-cx-frontend/crm",
"build:crm": "npx lerna run build --stream --scope @kovi-cx-frontend/crm",
"test:crm": "npx lerna run test --stream --scope @kovi-cx-frontend/crm",
"lint:crm": "npx lerna run lint --stream --scope @kovi-cx-frontend/crm",
"codegen:crm": "npx lerna run codegen --scope @kovi-cx-frontend/crm",
"start:crm:storybook": "npx lerna run start:storybook --stream --scope @kovi-cx-frontend/crm",
"build:crm:storybook": "npx lerna run build:storybook --stream --scope @kovi-cx-frontend/crm",
答案 0 :(得分:0)
在这里必须使用适当的工具。
我有一个类似的问题:纱线工作区中包含数十个程序包,它们之间相互依赖。
我的package.json
看起来像这样:
{
"scripts": {
"all": "run-s \"generic all\" \"all:apps all\" --",
"all:apps": "run-p --aggregate-output \"eslint-config {@}\" \"apps1 {@}\" \"apps2 {@}\" --",
"apps1": "run-s \"apps1:deps {@}\" \"apps1:c {@}\" --",
"apps1:c": "run-p --aggregate-output \"hatsy:c {@}\" --",
"apps1:deps": "run-s \"route-match:c {@}\" --",
"apps2": "run-p --aggregate-output \"siteparts:c {@}\" \"realworld-app:c {@}\" \"examples:c {@}\" --",
"build": "run-s \"generic build {@}\" \"all:apps build {@}\" --",
"lint": "run-p --aggregate-output \"generic lint {@}\" \"all:apps lint {@}\" --",
"test": "run-p --aggregate-output \"generic test {@}\" \"test:apps test {@}\" --",
"test:apps": "run-p --aggregate-output \"apps1:deps {@}\" \"apps1:c {@}\" \"siteparts:c {@}\" \"realworld-app:c {@}\" --",
"a-iterable": "run-s \"call-thru {@}\" \"a-iterable:c {@}\" --",
"a-iterable:c": "run-s -l \"a-iterable:x {@}\" --",
"a-iterable:x": "yarn workspace @proc7ts/a-iterable",
"call-thru": "run-s \"primitives:c {@}\" \"call-thru:c {@}\" --",
"call-thru:c": "run-s -l \"call-thru:x {@}\" --",
"call-thru:x": "yarn workspace @proc7ts/call-thru",
"context-values": "run-s \"call-thru {@}\" \"context-values:deps {@}\" \"context-values:c {@}\" --",
"context-values:c": "run-s -l \"context-values:x {@}\" --",
"context-values:deps": "run-p --aggregate-output \"a-iterable:c {@}\" \"fun-events:c {@}\" --",
"context-values:x": "yarn workspace @proc7ts/context-values",
"delta-set": "run-s \"delta-set:c {@}\" --",
"delta-set:c": "run-s -l \"delta-set:x {@}\" --",
"delta-set:x": "yarn workspace @proc7ts/delta-set",
"eslint-config": "run-s \"eslint-config:c {@}\" --",
"eslint-config:c": "run-s -l \"eslint-config:x {@}\" --",
"eslint-config:x": "yarn workspace @proc7ts/eslint-config",
"fun-events": "run-s \"call-thru {@}\" \"fun-events:c {@}\" --",
"fun-events:c": "run-s -l \"fun-events:x {@}\" --",
"fun-events:x": "yarn workspace @proc7ts/fun-events",
"hatsy": "run-s \"hatsy:deps {@}\" \"hatsy:c {@}\" --",
"hatsy:c": "run-s -l \"hatsy:x {@}\" --",
"hatsy:deps": "run-p --aggregate-output \"route-match {@}\" \"http-header-value:c {@}\" --",
"hatsy:x": "yarn workspace @hatsy/hatsy",
"http-header-value": "run-s \"http-header-value:c {@}\" --",
"http-header-value:c": "run-s -l \"http-header-value:x {@}\" --",
"http-header-value:x": "yarn workspace @hatsy/http-header-value",
"route-match": "run-s \"primitives:c {@}\" \"route-match:c {@}\" --",
"route-match:c": "run-s -l \"route-match:x {@}\" --",
"route-match:x": "yarn workspace @hatsy/route-match",
"input-aspects": "run-s \"input-aspects:deps0 {@}\" \"input-aspects:deps1 {@}\" \"input-aspects:c {@}\" --",
"input-aspects:c": "run-s -l \"input-aspects:x {@}\" --",
"input-aspects:deps0": "run-p --aggregate-output \"call-thru {@}\" \"namespace-aliaser:c {@}\" \"render-scheduler:c {@}\" --",
"input-aspects:deps1": "run-p --aggregate-output \"a-iterable:c {@}\" \"fun-events:c {@}\" \"delta-set:c {@}\" --",
"input-aspects:x": "yarn workspace @proc7ts/input-aspects",
"namespace-aliaser": "run-s \"namespace-aliaser:c {@}\" --",
"namespace-aliaser:c": "run-s -l \"namespace-aliaser:x {@}\" --",
"namespace-aliaser:x": "yarn workspace @proc7ts/namespace-aliaser",
"primitives": "run-s \"primitives:c {@}\" --",
"primitives:c": "run-s -l \"primitives:x {@}\" --",
"primitives:x": "yarn workspace @proc7ts/primitives",
"render-scheduler": "run-s \"render-scheduler:c {@}\" --",
"render-scheduler:c": "run-s -l \"render-scheduler:x {@}\" --",
"render-scheduler:x": "yarn workspace @proc7ts/render-scheduler",
"style-producer": "run-s \"style-producer:deps0 {@}\" \"style-producer:deps1 {@}\" \"style-producer:c {@}\" --",
"style-producer:c": "run-s -l \"style-producer:x {@}\" --",
"style-producer:deps0": "run-p --aggregate-output \"call-thru {@}\" \"namespace-aliaser:c {@}\" \"render-scheduler:c {@}\" --",
"style-producer:deps1": "run-p --aggregate-output \"a-iterable:c {@}\" \"fun-events:c {@}\" --",
"style-producer:x": "yarn workspace @proc7ts/style-producer",
"examples": "run-s \"generic {@}\" \"examples:c {@}\" --",
"examples:c": "run-s -l \"examples:x {@}\" --",
"examples:x": "yarn workspace @wesib/examples",
"generic": "run-s \"wesib {@}\" \"generic:deps {@}\" \"generic:c {@}\" --",
"generic:c": "run-s -l \"generic:x {@}\" --",
"generic:x": "yarn workspace @wesib/generic",
"generic:deps": "run-p --aggregate-output \"http-header-value:c {@}\" \"input-aspects:c {@}\" \"style-producer:c {@}\" --",
"realworld-app": "run-s \"generic {@}\" \"realworld-app:c {@}\" --",
"realworld-app:c": "run-s -l \"realworld-app:x {@}\" --",
"realworld-app:x": "yarn workspace @wesib/realworld-app",
"wesib": "run-s \"wesib:deps {@}\" \"wesib:c {@}\" --",
"wesib:c": "run-s -l \"wesib:x {@}\" --",
"wesib:x": "yarn workspace @wesib/wesib",
"wesib:deps": "run-p --aggregate-output \"context-values {@}\" \"namespace-aliaser:c {@}\" \"render-scheduler:c {@}\" --",
"siteparts": "run-s \"generic {@}\" \"siteparts:deps {@}\" \"siteparts:c {@}\" --",
"siteparts:c": "run-s -l \"siteparts:x {@}\" --",
"siteparts:deps": "run-s \"route-match:c {@}\" \"hatsy:c {@}\" --",
"siteparts:x": "yarn workspace @surol/siteparts"
}
}
这绝对不是 可行的方式。
所以我创建了run-z。
package.json
现在看起来像这样:
{
"scripts": {
"each": "run-z ...proc7ts ...hatsy ...wesib ...siteparts",
"each:p": "run-z --bap ...dev-kit ...run-z ...each",
"+dev-kit/*": "run-z +z ./dev-kit...dev-kit",
"hatsy/*": "run-z +z ./hatsy// ./hatsy/kit/packages//",
"proc7ts/*": "run-z +z ./proc7ts//",
"+run-z/*": "run-z +z ./run-z//",
"siteparts/*": "run-z +z ./siteparts",
"wesib/*": "run-z +z ./wesib//",
"z": "run-z +z:clean +z:test",
"z:clean": "run-z +each:p/clean",
"z:test": "run-z +each:p/lint,+each:p/cmd:jest/--runInBand"
}
}
所以,现在我可以:
yarn z clean build --all
重建所有软件包,yarn z build test --only hatsy
来构建和测试软件包的命名子集,yarn build --with-deps
来构建它及其依赖项,lint
和test
)...还有更多
run-z
需要花一些时间来学习,但结果令人满意。
顺便说一句,您可以尝试安装它而不安装它。例如。以下命令
npx run-z build:crm build:crm:storybook test:crm,lint:crm start:crm,start:crm:storybook
将先构建CRM和故事书,然后测试并完成测试(彼此并行),然后再启动CRM和故事书(同样,彼此并行)。