@modern-js/monorepo-tools 2.14.0 → 2.16.0

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 (96) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/cjs/cli/build.js +10 -31
  3. package/dist/cjs/cli/buildWatch.js +11 -31
  4. package/dist/cjs/cli/clear.js +11 -31
  5. package/dist/cjs/cli/deploy.js +14 -36
  6. package/dist/cjs/cli/index.js +23 -22
  7. package/dist/cjs/cli/install.js +11 -31
  8. package/dist/cjs/cli/new.js +17 -37
  9. package/dist/cjs/commands/build.js +21 -46
  10. package/dist/cjs/commands/buildWatch.js +19 -36
  11. package/dist/cjs/commands/clear.js +17 -34
  12. package/dist/cjs/commands/deploy.js +25 -41
  13. package/dist/cjs/commands/index.js +22 -21
  14. package/dist/cjs/commands/install.js +19 -36
  15. package/dist/cjs/constants.js +13 -26
  16. package/dist/cjs/dag/create.js +16 -28
  17. package/dist/cjs/dag/edgeManager.js +24 -28
  18. package/dist/cjs/dag/index.js +11 -29
  19. package/dist/cjs/dag/operator.js +106 -123
  20. package/dist/cjs/dag/task.js +52 -63
  21. package/dist/cjs/dag/utils.js +52 -49
  22. package/dist/cjs/features/build/index.js +52 -68
  23. package/dist/cjs/features/clear/index.js +66 -47
  24. package/dist/cjs/features/deploy/index.js +126 -96
  25. package/dist/cjs/features/dev/cmds.js +10 -25
  26. package/dist/cjs/features/dev/createTask.js +93 -56
  27. package/dist/cjs/features/dev/index.js +43 -71
  28. package/dist/cjs/features/dev/watchProjectsState.js +89 -64
  29. package/dist/cjs/features/install/index.js +74 -63
  30. package/dist/cjs/hooks/index.js +9 -27
  31. package/dist/cjs/index.js +36 -53
  32. package/dist/cjs/locale/en.js +7 -25
  33. package/dist/cjs/locale/index.js +18 -28
  34. package/dist/cjs/locale/zh.js +7 -25
  35. package/dist/cjs/log/error.js +7 -25
  36. package/dist/cjs/log/multiTasksLog.js +42 -43
  37. package/dist/cjs/log/time.js +19 -29
  38. package/dist/cjs/log/utils.js +7 -25
  39. package/dist/cjs/package/index.js +28 -30
  40. package/dist/cjs/parse-config/index.js +61 -49
  41. package/dist/cjs/parse-config/monorepo.js +81 -67
  42. package/dist/cjs/projects/checkProjectChange.js +95 -73
  43. package/dist/cjs/projects/clearMemoryFiles.js +52 -44
  44. package/dist/cjs/projects/getProjects.js +38 -65
  45. package/dist/cjs/projects/getProjectsByPackagesConfig.js +93 -71
  46. package/dist/cjs/projects/getProjectsByWorkspaceFile.js +89 -85
  47. package/dist/cjs/type.js +4 -15
  48. package/dist/cjs/utils/install.js +69 -44
  49. package/dist/cjs/utils/types.js +4 -15
  50. package/dist/esm/cli/build.js +2 -8
  51. package/dist/esm/cli/buildWatch.js +4 -9
  52. package/dist/esm/cli/clear.js +4 -9
  53. package/dist/esm/cli/deploy.js +7 -14
  54. package/dist/esm/cli/install.js +4 -9
  55. package/dist/esm/cli/new.js +9 -14
  56. package/dist/esm/commands/build.js +7 -17
  57. package/dist/esm/commands/buildWatch.js +6 -8
  58. package/dist/esm/commands/clear.js +6 -8
  59. package/dist/esm/commands/deploy.js +10 -11
  60. package/dist/esm/commands/install.js +6 -8
  61. package/dist/esm/constants.js +2 -6
  62. package/dist/esm/dag/create.js +10 -7
  63. package/dist/esm/dag/edgeManager.js +17 -6
  64. package/dist/esm/dag/index.js +1 -4
  65. package/dist/esm/dag/operator.js +77 -74
  66. package/dist/esm/dag/task.js +39 -30
  67. package/dist/esm/dag/utils.js +39 -27
  68. package/dist/esm/features/build/index.js +22 -27
  69. package/dist/esm/features/clear/index.js +4 -6
  70. package/dist/esm/features/deploy/index.js +55 -50
  71. package/dist/esm/features/dev/cmds.js +4 -4
  72. package/dist/esm/features/dev/createTask.js +31 -15
  73. package/dist/esm/features/dev/index.js +19 -27
  74. package/dist/esm/features/dev/watchProjectsState.js +41 -31
  75. package/dist/esm/features/install/index.js +11 -15
  76. package/dist/esm/hooks/index.js +1 -4
  77. package/dist/esm/index.js +12 -11
  78. package/dist/esm/locale/en.js +1 -4
  79. package/dist/esm/locale/index.js +5 -5
  80. package/dist/esm/locale/zh.js +1 -4
  81. package/dist/esm/log/error.js +1 -4
  82. package/dist/esm/log/multiTasksLog.js +32 -18
  83. package/dist/esm/log/time.js +7 -8
  84. package/dist/esm/log/utils.js +1 -4
  85. package/dist/esm/package/index.js +21 -8
  86. package/dist/esm/parse-config/index.js +11 -14
  87. package/dist/esm/parse-config/monorepo.js +20 -27
  88. package/dist/esm/projects/checkProjectChange.js +19 -23
  89. package/dist/esm/projects/clearMemoryFiles.js +3 -13
  90. package/dist/esm/projects/getProjects.js +21 -45
  91. package/dist/esm/projects/getProjectsByPackagesConfig.js +29 -33
  92. package/dist/esm/projects/getProjectsByWorkspaceFile.js +21 -41
  93. package/dist/esm/type.js +1 -0
  94. package/dist/esm/utils/install.js +12 -8
  95. package/dist/esm/utils/types.js +1 -0
  96. package/package.json +16 -12
