@modern-js/monorepo-tools 2.15.0 → 2.17.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,94 +1,134 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var createTask_exports = {};
29
- __export(createTask_exports, {
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
30
13
  createDependenciesTask: () => createDependenciesTask,
31
14
  createDevTask: () => createDevTask
32
15
  });
33
- module.exports = __toCommonJS(createTask_exports);
34
- var import_utils = require("@modern-js/utils");
35
- var import_error = require("../../log/error");
36
- var timeLog = __toESM(require("../../log/time"));
37
- var import_cmds = require("./cmds");
16
+ const _utils = require("@modern-js/utils");
17
+ const _error = require("../../log/error");
18
+ const _time = /* @__PURE__ */ _interop_require_wildcard(require("../../log/time"));
19
+ const _cmds = require("./cmds");
20
+ function _getRequireWildcardCache(nodeInterop) {
21
+ if (typeof WeakMap !== "function")
22
+ return null;
23
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
24
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop2) {
26
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) {
31
+ return obj;
32
+ }
33
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
+ return {
35
+ default: obj
36
+ };
37
+ }
38
+ var cache = _getRequireWildcardCache(nodeInterop);
39
+ if (cache && cache.has(obj)) {
40
+ return cache.get(obj);
41
+ }
42
+ var newObj = {};
43
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
44
+ for (var key in obj) {
45
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
46
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
47
+ if (desc && (desc.get || desc.set)) {
48
+ Object.defineProperty(newObj, key, desc);
49
+ } else {
50
+ newObj[key] = obj[key];
51
+ }
52
+ }
53
+ }
54
+ newObj.default = obj;
55
+ if (cache) {
56
+ cache.set(obj, newObj);
57
+ }
58
+ return newObj;
59
+ }
38
60
  const getFinalTaskCmds = (taskCmds, project) => {
39
61
  let finalTaskCmds = [];
40
62
  if (taskCmds.length === 1) {
41
- finalTaskCmds = [taskCmds[0]];
63
+ finalTaskCmds = [
64
+ taskCmds[0]
65
+ ];
42
66
  } else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "string") {
43
- finalTaskCmds = [taskCmds[1]];
67
+ finalTaskCmds = [
68
+ taskCmds[1]
69
+ ];
44
70
  } else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "function") {
45
71
  finalTaskCmds = taskCmds[1](project);
46
72
  } else {
47
- finalTaskCmds = ["build"];
73
+ finalTaskCmds = [
74
+ "build"
75
+ ];
48
76
  }
49
77
  return finalTaskCmds;
50
78
  };
