@modern-js/monorepo-tools 2.0.0-beta.0 → 2.0.0-beta.1

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 (78) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/js/modern/cli/new.js +0 -3
  3. package/dist/js/modern/commands/build.js +4 -9
  4. package/dist/js/modern/dag/create.js +8 -15
  5. package/dist/js/modern/dag/edge-manager.js +0 -10
  6. package/dist/js/modern/dag/operator.js +14 -57
  7. package/dist/js/modern/dag/task.js +0 -18
  8. package/dist/js/modern/dag/utils.js +13 -31
  9. package/dist/js/modern/features/build/index.js +8 -19
  10. package/dist/js/modern/features/clear/index.js +0 -1
  11. package/dist/js/modern/features/deploy/index.js +7 -35
  12. package/dist/js/modern/features/dev/cmds.js +1 -0
  13. package/dist/js/modern/features/dev/create-task.js +2 -13
  14. package/dist/js/modern/features/dev/index.js +4 -11
  15. package/dist/js/modern/features/dev/watch-projects-state.js +0 -19
  16. package/dist/js/modern/features/install/index.js +0 -12
  17. package/dist/js/modern/index.js +1 -2
  18. package/dist/js/modern/log/multi-tasks-log.js +8 -31
  19. package/dist/js/modern/log/time.js +0 -3
  20. package/dist/js/modern/log/utils.js +0 -2
  21. package/dist/js/modern/package/index.js +0 -8
  22. package/dist/js/modern/parse-config/index.js +3 -6
  23. package/dist/js/modern/parse-config/monorepo.js +0 -23
  24. package/dist/js/modern/projects/check-project-change.js +4 -16
  25. package/dist/js/modern/projects/get-projects-by-packages-config.js +12 -29
  26. package/dist/js/modern/projects/get-projects-by-workspace-file.js +0 -16
  27. package/dist/js/modern/projects/get-projects.js +4 -29
  28. package/dist/js/modern/utils/install.js +0 -2
  29. package/dist/js/node/cli/build-watch.js +0 -3
  30. package/dist/js/node/cli/build.js +0 -3
  31. package/dist/js/node/cli/clear.js +0 -3
  32. package/dist/js/node/cli/deploy.js +0 -3
  33. package/dist/js/node/cli/index.js +0 -12
  34. package/dist/js/node/cli/install.js +0 -3
  35. package/dist/js/node/cli/new.js +0 -7
  36. package/dist/js/node/commands/build-watch.js +0 -6
  37. package/dist/js/node/commands/build.js +2 -14
  38. package/dist/js/node/commands/clear.js +0 -5
  39. package/dist/js/node/commands/deploy.js +0 -9
  40. package/dist/js/node/commands/index.js +0 -10
  41. package/dist/js/node/commands/install.js +0 -6
  42. package/dist/js/node/dag/create.js +8 -17
  43. package/dist/js/node/dag/edge-manager.js +0 -12
  44. package/dist/js/node/dag/index.js +0 -4
  45. package/dist/js/node/dag/operator.js +14 -65
  46. package/dist/js/node/dag/task.js +0 -23
  47. package/dist/js/node/dag/utils.js +12 -39
  48. package/dist/js/node/features/build/index.js +8 -29
  49. package/dist/js/node/features/clear/index.js +0 -15
  50. package/dist/js/node/features/deploy/index.js +7 -53
  51. package/dist/js/node/features/dev/cmds.js +1 -0
  52. package/dist/js/node/features/dev/create-task.js +2 -22
  53. package/dist/js/node/features/dev/index.js +4 -19
  54. package/dist/js/node/features/dev/watch-projects-state.js +0 -25
  55. package/dist/js/node/features/install/index.js +0 -25
  56. package/dist/js/node/hooks/index.js +0 -2
  57. package/dist/js/node/index.js +2 -16
  58. package/dist/js/node/locale/index.js +0 -4
  59. package/dist/js/node/log/error.js +0 -2
  60. package/dist/js/node/log/multi-tasks-log.js +8 -34
  61. package/dist/js/node/log/time.js +0 -10
  62. package/dist/js/node/log/utils.js +0 -4
  63. package/dist/js/node/package/index.js +0 -10
  64. package/dist/js/node/parse-config/index.js +3 -14
  65. package/dist/js/node/parse-config/monorepo.js +0 -34
  66. package/dist/js/node/projects/check-project-change.js +4 -33
  67. package/dist/js/node/projects/clear-memory-files.js +0 -8
  68. package/dist/js/node/projects/get-projects-by-packages-config.js +12 -41
  69. package/dist/js/node/projects/get-projects-by-workspace-file.js +0 -36
  70. package/dist/js/node/projects/get-projects.js +4 -37
  71. package/dist/js/node/utils/install.js +0 -11
  72. package/dist/js/node/utils/language.js +0 -2
  73. package/dist/types/dag/operator.d.ts +0 -3
  74. package/dist/types/dag/utils.d.ts +0 -1
  75. package/dist/types/features/dev/index.d.ts +0 -1
  76. package/dist/types/index.d.ts +0 -2
  77. package/dist/types/projects/get-projects.d.ts +0 -1
  78. package/package.json +13 -13
