@modern-js/app-tools 2.0.3-alpha.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 +107 -0
- package/dist/js/modern/analyze/constants.js +1 -1
- package/dist/js/modern/analyze/generateCode.js +4 -12
- package/dist/js/modern/analyze/index.js +28 -7
- package/dist/js/modern/analyze/nestedRoutes.js +5 -1
- package/dist/js/modern/analyze/templates.js +15 -17
- package/dist/js/modern/analyze/utils.js +2 -19
- package/dist/js/modern/builder/index.js +5 -6
- package/dist/js/modern/commands/dev.js +1 -23
- package/dist/js/modern/config/default.js +3 -1
- package/dist/js/modern/hooks.js +0 -2
- package/dist/js/modern/index.js +8 -0
- package/dist/js/modern/initialize/index.js +7 -7
- 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/constants.js +1 -1
- package/dist/js/node/analyze/generateCode.js +3 -7
- package/dist/js/node/analyze/index.js +19 -5
- package/dist/js/node/analyze/nestedRoutes.js +5 -1
- package/dist/js/node/analyze/templates.js +15 -17
- package/dist/js/node/analyze/utils.js +1 -18
- package/dist/js/node/builder/index.js +5 -6
- package/dist/js/node/commands/dev.js +1 -23
- package/dist/js/node/config/default.js +3 -1
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +8 -0
- package/dist/js/node/initialize/index.js +7 -7
- 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/constants.js +1 -1
- package/dist/js/treeshaking/analyze/generateCode.js +5 -8
- package/dist/js/treeshaking/analyze/index.js +29 -14
- package/dist/js/treeshaking/analyze/nestedRoutes.js +12 -3
- package/dist/js/treeshaking/analyze/templates.js +10 -9
- package/dist/js/treeshaking/analyze/utils.js +2 -11
- package/dist/js/treeshaking/builder/index.js +6 -7
- package/dist/js/treeshaking/commands/dev.js +13 -31
- package/dist/js/treeshaking/config/default.js +3 -1
- package/dist/js/treeshaking/hooks.js +0 -2
- package/dist/js/treeshaking/index.js +14 -0
- package/dist/js/treeshaking/initialize/index.js +19 -42
- 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/analyze/constants.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +2 -8
- package/dist/types/analyze/utils.d.ts +0 -1
- 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/config/dev.d.ts +1 -1
- 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/lib/types.d.ts +6 -2
- package/package.json +24 -24
- 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
|
@@ -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
|
};
|
|
@@ -68,7 +68,7 @@ const NESTED_ROUTE = {
|
|
|
68
68
|
ERROR_FILE: "error",
|
|
69
69
|
LOADER_FILE: "loader"
|
|
70
70
|
};
|
|
71
|
-
const APP_CONFIG_NAME = "
|
|
71
|
+
const APP_CONFIG_NAME = "config";
|
|
72
72
|
const APP_INIT_EXPORTED = "init";
|
|
73
73
|
const APP_INIT_IMPORTED = "appInit";
|
|
74
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -106,7 +106,6 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
106
106
|
var _a, _b, _c;
|
|
107
107
|
const {
|
|
108
108
|
internalDirectory,
|
|
109
|
-
distDirectory,
|
|
110
109
|
srcDirectory,
|
|
111
110
|
internalDirAlias,
|
|
112
111
|
internalSrcAlias,
|
|
@@ -187,19 +186,16 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
187
186
|
ssrMode: mode,
|
|
188
187
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
189
188
|
entryName: entrypoint.entryName,
|
|
190
|
-
internalDirectory
|
|
191
|
-
internalDirAlias
|
|
189
|
+
internalDirectory
|
|
192
190
|
})
|
|
193
191
|
});
|
|
194
|
-
if (entrypoint.nestedRoutesEntry) {
|
|
192
|
+
if (entrypoint.nestedRoutesEntry && mode) {
|
|
195
193
|
const routesServerFile = (0, import_utils2.getServerLoadersFile)(
|
|
196
194
|
internalDirectory,
|
|
197
195
|
entryName
|
|
198
196
|
);
|
|
199
197
|
const code3 = templates.routesForServer({
|
|
200
|
-
routes
|
|
201
|
-
internalDirectory,
|
|
202
|
-
entryName
|
|
198
|
+
routes
|
|
203
199
|
});
|
|
204
200
|
yield import_utils.fs.ensureFile(routesServerFile);
|
|
205
201
|
yield import_utils.fs.writeFile(routesServerFile, code3);
|
|
@@ -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
|
|
@@ -226,13 +234,19 @@ var analyze_default = () => ({
|
|
|
226
234
|
config() {
|
|
227
235
|
return {
|
|
228
236
|
tools: {
|
|
229
|
-
webpackChain: (chain, { name
|
|
237
|
+
webpackChain: (chain, { name }) => {
|
|
230
238
|
const appContext = api.useAppContext();
|
|
231
239
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
232
|
-
const { entrypoints, internalDirectory } = appContext;
|
|
240
|
+
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
233
241
|
entrypoints.forEach((entrypoint) => {
|
|
234
242
|
const { entryName } = entrypoint;
|
|
235
|
-
|
|
243
|
+
const ssr = (0, import_utils.getEntryOptions)(
|
|
244
|
+
entryName,
|
|
245
|
+
resolvedConfig.server.ssr,
|
|
246
|
+
resolvedConfig.server.ssrByEntries,
|
|
247
|
+
packageName
|
|
248
|
+
);
|
|
249
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
236
250
|
const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
|
|
237
251
|
internalDirectory,
|
|
238
252
|
entryName
|
|
@@ -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:
|
|
@@ -102,7 +102,7 @@ const renderFunction = ({
|
|
|
102
102
|
return `
|
|
103
103
|
const finalAppConfig = {
|
|
104
104
|
...App.config,
|
|
105
|
-
...typeof ${import_constants.APP_CONFIG_NAME} === '
|
|
105
|
+
...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
AppWrapper = createApp({
|
|
@@ -157,17 +157,9 @@ const html = (partials) => `
|
|
|
157
157
|
</html>
|
|
158
158
|
`;
|
|
159
159
|
const routesForServer = ({
|
|
160
|
-
routes
|
|
161
|
-
internalDirectory,
|
|
162
|
-
entryName
|
|
160
|
+
routes
|
|
163
161
|
}) => {
|
|
164
162
|
const loaders = [];
|
|
165
|
-
const loaderIndexFile = import_path.default.join(
|
|
166
|
-
internalDirectory,
|
|
167
|
-
entryName,
|
|
168
|
-
import_constants.TEMP_LOADERS_DIR,
|
|
169
|
-
"index.js"
|
|
170
|
-
);
|
|
171
163
|
const traverseRouteTree = (route) => {
|
|
172
164
|
var _a;
|
|
173
165
|
let children;
|
|
@@ -206,7 +198,7 @@ const routesForServer = ({
|
|
|
206
198
|
let importLoadersCode = "";
|
|
207
199
|
if (loaders.length > 0) {
|
|
208
200
|
importLoadersCode = loaders.map((loader, index2) => {
|
|
209
|
-
return `import loader_${index2} from "${loader}"`;
|
|
201
|
+
return `import loader_${index2} from "${(0, import_utils.slash)(loader)}"`;
|
|
210
202
|
}).join("\n");
|
|
211
203
|
}
|
|
212
204
|
return `
|
|
@@ -219,8 +211,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
219
211
|
ssrMode,
|
|
220
212
|
nestedRoutesEntry,
|
|
221
213
|
entryName,
|
|
222
|
-
internalDirectory
|
|
223
|
-
internalDirAlias
|
|
214
|
+
internalDirectory
|
|
224
215
|
}) {
|
|
225
216
|
const loadings = [];
|
|
226
217
|
const errors = [];
|
|
@@ -239,11 +230,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
239
230
|
let rootLayoutCode = ``;
|
|
240
231
|
let componentLoaderPath = "";
|
|
241
232
|
const getDataLoaderPath = (loaderId) => {
|
|
242
|
-
if (!ssrMode)
|
|
233
|
+
if (!ssrMode) {
|
|
243
234
|
return "";
|
|
235
|
+
}
|
|
244
236
|
let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
245
237
|
if (nestedRoutesEntry) {
|
|
246
|
-
dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(
|
|
238
|
+
dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(
|
|
239
|
+
loadersMapFile
|
|
240
|
+
)}&loaderId=${loaderId}!`;
|
|
247
241
|
}
|
|
248
242
|
return dataLoaderPath;
|
|
249
243
|
};
|
|
@@ -339,10 +333,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
339
333
|
let importLoadersCode = "";
|
|
340
334
|
for (const [key, loaderInfo] of Object.entries(loadersMap)) {
|
|
341
335
|
if (loaderInfo.inline) {
|
|
342
|
-
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
336
|
+
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
337
|
+
key
|
|
338
|
+
)}${(0, import_utils.slash)(loaderInfo.filePath)}";
|
|
343
339
|
`;
|
|
344
340
|
} else {
|
|
345
|
-
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
341
|
+
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
342
|
+
key
|
|
343
|
+
)}${(0, import_utils.slash)(loaderInfo.filePath)}";
|
|
346
344
|
`;
|
|
347
345
|
}
|
|
348
346
|
}
|
|
@@ -46,7 +46,6 @@ __export(utils_exports, {
|
|
|
46
46
|
getDefaultImports: () => getDefaultImports,
|
|
47
47
|
getServerLoadersFile: () => getServerLoadersFile,
|
|
48
48
|
hasLoader: () => hasLoader,
|
|
49
|
-
isNestedRouteComponent: () => isNestedRouteComponent,
|
|
50
49
|
isPageComponentFile: () => isPageComponentFile,
|
|
51
50
|
parseModule: () => parseModule,
|
|
52
51
|
replaceWithAlias: () => replaceWithAlias,
|
|
@@ -135,17 +134,6 @@ const isPageComponentFile = (filePath) => {
|
|
|
135
134
|
}
|
|
136
135
|
return false;
|
|
137
136
|
};
|
|
138
|
-
const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
|
|
139
|
-
const reg = new RegExp(
|
|
140
|
-
`(${import_constants.NESTED_ROUTE.LAYOUT_FILE}|${import_constants.NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
|
|
141
|
-
);
|
|
142
|
-
return nestedRouteEntries.some((nestedRoutesEntry) => {
|
|
143
|
-
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
137
|
const replaceWithAlias = (base, filePath, alias) => (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
|
|
150
138
|
const parseModule = (_0) => __async(void 0, [_0], function* ({
|
|
151
139
|
source,
|
|
@@ -170,18 +158,13 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
|
|
|
170
158
|
return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
|
|
171
159
|
});
|
|
172
160
|
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
173
|
-
return import_path.default.join(
|
|
174
|
-
internalDirectory,
|
|
175
|
-
entryName,
|
|
176
|
-
"route-server-loaders.js"
|
|
177
|
-
);
|
|
161
|
+
return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
178
162
|
};
|
|
179
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
180
164
|
0 && (module.exports = {
|
|
181
165
|
getDefaultImports,
|
|
182
166
|
getServerLoadersFile,
|
|
183
167
|
hasLoader,
|
|
184
|
-
isNestedRouteComponent,
|
|
185
168
|
isPageComponentFile,
|
|
186
169
|
parseModule,
|
|
187
170
|
replaceWithAlias,
|
|
@@ -104,7 +104,6 @@ function createBuilderForModern(_0) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
107
|
-
var _a;
|
|
108
107
|
const output = createOutputConfig(normalizedConfig, appContext);
|
|
109
108
|
const htmlConfig = __spreadValues({}, normalizedConfig.html);
|
|
110
109
|
if (!htmlConfig.template) {
|
|
@@ -113,7 +112,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
113
112
|
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
114
113
|
output,
|
|
115
114
|
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
116
|
-
port:
|
|
115
|
+
port: appContext.port
|
|
117
116
|
}),
|
|
118
117
|
html: htmlConfig
|
|
119
118
|
});
|
|
@@ -152,14 +151,14 @@ function createBuilderOptions(target, appContext) {
|
|
|
152
151
|
function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
153
152
|
return __async(this, null, function* () {
|
|
154
153
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
155
|
-
const {
|
|
156
|
-
builder.addPlugins([
|
|
154
|
+
const { builderPluginNodePolyfill } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
|
|
155
|
+
builder.addPlugins([builderPluginNodePolyfill()]);
|
|
157
156
|
}
|
|
158
157
|
if (normalizedConfig.tools.esbuild) {
|
|
159
158
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
160
|
-
const {
|
|
159
|
+
const { builderPluginEsbuild } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
|
|
161
160
|
builder.addPlugins([
|
|
162
|
-
|
|
161
|
+
builderPluginEsbuild({
|
|
163
162
|
loader: false,
|
|
164
163
|
minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
|
|
165
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 = {
|
|
@@ -41,7 +41,9 @@ module.exports = __toCommonJS(default_exports);
|
|
|
41
41
|
var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
|
|
42
42
|
function createDefaultConfig(appContext) {
|
|
43
43
|
const defaultBuilderConfig = (0, import_builder_webpack_provider.createDefaultConfig)();
|
|
44
|
-
const dev = __spreadValues({}, defaultBuilderConfig.dev)
|
|
44
|
+
const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
|
|
45
|
+
port: void 0
|
|
46
|
+
});
|
|
45
47
|
const tools = __spreadValues({}, defaultBuilderConfig.tools);
|
|
46
48
|
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
47
49
|
disableNodePolyfill: true
|
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;
|
|
@@ -80,10 +80,10 @@ var initialize_default = () => ({
|
|
|
80
80
|
validateSchema,
|
|
81
81
|
resolvedConfig(_0) {
|
|
82
82
|
return __async(this, arguments, function* ({ resolved }) {
|
|
83
|
-
var _a2
|
|
83
|
+
var _a2;
|
|
84
84
|
let appContext = api.useAppContext();
|
|
85
85
|
const userConfig = api.useConfigContext();
|
|
86
|
-
const port = yield
|
|
86
|
+
const port = yield getServerPort(resolved);
|
|
87
87
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
88
88
|
port,
|
|
89
89
|
distDirectory: (0, import_utils.ensureAbsolutePath)(
|
|
@@ -98,7 +98,7 @@ var initialize_default = () => ({
|
|
|
98
98
|
_raw: userConfig,
|
|
99
99
|
source: normalizedConfig.source || {},
|
|
100
100
|
server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
|
|
101
|
-
port
|
|
101
|
+
port
|
|
102
102
|
}),
|
|
103
103
|
bff: normalizedConfig.bff || {},
|
|
104
104
|
dev: normalizedConfig.dev || {},
|
|
@@ -122,13 +122,13 @@ var initialize_default = () => ({
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
|
-
function
|
|
125
|
+
function getServerPort(config) {
|
|
126
126
|
return __async(this, null, function* () {
|
|
127
|
-
|
|
127
|
+
const prodPort = config.server.port || 8080;
|
|
128
128
|
if ((0, import_utils.isDev)() && (0, import_commands.isDevCommand)()) {
|
|
129
|
-
return (
|
|
129
|
+
return (0, import_utils.getPort)(config.dev.port || prodPort);
|
|
130
130
|
}
|
|
131
|
-
return
|
|
131
|
+
return prodPort;
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -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
|
});
|
|
@@ -35,13 +35,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
35
35
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
|
-
var
|
|
39
|
-
__export(
|
|
40
|
-
|
|
38
|
+
var getSelectedEntries_exports = {};
|
|
39
|
+
__export(getSelectedEntries_exports, {
|
|
40
|
+
getSelectedEntries: () => getSelectedEntries
|
|
41
41
|
});
|
|
42
|
-
module.exports = __toCommonJS(
|
|
42
|
+
module.exports = __toCommonJS(getSelectedEntries_exports);
|
|
43
43
|
var import_utils = require("@modern-js/utils");
|
|
44
|
-
|
|
44
|
+
var import_locale = require("../locale");
|
|
45
|
+
const getSelectedEntries = (entry, entrypoints) => __async(void 0, null, function* () {
|
|
45
46
|
const entryNames = entrypoints.map((e) => e.entryName);
|
|
46
47
|
if (!entry) {
|
|
47
48
|
return entryNames;
|
|
@@ -52,10 +53,10 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
52
53
|
type: "checkbox",
|
|
53
54
|
name: "selected",
|
|
54
55
|
choices: entryNames,
|
|
55
|
-
message:
|
|
56
|
+
message: import_locale.i18n.t(import_locale.localeKeys.command.dev.selectEntry),
|
|
56
57
|
validate(answer) {
|
|
57
58
|
if (answer.length < 1) {
|
|
58
|
-
return
|
|
59
|
+
return import_locale.i18n.t(import_locale.localeKeys.command.dev.requireEntry);
|
|
59
60
|
}
|
|
60
61
|
return true;
|
|
61
62
|
}
|
|
@@ -66,9 +67,9 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
66
67
|
entry.forEach((name) => {
|
|
67
68
|
if (!entryNames.includes(name)) {
|
|
68
69
|
throw new Error(
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
)}`
|
|
70
|
+
`Can not found entry ${import_utils.chalk.yellow(
|
|
71
|
+
name
|
|
72
|
+
)}, the entry should be one of ${import_utils.chalk.yellow(entryNames.join(", "))}`
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
75
|
});
|
|
@@ -76,5 +77,5 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
|
|
|
76
77
|
});
|
|
77
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
79
|
0 && (module.exports = {
|
|
79
|
-
|
|
80
|
+
getSelectedEntries
|
|
80
81
|
});
|
|
@@ -34,7 +34,7 @@ var NESTED_ROUTE = {
|
|
|
34
34
|
ERROR_FILE: "error",
|
|
35
35
|
LOADER_FILE: "loader"
|
|
36
36
|
};
|
|
37
|
-
var APP_CONFIG_NAME = "
|
|
37
|
+
var APP_CONFIG_NAME = "config";
|
|
38
38
|
var APP_INIT_EXPORTED = "init";
|
|
39
39
|
var APP_INIT_IMPORTED = "appInit";
|
|
40
40
|
export { APP_CONFIG_NAME, APP_FILE_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
|