@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.
- package/CHANGELOG.md +51 -0
- package/bin/modern.js +3 -1
- package/dist/js/modern/cli/build-watch.js +30 -5
- package/dist/js/modern/cli/build.js +31 -5
- package/dist/js/modern/cli/clear.js +30 -5
- package/dist/js/modern/cli/deploy.js +35 -7
- package/dist/js/modern/cli/index.js +1 -1
- package/dist/js/modern/cli/install.js +30 -5
- package/dist/js/modern/cli/new.js +56 -14
- package/dist/js/modern/commands/build-watch.js +32 -18
- package/dist/js/modern/commands/build.js +49 -23
- package/dist/js/modern/commands/clear.js +31 -15
- package/dist/js/modern/commands/deploy.js +38 -24
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/install.js +32 -17
- package/dist/js/modern/constants.js +13 -9
- package/dist/js/modern/dag/create.js +27 -23
- package/dist/js/modern/dag/edge-manager.js +5 -4
- package/dist/js/modern/dag/index.js +6 -5
- package/dist/js/modern/dag/operator.js +174 -156
- package/dist/js/modern/dag/task.js +64 -39
- package/dist/js/modern/dag/utils.js +32 -38
- package/dist/js/modern/features/build/index.js +47 -28
- package/dist/js/modern/features/clear/index.js +16 -15
- package/dist/js/modern/features/deploy/index.js +107 -82
- package/dist/js/modern/features/dev/cmds.js +4 -3
- package/dist/js/modern/features/dev/create-task.js +43 -34
- package/dist/js/modern/features/dev/index.js +60 -41
- package/dist/js/modern/features/dev/watch-projects-state.js +47 -24
- package/dist/js/modern/features/install/index.js +43 -22
- package/dist/js/modern/hooks/index.js +6 -3
- package/dist/js/modern/index.js +18 -16
- package/dist/js/modern/locale/en.js +10 -7
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +11 -8
- package/dist/js/modern/log/error.js +6 -3
- package/dist/js/modern/log/multi-tasks-log.js +25 -34
- package/dist/js/modern/log/time.js +26 -11
- package/dist/js/modern/log/utils.js +9 -5
- package/dist/js/modern/package/index.js +5 -6
- package/dist/js/modern/parse-config/index.js +49 -22
- package/dist/js/modern/parse-config/monorepo.js +41 -26
- package/dist/js/modern/projects/check-project-change.js +59 -30
- package/dist/js/modern/projects/clear-memory-files.js +17 -7
- package/dist/js/modern/projects/get-projects-by-packages-config.js +89 -52
- package/dist/js/modern/projects/get-projects-by-workspace-file.js +68 -32
- package/dist/js/modern/projects/get-projects.js +96 -53
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils/install.js +36 -19
- package/dist/js/modern/utils/language.js +6 -3
- package/dist/js/node/cli/build-watch.js +47 -10
- package/dist/js/node/cli/build.js +48 -10
- package/dist/js/node/cli/clear.js +47 -10
- package/dist/js/node/cli/deploy.js +52 -12
- package/dist/js/node/cli/index.js +22 -71
- package/dist/js/node/cli/install.js +47 -10
- package/dist/js/node/cli/new.js +73 -19
- package/dist/js/node/commands/build-watch.js +55 -29
- package/dist/js/node/commands/build.js +72 -32
- package/dist/js/node/commands/clear.js +53 -25
- package/dist/js/node/commands/deploy.js +61 -35
- package/dist/js/node/commands/index.js +21 -60
- package/dist/js/node/commands/install.js +55 -28
- package/dist/js/node/constants.js +28 -13
- package/dist/js/node/dag/create.js +44 -28
- package/dist/js/node/dag/edge-manager.js +21 -8
- package/dist/js/node/dag/index.js +26 -13
- package/dist/js/node/dag/operator.js +209 -174
- package/dist/js/node/dag/task.js +88 -46
- package/dist/js/node/dag/utils.js +51 -47
- package/dist/js/node/features/build/index.js +79 -47
- package/dist/js/node/features/clear/index.js +44 -28
- package/dist/js/node/features/deploy/index.js +135 -104
- package/dist/js/node/features/dev/cmds.js +22 -9
- package/dist/js/node/features/dev/create-task.js +75 -51
- package/dist/js/node/features/dev/index.js +94 -58
- package/dist/js/node/features/dev/watch-projects-state.js +69 -30
- package/dist/js/node/features/install/index.js +78 -41
- package/dist/js/node/hooks/index.js +23 -8
- package/dist/js/node/index.js +51 -32
- package/dist/js/node/locale/en.js +26 -11
- package/dist/js/node/locale/index.js +27 -15
- package/dist/js/node/locale/zh.js +27 -12
- package/dist/js/node/log/error.js +22 -7
- package/dist/js/node/log/multi-tasks-log.js +44 -41
- package/dist/js/node/log/time.js +43 -18
- package/dist/js/node/log/utils.js +26 -10
- package/dist/js/node/package/index.js +21 -10
- package/dist/js/node/parse-config/index.js +73 -30
- package/dist/js/node/parse-config/monorepo.js +71 -44
- package/dist/js/node/projects/check-project-change.js +96 -56
- package/dist/js/node/projects/clear-memory-files.js +38 -15
- package/dist/js/node/projects/get-projects-by-packages-config.js +116 -65
- package/dist/js/node/projects/get-projects-by-workspace-file.js +103 -55
- package/dist/js/node/projects/get-projects.js +109 -61
- package/dist/js/node/type.js +0 -5
- package/dist/js/node/utils/install.js +63 -31
- package/dist/js/node/utils/language.js +24 -8
- package/dist/types/dag/operator.d.ts +3 -0
- package/dist/types/dag/utils.d.ts +1 -0
- package/dist/types/features/dev/index.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/projects/get-projects.d.ts +1 -0
- package/package.json +12 -19
|
@@ -1,35 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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: [
|
|
36
|
+
ignore: ["**/node_modules/**", ".project-memory/**", "dist/**"]
|
|
17
37
|
};
|
|
18
38
|
const globPattern = `${projectDir}/**`;
|
|
19
|
-
const files =
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
FileSystem.writeFile(
|
|
61
|
+
monorepoGitMemory,
|
|
62
|
+
JsonFile.stringify(monorepoProjectHashJson),
|
|
63
|
+
{ ensureFolderExists: true }
|
|
64
|
+
);
|
|
45
65
|
}
|
|
46
66
|
return changed;
|
|
47
|
-
};
|
|
48
|
-
const getProjectContentHashObjectForFiles =
|
|
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: [
|
|
75
|
+
ignore: ["**/node_modules/**", ".project-memory/**", "**/dist/**"]
|
|
56
76
|
};
|
|
57
77
|
const globPattern = `${projectDir}/**`;
|
|
58
|
-
const files =
|
|
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
|
-
|
|
84
|
+
});
|
|
85
|
+
const checkProjectChangeByContent = (project) => __async(void 0, null, function* () {
|
|
67
86
|
const projectDir = project.extra.path;
|
|
68
|
-
const projectMemoryFolder = path.resolve(projectDir,
|
|
69
|
-
const projectJsonFile = path.join(
|
|
70
|
-
|
|
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
|
|
2
|
-
import { FileSystem } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
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(
|
|
7
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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(
|
|
20
|
-
errorLog(
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
32
|
-
const options =
|
|
33
|
-
const promise = pMap(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
83
|
+
const getProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => __async(void 0, null, function* () {
|
|
51
84
|
const finder = makeFileFinder(rootPath, packagesConfig, ignoreConfigs);
|
|
52
|
-
const fileName =
|
|
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 =
|
|
61
|
-
|
|
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 =
|
|
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
|
-
|
|
112
|
+
const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
|
|
82
113
|
const finder = makeSyncFileFinder(rootPath, packagesConfig, ignoreConfigs);
|
|
83
|
-
const fileName =
|
|
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(
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 =
|
|
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 = (
|
|
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 = (
|
|
53
|
+
packagesConfig = (_c = lernaJson.packages) != null ? _c : [];
|
|
31
54
|
}
|
|
32
|
-
const projects =
|
|
55
|
+
const projects = yield getProjectsByPackageConfig(
|
|
56
|
+
rootPath,
|
|
57
|
+
packagesConfig,
|
|
58
|
+
ignoreConfigs
|
|
59
|
+
);
|
|
33
60
|
return projects;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
let {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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(
|
|
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 = (
|
|
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 = (
|
|
86
|
+
packagesConfig = (_c = lernaJson.packages) != null ? _c : [];
|
|
59
87
|
}
|
|
60
|
-
const projects = syncGetProjectsByPackageConfig(
|
|
88
|
+
const projects = syncGetProjectsByPackageConfig(
|
|
89
|
+
rootPath,
|
|
90
|
+
packagesConfig,
|
|
91
|
+
ignoreConfigs
|
|
92
|
+
);
|
|
61
93
|
return projects;
|
|
62
|
-
};
|
|
94
|
+
};
|
|
95
|
+
export {
|
|
96
|
+
getProjectsByWorkspaceFile,
|
|
97
|
+
syncGetProjectsByWorkspaceFile
|
|
98
|
+
};
|