@@ -1,28 +1,20 @@
1
1
  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; }
2
-
3
2
  export class Package {
4
3
  constructor(packageJson, packageConfigPath, rootPath) {
5
4
  _defineProperty(this, "json", void 0);
6
-
7
5
  _defineProperty(this, "configPath", void 0);
8
-
9
6
  _defineProperty(this, "rootPath", void 0);
10
-
11
7
  this.configPath = packageConfigPath;
12
8
  this.rootPath = rootPath;
13
9
  this.json = packageJson;
14
10
  }
15
-
16
11
  get name() {
17
12
  return this.json.name;
18
13
  }
19
-
20
14
  get path() {
21
15
  return this.configPath;
22
16
  }
23
-
24
17
  get(key) {
25
18
  return this.json[key];
26
19
  }
27
-
28
20
  }
@@ -1,13 +1,11 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  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
-
7
4
  import * as path from 'path';
8
5
  import { JsonFile } from '@rushstack/node-core-library';
9
6
  import { getMonorepoBaseData } from "./monorepo";
10
- const defaultConfig = {// packagesMatchs: {
7
+ const defaultConfig = {
8
+ // packagesMatchs: {
11
9
  // workspaceFile: 'pnpm-lock.yaml',
12
10
  // },
13
11
  };
@@ -15,11 +13,10 @@ export const getFinalConfig = async (currentPath = process.cwd()) => {
15
13
  // TODO:
16
14
  // 1. 初始化获取信息
17
15
  // 2. 配置文件是否存在校验
16
+
18
17
  const monorepo = getMonorepoBaseData(currentPath);
19
18
  const userConfig = await JsonFile.loadAsync(path.resolve(monorepo.rootPath, 'mono-config.json'));
20
-
21
19
  const config = _objectSpread(_objectSpread({}, defaultConfig), userConfig);
22
-
23
20
  return {
24
21
  monorepo,
25
22
  config
@@ -1,67 +1,51 @@
1
1
  import * as path from 'path';
2
2
  import { FileSystem, JsonFile } from '@rushstack/node-core-library';
3
3
  import { WORKSPACE_FILE } from "../constants";
4
-
5
4
  const useLerna = monorepoRootPath => {
6
5
  if (FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.LERNA))) {
7
6
  return true;
8
7
  }
9
-
10
8
  return false;
11
9
  };
12
-
13
10
  const useYarnWorkspaces = monorepoRootPath => {
14
11
  if (!FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.YARN))) {
15
12
  return false;
16
13
  }
17
-
18
14
  const json = JsonFile.load(path.join(monorepoRootPath, WORKSPACE_FILE.YARN));
19
-
20
15
  if ('workspaces' in json && json.workspaces.packages) {
21
16
  return true;
22
17
  }
23
-
24
18
  return false;
25
19
  };
