@modern-js/monorepo-tools 1.4.0 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +68 -0
  3. package/dist/js/modern/cli/build-watch.js +3 -3
  4. package/dist/js/modern/cli/build.js +2 -2
  5. package/dist/js/modern/cli/clear.js +2 -2
  6. package/dist/js/modern/cli/deploy.js +2 -2
  7. package/dist/js/modern/cli/install.js +2 -2
  8. package/dist/js/modern/commands/build-watch.js +2 -4
  9. package/dist/js/modern/commands/build.js +2 -4
  10. package/dist/js/modern/commands/clear.js +3 -5
  11. package/dist/js/modern/commands/deploy.js +5 -6
  12. package/dist/js/modern/commands/install.js +2 -4
  13. package/dist/js/modern/dag/utils.js +0 -1
  14. package/dist/js/modern/features/build/index.js +2 -3
  15. package/dist/js/modern/features/deploy/index.js +3 -8
  16. package/dist/js/modern/features/dev/create-task.js +1 -2
  17. package/dist/js/modern/features/dev/index.js +1 -2
  18. package/dist/js/modern/features/install/index.js +3 -7
  19. package/dist/js/modern/hooks/index.js +2 -5
  20. package/dist/js/modern/index.js +22 -22
  21. package/dist/js/modern/log/multi-tasks-log.js +1 -1
  22. package/dist/js/modern/log/time.js +1 -1
  23. package/dist/js/modern/projects/get-projects-by-workspace-file.js +13 -6
  24. package/dist/js/modern/utils/install.js +1 -2
  25. package/dist/js/node/cli/build-watch.js +3 -3
  26. package/dist/js/node/cli/build.js +2 -2
  27. package/dist/js/node/cli/clear.js +2 -2
  28. package/dist/js/node/cli/deploy.js +2 -2
  29. package/dist/js/node/cli/install.js +2 -2
  30. package/dist/js/node/commands/build-watch.js +2 -5
  31. package/dist/js/node/commands/build.js +2 -5
  32. package/dist/js/node/commands/clear.js +3 -6
  33. package/dist/js/node/commands/deploy.js +5 -7
  34. package/dist/js/node/commands/install.js +2 -5
  35. package/dist/js/node/dag/utils.js +0 -1
  36. package/dist/js/node/features/build/index.js +5 -7
  37. package/dist/js/node/features/deploy/index.js +6 -16
  38. package/dist/js/node/features/dev/create-task.js +2 -6
  39. package/dist/js/node/features/dev/index.js +3 -5
  40. package/dist/js/node/features/install/index.js +4 -11
  41. package/dist/js/node/hooks/index.js +4 -10
  42. package/dist/js/node/index.js +25 -29
  43. package/dist/js/node/log/multi-tasks-log.js +4 -4
  44. package/dist/js/node/log/time.js +2 -2
  45. package/dist/js/node/projects/get-projects-by-workspace-file.js +16 -9
  46. package/dist/js/node/utils/install.js +2 -6
  47. package/dist/types/cli/build-watch.d.ts +3 -2
  48. package/dist/types/cli/build.d.ts +3 -2
  49. package/dist/types/cli/clear.d.ts +3 -2
  50. package/dist/types/cli/deploy.d.ts +3 -2
  51. package/dist/types/cli/install.d.ts +3 -2
  52. package/dist/types/cli/new.d.ts +1 -1
  53. package/dist/types/commands/build-watch.d.ts +2 -1
  54. package/dist/types/commands/build.d.ts +2 -1
  55. package/dist/types/commands/clear.d.ts +2 -1
  56. package/dist/types/commands/deploy.d.ts +2 -1
  57. package/dist/types/commands/install.d.ts +2 -1
  58. package/dist/types/hooks/index.d.ts +7 -1
  59. package/dist/types/index.d.ts +2 -3
  60. package/dist/types/log/time.d.ts +2 -2
  61. package/jest.config.js +0 -1
  62. package/package.json +9 -17
  63. package/tests/index.test.ts +0 -7
  64. package/tests/tsconfig.json +0 -13