51
- const createDependenciesTask = (config, taskCmds = import_cmds.defaultBuildWatchCmds, taskLogger) => {
79
+ const createDependenciesTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogger) => {
52
80
  const { packageManager } = config;
53
- const timelogInstance = timeLog.initTimeLog();
81
+ const timelogInstance = _time.initTimeLog();
54
82
  const task = async (project) => {
55
83
  const finalTaskCmds = getFinalTaskCmds(taskCmds, project);
56
84
  const cmd = project.extra.scripts || {};
57
85
  for (const taskCmd of finalTaskCmds) {
58
86
  if (cmd[taskCmd]) {
59
87
  const prefix = `run ${project.name} ${taskCmd} script`;
60
- timeLog.startTime(timelogInstance, prefix);
88
+ _time.startTime(timelogInstance, prefix);
61
89
  try {
62
- const childProcess = (0, import_utils.execa)(packageManager, [taskCmd], {
90
+ const childProcess = (0, _utils.execa)(packageManager, [
91
+ taskCmd
92
+ ], {
63
93
  cwd: project.extra.path,
64
- stdio: ["pipe", "pipe", "pipe"]
94
+ stdio: [
95
+ "pipe",
96
+ "pipe",
97
+ "pipe"
98
+ ]
65
99
  });
66
100
  taskLogger.addLogProvider(project.name, {
67
101
  stdout: childProcess.stdout,
68
102
  stderr: childProcess.stderr,
69
- logConfig: { label: "WATCH: " }
103
+ logConfig: {
104
+ label: "WATCH: "
105
+ }
70
106
  });
71
107
  await childProcess;
72
108
  } catch (e) {
73
- (0, import_error.errorLog)(project.name, e);
109
+ (0, _error.errorLog)(project.name, e);
74
110
  }
75
- timeLog.endTime(timelogInstance, prefix);
111
+ _time.endTime(timelogInstance, prefix);
76
112
  } else {
77
- import_utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
113
+ _utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
78
114
  }
79
115
  }
80
116
  };
81
117
  return task;
82
118
  };
83
- const createDevTask = (config, taskCmds = import_cmds.defaultBuildWatchCmds, taskLogger) => {
119
+ const createDevTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogger) => {
84
120
  const { packageManager } = config;
85
121
  const task = async (project) => {
86
- const devCmds = [taskCmds[0]];
122
+ const devCmds = [
123
+ taskCmds[0]
124
+ ];
87
125
  const cmd = project.extra.scripts || {};
88
126
  for (const taskCmd of devCmds) {
89
127
  if (cmd[taskCmd]) {
90
128
  try {
91
- const childProcess = (0, import_utils.execa)(packageManager, [taskCmd], {
129
+ const childProcess = (0, _utils.execa)(packageManager, [
130
+ taskCmd
131
+ ], {
92
132
  cwd: project.extra.path,
93
133
  stdio: "pipe",
94
134
  all: true
@@ -96,22 +136,19 @@ const createDevTask = (config, taskCmds = import_cmds.defaultBuildWatchCmds, tas
96
136
  taskLogger.addLogProvider(project.name, {
97
137
  stdout: childProcess.stdout,
98
138
  stderr: childProcess.stderr,
99
- logConfig: { label: `${taskCmd.toUpperCase()}: ` }
139
+ logConfig: {
140
+ label: `${taskCmd.toUpperCase()}: `
141
+ }
100
142
  });
101
143
  const ret = await childProcess;
102
144
  console.info(ret);
103
145
  } catch (e) {
104
- (0, import_error.errorLog)(project.name, e);
146
+ (0, _error.errorLog)(project.name, e);
105
147
  }
106
148
  } else {
107
- import_utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
149
+ _utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
108
150
  }
109
151
  }
110
152
  };
111
153
  return task;
112
154
  };
113
- // Annotate the CommonJS export names for ESM import in node:
114
- 0 && (module.exports = {
115
- createDependenciesTask,
116
- createDevTask
117
- });
@@ -1,59 +1,40 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var dev_exports = {};
29
- __export(dev_exports, {
30
- runBuildWatchTask: () => runBuildWatchTask
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "runBuildWatchTask", {
6
+ enumerable: true,
7
+ get: () => runBuildWatchTask
31
8
  });
32
- module.exports = __toCommonJS(dev_exports);
33
- var import_anymatch = __toESM(require("anymatch"));
34
- var import_utils = require("@modern-js/utils");
35
- var import_multiTasksLog = require("../../log/multiTasksLog");
36
- var import_watchProjectsState = require("./watchProjectsState");
37
- var import_cmds = require("./cmds");
38
- var import_createTask = require("./createTask");
9
+ const _anymatch = /* @__PURE__ */ _interop_require_default(require("anymatch"));
10
+ const _utils = require("@modern-js/utils");
11
+ const _multiTasksLog = require("../../log/multiTasksLog");
12
+ const _watchProjectsState = require("./watchProjectsState");
13
+ const _cmds = require("./cmds");
14
+ const _createTask = require("./createTask");
15
+ function _interop_require_default(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
39
20
  const getIgnored = (config) => (watchFilePath) => {
40
21
  const nodeModulesPattern = /(?:^|[\\/])node_modules/g;
41
22
  if (nodeModulesPattern.test(watchFilePath) || watchFilePath.includes("dist")) {
42
23
  return true;
43
24
  }
44
25
  if (config.ignoreMaybeChanged) {
45
- return (0, import_anymatch.default)(config.ignoreMaybeChanged)(watchFilePath);
26
+ return (0, _anymatch.default)(config.ignoreMaybeChanged)(watchFilePath);
46
27
  }
47
28
  return false;
48
29
  };
49
- const runBuildWatchTask = async (projectName, operator, config, taskCmds = import_cmds.defaultBuildWatchCmds) => {
30
+ const runBuildWatchTask = async (projectName, operator, config, taskCmds = _cmds.defaultBuildWatchCmds) => {
50
31
  const { needInit = true } = config;
51
- const taskLogger = new import_multiTasksLog.MultitasksLogger();
52
- const dependenciesTask = (0, import_createTask.createDependenciesTask)(config, taskCmds, taskLogger);
53
- const devTask = (0, import_createTask.createDevTask)(config, taskCmds, taskLogger);
32
+ const taskLogger = new _multiTasksLog.MultitasksLogger();
33
+ const dependenciesTask = (0, _createTask.createDependenciesTask)(config, taskCmds, taskLogger);
34
+ const devTask = (0, _createTask.createDevTask)(config, taskCmds, taskLogger);
54
35
  const fromNodes = operator.getNodeAllDependencyData(projectName);
55
- const watchedProjectState = new import_watchProjectsState.WatchedProjectsState(fromNodes, config);
56
- const watcher = new import_utils.chokidar.FSWatcher({
36
+ const watchedProjectState = new _watchProjectsState.WatchedProjectsState(fromNodes, config);
37
+ const watcher = new _utils.chokidar.FSWatcher({
57
38
  persistent: true,
58
39
  cwd: config.rootPath,
59
40
  followSymlinks: false,
@@ -64,12 +45,9 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = impor
64
45
  });
65
46
  watcher.add(watchedProjectState.getWatchedProjectsPath());
66
47
  if (needInit) {
67
- await operator.traverseDependenciesToProject(
68
- projectName,
69
- async (currentProject) => {
70
- await dependenciesTask(currentProject);
71
- }
72
- );
48
+ await operator.traverseDependenciesToProject(projectName, async (currentProject) => {
49
+ await dependenciesTask(currentProject);
50
+ });
73
51
  }
74
52
  await new Promise((resolve) => {
75
53
  console.info("start watch");
@@ -79,22 +57,18 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = impor
79
57
  }
80
58
  const changedProject = watchedProjectState.getChangedProject(changeFilePath);
81
59
  if (changedProject) {
82
- await operator.traverseProjectToDependent(
83
- changedProject.name,
84
- async (currentProject, _, earlyFinish) => {
85
- if (currentProject.name === projectName) {
86
- earlyFinish();
87
- return;
88
- }
89
- if (watchedProjectState.watchProjectsName.includes(
90
- currentProject.name
91
- )) {
92
- console.info("run build", currentProject.name);
93
- await dependenciesTask(currentProject);
94
- }
95
- },
96
- { withSelf: true }
97
- );
60
+ await operator.traverseProjectToDependent(changedProject.name, async (currentProject, _, earlyFinish) => {
61
+ if (currentProject.name === projectName) {
62
+ earlyFinish();
63
+ return;
64
+ }
65
+ if (watchedProjectState.watchProjectsName.includes(currentProject.name)) {
66
+ console.info("run build", currentProject.name);
67
+ await dependenciesTask(currentProject);
68
+ }
69
+ }, {
70
+ withSelf: true
71
+ });
98
72
  resolve(null);
99
73
  } else {
100
74
  console.info("changed is not in monorepo manager");
@@ -102,9 +76,7 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = impor
102
76
  });
103
77
  resolve(null);
104
78
  });
105
- await devTask(operator.getNodeData(projectName, { checkExist: true }));
79
+ await devTask(operator.getNodeData(projectName, {
80
+ checkExist: true
81
+ }));
106
82
  };
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- runBuildWatchTask
110
- });
@@ -1,69 +1,89 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var watchProjectsState_exports = {};
29
- __export(watchProjectsState_exports, {
30
- WatchedProjectsState: () => WatchedProjectsState
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
31
4
  });
32
- module.exports = __toCommonJS(watchProjectsState_exports);
33
- var path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
35
- class WatchedProjectsState {
36
- constructor(fromNodes, config) {
37
- this._fromNodes = fromNodes;
38
- this._config = config;
39
- this._projectsFileMap = /* @__PURE__ */ new Map();
40
- this._watchProjects = {};
41
- this._initState();
5
+ Object.defineProperty(exports, "WatchedProjectsState", {
6
+ enumerable: true,
7
+ get: () => WatchedProjectsState
8
+ });
9
+ const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ function _define_property(obj, key, value) {
12
+ if (key in obj) {
13
+ Object.defineProperty(obj, key, {
14
+ value,
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true
18
+ });
19
+ } else {
20
+ obj[key] = value;
21
+ }
22
+ return obj;
23
+ }
24
+ function _getRequireWildcardCache(nodeInterop) {
25
+ if (typeof WeakMap !== "function")
26
+ return null;
27
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
28
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
29
+ return (_getRequireWildcardCache = function(nodeInterop2) {
30
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
31
+ })(nodeInterop);
32
+ }
33
+ function _interop_require_wildcard(obj, nodeInterop) {
34
+ if (!nodeInterop && obj && obj.__esModule) {
35
+ return obj;
36
+ }
37
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
38
+ return {
39
+ default: obj
40
+ };
42
41
  }
42
+ var cache = _getRequireWildcardCache(nodeInterop);
43
+ if (cache && cache.has(obj)) {
44
+ return cache.get(obj);
45
+ }
46
+ var newObj = {};
47
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
48
+ for (var key in obj) {
49
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
50
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
51
+ if (desc && (desc.get || desc.set)) {
52
+ Object.defineProperty(newObj, key, desc);
53
+ } else {
54
+ newObj[key] = obj[key];
55
+ }
56
+ }
57
+ }
58
+ newObj.default = obj;
59
+ if (cache) {
60
+ cache.set(obj, newObj);
61
+ }
62
+ return newObj;
63
+ }
64
+ class WatchedProjectsState {
43
65
  _initState() {
44
66
  const globOption = {
45
67
  cwd: this._config.rootPath,
46
68
  absolute: true,
47
69
  expandDirectories: false,
48
70
  followSymbolicLinks: false,
49
- ignore: ["**/node_modules/**", ".project-memory/**", "dist/**"]
71
+ ignore: [
72
+ "**/node_modules/**",
73
+ ".project-memory/**",
74
+ "dist/**"
75
+ ]
50
76
  };
51
- this._watchProjects = this._fromNodes.reduce(
52
- (ret, node) => {
53
- const files = import_utils.globby.sync(`${node.extra.path}/**`, globOption);
54
- for (const filePath of files) {
55
- this._projectsFileMap.set(
56
- path.relative(this._config.rootPath, filePath),
57
- node.extra.path
58
- );
59
- }
60
- return {
61
- ...ret,
62
- [node.extra.path]: node
63
- };
64
- },
65
- {}
66
- );
77
+ this._watchProjects = this._fromNodes.reduce((ret, node) => {
78
+ const files = _utils.globby.sync(`${node.extra.path}/**`, globOption);
79
+ for (const filePath of files) {
80
+ this._projectsFileMap.set(_path.relative(this._config.rootPath, filePath), node.extra.path);
81
+ }
82
+ return {
83
+ ...ret,
84
+ [node.extra.path]: node
85
+ };
86
+ }, {});
67
87
  }
68
88
  getChangedProject(changedFilPath) {
69
89
  if (this._projectsFileMap.has(changedFilPath)) {
@@ -82,12 +102,17 @@ class WatchedProjectsState {
82
102
  return this._watchProjects;
83
103
  }
84
104
  get watchProjectsName() {
85
- return Object.keys(this._watchProjects).map(
86
- (projectPath) => this._watchProjects[projectPath].name
87
- );
105
+ return Object.keys(this._watchProjects).map((projectPath) => this._watchProjects[projectPath].name);
106
+ }
107
+ constructor(fromNodes, config) {
108
+ _define_property(this, "_config", void 0);
109
+ _define_property(this, "_fromNodes", void 0);
110
+ _define_property(this, "_watchProjects", void 0);
111
+ _define_property(this, "_projectsFileMap", void 0);
112
+ this._fromNodes = fromNodes;
113
+ this._config = config;
114
+ this._projectsFileMap = /* @__PURE__ */ new Map();
115
+ this._watchProjects = {};
116
+ this._initState();
88
117
  }
89
118
  }
90
- // Annotate the CommonJS export names for ESM import in node:
91
- 0 && (module.exports = {
92
- WatchedProjectsState
93
- });