@modern-js/app-tools 2.0.2 → 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/dist/js/modern/analyze/generateCode.js +4 -81
- package/dist/js/modern/analyze/index.js +24 -10
- package/dist/js/modern/analyze/nestedRoutes.js +2 -15
- package/dist/js/modern/analyze/templates.js +26 -56
- package/dist/js/modern/analyze/utils.js +8 -0
- 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 +22 -8
- package/dist/js/node/analyze/nestedRoutes.js +1 -14
- package/dist/js/node/analyze/templates.js +26 -56
- package/dist/js/node/analyze/utils.js +9 -0
- 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 +22 -15
- package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
- package/dist/js/treeshaking/analyze/templates.js +88 -72
- package/dist/js/treeshaking/analyze/utils.js +4 -1
- 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 +10 -10
- 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
|
@@ -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) {
|
|
@@ -297,7 +345,11 @@ var fileSystemRoutes = function() {
|
|
|
297
345
|
loaders.push(route.loader);
|
|
298
346
|
var loaderId = loaders.length - 1;
|
|
299
347
|
loader = "loader_".concat(loaderId);
|
|
300
|
-
loadersMap[loader] =
|
|
348
|
+
loadersMap[loader] = {
|
|
349
|
+
routeId: route.id,
|
|
350
|
+
filePath: route.loader,
|
|
351
|
+
inline: false
|
|
352
|
+
};
|
|
301
353
|
}
|
|
302
354
|
if (route._component) {
|
|
303
355
|
if (route.isRoot) {
|
|
@@ -365,78 +417,42 @@ var fileSystemRoutes = function() {
|
|
|
365
417
|
return "import error_".concat(index2, " from '").concat(error, "';\n");
|
|
366
418
|
}).join("");
|
|
367
419
|
importLoadersCode = "";
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
+
}
|
|
379
444
|
return [
|
|
380
445
|
4,
|
|
381
|
-
fs.ensureFile(
|
|
446
|
+
fs.ensureFile(loadersMapFile)
|
|
382
447
|
];
|
|
383
448
|
case 1:
|
|
384
|
-
_state.sent();
|
|
385
|
-
return [
|
|
386
|
-
4,
|
|
387
|
-
fs.writeFile(loaderEntryFile, loaderEntryCode)
|
|
388
|
-
];
|
|
389
|
-
case 2:
|
|
390
449
|
_state.sent();
|
|
391
450
|
return [
|
|
392
451
|
4,
|
|
393
452
|
fs.writeJSON(loadersMapFile, loadersMap)
|
|
394
453
|
];
|
|
395
|
-
case
|
|
396
|
-
_state.sent();
|
|
397
|
-
return [
|
|
398
|
-
4,
|
|
399
|
-
Promise.all(loaders.map(function() {
|
|
400
|
-
var _ref = _asyncToGenerator(function(loader, index2) {
|
|
401
|
-
var name, filename, code;
|
|
402
|
-
return __generator(this, function(_state) {
|
|
403
|
-
switch(_state.label){
|
|
404
|
-
case 0:
|
|
405
|
-
name = "loader_".concat(index2);
|
|
406
|
-
filename = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "".concat(name, ".js"));
|
|
407
|
-
code = "";
|
|
408
|
-
if (loader.includes(".loader.")) {
|
|
409
|
-
code = "\n export { default as ".concat(name, " } from '").concat(slash(loader), "'\n ");
|
|
410
|
-
} else {
|
|
411
|
-
code = "\n export { loader as ".concat(name, " } from '").concat(slash(loader), "'\n ");
|
|
412
|
-
}
|
|
413
|
-
return [
|
|
414
|
-
4,
|
|
415
|
-
fs.ensureFile(filename)
|
|
416
|
-
];
|
|
417
|
-
case 1:
|
|
418
|
-
_state.sent();
|
|
419
|
-
return [
|
|
420
|
-
4,
|
|
421
|
-
fs.writeFile(filename, code)
|
|
422
|
-
];
|
|
423
|
-
case 2:
|
|
424
|
-
_state.sent();
|
|
425
|
-
return [
|
|
426
|
-
2
|
|
427
|
-
];
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
return function(loader, index2) {
|
|
432
|
-
return _ref.apply(this, arguments);
|
|
433
|
-
};
|
|
434
|
-
}()))
|
|
435
|
-
];
|
|
436
|
-
case 4:
|
|
454
|
+
case 2:
|
|
437
455
|
_state.sent();
|
|
438
|
-
_state.label = 5;
|
|
439
|
-
case 5:
|
|
440
456
|
return [
|
|
441
457
|
2,
|
|
442
458
|
"\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
|
|
@@ -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",
|
|
@@ -23,7 +23,8 @@ var ZH_LOCALE = {
|
|
|
23
23
|
debug: "开启 Debug 模式,打印调试日志信息",
|
|
24
24
|
config: "生成器运行默认配置(JSON 字符串)",
|
|
25
25
|
distTag: "生成器使用特殊的 npm Tag 版本",
|
|
26
|
-
registry: "生成器运行过程中定制 npm Registry"
|
|
26
|
+
registry: "生成器运行过程中定制 npm Registry",
|
|
27
|
+
lang: "设置 new 命令执行语言(zh 或者 en)"
|
|
27
28
|
},
|
|
28
29
|
inspect: {
|
|
29
30
|
env: "查看指定环境下的配置",
|
|
@@ -24,4 +24,5 @@ export declare const parseModule: ({
|
|
|
24
24
|
source: string;
|
|
25
25
|
filename: string;
|
|
26
26
|
}) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
|
|
27
|
-
export declare const hasLoader: (filename: string) => Promise<boolean>;
|
|
27
|
+
export declare const hasLoader: (filename: string) => Promise<boolean>;
|
|
28
|
+
export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
|
|
@@ -26,6 +26,7 @@ declare const localeKeys: {
|
|
|
26
26
|
config: string;
|
|
27
27
|
distTag: string;
|
|
28
28
|
registry: string;
|
|
29
|
+
lang: string;
|
|
29
30
|
};
|
|
30
31
|
inspect: {
|
|
31
32
|
env: string;
|
|
@@ -59,6 +60,7 @@ declare const localeKeys: {
|
|
|
59
60
|
config: string;
|
|
60
61
|
distTag: string;
|
|
61
62
|
registry: string;
|
|
63
|
+
lang: string;
|
|
62
64
|
};
|
|
63
65
|
inspect: {
|
|
64
66
|
env: string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.
|
|
14
|
+
"version": "2.0.3-alpha.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -63,8 +63,6 @@
|
|
|
63
63
|
"@babel/runtime": "^7.18.0",
|
|
64
64
|
"@babel/traverse": "^7.18.0",
|
|
65
65
|
"@babel/types": "^7.18.0",
|
|
66
|
-
"es-module-lexer": "^1.1.0",
|
|
67
|
-
"esbuild": "0.15.7",
|
|
68
66
|
"@modern-js/builder": "2.0.2",
|
|
69
67
|
"@modern-js/builder-plugin-esbuild": "2.0.2",
|
|
70
68
|
"@modern-js/builder-plugin-node-polyfill": "2.0.2",
|
|
@@ -74,26 +72,28 @@
|
|
|
74
72
|
"@modern-js/new-action": "2.0.2",
|
|
75
73
|
"@modern-js/node-bundle-require": "2.0.2",
|
|
76
74
|
"@modern-js/plugin": "2.0.2",
|
|
77
|
-
"@modern-js/plugin-data-loader": "2.0.
|
|
75
|
+
"@modern-js/plugin-data-loader": "2.0.3-alpha.0",
|
|
78
76
|
"@modern-js/plugin-i18n": "2.0.2",
|
|
79
77
|
"@modern-js/plugin-lint": "2.0.2",
|
|
80
78
|
"@modern-js/prod-server": "2.0.2",
|
|
81
79
|
"@modern-js/server": "2.0.2",
|
|
82
80
|
"@modern-js/types": "2.0.2",
|
|
83
81
|
"@modern-js/upgrade": "2.0.2",
|
|
84
|
-
"@modern-js/utils": "2.0.2"
|
|
82
|
+
"@modern-js/utils": "2.0.2",
|
|
83
|
+
"es-module-lexer": "^1.1.0",
|
|
84
|
+
"esbuild": "0.15.7"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
+
"@modern-js/builder-plugin-swc": "2.0.2",
|
|
88
|
+
"@modern-js/server-core": "2.0.2",
|
|
89
|
+
"@scripts/build": "2.0.2",
|
|
90
|
+
"@scripts/jest-config": "2.0.2",
|
|
87
91
|
"@types/babel__traverse": "^7.14.2",
|
|
88
92
|
"@types/jest": "^27",
|
|
89
93
|
"@types/node": "^14",
|
|
90
94
|
"jest": "^27",
|
|
91
95
|
"typescript": "^4",
|
|
92
|
-
"webpack": "^5.75.0"
|
|
93
|
-
"@modern-js/builder-plugin-swc": "2.0.2",
|
|
94
|
-
"@modern-js/server-core": "2.0.2",
|
|
95
|
-
"@scripts/jest-config": "2.0.2",
|
|
96
|
-
"@scripts/build": "2.0.2"
|
|
96
|
+
"webpack": "^5.75.0"
|
|
97
97
|
},
|
|
98
98
|
"sideEffects": false,
|
|
99
99
|
"publishConfig": {
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { build } from "esbuild";
|
|
22
|
-
class Builder {
|
|
23
|
-
build(options) {
|
|
24
|
-
return __async(this, null, function* () {
|
|
25
|
-
this.buildRes = yield build(options);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
stop() {
|
|
29
|
-
var _a, _b;
|
|
30
|
-
((_a = this.buildRes) == null ? void 0 : _a.stop) && ((_b = this.buildRes) == null ? void 0 : _b.stop());
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const loaderBuilder = new Builder();
|
|
34
|
-
const serverLoaderBuilder = new Builder();
|
|
35
|
-
export {
|
|
36
|
-
Builder,
|
|
37
|
-
loaderBuilder,
|
|
38
|
-
serverLoaderBuilder
|
|
39
|
-
};
|