26
-
27
20
  const usePnpmWorkspaces = monorepoRootPath => {
28
21
  if (FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.PNPM))) {
29
22
  return true;
30
23
  }
31
-
32
24
  return false;
33
25
  };
34
-
35
26
  const isMonorepo = monorepoRootPath => {
36
27
  if (usePnpmWorkspaces(monorepoRootPath) || useLerna(monorepoRootPath) || useYarnWorkspaces(monorepoRootPath)) {
37
28
  return true;
38
29
  }
39
-
40
30
  return false;
41
31
  };
42
-
43
32
  export const findMonorepoRoot = starFindPath => {
44
33
  let inMonorepo = false;
45
34
  let findPath = starFindPath;
46
-
47
35
  while (findPath !== '/') {
48
36
  if (isMonorepo(findPath)) {
49
37
  inMonorepo = true;
50
38
  break;
51
39
  }
52
-
53
40
  findPath = path.dirname(findPath);
54
41
  }
55
-
56
42
  return inMonorepo ? findPath : undefined;
57
43
  };
58
44
  export const getWorkspaceFile = startFindPath => {
59
45
  const rootPath = findMonorepoRoot(startFindPath);
60
-
61
46
  if (!rootPath) {
62
47
  throw new Error('[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`');
63
48
  }
64
-
65
49
  if (usePnpmWorkspaces(rootPath)) {
66
50
  return WORKSPACE_FILE.PNPM;
67
51
  } else if (useLerna(rootPath)) {
@@ -77,33 +61,26 @@ export const packageManagerFlag = {
77
61
  yarn: ['yarn.lock', useYarnWorkspaces],
78
62
  npm: [() => true]
79
63
  };
80
-
81
64
  const usePnpmPackageManager = monorepoRootPath => packageManagerFlag.pnpm.some(flag => FileSystem.exists(path.join(monorepoRootPath, flag)));
82
-
83
65
  const useYarnPackageManager = monorepoRootPath => packageManagerFlag.yarn.some(flag => {
84
66
  if (typeof flag === 'function') {
85
67
  return flag(monorepoRootPath);
86
68
  }
87
-
88
69
  return FileSystem.exists(path.join(monorepoRootPath, flag));
89
70
  });
90
-
91
71
  export const getPackageManager = monorepoRootPath => {
92
72
  if (usePnpmPackageManager(monorepoRootPath)) {
93
73
  return 'pnpm';
94
74
  } else if (useYarnPackageManager(monorepoRootPath)) {
95
75
  return 'yarn';
96
76
  }
97
-
98
77
  return 'npm';
99
78
  };
100
79
  export const getMonorepoBaseData = (root = process.cwd()) => {
101
80
  const rootPath = findMonorepoRoot(root);
102
-
103
81
  if (!rootPath) {
104
82
  throw new Error('not find any monorepo, you can add lerna、pnpm or yarn workspace file');
105
83
  }
106
-
107
84
  return {
108
85
  rootPath,
109
86
  packageManager: getPackageManager(rootPath)
@@ -6,7 +6,6 @@ import md5 from 'md5';
6
6
  export const PROJECT_CONTENT_FILE_NAME = 'project-content.json';
7
7
  export const MONOREPO_GIT_FILE_NAME = 'monorepo-git.json';
8
8
  export const PROJECT_MEMORY_PATH = '.project-memory';
9
-
10
9
  const getProjectGitHash = async project => {
11
10
  const projectDir = project.extra.path;
12
11
  const globOption = {
@@ -19,38 +18,33 @@ const getProjectGitHash = async project => {
19
18
  const globPattern = `${projectDir}/**`;
20
19
  const files = await globby(path.posix.join(globPattern), globOption);
21
20
  const hashMap = getGitHashForFiles(files, projectDir);
22
- const hashObject = {}; // sort is important
21
+ const hashObject = {};
23
22
 
23
+ // sort is important
24
24
  Sort.sortMapKeys(hashMap);
25
25
  hashMap.forEach((value, key) => {
26
26
  hashObject[key] = value;
27
27
  });
28
28
  return md5(JsonFile.stringify(hashObject));
29
29
  };
30
-
31
30
  export const checkProjectChangeByGit = async (project, rootPath) => {
32
31
  const monorepoGitMemory = path.join(rootPath, MONOREPO_GIT_FILE_NAME);
33
32
  const currentProjectHash = await getProjectGitHash(project);
34
-
35
33
  if (!FileSystem.exists(monorepoGitMemory)) {
36
34
  FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify({}), {
37
35
  ensureFolderExists: true
38
36
  });
39
37
  }
40
-
41
38
  const monorepoProjectHashJson = JsonFile.load(monorepoGitMemory);
42
39
  const changed = monorepoProjectHashJson[project.name] !== currentProjectHash;
43
-
44
40
  if (changed) {
45
41
  monorepoProjectHashJson[project.name] = currentProjectHash;
46
42
  FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify(monorepoProjectHashJson), {
47
43
  ensureFolderExists: true
48
44
  });
49
45
  }
50
-
51
46
  return changed;
52
47
  };
53
-
54
48
  const getProjectContentHashObjectForFiles = async project => {
55
49
  const projectDir = project.extra.path;
56
50
  const globOption = {
@@ -62,37 +56,31 @@ const getProjectContentHashObjectForFiles = async project => {
62
56
  };
63
57
  const globPattern = `${projectDir}/**`;
64
58
  const files = await globby(path.posix.join(globPattern), globOption);
65
- const hashObject = {}; // sort is important
66
-
59
+ const hashObject = {};
60
+ // sort is important
67
61
  for (const file of files.sort()) {
68
62
  hashObject[file] = md5(FileSystem.readFile(file));
69
63
  }
70
-
71
64
  return hashObject;
72
65
  };
73
-
74
66
  export const checkProjectChangeByContent = async project => {
75
67
  const projectDir = project.extra.path;
76
68
  const projectMemoryFolder = path.resolve(projectDir, '.project-memory');
77
69
  const projectJsonFile = path.join(projectMemoryFolder, PROJECT_CONTENT_FILE_NAME);
78
70
  const currentHashObject = await getProjectContentHashObjectForFiles(project);
79
71
  const currentHashString = JsonFile.stringify(currentHashObject);
80
-
81
72
  if (!FileSystem.exists(projectJsonFile)) {
82
73
  FileSystem.writeFile(projectJsonFile, currentHashString, {
83
74
  ensureFolderExists: true
84
75
  });
85
76
  return true;
86
77
  }
87
-
88
78
  const localHashObject = JsonFile.load(projectJsonFile);
89
79
  const changed = JsonFile.stringify(localHashObject) !== currentHashString;
90
-
91
80
  if (changed) {
92
81
  FileSystem.writeFile(projectJsonFile, currentHashString, {
93
82
  ensureFolderExists: true
94
83
  });
95
84
  }
96
-
97
85
  return changed;
98
86
  };
@@ -1,18 +1,13 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  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
-
7
4
  import * as path from 'path';
8
5
  import { PackageJsonLookup } from '@rushstack/node-core-library';
9
6
  import { globby } from '@modern-js/utils';
10
7
  import pMap from 'p-map';
11
8
  import { errorLog } from "../log/error";
12
9
  import { Package } from "../package";
13
-
14
10
  const normalize = results => results.map(fp => path.normalize(fp));
15
-
16
11
  const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
17
12
  const globOpts = {
18
13
  cwd: rootPath,
@@ -20,45 +15,41 @@ const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
20
15
  expandDirectories: false,
21
16
  followSymbolicLinks: false
22
17
  };
23
-
24
18
  if (packageConfigs.some(cfg => cfg.includes('**'))) {
25
19
  if (packageConfigs.some(cfg => cfg.includes('node_modules'))) {
26
20
  errorLog('An explicit node_modules package path does not allow globstars (**)');
27
21
  }
28
-
29
- globOpts.ignore = [// allow globs like "packages/**",
22
+ globOpts.ignore = [
23
+ // allow globs like "packages/**",
30
24
  // but avoid picking up node_modules/**/package.json and dist/**/package.json
31
25
  '**/dist/**', '**/node_modules/**', ...(ignore || [])];
32
26
  }
33
-
34
27
  return globOpts;
35
28
  };
36
-
37
29
  const makeFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
38
30
  const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
39
31
  return async (fileName, fileMapper, customGlobOpts = {}) => {
40
32
  const options = _objectSpread(_objectSpread({}, customGlobOpts), globOpts);
41
-
42
33
  const promise = pMap(Array.from(packageConfigs).sort(), async globPath => {
43
- let result = await globby(path.posix.join(globPath, fileName), options); // fast-glob does not respect pattern order, so we re-sort by absolute path
44
-
45
- result = result.sort(); // POSIX results always need to be normalized
34
+ let result = await globby(path.posix.join(globPath, fileName), options);
46
35
 
36
+ // fast-glob does not respect pattern order, so we re-sort by absolute path
37
+ result = result.sort();
38
+ // POSIX results always need to be normalized
47
39
  result = normalize(result);
48
40
  return fileMapper(result);
49
41
  }, {
50
42
  concurrency: packageConfigs.length || Infinity
51
- }); // always flatten the results
43
+ });
52
44
 
45
+ // always flatten the results
53
46
  const results = await promise;
54
47
  return results.reduce((acc, result) => acc.concat(result), []);
55
48
  };
56
49
  };
57
-
58
50
  export const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignoreConfigs) => {
59
51
  const finder = makeFileFinder(rootPath, packagesConfig, ignoreConfigs);
60
52
  const fileName = 'package.json';
61
-
62
53
  const mapper = packageConfigPath => {
63
54
  const packageJsonLookup = new PackageJsonLookup({
64
55
  loadExtraFields: true
@@ -66,37 +57,30 @@ export const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignor
66
57
  const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
67
58
  return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
68
59
  };
69
-
70
60
  const projects = await finder(fileName, filePaths => pMap(filePaths, mapper, {
71
61
  concurrency: filePaths.length || Infinity
72
62
  }), {});
73
63
  return projects;
74
64
  };
75
-
76
65
  const makeSyncFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
77
66
  const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
78
67
  return (fileName, fileMapper, customGlobOpts = {}) => {
79
68
  const results = [];
80
-
81
69
  const options = _objectSpread(_objectSpread({}, customGlobOpts), globOpts);
82
-
83
70
  for (const globPath of Array.from(packageConfigs).sort()) {
84
- let result = globby.sync(path.posix.join(globPath, fileName), options); // fast-glob does not respect pattern order, so we re-sort by absolute path
85
-
86
- result = result.sort(); // POSIX results always need to be normalized
87
-
71
+ let result = globby.sync(path.posix.join(globPath, fileName), options);
72
+ // fast-glob does not respect pattern order, so we re-sort by absolute path
73
+ result = result.sort();
74
+ // POSIX results always need to be normalized
88
75
  result = normalize(result);
89
76
  results.push(fileMapper(result));
90
77
  }
91
-
92
78
  return results.reduce((acc, result) => acc.concat(result), []);
93
79
  };
94
80
  };
95
-
96
81
  export const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
97
82
  const finder = makeSyncFileFinder(rootPath, packagesConfig, ignoreConfigs);
98
83
  const fileName = 'package.json';
99
-
100
84
  const mapper = packageConfigPath => {
101
85
  const packageJsonLookup = new PackageJsonLookup({
102
86
  loadExtraFields: true
@@ -104,7 +88,6 @@ export const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreC
104
88
  const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
105
89
  return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
106
90
  };
107
-
108
91
  const projects = finder(fileName, filePaths => filePaths.map(filePath => mapper(filePath)), {});
109
92
  return projects;
110
93
  };
@@ -6,73 +6,57 @@ import { WORKSPACE_FILE } from "../constants";
6
6
  import { getProjectsByPackageConfig, syncGetProjectsByPackageConfig } from "./get-projects-by-packages-config";
7
7
  export const getProjectsByWorkspaceFile = async (rootPath, config, ignoreConfigs) => {
8
8
  var _config$workspaceFile;
9
-
10
9
  let {
11
10
  workspaceFile
12
11
  } = config;
13
-
14
12
  if (!config.enableAutoFinder && (!('workspaceFile' in config) || ((_config$workspaceFile = config.workspaceFile) === null || _config$workspaceFile === void 0 ? void 0 : _config$workspaceFile.length) === 0)) {
15
13
  throw new Error('Missing workspaceFile Key or workspaceFile is empty string');
16
14
  }
17
-
18
15
  if (config.enableAutoFinder) {
19
16
  workspaceFile = getWorkspaceFile(rootPath);
20
17
  }
21
-
22
18
  let packagesConfig = [];
23
-
24
19
  if (workspaceFile === WORKSPACE_FILE.PNPM) {
25
20
  const yamlString = await FileSystem.readFileAsync(path.resolve('/', rootPath, workspaceFile)).then(data => data.toString());
26
21
  const pnpmWorkspace = yaml.load(yamlString);
27
22
  packagesConfig = pnpmWorkspace.packages || [];
28
23
  } else if (workspaceFile === WORKSPACE_FILE.YARN) {
29
24
  var _pkgJson$workspaces;
30
-
31
25
  const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
32
26
  packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces = pkgJson.workspaces) === null || _pkgJson$workspaces === void 0 ? void 0 : _pkgJson$workspaces.packages) || [];
33
27
  } else if (workspaceFile === WORKSPACE_FILE.LERNA) {
34
28
  var _lernaJson$packages;
35
-
36
29
  const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
37
30
  packagesConfig = (_lernaJson$packages = lernaJson.packages) !== null && _lernaJson$packages !== void 0 ? _lernaJson$packages : [];
38
31
  }
39
-
40
32
  const projects = await getProjectsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
41
33
  return projects;
42
34
  };
43
35
  export const syncGetProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs) => {
44
36
  var _config$workspaceFile2;
45
-
46
37
  let {
47
38
  workspaceFile
48
39
  } = config;
49
-
50
40
  if (!config.enableAutoFinder && (!('workspaceFile' in config) || ((_config$workspaceFile2 = config.workspaceFile) === null || _config$workspaceFile2 === void 0 ? void 0 : _config$workspaceFile2.length) === 0)) {
51
41
  throw new Error('Missing workspaceFile Key or workspaceFile is empty string');
52
42
  }
53
-
54
43
  if (config.enableAutoFinder) {
55
44
  workspaceFile = getWorkspaceFile(rootPath);
56
45
  }
57
-
58
46
  let packagesConfig = [];
59
-
60
47
  if (workspaceFile === WORKSPACE_FILE.PNPM) {
61
48
  const yamlString = fs.readFileSync(path.resolve('/', rootPath, workspaceFile), 'utf-8');
62
49
  const pnpmWorkspace = yaml.load(yamlString);
63
50
  packagesConfig = pnpmWorkspace.packages || [];
64
51
  } else if (workspaceFile === WORKSPACE_FILE.YARN) {
65
52
  var _pkgJson$workspaces2;
66
-
67
53
  const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
68
54
  packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces2 = pkgJson.workspaces) === null || _pkgJson$workspaces2 === void 0 ? void 0 : _pkgJson$workspaces2.packages) || [];