package/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['@modern-js'],
4
+ parserOptions: {
5
+ tsconfigRootDir: __dirname,
6
+ project: ['./tsconfig.json'],
7
+ },
8
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # @modern-js/monorepo-tools
2
2
 
3
+ ## 1.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 6cffe99d: chore:
8
+ remove react eslint rules for `modern-js` rule set.
9
+ add .eslintrc for each package to speed up linting
10
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
11
+ - 60f7d8bf: feat: add tests dir to npmignore
12
+ - 305e0bb4: fix: commander.commandsMap typing not work
13
+ - 2888389b: add parse config for lerna
14
+ - Updated dependencies [a4330c73]
15
+ - Updated dependencies [b8599d09]
16
+ - Updated dependencies [6cffe99d]
17
+ - Updated dependencies [04ae5262]
18
+ - Updated dependencies [60f7d8bf]
19
+ - Updated dependencies [e4cec1ce]
20
+ - Updated dependencies [3b7aa8bb]
21
+ - Updated dependencies [5dbbeb57]
22
+ - Updated dependencies [ebfcbb35]
23
+ - Updated dependencies [3bf4f8b0]
24
+ - Updated dependencies [305e0bb4]
25
+ - @modern-js/core@1.8.0
26
+ - @modern-js/utils@1.5.0
27
+ - @modern-js/i18n-cli-language-detector@1.2.2
28
+ - @modern-js/plugin-changeset@1.2.5
29
+ - @modern-js/plugin-i18n@1.2.4
30
+ - @modern-js/new-action@1.3.6
31
+ - @modern-js/plugin@1.3.3
32
+
33
+ ## 1.4.2
34
+
35
+ ### Patch Changes
36
+
37
+ - 07a4887e: feat: prebundle commander and signale to @modern-js/utils
38
+ - Updated dependencies [60855eb2]
39
+ - Updated dependencies [ec1b7367]
40
+ - Updated dependencies [77ff9754]
41
+ - Updated dependencies [d2d1d6b2]
42
+ - Updated dependencies [07a4887e]
43
+ - Updated dependencies [ea2ae711]
44
+ - Updated dependencies [17d0cc46]
45
+ - Updated dependencies [d2d1d6b2]
46
+ - @modern-js/core@1.7.0
47
+ - @modern-js/utils@1.4.0
48
+ - @modern-js/plugin-i18n@1.2.3
49
+ - @modern-js/new-action@1.3.5
50
+ - @modern-js/plugin-changeset@1.2.4
51
+
52
+ ## 1.4.1
53
+
54
+ ### Patch Changes
55
+
56
+ - 57419eb4: convert to new plugin
57
+ - Updated dependencies [05ce88a0]
58
+ - Updated dependencies [a8df060e]
59
+ - Updated dependencies [c2046f37]
60
+ - Updated dependencies [dc88abf9]
61
+ - Updated dependencies [0462ff77]
62
+ - Updated dependencies [61e3f623]
63
+ - Updated dependencies [6a7acb81]
64
+ - Updated dependencies [681a1ff9]
65
+ - Updated dependencies [4e2026e4]
66
+ - @modern-js/core@1.6.0
67
+ - @modern-js/utils@1.3.6
68
+ - @modern-js/plugin@1.3.2
69
+ - @modern-js/plugin-changeset@1.2.3
70
+
3
71
  ## 1.4.0
4
72
 
