@modern-js/monorepo-tools 2.0.0-beta.3 → 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 +51 -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,152 +1,186 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ deploy: () => deploy
5
27
  });
6
- exports.deploy = void 0;
7
- var path = _interopRequireWildcard(require("path"));
8
- var _nodeCoreLibrary = require("@rushstack/node-core-library");
9
- var _utils = require("@modern-js/utils");
10
- var _constants = require("../../constants");
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+ module.exports = __toCommonJS(stdin_exports);
29
+ var path = __toESM(require("path"));
30
+ var import_node_core_library = require("@rushstack/node-core-library");
31
+ var import_utils = require("@modern-js/utils");
32
+ var import_constants = require("../../constants");
33
+ var __async = (__this, __arguments, generator) => {
34
+ return new Promise((resolve, reject) => {
35
+ var fulfilled = (value) => {
36
+ try {
37
+ step(generator.next(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var rejected = (value) => {
43
+ try {
44
+ step(generator.throw(value));
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ };
49
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
+ step((generator = generator.apply(__this, __arguments)).next());
51
+ });
52
+ };
13
53
  const createCopyMap = (rootPath, targetProject, copyProjects, deployDir) => {
14
- const map = new Map();
54
+ const map = /* @__PURE__ */ new Map();
15
55
  for (const project of copyProjects) {
16
56
  const relativePath = path.relative(rootPath, project.extra.path);
17
57
  const targetPath = path.join(deployDir, relativePath);
18
58
  map.set(project.extra.path, targetPath);
19
59
  }
20
- const targetProjectDeployPath = path.join(deployDir, 'apps/app');
60
+ const targetProjectDeployPath = path.join(deployDir, "apps/app");
21
61
  map.set(targetProject.extra.path, targetProjectDeployPath);
22
62
  return map;
23
63
  };
24
- const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename => {
64
+ const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => (filename) => {
25
65
  const sourcePath = path.join(monorepoDir, filename);
26
66
  const destinationPath = path.join(deployDir, filename);
27
- if (_nodeCoreLibrary.FileSystem.exists(sourcePath)) {
28
- _nodeCoreLibrary.FileSystem.copyFile({
67
+ if (import_node_core_library.FileSystem.exists(sourcePath)) {
68
+ import_node_core_library.FileSystem.copyFile({
29
69
  sourcePath,
30
70
  destinationPath
31
71
  });
32
72
  }
33
73
  };
34
- const checkAndUpdatePMWorkspaces = deployDir => {
35
- var _pkg$workspaces;
36
- // pnpm-workspace
37
- const pnpmWp = path.join(deployDir, _constants.WORKSPACE_FILE.PNPM);
38
- if (_utils.fs.existsSync(pnpmWp)) {
39
- const pnpmWorkspace = _utils.yaml.load(_utils.fs.readFileSync(pnpmWp, 'utf-8'));
74
+ const checkAndUpdatePMWorkspaces = (deployDir) => {
75
+ var _a;
76
+ const pnpmWp = path.join(deployDir, import_constants.WORKSPACE_FILE.PNPM);
77
+ if (import_utils.fs.existsSync(pnpmWp)) {
78
+ const pnpmWorkspace = import_utils.yaml.load(
79
+ import_utils.fs.readFileSync(pnpmWp, "utf-8")
80
+ );
40
81
  if (pnpmWorkspace.packages && Array.isArray(pnpmWorkspace.packages)) {
41
- pnpmWorkspace.packages.push('apps/**');
82
+ pnpmWorkspace.packages.push("apps/**");
42
83
  }
43
- _utils.fs.writeFileSync(pnpmWp, _utils.yaml.dump(pnpmWorkspace));
84
+ import_utils.fs.writeFileSync(pnpmWp, import_utils.yaml.dump(pnpmWorkspace));
44
85
  }
45
- const pkgPath = path.join(deployDir, _constants.WORKSPACE_FILE.YARN);
46
- const pkg = _nodeCoreLibrary.JsonFile.load(pkgPath);
47
- if ((_pkg$workspaces = pkg.workspaces) !== null && _pkg$workspaces !== void 0 && _pkg$workspaces.packages && Array.isArray(pkg.workspaces.packages)) {
48
- pkg.workspaces.packages.push('app/**');
86
+ const pkgPath = path.join(deployDir, import_constants.WORKSPACE_FILE.YARN);
87
+ const pkg = import_node_core_library.JsonFile.load(pkgPath);
88
+ if (((_a = pkg.workspaces) == null ? void 0 : _a.packages) && Array.isArray(pkg.workspaces.packages)) {
89
+ pkg.workspaces.packages.push("app/**");
49
90
  }
50
91
  };
51
92
  const generatorAndCopyRequiredFiles = (rootPath, deployDir) => {
52
- // copy .npmrc
53
93
  const copy = createCopyFromMonorepoToDeployDirFn(rootPath, deployDir);
54
- copy('.npmrc');
55
- copy('package.json');
56
- copy('pnpm-workspace.yaml');
57
- copy('lerna.json');
58
- copy('.pnpmfile.cjs');
59
- copy('tsconfig.json');
60
- copy('modern.config.js'); // TODO: 暂时配置,要移除
61
- // lock file
62
- copy('pnpm-lock.yaml');
63
- copy('yarn.lock');
64
- copy('package-lock.json');
65
-
66
- // check workspaces config and add 'apps/**',
67
- // because we deploy project to 'apps' dir
94
+ copy(".npmrc");
95
+ copy("package.json");
96
+ copy("pnpm-workspace.yaml");
97
+ copy("lerna.json");
98
+ copy(".pnpmfile.cjs");
99
+ copy("tsconfig.json");
100
+ copy("modern.config.js");
101
+ copy("pnpm-lock.yaml");
102
+ copy("yarn.lock");
103
+ copy("package-lock.json");
68
104
  checkAndUpdatePMWorkspaces(deployDir);
69
105
  };
70
- const checkAndRunDeployCommand = async (monorepoPath, targetProject, packageManager) => {
71
- var _targetProject$extra;
72
- const scripts = ((_targetProject$extra = targetProject.extra) === null || _targetProject$extra === void 0 ? void 0 : _targetProject$extra.scripts) || {};
106
+ const checkAndRunDeployCommand = (monorepoPath, targetProject, packageManager) => __async(void 0, null, function* () {
107
+ var _a, _b, _c;
108
+ const scripts = ((_a = targetProject.extra) == null ? void 0 : _a.scripts) || {};
73
109
  if (scripts.deploy) {
74
- var _childProcess$stdout, _childProcess$stderr;
75
- _utils.logger.info(`The 'deploy' command for the ${targetProject.name} is detected, so 'deploy' will be executed`);
76
- let runDeployCommands = ['run', 'deploy'];
77
- if (packageManager === 'pnpm') {
78
- const pnpmVersion = await (0, _utils.getPnpmVersion)();
79
- if (pnpmVersion.startsWith('6')) {
80
- runDeployCommands = ['run', 'deploy', '--filter', targetProject.name];
110
+ import_utils.logger.info(
111
+ `The 'deploy' command for the ${targetProject.name} is detected, so 'deploy' will be executed`
112
+ );
113
+ let runDeployCommands = ["run", "deploy"];
114
+ if (packageManager === "pnpm") {
115
+ const pnpmVersion = yield (0, import_utils.getPnpmVersion)();
116
+ if (pnpmVersion.startsWith("6")) {
117
+ runDeployCommands = ["run", "deploy", "--filter", targetProject.name];
81
118
  } else {
82
- runDeployCommands = ['run', '--filter', targetProject.name, 'deploy'];
119
+ runDeployCommands = ["run", "--filter", targetProject.name, "deploy"];
83
120
  }
84
- } else if (packageManager === 'yarn') {
85
- runDeployCommands = ['workspace', targetProject.name, 'run', 'deploy'];
121
+ } else if (packageManager === "yarn") {
122
+ runDeployCommands = ["workspace", targetProject.name, "run", "deploy"];
86
123
  }
87
- const cwd = packageManager === 'npm' ? targetProject.extra.path : monorepoPath;
88
- const childProcess = (0, _utils.execa)(packageManager, runDeployCommands, {
124
+ const cwd = packageManager === "npm" ? targetProject.extra.path : monorepoPath;
125
+ const childProcess = (0, import_utils.execa)(packageManager, runDeployCommands, {
89
126
  cwd,
90
- stdio: ['pipe']
127
+ stdio: ["pipe"]
91
128
  });
92
- (_childProcess$stdout = childProcess.stdout) === null || _childProcess$stdout === void 0 ? void 0 : _childProcess$stdout.pipe(process.stdout);
93
- (_childProcess$stderr = childProcess.stderr) === null || _childProcess$stderr === void 0 ? void 0 : _childProcess$stderr.pipe(process.stderr);
94
- await childProcess;
129
+ (_b = childProcess.stdout) == null ? void 0 : _b.pipe(process.stdout);
130
+ (_c = childProcess.stderr) == null ? void 0 : _c.pipe(process.stderr);
131
+ yield childProcess;
95
132
  }
96
- };
97
-
98
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
99
- const installDependency = async (deployDir, packageManager) => {
100
- // TODO: 使用公共方法替换
101
- const packageJsonPath = path.join(deployDir, 'package.json');
102
- const packageJson = _nodeCoreLibrary.JsonFile.load(packageJsonPath);
103
- const scripts = (packageJson === null || packageJson === void 0 ? void 0 : packageJson.scripts) || {};
133
+ });
134
+ const installDependency = (deployDir, packageManager) => __async(void 0, null, function* () {
135
+ const packageJsonPath = path.join(deployDir, "package.json");
136
+ const packageJson = import_node_core_library.JsonFile.load(packageJsonPath);
137
+ const scripts = (packageJson == null ? void 0 : packageJson.scripts) || {};
104
138
  let commands = [];
105
139
  if (scripts.setup) {
106
- _utils.logger.info(`The 'setup' command is detected, execute '${packageManager} run setup' to start installing the dependencies`);
107
- commands = ['run', 'setup'];
140
+ import_utils.logger.info(
141
+ `The 'setup' command is detected, execute '${packageManager} run setup' to start installing the dependencies`
142
+ );
143
+ commands = ["run", "setup"];
108
144
  } else {
109
- _utils.logger.info(`No 'setup' command detected, execute '${packageManager} install' to start installing dependencies`);
110
- commands = ['install'];
145
+ import_utils.logger.info(
146
+ `No 'setup' command detected, execute '${packageManager} install' to start installing dependencies`
147
+ );
148
+ commands = ["install"];
111
149
  }
112
- _utils.logger.log(_utils.chalk.rgb(218, 152, 92)('Install Log:\n'));
113
- const childProcess = (0, _utils.execa)(packageManager, commands, {
114
- stdio: 'inherit',
150
+ import_utils.logger.log(import_utils.chalk.rgb(218, 152, 92)("Install Log:\n"));
151
+ const childProcess = (0, import_utils.execa)(packageManager, commands, {
152
+ stdio: "inherit",
115
153
  cwd: deployDir,
116
- env: {
117
- NODE_ENV: undefined
118
- }
154
+ env: { NODE_ENV: void 0 }
119
155
  });
120
- await childProcess;
121
- };
122
- const excludeDirs = (filePath, dirs) => dirs.some(dir => filePath.includes(dir));
123
- const defaultDeployPath = 'output';
124
- const deploy = async (deployProjectNames, operator, config) => {
125
- const {
126
- rootPath,
127
- packageManager,
128
- deployPath = defaultDeployPath
129
- } = config;
156
+ yield childProcess;
157
+ });
158
+ const excludeDirs = (filePath, dirs) => dirs.some((dir) => filePath.includes(dir));
159
+ const defaultDeployPath = "output";
160
+ const deploy = (deployProjectNames, operator, config) => __async(void 0, null, function* () {
161
+ const { rootPath, packageManager, deployPath = defaultDeployPath } = config;
130
162
  const realDeployPath = path.isAbsolute(deployPath) ? deployPath : path.join(rootPath, deployPath);
131
- _nodeCoreLibrary.FileSystem.deleteFolder(realDeployPath); // 保证 realDeployPath 目录内为空
132
-
163
+ import_node_core_library.FileSystem.deleteFolder(realDeployPath);
133
164
  for (const deployProjectName of deployProjectNames) {
134
165
  const currentProject = operator.getNodeData(deployProjectName, {
135
166
  checkExist: true
136
167
  });
137
168
  const alldeps = operator.getNodeAllDependencyData(deployProjectName);
138
- const copyMap = createCopyMap(rootPath, currentProject, alldeps, realDeployPath);
139
- await checkAndRunDeployCommand(rootPath, currentProject, packageManager);
140
- _nodeCoreLibrary.FileSystem.ensureFolder(realDeployPath);
169
+ const copyMap = createCopyMap(
170
+ rootPath,
171
+ currentProject,
172
+ alldeps,
173
+ realDeployPath
174
+ );
175
+ yield checkAndRunDeployCommand(rootPath, currentProject, packageManager);
176
+ import_node_core_library.FileSystem.ensureFolder(realDeployPath);
141
177
  for (const [from, to] of copyMap) {
142
- // https://rushstack.io/pages/api/node-core-library.ifilesystemcopyfilesasyncoptions/
143
- _nodeCoreLibrary.FileSystem.copyFiles({
178
+ import_node_core_library.FileSystem.copyFiles({
144
179
  sourcePath: from,
145
180
  destinationPath: to,
146
- // If true, then when copying symlinks, copy the target object instead of copying the link.
147
181
  dereferenceSymlinks: false,
148
182
  filter(filePath) {
149
- if (excludeDirs(filePath, ['node_modules', 'dist'])) {
183
+ if (excludeDirs(filePath, ["node_modules", "dist"])) {
150
184
  return false;
151
185
  }
152
186
  return true;
@@ -155,8 +189,5 @@ const deploy = async (deployProjectNames, operator, config) => {
155
189
  }
156
190
  }
157
191
  generatorAndCopyRequiredFiles(rootPath, realDeployPath);
158
- // await installDependency(realDeployPath, packageManager);
159
-
160
- _utils.logger.success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
161
- };
162
- exports.deploy = deploy;
192
+ import_utils.logger.success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
193
+ });
@@ -1,10 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var stdin_exports = {};
19
+ __export(stdin_exports, {
20
+ defaultBuildWatchCmds: () => defaultBuildWatchCmds
5
21
  });
6
- exports.defaultBuildWatchCmds = void 0;
7
- // TODO: 第一个参数是否也需要为一个string[]
8
-
9
- const defaultBuildWatchCmds = ['dev', 'build'];
10
- exports.defaultBuildWatchCmds = defaultBuildWatchCmds;
22
+ module.exports = __toCommonJS(stdin_exports);
23
+ const defaultBuildWatchCmds = ["dev", "build"];
@@ -1,39 +1,73 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ createDependenciesTask: () => createDependenciesTask,
27
+ createDevTask: () => createDevTask
5
28
  });
6
- exports.createDevTask = exports.createDependenciesTask = void 0;
7
- var _utils = require("@modern-js/utils");
8
- var _error = require("../../log/error");
9
- var timeLog = _interopRequireWildcard(require("../../log/time"));
10
- var _cmds = require("./cmds");
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+ module.exports = __toCommonJS(stdin_exports);
30
+ var import_utils = require("@modern-js/utils");
31
+ var import_error = require("../../log/error");
32
+ var timeLog = __toESM(require("../../log/time"));
33
+ var import_cmds = require("./cmds");
34
+ var __async = (__this, __arguments, generator) => {
35
+ return new Promise((resolve, reject) => {
36
+ var fulfilled = (value) => {
37
+ try {
38
+ step(generator.next(value));
39
+ } catch (e) {
40
+ reject(e);
41
+ }
42
+ };
43
+ var rejected = (value) => {
44
+ try {
45
+ step(generator.throw(value));
46
+ } catch (e) {
47
+ reject(e);
48
+ }
49
+ };
50
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
51
+ step((generator = generator.apply(__this, __arguments)).next());
52
+ });
53
+ };
13
54
  const getFinalTaskCmds = (taskCmds, project) => {
14
55
  let finalTaskCmds = [];
15
- // case1: ["build"]
16
- // case2: ["dev", "build"]
17
- // case3: ["dev", () => []]
18
- // default: ['dev', 'build']
19
56
  if (taskCmds.length === 1) {
20
57
  finalTaskCmds = [taskCmds[0]];
21
- } else if (taskCmds.length === 2 && typeof taskCmds[0] === 'string' && typeof taskCmds[1] === 'string') {
58
+ } else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "string") {
22
59
  finalTaskCmds = [taskCmds[1]];
23
- } else if (taskCmds.length === 2 && typeof taskCmds[0] === 'string' && typeof taskCmds[1] === 'function') {
60
+ } else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "function") {
24
61
  finalTaskCmds = taskCmds[1](project);
25
62
  } else {
26
- // 如果以上为满足,则默认使用build
27
- finalTaskCmds = ['build'];
63
+ finalTaskCmds = ["build"];
28
64
  }
29
65
  return finalTaskCmds;
30
66
  };
31
- const createDependenciesTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogger) => {
32
- const {
33
- packageManager
34
- } = config;
67
+ const createDependenciesTask = (config, taskCmds = import_cmds.defaultBuildWatchCmds, taskLogger) => {
68
+ const { packageManager } = config;
35
69
  const timelogInstance = timeLog.initTimeLog();
36
- const task = async project => {
70
+ const task = (project) => __async(void 0, null, function* () {
37
71
  const finalTaskCmds = getFinalTaskCmds(taskCmds, project);
38
72
  const cmd = project.extra.scripts || {};
39
73
  for (const taskCmd of finalTaskCmds) {
@@ -41,64 +75,54 @@ const createDependenciesTask = (config, taskCmds = _cmds.defaultBuildWatchCmds,
41
75
  const prefix = `run ${project.name} ${taskCmd} script`;
42
76
  timeLog.startTime(timelogInstance, prefix);
43
77
  try {
44
- const childProcess = (0, _utils.execa)(packageManager, [taskCmd], {
78
+ const childProcess = (0, import_utils.execa)(packageManager, [taskCmd], {
45
79
  cwd: project.extra.path,
46
- stdio: ['pipe', 'pipe', 'pipe']
80
+ stdio: ["pipe", "pipe", "pipe"]
47
81
  });
48
82
  taskLogger.addLogProvider(project.name, {
49
83
  stdout: childProcess.stdout,
50
84
  stderr: childProcess.stderr,
51
- logConfig: {
52
- label: 'WATCH: '
53
- }
85
+ logConfig: { label: "WATCH: " }
54
86
  });
55
- await childProcess;
87
+ yield childProcess;
56
88
  } catch (e) {
57
- (0, _error.errorLog)(project.name, e);
89
+ (0, import_error.errorLog)(project.name, e);
58
90
  }
59
91
  timeLog.endTime(timelogInstance, prefix);
60
92
  } else {
61
- _utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
93
+ import_utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
62
94
  }
63
95
  }
64
- };
96
+ });
65
97
  return task;
66
98
  };
67
- exports.createDependenciesTask = createDependenciesTask;
68
- const createDevTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogger) => {
69
- const {
70
- packageManager
71
- } = config;
72
- const task = async project => {
99
+ const createDevTask = (config, taskCmds = import_cmds.defaultBuildWatchCmds, taskLogger) => {
100
+ const { packageManager } = config;
101
+ const task = (project) => __async(void 0, null, function* () {
73
102
  const devCmds = [taskCmds[0]];
74
103
  const cmd = project.extra.scripts || {};
75
104
  for (const taskCmd of devCmds) {
76
105
  if (cmd[taskCmd]) {
77
- // const prefix = `run ${project.name} ${taskCmd} script`;
78
- // log.info(prefix);
79
106
  try {
80
- const childProcess = (0, _utils.execa)(packageManager, [taskCmd], {
107
+ const childProcess = (0, import_utils.execa)(packageManager, [taskCmd], {
81
108
  cwd: project.extra.path,
82
- stdio: 'pipe',
109
+ stdio: "pipe",
83
110
  all: true
84
111
  });
85
112
  taskLogger.addLogProvider(project.name, {
86
113
  stdout: childProcess.stdout,
87
114
  stderr: childProcess.stderr,
88
- logConfig: {
89
- label: `${taskCmd.toUpperCase()}: `
90
- }
115
+ logConfig: { label: `${taskCmd.toUpperCase()}: ` }
91
116
  });
92
- const ret = await childProcess;
117
+ const ret = yield childProcess;
93
118
  console.info(ret);
94
119
  } catch (e) {
95
- (0, _error.errorLog)(project.name, e);
120
+ (0, import_error.errorLog)(project.name, e);
96
121
  }
97
122
  } else {
98
- _utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
123
+ import_utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
99
124
  }
100
125
  }
101
- };
126
+ });
102
127
  return task;
103
128
  };
104
- exports.createDevTask = createDevTask;