69
55
  } else if (workspaceFile === WORKSPACE_FILE.LERNA) {
70
56
  var _lernaJson$packages2;
71
-
72
57
  const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
73
58
  packagesConfig = (_lernaJson$packages2 = lernaJson.packages) !== null && _lernaJson$packages2 !== void 0 ? _lernaJson$packages2 : [];
74
59
  }
75
-
76
60
  const projects = syncGetProjectsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
77
61
  return projects;
78
62
  };
@@ -1,23 +1,17 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  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
-
7
4
  import { errorLog } from "../log/error";
8
5
  import { getMonorepoBaseData } from "../parse-config/monorepo";
9
6
  import { getProjectsByPackageConfig, syncGetProjectsByPackageConfig } from "./get-projects-by-packages-config";
10
7
  import { getProjectsByWorkspaceFile, syncGetProjectsByWorkspaceFile } from "./get-projects-by-workspace-file";
11
8
  var FindProjectsMode;
12
-
13
9
  (function (FindProjectsMode) {
14
10
  FindProjectsMode[FindProjectsMode["Rough"] = 0] = "Rough";
15
11
  FindProjectsMode[FindProjectsMode["Precise"] = 1] = "Precise";
16
12
  })(FindProjectsMode || (FindProjectsMode = {}));
17
-
18
13
  const getProjectsByProjectsConfig = (rootPath, configs = []) => {
19
14
  const subProjects = [];
20
-
21
15
  for (const config of configs) {
22
16
  subProjects.push({
23
17
  name: config.name,
@@ -31,13 +25,10 @@ const getProjectsByProjectsConfig = (rootPath, configs = []) => {
31
25
  circlePath: []
32
26
  });
33
27
  }
34
-
35
28
  return subProjects;
36
29
  };
37
-
38
30
  const getProjectsByPackagesMatch = async (rootPath, match, ignore) => {
39
31
  let projects = [];
40
-
41
32
  if (Array.isArray(match)) {
42
33
  // like lerna`s packages config
43
34
  projects = await getProjectsByPackageConfig(rootPath, match, ignore);
@@ -45,9 +36,7 @@ const getProjectsByPackagesMatch = async (rootPath, match, ignore) => {
45
36
  // use workspace file
46
37
  projects = await getProjectsByWorkspaceFile(rootPath, match, ignore);
47
38
  }
48
-
49
39
  const subProjects = [];
50
-
51
40
  for (const project of projects) {
52
41
  subProjects.push({
53
42
  name: project.name,
@@ -61,13 +50,11 @@ const getProjectsByPackagesMatch = async (rootPath, match, ignore) => {
61
50
  circlePath: []
62
51
  });
63
52
  }
64
-
65
53
  return subProjects;
66
54
  };
67
-
68
55
  const syncGetProjectsByPackagesMatch = (rootPath, match, ignore) => {
69
- let projects = []; // TODO: code start
70
-
56
+ let projects = [];
57
+ // TODO: code start
71
58
  if (Array.isArray(match)) {
72
59
  // like lerna`s packages config
73
60
  projects = syncGetProjectsByPackageConfig(rootPath, match, ignore);
@@ -75,9 +62,7 @@ const syncGetProjectsByPackagesMatch = (rootPath, match, ignore) => {
75
62
  // use workspace file
76
63
  projects = syncGetProjectsByWorkspaceFile(rootPath, match, ignore);
77
64
  }
78
-
79
65
  const subProjects = [];
80
-
81
66
  for (const project of projects) {
82
67
  subProjects.push({
83
68
  name: project.name,
@@ -91,44 +76,36 @@ const syncGetProjectsByPackagesMatch = (rootPath, match, ignore) => {
91
76
  circlePath: []
92
77
  });
93
78
  }
94
-
95
79
  return subProjects;
96
80
  };
97
-
98
- const checkFindProjectsMode = (config // eslint-disable-next-line consistent-return
81
+ const checkFindProjectsMode = (config
82
+ // eslint-disable-next-line consistent-return
99
83
  ) => {
100
84
  if (config.packagesMatchs && Array.isArray(config.packagesMatchs)) {
101
85
  return FindProjectsMode.Rough;
102
86
  }
103
-
104
87
  if (config.packagesMatchs && typeof config.packagesMatchs === 'object' && (config.packagesMatchs.workspaceFile || config.packagesMatchs.enableAutoFinder)) {
105
88
  return FindProjectsMode.Rough;
106
89
  }
107
-
108
90
  if (config.projectsConfig && Array.isArray(config.projectsConfig)) {
109
91
  return FindProjectsMode.Precise;
110
92
  }
111
-
112
93
  if (config.projectsConfig && config.packagesMatchs) {
113
94
  errorLog('There can not be both `packagesMatchs` and `projectsConfig`');
114
95
  }
115
-
116
96
  errorLog('No `packagesMatchs` and `projectsConfig` configurations found');
117
97
  };
118
-
119
98
  export const getProjects = async (config, currentDir = process.cwd()) => {
120
99
  const {
121
100
  rootPath
122
101
  } = getMonorepoBaseData(currentDir);
123
102
  const mode = checkFindProjectsMode(config);
124
103
  let projects = [];
125
-
126
104
  if (mode === FindProjectsMode.Rough) {
127
105
  projects = await getProjectsByPackagesMatch(rootPath, config.packagesMatchs, config.packagesIgnoreMatchs || []);
128
106
  } else if (mode === FindProjectsMode.Precise) {
129
107
  projects = getProjectsByProjectsConfig(rootPath, config.projectsConfig);
130
108
  }
131
-
132
109
  return projects;
133
110
  };
134
111
  export const syncGetProjects = (config, currentDir = process.cwd()) => {
@@ -137,12 +114,10 @@ export const syncGetProjects = (config, currentDir = process.cwd()) => {
137
114
  } = getMonorepoBaseData(currentDir);
138
115
  const mode = checkFindProjectsMode(config);
139
116
  let projects = [];
140
-
141
117
  if (mode === FindProjectsMode.Rough) {
142
118
  projects = syncGetProjectsByPackagesMatch(rootPath, config.packagesMatchs, config.packagesIgnoreMatchs || []);
143
119
  } else if (mode === FindProjectsMode.Precise) {
144
120
  projects = getProjectsByProjectsConfig(rootPath, config.projectsConfig);
145
121
  }
146
-
147
122
  return projects;
148
123
  };
@@ -17,13 +17,11 @@ export const installByPackageManager = async (packageManager, {
17
17
  if (removeLock) {
18
18
  removeLockFile(rootPath, packageManager);
19
19
  }
20
-
21
20
  if (packageManager === 'pnpm') {
22
21
  await execa('pnpm', ['install'], {
23
22
  stdio: 'inherit'
24
23
  });
25
24
  }
26
-
27
25
  if (packageManager === 'yarn') {
28
26
  await execa('yarn', ['install'], {
29
27
  stdio: 'inherit'
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.buildWatchCli = void 0;
7
-
8
7
  var _commands = require("../commands");
9
-
10
8
  const buildWatchCli = (program, api) => {
11
9
  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
10
  await (0, _commands.buildWatch)(targetProjectName, option, api);
13
11
  });
14
12
  };
15
-
16
13
  exports.buildWatchCli = buildWatchCli;
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.buildCli = void 0;
7
-
8
7
  var _commands = require("../commands");
9
-
10
8
  const buildCli = (program, api) => {
11
9
  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 dependencies').option('--only-self', 'build target project with nothing').option('-a, --all', 'build target project with project’s dependencies 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
10
  await (0, _commands.build)(targetProjectName, option, api);
13
11
  });
14
12
  };
15
-
16
13
  exports.buildCli = buildCli;
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.clearCli = void 0;
7
-
8
7
  var _commands = require("../commands");
9
-
10
8
  const clearCli = (program, api) => {
11
9
  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
10
  await (0, _commands.clear)(targetProjectNames, option, api);
13
11
  });
14
12
  };
15
-
16
13
  exports.clearCli = clearCli;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.deployCli = void 0;
7
-
8
7
  var _commands = require("../commands");
9
-
10
8
  const deployCli = (program, api) => {
11
9
  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
10
  // 在查找 workspace 下项目时,默认忽略 output 下面的项目
@@ -14,5 +12,4 @@ const deployCli = (program, api) => {
14
12
  await (0, _commands.deploy)(api, deployProjectNames, option, ignoreMatchs);
15
13
  });
16
14
  };
17
-
18
15
  exports.deployCli = deployCli;