@modern-js/monorepo-tools 2.0.0-beta.2 → 2.0.0-beta.4

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 (104) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/bin/modern.js +3 -1
  3. package/dist/js/modern/cli/build-watch.js +30 -5
  4. package/dist/js/modern/cli/build.js +31 -5
  5. package/dist/js/modern/cli/clear.js +30 -5
  6. package/dist/js/modern/cli/deploy.js +35 -7
  7. package/dist/js/modern/cli/index.js +1 -1
  8. package/dist/js/modern/cli/install.js +30 -5
  9. package/dist/js/modern/cli/new.js +56 -14
  10. package/dist/js/modern/commands/build-watch.js +32 -18
  11. package/dist/js/modern/commands/build.js +49 -23
  12. package/dist/js/modern/commands/clear.js +31 -15
  13. package/dist/js/modern/commands/deploy.js +38 -24
  14. package/dist/js/modern/commands/index.js +1 -1
  15. package/dist/js/modern/commands/install.js +32 -17
  16. package/dist/js/modern/constants.js +13 -9
  17. package/dist/js/modern/dag/create.js +27 -23
  18. package/dist/js/modern/dag/edge-manager.js +5 -4
  19. package/dist/js/modern/dag/index.js +6 -5
  20. package/dist/js/modern/dag/operator.js +174 -156
  21. package/dist/js/modern/dag/task.js +64 -39
  22. package/dist/js/modern/dag/utils.js +32 -38
  23. package/dist/js/modern/features/build/index.js +47 -28
  24. package/dist/js/modern/features/clear/index.js +16 -15
  25. package/dist/js/modern/features/deploy/index.js +107 -82
  26. package/dist/js/modern/features/dev/cmds.js +4 -3
  27. package/dist/js/modern/features/dev/create-task.js +43 -34
  28. package/dist/js/modern/features/dev/index.js +60 -41
  29. package/dist/js/modern/features/dev/watch-projects-state.js +47 -24
  30. package/dist/js/modern/features/install/index.js +43 -22
  31. package/dist/js/modern/hooks/index.js +6 -3
  32. package/dist/js/modern/index.js +18 -16
  33. package/dist/js/modern/locale/en.js +10 -7
  34. package/dist/js/modern/locale/index.js +6 -6
  35. package/dist/js/modern/locale/zh.js +11 -8
  36. package/dist/js/modern/log/error.js +6 -3
  37. package/dist/js/modern/log/multi-tasks-log.js +25 -34
  38. package/dist/js/modern/log/time.js +26 -11
  39. package/dist/js/modern/log/utils.js +9 -5
  40. package/dist/js/modern/package/index.js +5 -6
  41. package/dist/js/modern/parse-config/index.js +49 -22
  42. package/dist/js/modern/parse-config/monorepo.js +41 -26
  43. package/dist/js/modern/projects/check-project-change.js +59 -30
  44. package/dist/js/modern/projects/clear-memory-files.js +17 -7
  45. package/dist/js/modern/projects/get-projects-by-packages-config.js +89 -52
  46. package/dist/js/modern/projects/get-projects-by-workspace-file.js +68 -32
  47. package/dist/js/modern/projects/get-projects.js +96 -53
  48. package/dist/js/modern/type.js +0 -1
  49. package/dist/js/modern/utils/install.js +36 -19
  50. package/dist/js/modern/utils/language.js +6 -3
  51. package/dist/js/node/cli/build-watch.js +47 -10
  52. package/dist/js/node/cli/build.js +48 -10
  53. package/dist/js/node/cli/clear.js +47 -10
  54. package/dist/js/node/cli/deploy.js +52 -12
  55. package/dist/js/node/cli/index.js +22 -71
  56. package/dist/js/node/cli/install.js +47 -10
  57. package/dist/js/node/cli/new.js +73 -19
  58. package/dist/js/node/commands/build-watch.js +55 -29
  59. package/dist/js/node/commands/build.js +72 -32
  60. package/dist/js/node/commands/clear.js +53 -25
  61. package/dist/js/node/commands/deploy.js +61 -35
  62. package/dist/js/node/commands/index.js +21 -60
  63. package/dist/js/node/commands/install.js +55 -28
  64. package/dist/js/node/constants.js +28 -13
  65. package/dist/js/node/dag/create.js +44 -28
  66. package/dist/js/node/dag/edge-manager.js +21 -8
  67. package/dist/js/node/dag/index.js +26 -13
  68. package/dist/js/node/dag/operator.js +209 -174
  69. package/dist/js/node/dag/task.js +88 -46
  70. package/dist/js/node/dag/utils.js +51 -47
  71. package/dist/js/node/features/build/index.js +79 -47
  72. package/dist/js/node/features/clear/index.js +44 -28
  73. package/dist/js/node/features/deploy/index.js +135 -104
  74. package/dist/js/node/features/dev/cmds.js +22 -9
  75. package/dist/js/node/features/dev/create-task.js +75 -51
  76. package/dist/js/node/features/dev/index.js +94 -58
  77. package/dist/js/node/features/dev/watch-projects-state.js +69 -30
  78. package/dist/js/node/features/install/index.js +78 -41
  79. package/dist/js/node/hooks/index.js +23 -8
  80. package/dist/js/node/index.js +51 -32
  81. package/dist/js/node/locale/en.js +26 -11
  82. package/dist/js/node/locale/index.js +27 -15
  83. package/dist/js/node/locale/zh.js +27 -12
  84. package/dist/js/node/log/error.js +22 -7
  85. package/dist/js/node/log/multi-tasks-log.js +44 -41
  86. package/dist/js/node/log/time.js +43 -18
  87. package/dist/js/node/log/utils.js +26 -10
  88. package/dist/js/node/package/index.js +21 -10
  89. package/dist/js/node/parse-config/index.js +73 -30
  90. package/dist/js/node/parse-config/monorepo.js +71 -44
  91. package/dist/js/node/projects/check-project-change.js +96 -56
  92. package/dist/js/node/projects/clear-memory-files.js +38 -15
  93. package/dist/js/node/projects/get-projects-by-packages-config.js +116 -65
  94. package/dist/js/node/projects/get-projects-by-workspace-file.js +103 -55
  95. package/dist/js/node/projects/get-projects.js +109 -61
  96. package/dist/js/node/type.js +0 -5
  97. package/dist/js/node/utils/install.js +63 -31
  98. package/dist/js/node/utils/language.js +24 -8
  99. package/dist/types/dag/operator.d.ts +3 -0
  100. package/dist/types/dag/utils.d.ts +1 -0
  101. package/dist/types/features/dev/index.d.ts +1 -0
  102. package/dist/types/index.d.ts +2 -0
  103. package/dist/types/projects/get-projects.d.ts +1 -0
  104. package/package.json +12 -19
