@modern-js/app-tools 2.1.0 → 2.3.0
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 +89 -0
- package/dist/js/modern/analyze/index.js +14 -4
- package/dist/js/modern/analyze/nestedRoutes.js +5 -1
- package/dist/js/modern/builder/index.js +4 -4
- package/dist/js/modern/commands/dev.js +1 -23
- package/dist/js/modern/hooks.js +0 -2
- package/dist/js/modern/index.js +14 -2
- package/dist/js/modern/initialize/index.js +6 -2
- package/dist/js/modern/locale/en.js +3 -1
- package/dist/js/modern/locale/zh.js +3 -1
- package/dist/js/modern/utils/generateWatchFiles.js +55 -0
- package/dist/js/modern/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +9 -8
- package/dist/js/node/analyze/index.js +11 -4
- package/dist/js/node/analyze/nestedRoutes.js +5 -1
- package/dist/js/node/builder/index.js +4 -4
- package/dist/js/node/commands/dev.js +1 -23
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +9 -2
- package/dist/js/node/initialize/index.js +1 -2
- package/dist/js/node/locale/en.js +3 -1
- package/dist/js/node/locale/zh.js +3 -1
- package/dist/js/node/utils/{createFileWatcher.js → generateWatchFiles.js} +12 -66
- package/dist/js/node/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +12 -11
- package/dist/js/treeshaking/analyze/index.js +24 -11
- package/dist/js/treeshaking/analyze/nestedRoutes.js +12 -3
- package/dist/js/treeshaking/builder/index.js +5 -5
- package/dist/js/treeshaking/commands/dev.js +13 -31
- package/dist/js/treeshaking/hooks.js +0 -2
- package/dist/js/treeshaking/index.js +15 -2
- package/dist/js/treeshaking/initialize/index.js +1 -2
- package/dist/js/treeshaking/locale/en.js +3 -1
- package/dist/js/treeshaking/locale/zh.js +3 -1
- package/dist/js/treeshaking/utils/{createFileWatcher.js → generateWatchFiles.js} +16 -85
- package/dist/js/treeshaking/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +8 -7
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/types/hooks.d.ts +0 -5
- package/dist/types/utils/generateWatchFiles.d.ts +3 -0
- package/dist/types/utils/getSelectedEntries.d.ts +6 -0
- package/package.json +22 -22
- package/dist/js/modern/utils/commands.js +0 -13
- package/dist/js/modern/utils/createFileWatcher.js +0 -115
- package/dist/js/node/utils/commands.js +0 -37
- package/dist/js/treeshaking/utils/commands.js +0 -10
- package/dist/types/utils/commands.d.ts +0 -2
- package/dist/types/utils/createFileWatcher.d.ts +0 -4
- package/dist/types/utils/getSpecifiedEntries.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,94 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fd5a3ed: fix: failed to exit new command
|
|
8
|
+
|
|
9
|
+
fix: 修复 new 命令执行完成后未退出进程的问题
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [65f1322]
|
|
12
|
+
- Updated dependencies [7cd8185]
|
|
13
|
+
- Updated dependencies [fd5a3ed]
|
|
14
|
+
- Updated dependencies [362c9a8]
|
|
15
|
+
- Updated dependencies [67ba34a]
|
|
16
|
+
- Updated dependencies [2ad9fdf]
|
|
17
|
+
- Updated dependencies [7b2cdcb]
|
|
18
|
+
- Updated dependencies [1b0dd35]
|
|
19
|
+
- Updated dependencies [f9a26fe]
|
|
20
|
+
- Updated dependencies [6ca1c0b]
|
|
21
|
+
- Updated dependencies [89b6739]
|
|
22
|
+
- Updated dependencies [01e4a27]
|
|
23
|
+
- Updated dependencies [7736171]
|
|
24
|
+
- Updated dependencies [ff48fc2]
|
|
25
|
+
- Updated dependencies [b6c2eb8]
|
|
26
|
+
- Updated dependencies [3cdf48e]
|
|
27
|
+
- @modern-js/core@2.3.0
|
|
28
|
+
- @modern-js/builder@2.3.0
|
|
29
|
+
- @modern-js/builder-webpack-provider@2.3.0
|
|
30
|
+
- @modern-js/utils@2.3.0
|
|
31
|
+
- @modern-js/builder-shared@2.3.0
|
|
32
|
+
- @modern-js/server@2.3.0
|
|
33
|
+
- @modern-js/plugin-data-loader@2.3.0
|
|
34
|
+
- @modern-js/plugin-lint@2.3.0
|
|
35
|
+
- @modern-js/builder-plugin-esbuild@2.3.0
|
|
36
|
+
- @modern-js/builder-plugin-node-polyfill@2.3.0
|
|
37
|
+
- @modern-js/plugin-i18n@2.3.0
|
|
38
|
+
- @modern-js/new-action@2.3.0
|
|
39
|
+
- @modern-js/prod-server@2.3.0
|
|
40
|
+
- @modern-js/node-bundle-require@2.3.0
|
|
41
|
+
- @modern-js/upgrade@2.3.0
|
|
42
|
+
- @modern-js/plugin@2.3.0
|
|
43
|
+
- @modern-js/types@2.3.0
|
|
44
|
+
|
|
45
|
+
## 2.2.0
|
|
46
|
+
|
|
47
|
+
### Minor Changes
|
|
48
|
+
|
|
49
|
+
- 12ef50f: feat: `modern-js/core` can watch files change
|
|
50
|
+
feat: `modern-js/core` 可以监听文件变化
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 64ade69: fix(app-tools): dev --entry not work
|
|
55
|
+
|
|
56
|
+
fix(app-tools): 修复 dev --entry 参数不生效的问题
|
|
57
|
+
|
|
58
|
+
- 16bdc0a: chore: adjust builder plugin name
|
|
59
|
+
|
|
60
|
+
chore: 调整 builder 插件命名格式
|
|
61
|
+
|
|
62
|
+
- 19bb384: fix: when a child route does not exist, an empty layout should not be created
|
|
63
|
+
fix: 子路由不存在时,不应该创建空的 layout
|
|
64
|
+
- Updated dependencies [f2f8a83]
|
|
65
|
+
- Updated dependencies [cb12ee7]
|
|
66
|
+
- Updated dependencies [49eff0c]
|
|
67
|
+
- Updated dependencies [2d3e3df]
|
|
68
|
+
- Updated dependencies [360a259]
|
|
69
|
+
- Updated dependencies [9fc6de9]
|
|
70
|
+
- Updated dependencies [d82b621]
|
|
71
|
+
- Updated dependencies [16bdc0a]
|
|
72
|
+
- Updated dependencies [12ef50f]
|
|
73
|
+
- Updated dependencies [19bb384]
|
|
74
|
+
- @modern-js/builder-shared@2.2.0
|
|
75
|
+
- @modern-js/builder-webpack-provider@2.2.0
|
|
76
|
+
- @modern-js/core@2.2.0
|
|
77
|
+
- @modern-js/plugin-data-loader@2.2.0
|
|
78
|
+
- @modern-js/utils@2.2.0
|
|
79
|
+
- @modern-js/prod-server@2.2.0
|
|
80
|
+
- @modern-js/server@2.2.0
|
|
81
|
+
- @modern-js/builder@2.2.0
|
|
82
|
+
- @modern-js/builder-plugin-esbuild@2.2.0
|
|
83
|
+
- @modern-js/builder-plugin-node-polyfill@2.2.0
|
|
84
|
+
- @modern-js/types@2.2.0
|
|
85
|
+
- @modern-js/plugin-lint@2.2.0
|
|
86
|
+
- @modern-js/plugin-i18n@2.2.0
|
|
87
|
+
- @modern-js/new-action@2.2.0
|
|
88
|
+
- @modern-js/node-bundle-require@2.2.0
|
|
89
|
+
- @modern-js/upgrade@2.2.0
|
|
90
|
+
- @modern-js/plugin@2.2.0
|
|
91
|
+
|
|
3
92
|
## 2.1.0
|
|
4
93
|
|
|
5
94
|
### Patch Changes
|
|
@@ -43,14 +43,17 @@ import {
|
|
|
43
43
|
findExists,
|
|
44
44
|
fs,
|
|
45
45
|
getEntryOptions,
|
|
46
|
-
isApiOnly
|
|
46
|
+
isApiOnly,
|
|
47
|
+
minimist,
|
|
48
|
+
getCommand,
|
|
49
|
+
isDevCommand
|
|
47
50
|
} from "@modern-js/utils";
|
|
48
51
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
49
52
|
import { createBuilderForModern } from "../builder";
|
|
50
53
|
import { printInstructions } from "../utils/printInstructions";
|
|
51
54
|
import { generateRoutes } from "../utils/routes";
|
|
52
55
|
import { emitResolvedConfig } from "../utils/config";
|
|
53
|
-
import {
|
|
56
|
+
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
54
57
|
import { initialNormalizedConfig } from "../config";
|
|
55
58
|
import {
|
|
56
59
|
getServerLoadersFile,
|
|
@@ -110,7 +113,6 @@ var analyze_default = () => ({
|
|
|
110
113
|
import("./getHtmlTemplate")
|
|
111
114
|
]);
|
|
112
115
|
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
113
|
-
const defaultChecked = entrypoints.map((point) => point.entryName);
|
|
114
116
|
debug(`entrypoints: %o`, entrypoints);
|
|
115
117
|
const initialRoutes = getServerRoutes(entrypoints, {
|
|
116
118
|
appContext,
|
|
@@ -136,9 +138,17 @@ var analyze_default = () => ({
|
|
|
136
138
|
debug(`html templates: %o`, htmlTemplates);
|
|
137
139
|
yield hookRunners.addDefineTypes();
|
|
138
140
|
debug(`add Define Types`);
|
|
141
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
142
|
+
if (isDevCommand()) {
|
|
143
|
+
const { entry } = minimist(process.argv.slice(2));
|
|
144
|
+
checkedEntries = yield getSelectedEntries(
|
|
145
|
+
typeof entry === "string" ? entry.split(",") : entry,
|
|
146
|
+
entrypoints
|
|
147
|
+
);
|
|
148
|
+
}
|
|
139
149
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
140
150
|
entrypoints,
|
|
141
|
-
checkedEntries
|
|
151
|
+
checkedEntries,
|
|
142
152
|
apiOnly,
|
|
143
153
|
serverRoutes: routes,
|
|
144
154
|
htmlTemplates
|
|
@@ -64,7 +64,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
|
|
67
|
-
var _a, _b;
|
|
67
|
+
var _a, _b, _c;
|
|
68
68
|
if (!(yield fs.pathExists(dirname))) {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
@@ -146,6 +146,10 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
146
146
|
if (isPathlessLayout) {
|
|
147
147
|
delete finalRoute.path;
|
|
148
148
|
}
|
|
149
|
+
route.children = (_c = route.children) == null ? void 0 : _c.filter((childRoute) => childRoute);
|
|
150
|
+
if (route.children && route.children.length === 0 && !route.index) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
149
153
|
return finalRoute;
|
|
150
154
|
});
|
|
151
155
|
export {
|
|
@@ -134,14 +134,14 @@ function createBuilderOptions(target, appContext) {
|
|
|
134
134
|
function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
135
135
|
return __async(this, null, function* () {
|
|
136
136
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
137
|
-
const {
|
|
138
|
-
builder.addPlugins([
|
|
137
|
+
const { builderPluginNodePolyfill } = yield import("@modern-js/builder-plugin-node-polyfill");
|
|
138
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
139
139
|
}
|
|
140
140
|
if (normalizedConfig.tools.esbuild) {
|
|
141
141
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
142
|
-
const {
|
|
142
|
+
const { builderPluginEsbuild } = yield import("@modern-js/builder-plugin-esbuild");
|
|
143
143
|
builder.addPlugins([
|
|
144
|
-
|
|
144
|
+
builderPluginEsbuild({
|
|
145
145
|
loader: false,
|
|
146
146
|
minimize: applyOptionsChain({}, esbuildOptions)
|
|
147
147
|
})
|
|
@@ -38,7 +38,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
41
|
-
import { createFileWatcher } from "../utils/createFileWatcher";
|
|
42
41
|
import { printInstructions } from "../utils/printInstructions";
|
|
43
42
|
import {
|
|
44
43
|
setServer,
|
|
@@ -46,7 +45,6 @@ import {
|
|
|
46
45
|
injectDataLoaderPlugin
|
|
47
46
|
} from "../utils/createServer";
|
|
48
47
|
import { generateRoutes } from "../utils/routes";
|
|
49
|
-
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
50
48
|
import { buildServerConfig } from "../utils/config";
|
|
51
49
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
52
50
|
const dev = (api, options) => __async(void 0, null, function* () {
|
|
@@ -59,22 +57,7 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
59
57
|
const hookRunners = api.useHookRunners();
|
|
60
58
|
normalizedConfig = __spreadProps(__spreadValues({}, normalizedConfig), { cliOptions: options });
|
|
61
59
|
ResolvedConfigContext.set(normalizedConfig);
|
|
62
|
-
const {
|
|
63
|
-
appDirectory,
|
|
64
|
-
distDirectory,
|
|
65
|
-
port,
|
|
66
|
-
apiOnly,
|
|
67
|
-
entrypoints,
|
|
68
|
-
serverConfigFile
|
|
69
|
-
} = appContext;
|
|
70
|
-
const checkedEntries = yield getSpecifiedEntries(
|
|
71
|
-
options.entry || false,
|
|
72
|
-
entrypoints
|
|
73
|
-
);
|
|
74
|
-
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
75
|
-
checkedEntries
|
|
76
|
-
}));
|
|
77
|
-
appContext.checkedEntries = checkedEntries;
|
|
60
|
+
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile } = appContext;
|
|
78
61
|
yield buildServerConfig({
|
|
79
62
|
appDirectory,
|
|
80
63
|
distDirectory,
|
|
@@ -120,11 +103,6 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
120
103
|
});
|
|
121
104
|
setServer(server);
|
|
122
105
|
}
|
|
123
|
-
yield createFileWatcher(
|
|
124
|
-
appContext,
|
|
125
|
-
normalizedConfig.source.configDir,
|
|
126
|
-
hookRunners
|
|
127
|
-
);
|
|
128
106
|
});
|
|
129
107
|
export {
|
|
130
108
|
dev
|
package/dist/js/modern/hooks.js
CHANGED
|
@@ -24,8 +24,6 @@ const hooks = {
|
|
|
24
24
|
afterBuild: createAsyncWorkflow(),
|
|
25
25
|
beforeDeploy: createAsyncWorkflow(),
|
|
26
26
|
afterDeploy: createAsyncWorkflow(),
|
|
27
|
-
watchFiles: createParallelWorkflow(),
|
|
28
|
-
fileChange: createAsyncWorkflow(),
|
|
29
27
|
beforeRestart: createAsyncWorkflow(),
|
|
30
28
|
registerDev: createParallelWorkflow(),
|
|
31
29
|
beforeDevTask: createParallelWorkflow(),
|
package/dist/js/modern/index.js
CHANGED
|
@@ -39,15 +39,20 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
};
|
|
40
40
|
import path from "path";
|
|
41
41
|
import lintPlugin from "@modern-js/plugin-lint";
|
|
42
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
cleanRequireCache,
|
|
44
|
+
emptyDir,
|
|
45
|
+
Import,
|
|
46
|
+
getCommand
|
|
47
|
+
} from "@modern-js/utils";
|
|
43
48
|
import { castArray } from "@modern-js/utils/lodash";
|
|
44
49
|
import analyzePlugin from "./analyze";
|
|
45
50
|
import initializePlugin from "./initialize";
|
|
46
51
|
import { hooks } from "./hooks";
|
|
47
52
|
import { i18n, localeKeys } from "./locale";
|
|
48
53
|
import { getLocaleLanguage } from "./utils/language";
|
|
49
|
-
import { getCommand } from "./utils/commands";
|
|
50
54
|
import { restart } from "./utils/restart";
|
|
55
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
51
56
|
export * from "./defineConfig";
|
|
52
57
|
export * from "./types";
|
|
53
58
|
const upgradeModel = Import.lazy(
|
|
@@ -171,6 +176,13 @@ var src_default = () => ({
|
|
|
171
176
|
}
|
|
172
177
|
});
|
|
173
178
|
},
|
|
179
|
+
watchFiles() {
|
|
180
|
+
return __async(this, null, function* () {
|
|
181
|
+
const appContext = api.useAppContext();
|
|
182
|
+
const config = api.useResolvedConfigContext();
|
|
183
|
+
return generateWatchFiles(appContext, config.source.configDir);
|
|
184
|
+
});
|
|
185
|
+
},
|
|
174
186
|
fileChange(e) {
|
|
175
187
|
return __async(this, null, function* () {
|
|
176
188
|
const { filename, eventType } = e;
|
|
@@ -37,9 +37,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
ensureAbsolutePath,
|
|
42
|
+
getPort,
|
|
43
|
+
isDev,
|
|
44
|
+
isDevCommand
|
|
45
|
+
} from "@modern-js/utils";
|
|
41
46
|
import { legacySchema, schema } from "../schema";
|
|
42
|
-
import { isDevCommand } from "../utils/commands";
|
|
43
47
|
import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
|
|
44
48
|
import {
|
|
45
49
|
checkIsLegacyConfig,
|
|
@@ -7,7 +7,9 @@ const EN_LOCALE = {
|
|
|
7
7
|
dev: {
|
|
8
8
|
describe: "start dev server",
|
|
9
9
|
entry: "compiler by entry",
|
|
10
|
-
apiOnly: "start api server only"
|
|
10
|
+
apiOnly: "start api server only",
|
|
11
|
+
selectEntry: "Please select the entry that needs to be built",
|
|
12
|
+
requireEntry: "You must choose at least one entry"
|
|
11
13
|
},
|
|
12
14
|
build: {
|
|
13
15
|
describe: "build application"
|
|
@@ -0,0 +1,55 @@
|
|
|
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 path from "path";
|
|
22
|
+
import { fs, getServerConfig } from "@modern-js/utils";
|
|
23
|
+
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
24
|
+
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
25
|
+
const json = JSON.parse(
|
|
26
|
+
fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8")
|
|
27
|
+
);
|
|
28
|
+
return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
29
|
+
};
|
|
30
|
+
const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) => __async(void 0, null, function* () {
|
|
31
|
+
const serverConfig = yield getServerConfig(appDirectory, serverConfigFile);
|
|
32
|
+
if (serverConfig) {
|
|
33
|
+
dependencies.push(serverConfig);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
function generateWatchFiles(appContext, configDir) {
|
|
37
|
+
return __async(this, null, function* () {
|
|
38
|
+
const { appDirectory, configFile } = appContext;
|
|
39
|
+
const configPath = path.join(appDirectory, configDir || "");
|
|
40
|
+
const dependencies = getPackageConfig(
|
|
41
|
+
appContext.appDirectory,
|
|
42
|
+
appContext.packageName
|
|
43
|
+
) ? [path.resolve(appDirectory, "./package.json")] : [];
|
|
44
|
+
yield addServerConfigToDeps(
|
|
45
|
+
dependencies,
|
|
46
|
+
appContext.appDirectory,
|
|
47
|
+
appContext.serverConfigFile
|
|
48
|
+
);
|
|
49
|
+
return [`${configPath}/html`, configFile || "./config", ...dependencies];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
addServerConfigToDeps,
|
|
54
|
+
generateWatchFiles
|
|
55
|
+
};
|
|
@@ -18,8 +18,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
18
18
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
import { inquirer } from "@modern-js/utils";
|
|
22
|
-
|
|
21
|
+
import { chalk, inquirer } from "@modern-js/utils";
|
|
22
|
+
import { i18n, localeKeys } from "../locale";
|
|
23
|
+
const getSelectedEntries = (entry, entrypoints) => __async(void 0, null, function* () {
|
|
23
24
|
const entryNames = entrypoints.map((e) => e.entryName);
|
|
24
25
|
if (!entry) {
|
|
25
26
|
return entryNames;
|
|
@@ -30,10 +31,10 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
30
31
|
type: "checkbox",
|
|
31
32
|
name: "selected",
|
|
32
33
|
choices: entryNames,
|
|
33
|
-
message:
|
|
34
|
+
message: i18n.t(localeKeys.command.dev.selectEntry),
|
|
34
35
|
validate(answer) {
|
|
35
36
|
if (answer.length < 1) {
|
|
36
|
-
return
|
|
37
|
+
return i18n.t(localeKeys.command.dev.requireEntry);
|
|
37
38
|
}
|
|
38
39
|
return true;
|
|
39
40
|
}
|
|
@@ -44,14 +45,14 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
44
45
|
entry.forEach((name) => {
|
|
45
46
|
if (!entryNames.includes(name)) {
|
|
46
47
|
throw new Error(
|
|
47
|
-
`
|
|
48
|
-
|
|
49
|
-
)}`
|
|
48
|
+
`Can not found entry ${chalk.yellow(
|
|
49
|
+
name
|
|
50
|
+
)}, the entry should be one of ${chalk.yellow(entryNames.join(", "))}`
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
});
|
|
53
54
|
return entry;
|
|
54
55
|
});
|
|
55
56
|
export {
|
|
56
|
-
|
|
57
|
+
getSelectedEntries
|
|
57
58
|
};
|
|
@@ -70,7 +70,7 @@ var import_builder = require("../builder");
|
|
|
70
70
|
var import_printInstructions = require("../utils/printInstructions");
|
|
71
71
|
var import_routes = require("../utils/routes");
|
|
72
72
|
var import_config = require("../utils/config");
|
|
73
|
-
var
|
|
73
|
+
var import_getSelectedEntries = require("../utils/getSelectedEntries");
|
|
74
74
|
var import_config2 = require("../config");
|
|
75
75
|
var import_utils2 = require("./utils");
|
|
76
76
|
var import_constants = require("./constants");
|
|
@@ -121,7 +121,6 @@ var analyze_default = () => ({
|
|
|
121
121
|
Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
|
|
122
122
|
]);
|
|
123
123
|
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
124
|
-
const defaultChecked = entrypoints.map((point) => point.entryName);
|
|
125
124
|
debug(`entrypoints: %o`, entrypoints);
|
|
126
125
|
const initialRoutes = getServerRoutes(entrypoints, {
|
|
127
126
|
appContext,
|
|
@@ -147,15 +146,23 @@ var analyze_default = () => ({
|
|
|
147
146
|
debug(`html templates: %o`, htmlTemplates);
|
|
148
147
|
yield hookRunners.addDefineTypes();
|
|
149
148
|
debug(`add Define Types`);
|
|
149
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
150
|
+
if ((0, import_utils.isDevCommand)()) {
|
|
151
|
+
const { entry } = (0, import_utils.minimist)(process.argv.slice(2));
|
|
152
|
+
checkedEntries = yield (0, import_getSelectedEntries.getSelectedEntries)(
|
|
153
|
+
typeof entry === "string" ? entry.split(",") : entry,
|
|
154
|
+
entrypoints
|
|
155
|
+
);
|
|
156
|
+
}
|
|
150
157
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
151
158
|
entrypoints,
|
|
152
|
-
checkedEntries
|
|
159
|
+
checkedEntries,
|
|
153
160
|
apiOnly,
|
|
154
161
|
serverRoutes: routes,
|
|
155
162
|
htmlTemplates
|
|
156
163
|
});
|
|
157
164
|
api.setAppContext(appContext);
|
|
158
|
-
const command = (0,
|
|
165
|
+
const command = (0, import_utils.getCommand)();
|
|
159
166
|
const buildCommands = ["dev", "start", "build", "inspect", "deploy"];
|
|
160
167
|
if (buildCommands.includes(command)) {
|
|
161
168
|
let _b;
|
|
@@ -90,7 +90,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
|
90
90
|
});
|
|
91
91
|
};
|
|
92
92
|
const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
|
|
93
|
-
var _a, _b;
|
|
93
|
+
var _a, _b, _c;
|
|
94
94
|
if (!(yield import_utils.fs.pathExists(dirname))) {
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
@@ -172,6 +172,10 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
172
172
|
if (isPathlessLayout) {
|
|
173
173
|
delete finalRoute.path;
|
|
174
174
|
}
|
|
175
|
+
route.children = (_c = route.children) == null ? void 0 : _c.filter((childRoute) => childRoute);
|
|
176
|
+
if (route.children && route.children.length === 0 && !route.index) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
175
179
|
return finalRoute;
|
|
176
180
|
});
|
|
177
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -151,14 +151,14 @@ function createBuilderOptions(target, appContext) {
|
|
|
151
151
|
function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
152
152
|
return __async(this, null, function* () {
|
|
153
153
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
154
|
-
const {
|
|
155
|
-
builder.addPlugins([
|
|
154
|
+
const { builderPluginNodePolyfill } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
|
|
155
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
156
156
|
}
|
|
157
157
|
if (normalizedConfig.tools.esbuild) {
|
|
158
158
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
159
|
-
const {
|
|
159
|
+
const { builderPluginEsbuild } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
|
|
160
160
|
builder.addPlugins([
|
|
161
|
-
|
|
161
|
+
builderPluginEsbuild({
|
|
162
162
|
loader: false,
|
|
163
163
|
minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
|
|
164
164
|
})
|
|
@@ -58,11 +58,9 @@ __export(dev_exports, {
|
|
|
58
58
|
});
|
|
59
59
|
module.exports = __toCommonJS(dev_exports);
|
|
60
60
|
var import_core = require("@modern-js/core");
|
|
61
|
-
var import_createFileWatcher = require("../utils/createFileWatcher");
|
|
62
61
|
var import_printInstructions = require("../utils/printInstructions");
|
|
63
62
|
var import_createServer = require("../utils/createServer");
|
|
64
63
|
var import_routes = require("../utils/routes");
|
|
65
|
-
var import_getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
|
66
64
|
var import_config = require("../utils/config");
|
|
67
65
|
var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
68
66
|
const dev = (api, options) => __async(void 0, null, function* () {
|
|
@@ -75,22 +73,7 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
75
73
|
const hookRunners = api.useHookRunners();
|
|
76
74
|
normalizedConfig = __spreadProps(__spreadValues({}, normalizedConfig), { cliOptions: options });
|
|
77
75
|
import_core.ResolvedConfigContext.set(normalizedConfig);
|
|
78
|
-
const {
|
|
79
|
-
appDirectory,
|
|
80
|
-
distDirectory,
|
|
81
|
-
port,
|
|
82
|
-
apiOnly,
|
|
83
|
-
entrypoints,
|
|
84
|
-
serverConfigFile
|
|
85
|
-
} = appContext;
|
|
86
|
-
const checkedEntries = yield (0, import_getSpecifiedEntries.getSpecifiedEntries)(
|
|
87
|
-
options.entry || false,
|
|
88
|
-
entrypoints
|
|
89
|
-
);
|
|
90
|
-
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
91
|
-
checkedEntries
|
|
92
|
-
}));
|
|
93
|
-
appContext.checkedEntries = checkedEntries;
|
|
76
|
+
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile } = appContext;
|
|
94
77
|
yield (0, import_config.buildServerConfig)({
|
|
95
78
|
appDirectory,
|
|
96
79
|
distDirectory,
|
|
@@ -136,11 +119,6 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
136
119
|
});
|
|
137
120
|
(0, import_createServer.setServer)(server);
|
|
138
121
|
}
|
|
139
|
-
yield (0, import_createFileWatcher.createFileWatcher)(
|
|
140
|
-
appContext,
|
|
141
|
-
normalizedConfig.source.configDir,
|
|
142
|
-
hookRunners
|
|
143
|
-
);
|
|
144
122
|
});
|
|
145
123
|
// Annotate the CommonJS export names for ESM import in node:
|
|
146
124
|
0 && (module.exports = {
|
package/dist/js/node/hooks.js
CHANGED
|
@@ -42,8 +42,6 @@ const hooks = {
|
|
|
42
42
|
afterBuild: (0, import_plugin.createAsyncWorkflow)(),
|
|
43
43
|
beforeDeploy: (0, import_plugin.createAsyncWorkflow)(),
|
|
44
44
|
afterDeploy: (0, import_plugin.createAsyncWorkflow)(),
|
|
45
|
-
watchFiles: (0, import_plugin.createParallelWorkflow)(),
|
|
46
|
-
fileChange: (0, import_plugin.createAsyncWorkflow)(),
|
|
47
45
|
beforeRestart: (0, import_plugin.createAsyncWorkflow)(),
|
|
48
46
|
registerDev: (0, import_plugin.createParallelWorkflow)(),
|
|
49
47
|
beforeDevTask: (0, import_plugin.createParallelWorkflow)(),
|
package/dist/js/node/index.js
CHANGED
|
@@ -75,8 +75,8 @@ var import_initialize = __toESM(require("./initialize"));
|
|
|
75
75
|
var import_hooks = require("./hooks");
|
|
76
76
|
var import_locale = require("./locale");
|
|
77
77
|
var import_language = require("./utils/language");
|
|
78
|
-
var import_commands = require("./utils/commands");
|
|
79
78
|
var import_restart = require("./utils/restart");
|
|
79
|
+
var import_generateWatchFiles = require("./utils/generateWatchFiles");
|
|
80
80
|
__reExport(src_exports, require("./defineConfig"), module.exports);
|
|
81
81
|
__reExport(src_exports, require("./types"), module.exports);
|
|
82
82
|
const upgradeModel = import_utils.Import.lazy(
|
|
@@ -193,13 +193,20 @@ var src_default = () => ({
|
|
|
193
193
|
},
|
|
194
194
|
prepare() {
|
|
195
195
|
return __async(this, null, function* () {
|
|
196
|
-
const command = (0,
|
|
196
|
+
const command = (0, import_utils.getCommand)();
|
|
197
197
|
if (command === "dev" || command === "start" || command === "build") {
|
|
198
198
|
const appContext = api.useAppContext();
|
|
199
199
|
yield (0, import_utils.emptyDir)(appContext.distDirectory);
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
},
|
|
203
|
+
watchFiles() {
|
|
204
|
+
return __async(this, null, function* () {
|
|
205
|
+
const appContext = api.useAppContext();
|
|
206
|
+
const config = api.useResolvedConfigContext();
|
|
207
|
+
return (0, import_generateWatchFiles.generateWatchFiles)(appContext, config.source.configDir);
|
|
208
|
+
});
|
|
209
|
+
},
|
|
203
210
|
fileChange(e) {
|
|
204
211
|
return __async(this, null, function* () {
|
|
205
212
|
const { filename, eventType } = e;
|
|
@@ -59,7 +59,6 @@ __export(initialize_exports, {
|
|
|
59
59
|
module.exports = __toCommonJS(initialize_exports);
|
|
60
60
|
var import_utils = require("@modern-js/utils");
|
|
61
61
|
var import_schema = require("../schema");
|
|
62
|
-
var import_commands = require("../utils/commands");
|
|
63
62
|
var import_transformNormalizedConfig = require("../config/initial/transformNormalizedConfig");
|
|
64
63
|
var import_config = require("../config");
|
|
65
64
|
var initialize_default = () => ({
|
|
@@ -125,7 +124,7 @@ var initialize_default = () => ({
|
|
|
125
124
|
function getServerPort(config) {
|
|
126
125
|
return __async(this, null, function* () {
|
|
127
126
|
const prodPort = config.server.port || 8080;
|
|
128
|
-
if ((0, import_utils.isDev)() && (0,
|
|
127
|
+
if ((0, import_utils.isDev)() && (0, import_utils.isDevCommand)()) {
|
|
129
128
|
return (0, import_utils.getPort)(config.dev.port || prodPort);
|
|
130
129
|
}
|
|
131
130
|
return prodPort;
|
|
@@ -29,7 +29,9 @@ const EN_LOCALE = {
|
|
|
29
29
|
dev: {
|
|
30
30
|
describe: "start dev server",
|
|
31
31
|
entry: "compiler by entry",
|
|
32
|
-
apiOnly: "start api server only"
|
|
32
|
+
apiOnly: "start api server only",
|
|
33
|
+
selectEntry: "Please select the entry that needs to be built",
|
|
34
|
+
requireEntry: "You must choose at least one entry"
|
|
33
35
|
},
|
|
34
36
|
build: {
|
|
35
37
|
describe: "build application"
|