@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,35 +1,53 @@
1
- import * as path from 'path';
2
- import { FileSystem, JsonFile, Sort } from '@rushstack/node-core-library';
3
- import { getGitHashForFiles } from '@rushstack/package-deps-hash';
4
- import { globby } from '@modern-js/utils';
5
- import md5 from 'md5';
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
- const getProjectGitHash = async project => {
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 { FileSystem, JsonFile, Sort } from "@rushstack/node-core-library";
23
+ import { getGitHashForFiles } from "@rushstack/package-deps-hash";
24
+ import { globby } from "@modern-js/utils";
25
+ import md5 from "md5";
26
+ const PROJECT_CONTENT_FILE_NAME = "project-content.json";
27
+ const MONOREPO_GIT_FILE_NAME = "monorepo-git.json";
28
+ const PROJECT_MEMORY_PATH = ".project-memory";
29
+ const getProjectGitHash = (project) => __async(void 0, null, function* () {
10
30
  const projectDir = project.extra.path;
11
31
  const globOption = {
12
32
  cwd: projectDir,
13
33
  absolute: true,
14
34
  expandDirectories: false,
15
35
  followSymbolicLinks: false,
16
- ignore: ['**/node_modules/**', '.project-memory/**', 'dist/**']
36
+ ignore: ["**/node_modules/**", ".project-memory/**", "dist/**"]
17
37
  };
18
38
  const globPattern = `${projectDir}/**`;
19
- const files = await globby(path.posix.join(globPattern), globOption);
39
+ const files = yield globby(path.posix.join(globPattern), globOption);
20
40
  const hashMap = getGitHashForFiles(files, projectDir);
21
41
  const hashObject = {};
22
-
23
- // sort is important
24
42
  Sort.sortMapKeys(hashMap);
25
43
  hashMap.forEach((value, key) => {
26
44
  hashObject[key] = value;
27
45
  });
28
46
  return md5(JsonFile.stringify(hashObject));
29
- };
30
- export const checkProjectChangeByGit = async (project, rootPath) => {
47
+ });
48
+ const checkProjectChangeByGit = (project, rootPath) => __async(void 0, null, function* () {
31
49
  const monorepoGitMemory = path.join(rootPath, MONOREPO_GIT_FILE_NAME);
32
- const currentProjectHash = await getProjectGitHash(project);
50
+ const currentProjectHash = yield getProjectGitHash(project);
33
51
  if (!FileSystem.exists(monorepoGitMemory)) {
34
52
  FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify({}), {
35
53
  ensureFolderExists: true
@@ -39,35 +57,39 @@ export const checkProjectChangeByGit = async (project, rootPath) => {
39
57
  const changed = monorepoProjectHashJson[project.name] !== currentProjectHash;
40
58
  if (changed) {
41
59
  monorepoProjectHashJson[project.name] = currentProjectHash;
42
- FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify(monorepoProjectHashJson), {
43
- ensureFolderExists: true
44
- });
60
+ FileSystem.writeFile(
61
+ monorepoGitMemory,
62
+ JsonFile.stringify(monorepoProjectHashJson),
63
+ { ensureFolderExists: true }
64
+ );
45
65
  }
46
66
  return changed;
47
- };
48
- const getProjectContentHashObjectForFiles = async project => {
67
+ });
68
+ const getProjectContentHashObjectForFiles = (project) => __async(void 0, null, function* () {
49
69
  const projectDir = project.extra.path;
50
70
  const globOption = {
51
71
  cwd: projectDir,
52
72
  absolute: true,
53
73
  expandDirectories: false,
54
74
  followSymbolicLinks: false,
55
- ignore: ['**/node_modules/**', '.project-memory/**', '**/dist/**']
75
+ ignore: ["**/node_modules/**", ".project-memory/**", "**/dist/**"]
56
76
  };
57
77
  const globPattern = `${projectDir}/**`;
58
- const files = await globby(path.posix.join(globPattern), globOption);
78
+ const files = yield globby(path.posix.join(globPattern), globOption);
59
79
  const hashObject = {};
60
- // sort is important
61
80
  for (const file of files.sort()) {
62
81
  hashObject[file] = md5(FileSystem.readFile(file));
63
82
  }
64
83
  return hashObject;
65
- };
66
- export const checkProjectChangeByContent = async project => {
84
+ });
85
+ const checkProjectChangeByContent = (project) => __async(void 0, null, function* () {
67
86
  const projectDir = project.extra.path;
68
- const projectMemoryFolder = path.resolve(projectDir, '.project-memory');
69
- const projectJsonFile = path.join(projectMemoryFolder, PROJECT_CONTENT_FILE_NAME);
70
- const currentHashObject = await getProjectContentHashObjectForFiles(project);
87
+ const projectMemoryFolder = path.resolve(projectDir, ".project-memory");
88
+ const projectJsonFile = path.join(
89
+ projectMemoryFolder,
90
+ PROJECT_CONTENT_FILE_NAME
91
+ );
92
+ const currentHashObject = yield getProjectContentHashObjectForFiles(project);
71
93
  const currentHashString = JsonFile.stringify(currentHashObject);
72
94
  if (!FileSystem.exists(projectJsonFile)) {
73
95
  FileSystem.writeFile(projectJsonFile, currentHashString, {
@@ -83,4 +105,11 @@ export const checkProjectChangeByContent = async project => {
83
105
  });
84
106
  }
85
107
  return changed;
86
- };
108
+ });
109
+ export {
110
+ MONOREPO_GIT_FILE_NAME,
111
+ PROJECT_CONTENT_FILE_NAME,
112
+ PROJECT_MEMORY_PATH,
113
+ checkProjectChangeByContent,
114
+ checkProjectChangeByGit
115
+ };
@@ -1,10 +1,20 @@
1
- import * as path from 'path';
2
- import { FileSystem } from '@rushstack/node-core-library';
3
- import { PROJECT_MEMORY_PATH, PROJECT_CONTENT_FILE_NAME } from "./check-project-change";
4
- export const clearProjectsMemoryFile = projects => {
1
+ import * as path from "path";
2
+ import { FileSystem } from "@rushstack/node-core-library";
3
+ import {
4
+ PROJECT_MEMORY_PATH,
5
+ PROJECT_CONTENT_FILE_NAME
6
+ } from "./check-project-change";
7
+ const clearProjectsMemoryFile = (projects) => {
5
8
  for (const project of projects) {
6
- const memoryFilePath = path.join(project.extra.path, PROJECT_MEMORY_PATH, PROJECT_CONTENT_FILE_NAME);
7
- console.info('remove', memoryFilePath);
9
+ const memoryFilePath = path.join(
10
+ project.extra.path,
11
+ PROJECT_MEMORY_PATH,
12
+ PROJECT_CONTENT_FILE_NAME
13
+ );
14
+ console.info("remove", memoryFilePath);
8
15
  FileSystem.deleteFile(memoryFilePath);
9
16
  }
10
- };
17
+ };
18
+ export {
19
+ clearProjectsMemoryFile
20
+ };
@@ -1,13 +1,46 @@
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 { PackageJsonLookup } from '@rushstack/node-core-library';
6
- import { globby } from '@modern-js/utils';
7
- import pMap from 'p-map';
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
36
+ };
37
+ import * as path from "path";
38
+ import { PackageJsonLookup } from "@rushstack/node-core-library";
39
+ import { globby } from "@modern-js/utils";
40
+ import pMap from "p-map";
8
41
  import { errorLog } from "../log/error";
9
42
  import { Package } from "../package";
10
- const normalize = results => results.map(fp => path.normalize(fp));
43
+ const normalize = (results) => results.map((fp) => path.normalize(fp));
11
44
  const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
12
45
  const globOpts = {
13
46
  cwd: rootPath,
@@ -15,79 +48,83 @@ const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
15
48
  expandDirectories: false,
16
49
  followSymbolicLinks: false
17
50
  };
18
- if (packageConfigs.some(cfg => cfg.includes('**'))) {
19
- if (packageConfigs.some(cfg => cfg.includes('node_modules'))) {
20
- errorLog('An explicit node_modules package path does not allow globstars (**)');
51
+ if (packageConfigs.some((cfg) => cfg.includes("**"))) {
52
+ if (packageConfigs.some((cfg) => cfg.includes("node_modules"))) {
53
+ errorLog(
54
+ "An explicit node_modules package path does not allow globstars (**)"
55
+ );
21
56
  }
22
57
  globOpts.ignore = [
23
- // allow globs like "packages/**",
24
- // but avoid picking up node_modules/**/package.json and dist/**/package.json
25
- '**/dist/**', '**/node_modules/**', ...(ignore || [])];
58
+ "**/dist/**",
59
+ "**/node_modules/**",
60
+ ...ignore || []
61
+ ];
26
62
  }
27
63
  return globOpts;
28
64
  };
29
65
  const makeFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
30
66
  const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
31
- return async (fileName, fileMapper, customGlobOpts = {}) => {
32
- const options = _objectSpread(_objectSpread({}, customGlobOpts), globOpts);
33
- const promise = pMap(Array.from(packageConfigs).sort(), async globPath => {
34
- let result = await globby(path.posix.join(globPath, fileName), options);
35
-
36
- // fast-glob does not respect pattern order, so we re-sort by absolute path
37
- result = result.sort();
38
- // POSIX results always need to be normalized
39
- result = normalize(result);
40
- return fileMapper(result);
41
- }, {
42
- concurrency: packageConfigs.length || Infinity
43
- });
44
-
45
- // always flatten the results
46
- const results = await promise;
67
+ return (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (fileName, fileMapper, customGlobOpts = {}) {
68
+ const options = __spreadValues(__spreadValues({}, customGlobOpts), globOpts);
69
+ const promise = pMap(
70
+ Array.from(packageConfigs).sort(),
71
+ (globPath) => __async(void 0, null, function* () {
72
+ let result = yield globby(path.posix.join(globPath, fileName), options);
73
+ result = result.sort();
74
+ result = normalize(result);
75
+ return fileMapper(result);
76
+ }),
77
+ { concurrency: packageConfigs.length || Infinity }
78
+ );
79
+ const results = yield promise;
47
80
  return results.reduce((acc, result) => acc.concat(result), []);
48
- };
81
+ });
49
82
  };
50
- export const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignoreConfigs) => {
83
+ const getProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => __async(void 0, null, function* () {
51
84
  const finder = makeFileFinder(rootPath, packagesConfig, ignoreConfigs);
52
- const fileName = 'package.json';
53
- const mapper = packageConfigPath => {
54
- const packageJsonLookup = new PackageJsonLookup({
55
- loadExtraFields: true
56
- });
85
+ const fileName = "package.json";
86
+ const mapper = (packageConfigPath) => {
87
+ const packageJsonLookup = new PackageJsonLookup({ loadExtraFields: true });
57
88
  const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
58
89
  return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
59
90
  };
60
- const projects = await finder(fileName, filePaths => pMap(filePaths, mapper, {
61
- concurrency: filePaths.length || Infinity
62
- }), {});
91
+ const projects = yield finder(
92
+ fileName,
93
+ (filePaths) => pMap(filePaths, mapper, { concurrency: filePaths.length || Infinity }),
94
+ {}
95
+ );
63
96
  return projects;
64
- };
97
+ });
65
98
  const makeSyncFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
66
99
  const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
67
100
  return (fileName, fileMapper, customGlobOpts = {}) => {
68
101
  const results = [];
69
- const options = _objectSpread(_objectSpread({}, customGlobOpts), globOpts);
102
+ const options = __spreadValues(__spreadValues({}, customGlobOpts), globOpts);
70
103
  for (const globPath of Array.from(packageConfigs).sort()) {
71
104
  let result = globby.sync(path.posix.join(globPath, fileName), options);
72
- // fast-glob does not respect pattern order, so we re-sort by absolute path
73
105
  result = result.sort();
74
- // POSIX results always need to be normalized
75
106
  result = normalize(result);
76
107
  results.push(fileMapper(result));
77
108
  }
78
109
  return results.reduce((acc, result) => acc.concat(result), []);
79
110
  };
80
111
  };
