@modern-js/monorepo-tools 2.0.0-beta.3 → 2.0.0-beta.6
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 +103 -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 +51 -10
- package/dist/js/node/cli/build.js +52 -10
- package/dist/js/node/cli/clear.js +51 -10
- package/dist/js/node/cli/deploy.js +56 -12
- package/dist/js/node/cli/index.js +22 -71
- package/dist/js/node/cli/install.js +51 -10
- package/dist/js/node/cli/new.js +75 -19
- package/dist/js/node/commands/build-watch.js +59 -29
- package/dist/js/node/commands/build.js +74 -32
- package/dist/js/node/commands/clear.js +57 -25
- package/dist/js/node/commands/deploy.js +65 -35
- package/dist/js/node/commands/index.js +21 -60
- package/dist/js/node/commands/install.js +59 -28
- package/dist/js/node/constants.js +33 -13
- package/dist/js/node/dag/create.js +46 -28
- package/dist/js/node/dag/edge-manager.js +25 -8
- package/dist/js/node/dag/index.js +30 -13
- package/dist/js/node/dag/operator.js +211 -174
- package/dist/js/node/dag/task.js +92 -46
- package/dist/js/node/dag/utils.js +58 -47
- package/dist/js/node/features/build/index.js +84 -47
- package/dist/js/node/features/clear/index.js +49 -28
- package/dist/js/node/features/deploy/index.js +139 -104
- package/dist/js/node/features/dev/cmds.js +26 -9
- package/dist/js/node/features/dev/create-task.js +80 -51
- package/dist/js/node/features/dev/index.js +98 -58
- package/dist/js/node/features/dev/watch-projects-state.js +71 -30
- package/dist/js/node/features/install/index.js +82 -41
- package/dist/js/node/hooks/index.js +27 -8
- package/dist/js/node/index.js +53 -32
- package/dist/js/node/locale/en.js +30 -11
- package/dist/js/node/locale/index.js +31 -14
- package/dist/js/node/locale/zh.js +31 -12
- package/dist/js/node/log/error.js +26 -7
- package/dist/js/node/log/multi-tasks-log.js +48 -41
- package/dist/js/node/log/time.js +47 -18
- package/dist/js/node/log/utils.js +30 -10
- package/dist/js/node/package/index.js +25 -10
- package/dist/js/node/parse-config/index.js +76 -31
- package/dist/js/node/parse-config/monorepo.js +79 -44
- package/dist/js/node/projects/check-project-change.js +104 -56
- package/dist/js/node/projects/clear-memory-files.js +42 -15
- package/dist/js/node/projects/get-projects-by-packages-config.js +119 -65
- package/dist/js/node/projects/get-projects-by-workspace-file.js +108 -55
- package/dist/js/node/projects/get-projects.js +112 -61
- package/dist/js/node/type.js +15 -5
- package/dist/js/node/utils/install.js +68 -31
- package/dist/js/node/utils/language.js +28 -8
- package/dist/js/node/utils/types.js +15 -0
- 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,19 +1,49 @@
|
|
|
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 {
|
|
23
|
+
FileSystem,
|
|
24
|
+
JsonFile
|
|
25
|
+
} from "@rushstack/node-core-library";
|
|
26
|
+
import {
|
|
27
|
+
fs,
|
|
28
|
+
yaml,
|
|
29
|
+
execa,
|
|
30
|
+
logger,
|
|
31
|
+
chalk,
|
|
32
|
+
getPnpmVersion
|
|
33
|
+
} from "@modern-js/utils";
|
|
4
34
|
import { WORKSPACE_FILE } from "../../constants";
|
|
5
35
|
const createCopyMap = (rootPath, targetProject, copyProjects, deployDir) => {
|
|
6
|
-
const map = new Map();
|
|
36
|
+
const map = /* @__PURE__ */ new Map();
|
|
7
37
|
for (const project of copyProjects) {
|
|
8
38
|
const relativePath = path.relative(rootPath, project.extra.path);
|
|
9
39
|
const targetPath = path.join(deployDir, relativePath);
|
|
10
40
|
map.set(project.extra.path, targetPath);
|
|
11
41
|
}
|
|
12
|
-
const targetProjectDeployPath = path.join(deployDir,
|
|
42
|
+
const targetProjectDeployPath = path.join(deployDir, "apps/app");
|
|
13
43
|
map.set(targetProject.extra.path, targetProjectDeployPath);
|
|
14
44
|
return map;
|
|
15
45
|
};
|
|
16
|
-
const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename => {
|
|
46
|
+
const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => (filename) => {
|
|
17
47
|
const sourcePath = path.join(monorepoDir, filename);
|
|
18
48
|
const destinationPath = path.join(deployDir, filename);
|
|
19
49
|
if (FileSystem.exists(sourcePath)) {
|
|
@@ -23,122 +53,116 @@ const createCopyFromMonorepoToDeployDirFn = (monorepoDir, deployDir) => filename
|
|
|
23
53
|
});
|
|
24
54
|
}
|
|
25
55
|
};
|
|
26
|
-
const checkAndUpdatePMWorkspaces = deployDir => {
|
|
27
|
-
var
|
|
28
|
-
// pnpm-workspace
|
|
56
|
+
const checkAndUpdatePMWorkspaces = (deployDir) => {
|
|
57
|
+
var _a;
|
|
29
58
|
const pnpmWp = path.join(deployDir, WORKSPACE_FILE.PNPM);
|
|
30
59
|
if (fs.existsSync(pnpmWp)) {
|
|
31
|
-
const pnpmWorkspace = yaml.load(
|
|
60
|
+
const pnpmWorkspace = yaml.load(
|
|
61
|
+
fs.readFileSync(pnpmWp, "utf-8")
|
|
62
|
+
);
|
|
32
63
|
if (pnpmWorkspace.packages && Array.isArray(pnpmWorkspace.packages)) {
|
|
33
|
-
pnpmWorkspace.packages.push(
|
|
64
|
+
pnpmWorkspace.packages.push("apps/**");
|
|
34
65
|
}
|
|
35
66
|
fs.writeFileSync(pnpmWp, yaml.dump(pnpmWorkspace));
|
|
36
67
|
}
|
|
37
68
|
const pkgPath = path.join(deployDir, WORKSPACE_FILE.YARN);
|
|
38
69
|
const pkg = JsonFile.load(pkgPath);
|
|
39
|
-
if ((
|
|
40
|
-
pkg.workspaces.packages.push(
|
|
70
|
+
if (((_a = pkg.workspaces) == null ? void 0 : _a.packages) && Array.isArray(pkg.workspaces.packages)) {
|
|
71
|
+
pkg.workspaces.packages.push("app/**");
|
|
41
72
|
}
|
|
42
73
|
};
|
|
43
74
|
const generatorAndCopyRequiredFiles = (rootPath, deployDir) => {
|
|
44
|
-
// copy .npmrc
|
|
45
75
|
const copy = createCopyFromMonorepoToDeployDirFn(rootPath, deployDir);
|
|
46
|
-
copy(
|
|
47
|
-
copy(
|
|
48
|
-
copy(
|
|
49
|
-
copy(
|
|
50
|
-
copy(
|
|
51
|
-
copy(
|
|
52
|
-
copy(
|
|
53
|
-
|
|
54
|
-
copy(
|
|
55
|
-
copy(
|
|
56
|
-
copy('package-lock.json');
|
|
57
|
-
|
|
58
|
-
// check workspaces config and add 'apps/**',
|
|
59
|
-
// because we deploy project to 'apps' dir
|
|
76
|
+
copy(".npmrc");
|
|
77
|
+
copy("package.json");
|
|
78
|
+
copy("pnpm-workspace.yaml");
|
|
79
|
+
copy("lerna.json");
|
|
80
|
+
copy(".pnpmfile.cjs");
|
|
81
|
+
copy("tsconfig.json");
|
|
82
|
+
copy("modern.config.js");
|
|
83
|
+
copy("pnpm-lock.yaml");
|
|
84
|
+
copy("yarn.lock");
|
|
85
|
+
copy("package-lock.json");
|
|
60
86
|
checkAndUpdatePMWorkspaces(deployDir);
|
|
61
87
|
};
|
|
62
|
-
const checkAndRunDeployCommand =
|
|
63
|
-
var
|
|
64
|
-
const scripts = ((
|
|
88
|
+
const checkAndRunDeployCommand = (monorepoPath, targetProject, packageManager) => __async(void 0, null, function* () {
|
|
89
|
+
var _a, _b, _c;
|
|
90
|
+
const scripts = ((_a = targetProject.extra) == null ? void 0 : _a.scripts) || {};
|
|
65
91
|
if (scripts.deploy) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
92
|
+
logger.info(
|
|
93
|
+
`The 'deploy' command for the ${targetProject.name} is detected, so 'deploy' will be executed`
|
|
94
|
+
);
|
|
95
|
+
let runDeployCommands = ["run", "deploy"];
|
|
96
|
+
if (packageManager === "pnpm") {
|
|
97
|
+
const pnpmVersion = yield getPnpmVersion();
|
|
98
|
+
if (pnpmVersion.startsWith("6")) {
|
|
99
|
+
runDeployCommands = ["run", "deploy", "--filter", targetProject.name];
|
|
73
100
|
} else {
|
|
74
|
-
runDeployCommands = [
|
|
101
|
+
runDeployCommands = ["run", "--filter", targetProject.name, "deploy"];
|
|
75
102
|
}
|
|
76
|
-
} else if (packageManager ===
|
|
77
|
-
runDeployCommands = [
|
|
103
|
+
} else if (packageManager === "yarn") {
|
|
104
|
+
runDeployCommands = ["workspace", targetProject.name, "run", "deploy"];
|
|
78
105
|
}
|
|
79
|
-
const cwd = packageManager ===
|
|
106
|
+
const cwd = packageManager === "npm" ? targetProject.extra.path : monorepoPath;
|
|
80
107
|
const childProcess = execa(packageManager, runDeployCommands, {
|
|
81
108
|
cwd,
|
|
82
|
-
stdio: [
|
|
109
|
+
stdio: ["pipe"]
|
|
83
110
|
});
|
|
84
|
-
(
|
|
85
|
-
(
|
|
86
|
-
|
|
111
|
+
(_b = childProcess.stdout) == null ? void 0 : _b.pipe(process.stdout);
|
|
112
|
+
(_c = childProcess.stderr) == null ? void 0 : _c.pipe(process.stderr);
|
|
113
|
+
yield childProcess;
|
|
87
114
|
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const installDependency = async (deployDir, packageManager) => {
|
|
92
|
-
// TODO: 使用公共方法替换
|
|
93
|
-
const packageJsonPath = path.join(deployDir, 'package.json');
|
|
115
|
+
});
|
|
116
|
+
const installDependency = (deployDir, packageManager) => __async(void 0, null, function* () {
|
|
117
|
+
const packageJsonPath = path.join(deployDir, "package.json");
|
|
94
118
|
const packageJson = JsonFile.load(packageJsonPath);
|
|
95
|
-
const scripts = (packageJson
|
|
119
|
+
const scripts = (packageJson == null ? void 0 : packageJson.scripts) || {};
|
|
96
120
|
let commands = [];
|
|
97
121
|
if (scripts.setup) {
|
|
98
|
-
logger.info(
|
|
99
|
-
|
|
122
|
+
logger.info(
|
|
123
|
+
`The 'setup' command is detected, execute '${packageManager} run setup' to start installing the dependencies`
|
|
124
|
+
);
|
|
125
|
+
commands = ["run", "setup"];
|
|
100
126
|
} else {
|
|
101
|
-
logger.info(
|
|
102
|
-
|
|
127
|
+
logger.info(
|
|
128
|
+
`No 'setup' command detected, execute '${packageManager} install' to start installing dependencies`
|
|
129
|
+
);
|
|
130
|
+
commands = ["install"];
|
|
103
131
|
}
|
|
104
|
-
logger.log(chalk.rgb(218, 152, 92)(
|
|
132
|
+
logger.log(chalk.rgb(218, 152, 92)("Install Log:\n"));
|
|
105
133
|
const childProcess = execa(packageManager, commands, {
|
|
106
|
-
stdio:
|
|
134
|
+
stdio: "inherit",
|
|
107
135
|
cwd: deployDir,
|
|
108
|
-
env: {
|
|
109
|
-
NODE_ENV: undefined
|
|
110
|
-
}
|
|
136
|
+
env: { NODE_ENV: void 0 }
|
|
111
137
|
});
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
const excludeDirs = (filePath, dirs) => dirs.some(dir => filePath.includes(dir));
|
|
115
|
-
const defaultDeployPath =
|
|
116
|
-
|
|
117
|
-
const {
|
|
118
|
-
rootPath,
|
|
119
|
-
packageManager,
|
|
120
|
-
deployPath = defaultDeployPath
|
|
121
|
-
} = config;
|
|
138
|
+
yield childProcess;
|
|
139
|
+
});
|
|
140
|
+
const excludeDirs = (filePath, dirs) => dirs.some((dir) => filePath.includes(dir));
|
|
141
|
+
const defaultDeployPath = "output";
|
|
142
|
+
const deploy = (deployProjectNames, operator, config) => __async(void 0, null, function* () {
|
|
143
|
+
const { rootPath, packageManager, deployPath = defaultDeployPath } = config;
|
|
122
144
|
const realDeployPath = path.isAbsolute(deployPath) ? deployPath : path.join(rootPath, deployPath);
|
|
123
|
-
FileSystem.deleteFolder(realDeployPath);
|
|
124
|
-
|
|
145
|
+
FileSystem.deleteFolder(realDeployPath);
|
|
125
146
|
for (const deployProjectName of deployProjectNames) {
|
|
126
147
|
const currentProject = operator.getNodeData(deployProjectName, {
|
|
127
148
|
checkExist: true
|
|
128
149
|
});
|
|
129
150
|
const alldeps = operator.getNodeAllDependencyData(deployProjectName);
|
|
130
|
-
const copyMap = createCopyMap(
|
|
131
|
-
|
|
151
|
+
const copyMap = createCopyMap(
|
|
152
|
+
rootPath,
|
|
153
|
+
currentProject,
|
|
154
|
+
alldeps,
|
|
155
|
+
realDeployPath
|
|
156
|
+
);
|
|
157
|
+
yield checkAndRunDeployCommand(rootPath, currentProject, packageManager);
|
|
132
158
|
FileSystem.ensureFolder(realDeployPath);
|
|
133
159
|
for (const [from, to] of copyMap) {
|
|
134
|
-
// https://rushstack.io/pages/api/node-core-library.ifilesystemcopyfilesasyncoptions/
|
|
135
160
|
FileSystem.copyFiles({
|
|
136
161
|
sourcePath: from,
|
|
137
162
|
destinationPath: to,
|
|
138
|
-
// If true, then when copying symlinks, copy the target object instead of copying the link.
|
|
139
163
|
dereferenceSymlinks: false,
|
|
140
164
|
filter(filePath) {
|
|
141
|
-
if (excludeDirs(filePath, [
|
|
165
|
+
if (excludeDirs(filePath, ["node_modules", "dist"])) {
|
|
142
166
|
return false;
|
|
143
167
|
}
|
|
144
168
|
return true;
|
|
@@ -147,7 +171,8 @@ export const deploy = async (deployProjectNames, operator, config) => {
|
|
|
147
171
|
}
|
|
148
172
|
}
|
|
149
173
|
generatorAndCopyRequiredFiles(rootPath, realDeployPath);
|
|
150
|
-
// await installDependency(realDeployPath, packageManager);
|
|
151
|
-
|
|
152
174
|
logger.success(`Deploy success. The deploy dir is in '${rootPath}/output'`);
|
|
153
|
-
};
|
|
175
|
+
});
|
|
176
|
+
export {
|
|
177
|
+
deploy
|
|
178
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const defaultBuildWatchCmds = ["dev", "build"];
|
|
2
|
+
export {
|
|
3
|
+
defaultBuildWatchCmds
|
|
4
|
+
};
|
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
|
|
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 { execa, logger } from "@modern-js/utils";
|
|
2
22
|
import { errorLog } from "../../log/error";
|
|
3
23
|
import * as timeLog from "../../log/time";
|
|
4
24
|
import { defaultBuildWatchCmds } from "./cmds";
|
|
5
25
|
const getFinalTaskCmds = (taskCmds, project) => {
|
|
6
26
|
let finalTaskCmds = [];
|
|
7
|
-
// case1: ["build"]
|
|
8
|
-
// case2: ["dev", "build"]
|
|
9
|
-
// case3: ["dev", () => []]
|
|
10
|
-
// default: ['dev', 'build']
|
|
11
27
|
if (taskCmds.length === 1) {
|
|
12
28
|
finalTaskCmds = [taskCmds[0]];
|
|
13
|
-
} else if (taskCmds.length === 2 && typeof taskCmds[0] ===
|
|
29
|
+
} else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "string") {
|
|
14
30
|
finalTaskCmds = [taskCmds[1]];
|
|
15
|
-
} else if (taskCmds.length === 2 && typeof taskCmds[0] ===
|
|
31
|
+
} else if (taskCmds.length === 2 && typeof taskCmds[0] === "string" && typeof taskCmds[1] === "function") {
|
|
16
32
|
finalTaskCmds = taskCmds[1](project);
|
|
17
33
|
} else {
|
|
18
|
-
|
|
19
|
-
finalTaskCmds = ['build'];
|
|
34
|
+
finalTaskCmds = ["build"];
|
|
20
35
|
}
|
|
21
36
|
return finalTaskCmds;
|
|
22
37
|
};
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
packageManager
|
|
26
|
-
} = config;
|
|
38
|
+
const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds, taskLogger) => {
|
|
39
|
+
const { packageManager } = config;
|
|
27
40
|
const timelogInstance = timeLog.initTimeLog();
|
|
28
|
-
const task =
|
|
41
|
+
const task = (project) => __async(void 0, null, function* () {
|
|
29
42
|
const finalTaskCmds = getFinalTaskCmds(taskCmds, project);
|
|
30
43
|
const cmd = project.extra.scripts || {};
|
|
31
44
|
for (const taskCmd of finalTaskCmds) {
|
|
@@ -35,16 +48,14 @@ export const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds,
|
|
|
35
48
|
try {
|
|
36
49
|
const childProcess = execa(packageManager, [taskCmd], {
|
|
37
50
|
cwd: project.extra.path,
|
|
38
|
-
stdio: [
|
|
51
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
39
52
|
});
|
|
40
53
|
taskLogger.addLogProvider(project.name, {
|
|
41
54
|
stdout: childProcess.stdout,
|
|
42
55
|
stderr: childProcess.stderr,
|
|
43
|
-
logConfig: {
|
|
44
|
-
label: 'WATCH: '
|
|
45
|
-
}
|
|
56
|
+
logConfig: { label: "WATCH: " }
|
|
46
57
|
});
|
|
47
|
-
|
|
58
|
+
yield childProcess;
|
|
48
59
|
} catch (e) {
|
|
49
60
|
errorLog(project.name, e);
|
|
50
61
|
}
|
|
@@ -53,34 +64,28 @@ export const createDependenciesTask = (config, taskCmds = defaultBuildWatchCmds,
|
|
|
53
64
|
logger.info(`${project.name} not have ${taskCmd}, skip it.`);
|
|
54
65
|
}
|
|
55
66
|
}
|
|
56
|
-
};
|
|
67
|
+
});
|
|
57
68
|
return task;
|
|
58
69
|
};
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
} = config;
|
|
63
|
-
const task = async project => {
|
|
70
|
+
const createDevTask = (config, taskCmds = defaultBuildWatchCmds, taskLogger) => {
|
|
71
|
+
const { packageManager } = config;
|
|
72
|
+
const task = (project) => __async(void 0, null, function* () {
|
|
64
73
|
const devCmds = [taskCmds[0]];
|
|
65
74
|
const cmd = project.extra.scripts || {};
|
|
66
75
|
for (const taskCmd of devCmds) {
|
|
67
76
|
if (cmd[taskCmd]) {
|
|
68
|
-
// const prefix = `run ${project.name} ${taskCmd} script`;
|
|
69
|
-
// log.info(prefix);
|
|
70
77
|
try {
|
|
71
78
|
const childProcess = execa(packageManager, [taskCmd], {
|
|
72
79
|
cwd: project.extra.path,
|
|
73
|
-
stdio:
|
|
80
|
+
stdio: "pipe",
|
|
74
81
|
all: true
|
|
75
82
|
});
|
|
76
83
|
taskLogger.addLogProvider(project.name, {
|
|
77
84
|
stdout: childProcess.stdout,
|
|
78
85
|
stderr: childProcess.stderr,
|
|
79
|
-
logConfig: {
|
|
80
|
-
label: `${taskCmd.toUpperCase()}: `
|
|
81
|
-
}
|
|
86
|
+
logConfig: { label: `${taskCmd.toUpperCase()}: ` }
|
|
82
87
|
});
|
|
83
|
-
const ret =
|
|
88
|
+
const ret = yield childProcess;
|
|
84
89
|
console.info(ret);
|
|
85
90
|
} catch (e) {
|
|
86
91
|
errorLog(project.name, e);
|
|
@@ -89,6 +94,10 @@ export const createDevTask = (config, taskCmds = defaultBuildWatchCmds, taskLogg
|
|
|
89
94
|
logger.info(`${project.name} not have ${taskCmd}, skip it.`);
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
|
-
};
|
|
97
|
+
});
|
|
93
98
|
return task;
|
|
94
|
-
};
|
|
99
|
+
};
|
|
100
|
+
export {
|
|
101
|
+
createDependenciesTask,
|
|
102
|
+
createDevTask
|
|
103
|
+
};
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 anymatch from "anymatch";
|
|
22
|
+
import { chokidar } from "@modern-js/utils";
|
|
3
23
|
import { MultitasksLogger } from "../../log/multi-tasks-log";
|
|
4
24
|
import { WatchedProjectsState } from "./watch-projects-state";
|
|
5
25
|
import { defaultBuildWatchCmds } from "./cmds";
|
|
6
26
|
import { createDependenciesTask, createDevTask } from "./create-task";
|
|
7
|
-
const getIgnored = config => watchFilePath => {
|
|
8
|
-
// 默认忽略 node_modules 的变化和 dist 目录下文件的变化
|
|
27
|
+
const getIgnored = (config) => (watchFilePath) => {
|
|
9
28
|
const nodeModulesPattern = /(?:^|[\\/])node_modules/g;
|
|
10
|
-
if (nodeModulesPattern.test(watchFilePath) || watchFilePath.includes(
|
|
29
|
+
if (nodeModulesPattern.test(watchFilePath) || watchFilePath.includes("dist")) {
|
|
11
30
|
return true;
|
|
12
31
|
}
|
|
13
32
|
if (config.ignoreMaybeChanged) {
|
|
@@ -15,10 +34,8 @@ const getIgnored = config => watchFilePath => {
|
|
|
15
34
|
}
|
|
16
35
|
return false;
|
|
17
36
|
};
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
needInit = true
|
|
21
|
-
} = config;
|
|
37
|
+
const runBuildWatchTask = (_0, _1, _2, ..._3) => __async(void 0, [_0, _1, _2, ..._3], function* (projectName, operator, config, taskCmds = defaultBuildWatchCmds) {
|
|
38
|
+
const { needInit = true } = config;
|
|
22
39
|
const taskLogger = new MultitasksLogger();
|
|
23
40
|
const dependenciesTask = createDependenciesTask(config, taskCmds, taskLogger);
|
|
24
41
|
const devTask = createDevTask(config, taskCmds, taskLogger);
|
|
@@ -31,48 +48,50 @@ export const runBuildWatchTask = async (projectName, operator, config, taskCmds
|
|
|
31
48
|
ignoreInitial: true,
|
|
32
49
|
ignored: getIgnored(config),
|
|
33
50
|
disableGlobbing: true,
|
|
34
|
-
interval:
|
|
51
|
+
interval: 1e3
|
|
35
52
|
});
|
|
36
53
|
watcher.add(watchedProjectState.getWatchedProjectsPath());
|
|
37
|
-
|
|
38
|
-
// 可能会移除该判断和 neeInit 配置
|
|
39
54
|
if (needInit) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
yield operator.traverseDependenciesToProject(
|
|
56
|
+
projectName,
|
|
57
|
+
(currentProject) => __async(void 0, null, function* () {
|
|
58
|
+
yield dependenciesTask(currentProject);
|
|
59
|
+
})
|
|
60
|
+
);
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
console.info(
|
|
46
|
-
watcher.on(
|
|
47
|
-
|
|
48
|
-
if (eventName === 'add') {
|
|
62
|
+
yield new Promise((resolve) => {
|
|
63
|
+
console.info("start watch");
|
|
64
|
+
watcher.on("all", (eventName, changeFilePath) => __async(void 0, null, function* () {
|
|
65
|
+
if (eventName === "add") {
|
|
49
66
|
watchedProjectState.updateState();
|
|
50
67
|
}
|
|
51
68
|
const changedProject = watchedProjectState.getChangedProject(changeFilePath);
|
|
52
69
|
if (changedProject) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
yield operator.traverseProjectToDependent(
|
|
71
|
+
changedProject.name,
|
|
72
|
+
(currentProject, _, earlyFinish) => __async(void 0, null, function* () {
|
|
73
|
+
if (currentProject.name === projectName) {
|
|
74
|
+
earlyFinish();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (watchedProjectState.watchProjectsName.includes(
|
|
78
|
+
currentProject.name
|
|
79
|
+
)) {
|
|
80
|
+
console.info("run build", currentProject.name);
|
|
81
|
+
yield dependenciesTask(currentProject);
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
{ withSelf: true }
|
|
85
|
+
);
|
|
66
86
|
resolve(null);
|
|
67
87
|
} else {
|
|
68
|
-
console.info(
|
|
88
|
+
console.info("changed is not in monorepo manager");
|
|
69
89
|
}
|
|
70
|
-
});
|
|
90
|
+
}));
|
|
71
91
|
resolve(null);
|
|
72
92
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
93
|
+
yield devTask(operator.getNodeData(projectName, { checkExist: true }));
|
|
94
|
+
});
|
|
95
|
+
export {
|
|
96
|
+
runBuildWatchTask
|
|
97
|
+
};
|
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import * as path from "path";
|
|
21
|
+
import { globby } from "@modern-js/utils";
|
|
22
|
+
class WatchedProjectsState {
|
|
7
23
|
constructor(fromNodes, config) {
|
|
8
|
-
_defineProperty(this, "_config", void 0);
|
|
9
|
-
_defineProperty(this, "_fromNodes", void 0);
|
|
10
|
-
_defineProperty(this, "_watchProjects", void 0);
|
|
11
|
-
_defineProperty(this, "_projectsFileMap", void 0);
|
|
12
24
|
this._fromNodes = fromNodes;
|
|
13
25
|
this._config = config;
|
|
14
|
-
this._projectsFileMap = new Map();
|
|
26
|
+
this._projectsFileMap = /* @__PURE__ */ new Map();
|
|
15
27
|
this._watchProjects = {};
|
|
16
28
|
this._initState();
|
|
17
29
|
}
|
|
@@ -21,24 +33,30 @@ export class WatchedProjectsState {
|
|
|
21
33
|
absolute: true,
|
|
22
34
|
expandDirectories: false,
|
|
23
35
|
followSymbolicLinks: false,
|
|
24
|
-
ignore: [
|
|
36
|
+
ignore: ["**/node_modules/**", ".project-memory/**", "dist/**"]
|
|
25
37
|
};
|
|
26
|
-
this._watchProjects = this._fromNodes.reduce(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
this._watchProjects = this._fromNodes.reduce(
|
|
39
|
+
(ret, node) => {
|
|
40
|
+
const files = globby.sync(`${node.extra.path}/**`, globOption);
|
|
41
|
+
for (const filePath of files) {
|
|
42
|
+
this._projectsFileMap.set(
|
|
43
|
+
path.relative(this._config.rootPath, filePath),
|
|
44
|
+
node.extra.path
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return __spreadProps(__spreadValues({}, ret), {
|
|
48
|
+
[node.extra.path]: node
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
{}
|
|
52
|
+
);
|
|
35
53
|
}
|
|
36
54
|
getChangedProject(changedFilPath) {
|
|
37
55
|
if (this._projectsFileMap.has(changedFilPath)) {
|
|
38
56
|
const projectPath = this._projectsFileMap.get(changedFilPath);
|
|
39
57
|
return this._watchProjects[projectPath];
|
|
40
58
|
}
|
|
41
|
-
return
|
|
59
|
+
return void 0;
|
|
42
60
|
}
|
|
43
61
|
getWatchedProjectsPath() {
|
|
44
62
|
return Object.keys(this._watchProjects);
|
|
@@ -50,6 +68,11 @@ export class WatchedProjectsState {
|
|
|
50
68
|
return this._watchProjects;
|
|
51
69
|
}
|
|
52
70
|
get watchProjectsName() {
|
|
53
|
-
return Object.keys(this._watchProjects).map(
|
|
71
|
+
return Object.keys(this._watchProjects).map(
|
|
72
|
+
(projectPath) => this._watchProjects[projectPath].name
|
|
73
|
+
);
|
|
54
74
|
}
|
|
55
|
-
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
WatchedProjectsState
|
|
78
|
+
};
|