5
73
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  import { buildWatch } from "../commands";
2
- export const buildWatchCli = program => {
3
- program.command('build-watch [project]').usage('[options]').option('--only-self', 'build target project with nothing').option('-i, --init', 'init build beforebuild watch ').description('watch target project and target project’s dependences').action(async (targetProjectName, option) => {
4
- await buildWatch(targetProjectName, option);
2
+ export const buildWatchCli = (program, api) => {
3
+ program.command('build-watch [project]').usage('[options]').option('--only-self', 'build target project with nothing').option('-i, --init', 'init build beforebuild watch ').description('watch target project and target project’s dependencies').action(async (targetProjectName, option) => {
4
+ await buildWatch(targetProjectName, option, api);
5
5
  });
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import { build } from "../commands";
2
- export const buildCli = program => {
2
+ export const buildCli = (program, api) => {
3
3
  program.command('build [project]').usage('[options]').option('--no-self', 'build without target project').option('-t, --dept', 'build target project with project’s dependent').option('--no-deps', 'build target project without project’s dependences').option('--only-self', 'build target project with nothing').option('-a, --all', 'build target project with project’s dependences and dependent').option('--content-hash', 'build target project use content hash cache').option('--git-hash', 'build target project use git hash cache').description('build target project').action(async (targetProjectName, option) => {
4
- await build(targetProjectName, option);
4
+ await build(targetProjectName, option, api);
5
5
  });
6
6
  };
@@ -1,6 +1,6 @@
1
1
  import { clear } from "../commands";
2
- export const clearCli = program => {
2
+ export const clearCli = (program, api) => {
3
3
  program.command('clear [projects...]').usage('[options]').option('--remove-dirs [dirs...]', 'remove dirs, default is node_modules').description('clear project dirs').action(async (targetProjectNames, option) => {
4
- await clear(targetProjectNames, option);
4
+ await clear(targetProjectNames, option, api);
5
5
  });
6
6
  };
@@ -1,8 +1,8 @@
1
1
  import { deploy } from "../commands";
2
- export const deployCli = program => {
2
+ export const deployCli = (program, api) => {
3
3
  program.command('deploy [project...]').usage('[options]').option('-p, --path [path]', 'Specify the path of the product output', 'output').description('deploy project').action(async (deployProjectNames, option) => {
4
4
  // 在查找 workspace 下项目时,默认忽略 output 下面的项目
5
5
  const ignoreMatchs = ['**/output/**'];
6
- await deploy(deployProjectNames, option, ignoreMatchs);
6
+ await deploy(api, deployProjectNames, option, ignoreMatchs);
7
7
  });
8
8
  };
@@ -1,6 +1,6 @@
1
1
  import { install } from "../commands";
2
- export const installCli = program => {
2
+ export const installCli = (program, api) => {
3
3
  program.command('install [project...]').usage('[options]').description('install deps for some projects').action(async (installProjectNames, option) => {
4
- await install(installProjectNames, option);
4
+ await install(installProjectNames, option, api);
5
5
  });
6
6
  };
@@ -1,13 +1,11 @@
1
- import { useAppContext } from '@modern-js/core';
2
1
  import { getMonorepoBaseData } from "../parse-config/monorepo";
3
2
  import { runBuildWatchTask } from "../features/dev";
4
3
  import { getProjects } from "../projects/get-projects";
5
4
  import { initDAG } from "../dag";
6
- export const buildWatch = async (targetProjectName, option) => {
7
- // eslint-disable-next-line react-hooks/rules-of-hooks
5
+ export const buildWatch = async (targetProjectName, option, api) => {
8
6
  const {
9
7
  appDirectory
10
- } = useAppContext();
8
+ } = api.useAppContext();
11
9
  const {
12
10
  onlySelf = false,
13
11
  init = false
@@ -4,17 +4,15 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { useAppContext } from '@modern-js/core';
8
7
  import { getMonorepoBaseData } from "../parse-config/monorepo";
9
8
  import { runBuildTask, runAllBuildTask } from "../features/build";
10
9
  import { getProjects } from "../projects/get-projects";
11
10
  import { initDAG } from "../dag"; // import { clearProjectsMemoryFile } from './projects/clear-memory-files';
12
11
 
13
- export const build = async (targetProjectName, option) => {
14
- // eslint-disable-next-line react-hooks/rules-of-hooks
12
+ export const build = async (targetProjectName, option, api) => {
15
13
  const {
16
14
  appDirectory
17
- } = useAppContext();
15
+ } = api.useAppContext();
18
16
  const {
19
17
  self = true,
20
18
  dept = false,
@@ -1,15 +1,13 @@
1
- import { useAppContext } from '@modern-js/core';
2
1
  import { getProjects } from "../projects/get-projects";
3
2
  import { getMonorepoBaseData } from "../parse-config/monorepo";
4
3
  import { runClearTask } from "../features/clear";
5
- export const clear = async (projectNames, option) => {
4
+ export const clear = async (projectNames, option, api) => {
6
5
  const {
7
6
  removeDirs
8
- } = option; // eslint-disable-next-line react-hooks/rules-of-hooks
9
-
7
+ } = option;
10
8
  const {
11
9
  appDirectory
12
- } = useAppContext();
10
+ } = api.useAppContext();
13
11
  const projects = await getProjects({
14
12
  packagesMatchs: {
15
13
  enableAutoFinder: true
@@ -1,17 +1,15 @@
1
- import { useAppContext, mountHook } from '@modern-js/core';
2
1
  import { logger } from '@modern-js/utils';
3
2
  import { initDAG } from "../dag";
4
3
  import { getMonorepoBaseData } from "../parse-config/monorepo";
5
4
  import { getProjects } from "../projects/get-projects";
6
5
  import { deploy as runDeployTask } from "../features/deploy";
7
- export const deploy = async (deployProjectNames, option, ignoreMatchs = []) => {
6
+ export const deploy = async (api, deployProjectNames, option, ignoreMatchs = []) => {
8
7
  const {
9
8
  deployPath = 'output'
10
- } = option; // eslint-disable-next-line react-hooks/rules-of-hooks
11
-
9
+ } = option;
12
10
  const {
13
11
  appDirectory
14
- } = useAppContext();
12
+ } = api.useAppContext();
15
13
  logger.info(`start deploy ${deployProjectNames.join(',')}`);
16
14
  const projects = await getProjects({
17
15
  packagesMatchs: {
@@ -29,7 +27,8 @@ export const deploy = async (deployProjectNames, option, ignoreMatchs = []) => {
29
27
  packageManager,
30
28
  deployPath
31
29
  });
32
- mountHook().afterMonorepoDeploy({
30
+ const runners = api.useHookRunners();
31
+ runners.afterMonorepoDeploy({
33
32
  operator,
34
33
  deployProjectNames
35
34
  });
@@ -1,13 +1,11 @@
1
- import { useAppContext } from '@modern-js/core';
2
1
  import { runInstallTask } from "../features/install";
3
2
  import { getMonorepoBaseData } from "../parse-config/monorepo";
4
3
  import { getProjects } from "../projects/get-projects";
5
4
  import { initDAG } from "../dag";
6
- export const install = async (projectNames = [], option) => {
7
- // eslint-disable-next-line react-hooks/rules-of-hooks
5
+ export const install = async (projectNames = [], option, api) => {
8
6
  const {
9
7
  appDirectory
10
- } = useAppContext();
8
+ } = api.useAppContext();
11
9
  const {
12
10
  auto
13
11
  } = option;
@@ -62,7 +62,6 @@ export const recursiveGetDependency = (project, skipCircleProjects = false) => {
62
62
 
63
63
  return allDependency;
64
64
  }; // 拓扑排序
65
- // eslint-disable-next-line max-statements
66
65
 
67
66
  export const sortProjects = projects => {
68
67
  const sortedQueue = []; // 排好序的队列
@@ -1,6 +1,5 @@
1
1
  import os from 'os';
2
- import execa from 'execa';
3
- import signale from 'signale';
2
+ import { execa, signale } from '@modern-js/utils';
4
3
  import { checkProjectChangeByGit, checkProjectChangeByContent } from "../../projects/check-project-change";
5
4
  import { errorLog } from "../../log/error";
6
5
  import { MultitasksLogger } from "../../log/multi-tasks-log";
@@ -11,7 +10,7 @@ const createTask = (config, taskCmds = defaultBuildCmds, taskLogger) => {
11
10
  packageManager,
12
11
  disableContentHash = false,
13
12
  enableGitHash = false
14
- } = config; // eslint-disable-next-line max-statements
13
+ } = config;
15
14
 
16
15
  const task = async project => {
17
16
  console.info('run ', project.name); // const taskTimeLog = timeLog.initTimeLog({ scope: '' });
@@ -1,9 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import { FileSystem, JsonFile } from '@rushstack/node-core-library';
3
- import execa from 'execa';
4
- import { success } from 'signale';
5
- import yaml from 'js-yaml';
6
- import { fs, logger, chalk } from '@modern-js/utils';
3
+ import { fs, yaml, execa, logger, chalk, signale } from '@modern-js/utils';
7
4
  import { WORKSPACE_FILE } from "../../constants";
8
5
 
9
6
  const createCopyMap = (rootPath, targetProject, copyProjects, deployDir) => {
@@ -39,13 +36,11 @@ const checkAndUpdatePMWorkspaces = deployDir => {
39
36
  const pnpmWp = path.join(deployDir, WORKSPACE_FILE.PNPM);
40
37
 
41
38
  if (fs.existsSync(pnpmWp)) {
42
- // eslint-disable-next-line import/no-named-as-default-member
43
39
  const pnpmWorkspace = yaml.load(fs.readFileSync(pnpmWp, 'utf-8'));
44
40
 
45
41
  if (pnpmWorkspace.packages && Array.isArray(pnpmWorkspace.packages)) {
46
42
  pnpmWorkspace.packages.push('apps/**');
47
- } // eslint-disable-next-line import/no-named-as-default-member
48
-
43
+ }
49
44
 
50
45
  fs.writeFileSync(pnpmWp, yaml.dump(pnpmWorkspace));
51
46
  }
@@ -175,5 +170,5 @@ export const deploy = async (deployProjectNames, operator, config) => {
175
170
 
176
171
  generatorAndCopyRequiredFiles(rootPath, realDeployPath); // await installDependency(realDeployPath, packageManager);
177
172
 
178
- success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
173
+ signale.success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
179
174
  };
@@ -1,5 +1,4 @@
1
- import execa from 'execa';
2
- import { logger } from '@modern-js/utils';
1
+ import { execa, logger } from '@modern-js/utils';
3
2
  import { errorLog } from "../../log/error";
4
3
  import * as timeLog from "../../log/time";
5
4
  import { defaultBuildWatchCmds } from "./cmds";
@@ -1,10 +1,9 @@
1
- import { Import } from '@rushstack/node-core-library';
2
1
  import anymatch from 'anymatch';
2
+ import { chokidar } from '@modern-js/utils';
3
3
  import { MultitasksLogger } from "../../log/multi-tasks-log";
4
4
  import { WatchedProjectsState } from "./watch-projects-state";
5
5
  import { defaultBuildWatchCmds } from "./cmds";
6
6
  import { createDependenciesTask, createDevTask } from "./create-task";
7
- const chokidar = Import.lazy('chokidar', require);
8
7
 
9
8
  const getIgnored = config => watchFilePath => {
10
9
  // 默认忽略 node_modules 的变化和 dist 目录下文件的变化
@@ -1,6 +1,5 @@
1
1
  import * as path from 'path';
2
- import { fs } from '@modern-js/utils';
3
- import yaml from 'js-yaml';
2
+ import { fs, yaml } from '@modern-js/utils';
4
3
  import { JsonFile } from '@rushstack/node-core-library';
5
4
  import { WORKSPACE_FILE } from "../../constants";
6
5
  import { installByPackageManager } from "../../utils/install";
@@ -13,15 +12,12 @@ const replaceWorkspaces = ({
13
12
  const pnpmWsFilePath = path.join(rootPath, WORKSPACE_FILE.PNPM);
14
13
 
15
14
  if (fs.existsSync(pnpmWsFilePath)) {
16
- const pnpmWorkspace = fs.readFileSync(pnpmWsFilePath, 'utf-8'); // eslint-disable-next-line import/no-named-as-default-member
17
-
15
+ const pnpmWorkspace = fs.readFileSync(pnpmWsFilePath, 'utf-8');
18
16
  const orignalPnpmWorkspaces = yaml.load(pnpmWorkspace);
19
- fs.writeFileSync(pnpmWsFilePath, // eslint-disable-next-line import/no-named-as-default-member
20
- yaml.dump({
17
+ fs.writeFileSync(pnpmWsFilePath, yaml.dump({
21
18
  packages: projectsInWorkspacs
22
19
  }));
23
20
  return () => {
24
- // eslint-disable-next-line import/no-named-as-default-member
25
21
  yaml.dump(orignalPnpmWorkspaces);
26
22
  };
27
23
  }
@@ -1,8 +1,5 @@
1
- import { registerHook } from '@modern-js/core';
2
1
  import { createAsyncWorkflow } from '@modern-js/plugin';
3
2
  const afterMonorepoDeploy = createAsyncWorkflow();
4
- export const lifecycle = () => {
5
- registerHook({
6
- afterMonorepoDeploy
7
- });
3
+ export const hooks = {
4
+ afterMonorepoDeploy
8
5
  };
@@ -1,27 +1,27 @@
1
- import { createPlugin, usePlugins, defineConfig } from '@modern-js/core';
1
+ import ChangesetPlugin from '@modern-js/plugin-changeset';
2
2
  import { i18n } from "./locale";
3
3
  import { newCli, deployCli, clearCli } from "./cli";
4
4
  import { getLocaleLanguage } from "./utils/language";
5
- import { lifecycle } from "./hooks";
6
- export { defineConfig }; // eslint-disable-next-line react-hooks/rules-of-hooks
5
+ import { hooks } from "./hooks";
6
+ export default (() => ({
7
+ name: '@modern-js/monorepo-tools',
8
+ usePlugins: [ChangesetPlugin()],
9
+ registerHook: hooks,
10
+ setup: api => {
11
+ const locale = getLocaleLanguage();
12
+ i18n.changeLanguage({
13
+ locale
14
+ });
15
+ return {
16
+ commands({
17
+ program
18
+ }) {
19
+ clearCli(program, api);
20
+ deployCli(program, api);
21
+ newCli(program, locale);
22
+ }
7
23
 
8
- usePlugins([require.resolve('@modern-js/plugin-changeset/cli')]);
9
- export default createPlugin(() => {
10
- lifecycle();
11
- const locale = getLocaleLanguage();
12
- i18n.changeLanguage({
13
- locale
14
- });
15
- return {
16
- commands({
17
- program
18
- }) {
19
- clearCli(program);
20
- deployCli(program);
21
- newCli(program, locale);
22
- }
23
-
24
- };
25
- }, {
24
+ };
25
+ },
26
26
  post: ['@modern-js/plugin-changeset']
27
- });
27
+ }));
@@ -1,4 +1,4 @@
1
- import { Signale } from 'signale';
1
+ import { Signale } from '@modern-js/utils';
2
2
  import { formatLog } from "./utils";
3
3
 
4
4
  const createLogger = (name, config) => {
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { Signale } from 'signale';
7
+ import { Signale } from '@modern-js/utils';
8
8
  export const initTimeLog = (option = {}) => new Signale(_objectSpread({
9
9
  interactive: true,
10
10
  scope: 'time-log'
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import { FileSystem, JsonFile } from '@rushstack/node-core-library';
3
- import { fs } from '@modern-js/utils';
4
- import yaml from 'js-yaml';
3
+ import { fs, yaml } from '@modern-js/utils';
5
4
  import { getWorkspaceFile } from "../parse-config/monorepo";
6
5
  import { WORKSPACE_FILE } from "../constants";
7
6
  import { getProjetsByPackageConfig, syncGetProjetsByPackageConfig } from "./get-projects-by-packages-config";
@@ -23,8 +22,7 @@ export const getProjectsByWorkspaceFile = async (rootPath, config, ignoreConfigs
23
22
  let packagesConfig = [];
24
23
 
25
24
  if (workspaceFile === WORKSPACE_FILE.PNPM) {
26
- const yamlString = await FileSystem.readFileAsync(path.resolve('/', rootPath, workspaceFile)).then(data => data.toString()); // eslint-disable-next-line import/no-named-as-default-member
27
-
25
+ const yamlString = await FileSystem.readFileAsync(path.resolve('/', rootPath, workspaceFile)).then(data => data.toString());
28
26
  const pnpmWorkspace = yaml.load(yamlString);
29
27
  packagesConfig = pnpmWorkspace.packages || [];
30
28
  } else if (workspaceFile === WORKSPACE_FILE.YARN) {
@@ -32,6 +30,11 @@ export const getProjectsByWorkspaceFile = async (rootPath, config, ignoreConfigs
32
30
 
33
31
  const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
34
32
  packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces = pkgJson.workspaces) === null || _pkgJson$workspaces === void 0 ? void 0 : _pkgJson$workspaces.packages) || [];
33
+ } else if (workspaceFile === WORKSPACE_FILE.LERNA) {
34
+ var _lernaJson$packages;
35
+
36
+ const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
37
+ packagesConfig = (_lernaJson$packages = lernaJson.packages) !== null && _lernaJson$packages !== void 0 ? _lernaJson$packages : [];
35
38
  }
36
39
 
37
40
  const projects = await getProjetsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
@@ -55,8 +58,7 @@ export const syncGetProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs)
55
58
  let packagesConfig = [];
56
59
 
57
60
  if (workspaceFile === WORKSPACE_FILE.PNPM) {
58
- const yamlString = fs.readFileSync(path.resolve('/', rootPath, workspaceFile), 'utf-8'); // eslint-disable-next-line import/no-named-as-default-member
59
-
61
+ const yamlString = fs.readFileSync(path.resolve('/', rootPath, workspaceFile), 'utf-8');
60
62
  const pnpmWorkspace = yaml.load(yamlString);
61
63
  packagesConfig = pnpmWorkspace.packages || [];
62
64
  } else if (workspaceFile === WORKSPACE_FILE.YARN) {
@@ -64,6 +66,11 @@ export const syncGetProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs)
64
66
 
65
67
  const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
66
68
  packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces2 = pkgJson.workspaces) === null || _pkgJson$workspaces2 === void 0 ? void 0 : _pkgJson$workspaces2.packages) || [];
69
+ } else if (workspaceFile === WORKSPACE_FILE.LERNA) {
70
+ var _lernaJson$packages2;
71
+
72
+ const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
73
+ packagesConfig = (_lernaJson$packages2 = lernaJson.packages) !== null && _lernaJson$packages2 !== void 0 ? _lernaJson$packages2 : [];
67
74
  }
68
75
 
69
76
  const projects = syncGetProjetsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
@@ -1,6 +1,5 @@
1
1
  import * as path from 'path';
2
- import { fs } from '@modern-js/utils';
3
- import execa from 'execa';
2
+ import { fs, execa } from '@modern-js/utils';
4
3
  import { LOCK_FILE } from "../constants";
5
4
  export const removeLockFile = (rootPath, packageManager) => {
6
5
  if (packageManager === 'pnpm') {
@@ -7,9 +7,9 @@ exports.buildWatchCli = void 0;
7
7
 
8
8
  var _commands = require("../commands");
9
9
 
10
- const buildWatchCli = program => {
11
- program.command('build-watch [project]').usage('[options]').option('--only-self', 'build target project with nothing').option('-i, --init', 'init build beforebuild watch ').description('watch target project and target project’s dependences').action(async (targetProjectName, option) => {
12
- await (0, _commands.buildWatch)(targetProjectName, option);
10
+ const buildWatchCli = (program, api) => {
11
+ program.command('build-watch [project]').usage('[options]').option('--only-self', 'build target project with nothing').option('-i, --init', 'init build beforebuild watch ').description('watch target project and target project’s dependencies').action(async (targetProjectName, option) => {
12
+ await (0, _commands.buildWatch)(targetProjectName, option, api);
13
13
  });
14
14
  };
15
15
 
@@ -7,9 +7,9 @@ exports.buildCli = void 0;
7
7
 
8
8
  var _commands = require("../commands");
9
9
 
10
- const buildCli = program => {
10
+ const buildCli = (program, api) => {
11
11
  program.command('build [project]').usage('[options]').option('--no-self', 'build without target project').option('-t, --dept', 'build target project with project’s dependent').option('--no-deps', 'build target project without project’s dependences').option('--only-self', 'build target project with nothing').option('-a, --all', 'build target project with project’s dependences and dependent').option('--content-hash', 'build target project use content hash cache').option('--git-hash', 'build target project use git hash cache').description('build target project').action(async (targetProjectName, option) => {
12
- await (0, _commands.build)(targetProjectName, option);
12
+ await (0, _commands.build)(targetProjectName, option, api);
13
13
  });
14
14
  };
15
15
 
@@ -7,9 +7,9 @@ exports.clearCli = void 0;
7
7
 
8
8
  var _commands = require("../commands");
9
9
 
10
- const clearCli = program => {
10
+ const clearCli = (program, api) => {
11
11
  program.command('clear [projects...]').usage('[options]').option('--remove-dirs [dirs...]', 'remove dirs, default is node_modules').description('clear project dirs').action(async (targetProjectNames, option) => {
12
- await (0, _commands.clear)(targetProjectNames, option);
12
+ await (0, _commands.clear)(targetProjectNames, option, api);
13
13
  });
14
14
  };
15
15
 
@@ -7,11 +7,11 @@ exports.deployCli = void 0;
7
7
 
8
8
  var _commands = require("../commands");
9
9
 
10
- const deployCli = program => {
10
+ const deployCli = (program, api) => {
11
11
  program.command('deploy [project...]').usage('[options]').option('-p, --path [path]', 'Specify the path of the product output', 'output').description('deploy project').action(async (deployProjectNames, option) => {
12
12
  // 在查找 workspace 下项目时,默认忽略 output 下面的项目
13
13
  const ignoreMatchs = ['**/output/**'];
14
- await (0, _commands.deploy)(deployProjectNames, option, ignoreMatchs);
14
+ await (0, _commands.deploy)(api, deployProjectNames, option, ignoreMatchs);
15
15
  });
16
16
  };
17
17
 
@@ -7,9 +7,9 @@ exports.installCli = void 0;
7
7
 
8
8
  var _commands = require("../commands");
9
9
 
10
- const installCli = program => {
10
+ const installCli = (program, api) => {
11
11
  program.command('install [project...]').usage('[options]').description('install deps for some projects').action(async (installProjectNames, option) => {
12
- await (0, _commands.install)(installProjectNames, option);
12
+ await (0, _commands.install)(installProjectNames, option, api);
13
13
  });
14
14
  };
15
15
 
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildWatch = void 0;
7
7
 
8
- var _core = require("@modern-js/core");
9
-
10
8
  var _monorepo = require("../parse-config/monorepo");
11
9
 
12
10
  var _dev = require("../features/dev");
@@ -15,11 +13,10 @@ var _getProjects = require("../projects/get-projects");
15
13
 
16
14
  var _dag = require("../dag");
17
15
 
18
- const buildWatch = async (targetProjectName, option) => {
19
- // eslint-disable-next-line react-hooks/rules-of-hooks
16
+ const buildWatch = async (targetProjectName, option, api) => {
20
17
  const {
21
18
  appDirectory
22
- } = (0, _core.useAppContext)();
19
+ } = api.useAppContext();
23
20
  const {
24
21
  onlySelf = false,
25
22
  init = false
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.build = void 0;
7
7
 
8
- var _core = require("@modern-js/core");
9
-
10
8
  var _monorepo = require("../parse-config/monorepo");
11
9
 
12
10
  var _build = require("../features/build");
@@ -21,11 +19,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
21
19
 
22
20
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
21
 
24
- const build = async (targetProjectName, option) => {
25
- // eslint-disable-next-line react-hooks/rules-of-hooks
22
+ const build = async (targetProjectName, option, api) => {
26
23
  const {
27
24
  appDirectory
28
- } = (0, _core.useAppContext)();
25
+ } = api.useAppContext();
29
26
  const {
30
27
  self = true,
31
28
  dept = false,
@@ -5,22 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.clear = void 0;
7
7
 
8
- var _core = require("@modern-js/core");
9
-
10
8
  var _getProjects = require("../projects/get-projects");
11
9
 
12
10
  var _monorepo = require("../parse-config/monorepo");
13
11
 
14
12
  var _clear = require("../features/clear");
15
13
 
16
- const clear = async (projectNames, option) => {
14
+ const clear = async (projectNames, option, api) => {
17
15
  const {
18
16
  removeDirs
19
- } = option; // eslint-disable-next-line react-hooks/rules-of-hooks
20
-
17
+ } = option;
21
18
  const {
22
19
  appDirectory
23
- } = (0, _core.useAppContext)();
20
+ } = api.useAppContext();
24
21
  const projects = await (0, _getProjects.getProjects)({
25
22
  packagesMatchs: {
26
23
  enableAutoFinder: true