@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
|
@@ -4,37 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deploy = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _nodeCoreLibrary = require("@rushstack/node-core-library");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
var _constants = require("../../constants");
|
|
15
|
-
|
|
16
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); }
|
|
17
|
-
|
|
18
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; }
|
|
19
|
-
|
|
20
13
|
const createCopyMap = (rootPath, targetProject, copyProjects, deployDir) => {
|
|
21
14
|
const map = new Map();
|
|
22
|
-
|
|
23
15
|
for (const project of copyProjects) {
|
|
24
16
|
const relativePath = path.relative(rootPath, project.extra.path);
|
|
25
17
|
const targetPath = path.join(deployDir, relativePath);
|
|
26
18
|
map.set(project.extra.path, targetPath);
|
|
27
19
|
}
|
|
28
|
-
|
|
29
20
|
const targetProjectDeployPath = path.join(deployDir, 'apps/app');
|
|
30
21
|
map.set(targetProject.extra.path, targetProjectDeployPath);
|
|
31
22
|
return map;
|
|
32
23
|
};
|
|
33
|
-
|
|
34
24
|
const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename => {
|
|
35
25
|
const sourcePath = path.join(monorepoDir, filename);
|
|
36
26
|
const destinationPath = path.join(deployDir, filename);
|
|
37
|
-
|
|
38
27
|
if (_nodeCoreLibrary.FileSystem.exists(sourcePath)) {
|
|
39
28
|
_nodeCoreLibrary.FileSystem.copyFile({
|
|
40
29
|
sourcePath,
|
|
@@ -42,32 +31,23 @@ const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename
|
|
|
42
31
|
});
|
|
43
32
|
}
|
|
44
33
|
};
|
|
45
|
-
|
|
46
34
|
const checkAndUpdatePMWorkspaces = deployDir => {
|
|
47
35
|
var _pkg$workspaces;
|
|
48
|
-
|
|
49
36
|
// pnpm-workspace
|
|
50
37
|
const pnpmWp = path.join(deployDir, _constants.WORKSPACE_FILE.PNPM);
|
|
51
|
-
|
|
52
38
|
if (_utils.fs.existsSync(pnpmWp)) {
|
|
53
39
|
const pnpmWorkspace = _utils.yaml.load(_utils.fs.readFileSync(pnpmWp, 'utf-8'));
|
|
54
|
-
|
|
55
40
|
if (pnpmWorkspace.packages && Array.isArray(pnpmWorkspace.packages)) {
|
|
56
41
|
pnpmWorkspace.packages.push('apps/**');
|
|
57
42
|
}
|
|
58
|
-
|
|
59
43
|
_utils.fs.writeFileSync(pnpmWp, _utils.yaml.dump(pnpmWorkspace));
|
|
60
44
|
}
|
|
61
|
-
|
|
62
45
|
const pkgPath = path.join(deployDir, _constants.WORKSPACE_FILE.YARN);
|
|
63
|
-
|
|
64
46
|
const pkg = _nodeCoreLibrary.JsonFile.load(pkgPath);
|
|
65
|
-
|
|
66
47
|
if ((_pkg$workspaces = pkg.workspaces) !== null && _pkg$workspaces !== void 0 && _pkg$workspaces.packages && Array.isArray(pkg.workspaces.packages)) {
|
|
67
48
|
pkg.workspaces.packages.push('app/**');
|
|
68
49
|
}
|
|
69
50
|
};
|
|
70
|
-
|
|
71
51
|
const generatorAndCopyRequiredFiles = (rootPath, deployDir) => {
|
|
72
52
|
// copy .npmrc
|
|
73
53
|
const copy = createCopyFromMonorepoToDeployDirFn(rootPath, deployDir);
|
|
@@ -79,30 +59,23 @@ const generatorAndCopyRequiredFiles = (rootPath, deployDir) => {
|
|
|
79
59
|
copy('tsconfig.json');
|
|
80
60
|
copy('modern.config.js'); // TODO: 暂时配置,要移除
|
|
81
61
|
// lock file
|
|
82
|
-
|
|
83
62
|
copy('pnpm-lock.yaml');
|
|
84
63
|
copy('yarn.lock');
|
|
85
|
-
copy('package-lock.json');
|
|
86
|
-
// because we deploy project to 'apps' dir
|
|
64
|
+
copy('package-lock.json');
|
|
87
65
|
|
|
66
|
+
// check workspaces config and add 'apps/**',
|
|
67
|
+
// because we deploy project to 'apps' dir
|
|
88
68
|
checkAndUpdatePMWorkspaces(deployDir);
|
|
89
69
|
};
|
|
90
|
-
|
|
91
70
|
const checkAndRunDeployCommand = async (monorepoPath, targetProject, packageManager) => {
|
|
92
71
|
var _targetProject$extra;
|
|
93
|
-
|
|
94
72
|
const scripts = ((_targetProject$extra = targetProject.extra) === null || _targetProject$extra === void 0 ? void 0 : _targetProject$extra.scripts) || {};
|
|
95
|
-
|
|
96
73
|
if (scripts.deploy) {
|
|
97
74
|
var _childProcess$stdout, _childProcess$stderr;
|
|
98
|
-
|
|
99
75
|
_utils.logger.info(`The 'deploy' command for the ${targetProject.name} is detected, so 'deploy' will be executed`);
|
|
100
|
-
|
|
101
76
|
let runDeployCommands = ['run', 'deploy'];
|
|
102
|
-
|
|
103
77
|
if (packageManager === 'pnpm') {
|
|
104
78
|
const pnpmVersion = await (0, _utils.getPnpmVersion)();
|
|
105
|
-
|
|
106
79
|
if (pnpmVersion.startsWith('6')) {
|
|
107
80
|
runDeployCommands = ['run', 'deploy', '--filter', targetProject.name];
|
|
108
81
|
} else {
|
|
@@ -111,7 +84,6 @@ const checkAndRunDeployCommand = async (monorepoPath, targetProject, packageMana
|
|
|
111
84
|
} else if (packageManager === 'yarn') {
|
|
112
85
|
runDeployCommands = ['workspace', targetProject.name, 'run', 'deploy'];
|
|
113
86
|
}
|
|
114
|
-
|
|
115
87
|
const cwd = packageManager === 'npm' ? targetProject.extra.path : monorepoPath;
|
|
116
88
|
const childProcess = (0, _utils.execa)(packageManager, runDeployCommands, {
|
|
117
89
|
cwd,
|
|
@@ -121,30 +93,23 @@ const checkAndRunDeployCommand = async (monorepoPath, targetProject, packageMana
|
|
|
121
93
|
(_childProcess$stderr = childProcess.stderr) === null || _childProcess$stderr === void 0 ? void 0 : _childProcess$stderr.pipe(process.stderr);
|
|
122
94
|
await childProcess;
|
|
123
95
|
}
|
|
124
|
-
};
|
|
125
|
-
|
|
96
|
+
};
|
|
126
97
|
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
127
99
|
const installDependency = async (deployDir, packageManager) => {
|
|
128
100
|
// TODO: 使用公共方法替换
|
|
129
101
|
const packageJsonPath = path.join(deployDir, 'package.json');
|
|
130
|
-
|
|
131
102
|
const packageJson = _nodeCoreLibrary.JsonFile.load(packageJsonPath);
|
|
132
|
-
|
|
133
103
|
const scripts = (packageJson === null || packageJson === void 0 ? void 0 : packageJson.scripts) || {};
|
|
134
104
|
let commands = [];
|
|
135
|
-
|
|
136
105
|
if (scripts.setup) {
|
|
137
106
|
_utils.logger.info(`The 'setup' command is detected, execute '${packageManager} run setup' to start installing the dependencies`);
|
|
138
|
-
|
|
139
107
|
commands = ['run', 'setup'];
|
|
140
108
|
} else {
|
|
141
109
|
_utils.logger.info(`No 'setup' command detected, execute '${packageManager} install' to start installing dependencies`);
|
|
142
|
-
|
|
143
110
|
commands = ['install'];
|
|
144
111
|
}
|
|
145
|
-
|
|
146
112
|
_utils.logger.log(_utils.chalk.rgb(218, 152, 92)('Install Log:\n'));
|
|
147
|
-
|
|
148
113
|
const childProcess = (0, _utils.execa)(packageManager, commands, {
|
|
149
114
|
stdio: 'inherit',
|
|
150
115
|
cwd: deployDir,
|
|
@@ -154,11 +119,8 @@ const installDependency = async (deployDir, packageManager) => {
|
|
|
154
119
|
});
|
|
155
120
|
await childProcess;
|
|
156
121
|
};
|
|
157
|
-
|
|
158
122
|
const excludeDirs = (filePath, dirs) => dirs.some(dir => filePath.includes(dir));
|
|
159
|
-
|
|
160
123
|
const defaultDeployPath = 'output';
|
|
161
|
-
|
|
162
124
|
const deploy = async (deployProjectNames, operator, config) => {
|
|
163
125
|
const {
|
|
164
126
|
rootPath,
|
|
@@ -166,10 +128,8 @@ const deploy = async (deployProjectNames, operator, config) => {
|
|
|
166
128
|
deployPath = defaultDeployPath
|
|
167
129
|
} = config;
|
|
168
130
|
const realDeployPath = path.isAbsolute(deployPath) ? deployPath : path.join(rootPath, deployPath);
|
|
169
|
-
|
|
170
131
|
_nodeCoreLibrary.FileSystem.deleteFolder(realDeployPath); // 保证 realDeployPath 目录内为空
|
|
171
132
|
|
|
172
|
-
|
|
173
133
|
for (const deployProjectName of deployProjectNames) {
|
|
174
134
|
const currentProject = operator.getNodeData(deployProjectName, {
|
|
175
135
|
checkExist: true
|
|
@@ -177,9 +137,7 @@ const deploy = async (deployProjectNames, operator, config) => {
|
|
|
177
137
|
const alldeps = operator.getNodeAllDependencyData(deployProjectName);
|
|
178
138
|
const copyMap = createCopyMap(rootPath, currentProject, alldeps, realDeployPath);
|
|
179
139
|
await checkAndRunDeployCommand(rootPath, currentProject, packageManager);
|
|
180
|
-
|
|
181
140
|
_nodeCoreLibrary.FileSystem.ensureFolder(realDeployPath);
|
|
182
|
-
|
|
183
141
|
for (const [from, to] of copyMap) {
|
|
184
142
|
// https://rushstack.io/pages/api/node-core-library.ifilesystemcopyfilesasyncoptions/
|
|
185
143
|
_nodeCoreLibrary.FileSystem.copyFiles({
|
|
@@ -187,22 +145,18 @@ const deploy = async (deployProjectNames, operator, config) => {
|
|
|
187
145
|
destinationPath: to,
|
|
188
146
|
// If true, then when copying symlinks, copy the target object instead of copying the link.
|
|
189
147
|
dereferenceSymlinks: false,
|
|
190
|
-
|
|
191
148
|
filter(filePath) {
|
|
192
149
|
if (excludeDirs(filePath, ['node_modules', 'dist'])) {
|
|
193
150
|
return false;
|
|
194
151
|
}
|
|
195
|
-
|
|
196
152
|
return true;
|
|
197
153
|
}
|
|
198
|
-
|
|
199
154
|
});
|
|
200
155
|
}
|
|
201
156
|
}
|
|
202
|
-
|
|
203
|
-
|
|
157
|
+
generatorAndCopyRequiredFiles(rootPath, realDeployPath);
|
|
158
|
+
// await installDependency(realDeployPath, packageManager);
|
|
204
159
|
|
|
205
160
|
_utils.logger.success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
|
|
206
161
|
};
|
|
207
|
-
|
|
208
162
|
exports.deploy = deploy;
|
|
@@ -4,25 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createDevTask = exports.createDependenciesTask = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
var _error = require("../../log/error");
|
|
11
|
-
|
|
12
9
|
var timeLog = _interopRequireWildcard(require("../../log/time"));
|
|
13
|
-
|
|
14
10
|
var _cmds = require("./cmds");
|
|
15
|
-
|
|
16
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); }
|
|
17
|
-
|
|
18
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; }
|
|
19
|
-
|
|
20
13
|
const getFinalTaskCmds = (taskCmds, project) => {
|
|
21
|
-
let finalTaskCmds = [];
|
|
14
|
+
let finalTaskCmds = [];
|
|
15
|
+
// case1: ["build"]
|
|
22
16
|
// case2: ["dev", "build"]
|
|
23
17
|
// case3: ["dev", () => []]
|
|
24
18
|
// default: ['dev', 'build']
|
|
25
|
-
|
|
26
19
|
if (taskCmds.length === 1) {
|
|
27
20
|
finalTaskCmds = [taskCmds[0]];
|
|
28
21
|
} else if (taskCmds.length === 2 && typeof taskCmds[0] === 'string' && typeof taskCmds[1] === 'string') {
|
|
@@ -33,25 +26,20 @@ const getFinalTaskCmds = (taskCmds, project) => {
|
|
|
33
26
|
// 如果以上为满足,则默认使用build
|
|
34
27
|
finalTaskCmds = ['build'];
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
return finalTaskCmds;
|
|
38
30
|
};
|
|
39
|
-
|
|
40
31
|
const createDependenciesTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogger) => {
|
|
41
32
|
const {
|
|
42
33
|
packageManager
|
|
43
34
|
} = config;
|
|
44
35
|
const timelogInstance = timeLog.initTimeLog();
|
|
45
|
-
|
|
46
36
|
const task = async project => {
|
|
47
37
|
const finalTaskCmds = getFinalTaskCmds(taskCmds, project);
|
|
48
38
|
const cmd = project.extra.scripts || {};
|
|
49
|
-
|
|
50
39
|
for (const taskCmd of finalTaskCmds) {
|
|
51
40
|
if (cmd[taskCmd]) {
|
|
52
41
|
const prefix = `run ${project.name} ${taskCmd} script`;
|
|
53
42
|
timeLog.startTime(timelogInstance, prefix);
|
|
54
|
-
|
|
55
43
|
try {
|
|
56
44
|
const childProcess = (0, _utils.execa)(packageManager, [taskCmd], {
|
|
57
45
|
cwd: project.extra.path,
|
|
@@ -68,28 +56,22 @@ const createDependenciesTask = (config, taskCmds = _cmds.defaultBuildWatchCmds,
|
|
|
68
56
|
} catch (e) {
|
|
69
57
|
(0, _error.errorLog)(project.name, e);
|
|
70
58
|
}
|
|
71
|
-
|
|
72
59
|
timeLog.endTime(timelogInstance, prefix);
|
|
73
60
|
} else {
|
|
74
61
|
_utils.logger.info(`${project.name} not have ${taskCmd}, skip it.`);
|
|
75
62
|
}
|
|
76
63
|
}
|
|
77
64
|
};
|
|
78
|
-
|
|
79
65
|
return task;
|
|
80
66
|
};
|
|
81
|
-
|
|
82
67
|
exports.createDependenciesTask = createDependenciesTask;
|
|
83
|
-
|
|
84
68
|
const createDevTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogger) => {
|
|
85
69
|
const {
|
|
86
70
|
packageManager
|
|
87
71
|
} = config;
|
|
88
|
-
|
|
89
72
|
const task = async project => {
|
|
90
73
|
const devCmds = [taskCmds[0]];
|
|
91
74
|
const cmd = project.extra.scripts || {};
|
|
92
|
-
|
|
93
75
|
for (const taskCmd of devCmds) {
|
|
94
76
|
if (cmd[taskCmd]) {
|
|
95
77
|
// const prefix = `run ${project.name} ${taskCmd} script`;
|
|
@@ -117,8 +99,6 @@ const createDevTask = (config, taskCmds = _cmds.defaultBuildWatchCmds, taskLogge
|
|
|
117
99
|
}
|
|
118
100
|
}
|
|
119
101
|
};
|
|
120
|
-
|
|
121
102
|
return task;
|
|
122
103
|
};
|
|
123
|
-
|
|
124
104
|
exports.createDevTask = createDevTask;
|
|
@@ -4,36 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.runBuildWatchTask = void 0;
|
|
7
|
-
|
|
8
7
|
var _anymatch = _interopRequireDefault(require("anymatch"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _multiTasksLog = require("../../log/multi-tasks-log");
|
|
13
|
-
|
|
14
10
|
var _watchProjectsState = require("./watch-projects-state");
|
|
15
|
-
|
|
16
11
|
var _cmds = require("./cmds");
|
|
17
|
-
|
|
18
12
|
var _createTask = require("./create-task");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
const getIgnored = config => watchFilePath => {
|
|
23
15
|
// 默认忽略 node_modules 的变化和 dist 目录下文件的变化
|
|
24
16
|
const nodeModulesPattern = /(?:^|[\\/])node_modules/g;
|
|
25
|
-
|
|
26
17
|
if (nodeModulesPattern.test(watchFilePath) || watchFilePath.includes('dist')) {
|
|
27
18
|
return true;
|
|
28
19
|
}
|
|
29
|
-
|
|
30
20
|
if (config.ignoreMaybeChanged) {
|
|
31
21
|
return (0, _anymatch.default)(config.ignoreMaybeChanged)(watchFilePath);
|
|
32
22
|
}
|
|
33
|
-
|
|
34
23
|
return false;
|
|
35
24
|
};
|
|
36
|
-
|
|
37
25
|
const runBuildWatchTask = async (projectName, operator, config, taskCmds = _cmds.defaultBuildWatchCmds) => {
|
|
38
26
|
const {
|
|
39
27
|
needInit = true
|
|
@@ -52,14 +40,14 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = _cmds
|
|
|
52
40
|
disableGlobbing: true,
|
|
53
41
|
interval: 1000
|
|
54
42
|
});
|
|
55
|
-
watcher.add(watchedProjectState.getWatchedProjectsPath());
|
|
43
|
+
watcher.add(watchedProjectState.getWatchedProjectsPath());
|
|
56
44
|
|
|
45
|
+
// 可能会移除该判断和 neeInit 配置
|
|
57
46
|
if (needInit) {
|
|
58
47
|
await operator.traverseDependenciesToProject(projectName, async currentProject => {
|
|
59
48
|
await dependenciesTask(currentProject);
|
|
60
49
|
});
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
await new Promise(resolve => {
|
|
64
52
|
console.info('start watch');
|
|
65
53
|
watcher.on('all', async (eventName, changeFilePath) => {
|
|
@@ -67,9 +55,7 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = _cmds
|
|
|
67
55
|
if (eventName === 'add') {
|
|
68
56
|
watchedProjectState.updateState();
|
|
69
57
|
}
|
|
70
|
-
|
|
71
58
|
const changedProject = watchedProjectState.getChangedProject(changeFilePath);
|
|
72
|
-
|
|
73
59
|
if (changedProject) {
|
|
74
60
|
await operator.traverseProjectToDependent(changedProject.name, async (currentProject, _, earlyFinish) => {
|
|
75
61
|
// 调试的项目跳过
|
|
@@ -77,7 +63,6 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = _cmds
|
|
|
77
63
|
earlyFinish();
|
|
78
64
|
return;
|
|
79
65
|
}
|
|
80
|
-
|
|
81
66
|
if (watchedProjectState.watchProjectsName.includes(currentProject.name)) {
|
|
82
67
|
console.info('run build', currentProject.name);
|
|
83
68
|
await dependenciesTask(currentProject);
|
|
@@ -91,11 +76,11 @@ const runBuildWatchTask = async (projectName, operator, config, taskCmds = _cmds
|
|
|
91
76
|
}
|
|
92
77
|
});
|
|
93
78
|
resolve(null);
|
|
94
|
-
});
|
|
79
|
+
});
|
|
95
80
|
|
|
81
|
+
// 执行目标项目的 dev 任务
|
|
96
82
|
await devTask(operator.getNodeData(projectName, {
|
|
97
83
|
checkExist: true
|
|
98
84
|
}));
|
|
99
85
|
};
|
|
100
|
-
|
|
101
86
|
exports.runBuildWatchTask = runBuildWatchTask;
|
|
@@ -4,39 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.WatchedProjectsState = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
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); }
|
|
13
|
-
|
|
14
10
|
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; }
|
|
15
|
-
|
|
16
11
|
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; }
|
|
17
|
-
|
|
18
12
|
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; }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
class WatchedProjectsState {
|
|
23
15
|
constructor(fromNodes, config) {
|
|
24
16
|
_defineProperty(this, "_config", void 0);
|
|
25
|
-
|
|
26
17
|
_defineProperty(this, "_fromNodes", void 0);
|
|
27
|
-
|
|
28
18
|
_defineProperty(this, "_watchProjects", void 0);
|
|
29
|
-
|
|
30
19
|
_defineProperty(this, "_projectsFileMap", void 0);
|
|
31
|
-
|
|
32
20
|
this._fromNodes = fromNodes;
|
|
33
21
|
this._config = config;
|
|
34
22
|
this._projectsFileMap = new Map();
|
|
35
23
|
this._watchProjects = {};
|
|
36
|
-
|
|
37
24
|
this._initState();
|
|
38
25
|
}
|
|
39
|
-
|
|
40
26
|
_initState() {
|
|
41
27
|
const globOption = {
|
|
42
28
|
cwd: this._config.rootPath,
|
|
@@ -47,43 +33,32 @@ class WatchedProjectsState {
|
|
|
47
33
|
};
|
|
48
34
|
this._watchProjects = this._fromNodes.reduce((ret, node) => {
|
|
49
35
|
const files = _utils.globby.sync(`${node.extra.path}/**`, globOption);
|
|
50
|
-
|
|
51
36
|
for (const filePath of files) {
|
|
52
37
|
this._projectsFileMap.set(path.relative(this._config.rootPath, filePath), node.extra.path);
|
|
53
38
|
}
|
|
54
|
-
|
|
55
39
|
return _objectSpread(_objectSpread({}, ret), {}, {
|
|
56
40
|
[node.extra.path]: node
|
|
57
41
|
});
|
|
58
42
|
}, {});
|
|
59
43
|
}
|
|
60
|
-
|
|
61
44
|
getChangedProject(changedFilPath) {
|
|
62
45
|
if (this._projectsFileMap.has(changedFilPath)) {
|
|
63
46
|
const projectPath = this._projectsFileMap.get(changedFilPath);
|
|
64
|
-
|
|
65
47
|
return this._watchProjects[projectPath];
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
return undefined;
|
|
69
50
|
}
|
|
70
|
-
|
|
71
51
|
getWatchedProjectsPath() {
|
|
72
52
|
return Object.keys(this._watchProjects);
|
|
73
53
|
}
|
|
74
|
-
|
|
75
54
|
updateState() {
|
|
76
55
|
this._initState();
|
|
77
56
|
}
|
|
78
|
-
|
|
79
57
|
get watchProjects() {
|
|
80
58
|
return this._watchProjects;
|
|
81
59
|
}
|
|
82
|
-
|
|
83
60
|
get watchProjectsName() {
|
|
84
61
|
return Object.keys(this._watchProjects).map(projectPath => this._watchProjects[projectPath].name);
|
|
85
62
|
}
|
|
86
|
-
|
|
87
63
|
}
|
|
88
|
-
|
|
89
64
|
exports.WatchedProjectsState = WatchedProjectsState;
|
|
@@ -4,81 +4,58 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.runInstallTask = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _nodeCoreLibrary = require("@rushstack/node-core-library");
|
|
13
|
-
|
|
14
10
|
var _constants = require("../../constants");
|
|
15
|
-
|
|
16
11
|
var _install = require("../../utils/install");
|
|
17
|
-
|
|
18
12
|
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); }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
const replaceWorkspaces = ({
|
|
23
15
|
rootPath,
|
|
24
16
|
projectsInWorkspaces
|
|
25
17
|
}) => {
|
|
26
18
|
// pnpm
|
|
27
19
|
const pnpmWsFilePath = path.join(rootPath, _constants.WORKSPACE_FILE.PNPM);
|
|
28
|
-
|
|
29
20
|
if (_utils.fs.existsSync(pnpmWsFilePath)) {
|
|
30
21
|
const pnpmWorkspace = _utils.fs.readFileSync(pnpmWsFilePath, 'utf-8');
|
|
31
|
-
|
|
32
22
|
const originalPnpmWorkspaces = _utils.yaml.load(pnpmWorkspace);
|
|
33
|
-
|
|
34
23
|
_utils.fs.writeFileSync(pnpmWsFilePath, _utils.yaml.dump({
|
|
35
24
|
packages: projectsInWorkspaces
|
|
36
25
|
}));
|
|
37
|
-
|
|
38
26
|
return () => {
|
|
39
27
|
_utils.yaml.dump(originalPnpmWorkspaces);
|
|
40
28
|
};
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
const pkgFilePath = path.join(rootPath, _constants.WORKSPACE_FILE.YARN);
|
|
44
|
-
|
|
45
31
|
if (_utils.fs.existsSync(pkgFilePath)) {
|
|
46
32
|
var _pkg$workspaces;
|
|
47
|
-
|
|
48
33
|
const pkg = _nodeCoreLibrary.JsonFile.load(pkgFilePath);
|
|
49
|
-
|
|
50
34
|
if (pkg !== null && pkg !== void 0 && (_pkg$workspaces = pkg.workspaces) !== null && _pkg$workspaces !== void 0 && _pkg$workspaces.packages) {
|
|
51
35
|
const originalPkg = pkg;
|
|
52
36
|
pkg.workspaces.packages = projectsInWorkspaces;
|
|
53
|
-
|
|
54
37
|
_nodeCoreLibrary.JsonFile.save(pkg, pkgFilePath);
|
|
55
|
-
|
|
56
38
|
return () => {
|
|
57
39
|
_nodeCoreLibrary.JsonFile.save(originalPkg, pkgFilePath);
|
|
58
40
|
};
|
|
59
41
|
}
|
|
60
42
|
}
|
|
61
|
-
|
|
62
43
|
return false;
|
|
63
44
|
};
|
|
64
|
-
|
|
65
45
|
const runInstallTask = async (projectNames, operator, config) => {
|
|
66
46
|
const {
|
|
67
47
|
rootPath,
|
|
68
48
|
packageManager
|
|
69
49
|
} = config;
|
|
70
50
|
let projectsInWorkspaces = [];
|
|
71
|
-
|
|
72
51
|
if (projectNames.length === 0) {
|
|
73
52
|
console.info('install all projects');
|
|
74
53
|
return;
|
|
75
54
|
}
|
|
76
|
-
|
|
77
55
|
for (const projectName of projectNames) {
|
|
78
56
|
const allDeps = operator.getNodeAllDependencyData(projectName);
|
|
79
57
|
projectsInWorkspaces = [...projectsInWorkspaces, path.relative(rootPath, operator.getNodeData(projectName).extra.path), ...allDeps.map(p => path.relative(rootPath, p.extra.path))];
|
|
80
58
|
}
|
|
81
|
-
|
|
82
59
|
const noDupProjectList = Array.from(new Set(projectsInWorkspaces));
|
|
83
60
|
const restorWorkspace = replaceWorkspaces({
|
|
84
61
|
rootPath,
|
|
@@ -88,10 +65,8 @@ const runInstallTask = async (projectNames, operator, config) => {
|
|
|
88
65
|
rootPath,
|
|
89
66
|
removeLock: true
|
|
90
67
|
});
|
|
91
|
-
|
|
92
68
|
if (restorWorkspace) {
|
|
93
69
|
restorWorkspace();
|
|
94
70
|
}
|
|
95
71
|
};
|
|
96
|
-
|
|
97
72
|
exports.runInstallTask = runInstallTask;
|
package/dist/js/node/index.js
CHANGED
|
@@ -4,36 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _pluginChangeset = _interopRequireDefault(require("@modern-js/plugin-changeset"));
|
|
9
|
-
|
|
10
|
-
var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
|
|
11
|
-
|
|
8
|
+
var _pluginLint = _interopRequireDefault(require("@modern-js/plugin-lint"));
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
var _locale = require("./locale");
|
|
15
|
-
|
|
16
11
|
var _cli = require("./cli");
|
|
17
|
-
|
|
18
12
|
var _language = require("./utils/language");
|
|
19
|
-
|
|
20
13
|
var _hooks = require("./hooks");
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
15
|
const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
|
|
25
|
-
|
|
26
16
|
var _default = () => ({
|
|
27
17
|
name: '@modern-js/monorepo-tools',
|
|
28
|
-
usePlugins: [(0, _pluginChangeset.default)(), (0,
|
|
18
|
+
usePlugins: [(0, _pluginChangeset.default)(), (0, _pluginLint.default)()],
|
|
29
19
|
registerHook: _hooks.hooks,
|
|
30
20
|
setup: api => {
|
|
31
21
|
const locale = (0, _language.getLocaleLanguage)();
|
|
32
|
-
|
|
33
22
|
_locale.i18n.changeLanguage({
|
|
34
23
|
locale
|
|
35
24
|
});
|
|
36
|
-
|
|
37
25
|
return {
|
|
38
26
|
commands({
|
|
39
27
|
program
|
|
@@ -43,10 +31,8 @@ var _default = () => ({
|
|
|
43
31
|
(0, _cli.newCli)(program, locale);
|
|
44
32
|
upgradeModel.defineCommand(program.command('upgrade'));
|
|
45
33
|
}
|
|
46
|
-
|
|
47
34
|
};
|
|
48
35
|
},
|
|
49
36
|
post: ['@modern-js/plugin-changeset']
|
|
50
37
|
});
|
|
51
|
-
|
|
52
38
|
exports.default = _default;
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.localeKeys = exports.i18n = void 0;
|
|
7
|
-
|
|
8
7
|
var _pluginI18n = require("@modern-js/plugin-i18n");
|
|
9
|
-
|
|
10
8
|
var _zh = require("./zh");
|
|
11
|
-
|
|
12
9
|
var _en = require("./en");
|
|
13
|
-
|
|
14
10
|
const i18n = new _pluginI18n.I18n();
|
|
15
11
|
exports.i18n = i18n;
|
|
16
12
|
const localeKeys = i18n.init('zh', {
|