@@ -1,19 +1,49 @@
1
- import * as path from 'path';
2
- import { FileSystem, JsonFile } from '@rushstack/node-core-library';
3
- import { fs, yaml, execa, logger, chalk, getPnpmVersion } from '@modern-js/utils';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import * as path from "path";
22
+ import {
23
+ FileSystem,
24
+ JsonFile
25
+ } from "@rushstack/node-core-library";
26
+ import {
27
+ fs,
28
+ yaml,
29
+ execa,
30
+ logger,
31
+ chalk,
32
+ getPnpmVersion
33
+ } from "@modern-js/utils";
4
34
  import { WORKSPACE_FILE } from "../../constants";
5
35
  const createCopyMap = (rootPath, targetProject, copyProjects, deployDir) => {
6
- const map = new Map();
36
+ const map = /* @__PURE__ */ new Map();
7
37
  for (const project of copyProjects) {
8
38
  const relativePath = path.relative(rootPath, project.extra.path);
9
39
  const targetPath = path.join(deployDir, relativePath);
10
40
  map.set(project.extra.path, targetPath);
11
41
  }
12
- const targetProjectDeployPath = path.join(deployDir, 'apps/app');
42
+ const targetProjectDeployPath = path.join(deployDir, "apps/app");
13
43
  map.set(targetProject.extra.path, targetProjectDeployPath);
14
44
  return map;
15
45
  };