@@ -1,3 +1,16 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import { Signale } from "@modern-js/utils";
2
15
  import { formatLog } from "./utils";
3
16
  const createLogger = (name, config) => {
@@ -21,20 +34,17 @@ const createListenHandler = (name, config) => {
21
34
  const stderr = (chunk) => {
22
35
  logger.error(chunk.toString());
23
36
  };
24
- return { stdout, stderr };
37
+ return {
38
+ stdout,
39
+ stderr
40
+ };
25
41
  };
26
- class MultitasksLogger {
27
- constructor() {
28
- this._taskNameList = [];
29
- this._taskStdoutListenerMap = /* @__PURE__ */ new Map();
30
- this._taskStderrListenerMap = /* @__PURE__ */ new Map();
31
- this._taskLogConfigMap = /* @__PURE__ */ new Map();
32
- }
42
+ export class MultitasksLogger {
33
43
  addLogProvider(name, config) {
34
- var _a, _b;
35
44
  if (this._taskNameList.includes(name)) {
36
- (_a = this._taskStdoutListenerMap.get(name)) == null ? void 0 : _a.removeAllListeners();
37
- (_b = this._taskStderrListenerMap.get(name)) == null ? void 0 : _b.removeAllListeners();
45
+ var _this__taskStdoutListenerMap_get, _this__taskStderrListenerMap_get;
46
+ (_this__taskStdoutListenerMap_get = this._taskStdoutListenerMap.get(name)) === null || _this__taskStdoutListenerMap_get === void 0 ? void 0 : _this__taskStdoutListenerMap_get.removeAllListeners();
47
+ (_this__taskStderrListenerMap_get = this._taskStderrListenerMap.get(name)) === null || _this__taskStderrListenerMap_get === void 0 ? void 0 : _this__taskStderrListenerMap_get.removeAllListeners();
38
48
  this._taskStdoutListenerMap.delete(name);
39
49
  this._taskStderrListenerMap.delete(name);
40
50
  }
@@ -45,10 +55,7 @@ class MultitasksLogger {
45
55
  this.startListen(name);
46
56
  }
47
57
  startListen(taskName) {
48
- const listenHandler = createListenHandler(
49
- taskName,
50
- this._taskLogConfigMap.get(taskName).logConfig
51
- );
58
+ const listenHandler = createListenHandler(taskName, this._taskLogConfigMap.get(taskName).logConfig);
52
59
  this._taskStdoutListenerMap.get(taskName).on("data", listenHandler.stdout);
53
60
  this._taskStdoutListenerMap.get(taskName).on("error", listenHandler.stderr);
54
61
  this._taskStderrListenerMap.get(taskName).on("data", listenHandler.stderr);
@@ -60,7 +67,14 @@ class MultitasksLogger {
60
67
  }
61
68
  finishListen() {
62
69
  }
70
+ constructor() {
71
+ _define_property(this, "_taskNameList", void 0);
72
+ _define_property(this, "_taskStdoutListenerMap", void 0);
73
+ _define_property(this, "_taskStderrListenerMap", void 0);
74
+ _define_property(this, "_taskLogConfigMap", void 0);
75
+ this._taskNameList = [];
76
+ this._taskStdoutListenerMap = /* @__PURE__ */ new Map();
77
+ this._taskStderrListenerMap = /* @__PURE__ */ new Map();
78
+ this._taskLogConfigMap = /* @__PURE__ */ new Map();
79
+ }
63
80
  }
64
- export {
65
- MultitasksLogger
66
- };
@@ -1,13 +1,12 @@
1
1
  import { Signale } from "@modern-js/utils";
2
- const initTimeLog = (option = {}) => new Signale({ interactive: true, scope: "time-log", ...option });
3
- const startTime = (signaleInstance, prefix = "") => {
2
+ export const initTimeLog = (option = {}) => new Signale({
3
+ interactive: true,
4
+ scope: "time-log",
5
+ ...option
6
+ });
7
+ export const startTime = (signaleInstance, prefix = "") => {
4
8
  signaleInstance.time(prefix);
5
9
  };
6
- const endTime = (signaleInstance, prefix = "") => {
10
+ export const endTime = (signaleInstance, prefix = "") => {
7
11
  signaleInstance.timeEnd(prefix);
8
12
  };
9
- export {
10
- endTime,
11
- initTimeLog,
12
- startTime
13
- };
@@ -1,4 +1,4 @@
1
- const formatLog = (log) => {
1
+ export const formatLog = (log) => {
2
2
  const strs = log.split(/\r\n|\n\r|\r|\n/g);
3
3
  if (strs[0].trim() === "") {
4
4
  return `
@@ -6,6 +6,3 @@ ${strs.slice(1).filter((s) => Boolean(s)).join("\n")}`;
6
6
  }
7
7
  return strs.filter((s) => Boolean(s)).join("\n");
8
8
  };
9
- export {
10
- formatLog
11
- };
@@ -1,9 +1,17 @@
1
- class Package {
2
- constructor(packageJson, packageConfigPath, rootPath) {
3
- this.configPath = packageConfigPath;
4
- this.rootPath = rootPath;
5
- this.json = packageJson;
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
6
11
  }
12
+ return obj;
13
+ }
14
+ export class Package {
7
15
  get name() {
8
16
  return this.json.name;
9
17
  }
@@ -13,7 +21,12 @@ class Package {
13
21
  get(key) {
14
22
  return this.json[key];
15
23
  }
24
+ constructor(packageJson, packageConfigPath, rootPath) {
25
+ _define_property(this, "json", void 0);
26
+ _define_property(this, "configPath", void 0);
27
+ _define_property(this, "rootPath", void 0);
28
+ this.configPath = packageConfigPath;
29
+ this.rootPath = rootPath;
30
+ this.json = packageJson;
31
+ }
16
32
  }
17
- export {
18
- Package
19
- };
@@ -1,19 +1,16 @@
1
1
  import * as path from "path";
2
2
  import { JsonFile } from "@rushstack/node-core-library";
3
3
  import { getMonorepoBaseData } from "./monorepo";
4
- const defaultConfig = {
5
- // packagesMatchs: {
6
- // workspaceFile: 'pnpm-lock.yaml',
7
- // },
8
- };
9
- const getFinalConfig = async (currentPath = process.cwd()) => {
4
+ const defaultConfig = {};
5
+ export const getFinalConfig = async (currentPath = process.cwd()) => {
10
6
  const monorepo = getMonorepoBaseData(currentPath);
11
- const userConfig = await JsonFile.loadAsync(
12
- path.resolve(monorepo.rootPath, "mono-config.json")
13
- );
14
- const config = { ...defaultConfig, ...userConfig };
15
- return { monorepo, config };
16
- };
17
- export {
18
- getFinalConfig
7
+ const userConfig = await JsonFile.loadAsync(path.resolve(monorepo.rootPath, "mono-config.json"));
8
+ const config = {
9
+ ...defaultConfig,
10
+ ...userConfig
11
+ };
12
+ return {
13
+ monorepo,
14
+ config
15
+ };
19
16
  };
@@ -29,7 +29,7 @@ const isMonorepo = (monorepoRootPath) => {
29
29
  }
30
30
  return false;
31
31
  };
32
- const findMonorepoRoot = (starFindPath) => {
32
+ export const findMonorepoRoot = (starFindPath) => {
33
33
  let inMonorepo = false;
34
34
  let findPath = starFindPath;
35
35
  while (findPath !== "/") {
@@ -41,12 +41,10 @@ const findMonorepoRoot = (starFindPath) => {
41
41
  }
42
42
  return inMonorepo ? findPath : void 0;
43
43
  };
44
- const getWorkspaceFile = (startFindPath) => {
44
+ export const getWorkspaceFile = (startFindPath) => {
45
45
  const rootPath = findMonorepoRoot(startFindPath);
46
46
  if (!rootPath) {
47
- throw new Error(
48
- "[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`"
49
- );
47
+ throw new Error("[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`");
50
48
  }
51
49
  if (usePnpmWorkspaces(rootPath)) {
52
50
  return WORKSPACE_FILE.PNPM;
@@ -55,26 +53,30 @@ const getWorkspaceFile = (startFindPath) => {
55
53
  } else if (useYarnWorkspaces(rootPath)) {
56
54
  return WORKSPACE_FILE.YARN;
57
55
  } else {
58
- throw new Error(
59
- "[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`"
60
- );
56
+ throw new Error("[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`");
61
57
  }
62
58
  };
63
- const packageManagerFlag = {
64
- pnpm: [WORKSPACE_FILE.PNPM, "pnpm-lock.yaml"],
65
- yarn: ["yarn.lock", useYarnWorkspaces],
66
- npm: [() => true]
59
+ export const packageManagerFlag = {
60
+ pnpm: [
61
+ WORKSPACE_FILE.PNPM,
62
+ "pnpm-lock.yaml"
63
+ ],
64
+ yarn: [
65
+ "yarn.lock",
66
+ useYarnWorkspaces
67
+ ],
68
+ npm: [
69
+ () => true
70
+ ]
67
71
  };
68
- const usePnpmPackageManager = (monorepoRootPath) => packageManagerFlag.pnpm.some(
69
- (flag) => FileSystem.exists(path.join(monorepoRootPath, flag))
70
- );
72
+ const usePnpmPackageManager = (monorepoRootPath) => packageManagerFlag.pnpm.some((flag) => FileSystem.exists(path.join(monorepoRootPath, flag)));
71
73
  const useYarnPackageManager = (monorepoRootPath) => packageManagerFlag.yarn.some((flag) => {
72
74
  if (typeof flag === "function") {
73
75
  return flag(monorepoRootPath);
74
76
  }
75
77
  return FileSystem.exists(path.join(monorepoRootPath, flag));
76
78
  });
77
- const getPackageManager = (monorepoRootPath) => {
79
+ export const getPackageManager = (monorepoRootPath) => {
78
80
  if (usePnpmPackageManager(monorepoRootPath)) {
79
81
  return "pnpm";
80
82
  } else if (useYarnPackageManager(monorepoRootPath)) {
@@ -82,22 +84,13 @@ const getPackageManager = (monorepoRootPath) => {
82
84
  }
83
85
  return "npm";
84
86
  };
85
- const getMonorepoBaseData = (root = process.cwd()) => {
87
+ export const getMonorepoBaseData = (root = process.cwd()) => {
86
88
  const rootPath = findMonorepoRoot(root);
87
89
  if (!rootPath) {
88
- throw new Error(
89
- "not find any monorepo, you can add lerna、pnpm or yarn workspace file"
90
- );
90
+ throw new Error("not find any monorepo, you can add lerna、pnpm or yarn workspace file");
91
91
  }
92
92
  return {
93
93
  rootPath,
94
94
  packageManager: getPackageManager(rootPath)
95
95
  };
96
96
  };
97
- export {
98
- findMonorepoRoot,
99
- getMonorepoBaseData,
100
- getPackageManager,
101
- getWorkspaceFile,
102
- packageManagerFlag
103
- };
@@ -3,9 +3,9 @@ import { FileSystem, JsonFile, Sort } from "@rushstack/node-core-library";
3
3
  import { getGitHashForFiles } from "@rushstack/package-deps-hash";
4
4
  import { globby } from "@modern-js/utils";
5
5
  import md5 from "md5";
6
- const PROJECT_CONTENT_FILE_NAME = "project-content.json";
7
- const MONOREPO_GIT_FILE_NAME = "monorepo-git.json";
8
- const PROJECT_MEMORY_PATH = ".project-memory";
6
+ export const PROJECT_CONTENT_FILE_NAME = "project-content.json";
7
+ export const MONOREPO_GIT_FILE_NAME = "monorepo-git.json";
8
+ export const PROJECT_MEMORY_PATH = ".project-memory";
9
9
  const getProjectGitHash = async (project) => {
10
10
  const projectDir = project.extra.path;
11
11
  const globOption = {
@@ -13,7 +13,11 @@ const getProjectGitHash = async (project) => {
13
13
  absolute: true,
14
14
  expandDirectories: false,
15
15
  followSymbolicLinks: false,
16
- ignore: ["**/node_modules/**", ".project-memory/**", "dist/**"]
16
+ ignore: [
17
+ "**/node_modules/**",
18
+ ".project-memory/**",
19
+ "dist/**"
20
+ ]
17
21
  };
18
22
  const globPattern = `${projectDir}/**`;
19
23
  const files = await globby(path.posix.join(globPattern), globOption);
@@ -25,7 +29,7 @@ const getProjectGitHash = async (project) => {
25
29
  });
26
30
  return md5(JsonFile.stringify(hashObject));
27
31
  };
28
- const checkProjectChangeByGit = async (project, rootPath) => {
32
+ export const checkProjectChangeByGit = async (project, rootPath) => {
29
33
  const monorepoGitMemory = path.join(rootPath, MONOREPO_GIT_FILE_NAME);
30
34
  const currentProjectHash = await getProjectGitHash(project);
31
35
  if (!FileSystem.exists(monorepoGitMemory)) {
@@ -37,11 +41,9 @@ const checkProjectChangeByGit = async (project, rootPath) => {
37
41
  const changed = monorepoProjectHashJson[project.name] !== currentProjectHash;
38
42
  if (changed) {
39
43
  monorepoProjectHashJson[project.name] = currentProjectHash;
40
- FileSystem.writeFile(
41
- monorepoGitMemory,
42
- JsonFile.stringify(monorepoProjectHashJson),
43
- { ensureFolderExists: true }
44
- );
44
+ FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify(monorepoProjectHashJson), {
45
+ ensureFolderExists: true
46
+ });
45
47
  }
46
48
  return changed;
47
49
  };
@@ -52,7 +54,11 @@ const getProjectContentHashObjectForFiles = async (project) => {
52
54
  absolute: true,
53
55
  expandDirectories: false,
54
56
  followSymbolicLinks: false,
55
- ignore: ["**/node_modules/**", ".project-memory/**", "**/dist/**"]
57
+ ignore: [
58
+ "**/node_modules/**",
59
+ ".project-memory/**",
60
+ "**/dist/**"
61
+ ]
56
62
  };
57
63
  const globPattern = `${projectDir}/**`;
58
64
  const files = await globby(path.posix.join(globPattern), globOption);
@@ -62,13 +68,10 @@ const getProjectContentHashObjectForFiles = async (project) => {
62
68
  }
63
69
  return hashObject;
64
70
  };
65
- const checkProjectChangeByContent = async (project) => {
71
+ export const checkProjectChangeByContent = async (project) => {
66
72
  const projectDir = project.extra.path;
67
73
  const projectMemoryFolder = path.resolve(projectDir, ".project-memory");
68
- const projectJsonFile = path.join(
69
- projectMemoryFolder,
70
- PROJECT_CONTENT_FILE_NAME
71
- );
74
+ const projectJsonFile = path.join(projectMemoryFolder, PROJECT_CONTENT_FILE_NAME);
72
75
  const currentHashObject = await getProjectContentHashObjectForFiles(project);
73
76
  const currentHashString = JsonFile.stringify(currentHashObject);
74
77
  if (!FileSystem.exists(projectJsonFile)) {
@@ -86,10 +89,3 @@ const checkProjectChangeByContent = async (project) => {
86
89
  }
87
90
  return changed;
88
91
  };
89
- export {
90
- MONOREPO_GIT_FILE_NAME,
91
- PROJECT_CONTENT_FILE_NAME,
92
- PROJECT_MEMORY_PATH,
93
- checkProjectChangeByContent,
94
- checkProjectChangeByGit
95
- };
@@ -1,20 +1,10 @@
1
1
  import * as path from "path";
2
2
  import { FileSystem } from "@rushstack/node-core-library";
3
- import {
4
- PROJECT_MEMORY_PATH,
5
- PROJECT_CONTENT_FILE_NAME
6
- } from "./checkProjectChange";
7
- const clearProjectsMemoryFile = (projects) => {
3
+ import { PROJECT_MEMORY_PATH, PROJECT_CONTENT_FILE_NAME } from "./checkProjectChange";
4
+ export const clearProjectsMemoryFile = (projects) => {
8
5
  for (const project of projects) {
9
- const memoryFilePath = path.join(
10
- project.extra.path,
11
- PROJECT_MEMORY_PATH,
12
- PROJECT_CONTENT_FILE_NAME
13
- );
6
+ const memoryFilePath = path.join(project.extra.path, PROJECT_MEMORY_PATH, PROJECT_CONTENT_FILE_NAME);
14
7
  console.info("remove", memoryFilePath);
15
8
  FileSystem.deleteFile(memoryFilePath);
16
9
  }
17
10
  };
18
- export {
19
- clearProjectsMemoryFile
20
- };
@@ -1,24 +1,20 @@
1
1
  import { errorLog } from "../log/error";
2
2
  import { getMonorepoBaseData } from "../parse-config/monorepo";
3
- import {
4
- getProjectsByPackageConfig,
5
- syncGetProjectsByPackageConfig
6
- } from "./getProjectsByPackagesConfig";
7
- import {
8
- getProjectsByWorkspaceFile,
9
- syncGetProjectsByWorkspaceFile
10
- } from "./getProjectsByWorkspaceFile";
11
- var FindProjectsMode = /* @__PURE__ */ ((FindProjectsMode2) => {
3
+ import { getProjectsByPackageConfig, syncGetProjectsByPackageConfig } from "./getProjectsByPackagesConfig";
4
+ import { getProjectsByWorkspaceFile, syncGetProjectsByWorkspaceFile } from "./getProjectsByWorkspaceFile";
5
+ var FindProjectsMode;
6
+ (function(FindProjectsMode2) {
12
7
  FindProjectsMode2[FindProjectsMode2["Rough"] = 0] = "Rough";
13
8
  FindProjectsMode2[FindProjectsMode2["Precise"] = 1] = "Precise";
14
- return FindProjectsMode2;
15
- })(FindProjectsMode || {});
9
+ })(FindProjectsMode || (FindProjectsMode = {}));
16
10
  const getProjectsByProjectsConfig = (rootPath, configs = []) => {
17
11
  const subProjects = [];
18
12
  for (const config of configs) {
19
13
  subProjects.push({
20
14
  name: config.name,
21
- extra: { path: config.path },
15
+ extra: {
16
+ path: config.path
17
+ },
22
18
  // dagNodeEdge: 0,
23
19
  dependencyEdge: 0,
24
20
  dependentEdge: 0,
@@ -33,11 +29,7 @@ const getProjectsByPackagesMatch = async (rootPath, match, ignore) => {
33
29
  if (Array.isArray(match)) {
34
30
  projects = await getProjectsByPackageConfig(rootPath, match, ignore);
35
31
  } else {
36
- projects = await getProjectsByWorkspaceFile(
37
- rootPath,
38
- match,
39
- ignore
40
- );
32
+ projects = await getProjectsByWorkspaceFile(rootPath, match, ignore);
41
33
  }
42
34
  const subProjects = [];
43
35
  for (const project of projects) {
@@ -61,11 +53,7 @@ const syncGetProjectsByPackagesMatch = (rootPath, match, ignore) => {
61
53
  if (Array.isArray(match)) {
62
54
  projects = syncGetProjectsByPackageConfig(rootPath, match, ignore);
63
55
  } else {
64
- projects = syncGetProjectsByWorkspaceFile(
65
- rootPath,
66
- match,
67
- ignore
68
- );
56
+ projects = syncGetProjectsByWorkspaceFile(rootPath, match, ignore);
69
57
  }
70
58
  const subProjects = [];
71
59
  for (const project of projects) {
@@ -86,50 +74,38 @@ const syncGetProjectsByPackagesMatch = (rootPath, match, ignore) => {
86
74
  };
87
75
  const checkFindProjectsMode = (config) => {
88
76
  if (config.packagesMatchs && Array.isArray(config.packagesMatchs)) {
89
- return 0 /* Rough */;
77
+ return FindProjectsMode.Rough;
90
78
  }
91
79
  if (config.packagesMatchs && typeof config.packagesMatchs === "object" && (config.packagesMatchs.workspaceFile || config.packagesMatchs.enableAutoFinder)) {
92
- return 0 /* Rough */;
80
+ return FindProjectsMode.Rough;
93
81
  }
94
82
  if (config.projectsConfig && Array.isArray(config.projectsConfig)) {
95
- return 1 /* Precise */;
83
+ return FindProjectsMode.Precise;
96
84
  }
97
85
  if (config.projectsConfig && config.packagesMatchs) {
98
86
  errorLog("There can not be both `packagesMatchs` and `projectsConfig`");
99
87
  }
100
88
  errorLog("No `packagesMatchs` and `projectsConfig` configurations found");
101
89
  };
102
- const getProjects = async (config, currentDir = process.cwd()) => {
90
+ export const getProjects = async (config, currentDir = process.cwd()) => {
103
91
  const { rootPath } = getMonorepoBaseData(currentDir);
104
92
  const mode = checkFindProjectsMode(config);
105
93
  let projects = [];
106
- if (mode === 0 /* Rough */) {
107
- projects = await getProjectsByPackagesMatch(
108
- rootPath,
109
- config.packagesMatchs,
110
- config.packagesIgnoreMatchs || []
111
- );
112
- } else if (mode === 1 /* Precise */) {
94
+ if (mode === FindProjectsMode.Rough) {
95
+ projects = await getProjectsByPackagesMatch(rootPath, config.packagesMatchs, config.packagesIgnoreMatchs || []);
96
+ } else if (mode === FindProjectsMode.Precise) {
113
97
  projects = getProjectsByProjectsConfig(rootPath, config.projectsConfig);
114
98
  }
115
99
  return projects;
116
100
  };
117
- const syncGetProjects = (config, currentDir = process.cwd()) => {
101
+ export const syncGetProjects = (config, currentDir = process.cwd()) => {
118
102
  const { rootPath } = getMonorepoBaseData(currentDir);
119
103
  const mode = checkFindProjectsMode(config);
120
104
  let projects = [];
121
- if (mode === 0 /* Rough */) {
122
- projects = syncGetProjectsByPackagesMatch(
123
- rootPath,
124
- config.packagesMatchs,
125
- config.packagesIgnoreMatchs || []
126
- );
127
- } else if (mode === 1 /* Precise */) {
105
+ if (mode === FindProjectsMode.Rough) {
106
+ projects = syncGetProjectsByPackagesMatch(rootPath, config.packagesMatchs, config.packagesIgnoreMatchs || []);
107
+ } else if (mode === FindProjectsMode.Precise) {
128
108
  projects = getProjectsByProjectsConfig(rootPath, config.projectsConfig);
129
109
  }
130
110
  return projects;
131
111
  };
132
- export {
133
- getProjects,
134
- syncGetProjects
135
- };
@@ -14,9 +14,7 @@ const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
14
14
  };
15
15
  if (packageConfigs.some((cfg) => cfg.includes("**"))) {
16
16
  if (packageConfigs.some((cfg) => cfg.includes("node_modules"))) {
17
- errorLog(
18
- "An explicit node_modules package path does not allow globstars (**)"
19
- );
17
+ errorLog("An explicit node_modules package path does not allow globstars (**)");
20
18
  }
21
19
  globOpts.ignore = [
22
20
  // allow globs like "packages/**",
@@ -31,41 +29,45 @@ const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
31
29
  const makeFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
32
30
  const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
33
31
  return async (fileName, fileMapper, customGlobOpts = {}) => {
34
- const options = { ...customGlobOpts, ...globOpts };
35
- const promise = pMap(
36
- Array.from(packageConfigs).sort(),
37
- async (globPath) => {
38
- let result = await globby(path.posix.join(globPath, fileName), options);
39
- result = result.sort();
40
- result = normalize(result);
41
- return fileMapper(result);
42
- },
43
- { concurrency: packageConfigs.length || Infinity }
44
- );
32
+ const options = {
33
+ ...customGlobOpts,
34
+ ...globOpts
35
+ };
36
+ const promise = pMap(Array.from(packageConfigs).sort(), async (globPath) => {
37
+ let result = await globby(path.posix.join(globPath, fileName), options);
38
+ result = result.sort();
39
+ result = normalize(result);
40
+ return fileMapper(result);
41
+ }, {
42
+ concurrency: packageConfigs.length || Infinity
43
+ });
45
44
  const results = await promise;
46
45
  return results.reduce((acc, result) => acc.concat(result), []);
47
46
  };
48
47
  };
49
- const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignoreConfigs) => {
48
+ export const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignoreConfigs) => {
50
49
  const finder = makeFileFinder(rootPath, packagesConfig, ignoreConfigs);
51
50
  const fileName = "package.json";
52
51
  const mapper = (packageConfigPath) => {
53
- const packageJsonLookup = new PackageJsonLookup({ loadExtraFields: true });
52
+ const packageJsonLookup = new PackageJsonLookup({
53
+ loadExtraFields: true
54
+ });
54
55
  const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
55
56
  return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
56
57
  };
57
- const projects = await finder(
58
- fileName,
59
- (filePaths) => pMap(filePaths, mapper, { concurrency: filePaths.length || Infinity }),
60
- {}
61
- );
58
+ const projects = await finder(fileName, (filePaths) => pMap(filePaths, mapper, {
59
+ concurrency: filePaths.length || Infinity
60
+ }), {});
62
61
  return projects;
63
62
  };
64
63
  const makeSyncFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
65
64
  const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
66
65
  return (fileName, fileMapper, customGlobOpts = {}) => {
67
66
  const results = [];
68
- const options = { ...customGlobOpts, ...globOpts };
67
+ const options = {
68
+ ...customGlobOpts,
69
+ ...globOpts
70
+ };
69
71
  for (const globPath of Array.from(packageConfigs).sort()) {
70
72
  let result = globby.sync(path.posix.join(globPath, fileName), options);
71
73
  result = result.sort();
@@ -75,22 +77,16 @@ const makeSyncFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
75
77
  return results.reduce((acc, result) => acc.concat(result), []);
76
78
  };
77
79
  };
78
- const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
80
+ export const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
79
81
  const finder = makeSyncFileFinder(rootPath, packagesConfig, ignoreConfigs);
80
82
  const fileName = "package.json";
81
83
  const mapper = (packageConfigPath) => {
82
- const packageJsonLookup = new PackageJsonLookup({ loadExtraFields: true });
84
+ const packageJsonLookup = new PackageJsonLookup({
85
+ loadExtraFields: true
86
+ });
83
87
  const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
84
88
  return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
85
89
  };
86
- const projects = finder(
87
- fileName,
88
- (filePaths) => filePaths.map((filePath) => mapper(filePath)),
89
- {}
90
- );
90
+ const projects = finder(fileName, (filePaths) => filePaths.map((filePath) => mapper(filePath)), {});
91
91
  return projects;
92
92
  };
93
- export {
94
- getProjectsByPackageConfig,
95
- syncGetProjectsByPackageConfig
96
- };