81
- export const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
112
+ const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
82
113
  const finder = makeSyncFileFinder(rootPath, packagesConfig, ignoreConfigs);
83
- const fileName = 'package.json';
84
- const mapper = packageConfigPath => {
85
- const packageJsonLookup = new PackageJsonLookup({
86
- loadExtraFields: true
87
- });
114
+ const fileName = "package.json";
115
+ const mapper = (packageConfigPath) => {
116
+ const packageJsonLookup = new PackageJsonLookup({ loadExtraFields: true });
88
117
  const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
89
118
  return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
90
119
  };
91
- const projects = finder(fileName, filePaths => filePaths.map(filePath => mapper(filePath)), {});
120
+ const projects = finder(
121
+ fileName,
122
+ (filePaths) => filePaths.map((filePath) => mapper(filePath)),
123
+ {}
124
+ );
92
125
  return projects;
93
- };
126
+ };
127
+ export {
128
+ getProjectsByPackageConfig,
129
+ syncGetProjectsByPackageConfig
130
+ };
@@ -1,62 +1,98 @@
1
- import * as path from 'path';
2
- import { FileSystem, JsonFile } from '@rushstack/node-core-library';
3
- import { fs, yaml } 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 { FileSystem, JsonFile } from "@rushstack/node-core-library";
23
+ import { fs, yaml } from "@modern-js/utils";
4
24
  import { getWorkspaceFile } from "../parse-config/monorepo";
