@modern-js/app-tools 2.0.1 → 2.0.3-alpha.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 +25 -0
- package/dist/js/modern/analyze/generateCode.js +4 -81
- package/dist/js/modern/analyze/index.js +26 -12
- package/dist/js/modern/analyze/nestedRoutes.js +2 -15
- package/dist/js/modern/analyze/templates.js +35 -60
- package/dist/js/modern/analyze/utils.js +9 -1
- package/dist/js/modern/config/initial/inits.js +1 -9
- package/dist/js/modern/index.js +6 -7
- package/dist/js/modern/locale/en.js +2 -1
- package/dist/js/modern/locale/zh.js +2 -1
- package/dist/js/node/analyze/generateCode.js +2 -77
- package/dist/js/node/analyze/index.js +24 -10
- package/dist/js/node/analyze/nestedRoutes.js +1 -14
- package/dist/js/node/analyze/templates.js +35 -60
- package/dist/js/node/analyze/utils.js +10 -1
- package/dist/js/node/config/initial/inits.js +1 -9
- package/dist/js/node/index.js +2 -3
- package/dist/js/node/locale/en.js +2 -1
- package/dist/js/node/locale/zh.js +2 -1
- package/dist/js/treeshaking/analyze/generateCode.js +21 -148
- package/dist/js/treeshaking/analyze/index.js +25 -18
- package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
- package/dist/js/treeshaking/analyze/templates.js +97 -76
- package/dist/js/treeshaking/analyze/utils.js +5 -2
- package/dist/js/treeshaking/config/initial/inits.js +1 -12
- package/dist/js/treeshaking/index.js +8 -9
- package/dist/js/treeshaking/locale/en.js +2 -1
- package/dist/js/treeshaking/locale/zh.js +2 -1
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/package.json +24 -24
- package/dist/js/modern/analyze/Builder.js +0 -39
- package/dist/js/node/analyze/Builder.js +0 -64
- package/dist/js/treeshaking/analyze/Builder.js +0 -199
- package/dist/types/analyze/Builder.d.ts +0 -8
|
@@ -221,7 +221,7 @@ 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 } from "@modern-js/utils";
|
|
224
|
+
import { createDebugger, findExists, fs, isApiOnly, isUseSSRBundle } 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";
|
|
@@ -229,8 +229,7 @@ import { generateRoutes } from "../utils/routes";
|
|
|
229
229
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
230
|
import { getCommand } from "../utils/commands";
|
|
231
231
|
import { initialNormalizedConfig } from "../config";
|
|
232
|
-
import {
|
|
233
|
-
import { loaderBuilder, serverLoaderBuilder } from "./Builder";
|
|
232
|
+
import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
234
233
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
235
234
|
var debug = createDebugger("plugin-analyze");
|
|
236
235
|
var analyze_default = function() {
|
|
@@ -525,6 +524,25 @@ var analyze_default = function() {
|
|
|
525
524
|
watchFiles: function watchFiles() {
|
|
526
525
|
return pagesDir;
|
|
527
526
|
},
|
|
527
|
+
config: function config() {
|
|
528
|
+
return {
|
|
529
|
+
tools: {
|
|
530
|
+
webpackChain: function(chain, param) {
|
|
531
|
+
var name = param.name, CHAIN_ID = param.CHAIN_ID;
|
|
532
|
+
var appContext = api.useAppContext();
|
|
533
|
+
var resolvedConfig = api.useResolvedConfigContext();
|
|
534
|
+
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory;
|
|
535
|
+
entrypoints.forEach(function(entrypoint) {
|
|
536
|
+
var entryName = entrypoint.entryName;
|
|
537
|
+
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(resolvedConfig)) {
|
|
538
|
+
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
539
|
+
chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
},
|
|
528
546
|
resolvedConfig: function resolvedConfig(param) {
|
|
529
547
|
var resolved = param.resolved;
|
|
530
548
|
var appContext = api.useAppContext();
|
|
@@ -536,12 +554,12 @@ var analyze_default = function() {
|
|
|
536
554
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
537
555
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
538
556
|
return _asyncToGenerator(function() {
|
|
539
|
-
var appContext, srcDirectory, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
|
|
557
|
+
var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
|
|
540
558
|
return __generator(this, function(_state) {
|
|
541
559
|
switch(_state.label){
|
|
542
560
|
case 0:
|
|
543
561
|
appContext = api.useAppContext();
|
|
544
|
-
srcDirectory = appContext.srcDirectory;
|
|
562
|
+
srcDirectory = appContext.srcDirectory, internalSrcAlias = appContext.internalSrcAlias;
|
|
545
563
|
fileSystemRoutes = entrypoint.fileSystemRoutes, nestedRoutesEntry = entrypoint.nestedRoutesEntry;
|
|
546
564
|
if (!(fileSystemRoutes && nestedRoutesEntry)) return [
|
|
547
565
|
3,
|
|
@@ -582,7 +600,7 @@ var analyze_default = function() {
|
|
|
582
600
|
hasAppConfig = moduleExports.some(function(e) {
|
|
583
601
|
return e.n === APP_CONFIG_NAME;
|
|
584
602
|
});
|
|
585
|
-
generateLayoutPath = replaceWithAlias(srcDirectory, rootLayoutFile,
|
|
603
|
+
generateLayoutPath = replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias);
|
|
586
604
|
if (hasAppConfig) {
|
|
587
605
|
imports.push({
|
|
588
606
|
value: generateLayoutPath,
|
|
@@ -620,17 +638,6 @@ var analyze_default = function() {
|
|
|
620
638
|
});
|
|
621
639
|
})();
|
|
622
640
|
},
|
|
623
|
-
beforeRestart: function beforeRestart() {
|
|
624
|
-
return _asyncToGenerator(function() {
|
|
625
|
-
return __generator(this, function(_state) {
|
|
626
|
-
serverLoaderBuilder.stop();
|
|
627
|
-
loaderBuilder.stop();
|
|
628
|
-
return [
|
|
629
|
-
2
|
|
630
|
-
];
|
|
631
|
-
});
|
|
632
|
-
})();
|
|
633
|
-
},
|
|
634
641
|
fileChange: function fileChange(e) {
|
|
635
642
|
return _asyncToGenerator(function() {
|
|
636
643
|
var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
|
|
@@ -647,7 +654,7 @@ var analyze_default = function() {
|
|
|
647
654
|
};
|
|
648
655
|
absoluteFilePath = path.resolve(appDirectory, filename);
|
|
649
656
|
isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
|
650
|
-
if (!(isRouteComponent && (eventType === "add" || eventType === "unlink")
|
|
657
|
+
if (!(isRouteComponent && (eventType === "add" || eventType === "unlink"))) return [
|
|
651
658
|
3,
|
|
652
659
|
2
|
|
653
660
|
];
|
|
@@ -177,35 +177,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
177
177
|
import * as path from "path";
|
|
178
178
|
import { fs, getRouteId } from "@modern-js/utils";
|
|
179
179
|
import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
|
|
180
|
-
import {
|
|
180
|
+
import { replaceWithAlias } from "./utils";
|
|
181
181
|
var conventionNames = Object.values(NESTED_ROUTE);
|
|
182
|
-
var getLoaderPath = function() {
|
|
183
|
-
var _ref = _asyncToGenerator(function(filename) {
|
|
184
|
-
return __generator(this, function(_state) {
|
|
185
|
-
switch(_state.label){
|
|
186
|
-
case 0:
|
|
187
|
-
return [
|
|
188
|
-
4,
|
|
189
|
-
hasLoader(filename)
|
|
190
|
-
];
|
|
191
|
-
case 1:
|
|
192
|
-
if (_state.sent()) {
|
|
193
|
-
return [
|
|
194
|
-
2,
|
|
195
|
-
filename
|
|
196
|
-
];
|
|
197
|
-
}
|
|
198
|
-
return [
|
|
199
|
-
2,
|
|
200
|
-
void 0
|
|
201
|
-
];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
return function getLoaderPath(filename) {
|
|
206
|
-
return _ref.apply(this, arguments);
|
|
207
|
-
};
|
|
208
|
-
}();
|
|
209
182
|
var replaceDynamicPath = function(routePath) {
|
|
210
183
|
return routePath.replace(/\[(.*?)\]/g, ":$1");
|
|
211
184
|
};
|
|
@@ -224,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
|
224
197
|
};
|
|
225
198
|
var walk = function() {
|
|
226
199
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
|
227
|
-
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref,
|
|
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, ref, ref1, err, finalRoute;
|
|
228
201
|
return __generator(this, function(_state) {
|
|
229
202
|
switch(_state.label){
|
|
230
203
|
case 0:
|
|
@@ -280,16 +253,16 @@ var walk = function() {
|
|
|
280
253
|
case 4:
|
|
281
254
|
_state.trys.push([
|
|
282
255
|
4,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
256
|
+
11,
|
|
257
|
+
12,
|
|
258
|
+
13
|
|
286
259
|
]);
|
|
287
260
|
_iterator = items[Symbol.iterator]();
|
|
288
261
|
_state.label = 5;
|
|
289
262
|
case 5:
|
|
290
263
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
291
264
|
3,
|
|
292
|
-
|
|
265
|
+
10
|
|
293
266
|
];
|
|
294
267
|
item = _step.value;
|
|
295
268
|
itemPath = path.join(dirname, item);
|
|
@@ -320,7 +293,7 @@ var walk = function() {
|
|
|
320
293
|
if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
|
|
321
294
|
return [
|
|
322
295
|
3,
|
|
323
|
-
|
|
296
|
+
9
|
|
324
297
|
];
|
|
325
298
|
}
|
|
326
299
|
if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
|
|
@@ -328,73 +301,49 @@ var walk = function() {
|
|
|
328
301
|
route.loader = itemPath;
|
|
329
302
|
}
|
|
330
303
|
}
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
10
|
|
334
|
-
];
|
|
335
|
-
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
336
|
-
return [
|
|
337
|
-
4,
|
|
338
|
-
getLoaderPath(itemPath)
|
|
339
|
-
];
|
|
340
|
-
case 9:
|
|
341
|
-
loaderPath = _state.sent();
|
|
342
|
-
if (loaderPath) {
|
|
343
|
-
route.loader = loaderPath;
|
|
304
|
+
if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
|
|
305
|
+
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
344
306
|
}
|
|
345
|
-
_state.label = 10;
|
|
346
|
-
case 10:
|
|
347
307
|
if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
|
|
348
308
|
pageLoaderFile = itemPath;
|
|
349
309
|
}
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
getLoaderPath(itemPath)
|
|
360
|
-
];
|
|
361
|
-
case 11:
|
|
362
|
-
loaderPath1 = _state.sent();
|
|
363
|
-
if (loaderPath1) {
|
|
364
|
-
pageRoute.loader = loaderPath1;
|
|
365
|
-
} else if (pageLoaderFile) {
|
|
366
|
-
pageRoute.loader = pageLoaderFile;
|
|
310
|
+
if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
|
|
311
|
+
;
|
|
312
|
+
pageRoute = createIndexRoute({
|
|
313
|
+
_component: replaceWithAlias(alias.basename, itemPath, alias.name)
|
|
314
|
+
}, rootDir, itemPath, entryName);
|
|
315
|
+
if (pageLoaderFile) {
|
|
316
|
+
pageRoute.loader = pageLoaderFile;
|
|
317
|
+
}
|
|
318
|
+
(ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(pageRoute);
|
|
367
319
|
}
|
|
368
|
-
(ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(pageRoute);
|
|
369
|
-
_state.label = 12;
|
|
370
|
-
case 12:
|
|
371
320
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
372
321
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
373
322
|
}
|
|
374
323
|
if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
|
|
375
324
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
376
325
|
}
|
|
377
|
-
_state.label =
|
|
378
|
-
case
|
|
326
|
+
_state.label = 9;
|
|
327
|
+
case 9:
|
|
379
328
|
_iteratorNormalCompletion = true;
|
|
380
329
|
return [
|
|
381
330
|
3,
|
|
382
331
|
5
|
|
383
332
|
];
|
|
384
|
-
case
|
|
333
|
+
case 10:
|
|
385
334
|
return [
|
|
386
335
|
3,
|
|
387
|
-
|
|
336
|
+
13
|
|
388
337
|
];
|
|
389
|
-
case
|
|
338
|
+
case 11:
|
|
390
339
|
err = _state.sent();
|
|
391
340
|
_didIteratorError = true;
|
|
392
341
|
_iteratorError = err;
|
|
393
342
|
return [
|
|
394
343
|
3,
|
|
395
|
-
|
|
344
|
+
13
|
|
396
345
|
];
|
|
397
|
-
case
|
|
346
|
+
case 12:
|
|
398
347
|
try {
|
|
399
348
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
400
349
|
_iterator.return();
|
|
@@ -407,7 +356,7 @@ var walk = function() {
|
|
|
407
356
|
return [
|
|
408
357
|
7
|
|
409
358
|
];
|
|
410
|
-
case
|
|
359
|
+
case 13:
|
|
411
360
|
finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(NESTED_ROUTE.LAYOUT_FILE, ".ts")), entryName);
|
|
412
361
|
if (isPathlessLayout) {
|
|
413
362
|
delete finalRoute.path;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
1
9
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
10
|
try {
|
|
3
11
|
var info = gen[key](arg);
|
|
@@ -40,6 +48,33 @@ function _defineProperty(obj, key, value) {
|
|
|
40
48
|
}
|
|
41
49
|
return obj;
|
|
42
50
|
}
|
|
51
|
+
function _iterableToArrayLimit(arr, i) {
|
|
52
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
53
|
+
if (_i == null) return;
|
|
54
|
+
var _arr = [];
|
|
55
|
+
var _n = true;
|
|
56
|
+
var _d = false;
|
|
57
|
+
var _s, _e;
|
|
58
|
+
try {
|
|
59
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
60
|
+
_arr.push(_s.value);
|
|
61
|
+
if (i && _arr.length === i) break;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_d = true;
|
|
65
|
+
_e = err;
|
|
66
|
+
} finally{
|
|
67
|
+
try {
|
|
68
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
69
|
+
} finally{
|
|
70
|
+
if (_d) throw _e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return _arr;
|
|
74
|
+
}
|
|
75
|
+
function _nonIterableRest() {
|
|
76
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
|
+
}
|
|
43
78
|
function _objectSpread(target) {
|
|
44
79
|
for(var i = 1; i < arguments.length; i++){
|
|
45
80
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -79,6 +114,17 @@ function _objectSpreadProps(target, source) {
|
|
|
79
114
|
}
|
|
80
115
|
return target;
|
|
81
116
|
}
|
|
117
|
+
function _slicedToArray(arr, i) {
|
|
118
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
119
|
+
}
|
|
120
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
121
|
+
if (!o) return;
|
|
122
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
123
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
124
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
125
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
126
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
127
|
+
}
|
|
82
128
|
var __generator = this && this.__generator || function(thisArg, body) {
|
|
83
129
|
var f, y, t, g, _ = {
|
|
84
130
|
label: 0,
|
|
@@ -243,15 +289,15 @@ var routesForServer = function(param) {
|
|
|
243
289
|
routesCode += "\n];";
|
|
244
290
|
var importLoadersCode = "";
|
|
245
291
|
if (loaders.length > 0) {
|
|
246
|
-
importLoadersCode =
|
|
247
|
-
return "loader_".concat(index2);
|
|
248
|
-
})
|
|
292
|
+
importLoadersCode = loaders.map(function(loader, index2) {
|
|
293
|
+
return "import loader_".concat(index2, ' from "').concat(loader, '"');
|
|
294
|
+
}).join("\n");
|
|
249
295
|
}
|
|
250
296
|
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
|
251
297
|
};
|
|
252
298
|
var fileSystemRoutes = function() {
|
|
253
299
|
var _ref = _asyncToGenerator(function(param) {
|
|
254
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, internalDirAlias, loadings, errors, loaders, loadersMap,
|
|
300
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, internalDirAlias, 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;
|
|
255
301
|
return __generator(this, function(_state) {
|
|
256
302
|
switch(_state.label){
|
|
257
303
|
case 0:
|
|
@@ -260,17 +306,19 @@ var fileSystemRoutes = function() {
|
|
|
260
306
|
errors = [];
|
|
261
307
|
loaders = [];
|
|
262
308
|
loadersMap = {};
|
|
263
|
-
loadersIndexFile = path.join(internalDirAlias, entryName, TEMP_LOADERS_DIR, "index.js");
|
|
264
309
|
loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
|
|
265
310
|
importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
|
|
266
311
|
rootLayoutCode = "";
|
|
267
|
-
dataLoaderPath = "";
|
|
268
312
|
componentLoaderPath = "";
|
|
269
|
-
|
|
270
|
-
|
|
313
|
+
getDataLoaderPath = function(loaderId) {
|
|
314
|
+
if (!ssrMode) return "";
|
|
315
|
+
var dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
271
316
|
if (nestedRoutesEntry) {
|
|
272
|
-
dataLoaderPath = "".concat(dataLoaderPath, "?
|
|
317
|
+
dataLoaderPath = "".concat(slash(dataLoaderPath), "?mapFile=").concat(slash(loadersMapFile), "&loaderId=").concat(loaderId, "!");
|
|
273
318
|
}
|
|
319
|
+
return dataLoaderPath;
|
|
320
|
+
};
|
|
321
|
+
if (ssrMode) {
|
|
274
322
|
componentLoaderPath = "".concat(path.join(__dirname, "../builder/loaders/routerLoader"), "!");
|
|
275
323
|
}
|
|
276
324
|
traverseRouteTree = function(route) {
|
|
@@ -283,6 +331,7 @@ var fileSystemRoutes = function() {
|
|
|
283
331
|
var error;
|
|
284
332
|
var loader;
|
|
285
333
|
var component = "";
|
|
334
|
+
var lazyImport = null;
|
|
286
335
|
if (route.type === "nested") {
|
|
287
336
|
if (route.loading) {
|
|
288
337
|
loadings.push(route.loading);
|
|
@@ -296,22 +345,30 @@ var fileSystemRoutes = function() {
|
|
|
296
345
|
loaders.push(route.loader);
|
|
297
346
|
var loaderId = loaders.length - 1;
|
|
298
347
|
loader = "loader_".concat(loaderId);
|
|
299
|
-
loadersMap[loader] =
|
|
348
|
+
loadersMap[loader] = {
|
|
349
|
+
routeId: route.id,
|
|
350
|
+
filePath: route.loader,
|
|
351
|
+
inline: false
|
|
352
|
+
};
|
|
300
353
|
}
|
|
301
354
|
if (route._component) {
|
|
302
355
|
if (route.isRoot) {
|
|
303
356
|
rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
|
|
304
357
|
component = "RootLayout";
|
|
305
358
|
} else if (ssrMode === "string") {
|
|
306
|
-
|
|
359
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(componentLoaderPath).concat(route._component, "')");
|
|
360
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
307
361
|
} else {
|
|
308
|
-
|
|
362
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(componentLoaderPath).concat(route._component, "')");
|
|
363
|
+
component = "lazy(".concat(lazyImport, ")");
|
|
309
364
|
}
|
|
310
365
|
}
|
|
311
366
|
} else if (route._component) {
|
|
312
|
-
|
|
367
|
+
lazyImport = "() => import('".concat(route._component, "')");
|
|
368
|
+
component = "loadable(".concat(lazyImport, ")");
|
|
313
369
|
}
|
|
314
370
|
var finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
371
|
+
lazyImport: lazyImport,
|
|
315
372
|
loading: loading,
|
|
316
373
|
loader: loader,
|
|
317
374
|
error: error,
|
|
@@ -329,7 +386,7 @@ var fileSystemRoutes = function() {
|
|
|
329
386
|
route = _step.value;
|
|
330
387
|
if ("type" in route) {
|
|
331
388
|
newRoute = traverseRouteTree(route);
|
|
332
|
-
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(lazy.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"'), ",");
|
|
389
|
+
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"'), ",");
|
|
333
390
|
} else {
|
|
334
391
|
component = "loadable(() => import('".concat(route._component, "'))");
|
|
335
392
|
finalRoute = _objectSpreadProps(_objectSpread({}, route), {
|
|
@@ -360,78 +417,42 @@ var fileSystemRoutes = function() {
|
|
|
360
417
|
return "import error_".concat(index2, " from '").concat(error, "';\n");
|
|
361
418
|
}).join("");
|
|
362
419
|
importLoadersCode = "";
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
420
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
421
|
+
try {
|
|
422
|
+
for(_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
423
|
+
_value = _slicedToArray(_step1.value, 2), key = _value[0], loaderInfo = _value[1];
|
|
424
|
+
if (loaderInfo.inline) {
|
|
425
|
+
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(loaderInfo.filePath, '";\n');
|
|
426
|
+
} else {
|
|
427
|
+
importLoadersCode += "import ".concat(key, ' from "').concat(getDataLoaderPath(key)).concat(loaderInfo.filePath, '";\n');
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} catch (err) {
|
|
431
|
+
_didIteratorError1 = true;
|
|
432
|
+
_iteratorError1 = err;
|
|
433
|
+
} finally{
|
|
434
|
+
try {
|
|
435
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
436
|
+
_iterator1.return();
|
|
437
|
+
}
|
|
438
|
+
} finally{
|
|
439
|
+
if (_didIteratorError1) {
|
|
440
|
+
throw _iteratorError1;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
374
444
|
return [
|
|
375
445
|
4,
|
|
376
|
-
fs.ensureFile(
|
|
446
|
+
fs.ensureFile(loadersMapFile)
|
|
377
447
|
];
|
|
378
448
|
case 1:
|
|
379
|
-
_state.sent();
|
|
380
|
-
return [
|
|
381
|
-
4,
|
|
382
|
-
fs.writeFile(loaderEntryFile, loaderEntryCode)
|
|
383
|
-
];
|
|
384
|
-
case 2:
|
|
385
449
|
_state.sent();
|
|
386
450
|
return [
|
|
387
451
|
4,
|
|
388
452
|
fs.writeJSON(loadersMapFile, loadersMap)
|
|
389
453
|
];
|
|
390
|
-
case
|
|
391
|
-
_state.sent();
|
|
392
|
-
return [
|
|
393
|
-
4,
|
|
394
|
-
Promise.all(loaders.map(function() {
|
|
395
|
-
var _ref = _asyncToGenerator(function(loader, index2) {
|
|
396
|
-
var name, filename, code;
|
|
397
|
-
return __generator(this, function(_state) {
|
|
398
|
-
switch(_state.label){
|
|
399
|
-
case 0:
|
|
400
|
-
name = "loader_".concat(index2);
|
|
401
|
-
filename = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "".concat(name, ".js"));
|
|
402
|
-
code = "";
|
|
403
|
-
if (loader.includes(".loader.")) {
|
|
404
|
-
code = "\n export { default as ".concat(name, " } from '").concat(slash(loader), "'\n ");
|
|
405
|
-
} else {
|
|
406
|
-
code = "\n export { loader as ".concat(name, " } from '").concat(slash(loader), "'\n ");
|
|
407
|
-
}
|
|
408
|
-
return [
|
|
409
|
-
4,
|
|
410
|
-
fs.ensureFile(filename)
|
|
411
|
-
];
|
|
412
|
-
case 1:
|
|
413
|
-
_state.sent();
|
|
414
|
-
return [
|
|
415
|
-
4,
|
|
416
|
-
fs.writeFile(filename, code)
|
|
417
|
-
];
|
|
418
|
-
case 2:
|
|
419
|
-
_state.sent();
|
|
420
|
-
return [
|
|
421
|
-
2
|
|
422
|
-
];
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
});
|
|
426
|
-
return function(loader, index2) {
|
|
427
|
-
return _ref.apply(this, arguments);
|
|
428
|
-
};
|
|
429
|
-
}()))
|
|
430
|
-
];
|
|
431
|
-
case 4:
|
|
454
|
+
case 2:
|
|
432
455
|
_state.sent();
|
|
433
|
-
_state.label = 5;
|
|
434
|
-
case 5:
|
|
435
456
|
return [
|
|
436
457
|
2,
|
|
437
458
|
"\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
@@ -287,7 +287,7 @@ var isPageComponentFile = function(filePath) {
|
|
|
287
287
|
return false;
|
|
288
288
|
};
|
|
289
289
|
var isNestedRouteComponent = function(nestedRouteEntries, absoluteFilePath) {
|
|
290
|
-
var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, "
|
|
290
|
+
var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, ")\\.tsx?$"));
|
|
291
291
|
return nestedRouteEntries.some(function(nestedRoutesEntry) {
|
|
292
292
|
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
293
293
|
return true;
|
|
@@ -377,4 +377,7 @@ var hasLoader = function() {
|
|
|
377
377
|
return _ref.apply(this, arguments);
|
|
378
378
|
};
|
|
379
379
|
}();
|
|
380
|
-
|
|
380
|
+
var getServerLoadersFile = function(internalDirectory, entryName) {
|
|
381
|
+
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
382
|
+
};
|
|
383
|
+
export { getDefaultImports, getServerLoadersFile, hasLoader, isNestedRouteComponent, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -197,7 +197,7 @@ function initToolsConfig(config) {
|
|
|
197
197
|
]
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
|
-
var _tools = config.tools, tsChecker = _tools.tsChecker, tsLoader = _tools.tsLoader
|
|
200
|
+
var _tools = config.tools, tsChecker = _tools.tsChecker, tsLoader = _tools.tsLoader;
|
|
201
201
|
config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
|
|
202
202
|
tsLoader && (config.tools.tsLoader = function(tsLoaderConfig, utils) {
|
|
203
203
|
applyOptionsChain(_objectSpreadProps(_objectSpread({}, tsLoaderConfig), {
|
|
@@ -205,16 +205,5 @@ function initToolsConfig(config) {
|
|
|
205
205
|
allowTsInNodeModules: true
|
|
206
206
|
}), tsLoader || {}, utils);
|
|
207
207
|
});
|
|
208
|
-
config.tools.htmlPlugin = [
|
|
209
|
-
function(config2) {
|
|
210
|
-
return _objectSpreadProps(_objectSpread({}, config2), {
|
|
211
|
-
minify: typeof config2.minify === "object" ? _objectSpreadProps(_objectSpread({}, config2.minify), {
|
|
212
|
-
removeComments: false
|
|
213
|
-
}) : config2.minify
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
].concat(_toConsumableArray(Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [
|
|
217
|
-
htmlPlugin
|
|
218
|
-
] : []));
|
|
219
208
|
}
|
|
220
209
|
export { initHtmlConfig, initSourceConfig, initToolsConfig };
|
|
@@ -175,11 +175,11 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
import path from "path";
|
|
178
|
-
import
|
|
178
|
+
import lintPlugin from "@modern-js/plugin-lint";
|
|
179
179
|
import { cleanRequireCache, emptyDir, Import } from "@modern-js/utils";
|
|
180
180
|
import { castArray } from "@modern-js/utils/lodash";
|
|
181
|
-
import
|
|
182
|
-
import
|
|
181
|
+
import analyzePlugin from "./analyze";
|
|
182
|
+
import initializePlugin from "./initialize";
|
|
183
183
|
import { hooks } from "./hooks";
|
|
184
184
|
import { i18n, localeKeys } from "./locale";
|
|
185
185
|
import { getLocaleLanguage } from "./utils/language";
|
|
@@ -345,7 +345,6 @@ var buildCommand = function() {
|
|
|
345
345
|
];
|
|
346
346
|
case 2:
|
|
347
347
|
_state.sent();
|
|
348
|
-
process.exit(0);
|
|
349
348
|
return [
|
|
350
349
|
2
|
|
351
350
|
];
|
|
@@ -454,9 +453,9 @@ var src_default = function() {
|
|
|
454
453
|
],
|
|
455
454
|
registerHook: hooks,
|
|
456
455
|
usePlugins: [
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
456
|
+
initializePlugin(),
|
|
457
|
+
analyzePlugin(),
|
|
458
|
+
lintPlugin()
|
|
460
459
|
],
|
|
461
460
|
setup: function(api) {
|
|
462
461
|
var locale = getLocaleLanguage();
|
|
@@ -546,7 +545,7 @@ var src_default = function() {
|
|
|
546
545
|
return _ref.apply(this, arguments);
|
|
547
546
|
};
|
|
548
547
|
}());
|
|
549
|
-
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action(function() {
|
|
548
|
+
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action(function() {
|
|
550
549
|
var _ref = _asyncToGenerator(function(options) {
|
|
551
550
|
var MWANewAction;
|
|
552
551
|
return __generator(this, function(_state) {
|
|
@@ -561,7 +560,7 @@ var src_default = function() {
|
|
|
561
560
|
return [
|
|
562
561
|
4,
|
|
563
562
|
MWANewAction(_objectSpreadProps(_objectSpread({}, options), {
|
|
564
|
-
locale: locale
|
|
563
|
+
locale: options.lang || locale
|
|
565
564
|
}))
|
|
566
565
|
];
|
|
567
566
|
case 2:
|
|
@@ -23,7 +23,8 @@ var EN_LOCALE = {
|
|
|
23
23
|
debug: "using debug mode to log something",
|
|
24
24
|
config: "set default generator config(json string)",
|
|
25
25
|
distTag: "use specified tag version for it's generator",
|
|
26
|
-
registry: "set npm registry url to run npm command"
|
|
26
|
+
registry: "set npm registry url to run npm command",
|
|
27
|
+
lang: "set new command language(en or zh)"
|
|
27
28
|
},
|
|
28
29
|
inspect: {
|
|
29
30
|
env: "specify env mode",
|