@modern-js/app-tools 2.1.0 → 2.2.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 +47 -0
- package/dist/js/modern/analyze/index.js +13 -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 +8 -0
- 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 +10 -2
- 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 +8 -0
- 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 +25 -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 +14 -0
- 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/createFileWatcher.js +0 -115
- 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,52 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 12ef50f: feat: `modern-js/core` can watch files change
|
|
8
|
+
feat: `modern-js/core` 可以监听文件变化
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 64ade69: fix(app-tools): dev --entry not work
|
|
13
|
+
|
|
14
|
+
fix(app-tools): 修复 dev --entry 参数不生效的问题
|
|
15
|
+
|
|
16
|
+
- 16bdc0a: chore: adjust builder plugin name
|
|
17
|
+
|
|
18
|
+
chore: 调整 builder 插件命名格式
|
|
19
|
+
|
|
20
|
+
- 19bb384: fix: when a child route does not exist, an empty layout should not be created
|
|
21
|
+
fix: 子路由不存在时,不应该创建空的 layout
|
|
22
|
+
- Updated dependencies [f2f8a83]
|
|
23
|
+
- Updated dependencies [cb12ee7]
|
|
24
|
+
- Updated dependencies [49eff0c]
|
|
25
|
+
- Updated dependencies [2d3e3df]
|
|
26
|
+
- Updated dependencies [360a259]
|
|
27
|
+
- Updated dependencies [9fc6de9]
|
|
28
|
+
- Updated dependencies [d82b621]
|
|
29
|
+
- Updated dependencies [16bdc0a]
|
|
30
|
+
- Updated dependencies [12ef50f]
|
|
31
|
+
- Updated dependencies [19bb384]
|
|
32
|
+
- @modern-js/builder-shared@2.2.0
|
|
33
|
+
- @modern-js/builder-webpack-provider@2.2.0
|
|
34
|
+
- @modern-js/core@2.2.0
|
|
35
|
+
- @modern-js/plugin-data-loader@2.2.0
|
|
36
|
+
- @modern-js/utils@2.2.0
|
|
37
|
+
- @modern-js/prod-server@2.2.0
|
|
38
|
+
- @modern-js/server@2.2.0
|
|
39
|
+
- @modern-js/builder@2.2.0
|
|
40
|
+
- @modern-js/builder-plugin-esbuild@2.2.0
|
|
41
|
+
- @modern-js/builder-plugin-node-polyfill@2.2.0
|
|
42
|
+
- @modern-js/types@2.2.0
|
|
43
|
+
- @modern-js/plugin-lint@2.2.0
|
|
44
|
+
- @modern-js/plugin-i18n@2.2.0
|
|
45
|
+
- @modern-js/new-action@2.2.0
|
|
46
|
+
- @modern-js/node-bundle-require@2.2.0
|
|
47
|
+
- @modern-js/upgrade@2.2.0
|
|
48
|
+
- @modern-js/plugin@2.2.0
|
|
49
|
+
|
|
3
50
|
## 2.1.0
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
|
@@ -43,14 +43,16 @@ import {
|
|
|
43
43
|
findExists,
|
|
44
44
|
fs,
|
|
45
45
|
getEntryOptions,
|
|
46
|
-
isApiOnly
|
|
46
|
+
isApiOnly,
|
|
47
|
+
minimist
|
|
47
48
|
} from "@modern-js/utils";
|
|
48
49
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
49
50
|
import { createBuilderForModern } from "../builder";
|
|
50
51
|
import { printInstructions } from "../utils/printInstructions";
|
|
51
52
|
import { generateRoutes } from "../utils/routes";
|
|
52
53
|
import { emitResolvedConfig } from "../utils/config";
|
|
53
|
-
import { getCommand } from "../utils/commands";
|
|
54
|
+
import { getCommand, isDevCommand } from "../utils/commands";
|
|
55
|
+
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
54
56
|
import { initialNormalizedConfig } from "../config";
|
|
55
57
|
import {
|
|
56
58
|
getServerLoadersFile,
|
|
@@ -110,7 +112,6 @@ var analyze_default = () => ({
|
|
|
110
112
|
import("./getHtmlTemplate")
|
|
111
113
|
]);
|
|
112
114
|
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
113
|
-
const defaultChecked = entrypoints.map((point) => point.entryName);
|
|
114
115
|
debug(`entrypoints: %o`, entrypoints);
|
|
115
116
|
const initialRoutes = getServerRoutes(entrypoints, {
|
|
116
117
|
appContext,
|
|
@@ -136,9 +137,17 @@ var analyze_default = () => ({
|
|
|
136
137
|
debug(`html templates: %o`, htmlTemplates);
|
|
137
138
|
yield hookRunners.addDefineTypes();
|
|
138
139
|
debug(`add Define Types`);
|
|
140
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
141
|
+
if (isDevCommand()) {
|
|
142
|
+
const { entry } = minimist(process.argv.slice(2));
|
|
143
|
+
checkedEntries = yield getSelectedEntries(
|
|
144
|
+
typeof entry === "string" ? entry.split(",") : entry,
|
|
145
|
+
entrypoints
|
|
146
|
+
);
|
|
147
|
+
}
|
|
139
148
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
140
149
|
entrypoints,
|
|
141
|
-
checkedEntries
|
|
150
|
+
checkedEntries,
|
|
142
151
|
apiOnly,
|
|
143
152
|
serverRoutes: routes,
|
|
144
153
|
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
|
@@ -48,6 +48,7 @@ import { i18n, localeKeys } from "./locale";
|
|
|
48
48
|
import { getLocaleLanguage } from "./utils/language";
|
|
49
49
|
import { getCommand } from "./utils/commands";
|
|
50
50
|
import { restart } from "./utils/restart";
|
|
51
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
51
52
|
export * from "./defineConfig";
|
|
52
53
|
export * from "./types";
|
|
53
54
|
const upgradeModel = Import.lazy(
|
|
@@ -171,6 +172,13 @@ var src_default = () => ({
|
|
|
171
172
|
}
|
|
172
173
|
});
|
|
173
174
|
},
|
|
175
|
+
watchFiles() {
|
|
176
|
+
return __async(this, null, function* () {
|
|
177
|
+
const appContext = api.useAppContext();
|
|
178
|
+
const config = api.useResolvedConfigContext();
|
|
179
|
+
return generateWatchFiles(appContext, config.source.configDir);
|
|
180
|
+
});
|
|
181
|
+
},
|
|
174
182
|
fileChange(e) {
|
|
175
183
|
return __async(this, null, function* () {
|
|
176
184
|
const { filename, eventType } = e;
|
|
@@ -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
|
};
|
|
@@ -71,6 +71,7 @@ var import_printInstructions = require("../utils/printInstructions");
|
|
|
71
71
|
var import_routes = require("../utils/routes");
|
|
72
72
|
var import_config = require("../utils/config");
|
|
73
73
|
var import_commands = require("../utils/commands");
|
|
74
|
+
var import_getSelectedEntries = require("../utils/getSelectedEntries");
|
|
74
75
|
var import_config2 = require("../config");
|
|
75
76
|
var import_utils2 = require("./utils");
|
|
76
77
|
var import_constants = require("./constants");
|
|
@@ -121,7 +122,6 @@ var analyze_default = () => ({
|
|
|
121
122
|
Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
|
|
122
123
|
]);
|
|
123
124
|
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
124
|
-
const defaultChecked = entrypoints.map((point) => point.entryName);
|
|
125
125
|
debug(`entrypoints: %o`, entrypoints);
|
|
126
126
|
const initialRoutes = getServerRoutes(entrypoints, {
|
|
127
127
|
appContext,
|
|
@@ -147,9 +147,17 @@ var analyze_default = () => ({
|
|
|
147
147
|
debug(`html templates: %o`, htmlTemplates);
|
|
148
148
|
yield hookRunners.addDefineTypes();
|
|
149
149
|
debug(`add Define Types`);
|
|
150
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
151
|
+
if ((0, import_commands.isDevCommand)()) {
|
|
152
|
+
const { entry } = (0, import_utils.minimist)(process.argv.slice(2));
|
|
153
|
+
checkedEntries = yield (0, import_getSelectedEntries.getSelectedEntries)(
|
|
154
|
+
typeof entry === "string" ? entry.split(",") : entry,
|
|
155
|
+
entrypoints
|
|
156
|
+
);
|
|
157
|
+
}
|
|
150
158
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
151
159
|
entrypoints,
|
|
152
|
-
checkedEntries
|
|
160
|
+
checkedEntries,
|
|
153
161
|
apiOnly,
|
|
154
162
|
serverRoutes: routes,
|
|
155
163
|
htmlTemplates
|
|
@@ -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
|
@@ -77,6 +77,7 @@ var import_locale = require("./locale");
|
|
|
77
77
|
var import_language = require("./utils/language");
|
|
78
78
|
var import_commands = require("./utils/commands");
|
|
79
79
|
var import_restart = require("./utils/restart");
|
|
80
|
+
var import_generateWatchFiles = require("./utils/generateWatchFiles");
|
|
80
81
|
__reExport(src_exports, require("./defineConfig"), module.exports);
|
|
81
82
|
__reExport(src_exports, require("./types"), module.exports);
|
|
82
83
|
const upgradeModel = import_utils.Import.lazy(
|
|
@@ -200,6 +201,13 @@ var src_default = () => ({
|
|
|
200
201
|
}
|
|
201
202
|
});
|
|
202
203
|
},
|
|
204
|
+
watchFiles() {
|
|
205
|
+
return __async(this, null, function* () {
|
|
206
|
+
const appContext = api.useAppContext();
|
|
207
|
+
const config = api.useResolvedConfigContext();
|
|
208
|
+
return (0, import_generateWatchFiles.generateWatchFiles)(appContext, config.source.configDir);
|
|
209
|
+
});
|
|
210
|
+
},
|
|
203
211
|
fileChange(e) {
|
|
204
212
|
return __async(this, null, function* () {
|
|
205
213
|
const { filename, eventType } = e;
|
|
@@ -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"
|
|
@@ -41,20 +41,18 @@ var __async = (__this, __arguments, generator) => {
|
|
|
41
41
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
var
|
|
45
|
-
__export(
|
|
44
|
+
var generateWatchFiles_exports = {};
|
|
45
|
+
__export(generateWatchFiles_exports, {
|
|
46
46
|
addServerConfigToDeps: () => addServerConfigToDeps,
|
|
47
|
-
|
|
47
|
+
generateWatchFiles: () => generateWatchFiles
|
|
48
48
|
});
|
|
49
|
-
module.exports = __toCommonJS(
|
|
50
|
-
var import_crypto = __toESM(require("crypto"));
|
|
51
|
-
var import_fs = __toESM(require("fs"));
|
|
49
|
+
module.exports = __toCommonJS(generateWatchFiles_exports);
|
|
52
50
|
var import_path = __toESM(require("path"));
|
|
53
51
|
var import_utils = require("@modern-js/utils");
|
|
54
52
|
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
55
53
|
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
56
54
|
const json = JSON.parse(
|
|
57
|
-
|
|
55
|
+
import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8")
|
|
58
56
|
);
|
|
59
57
|
return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
60
58
|
};
|
|
@@ -64,14 +62,10 @@ const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) =>
|
|
|
64
62
|
dependencies.push(serverConfig);
|
|
65
63
|
}
|
|
66
64
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const hashMap = /* @__PURE__ */ new Map();
|
|
70
|
-
const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0, null, function* () {
|
|
71
|
-
if ((0, import_utils.isDev)() || (0, import_utils.isTest)()) {
|
|
65
|
+
function generateWatchFiles(appContext, configDir) {
|
|
66
|
+
return __async(this, null, function* () {
|
|
72
67
|
const { appDirectory, configFile } = appContext;
|
|
73
|
-
const
|
|
74
|
-
const configPath = import_path.default.join(appDirectory, configDir);
|
|
68
|
+
const configPath = import_path.default.join(appDirectory, configDir || "");
|
|
75
69
|
const dependencies = getPackageConfig(
|
|
76
70
|
appContext.appDirectory,
|
|
77
71
|
appContext.packageName
|
|
@@ -81,59 +75,11 @@ const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0
|
|
|
81
75
|
appContext.appDirectory,
|
|
82
76
|
appContext.serverConfigFile
|
|
83
77
|
);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
...dependencies,
|
|
88
|
-
configFile
|
|
89
|
-
].filter(Boolean);
|
|
90
|
-
debug(`watched: %o`, watched);
|
|
91
|
-
const watcher = import_utils.chokidar.watch(watched, {
|
|
92
|
-
cwd: appDirectory,
|
|
93
|
-
ignoreInitial: true,
|
|
94
|
-
ignorePermissionErrors: true,
|
|
95
|
-
ignored: [
|
|
96
|
-
/node_modules/,
|
|
97
|
-
"**/__test__/**",
|
|
98
|
-
"**/*.test.(js|jsx|ts|tsx)",
|
|
99
|
-
"**/*.spec.(js|jsx|ts|tsx)",
|
|
100
|
-
"**/*.stories.(js|jsx|ts|tsx)"
|
|
101
|
-
]
|
|
102
|
-
});
|
|
103
|
-
watcher.on("change", (changed) => {
|
|
104
|
-
const lastHash = hashMap.get(changed);
|
|
105
|
-
const currentHash = md5(
|
|
106
|
-
import_fs.default.readFileSync(import_path.default.join(appDirectory, changed), "utf8")
|
|
107
|
-
);
|
|
108
|
-
if (currentHash !== lastHash) {
|
|
109
|
-
debug(`file change: %s`, changed);
|
|
110
|
-
hashMap.set(changed, currentHash);
|
|
111
|
-
hooksRunner.fileChange({ filename: changed, eventType: "change" });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
watcher.on("add", (name) => {
|
|
115
|
-
debug(`add file: %s`, name);
|
|
116
|
-
const currentHash = md5(
|
|
117
|
-
import_fs.default.readFileSync(import_path.default.join(appDirectory, name), "utf8")
|
|
118
|
-
);
|
|
119
|
-
hashMap.set(name, currentHash);
|
|
120
|
-
hooksRunner.fileChange({ filename: name, eventType: "add" });
|
|
121
|
-
});
|
|
122
|
-
watcher.on("unlink", (name) => {
|
|
123
|
-
debug(`remove file: %s`, name);
|
|
124
|
-
if (hashMap.has(name)) {
|
|
125
|
-
hashMap.delete(name);
|
|
126
|
-
}
|
|
127
|
-
hooksRunner.fileChange({ filename: name, eventType: "unlink" });
|
|
128
|
-
});
|
|
129
|
-
watcher.on("error", (err) => {
|
|
130
|
-
throw err;
|
|
131
|
-
});
|
|
132
|
-
return watcher;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
78
|
+
return [`${configPath}/html`, configFile || "./config", ...dependencies];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
135
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
136
82
|
0 && (module.exports = {
|
|
137
83
|
addServerConfigToDeps,
|
|
138
|
-
|
|
84
|
+
generateWatchFiles
|
|
139
85
|
});
|