@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
|
@@ -240,7 +240,7 @@ var createImportStatements = function(statements) {
|
|
|
240
240
|
};
|
|
241
241
|
var generateCode = function() {
|
|
242
242
|
var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
|
|
243
|
-
var ref, ref1, ref2, internalDirectory,
|
|
243
|
+
var ref, ref1, ref2, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
|
|
244
244
|
function generateEntryCode(entrypoint) {
|
|
245
245
|
return _generateEntryCode.apply(this, arguments);
|
|
246
246
|
}
|
|
@@ -335,8 +335,7 @@ var generateCode = function() {
|
|
|
335
335
|
ssrMode: mode,
|
|
336
336
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
337
337
|
entryName: entrypoint.entryName,
|
|
338
|
-
internalDirectory: internalDirectory
|
|
339
|
-
internalDirAlias: internalDirAlias
|
|
338
|
+
internalDirectory: internalDirectory
|
|
340
339
|
})
|
|
341
340
|
];
|
|
342
341
|
case 5:
|
|
@@ -348,15 +347,13 @@ var generateCode = function() {
|
|
|
348
347
|
];
|
|
349
348
|
case 6:
|
|
350
349
|
ref = _state.sent(), code2 = ref.code;
|
|
351
|
-
if (!entrypoint.nestedRoutesEntry) return [
|
|
350
|
+
if (!(entrypoint.nestedRoutesEntry && mode)) return [
|
|
352
351
|
3,
|
|
353
352
|
9
|
|
354
353
|
];
|
|
355
354
|
routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
356
355
|
code3 = templates.routesForServer({
|
|
357
|
-
routes: routes
|
|
358
|
-
internalDirectory: internalDirectory,
|
|
359
|
-
entryName: entryName
|
|
356
|
+
routes: routes
|
|
360
357
|
});
|
|
361
358
|
return [
|
|
362
359
|
4,
|
|
@@ -464,7 +461,7 @@ var generateCode = function() {
|
|
|
464
461
|
return __generator(this, function(_state) {
|
|
465
462
|
switch(_state.label){
|
|
466
463
|
case 0:
|
|
467
|
-
internalDirectory = appContext.internalDirectory,
|
|
464
|
+
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
|
468
465
|
hookRunners = api.useHookRunners();
|
|
469
466
|
isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
|
|
470
467
|
mountId = config.html.mountId;
|
|
@@ -221,13 +221,14 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import * as path from "path";
|
|
224
|
-
import { createDebugger, findExists, fs, isApiOnly,
|
|
224
|
+
import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
226
|
import { createBuilderForModern } from "../builder";
|
|
227
227
|
import { printInstructions } from "../utils/printInstructions";
|
|
228
228
|
import { generateRoutes } from "../utils/routes";
|
|
229
229
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
|
-
import { getCommand } from "../utils/commands";
|
|
230
|
+
import { getCommand, isDevCommand } from "../utils/commands";
|
|
231
|
+
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
231
232
|
import { initialNormalizedConfig } from "../config";
|
|
232
233
|
import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
233
234
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
@@ -242,7 +243,7 @@ var analyze_default = function() {
|
|
|
242
243
|
return {
|
|
243
244
|
prepare: function prepare() {
|
|
244
245
|
return _asyncToGenerator(function() {
|
|
245
|
-
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints,
|
|
246
|
+
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, builder;
|
|
246
247
|
return __generator(this, function(_state) {
|
|
247
248
|
switch(_state.label){
|
|
248
249
|
case 0:
|
|
@@ -301,9 +302,6 @@ var analyze_default = function() {
|
|
|
301
302
|
4
|
|
302
303
|
]), getBundleEntry = ref2[0].getBundleEntry, getServerRoutes = ref2[1].getServerRoutes, generateCode = ref2[2].generateCode, getHtmlTemplate = ref2[3].getHtmlTemplate;
|
|
303
304
|
entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
304
|
-
defaultChecked = entrypoints.map(function(point) {
|
|
305
|
-
return point.entryName;
|
|
306
|
-
});
|
|
307
305
|
debug("entrypoints: %o", entrypoints);
|
|
308
306
|
initialRoutes = getServerRoutes(entrypoints, {
|
|
309
307
|
appContext: appContext,
|
|
@@ -353,9 +351,25 @@ var analyze_default = function() {
|
|
|
353
351
|
case 9:
|
|
354
352
|
_state.sent();
|
|
355
353
|
debug("add Define Types");
|
|
354
|
+
checkedEntries = entrypoints.map(function(point) {
|
|
355
|
+
return point.entryName;
|
|
356
|
+
});
|
|
357
|
+
if (!isDevCommand()) return [
|
|
358
|
+
3,
|
|
359
|
+
11
|
|
360
|
+
];
|
|
361
|
+
entry = minimist(process.argv.slice(2)).entry;
|
|
362
|
+
return [
|
|
363
|
+
4,
|
|
364
|
+
getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
|
|
365
|
+
];
|
|
366
|
+
case 10:
|
|
367
|
+
checkedEntries = _state.sent();
|
|
368
|
+
_state.label = 11;
|
|
369
|
+
case 11:
|
|
356
370
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
357
371
|
entrypoints: entrypoints,
|
|
358
|
-
checkedEntries:
|
|
372
|
+
checkedEntries: checkedEntries,
|
|
359
373
|
apiOnly: apiOnly,
|
|
360
374
|
serverRoutes: routes,
|
|
361
375
|
htmlTemplates: htmlTemplates
|
|
@@ -371,7 +385,7 @@ var analyze_default = function() {
|
|
|
371
385
|
];
|
|
372
386
|
if (!buildCommands.includes(command)) return [
|
|
373
387
|
3,
|
|
374
|
-
|
|
388
|
+
13
|
|
375
389
|
];
|
|
376
390
|
normalizedConfig = api.useResolvedConfigContext();
|
|
377
391
|
return [
|
|
@@ -505,15 +519,15 @@ var analyze_default = function() {
|
|
|
505
519
|
}
|
|
506
520
|
})
|
|
507
521
|
];
|
|
508
|
-
case
|
|
522
|
+
case 12:
|
|
509
523
|
builder = _state.sent();
|
|
510
524
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
511
525
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
512
526
|
builder: builder
|
|
513
527
|
});
|
|
514
528
|
api.setAppContext(appContext);
|
|
515
|
-
_state.label =
|
|
516
|
-
case
|
|
529
|
+
_state.label = 13;
|
|
530
|
+
case 13:
|
|
517
531
|
return [
|
|
518
532
|
2
|
|
519
533
|
];
|
|
@@ -528,13 +542,14 @@ var analyze_default = function() {
|
|
|
528
542
|
return {
|
|
529
543
|
tools: {
|
|
530
544
|
webpackChain: function(chain, param) {
|
|
531
|
-
var name = param.name
|
|
545
|
+
var name = param.name;
|
|
532
546
|
var appContext = api.useAppContext();
|
|
533
547
|
var resolvedConfig = api.useResolvedConfigContext();
|
|
534
|
-
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory;
|
|
548
|
+
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory, packageName = appContext.packageName;
|
|
535
549
|
entrypoints.forEach(function(entrypoint) {
|
|
536
550
|
var entryName = entrypoint.entryName;
|
|
537
|
-
|
|
551
|
+
var ssr = getEntryOptions(entryName, resolvedConfig.server.ssr, resolvedConfig.server.ssrByEntries, packageName);
|
|
552
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
538
553
|
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
539
554
|
chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
|
|
540
555
|
}
|
|
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
|
197
197
|
};
|
|
198
198
|
var walk = function() {
|
|
199
199
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
|
200
|
-
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute,
|
|
200
|
+
var ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, err, finalRoute;
|
|
201
201
|
return __generator(this, function(_state) {
|
|
202
202
|
switch(_state.label){
|
|
203
203
|
case 0:
|
|
@@ -286,7 +286,7 @@ var walk = function() {
|
|
|
286
286
|
childRoute = _state.sent();
|
|
287
287
|
if (childRoute) {
|
|
288
288
|
;
|
|
289
|
-
(
|
|
289
|
+
(ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(childRoute);
|
|
290
290
|
}
|
|
291
291
|
_state.label = 8;
|
|
292
292
|
case 8:
|
|
@@ -315,7 +315,7 @@ var walk = function() {
|
|
|
315
315
|
if (pageLoaderFile) {
|
|
316
316
|
pageRoute.loader = pageLoaderFile;
|
|
317
317
|
}
|
|
318
|
-
(
|
|
318
|
+
(ref2 = route.children) === null || ref2 === void 0 ? void 0 : ref2.push(pageRoute);
|
|
319
319
|
}
|
|
320
320
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
321
321
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
@@ -361,6 +361,15 @@ var walk = function() {
|
|
|
361
361
|
if (isPathlessLayout) {
|
|
362
362
|
delete finalRoute.path;
|
|
363
363
|
}
|
|
364
|
+
route.children = (ref = route.children) === null || ref === void 0 ? void 0 : ref.filter(function(childRoute) {
|
|
365
|
+
return childRoute;
|
|
366
|
+
});
|
|
367
|
+
if (route.children && route.children.length === 0 && !route.index) {
|
|
368
|
+
return [
|
|
369
|
+
2,
|
|
370
|
+
null
|
|
371
|
+
];
|
|
372
|
+
}
|
|
364
373
|
return [
|
|
365
374
|
2,
|
|
366
375
|
finalRoute
|
|
@@ -229,7 +229,7 @@ var index = function(param) {
|
|
|
229
229
|
};
|
|
230
230
|
var renderFunction = function(param) {
|
|
231
231
|
var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes2 = param.fileSystemRoutes;
|
|
232
|
-
return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === '
|
|
232
|
+
return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param) {
|
|
233
233
|
var name = param.name, options = param.options, args = param.args;
|
|
234
234
|
return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
|
|
235
235
|
}).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
|
|
@@ -238,9 +238,8 @@ var html = function(partials) {
|
|
|
238
238
|
return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join("\n"), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join("\n"), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\n <div id=\"<%= mountId %>\"><!--<?- html ?>--></div>\n ").concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
|
|
239
239
|
};
|
|
240
240
|
var routesForServer = function(param) {
|
|
241
|
-
var routes = param.routes
|
|
241
|
+
var routes = param.routes;
|
|
242
242
|
var loaders = [];
|
|
243
|
-
var loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
|
|
244
243
|
var traverseRouteTree = function(route) {
|
|
245
244
|
var children;
|
|
246
245
|
if ("children" in route && route.children) {
|
|
@@ -290,18 +289,18 @@ var routesForServer = function(param) {
|
|
|
290
289
|
var importLoadersCode = "";
|
|
291
290
|
if (loaders.length > 0) {
|
|
292
291
|
importLoadersCode = loaders.map(function(loader, index2) {
|
|
293
|
-
return "import loader_".concat(index2, ' from "').concat(loader, '"');
|
|
292
|
+
return "import loader_".concat(index2, ' from "').concat(slash(loader), '"');
|
|
294
293
|
}).join("\n");
|
|
295
294
|
}
|
|
296
295
|
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
|
297
296
|
};
|
|
298
297
|
var fileSystemRoutes = function() {
|
|
299
298
|
var _ref = _asyncToGenerator(function(param) {
|
|
300
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory,
|
|
299
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, componentLoaderPath, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _value, key, loaderInfo;
|
|
301
300
|
return __generator(this, function(_state) {
|
|
302
301
|
switch(_state.label){
|
|
303
302
|
case 0:
|
|
304
|
-
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory
|
|
303
|
+
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
|
|
305
304
|
loadings = [];
|
|
306
305
|
errors = [];
|
|
307
306
|
loaders = [];
|
|
@@ -311,7 +310,9 @@ var fileSystemRoutes = function() {
|
|
|
311
310
|
rootLayoutCode = "";
|
|
312
311
|
componentLoaderPath = "";
|
|
313
312
|
getDataLoaderPath = function(loaderId) {
|
|
314
|
-
if (!ssrMode)
|
|
313
|
+
if (!ssrMode) {
|
|
314
|
+
return "";
|
|
315
|
+
}
|
|
315
316
|
var dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
316
317
|
if (nestedRoutesEntry) {
|
|
317
318
|
dataLoaderPath = "".concat(slash(dataLoaderPath), "?mapFile=").concat(slash(loadersMapFile), "&loaderId=").concat(loaderId, "!");
|
|
@@ -422,9 +423,9 @@ var fileSystemRoutes = function() {
|
|
|
422
423
|
for(_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
423
424
|
_value = _slicedToArray(_step1.value, 2), key = _value[0], loaderInfo = _value[1];
|
|
424
425
|
if (loaderInfo.inline) {
|
|
425
|
-
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(loaderInfo.filePath, '";\n');
|
|
426
|
+
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
|
|
426
427
|
} else {
|
|
427
|
-
importLoadersCode += "import ".concat(key, ' from "').concat(getDataLoaderPath(key)).concat(loaderInfo.filePath, '";\n');
|
|
428
|
+
importLoadersCode += "import ".concat(key, ' from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
|
|
428
429
|
}
|
|
429
430
|
}
|
|
430
431
|
} catch (err) {
|
|
@@ -185,7 +185,7 @@ import path from "path";
|
|
|
185
185
|
import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
|
|
186
186
|
import { transform } from "esbuild";
|
|
187
187
|
import { parse } from "es-module-lexer";
|
|
188
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME
|
|
188
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME } from "./constants";
|
|
189
189
|
var walkDirectory = function(dir) {
|
|
190
190
|
return fs.readdirSync(dir).reduce(function(previous, filename) {
|
|
191
191
|
var filePath = path.join(dir, filename);
|
|
@@ -286,15 +286,6 @@ var isPageComponentFile = function(filePath) {
|
|
|
286
286
|
}
|
|
287
287
|
return false;
|
|
288
288
|
};
|
|
289
|
-
var isNestedRouteComponent = function(nestedRouteEntries, absoluteFilePath) {
|
|
290
|
-
var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, ")\\.tsx?$"));
|
|
291
|
-
return nestedRouteEntries.some(function(nestedRoutesEntry) {
|
|
292
|
-
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
return false;
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
289
|
var replaceWithAlias = function(base, filePath, alias) {
|
|
299
290
|
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
300
291
|
};
|
|
@@ -380,4 +371,4 @@ var hasLoader = function() {
|
|
|
380
371
|
var getServerLoadersFile = function(internalDirectory, entryName) {
|
|
381
372
|
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
382
373
|
};
|
|
383
|
-
export { getDefaultImports, getServerLoadersFile, hasLoader,
|
|
374
|
+
export { getDefaultImports, getServerLoadersFile, hasLoader, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -264,7 +264,6 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
264
264
|
cleanDistPath: false
|
|
265
265
|
});
|
|
266
266
|
};
|
|
267
|
-
var ref;
|
|
268
267
|
var output = createOutputConfig(normalizedConfig, appContext);
|
|
269
268
|
var htmlConfig = _objectSpread({}, normalizedConfig.html);
|
|
270
269
|
if (!htmlConfig.template) {
|
|
@@ -273,7 +272,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
273
272
|
return _objectSpreadProps(_objectSpread({}, normalizedConfig), {
|
|
274
273
|
output: output,
|
|
275
274
|
dev: _objectSpreadProps(_objectSpread({}, normalizedConfig.dev), {
|
|
276
|
-
port:
|
|
275
|
+
port: appContext.port
|
|
277
276
|
}),
|
|
278
277
|
html: htmlConfig
|
|
279
278
|
});
|
|
@@ -323,7 +322,7 @@ function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPlugin
|
|
|
323
322
|
}
|
|
324
323
|
function _applyBuilderPlugins() {
|
|
325
324
|
_applyBuilderPlugins = _asyncToGenerator(function(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
326
|
-
var
|
|
325
|
+
var builderPluginNodePolyfill, _tools, esbuildOptions, builderPluginEsbuild;
|
|
327
326
|
return __generator(this, function(_state) {
|
|
328
327
|
switch(_state.label){
|
|
329
328
|
case 0:
|
|
@@ -336,9 +335,9 @@ function _applyBuilderPlugins() {
|
|
|
336
335
|
import("@modern-js/builder-plugin-node-polyfill")
|
|
337
336
|
];
|
|
338
337
|
case 1:
|
|
339
|
-
|
|
338
|
+
builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
|
|
340
339
|
builder.addPlugins([
|
|
341
|
-
|
|
340
|
+
builderPluginNodePolyfill()
|
|
342
341
|
]);
|
|
343
342
|
_state.label = 2;
|
|
344
343
|
case 2:
|
|
@@ -352,9 +351,9 @@ function _applyBuilderPlugins() {
|
|
|
352
351
|
import("@modern-js/builder-plugin-esbuild")
|
|
353
352
|
];
|
|
354
353
|
case 3:
|
|
355
|
-
|
|
354
|
+
builderPluginEsbuild = _state.sent().builderPluginEsbuild;
|
|
356
355
|
builder.addPlugins([
|
|
357
|
-
|
|
356
|
+
builderPluginEsbuild({
|
|
358
357
|
loader: false,
|
|
359
358
|
minimize: applyOptionsChain({}, esbuildOptions)
|
|
360
359
|
})
|
|
@@ -175,16 +175,14 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
178
|
-
import { createFileWatcher } from "../utils/createFileWatcher";
|
|
179
178
|
import { printInstructions } from "../utils/printInstructions";
|
|
180
179
|
import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
|
|
181
180
|
import { generateRoutes } from "../utils/routes";
|
|
182
|
-
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
183
181
|
import { buildServerConfig } from "../utils/config";
|
|
184
182
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
185
183
|
var dev = function() {
|
|
186
184
|
var _ref = _asyncToGenerator(function(api, options) {
|
|
187
|
-
var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly,
|
|
185
|
+
var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, app, server;
|
|
188
186
|
return __generator(this, function(_state) {
|
|
189
187
|
switch(_state.label){
|
|
190
188
|
case 0:
|
|
@@ -198,17 +196,7 @@ var dev = function() {
|
|
|
198
196
|
cliOptions: options
|
|
199
197
|
});
|
|
200
198
|
ResolvedConfigContext.set(normalizedConfig);
|
|
201
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly,
|
|
202
|
-
return [
|
|
203
|
-
4,
|
|
204
|
-
getSpecifiedEntries(options.entry || false, entrypoints)
|
|
205
|
-
];
|
|
206
|
-
case 1:
|
|
207
|
-
checkedEntries = _state.sent();
|
|
208
|
-
api.setAppContext(_objectSpreadProps(_objectSpread({}, appContext), {
|
|
209
|
-
checkedEntries: checkedEntries
|
|
210
|
-
}));
|
|
211
|
-
appContext.checkedEntries = checkedEntries;
|
|
199
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile;
|
|
212
200
|
return [
|
|
213
201
|
4,
|
|
214
202
|
buildServerConfig({
|
|
@@ -222,13 +210,13 @@ var dev = function() {
|
|
|
222
210
|
}
|
|
223
211
|
})
|
|
224
212
|
];
|
|
225
|
-
case
|
|
213
|
+
case 1:
|
|
226
214
|
_state.sent();
|
|
227
215
|
return [
|
|
228
216
|
4,
|
|
229
217
|
hookRunners.beforeDev()
|
|
230
218
|
];
|
|
231
|
-
case
|
|
219
|
+
case 2:
|
|
232
220
|
_state.sent();
|
|
233
221
|
if (!appContext.builder && !apiOnly) {
|
|
234
222
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
@@ -237,13 +225,13 @@ var dev = function() {
|
|
|
237
225
|
4,
|
|
238
226
|
generateRoutes(appContext)
|
|
239
227
|
];
|
|
240
|
-
case
|
|
228
|
+
case 3:
|
|
241
229
|
_state.sent();
|
|
242
230
|
return [
|
|
243
231
|
4,
|
|
244
232
|
getServerInternalPlugins(api)
|
|
245
233
|
];
|
|
246
|
-
case
|
|
234
|
+
case 4:
|
|
247
235
|
serverInternalPlugins = _state.sent();
|
|
248
236
|
serverOptions = {
|
|
249
237
|
dev: _objectSpread({
|
|
@@ -257,7 +245,7 @@ var dev = function() {
|
|
|
257
245
|
};
|
|
258
246
|
if (!apiOnly) return [
|
|
259
247
|
3,
|
|
260
|
-
|
|
248
|
+
6
|
|
261
249
|
];
|
|
262
250
|
return [
|
|
263
251
|
4,
|
|
@@ -265,7 +253,7 @@ var dev = function() {
|
|
|
265
253
|
compiler: null
|
|
266
254
|
}))
|
|
267
255
|
];
|
|
268
|
-
case
|
|
256
|
+
case 5:
|
|
269
257
|
app = _state.sent();
|
|
270
258
|
app.listen(port, function() {
|
|
271
259
|
var _ref = _asyncToGenerator(function(err) {
|
|
@@ -285,9 +273,9 @@ var dev = function() {
|
|
|
285
273
|
}());
|
|
286
274
|
return [
|
|
287
275
|
3,
|
|
288
|
-
|
|
276
|
+
8
|
|
289
277
|
];
|
|
290
|
-
case
|
|
278
|
+
case 6:
|
|
291
279
|
return [
|
|
292
280
|
4,
|
|
293
281
|
appContext.builder.startDevServer({
|
|
@@ -295,17 +283,11 @@ var dev = function() {
|
|
|
295
283
|
serverOptions: serverOptions
|
|
296
284
|
})
|
|
297
285
|
];
|
|
298
|
-
case
|
|
286
|
+
case 7:
|
|
299
287
|
server = _state.sent().server;
|
|
300
288
|
setServer(server);
|
|
301
|
-
_state.label =
|
|
302
|
-
case
|
|
303
|
-
return [
|
|
304
|
-
4,
|
|
305
|
-
createFileWatcher(appContext, normalizedConfig.source.configDir, hookRunners)
|
|
306
|
-
];
|
|
307
|
-
case 10:
|
|
308
|
-
_state.sent();
|
|
289
|
+
_state.label = 8;
|
|
290
|
+
case 8:
|
|
309
291
|
return [
|
|
310
292
|
2
|
|
311
293
|
];
|
|
@@ -53,7 +53,9 @@ function _objectSpreadProps(target, source) {
|
|
|
53
53
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
54
54
|
function createDefaultConfig(appContext) {
|
|
55
55
|
var defaultBuilderConfig = createDefaultBuilderConfig();
|
|
56
|
-
var dev = _objectSpread({}, defaultBuilderConfig.dev)
|
|
56
|
+
var dev = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.dev), {
|
|
57
|
+
port: void 0
|
|
58
|
+
});
|
|
57
59
|
var tools = _objectSpread({}, defaultBuilderConfig.tools);
|
|
58
60
|
var output = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.output), {
|
|
59
61
|
disableNodePolyfill: true
|
|
@@ -20,8 +20,6 @@ var hooks = {
|
|
|
20
20
|
afterBuild: createAsyncWorkflow(),
|
|
21
21
|
beforeDeploy: createAsyncWorkflow(),
|
|
22
22
|
afterDeploy: createAsyncWorkflow(),
|
|
23
|
-
watchFiles: createParallelWorkflow(),
|
|
24
|
-
fileChange: createAsyncWorkflow(),
|
|
25
23
|
beforeRestart: createAsyncWorkflow(),
|
|
26
24
|
registerDev: createParallelWorkflow(),
|
|
27
25
|
beforeDevTask: createParallelWorkflow(),
|
|
@@ -185,6 +185,7 @@ import { i18n, localeKeys } from "./locale";
|
|
|
185
185
|
import { getLocaleLanguage } from "./utils/language";
|
|
186
186
|
import { getCommand } from "./utils/commands";
|
|
187
187
|
import { restart } from "./utils/restart";
|
|
188
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
188
189
|
export * from "./defineConfig";
|
|
189
190
|
export * from "./types";
|
|
190
191
|
var upgradeModel = Import.lazy("@modern-js/upgrade", require);
|
|
@@ -633,6 +634,19 @@ var src_default = function() {
|
|
|
633
634
|
});
|
|
634
635
|
})();
|
|
635
636
|
},
|
|
637
|
+
watchFiles: function watchFiles() {
|
|
638
|
+
return _asyncToGenerator(function() {
|
|
639
|
+
var appContext, config;
|
|
640
|
+
return __generator(this, function(_state) {
|
|
641
|
+
appContext = api.useAppContext();
|
|
642
|
+
config = api.useResolvedConfigContext();
|
|
643
|
+
return [
|
|
644
|
+
2,
|
|
645
|
+
generateWatchFiles(appContext, config.source.configDir)
|
|
646
|
+
];
|
|
647
|
+
});
|
|
648
|
+
})();
|
|
649
|
+
},
|
|
636
650
|
fileChange: function fileChange(e) {
|
|
637
651
|
return _asyncToGenerator(function() {
|
|
638
652
|
var filename, eventType, appContext, appDirectory, srcDirectory, absolutePath, closeServer;
|
|
@@ -199,7 +199,7 @@ var initialize_default = function() {
|
|
|
199
199
|
resolvedConfig: function resolvedConfig(param) {
|
|
200
200
|
var resolved = param.resolved;
|
|
201
201
|
return _asyncToGenerator(function() {
|
|
202
|
-
var ref,
|
|
202
|
+
var ref, appContext, userConfig, port, normalizedConfig;
|
|
203
203
|
return __generator(this, function(_state) {
|
|
204
204
|
switch(_state.label){
|
|
205
205
|
case 0:
|
|
@@ -207,7 +207,7 @@ var initialize_default = function() {
|
|
|
207
207
|
userConfig = api.useConfigContext();
|
|
208
208
|
return [
|
|
209
209
|
4,
|
|
210
|
-
|
|
210
|
+
getServerPort(resolved)
|
|
211
211
|
];
|
|
212
212
|
case 1:
|
|
213
213
|
port = _state.sent();
|
|
@@ -224,7 +224,7 @@ var initialize_default = function() {
|
|
|
224
224
|
_raw: userConfig,
|
|
225
225
|
source: normalizedConfig.source || {},
|
|
226
226
|
server: _objectSpreadProps(_objectSpread({}, normalizedConfig.server || {}), {
|
|
227
|
-
port: port
|
|
227
|
+
port: port
|
|
228
228
|
}),
|
|
229
229
|
bff: normalizedConfig.bff || {},
|
|
230
230
|
dev: normalizedConfig.dev || {},
|
|
@@ -252,49 +252,26 @@ var initialize_default = function() {
|
|
|
252
252
|
}
|
|
253
253
|
};
|
|
254
254
|
};
|
|
255
|
-
function
|
|
256
|
-
return
|
|
255
|
+
function getServerPort(config) {
|
|
256
|
+
return _getServerPort.apply(this, arguments);
|
|
257
257
|
}
|
|
258
|
-
function
|
|
259
|
-
|
|
260
|
-
var
|
|
258
|
+
function _getServerPort() {
|
|
259
|
+
_getServerPort = _asyncToGenerator(function(config) {
|
|
260
|
+
var prodPort;
|
|
261
261
|
return __generator(this, function(_state) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (!(((_port = appContext.port) !== null && _port !== void 0 ? _port : 0) > 0)) return [
|
|
269
|
-
3,
|
|
270
|
-
1
|
|
271
|
-
];
|
|
272
|
-
_tmp = appContext.port;
|
|
273
|
-
return [
|
|
274
|
-
3,
|
|
275
|
-
3
|
|
276
|
-
];
|
|
277
|
-
case 1:
|
|
278
|
-
return [
|
|
279
|
-
4,
|
|
280
|
-
getPort(resolved.server.port || 8080)
|
|
281
|
-
];
|
|
282
|
-
case 2:
|
|
283
|
-
_tmp = _state.sent();
|
|
284
|
-
_state.label = 3;
|
|
285
|
-
case 3:
|
|
286
|
-
return [
|
|
287
|
-
2,
|
|
288
|
-
_tmp
|
|
289
|
-
];
|
|
290
|
-
case 4:
|
|
291
|
-
return [
|
|
292
|
-
2,
|
|
293
|
-
resolved.server.port
|
|
294
|
-
];
|
|
262
|
+
prodPort = config.server.port || 8080;
|
|
263
|
+
if (isDev() && isDevCommand()) {
|
|
264
|
+
return [
|
|
265
|
+
2,
|
|
266
|
+
getPort(config.dev.port || prodPort)
|
|
267
|
+
];
|
|
295
268
|
}
|
|
269
|
+
return [
|
|
270
|
+
2,
|
|
271
|
+
prodPort
|
|
272
|
+
];
|
|
296
273
|
});
|
|
297
274
|
});
|
|
298
|
-
return
|
|
275
|
+
return _getServerPort.apply(this, arguments);
|
|
299
276
|
}
|
|
300
277
|
export { initialize_default as default };
|
|
@@ -7,7 +7,9 @@ var 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"
|