5
25
  import { WORKSPACE_FILE } from "../constants";
6
- import { getProjectsByPackageConfig, syncGetProjectsByPackageConfig } from "./get-projects-by-packages-config";
7
- export const getProjectsByWorkspaceFile = async (rootPath, config, ignoreConfigs) => {
8
- var _config$workspaceFile;
9
- let {
10
- workspaceFile
11
- } = config;
12
- if (!config.enableAutoFinder && (!('workspaceFile' in config) || ((_config$workspaceFile = config.workspaceFile) === null || _config$workspaceFile === void 0 ? void 0 : _config$workspaceFile.length) === 0)) {
13
- throw new Error('Missing workspaceFile Key or workspaceFile is empty string');
26
+ import {
27
+ getProjectsByPackageConfig,
28
+ syncGetProjectsByPackageConfig
29
+ } from "./get-projects-by-packages-config";
30
+ const getProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs) => __async(void 0, null, function* () {
31
+ var _a, _b, _c;
32
+ let { workspaceFile } = config;
33
+ if (!config.enableAutoFinder && (!("workspaceFile" in config) || ((_a = config.workspaceFile) == null ? void 0 : _a.length) === 0)) {
34
+ throw new Error(
35
+ "Missing workspaceFile Key or workspaceFile is empty string"
36
+ );
14
37
  }
15
38
  if (config.enableAutoFinder) {
16
39
  workspaceFile = getWorkspaceFile(rootPath);
17
40
  }
18
41
  let packagesConfig = [];
19
42
  if (workspaceFile === WORKSPACE_FILE.PNPM) {
20
- const yamlString = await FileSystem.readFileAsync(path.resolve('/', rootPath, workspaceFile)).then(data => data.toString());
43
+ const yamlString = yield FileSystem.readFileAsync(
44
+ path.resolve("/", rootPath, workspaceFile)
45
+ ).then((data) => data.toString());
21
46
  const pnpmWorkspace = yaml.load(yamlString);
22
47
  packagesConfig = pnpmWorkspace.packages || [];
23
48
  } else if (workspaceFile === WORKSPACE_FILE.YARN) {
24
- var _pkgJson$workspaces;
25
49
  const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
26
- packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces = pkgJson.workspaces) === null || _pkgJson$workspaces === void 0 ? void 0 : _pkgJson$workspaces.packages) || [];
50
+ packagesConfig = ((_b = pkgJson == null ? void 0 : pkgJson.workspaces) == null ? void 0 : _b.packages) || [];
27
51
  } else if (workspaceFile === WORKSPACE_FILE.LERNA) {
28
- var _lernaJson$packages;
29
52
  const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
30
- packagesConfig = (_lernaJson$packages = lernaJson.packages) !== null && _lernaJson$packages !== void 0 ? _lernaJson$packages : [];
53
+ packagesConfig = (_c = lernaJson.packages) != null ? _c : [];
31
54
  }
32
- const projects = await getProjectsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
55
+ const projects = yield getProjectsByPackageConfig(
56
+ rootPath,
57
+ packagesConfig,
58
+ ignoreConfigs
59
+ );
33
60
  return projects;
34
- };
35
- export const syncGetProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs) => {
36
- var _config$workspaceFile2;
37
- let {
38
- workspaceFile
39
- } = config;
40
- if (!config.enableAutoFinder && (!('workspaceFile' in config) || ((_config$workspaceFile2 = config.workspaceFile) === null || _config$workspaceFile2 === void 0 ? void 0 : _config$workspaceFile2.length) === 0)) {
41
- throw new Error('Missing workspaceFile Key or workspaceFile is empty string');
61
+ });
62
+ const syncGetProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs) => {
63
+ var _a, _b, _c;
64
+ let { workspaceFile } = config;
65
+ if (!config.enableAutoFinder && (!("workspaceFile" in config) || ((_a = config.workspaceFile) == null ? void 0 : _a.length) === 0)) {
66
+ throw new Error(
67
+ "Missing workspaceFile Key or workspaceFile is empty string"
68
+ );
42
69
  }
43
70
  if (config.enableAutoFinder) {
44
71
  workspaceFile = getWorkspaceFile(rootPath);
45
72
  }
46
73
  let packagesConfig = [];
47
74
  if (workspaceFile === WORKSPACE_FILE.PNPM) {
48
- const yamlString = fs.readFileSync(path.resolve('/', rootPath, workspaceFile), 'utf-8');
75
+ const yamlString = fs.readFileSync(
76
+ path.resolve("/", rootPath, workspaceFile),
77
+ "utf-8"
78
+ );
49
79
  const pnpmWorkspace = yaml.load(yamlString);
50
80
  packagesConfig = pnpmWorkspace.packages || [];
51
81
  } else if (workspaceFile === WORKSPACE_FILE.YARN) {
52
- var _pkgJson$workspaces2;
53
82
  const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
54
- packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces2 = pkgJson.workspaces) === null || _pkgJson$workspaces2 === void 0 ? void 0 : _pkgJson$workspaces2.packages) || [];
83
+ packagesConfig = ((_b = pkgJson == null ? void 0 : pkgJson.workspaces) == null ? void 0 : _b.packages) || [];
55
84
  } else if (workspaceFile === WORKSPACE_FILE.LERNA) {
56
- var _lernaJson$packages2;
57
85
  const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
58
- packagesConfig = (_lernaJson$packages2 = lernaJson.packages) !== null && _lernaJson$packages2 !== void 0 ? _lernaJson$packages2 : [];
86
+ packagesConfig = (_c = lernaJson.packages) != null ? _c : [];
59
87
  }
60
- const projects = syncGetProjectsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
88
+ const projects = syncGetProjectsByPackageConfig(
89
+ rootPath,
90
+ packagesConfig,
91
+ ignoreConfigs
92
+ );
61
93
  return projects;
62
- };
94
+ };
95
+ export {
96
+ getProjectsByWorkspaceFile,
97
+ syncGetProjectsByWorkspaceFile
98
+ };