@modern-js/app-tools 2.3.1-alpha.1 → 2.3.1-alpha.2
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/nestedRoutes.js +10 -1
- package/dist/js/modern/analyze/templates.js +2 -9
- package/dist/js/node/analyze/nestedRoutes.js +10 -1
- package/dist/js/node/analyze/templates.js +2 -9
- package/dist/js/treeshaking/analyze/nestedRoutes.js +10 -1
- package/dist/js/treeshaking/analyze/templates.js +3 -7
- package/dist/types/defineConfig.d.ts +3 -2
- package/package.json +1 -1
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/node/builder/loaders/routerLoader.js +0 -38
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/types/builder/loaders/routerLoader.d.ts +0 -3
|
@@ -157,7 +157,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
157
157
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
|
|
160
|
+
let finalRoute = createRoute(
|
|
161
161
|
route,
|
|
162
162
|
rootDir,
|
|
163
163
|
path.join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
@@ -170,6 +170,15 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
170
170
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
174
|
+
const childRoute = finalRoute.children[0];
|
|
175
|
+
if (childRoute.path === "*") {
|
|
176
|
+
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
177
|
+
finalRoute = __spreadProps(__spreadValues({}, childRoute), {
|
|
178
|
+
path: path2
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
173
182
|
return finalRoute;
|
|
174
183
|
});
|
|
175
184
|
export {
|
|
@@ -198,7 +198,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
198
198
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
199
199
|
`;
|
|
200
200
|
let rootLayoutCode = ``;
|
|
201
|
-
let componentLoaderPath = "";
|
|
202
201
|
const getDataLoaderPath = (loaderId) => {
|
|
203
202
|
if (!ssrMode) {
|
|
204
203
|
return "";
|
|
@@ -211,12 +210,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
211
210
|
}
|
|
212
211
|
return dataLoaderPath;
|
|
213
212
|
};
|
|
214
|
-
if (ssrMode) {
|
|
215
|
-
componentLoaderPath = `${path.join(
|
|
216
|
-
__dirname,
|
|
217
|
-
"../builder/loaders/routerLoader"
|
|
218
|
-
)}!`;
|
|
219
|
-
}
|
|
220
213
|
const traverseRouteTree = (route) => {
|
|
221
214
|
var _a;
|
|
222
215
|
let children;
|
|
@@ -252,10 +245,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
252
245
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
253
246
|
component = `RootLayout`;
|
|
254
247
|
} else if (ssrMode === "string") {
|
|
255
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
248
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
256
249
|
component = `loadable(${lazyImport})`;
|
|
257
250
|
} else {
|
|
258
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
251
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
259
252
|
component = `lazy(${lazyImport})`;
|
|
260
253
|
}
|
|
261
254
|
}
|
|
@@ -183,7 +183,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
183
183
|
route.error = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
|
|
186
|
+
let finalRoute = createRoute(
|
|
187
187
|
route,
|
|
188
188
|
rootDir,
|
|
189
189
|
path.join(dirname, `${import_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
@@ -196,6 +196,15 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
196
196
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
197
197
|
return null;
|
|
198
198
|
}
|
|
199
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
200
|
+
const childRoute = finalRoute.children[0];
|
|
201
|
+
if (childRoute.path === "*") {
|
|
202
|
+
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
203
|
+
finalRoute = __spreadProps(__spreadValues({}, childRoute), {
|
|
204
|
+
path: path2
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
199
208
|
return finalRoute;
|
|
200
209
|
});
|
|
201
210
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -228,7 +228,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
228
228
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
229
229
|
`;
|
|
230
230
|
let rootLayoutCode = ``;
|
|
231
|
-
let componentLoaderPath = "";
|
|
232
231
|
const getDataLoaderPath = (loaderId) => {
|
|
233
232
|
if (!ssrMode) {
|
|
234
233
|
return "";
|
|
@@ -241,12 +240,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
241
240
|
}
|
|
242
241
|
return dataLoaderPath;
|
|
243
242
|
};
|
|
244
|
-
if (ssrMode) {
|
|
245
|
-
componentLoaderPath = `${import_path.default.join(
|
|
246
|
-
__dirname,
|
|
247
|
-
"../builder/loaders/routerLoader"
|
|
248
|
-
)}!`;
|
|
249
|
-
}
|
|
250
243
|
const traverseRouteTree = (route) => {
|
|
251
244
|
var _a;
|
|
252
245
|
let children;
|
|
@@ -282,10 +275,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
282
275
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
283
276
|
component = `RootLayout`;
|
|
284
277
|
} else if (ssrMode === "string") {
|
|
285
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
278
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
286
279
|
component = `loadable(${lazyImport})`;
|
|
287
280
|
} else {
|
|
288
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
281
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
289
282
|
component = `lazy(${lazyImport})`;
|
|
290
283
|
}
|
|
291
284
|
}
|
|
@@ -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 ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, ref3, err, finalRoute;
|
|
200
|
+
var ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, ref3, err, finalRoute, childRoute1, path2;
|
|
201
201
|
return __generator(this, function(_state) {
|
|
202
202
|
switch(_state.label){
|
|
203
203
|
case 0:
|
|
@@ -386,6 +386,15 @@ var walk = function() {
|
|
|
386
386
|
null
|
|
387
387
|
];
|
|
388
388
|
}
|
|
389
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
390
|
+
childRoute1 = finalRoute.children[0];
|
|
391
|
+
if (childRoute1.path === "*") {
|
|
392
|
+
path2 = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
|
|
393
|
+
finalRoute = _objectSpreadProps(_objectSpread({}, childRoute1), {
|
|
394
|
+
path: path2
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
389
398
|
return [
|
|
390
399
|
2,
|
|
391
400
|
finalRoute
|
|
@@ -296,7 +296,7 @@ var routesForServer = function(param) {
|
|
|
296
296
|
};
|
|
297
297
|
var fileSystemRoutes = function() {
|
|
298
298
|
var _ref = _asyncToGenerator(function(param) {
|
|
299
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode,
|
|
299
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _value, key, loaderInfo;
|
|
300
300
|
return __generator(this, function(_state) {
|
|
301
301
|
switch(_state.label){
|
|
302
302
|
case 0:
|
|
@@ -308,7 +308,6 @@ var fileSystemRoutes = function() {
|
|
|
308
308
|
loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
|
|
309
309
|
importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
|
|
310
310
|
rootLayoutCode = "";
|
|
311
|
-
componentLoaderPath = "";
|
|
312
311
|
getDataLoaderPath = function(loaderId) {
|
|
313
312
|
if (!ssrMode) {
|
|
314
313
|
return "";
|
|
@@ -319,9 +318,6 @@ var fileSystemRoutes = function() {
|
|
|
319
318
|
}
|
|
320
319
|
return dataLoaderPath;
|
|
321
320
|
};
|
|
322
|
-
if (ssrMode) {
|
|
323
|
-
componentLoaderPath = "".concat(path.join(__dirname, "../builder/loaders/routerLoader"), "!");
|
|
324
|
-
}
|
|
325
321
|
traverseRouteTree = function(route) {
|
|
326
322
|
var children;
|
|
327
323
|
if ("children" in route && route.children) {
|
|
@@ -357,10 +353,10 @@ var fileSystemRoutes = function() {
|
|
|
357
353
|
rootLayoutCode = "import RootLayout from '".concat(route._component, "'");
|
|
358
354
|
component = "RootLayout";
|
|
359
355
|
} else if (ssrMode === "string") {
|
|
360
|
-
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(
|
|
356
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
361
357
|
component = "loadable(".concat(lazyImport, ")");
|
|
362
358
|
} else {
|
|
363
|
-
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(
|
|
359
|
+
lazyImport = '() => import(/* webpackChunkName: "'.concat(route.id, "\" */ '").concat(route._component, "')");
|
|
364
360
|
component = "lazy(".concat(lazyImport, ")");
|
|
365
361
|
}
|
|
366
362
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { UserConfigExport } from '@modern-js/core';
|
|
2
|
+
import type { AppUserConfig, AppLegacyUserConfig } from './types';
|
|
3
|
+
export declare const defineConfig: (config: UserConfigExport<AppUserConfig>) => UserConfigExport<AppUserConfig>;
|
|
3
4
|
/**
|
|
4
5
|
* @deprecated
|
|
5
6
|
* Using defineConfig first.
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { slash } from "@modern-js/utils";
|
|
2
|
-
function loader(source) {
|
|
3
|
-
this.cacheable();
|
|
4
|
-
const { target } = this._compiler.options;
|
|
5
|
-
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
|
6
|
-
return source;
|
|
7
|
-
}
|
|
8
|
-
const { resourcePath } = this;
|
|
9
|
-
const code = `
|
|
10
|
-
export { default } from "${slash(resourcePath)}";
|
|
11
|
-
`;
|
|
12
|
-
return code;
|
|
13
|
-
}
|
|
14
|
-
var routerLoader_default = loader;
|
|
15
|
-
export {
|
|
16
|
-
routerLoader_default as default
|
|
17
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var routerLoader_exports = {};
|
|
19
|
-
__export(routerLoader_exports, {
|
|
20
|
-
default: () => routerLoader_default
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(routerLoader_exports);
|
|
23
|
-
var import_utils = require("@modern-js/utils");
|
|
24
|
-
function loader(source) {
|
|
25
|
-
this.cacheable();
|
|
26
|
-
const { target } = this._compiler.options;
|
|
27
|
-
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
|
28
|
-
return source;
|
|
29
|
-
}
|
|
30
|
-
const { resourcePath } = this;
|
|
31
|
-
const code = `
|
|
32
|
-
export { default } from "${(0, import_utils.slash)(resourcePath)}";
|
|
33
|
-
`;
|
|
34
|
-
return code;
|
|
35
|
-
}
|
|
36
|
-
var routerLoader_default = loader;
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { slash } from "@modern-js/utils";
|
|
2
|
-
function loader(source) {
|
|
3
|
-
this.cacheable();
|
|
4
|
-
var target = this._compiler.options.target;
|
|
5
|
-
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
|
6
|
-
return source;
|
|
7
|
-
}
|
|
8
|
-
var resourcePath = this.resourcePath;
|
|
9
|
-
var code = '\n export { default } from "'.concat(slash(resourcePath), '";\n ');
|
|
10
|
-
return code;
|
|
11
|
-
}
|
|
12
|
-
var routerLoader_default = loader;
|
|
13
|
-
export { routerLoader_default as default };
|