16
- const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename => {
46
+ const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => (filename) => {
17
47
  const sourcePath = path.join(monorepoDir, filename);
18
48
  const destinationPath = path.join(deployDir, filename);
19
49
  if (FileSystem.exists(sourcePath)) {
@@ -23,122 +53,116 @@ const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename
23
53
  });
24
54
  }
25
55
  };
26
- const checkAndUpdatePMWorkspaces = deployDir => {
27
- var _pkg$workspaces;
28
- // pnpm-workspace
56
+ const checkAndUpdatePMWorkspaces = (deployDir) => {
57
+ var _a;
29
58
  const pnpmWp = path.join(deployDir, WORKSPACE_FILE.PNPM);
30
59
  if (fs.existsSync(pnpmWp)) {
31
- const pnpmWorkspace = yaml.load(fs.readFileSync(pnpmWp, 'utf-8'));
60
+ const pnpmWorkspace = yaml.load(
61
+ fs.readFileSync(pnpmWp, "utf-8")
62
+ );
32
63
  if (pnpmWorkspace.packages && Array.isArray(pnpmWorkspace.packages)) {
33
- pnpmWorkspace.packages.push('apps/**');
64
+ pnpmWorkspace.packages.push("apps/**");
34
65
  }
35
66
  fs.writeFileSync(pnpmWp, yaml.dump(pnpmWorkspace));
36
67
  }
37
68
  const pkgPath = path.join(deployDir, WORKSPACE_FILE.YARN);
38
69
  const pkg = JsonFile.load(pkgPath);
39
- if ((_pkg$workspaces = pkg.workspaces) !== null && _pkg$workspaces !== void 0 && _pkg$workspaces.packages && Array.isArray(pkg.workspaces.packages)) {
40
- pkg.workspaces.packages.push('app/**');
70
+ if (((_a = pkg.workspaces) == null ? void 0 : _a.packages) && Array.isArray(pkg.workspaces.packages)) {
71
+ pkg.workspaces.packages.push("app/**");
41
72
  }
42
73
  };
43
74
  const generatorAndCopyRequiredFiles = (rootPath, deployDir) => {
44
- // copy .npmrc
45
75
  const copy = createCopyFromMonorepoToDeployDirFn(rootPath, deployDir);
46
- copy('.npmrc');
47
- copy('package.json');
48
- copy('pnpm-workspace.yaml');
49
- copy('lerna.json');
50
- copy('.pnpmfile.cjs');
51
- copy('tsconfig.json');
52
- copy('modern.config.js'); // TODO: 暂时配置,要移除
53
- // lock file
54
- copy('pnpm-lock.yaml');
55
- copy('yarn.lock');
56
- copy('package-lock.json');
57
-
58
- // check workspaces config and add 'apps/**',
59
- // because we deploy project to 'apps' dir
76
+ copy(".npmrc");
77
+ copy("package.json");
78
+ copy("pnpm-workspace.yaml");
79
+ copy("lerna.json");
80
+ copy(".pnpmfile.cjs");
81
+ copy("tsconfig.json");
82
+ copy("modern.config.js");
83
+ copy("pnpm-lock.yaml");
84
+ copy("yarn.lock");
85
+ copy("package-lock.json");
60
86
  checkAndUpdatePMWorkspaces(deployDir);
61
87
  };
62
- const checkAndRunDeployCommand = async (monorepoPath, targetProject, packageManager) => {
63
- var _targetProject$extra;
64
- const scripts = ((_targetProject$extra = targetProject.extra) === null || _targetProject$extra === void 0 ? void 0 : _targetProject$extra.scripts) || {};
88
+ const checkAndRunDeployCommand = (monorepoPath, targetProject, packageManager) => __async(void 0, null, function* () {
89
+ var _a, _b, _c;
90
+ const scripts = ((_a = targetProject.extra) == null ? void 0 : _a.scripts) || {};
65
91
  if (scripts.deploy) {
66
- var _childProcess$stdout, _childProcess$stderr;
67
- logger.info(`The 'deploy' command for the ${targetProject.name} is detected, so 'deploy' will be executed`);
68
- let runDeployCommands = ['run', 'deploy'];
69
- if (packageManager === 'pnpm') {
70
- const pnpmVersion = await getPnpmVersion();
71
- if (pnpmVersion.startsWith('6')) {
72
- runDeployCommands = ['run', 'deploy', '--filter', targetProject.name];
92
+ logger.info(
93
+ `The 'deploy' command for the ${targetProject.name} is detected, so 'deploy' will be executed`
94
+ );
95
+ let runDeployCommands = ["run", "deploy"];
96
+ if (packageManager === "pnpm") {
97
+ const pnpmVersion = yield getPnpmVersion();
98
+ if (pnpmVersion.startsWith("6")) {
99
+ runDeployCommands = ["run", "deploy", "--filter", targetProject.name];
73
100
  } else {
74
- runDeployCommands = ['run', '--filter', targetProject.name, 'deploy'];
101
+ runDeployCommands = ["run", "--filter", targetProject.name, "deploy"];
75
102
  }
76
- } else if (packageManager === 'yarn') {
77
- runDeployCommands = ['workspace', targetProject.name, 'run', 'deploy'];
103
+ } else if (packageManager === "yarn") {
104
+ runDeployCommands = ["workspace", targetProject.name, "run", "deploy"];
78
105
  }
79
- const cwd = packageManager === 'npm' ? targetProject.extra.path : monorepoPath;
106
+ const cwd = packageManager === "npm" ? targetProject.extra.path : monorepoPath;
80
107
  const childProcess = execa(packageManager, runDeployCommands, {
81
108
  cwd,
82
- stdio: ['pipe']
109
+ stdio: ["pipe"]
83
110
  });
84
- (_childProcess$stdout = childProcess.stdout) === null || _childProcess$stdout === void 0 ? void 0 : _childProcess$stdout.pipe(process.stdout);
85
- (_childProcess$stderr = childProcess.stderr) === null || _childProcess$stderr === void 0 ? void 0 : _childProcess$stderr.pipe(process.stderr);
86
- await childProcess;
111
+ (_b = childProcess.stdout) == null ? void 0 : _b.pipe(process.stdout);
112
+ (_c = childProcess.stderr) == null ? void 0 : _c.pipe(process.stderr);
113
+ yield childProcess;
87
114
  }
88
- };
89
-
90
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
91
- const installDependency = async (deployDir, packageManager) => {
92
- // TODO: 使用公共方法替换
93
- const packageJsonPath = path.join(deployDir, 'package.json');
115
+ });
116
+ const installDependency = (deployDir, packageManager) => __async(void 0, null, function* () {
117
+ const packageJsonPath = path.join(deployDir, "package.json");
94
118
  const packageJson = JsonFile.load(packageJsonPath);
95
- const scripts = (packageJson === null || packageJson === void 0 ? void 0 : packageJson.scripts) || {};
119
+ const scripts = (packageJson == null ? void 0 : packageJson.scripts) || {};
96
120
  let commands = [];
97
121
  if (scripts.setup) {
98
- logger.info(`The 'setup' command is detected, execute '${packageManager} run setup' to start installing the dependencies`);
99
- commands = ['run', 'setup'];
122
+ logger.info(
123
+ `The 'setup' command is detected, execute '${packageManager} run setup' to start installing the dependencies`
124
+ );
125
+ commands = ["run", "setup"];
100
126
  } else {
101
- logger.info(`No 'setup' command detected, execute '${packageManager} install' to start installing dependencies`);
102
- commands = ['install'];
127
+ logger.info(
128
+ `No 'setup' command detected, execute '${packageManager} install' to start installing dependencies`
129
+ );
130
+ commands = ["install"];
103
131
  }
104
- logger.log(chalk.rgb(218, 152, 92)('Install Log:\n'));
132
+ logger.log(chalk.rgb(218, 152, 92)("Install Log:\n"));
105
133
  const childProcess = execa(packageManager, commands, {
106
- stdio: 'inherit',
134
+ stdio: "inherit",
107
135
  cwd: deployDir,
108
- env: {
109
- NODE_ENV: undefined
110
- }
136
+ env: { NODE_ENV: void 0 }
111
137
  });
112
- await childProcess;
113
- };
114
- const excludeDirs = (filePath, dirs) => dirs.some(dir => filePath.includes(dir));
115
- const defaultDeployPath = 'output';
116
- export const deploy = async (deployProjectNames, operator, config) => {
117
- const {
118
- rootPath,
119
- packageManager,
120
- deployPath = defaultDeployPath
121
- } = config;
138
+ yield childProcess;
139
+ });
140
+ const excludeDirs = (filePath, dirs) => dirs.some((dir) => filePath.includes(dir));
141
+ const defaultDeployPath = "output";
142
+ const deploy = (deployProjectNames, operator, config) => __async(void 0, null, function* () {
143
+ const { rootPath, packageManager, deployPath = defaultDeployPath } = config;
122
144
  const realDeployPath = path.isAbsolute(deployPath) ? deployPath : path.join(rootPath, deployPath);
123
- FileSystem.deleteFolder(realDeployPath); // 保证 realDeployPath 目录内为空
124
-
145
+ FileSystem.deleteFolder(realDeployPath);
125
146
  for (const deployProjectName of deployProjectNames) {
126
147
  const currentProject = operator.getNodeData(deployProjectName, {
127
148
  checkExist: true
128
149
  });
129
150
  const alldeps = operator.getNodeAllDependencyData(deployProjectName);
130
- const copyMap = createCopyMap(rootPath, currentProject, alldeps, realDeployPath);
131
- await checkAndRunDeployCommand(rootPath, currentProject, packageManager);
151
+ const copyMap = createCopyMap(
152
+ rootPath,
153
+ currentProject,
154
+ alldeps,
155
+ realDeployPath
156
+ );
157
+ yield checkAndRunDeployCommand(rootPath, currentProject, packageManager);
132
158
  FileSystem.ensureFolder(realDeployPath);
133
159
  for (const [from, to] of copyMap) {
134
- // https://rushstack.io/pages/api/node-core-library.ifilesystemcopyfilesasyncoptions/
135
160
  FileSystem.copyFiles({
136
161
  sourcePath: from,
137
162
  destinationPath: to,
138
- // If true, then when copying symlinks, copy the target object instead of copying the link.
139
163
  dereferenceSymlinks: false,
140
164
  filter(filePath) {
141
- if (excludeDirs(filePath, ['node_modules', 'dist'])) {
165
+ if (excludeDirs(filePath, ["node_modules", "dist"])) {
142
166
  return false;
143
167
  }
144
168
  return true;
@@ -147,7 +171,8 @@ export const deploy = async (deployProjectNames, operator, config) => {
147
171
  }
148
172
  }
149
173
  generatorAndCopyRequiredFiles(rootPath, realDeployPath);
150
- // await installDependency(realDeployPath, packageManager);
151
-
152
174
  logger.success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
153
- };
175
+ });
176
+ export {
177
+ deploy
178
+ };
@@ -1,3 +1,4 @@
1
- // TODO: 第一个参数是否也需要为一个string[]
2
-
3
- export const defaultBuildWatchCmds = ['dev', 'build'];
1
+ const defaultBuildWatchCmds = ["dev", "build"];
2
+ export {
3
+ defaultBuildWatchCmds
4
+ };
@@ -1,31 +1,44 @@
1
- import { execa, logger } from '@modern-js/utils';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { execa, logger } from "@modern-js/utils";
2
22
  import { errorLog } from "../../log/error";
3
23
  import * as timeLog from "../../log/time";
4
24
  import { defaultBuildWatchCmds } from "./cmds";
5
25
  const getFinalTaskCmds = (taskCmds, project) => {
6
26
  let finalTaskCmds = [];
7
- // case1: ["build"]
8
- // case2: ["dev", "build"]
9
- // case3: ["dev", () => []]
10
- // default: ['dev', 'build']
11
27
  if (taskCmds.length === 1) {
12
28
  finalTaskCmds = [taskCmds[0]];
13
- } else if (taskCmds.length === 2 && typeof taskCmds[0] === 'string' && typeof taskCmds[1] === 'string') {
29
+ } else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "string") {
14
30
  finalTaskCmds = [taskCmds[1]];
15
- } else if (taskCmds.length === 2 && typeof taskCmds[0] === 'string' && typeof taskCmds[1] === 'function') {
31
+ } else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "function") {
16
32
  finalTaskCmds = taskCmds[1](project);
17
33
  } else {
18
- // 如果以上为满足,则默认使用build
19
- finalTaskCmds = ['build'];
34
+ finalTaskCmds = ["build"];
20
35
  }
21
36
  return finalTaskCmds;
22
37
  };
23
- export const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds, taskLogger) => {
24
- const {
25
- packageManager
26
- } = config;
38
+ const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds, taskLogger) => {
39
+ const { packageManager } = config;
27
40
  const timelogInstance = timeLog.initTimeLog();
28
- const task = async project => {
41
+ const task = (project) => __async(void 0, null, function* () {
29
42
  const finalTaskCmds = getFinalTaskCmds(taskCmds, project);
30
43
  const cmd = project.extra.scripts || {};
31
44
  for (const taskCmd of finalTaskCmds) {
@@ -35,16 +48,14 @@ export const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds,
35
48
  try {
36
49
  const childProcess = execa(packageManager, [taskCmd], {
37
50
  cwd: project.extra.path,
38
- stdio: ['pipe', 'pipe', 'pipe']
51
+ stdio: ["pipe", "pipe", "pipe"]
39
52
  });
40
53
  taskLogger.addLogProvider(project.name, {
41
54
  stdout: childProcess.stdout,
42
55
  stderr: childProcess.stderr,
43
- logConfig: {
44
- label: 'WATCH: '
45
- }
56
+ logConfig: { label: "WATCH: " }
46
57
  });
47
- await childProcess;
58
+ yield childProcess;
48
59
  } catch (e) {
49
60
  errorLog(project.name, e);
50
61
  }
@@ -53,34 +64,28 @@ export const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds,
53
64
  logger.info(`${project.name} not have ${taskCmd}, skip it.`);
54
65
  }
55
66
  }
56
- };
67
+ });
57
68
  return task;
58
69
  };
59
- export const createDevTask = (config, taskCmds = defaultBuildWatchCmds, taskLogger) => {
60
- const {
61
- packageManager
62
- } = config;
63
- const task = async project => {
70
+ const createDevTask = (config, taskCmds = defaultBuildWatchCmds, taskLogger) => {
71
+ const { packageManager } = config;
72
+ const task = (project) => __async(void 0, null, function* () {
64
73
  const devCmds = [taskCmds[0]];
65
74
  const cmd = project.extra.scripts || {};
66
75
  for (const taskCmd of devCmds) {
67
76
  if (cmd[taskCmd]) {
68
- // const prefix = `run ${project.name} ${taskCmd} script`;
69
- // log.info(prefix);
70
77
  try {
71
78
  const childProcess = execa(packageManager, [taskCmd], {
72
79
  cwd: project.extra.path,
73
- stdio: 'pipe',
80
+ stdio: "pipe",
74
81
  all: true
75
82
  });
76
83
  taskLogger.addLogProvider(project.name, {
77
84
  stdout: childProcess.stdout,
78
85
  stderr: childProcess.stderr,
79
- logConfig: {
80
- label: `${taskCmd.toUpperCase()}: `
81
- }
86
+ logConfig: { label: `${taskCmd.toUpperCase()}: ` }
82
87
  });
83
- const ret = await childProcess;
88
+ const ret = yield childProcess;
84
89
  console.info(ret);
85
90
  } catch (e) {
86
91
  errorLog(project.name, e);
@@ -89,6 +94,10 @@ export const createDevTask = (config, taskCmds = defaultBuildWatchCmds, taskLogg
89
94
  logger.info(`${project.name} not have ${taskCmd}, skip it.`);
90
95
  }
91
96
  }
92
- };
97
+ });
93
98
  return task;
94
- };
99
+ };
100
+ export {
101
+ createDependenciesTask,
102
+ createDevTask
103
+ };
@@ -1,13 +1,32 @@
1
- import anymatch from 'anymatch';
2
- import { chokidar } from '@modern-js/utils';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import anymatch from "anymatch";
22
+ import { chokidar } from "@modern-js/utils";
3
23
  import { MultitasksLogger } from "../../log/multi-tasks-log";
4
24
  import { WatchedProjectsState } from "./watch-projects-state";
5
25
  import { defaultBuildWatchCmds } from "./cmds";
6
26
  import { createDependenciesTask, createDevTask } from "./create-task";
7
- const getIgnored = config => watchFilePath => {
8
- // 默认忽略 node_modules 的变化和 dist 目录下文件的变化
27
+ const getIgnored = (config) => (watchFilePath) => {
9
28
  const nodeModulesPattern = /(?:^|[\\/])node_modules/g;
10
- if (nodeModulesPattern.test(watchFilePath) || watchFilePath.includes('dist')) {
29
+ if (nodeModulesPattern.test(watchFilePath) || watchFilePath.includes("dist")) {
11
30
  return true;
12
31
  }
13
32
  if (config.ignoreMaybeChanged) {
@@ -15,10 +34,8 @@ const getIgnored = config => watchFilePath => {
15
34
  }
16
35
  return false;
17
36
  };
18
- export const runBuildWatchTask = async (projectName, operator, config, taskCmds = defaultBuildWatchCmds) => {
19
- const {
20
- needInit = true
21
- } = config;
37
+ const runBuildWatchTask = (_0, _1, _2, ..._3) => __async(void 0, [_0, _1, _2, ..._3], function* (projectName, operator, config, taskCmds = defaultBuildWatchCmds) {
38
+ const { needInit = true } = config;
22
39
  const taskLogger = new MultitasksLogger();
23
40
  const dependenciesTask = createDependenciesTask(config, taskCmds, taskLogger);
24
41
  const devTask = createDevTask(config, taskCmds, taskLogger);
@@ -31,48 +48,50 @@ export const runBuildWatchTask = async (projectName, operator, config, taskCmds
31
48
  ignoreInitial: true,
32
49
  ignored: getIgnored(config),
33
50
  disableGlobbing: true,
34
- interval: 1000
51
+ interval: 1e3
35
52
  });
36
53
  watcher.add(watchedProjectState.getWatchedProjectsPath());
37
-
38
- // 可能会移除该判断和 neeInit 配置
39
54
  if (needInit) {
40
- await operator.traverseDependenciesToProject(projectName, async currentProject => {
41
- await dependenciesTask(currentProject);
42
- });
55
+ yield operator.traverseDependenciesToProject(
56
+ projectName,
57
+ (currentProject) => __async(void 0, null, function* () {
58
+ yield dependenciesTask(currentProject);
59
+ })
60
+ );
43
61
  }
44
- await new Promise(resolve => {
45
- console.info('start watch');
46
- watcher.on('all', async (eventName, changeFilePath) => {
47
- // TODO: 错误情况处理
48
- if (eventName === 'add') {
62
+ yield new Promise((resolve) => {
63
+ console.info("start watch");
64
+ watcher.on("all", (eventName, changeFilePath) => __async(void 0, null, function* () {
65
+ if (eventName === "add") {
49
66
  watchedProjectState.updateState();
50
67
  }
51
68
  const changedProject = watchedProjectState.getChangedProject(changeFilePath);
52
69
  if (changedProject) {
53
- await operator.traverseProjectToDependent(changedProject.name, async (currentProject, _, earlyFinish) => {
54
- // 调试的项目跳过
55
- if (currentProject.name === projectName) {
56
- earlyFinish();
57
- return;
58
- }
59
- if (watchedProjectState.watchProjectsName.includes(currentProject.name)) {
60
- console.info('run build', currentProject.name);
61
- await dependenciesTask(currentProject);
62
- }
63
- }, {
64
- withSelf: true
65
- });
70
+ yield operator.traverseProjectToDependent(
71
+ changedProject.name,
72
+ (currentProject, _, earlyFinish) => __async(void 0, null, function* () {
73
+ if (currentProject.name === projectName) {
74
+ earlyFinish();
75
+ return;
76
+ }
77
+ if (watchedProjectState.watchProjectsName.includes(
78
+ currentProject.name
79
+ )) {
80
+ console.info("run build", currentProject.name);
81
+ yield dependenciesTask(currentProject);
82
+ }
83
+ }),
84
+ { withSelf: true }
85
+ );
66
86
  resolve(null);
67
87
  } else {
68
- console.info('changed is not in monorepo manager');
88
+ console.info("changed is not in monorepo manager");
69
89
  }
70
- });
90
+ }));
71
91
  resolve(null);
72
92
  });
73
-
74
- // 执行目标项目的 dev 任务
75
- await devTask(operator.getNodeData(projectName, {
76
- checkExist: true
77
- }));
78
- };
93
+ yield devTask(operator.getNodeData(projectName, { checkExist: true }));
94
+ });
95
+ export {
96
+ runBuildWatchTask
97
+ };
@@ -1,17 +1,29 @@
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
- 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; }
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; }
4
- import * as path from 'path';
5
- import { globby } from '@modern-js/utils';
6
- export class WatchedProjectsState {
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import * as path from "path";
21
+ import { globby } from "@modern-js/utils";
22
+ class WatchedProjectsState {
7
23
  constructor(fromNodes, config) {
8
- _defineProperty(this, "_config", void 0);
9
- _defineProperty(this, "_fromNodes", void 0);
10
- _defineProperty(this, "_watchProjects", void 0);
11
- _defineProperty(this, "_projectsFileMap", void 0);
12
24
  this._fromNodes = fromNodes;
13
25
  this._config = config;
14
- this._projectsFileMap = new Map();
26
+ this._projectsFileMap = /* @__PURE__ */ new Map();
15
27
  this._watchProjects = {};
16
28
  this._initState();
17
29
  }
@@ -21,24 +33,30 @@ export class WatchedProjectsState {
21
33
  absolute: true,
22
34
  expandDirectories: false,
23
35
  followSymbolicLinks: false,
24
- ignore: ['**/node_modules/**', '.project-memory/**', 'dist/**']
36
+ ignore: ["**/node_modules/**", ".project-memory/**", "dist/**"]
25
37
  };
26
- this._watchProjects = this._fromNodes.reduce((ret, node) => {
27
- const files = globby.sync(`${node.extra.path}/**`, globOption);
28
- for (const filePath of files) {
29
- this._projectsFileMap.set(path.relative(this._config.rootPath, filePath), node.extra.path);
30
- }
31
- return _objectSpread(_objectSpread({}, ret), {}, {
32
- [node.extra.path]: node
33
- });
34
- }, {});
38
+ this._watchProjects = this._fromNodes.reduce(
39
+ (ret, node) => {
40
+ const files = globby.sync(`${node.extra.path}/**`, globOption);
41
+ for (const filePath of files) {
42
+ this._projectsFileMap.set(
43
+ path.relative(this._config.rootPath, filePath),
44
+ node.extra.path
45
+ );
46
+ }
47
+ return __spreadProps(__spreadValues({}, ret), {
48
+ [node.extra.path]: node
49
+ });
50
+ },
51
+ {}
52
+ );
35
53
  }
36
54
  getChangedProject(changedFilPath) {
37
55
  if (this._projectsFileMap.has(changedFilPath)) {
38
56
  const projectPath = this._projectsFileMap.get(changedFilPath);
39
57
  return this._watchProjects[projectPath];
40
58
  }
41
- return undefined;
59
+ return void 0;
42
60
  }
43
61
  getWatchedProjectsPath() {
44
62
  return Object.keys(this._watchProjects);
@@ -50,6 +68,11 @@ export class WatchedProjectsState {
50
68
  return this._watchProjects;
51
69
  }
52
70
  get watchProjectsName() {
53
- return Object.keys(this._watchProjects).map(projectPath => this._watchProjects[projectPath].name);
71
+ return Object.keys(this._watchProjects).map(
72
+ (projectPath) => this._watchProjects[projectPath].name
73
+ );
54
74
  }
55
- }
75
+ }
76
+ export {
77
+ WatchedProjectsState
78
+ };