@modern-js/monorepo-tools 2.0.0-beta.0 → 2.0.0-beta.2
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 +76 -0
- package/dist/js/modern/cli/new.js +0 -3
- package/dist/js/modern/commands/build.js +4 -9
- package/dist/js/modern/dag/create.js +8 -15
- package/dist/js/modern/dag/edge-manager.js +0 -10
- package/dist/js/modern/dag/operator.js +14 -57
- package/dist/js/modern/dag/task.js +0 -18
- package/dist/js/modern/dag/utils.js +13 -31
- package/dist/js/modern/features/build/index.js +8 -19
- package/dist/js/modern/features/clear/index.js +0 -1
- package/dist/js/modern/features/deploy/index.js +7 -35
- package/dist/js/modern/features/dev/cmds.js +1 -0
- package/dist/js/modern/features/dev/create-task.js +2 -13
- package/dist/js/modern/features/dev/index.js +4 -11
- package/dist/js/modern/features/dev/watch-projects-state.js +0 -19
- package/dist/js/modern/features/install/index.js +0 -12
- package/dist/js/modern/index.js +1 -2
- package/dist/js/modern/log/multi-tasks-log.js +8 -31
- package/dist/js/modern/log/time.js +0 -3
- package/dist/js/modern/log/utils.js +0 -2
- package/dist/js/modern/package/index.js +0 -8
- package/dist/js/modern/parse-config/index.js +3 -6
- package/dist/js/modern/parse-config/monorepo.js +0 -23
- package/dist/js/modern/projects/check-project-change.js +4 -16
- package/dist/js/modern/projects/get-projects-by-packages-config.js +12 -29
- package/dist/js/modern/projects/get-projects-by-workspace-file.js +0 -16
- package/dist/js/modern/projects/get-projects.js +4 -29
- package/dist/js/modern/utils/install.js +0 -2
- package/dist/js/node/cli/build-watch.js +0 -3
- package/dist/js/node/cli/build.js +0 -3
- package/dist/js/node/cli/clear.js +0 -3
- package/dist/js/node/cli/deploy.js +0 -3
- package/dist/js/node/cli/index.js +0 -12
- package/dist/js/node/cli/install.js +0 -3
- package/dist/js/node/cli/new.js +0 -7
- package/dist/js/node/commands/build-watch.js +0 -6
- package/dist/js/node/commands/build.js +2 -14
- package/dist/js/node/commands/clear.js +0 -5
- package/dist/js/node/commands/deploy.js +0 -9
- package/dist/js/node/commands/index.js +0 -10
- package/dist/js/node/commands/install.js +0 -6
- package/dist/js/node/dag/create.js +8 -17
- package/dist/js/node/dag/edge-manager.js +0 -12
- package/dist/js/node/dag/index.js +0 -4
- package/dist/js/node/dag/operator.js +14 -65
- package/dist/js/node/dag/task.js +0 -23
- package/dist/js/node/dag/utils.js +12 -39
- package/dist/js/node/features/build/index.js +8 -29
- package/dist/js/node/features/clear/index.js +0 -15
- package/dist/js/node/features/deploy/index.js +7 -53
- package/dist/js/node/features/dev/cmds.js +1 -0
- package/dist/js/node/features/dev/create-task.js +2 -22
- package/dist/js/node/features/dev/index.js +4 -19
- package/dist/js/node/features/dev/watch-projects-state.js +0 -25
- package/dist/js/node/features/install/index.js +0 -25
- package/dist/js/node/hooks/index.js +0 -2
- package/dist/js/node/index.js +2 -16
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/log/error.js +0 -2
- package/dist/js/node/log/multi-tasks-log.js +8 -34
- package/dist/js/node/log/time.js +0 -10
- package/dist/js/node/log/utils.js +0 -4
- package/dist/js/node/package/index.js +0 -10
- package/dist/js/node/parse-config/index.js +3 -14
- package/dist/js/node/parse-config/monorepo.js +0 -34
- package/dist/js/node/projects/check-project-change.js +4 -33
- package/dist/js/node/projects/clear-memory-files.js +0 -8
- package/dist/js/node/projects/get-projects-by-packages-config.js +12 -41
- package/dist/js/node/projects/get-projects-by-workspace-file.js +0 -36
- package/dist/js/node/projects/get-projects.js +4 -37
- package/dist/js/node/utils/install.js +0 -11
- package/dist/js/node/utils/language.js +0 -2
- package/dist/types/cli/clear.d.ts +2 -1
- package/dist/types/cli/deploy.d.ts +2 -1
- package/dist/types/commands/clear.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/dag/operator.d.ts +0 -3
- package/dist/types/dag/utils.d.ts +0 -1
- package/dist/types/features/dev/index.d.ts +0 -1
- package/dist/types/index.d.ts +2 -3
- package/dist/types/projects/get-projects.d.ts +0 -1
- package/dist/types/type.d.ts +5 -1
- package/package.json +15 -15
package/dist/js/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ChangesetPlugin from '@modern-js/plugin-changeset';
|
|
2
|
-
import LintPlugin from '@modern-js/plugin-
|
|
2
|
+
import LintPlugin from '@modern-js/plugin-lint';
|
|
3
3
|
import { Import } from '@modern-js/utils';
|
|
4
4
|
import { i18n } from "./locale";
|
|
5
5
|
import { newCli, deployCli, clearCli } from "./cli";
|
|
@@ -24,7 +24,6 @@ export default (() => ({
|
|
|
24
24
|
newCli(program, locale);
|
|
25
25
|
upgradeModel.defineCommand(program.command('upgrade'));
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
};
|
|
29
28
|
},
|
|
30
29
|
post: ['@modern-js/plugin-changeset']
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
import { Signale } from '@modern-js/utils';
|
|
4
3
|
import { formatLog } from "./utils";
|
|
5
|
-
|
|
6
4
|
const createLogger = (name, config) => {
|
|
7
5
|
const options = {
|
|
8
6
|
scope: config.label ? config.label + name : name,
|
|
@@ -16,19 +14,18 @@ const createLogger = (name, config) => {
|
|
|
16
14
|
};
|
|
17
15
|
return new Signale(options);
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
const createListenHandler = (name, config) => {
|
|
21
18
|
// const sb = new StringBuilder();
|
|
22
|
-
const logger = createLogger(name, config);
|
|
23
|
-
|
|
19
|
+
const logger = createLogger(name, config);
|
|
20
|
+
// eslint-disable-next-line node/prefer-global/buffer
|
|
24
21
|
const stdout = chunk => {
|
|
25
22
|
// console.info(chunk.toString().split(/\r\n|\n\r|\r|\n/g).length);
|
|
26
23
|
logger.info(formatLog(chunk.toString()));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
};
|
|
25
|
+
// eslint-disable-next-line node/prefer-global/buffer
|
|
30
26
|
const stderr = chunk => {
|
|
31
|
-
logger.error(chunk.toString());
|
|
27
|
+
logger.error(chunk.toString());
|
|
28
|
+
// logger.log('#####################');
|
|
32
29
|
};
|
|
33
30
|
|
|
34
31
|
return {
|
|
@@ -36,63 +33,43 @@ const createListenHandler = (name, config) => {
|
|
|
36
33
|
stderr
|
|
37
34
|
};
|
|
38
35
|
};
|
|
39
|
-
|
|
40
36
|
export class MultitasksLogger {
|
|
41
37
|
constructor() {
|
|
42
38
|
_defineProperty(this, "_taskNameList", void 0);
|
|
43
|
-
|
|
44
39
|
_defineProperty(this, "_taskStdoutListenerMap", void 0);
|
|
45
|
-
|
|
46
40
|
_defineProperty(this, "_taskStderrListenerMap", void 0);
|
|
47
|
-
|
|
48
41
|
_defineProperty(this, "_taskLogConfigMap", void 0);
|
|
49
|
-
|
|
50
42
|
this._taskNameList = [];
|
|
51
43
|
this._taskStdoutListenerMap = new Map();
|
|
52
44
|
this._taskStderrListenerMap = new Map();
|
|
53
45
|
this._taskLogConfigMap = new Map();
|
|
54
46
|
}
|
|
55
|
-
|
|
56
47
|
addLogProvider(name, config) {
|
|
57
48
|
if (this._taskNameList.includes(name)) {
|
|
58
49
|
var _this$_taskStdoutList, _this$_taskStderrList;
|
|
59
|
-
|
|
60
50
|
(_this$_taskStdoutList = this._taskStdoutListenerMap.get(name)) === null || _this$_taskStdoutList === void 0 ? void 0 : _this$_taskStdoutList.removeAllListeners();
|
|
61
51
|
(_this$_taskStderrList = this._taskStderrListenerMap.get(name)) === null || _this$_taskStderrList === void 0 ? void 0 : _this$_taskStderrList.removeAllListeners();
|
|
62
|
-
|
|
63
52
|
this._taskStdoutListenerMap.delete(name);
|
|
64
|
-
|
|
65
53
|
this._taskStderrListenerMap.delete(name);
|
|
66
54
|
}
|
|
67
|
-
|
|
68
55
|
this._taskNameList.push(name);
|
|
69
|
-
|
|
70
56
|
this._taskLogConfigMap.set(name, config);
|
|
71
|
-
|
|
72
57
|
this._taskStdoutListenerMap.set(name, config.stdout);
|
|
73
|
-
|
|
74
58
|
this._taskStderrListenerMap.set(name, config.stderr);
|
|
75
|
-
|
|
76
59
|
this.startListen(name);
|
|
77
60
|
}
|
|
78
|
-
|
|
79
61
|
startListen(taskName) {
|
|
80
62
|
const listenHandler = createListenHandler(taskName, this._taskLogConfigMap.get(taskName).logConfig);
|
|
81
|
-
|
|
82
63
|
this._taskStdoutListenerMap.get(taskName).on('data', listenHandler.stdout);
|
|
83
|
-
|
|
84
64
|
this._taskStdoutListenerMap.get(taskName).on('error', listenHandler.stderr);
|
|
85
|
-
|
|
86
65
|
this._taskStderrListenerMap.get(taskName).on('data', listenHandler.stderr);
|
|
87
66
|
}
|
|
88
|
-
|
|
89
67
|
startListenAll() {
|
|
90
68
|
for (const taskName of this._taskNameList) {
|
|
91
69
|
this.startListen(taskName);
|
|
92
70
|
}
|
|
93
71
|
}
|
|
94
|
-
|
|
95
|
-
|
|
72
|
+
finishListen() {
|
|
73
|
+
// 是否需要
|
|
96
74
|
}
|
|
97
|
-
|
|
98
75
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
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
|
-
|
|
3
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; }
|
|
4
|
-
|
|
5
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; }
|
|
6
|
-
|
|
7
4
|
import { Signale } from '@modern-js/utils';
|
|
8
5
|
export const initTimeLog = (option = {}) => new Signale(_objectSpread({
|
|
9
6
|
interactive: true,
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
export class Package {
|
|
4
3
|
constructor(packageJson, packageConfigPath, rootPath) {
|
|
5
4
|
_defineProperty(this, "json", void 0);
|
|
6
|
-
|
|
7
5
|
_defineProperty(this, "configPath", void 0);
|
|
8
|
-
|
|
9
6
|
_defineProperty(this, "rootPath", void 0);
|
|
10
|
-
|
|
11
7
|
this.configPath = packageConfigPath;
|
|
12
8
|
this.rootPath = rootPath;
|
|
13
9
|
this.json = packageJson;
|
|
14
10
|
}
|
|
15
|
-
|
|
16
11
|
get name() {
|
|
17
12
|
return this.json.name;
|
|
18
13
|
}
|
|
19
|
-
|
|
20
14
|
get path() {
|
|
21
15
|
return this.configPath;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
get(key) {
|
|
25
18
|
return this.json[key];
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
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
|
-
|
|
3
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; }
|
|
4
|
-
|
|
5
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; }
|
|
6
|
-
|
|
7
4
|
import * as path from 'path';
|
|
8
5
|
import { JsonFile } from '@rushstack/node-core-library';
|
|
9
6
|
import { getMonorepoBaseData } from "./monorepo";
|
|
10
|
-
const defaultConfig = {
|
|
7
|
+
const defaultConfig = {
|
|
8
|
+
// packagesMatchs: {
|
|
11
9
|
// workspaceFile: 'pnpm-lock.yaml',
|
|
12
10
|
// },
|
|
13
11
|
};
|
|
@@ -15,11 +13,10 @@ export const getFinalConfig = async (currentPath = process.cwd()) => {
|
|
|
15
13
|
// TODO:
|
|
16
14
|
// 1. 初始化获取信息
|
|
17
15
|
// 2. 配置文件是否存在校验
|
|
16
|
+
|
|
18
17
|
const monorepo = getMonorepoBaseData(currentPath);
|
|
19
18
|
const userConfig = await JsonFile.loadAsync(path.resolve(monorepo.rootPath, 'mono-config.json'));
|
|
20
|
-
|
|
21
19
|
const config = _objectSpread(_objectSpread({}, defaultConfig), userConfig);
|
|
22
|
-
|
|
23
20
|
return {
|
|
24
21
|
monorepo,
|
|
25
22
|
config
|
|
@@ -1,67 +1,51 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import { FileSystem, JsonFile } from '@rushstack/node-core-library';
|
|
3
3
|
import { WORKSPACE_FILE } from "../constants";
|
|
4
|
-
|
|
5
4
|
const useLerna = monorepoRootPath => {
|
|
6
5
|
if (FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.LERNA))) {
|
|
7
6
|
return true;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
return false;
|
|
11
9
|
};
|
|
12
|
-
|
|
13
10
|
const useYarnWorkspaces = monorepoRootPath => {
|
|
14
11
|
if (!FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.YARN))) {
|
|
15
12
|
return false;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
const json = JsonFile.load(path.join(monorepoRootPath, WORKSPACE_FILE.YARN));
|
|
19
|
-
|
|
20
15
|
if ('workspaces' in json && json.workspaces.packages) {
|
|
21
16
|
return true;
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
return false;
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
const usePnpmWorkspaces = monorepoRootPath => {
|
|
28
21
|
if (FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.PNPM))) {
|
|
29
22
|
return true;
|
|
30
23
|
}
|
|
31
|
-
|
|
32
24
|
return false;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
const isMonorepo = monorepoRootPath => {
|
|
36
27
|
if (usePnpmWorkspaces(monorepoRootPath) || useLerna(monorepoRootPath) || useYarnWorkspaces(monorepoRootPath)) {
|
|
37
28
|
return true;
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
return false;
|
|
41
31
|
};
|
|
42
|
-
|
|
43
32
|
export const findMonorepoRoot = starFindPath => {
|
|
44
33
|
let inMonorepo = false;
|
|
45
34
|
let findPath = starFindPath;
|
|
46
|
-
|
|
47
35
|
while (findPath !== '/') {
|
|
48
36
|
if (isMonorepo(findPath)) {
|
|
49
37
|
inMonorepo = true;
|
|
50
38
|
break;
|
|
51
39
|
}
|
|
52
|
-
|
|
53
40
|
findPath = path.dirname(findPath);
|
|
54
41
|
}
|
|
55
|
-
|
|
56
42
|
return inMonorepo ? findPath : undefined;
|
|
57
43
|
};
|
|
58
44
|
export const getWorkspaceFile = startFindPath => {
|
|
59
45
|
const rootPath = findMonorepoRoot(startFindPath);
|
|
60
|
-
|
|
61
46
|
if (!rootPath) {
|
|
62
47
|
throw new Error('[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`');
|
|
63
48
|
}
|
|
64
|
-
|
|
65
49
|
if (usePnpmWorkspaces(rootPath)) {
|
|
66
50
|
return WORKSPACE_FILE.PNPM;
|
|
67
51
|
} else if (useLerna(rootPath)) {
|
|
@@ -77,33 +61,26 @@ export const packageManagerFlag = {
|
|
|
77
61
|
yarn: ['yarn.lock', useYarnWorkspaces],
|
|
78
62
|
npm: [() => true]
|
|
79
63
|
};
|
|
80
|
-
|
|
81
64
|
const usePnpmPackageManager = monorepoRootPath => packageManagerFlag.pnpm.some(flag => FileSystem.exists(path.join(monorepoRootPath, flag)));
|
|
82
|
-
|
|
83
65
|
const useYarnPackageManager = monorepoRootPath => packageManagerFlag.yarn.some(flag => {
|
|
84
66
|
if (typeof flag === 'function') {
|
|
85
67
|
return flag(monorepoRootPath);
|
|
86
68
|
}
|
|
87
|
-
|
|
88
69
|
return FileSystem.exists(path.join(monorepoRootPath, flag));
|
|
89
70
|
});
|
|
90
|
-
|
|
91
71
|
export const getPackageManager = monorepoRootPath => {
|
|
92
72
|
if (usePnpmPackageManager(monorepoRootPath)) {
|
|
93
73
|
return 'pnpm';
|
|
94
74
|
} else if (useYarnPackageManager(monorepoRootPath)) {
|
|
95
75
|
return 'yarn';
|
|
96
76
|
}
|
|
97
|
-
|
|
98
77
|
return 'npm';
|
|
99
78
|
};
|
|
100
79
|
export const getMonorepoBaseData = (root = process.cwd()) => {
|
|
101
80
|
const rootPath = findMonorepoRoot(root);
|
|
102
|
-
|
|
103
81
|
if (!rootPath) {
|
|
104
82
|
throw new Error('not find any monorepo, you can add lerna、pnpm or yarn workspace file');
|
|
105
83
|
}
|
|
106
|
-
|
|
107
84
|
return {
|
|
108
85
|
rootPath,
|
|
109
86
|
packageManager: getPackageManager(rootPath)
|
|
@@ -6,7 +6,6 @@ import md5 from 'md5';
|
|
|
6
6
|
export const PROJECT_CONTENT_FILE_NAME = 'project-content.json';
|
|
7
7
|
export const MONOREPO_GIT_FILE_NAME = 'monorepo-git.json';
|
|
8
8
|
export const PROJECT_MEMORY_PATH = '.project-memory';
|
|
9
|
-
|
|
10
9
|
const getProjectGitHash = async project => {
|
|
11
10
|
const projectDir = project.extra.path;
|
|
12
11
|
const globOption = {
|
|
@@ -19,38 +18,33 @@ const getProjectGitHash = async project => {
|
|
|
19
18
|
const globPattern = `${projectDir}/**`;
|
|
20
19
|
const files = await globby(path.posix.join(globPattern), globOption);
|
|
21
20
|
const hashMap = getGitHashForFiles(files, projectDir);
|
|
22
|
-
const hashObject = {};
|
|
21
|
+
const hashObject = {};
|
|
23
22
|
|
|
23
|
+
// sort is important
|
|
24
24
|
Sort.sortMapKeys(hashMap);
|
|
25
25
|
hashMap.forEach((value, key) => {
|
|
26
26
|
hashObject[key] = value;
|
|
27
27
|
});
|
|
28
28
|
return md5(JsonFile.stringify(hashObject));
|
|
29
29
|
};
|
|
30
|
-
|
|
31
30
|
export const checkProjectChangeByGit = async (project, rootPath) => {
|
|
32
31
|
const monorepoGitMemory = path.join(rootPath, MONOREPO_GIT_FILE_NAME);
|
|
33
32
|
const currentProjectHash = await getProjectGitHash(project);
|
|
34
|
-
|
|
35
33
|
if (!FileSystem.exists(monorepoGitMemory)) {
|
|
36
34
|
FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify({}), {
|
|
37
35
|
ensureFolderExists: true
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
|
-
|
|
41
38
|
const monorepoProjectHashJson = JsonFile.load(monorepoGitMemory);
|
|
42
39
|
const changed = monorepoProjectHashJson[project.name] !== currentProjectHash;
|
|
43
|
-
|
|
44
40
|
if (changed) {
|
|
45
41
|
monorepoProjectHashJson[project.name] = currentProjectHash;
|
|
46
42
|
FileSystem.writeFile(monorepoGitMemory, JsonFile.stringify(monorepoProjectHashJson), {
|
|
47
43
|
ensureFolderExists: true
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
|
-
|
|
51
46
|
return changed;
|
|
52
47
|
};
|
|
53
|
-
|
|
54
48
|
const getProjectContentHashObjectForFiles = async project => {
|
|
55
49
|
const projectDir = project.extra.path;
|
|
56
50
|
const globOption = {
|
|
@@ -62,37 +56,31 @@ const getProjectContentHashObjectForFiles = async project => {
|
|
|
62
56
|
};
|
|
63
57
|
const globPattern = `${projectDir}/**`;
|
|
64
58
|
const files = await globby(path.posix.join(globPattern), globOption);
|
|
65
|
-
const hashObject = {};
|
|
66
|
-
|
|
59
|
+
const hashObject = {};
|
|
60
|
+
// sort is important
|
|
67
61
|
for (const file of files.sort()) {
|
|
68
62
|
hashObject[file] = md5(FileSystem.readFile(file));
|
|
69
63
|
}
|
|
70
|
-
|
|
71
64
|
return hashObject;
|
|
72
65
|
};
|
|
73
|
-
|
|
74
66
|
export const checkProjectChangeByContent = async project => {
|
|
75
67
|
const projectDir = project.extra.path;
|
|
76
68
|
const projectMemoryFolder = path.resolve(projectDir, '.project-memory');
|
|
77
69
|
const projectJsonFile = path.join(projectMemoryFolder, PROJECT_CONTENT_FILE_NAME);
|
|
78
70
|
const currentHashObject = await getProjectContentHashObjectForFiles(project);
|
|
79
71
|
const currentHashString = JsonFile.stringify(currentHashObject);
|
|
80
|
-
|
|
81
72
|
if (!FileSystem.exists(projectJsonFile)) {
|
|
82
73
|
FileSystem.writeFile(projectJsonFile, currentHashString, {
|
|
83
74
|
ensureFolderExists: true
|
|
84
75
|
});
|
|
85
76
|
return true;
|
|
86
77
|
}
|
|
87
|
-
|
|
88
78
|
const localHashObject = JsonFile.load(projectJsonFile);
|
|
89
79
|
const changed = JsonFile.stringify(localHashObject) !== currentHashString;
|
|
90
|
-
|
|
91
80
|
if (changed) {
|
|
92
81
|
FileSystem.writeFile(projectJsonFile, currentHashString, {
|
|
93
82
|
ensureFolderExists: true
|
|
94
83
|
});
|
|
95
84
|
}
|
|
96
|
-
|
|
97
85
|
return changed;
|
|
98
86
|
};
|
|
@@ -1,18 +1,13 @@
|
|
|
1
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
|
-
|
|
3
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; }
|
|
4
|
-
|
|
5
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; }
|
|
6
|
-
|
|
7
4
|
import * as path from 'path';
|
|
8
5
|
import { PackageJsonLookup } from '@rushstack/node-core-library';
|
|
9
6
|
import { globby } from '@modern-js/utils';
|
|
10
7
|
import pMap from 'p-map';
|
|
11
8
|
import { errorLog } from "../log/error";
|
|
12
9
|
import { Package } from "../package";
|
|
13
|
-
|
|
14
10
|
const normalize = results => results.map(fp => path.normalize(fp));
|
|
15
|
-
|
|
16
11
|
const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
|
|
17
12
|
const globOpts = {
|
|
18
13
|
cwd: rootPath,
|
|
@@ -20,45 +15,41 @@ const getGlobOpts = (rootPath, packageConfigs, ignore = []) => {
|
|
|
20
15
|
expandDirectories: false,
|
|
21
16
|
followSymbolicLinks: false
|
|
22
17
|
};
|
|
23
|
-
|
|
24
18
|
if (packageConfigs.some(cfg => cfg.includes('**'))) {
|
|
25
19
|
if (packageConfigs.some(cfg => cfg.includes('node_modules'))) {
|
|
26
20
|
errorLog('An explicit node_modules package path does not allow globstars (**)');
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
globOpts.ignore = [
|
|
23
|
+
// allow globs like "packages/**",
|
|
30
24
|
// but avoid picking up node_modules/**/package.json and dist/**/package.json
|
|
31
25
|
'**/dist/**', '**/node_modules/**', ...(ignore || [])];
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
return globOpts;
|
|
35
28
|
};
|
|
36
|
-
|
|
37
29
|
const makeFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
|
|
38
30
|
const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
|
|
39
31
|
return async (fileName, fileMapper, customGlobOpts = {}) => {
|
|
40
32
|
const options = _objectSpread(_objectSpread({}, customGlobOpts), globOpts);
|
|
41
|
-
|
|
42
33
|
const promise = pMap(Array.from(packageConfigs).sort(), async globPath => {
|
|
43
|
-
let result = await globby(path.posix.join(globPath, fileName), options);
|
|
44
|
-
|
|
45
|
-
result = result.sort(); // POSIX results always need to be normalized
|
|
34
|
+
let result = await globby(path.posix.join(globPath, fileName), options);
|
|
46
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
|
|
47
39
|
result = normalize(result);
|
|
48
40
|
return fileMapper(result);
|
|
49
41
|
}, {
|
|
50
42
|
concurrency: packageConfigs.length || Infinity
|
|
51
|
-
});
|
|
43
|
+
});
|
|
52
44
|
|
|
45
|
+
// always flatten the results
|
|
53
46
|
const results = await promise;
|
|
54
47
|
return results.reduce((acc, result) => acc.concat(result), []);
|
|
55
48
|
};
|
|
56
49
|
};
|
|
57
|
-
|
|
58
50
|
export const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignoreConfigs) => {
|
|
59
51
|
const finder = makeFileFinder(rootPath, packagesConfig, ignoreConfigs);
|
|
60
52
|
const fileName = 'package.json';
|
|
61
|
-
|
|
62
53
|
const mapper = packageConfigPath => {
|
|
63
54
|
const packageJsonLookup = new PackageJsonLookup({
|
|
64
55
|
loadExtraFields: true
|
|
@@ -66,37 +57,30 @@ export const getProjectsByPackageConfig = async (rootPath, packagesConfig, ignor
|
|
|
66
57
|
const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
|
|
67
58
|
return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
|
|
68
59
|
};
|
|
69
|
-
|
|
70
60
|
const projects = await finder(fileName, filePaths => pMap(filePaths, mapper, {
|
|
71
61
|
concurrency: filePaths.length || Infinity
|
|
72
62
|
}), {});
|
|
73
63
|
return projects;
|
|
74
64
|
};
|
|
75
|
-
|
|
76
65
|
const makeSyncFileFinder = (rootPath, packageConfigs, ignoreConfigs = []) => {
|
|
77
66
|
const globOpts = getGlobOpts(rootPath, packageConfigs, ignoreConfigs);
|
|
78
67
|
return (fileName, fileMapper, customGlobOpts = {}) => {
|
|
79
68
|
const results = [];
|
|
80
|
-
|
|
81
69
|
const options = _objectSpread(_objectSpread({}, customGlobOpts), globOpts);
|
|
82
|
-
|
|
83
70
|
for (const globPath of Array.from(packageConfigs).sort()) {
|
|
84
|
-
let result = globby.sync(path.posix.join(globPath, fileName), options);
|
|
85
|
-
|
|
86
|
-
result = result.sort();
|
|
87
|
-
|
|
71
|
+
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
|
+
result = result.sort();
|
|
74
|
+
// POSIX results always need to be normalized
|
|
88
75
|
result = normalize(result);
|
|
89
76
|
results.push(fileMapper(result));
|
|
90
77
|
}
|
|
91
|
-
|
|
92
78
|
return results.reduce((acc, result) => acc.concat(result), []);
|
|
93
79
|
};
|
|
94
80
|
};
|
|
95
|
-
|
|
96
81
|
export const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreConfigs) => {
|
|
97
82
|
const finder = makeSyncFileFinder(rootPath, packagesConfig, ignoreConfigs);
|
|
98
83
|
const fileName = 'package.json';
|
|
99
|
-
|
|
100
84
|
const mapper = packageConfigPath => {
|
|
101
85
|
const packageJsonLookup = new PackageJsonLookup({
|
|
102
86
|
loadExtraFields: true
|
|
@@ -104,7 +88,6 @@ export const syncGetProjectsByPackageConfig = (rootPath, packagesConfig, ignoreC
|
|
|
104
88
|
const packageJson = packageJsonLookup.loadNodePackageJson(packageConfigPath);
|
|
105
89
|
return new Package(packageJson, path.dirname(packageConfigPath), rootPath);
|
|
106
90
|
};
|
|
107
|
-
|
|
108
91
|
const projects = finder(fileName, filePaths => filePaths.map(filePath => mapper(filePath)), {});
|
|
109
92
|
return projects;
|
|
110
93
|
};
|
|
@@ -6,73 +6,57 @@ import { WORKSPACE_FILE } from "../constants";
|
|
|
6
6
|
import { getProjectsByPackageConfig, syncGetProjectsByPackageConfig } from "./get-projects-by-packages-config";
|
|
7
7
|
export const getProjectsByWorkspaceFile = async (rootPath, config, ignoreConfigs) => {
|
|
8
8
|
var _config$workspaceFile;
|
|
9
|
-
|
|
10
9
|
let {
|
|
11
10
|
workspaceFile
|
|
12
11
|
} = config;
|
|
13
|
-
|
|
14
12
|
if (!config.enableAutoFinder && (!('workspaceFile' in config) || ((_config$workspaceFile = config.workspaceFile) === null || _config$workspaceFile === void 0 ? void 0 : _config$workspaceFile.length) === 0)) {
|
|
15
13
|
throw new Error('Missing workspaceFile Key or workspaceFile is empty string');
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
if (config.enableAutoFinder) {
|
|
19
16
|
workspaceFile = getWorkspaceFile(rootPath);
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
let packagesConfig = [];
|
|
23
|
-
|
|
24
19
|
if (workspaceFile === WORKSPACE_FILE.PNPM) {
|
|
25
20
|
const yamlString = await FileSystem.readFileAsync(path.resolve('/', rootPath, workspaceFile)).then(data => data.toString());
|
|
26
21
|
const pnpmWorkspace = yaml.load(yamlString);
|
|
27
22
|
packagesConfig = pnpmWorkspace.packages || [];
|
|
28
23
|
} else if (workspaceFile === WORKSPACE_FILE.YARN) {
|
|
29
24
|
var _pkgJson$workspaces;
|
|
30
|
-
|
|
31
25
|
const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
|
|
32
26
|
packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces = pkgJson.workspaces) === null || _pkgJson$workspaces === void 0 ? void 0 : _pkgJson$workspaces.packages) || [];
|
|
33
27
|
} else if (workspaceFile === WORKSPACE_FILE.LERNA) {
|
|
34
28
|
var _lernaJson$packages;
|
|
35
|
-
|
|
36
29
|
const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
|
|
37
30
|
packagesConfig = (_lernaJson$packages = lernaJson.packages) !== null && _lernaJson$packages !== void 0 ? _lernaJson$packages : [];
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
const projects = await getProjectsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
|
|
41
33
|
return projects;
|
|
42
34
|
};
|
|
43
35
|
export const syncGetProjectsByWorkspaceFile = (rootPath, config, ignoreConfigs) => {
|
|
44
36
|
var _config$workspaceFile2;
|
|
45
|
-
|
|
46
37
|
let {
|
|
47
38
|
workspaceFile
|
|
48
39
|
} = config;
|
|
49
|
-
|
|
50
40
|
if (!config.enableAutoFinder && (!('workspaceFile' in config) || ((_config$workspaceFile2 = config.workspaceFile) === null || _config$workspaceFile2 === void 0 ? void 0 : _config$workspaceFile2.length) === 0)) {
|
|
51
41
|
throw new Error('Missing workspaceFile Key or workspaceFile is empty string');
|
|
52
42
|
}
|
|
53
|
-
|
|
54
43
|
if (config.enableAutoFinder) {
|
|
55
44
|
workspaceFile = getWorkspaceFile(rootPath);
|
|
56
45
|
}
|
|
57
|
-
|
|
58
46
|
let packagesConfig = [];
|
|
59
|
-
|
|
60
47
|
if (workspaceFile === WORKSPACE_FILE.PNPM) {
|
|
61
48
|
const yamlString = fs.readFileSync(path.resolve('/', rootPath, workspaceFile), 'utf-8');
|
|
62
49
|
const pnpmWorkspace = yaml.load(yamlString);
|
|
63
50
|
packagesConfig = pnpmWorkspace.packages || [];
|
|
64
51
|
} else if (workspaceFile === WORKSPACE_FILE.YARN) {
|
|
65
52
|
var _pkgJson$workspaces2;
|
|
66
|
-
|
|
67
53
|
const pkgJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
|
|
68
54
|
packagesConfig = (pkgJson === null || pkgJson === void 0 ? void 0 : (_pkgJson$workspaces2 = pkgJson.workspaces) === null || _pkgJson$workspaces2 === void 0 ? void 0 : _pkgJson$workspaces2.packages) || [];
|
|
69
55
|
} else if (workspaceFile === WORKSPACE_FILE.LERNA) {
|
|
70
56
|
var _lernaJson$packages2;
|
|
71
|
-
|
|
72
57
|
const lernaJson = JsonFile.load(path.resolve(rootPath, workspaceFile));
|
|
73
58
|
packagesConfig = (_lernaJson$packages2 = lernaJson.packages) !== null && _lernaJson$packages2 !== void 0 ? _lernaJson$packages2 : [];
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
const projects = syncGetProjectsByPackageConfig(rootPath, packagesConfig, ignoreConfigs);
|
|
77
61
|
return projects;
|
|
78
62
|
};
|