@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.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/CHANGELOG.md +375 -0
- package/dist/js/modern/analyze/generateCode.js +30 -38
- package/dist/js/modern/analyze/getBundleEntry.js +5 -13
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
- package/dist/js/modern/analyze/getServerRoutes.js +25 -38
- package/dist/js/modern/analyze/index.js +90 -48
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
- package/dist/js/modern/builder/index.js +56 -37
- package/dist/js/modern/builder/share.js +1 -5
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +12 -46
- package/dist/js/modern/commands/dev.js +20 -23
- package/dist/js/modern/commands/inspect.js +4 -19
- package/dist/js/modern/commands/start.js +1 -2
- package/dist/js/modern/config/default.js +207 -0
- package/dist/js/modern/config/index.js +2 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
- package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +19 -18
- package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
- package/dist/js/modern/config/initial/index.js +11 -0
- package/dist/js/modern/config/initial/inits.js +117 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
- package/dist/js/modern/defineConfig.js +12 -0
- package/dist/js/modern/hooks.js +23 -19
- package/dist/js/modern/index.js +12 -19
- package/dist/js/modern/initialize/index.js +72 -0
- package/dist/js/modern/schema/Schema.js +39 -0
- package/dist/js/modern/schema/index.js +139 -0
- package/dist/js/modern/schema/legacy.js +284 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +2 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +4 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +1 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +2 -13
- package/dist/js/modern/utils/createFileWatcher.js +82 -0
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/restart.js +17 -0
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +30 -61
- package/dist/js/node/analyze/getBundleEntry.js +5 -19
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
- package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
- package/dist/js/node/analyze/getServerRoutes.js +24 -46
- package/dist/js/node/analyze/index.js +91 -70
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
- package/dist/js/node/builder/index.js +57 -51
- package/dist/js/node/builder/share.js +1 -13
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +10 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +19 -34
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +4 -26
- package/dist/js/node/commands/start.js +1 -11
- package/dist/js/node/config/default.js +214 -0
- package/dist/js/node/config/index.js +31 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
- package/dist/js/node/{builder → config/initial}/createOutputConfig.js +19 -20
- package/dist/js/node/config/initial/createSourceConfig.js +38 -0
- package/dist/js/node/config/initial/createToolsConfig.js +47 -0
- package/dist/js/node/config/initial/index.js +24 -0
- package/dist/js/node/config/initial/inits.js +127 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
- package/dist/js/node/defineConfig.js +20 -0
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +23 -30
- package/dist/js/node/index.js +35 -48
- package/dist/js/node/initialize/index.js +79 -0
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/schema/Schema.js +46 -0
- package/dist/js/node/schema/index.js +152 -0
- package/dist/js/node/schema/legacy.js +291 -0
- package/dist/js/node/types/config/deploy.js +0 -0
- package/dist/js/node/types/config/dev.js +0 -0
- package/dist/js/node/types/config/experiments.js +0 -0
- package/dist/js/node/types/config/html.js +0 -0
- package/dist/js/node/types/config/index.js +16 -0
- package/dist/js/node/types/config/output.js +0 -0
- package/dist/js/node/types/config/performance.js +0 -0
- package/dist/js/node/types/config/security.js +0 -0
- package/dist/js/node/types/config/source.js +0 -0
- package/dist/js/node/types/config/tools.js +0 -0
- package/dist/js/node/types/hooks.js +0 -0
- package/dist/js/node/types/index.js +38 -0
- package/dist/js/node/types/legacyConfig/deploy.js +0 -0
- package/dist/js/node/types/legacyConfig/dev.js +0 -0
- package/dist/js/node/types/legacyConfig/index.js +0 -0
- package/dist/js/node/types/legacyConfig/output.js +5 -0
- package/dist/js/node/types/legacyConfig/source.js +0 -0
- package/dist/js/node/types/legacyConfig/tools.js +0 -0
- package/dist/js/node/utils/commands.js +0 -2
- package/dist/js/node/utils/config.js +2 -26
- package/dist/js/node/utils/createFileWatcher.js +90 -0
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/restart.js +23 -0
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +58 -101
- package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
- package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
- package/dist/js/treeshaking/analyze/index.js +195 -91
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
- package/dist/js/treeshaking/builder/index.js +69 -65
- package/dist/js/treeshaking/builder/share.js +1 -5
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +41 -116
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +38 -46
- package/dist/js/treeshaking/commands/inspect.js +9 -27
- package/dist/js/treeshaking/commands/start.js +1 -9
- package/dist/js/treeshaking/config/default.js +200 -0
- package/dist/js/treeshaking/config/index.js +2 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +67 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
- package/dist/js/treeshaking/config/initial/index.js +11 -0
- package/dist/js/treeshaking/config/initial/inits.js +114 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
- package/dist/js/treeshaking/defineConfig.js +14 -0
- package/dist/js/treeshaking/hooks.js +23 -19
- package/dist/js/treeshaking/index.js +8 -43
- package/dist/js/treeshaking/initialize/index.js +121 -0
- package/dist/js/treeshaking/schema/Schema.js +75 -0
- package/dist/js/treeshaking/schema/index.js +138 -0
- package/dist/js/treeshaking/schema/legacy.js +273 -0
- package/dist/js/treeshaking/types/config/deploy.js +0 -0
- package/dist/js/treeshaking/types/config/dev.js +0 -0
- package/dist/js/treeshaking/types/config/experiments.js +0 -0
- package/dist/js/treeshaking/types/config/html.js +0 -0
- package/dist/js/treeshaking/types/config/index.js +2 -0
- package/dist/js/treeshaking/types/config/output.js +0 -0
- package/dist/js/treeshaking/types/config/performance.js +0 -0
- package/dist/js/treeshaking/types/config/security.js +0 -0
- package/dist/js/treeshaking/types/config/source.js +0 -0
- package/dist/js/treeshaking/types/config/tools.js +0 -0
- package/dist/js/treeshaking/types/hooks.js +0 -0
- package/dist/js/treeshaking/types/index.js +4 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
- package/dist/js/treeshaking/utils/config.js +2 -18
- package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/restart.js +45 -0
- package/dist/js/treeshaking/utils/routes.js +0 -4
- package/dist/types/analyze/generateCode.d.ts +3 -2
- package/dist/types/analyze/getBundleEntry.d.ts +2 -2
- package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
- package/dist/types/analyze/getServerRoutes.d.ts +3 -2
- package/dist/types/analyze/index.d.ts +3 -42
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +4 -2
- package/dist/types/analyze/utils.d.ts +1 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
- package/dist/types/builder/index.d.ts +7 -8
- package/dist/types/builder/share.d.ts +2 -2
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/inspect.d.ts +6 -1
- package/dist/types/commands/start.d.ts +2 -2
- package/dist/types/config/default.d.ts +3 -0
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
- package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
- package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
- package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
- package/dist/types/config/initial/index.d.ts +4 -0
- package/dist/types/config/initial/inits.d.ts +4 -0
- package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
- package/dist/types/defineConfig.d.ts +7 -0
- package/dist/types/hooks.d.ts +2 -42
- package/dist/types/index.d.ts +5 -7
- package/dist/types/initialize/index.d.ts +3 -0
- package/dist/types/schema/Schema.d.ts +14 -0
- package/dist/types/schema/index.d.ts +4 -0
- package/dist/types/schema/legacy.d.ts +3 -0
- package/dist/types/types/config/deploy.d.ts +9 -0
- package/dist/types/types/config/dev.d.ts +13 -0
- package/dist/types/types/config/experiments.d.ts +4 -0
- package/dist/types/types/config/html.d.ts +4 -0
- package/dist/types/types/config/index.d.ts +62 -0
- package/dist/types/types/config/output.d.ts +23 -0
- package/dist/types/types/config/performance.d.ts +4 -0
- package/dist/types/types/config/security.d.ts +4 -0
- package/dist/types/types/config/source.d.ts +22 -0
- package/dist/types/types/config/tools.d.ts +15 -0
- package/dist/types/types/hooks.d.ts +80 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
- package/dist/types/types/legacyConfig/dev.d.ts +12 -0
- package/dist/types/types/legacyConfig/index.d.ts +33 -0
- package/dist/types/types/legacyConfig/output.d.ts +51 -0
- package/dist/types/types/legacyConfig/source.d.ts +25 -0
- package/dist/types/types/legacyConfig/tools.d.ts +16 -0
- package/dist/types/utils/config.d.ts +2 -3
- package/dist/types/utils/createFileWatcher.d.ts +3 -0
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +3 -0
- package/package.json +26 -25
- package/dist/js/modern/builder/createHtmlConfig.js +0 -58
- package/dist/js/modern/builder/createSourceConfig.js +0 -85
- package/dist/js/modern/builder/createToolsConfig.js +0 -94
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/builder/createHtmlConfig.js +0 -76
- package/dist/js/node/builder/createSourceConfig.js +0 -99
- package/dist/js/node/builder/createToolsConfig.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
- package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
- package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
- package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- package/dist/types/builder/createHtmlConfig.d.ts +0 -6
- package/dist/types/builder/createOutputConfig.d.ts +0 -3
- package/dist/types/builder/createSourceConfig.d.ts +0 -5
- package/dist/types/builder/createToolsConfig.d.ts +0 -13
- package/dist/types/utils/createCompiler.d.ts +0 -12
|
@@ -4,37 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateCode = exports.createImportStatements = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _core = require("@modern-js/core");
|
|
13
|
-
|
|
14
10
|
var _esbuild = _interopRequireDefault(require("esbuild"));
|
|
15
|
-
|
|
16
11
|
var _commands = require("../utils/commands");
|
|
17
|
-
|
|
18
12
|
var templates = _interopRequireWildcard(require("./templates"));
|
|
19
|
-
|
|
20
13
|
var _getClientRoutes = require("./getClientRoutes");
|
|
21
|
-
|
|
22
14
|
var _constants = require("./constants");
|
|
23
|
-
|
|
24
15
|
var _utils2 = require("./utils");
|
|
25
|
-
|
|
26
16
|
var _nestedRoutes = require("./nestedRoutes");
|
|
27
|
-
|
|
28
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
-
|
|
30
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
-
|
|
32
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
-
|
|
34
20
|
const createImportSpecifier = specifiers => {
|
|
35
21
|
let defaults = '';
|
|
36
22
|
const named = [];
|
|
37
|
-
|
|
38
23
|
for (const {
|
|
39
24
|
local,
|
|
40
25
|
imported
|
|
@@ -47,7 +32,6 @@ const createImportSpecifier = specifiers => {
|
|
|
47
32
|
named.push(imported);
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
|
-
|
|
51
35
|
if (defaults && named.length) {
|
|
52
36
|
return `${defaults}, { ${named.join(', ')} }`;
|
|
53
37
|
} else if (defaults) {
|
|
@@ -56,12 +40,10 @@ const createImportSpecifier = specifiers => {
|
|
|
56
40
|
return `{ ${named.join(', ')} }`;
|
|
57
41
|
}
|
|
58
42
|
};
|
|
59
|
-
|
|
60
43
|
const createImportStatements = statements => {
|
|
61
44
|
// merge import statements with the same value.
|
|
62
45
|
const deDuplicated = [];
|
|
63
46
|
const seen = new Map();
|
|
64
|
-
|
|
65
47
|
for (const {
|
|
66
48
|
value,
|
|
67
49
|
specifiers,
|
|
@@ -76,24 +58,20 @@ const createImportStatements = statements => {
|
|
|
76
58
|
seen.set(value, specifiers);
|
|
77
59
|
} else {
|
|
78
60
|
var _deDuplicated$modifyI, _deDuplicated$modifyI2;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
seen.get(value).push(...specifiers);
|
|
62
|
+
// make "initialize" param can be connected when multiple plugins were imported from same package
|
|
82
63
|
const modifyIndex = deDuplicated.findIndex(v => v.value === value);
|
|
83
64
|
const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
|
|
84
65
|
deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
|
|
85
66
|
}
|
|
86
67
|
}
|
|
87
|
-
|
|
88
68
|
return deDuplicated.map(({
|
|
89
69
|
value,
|
|
90
70
|
specifiers,
|
|
91
71
|
initialize
|
|
92
72
|
}) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
|
|
93
73
|
};
|
|
94
|
-
|
|
95
74
|
exports.createImportStatements = createImportStatements;
|
|
96
|
-
|
|
97
75
|
const buildLoader = async (entry, outfile) => {
|
|
98
76
|
const loader = {
|
|
99
77
|
'.js': 'jsx',
|
|
@@ -113,32 +91,27 @@ const buildLoader = async (entry, outfile) => {
|
|
|
113
91
|
outfile,
|
|
114
92
|
plugins: [{
|
|
115
93
|
name: 'make-all-packages-external',
|
|
116
|
-
|
|
117
94
|
setup(build) {
|
|
118
95
|
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
|
119
96
|
build.onResolve({
|
|
120
97
|
filter: EXTERNAL_REGEXP
|
|
121
98
|
}, args => {
|
|
122
|
-
let external = true;
|
|
123
|
-
|
|
99
|
+
let external = true;
|
|
100
|
+
// FIXME: windows external entrypoint
|
|
124
101
|
if (args.kind === 'entry-point') {
|
|
125
102
|
external = false;
|
|
126
103
|
}
|
|
127
|
-
|
|
128
104
|
return {
|
|
129
105
|
path: args.path,
|
|
130
106
|
external
|
|
131
107
|
};
|
|
132
108
|
});
|
|
133
109
|
}
|
|
134
|
-
|
|
135
110
|
}]
|
|
136
111
|
});
|
|
137
112
|
};
|
|
138
|
-
|
|
139
113
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
140
114
|
var _config$runtime, _config$runtime$route;
|
|
141
|
-
|
|
142
115
|
const {
|
|
143
116
|
internalDirectory,
|
|
144
117
|
distDirectory,
|
|
@@ -150,10 +123,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
150
123
|
const islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
|
|
151
124
|
const {
|
|
152
125
|
mountId
|
|
153
|
-
} = config.
|
|
126
|
+
} = config.html;
|
|
154
127
|
const getRoutes = islegacy ? _getClientRoutes.getClientRoutesLegacy : _getClientRoutes.getClientRoutes;
|
|
155
128
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
156
|
-
|
|
157
129
|
async function generateEntryCode(entrypoint) {
|
|
158
130
|
const {
|
|
159
131
|
entryName,
|
|
@@ -161,13 +133,11 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
161
133
|
customBootstrap,
|
|
162
134
|
fileSystemRoutes
|
|
163
135
|
} = entrypoint;
|
|
164
|
-
|
|
165
136
|
if (isAutoMount) {
|
|
166
137
|
// generate routes file for file system routes entrypoint.
|
|
167
138
|
if (fileSystemRoutes) {
|
|
168
139
|
let initialRoutes = [];
|
|
169
140
|
let nestedRoute = null;
|
|
170
|
-
|
|
171
141
|
if (entrypoint.entry) {
|
|
172
142
|
initialRoutes = getRoutes({
|
|
173
143
|
entrypoint,
|
|
@@ -177,25 +147,21 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
177
147
|
internalDirAlias
|
|
178
148
|
});
|
|
179
149
|
}
|
|
180
|
-
|
|
181
150
|
if (entrypoint.nestedRoutesEntry) {
|
|
182
151
|
if (!islegacy) {
|
|
183
152
|
nestedRoute = await (0, _nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
184
153
|
name: internalSrcAlias,
|
|
185
154
|
basename: srcDirectory
|
|
186
|
-
});
|
|
187
|
-
|
|
155
|
+
}, entrypoint.entryName);
|
|
188
156
|
if (nestedRoute) {
|
|
189
157
|
initialRoutes.unshift(nestedRoute);
|
|
190
158
|
}
|
|
191
159
|
} else {
|
|
192
|
-
_utils.logger.error('Nested routes is not supported in legacy mode.');
|
|
193
|
-
|
|
194
|
-
|
|
160
|
+
_utils.logger.error('Nested routes is not supported in legacy mode.');
|
|
161
|
+
// eslint-disable-next-line no-process-exit
|
|
195
162
|
process.exit(1);
|
|
196
163
|
}
|
|
197
164
|
}
|
|
198
|
-
|
|
199
165
|
const {
|
|
200
166
|
routes
|
|
201
167
|
} = await hookRunners.modifyFileSystemRoutes({
|
|
@@ -205,13 +171,19 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
205
171
|
const config = (0, _core.useResolvedConfigContext)();
|
|
206
172
|
const ssr = config === null || config === void 0 ? void 0 : config.server.ssr;
|
|
207
173
|
let mode;
|
|
208
|
-
|
|
209
174
|
if (ssr) {
|
|
210
175
|
mode = typeof ssr === 'object' ? ssr.mode || 'string' : 'string';
|
|
211
176
|
} else {
|
|
212
177
|
mode = false;
|
|
213
178
|
}
|
|
214
|
-
|
|
179
|
+
if (mode === 'stream') {
|
|
180
|
+
const hasPageRoute = routes.some(route => 'type' in route && route.type === 'page');
|
|
181
|
+
if (hasPageRoute) {
|
|
182
|
+
_utils.logger.error('streaming ssr is not supported when pages dir exists');
|
|
183
|
+
// eslint-disable-next-line no-process-exit
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
215
187
|
const {
|
|
216
188
|
code
|
|
217
189
|
} = await hookRunners.beforeGenerateRoutes({
|
|
@@ -219,15 +191,15 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
219
191
|
code: templates.fileSystemRoutes({
|
|
220
192
|
routes,
|
|
221
193
|
ssrMode: mode,
|
|
222
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry
|
|
194
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
195
|
+
entryName: entrypoint.entryName
|
|
223
196
|
})
|
|
224
|
-
});
|
|
197
|
+
});
|
|
225
198
|
|
|
199
|
+
// extract nested router loaders
|
|
226
200
|
if (entrypoint.nestedRoutesEntry) {
|
|
227
201
|
const routesServerFile = _path.default.join(internalDirectory, entryName, 'routes.server.js');
|
|
228
|
-
|
|
229
202
|
const outputRoutesServerFile = _path.default.join(distDirectory, 'loader-routes', entryName, 'index.js');
|
|
230
|
-
|
|
231
203
|
const code = templates.routesForServer({
|
|
232
204
|
routes: routes,
|
|
233
205
|
alias: {
|
|
@@ -239,11 +211,10 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
239
211
|
await _utils.fs.writeFile(routesServerFile, code);
|
|
240
212
|
await buildLoader(routesServerFile, outputRoutesServerFile);
|
|
241
213
|
}
|
|
242
|
-
|
|
243
214
|
_utils.fs.outputFileSync(_path.default.resolve(internalDirectory, `./${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
|
|
244
|
-
}
|
|
245
|
-
|
|
215
|
+
}
|
|
246
216
|
|
|
217
|
+
// call modifyEntryImports hook
|
|
247
218
|
const {
|
|
248
219
|
imports: importStatements
|
|
249
220
|
} = await hookRunners.modifyEntryImports({
|
|
@@ -255,15 +226,17 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
255
226
|
internalDirAlias,
|
|
256
227
|
internalDirectory
|
|
257
228
|
})
|
|
258
|
-
});
|
|
229
|
+
});
|
|
259
230
|
|
|
231
|
+
// call modifyEntryRuntimePlugins hook
|
|
260
232
|
const {
|
|
261
233
|
plugins
|
|
262
234
|
} = await hookRunners.modifyEntryRuntimePlugins({
|
|
263
235
|
entrypoint,
|
|
264
236
|
plugins: []
|
|
265
|
-
});
|
|
237
|
+
});
|
|
266
238
|
|
|
239
|
+
// call modifyEntryRenderFunction hook
|
|
267
240
|
const {
|
|
268
241
|
code: renderFunction
|
|
269
242
|
} = await hookRunners.modifyEntryRenderFunction({
|
|
@@ -273,8 +246,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
273
246
|
customBootstrap,
|
|
274
247
|
fileSystemRoutes
|
|
275
248
|
})
|
|
276
|
-
});
|
|
249
|
+
});
|
|
277
250
|
|
|
251
|
+
// call modifyEntryExport hook
|
|
278
252
|
const {
|
|
279
253
|
exportStatement
|
|
280
254
|
} = await hookRunners.modifyEntryExport({
|
|
@@ -287,11 +261,10 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
287
261
|
renderFunction,
|
|
288
262
|
exportStatement
|
|
289
263
|
});
|
|
290
|
-
|
|
291
264
|
const entryFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_POINT_FILE_NAME}`);
|
|
265
|
+
entrypoint.entry = entryFile;
|
|
292
266
|
|
|
293
|
-
|
|
294
|
-
|
|
267
|
+
// generate entry file.
|
|
295
268
|
if (config.source.enableAsyncEntry) {
|
|
296
269
|
const {
|
|
297
270
|
code: asyncEntryCode
|
|
@@ -299,11 +272,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
299
272
|
entrypoint,
|
|
300
273
|
code: `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
|
|
301
274
|
});
|
|
302
|
-
|
|
303
275
|
_utils.fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
|
304
|
-
|
|
305
276
|
const bootstrapFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
306
|
-
|
|
307
277
|
_utils.fs.outputFileSync(bootstrapFile, code, 'utf8');
|
|
308
278
|
} else {
|
|
309
279
|
_utils.fs.outputFileSync(entryFile, code, 'utf8');
|
|
@@ -311,5 +281,4 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
311
281
|
}
|
|
312
282
|
}
|
|
313
283
|
};
|
|
314
|
-
|
|
315
284
|
exports.generateCode = generateCode;
|
|
@@ -4,40 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBundleEntry = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _getFileSystemEntry = require("./getFileSystemEntry");
|
|
13
|
-
|
|
14
10
|
var _constants = require("./constants");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
const ensureExtensions = file => {
|
|
19
13
|
if (!_path.default.extname(file)) {
|
|
20
14
|
return (0, _utils.findExists)(_constants.JS_EXTENSIONS.map(ext => `${file}${ext}`)) || file;
|
|
21
15
|
}
|
|
22
|
-
|
|
23
16
|
return file;
|
|
24
17
|
};
|
|
25
|
-
|
|
26
18
|
const ifAlreadyExists = (entrypoints, checked) => entrypoints.some(entrypoint => {
|
|
27
19
|
if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
|
|
28
20
|
// reset entryName
|
|
29
21
|
checked.entryName = entrypoint.entryName;
|
|
30
22
|
return true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
}
|
|
24
|
+
// filesystem routes entrypoint conflict with normal entrypoint.
|
|
34
25
|
if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
|
|
35
26
|
throw new Error(`Entry configuration conflicts\n Your configuration: ${checked.entry}.\n Default entrypoint: ${entrypoint.entry}\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules.`);
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
return false;
|
|
39
29
|
});
|
|
40
|
-
|
|
41
30
|
const getBundleEntry = (appContext, config) => {
|
|
42
31
|
const {
|
|
43
32
|
appDirectory,
|
|
@@ -50,8 +39,9 @@ const getBundleEntry = (appContext, config) => {
|
|
|
50
39
|
entriesDir
|
|
51
40
|
}
|
|
52
41
|
} = config;
|
|
53
|
-
const defaults = disableDefaultEntries ? [] : (0, _getFileSystemEntry.getFileSystemEntry)(appContext, config);
|
|
42
|
+
const defaults = disableDefaultEntries ? [] : (0, _getFileSystemEntry.getFileSystemEntry)(appContext, config);
|
|
54
43
|
|
|
44
|
+
// merge entrypoints from user config with directory convention.
|
|
55
45
|
if (entries) {
|
|
56
46
|
Object.keys(entries).forEach(name => {
|
|
57
47
|
const value = entries[name];
|
|
@@ -66,16 +56,14 @@ const getBundleEntry = (appContext, config) => {
|
|
|
66
56
|
isAutoMount: !value.disableMount,
|
|
67
57
|
fileSystemRoutes: value.enableFileSystemRoutes ? {} : undefined
|
|
68
58
|
};
|
|
69
|
-
|
|
70
59
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
71
60
|
defaults.push(entrypoint);
|
|
72
61
|
}
|
|
73
62
|
});
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
if (!disableDefaultEntries) {
|
|
77
65
|
// find main entry point which server route is '/'.
|
|
78
|
-
const entriesDirAbs = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir);
|
|
66
|
+
const entriesDirAbs = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir || '');
|
|
79
67
|
const found = defaults.find(({
|
|
80
68
|
entryName,
|
|
81
69
|
entry,
|
|
@@ -83,8 +71,6 @@ const getBundleEntry = (appContext, config) => {
|
|
|
83
71
|
}) => entryName === packageName || _path.default.dirname(entry) === entriesDirAbs || _path.default.dirname(_nestedRoutesEntry) === entriesDirAbs);
|
|
84
72
|
found && (found.entryName = _utils.MAIN_ENTRY_NAME);
|
|
85
73
|
}
|
|
86
|
-
|
|
87
74
|
return defaults;
|
|
88
75
|
};
|
|
89
|
-
|
|
90
76
|
exports.getBundleEntry = getBundleEntry;
|
|
@@ -4,41 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getClientRoutes = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _makeLegalIdentifier = require("../makeLegalIdentifier");
|
|
13
|
-
|
|
14
10
|
var _constants = require("../constants");
|
|
15
|
-
|
|
16
11
|
var _utils2 = require("../utils");
|
|
17
|
-
|
|
18
12
|
var _utils3 = require("./utils");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
|
|
26
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
28
17
|
const compName = (srcDirectory, filePath) => {
|
|
29
18
|
const legalCompName = (0, _makeLegalIdentifier.makeLegalIdentifier)(_path.default.relative(srcDirectory, filePath));
|
|
30
19
|
return `Comp_${legalCompName}`;
|
|
31
20
|
};
|
|
32
|
-
|
|
33
21
|
const layoutNameAbbr = filePath => {
|
|
34
22
|
const prefix = 'L_';
|
|
35
23
|
const dirName = _path.default.dirname(filePath).split('/').pop() || '';
|
|
36
24
|
return `${prefix}${(0, _makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
|
|
37
25
|
};
|
|
38
|
-
|
|
39
26
|
const parents = [];
|
|
40
|
-
/* eslint-disable no-param-reassign */
|
|
41
27
|
|
|
28
|
+
/* eslint-disable no-param-reassign */
|
|
42
29
|
const recursiveReadDir = ({
|
|
43
30
|
dir,
|
|
44
31
|
routes,
|
|
@@ -50,7 +37,6 @@ const recursiveReadDir = ({
|
|
|
50
37
|
let resetParent = false;
|
|
51
38
|
let parent = parents[parents.length - 1];
|
|
52
39
|
const layout = (0, _utils3.findLayout)(dir);
|
|
53
|
-
|
|
54
40
|
if (layout) {
|
|
55
41
|
if (_basePath === '/') {
|
|
56
42
|
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
@@ -72,18 +58,13 @@ const recursiveReadDir = ({
|
|
|
72
58
|
routes = route.children;
|
|
73
59
|
}
|
|
74
60
|
}
|
|
75
|
-
|
|
76
61
|
for (const relative of _utils.fs.readdirSync(dir)) {
|
|
77
62
|
const filePath = _path.default.join(dir, relative);
|
|
78
|
-
|
|
79
63
|
if (!(0, _utils3.shouldSkip)(filePath)) {
|
|
80
64
|
const filename = _path.default.basename(filePath, _path.default.extname(filePath));
|
|
81
|
-
|
|
82
65
|
const alias = (0, _utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
|
|
83
66
|
const componentName = compName(srcDirectory, filePath);
|
|
84
|
-
|
|
85
67
|
const dynamicRouteMatched = _constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
86
|
-
|
|
87
68
|
if (dynamicRouteMatched) {
|
|
88
69
|
if (hasDynamicRoute) {
|
|
89
70
|
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
@@ -91,7 +72,6 @@ const recursiveReadDir = ({
|
|
|
91
72
|
hasDynamicRoute = true;
|
|
92
73
|
}
|
|
93
74
|
}
|
|
94
|
-
|
|
95
75
|
const route = {
|
|
96
76
|
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
97
77
|
_component: alias,
|
|
@@ -99,7 +79,6 @@ const recursiveReadDir = ({
|
|
|
99
79
|
parent,
|
|
100
80
|
type: 'page'
|
|
101
81
|
};
|
|
102
|
-
|
|
103
82
|
if (_utils.fs.statSync(filePath).isDirectory()) {
|
|
104
83
|
recursiveReadDir({
|
|
105
84
|
dir: filePath,
|
|
@@ -110,38 +89,32 @@ const recursiveReadDir = ({
|
|
|
110
89
|
});
|
|
111
90
|
continue;
|
|
112
91
|
}
|
|
113
|
-
|
|
114
92
|
if (filename === _constants.FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
115
93
|
continue;
|
|
116
94
|
}
|
|
117
|
-
|
|
118
95
|
if (filename === _constants.FILE_SYSTEM_ROUTES_INDEX) {
|
|
119
96
|
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
120
97
|
}
|
|
121
|
-
|
|
122
98
|
if (filename === '404' && _basePath === '/') {
|
|
123
99
|
route.path = '*';
|
|
124
100
|
}
|
|
125
|
-
|
|
126
101
|
routes.push(route);
|
|
127
102
|
}
|
|
128
103
|
}
|
|
129
|
-
|
|
130
104
|
if (resetParent) {
|
|
131
105
|
parents.pop();
|
|
132
106
|
}
|
|
133
107
|
};
|
|
134
108
|
/* eslint-enable no-param-reassign */
|
|
135
109
|
|
|
136
|
-
|
|
137
110
|
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
138
111
|
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.children) ? flat(route.children) : [route]), []);
|
|
139
|
-
|
|
140
112
|
const generate = route => {
|
|
141
113
|
const codes = [];
|
|
142
114
|
let lastComponent = route.component;
|
|
143
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
115
|
+
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
144
116
|
|
|
117
|
+
// eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
145
118
|
while (route = route.parent) {
|
|
146
119
|
const layoutComponent = route.component;
|
|
147
120
|
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
@@ -150,17 +123,13 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
150
123
|
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
151
124
|
lastComponent = currentComponent;
|
|
152
125
|
}
|
|
153
|
-
|
|
154
126
|
const file = _path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
155
|
-
|
|
156
127
|
_utils.fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
157
|
-
|
|
158
128
|
return {
|
|
159
129
|
component: lastComponent,
|
|
160
130
|
_component: (0, _utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
|
|
161
131
|
};
|
|
162
132
|
};
|
|
163
|
-
|
|
164
133
|
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
165
134
|
parent: undefined
|
|
166
135
|
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
@@ -168,7 +137,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
168
137
|
}));
|
|
169
138
|
return normalized;
|
|
170
139
|
};
|
|
171
|
-
|
|
172
140
|
const getClientRoutes = ({
|
|
173
141
|
entrypoint,
|
|
174
142
|
srcDirectory,
|
|
@@ -180,15 +148,12 @@ const getClientRoutes = ({
|
|
|
180
148
|
entry,
|
|
181
149
|
entryName
|
|
182
150
|
} = entrypoint;
|
|
183
|
-
|
|
184
151
|
if (!_utils.fs.existsSync(entry)) {
|
|
185
152
|
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
186
153
|
}
|
|
187
|
-
|
|
188
154
|
if (!(_utils.fs.existsSync(entry) && _utils.fs.statSync(entry).isDirectory())) {
|
|
189
155
|
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
190
156
|
}
|
|
191
|
-
|
|
192
157
|
let routes = [];
|
|
193
158
|
recursiveReadDir({
|
|
194
159
|
dir: entry,
|
|
@@ -197,25 +162,20 @@ const getClientRoutes = ({
|
|
|
197
162
|
srcDirectory,
|
|
198
163
|
srcAlias
|
|
199
164
|
});
|
|
200
|
-
|
|
201
165
|
const internalComponentsDir = _path.default.resolve(internalDirectory, `${entryName}/${_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
202
|
-
|
|
203
166
|
_utils.fs.emptyDirSync(internalComponentsDir);
|
|
204
|
-
|
|
205
167
|
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
206
|
-
parents.length = 0;
|
|
168
|
+
parents.length = 0;
|
|
207
169
|
|
|
170
|
+
// FIXME: support more situations
|
|
208
171
|
routes.sort((a, b) => {
|
|
209
172
|
const delta = (0, _utils3.getRouteWeight)(a.path) - (0, _utils3.getRouteWeight)(b.path);
|
|
210
|
-
|
|
211
173
|
if (delta === 0) {
|
|
212
174
|
return a.path.length - b.path.length;
|
|
213
175
|
}
|
|
214
|
-
|
|
215
176
|
return delta;
|
|
216
177
|
});
|
|
217
178
|
(0, _utils3.debug)(`fileSystem routes: %o`, routes);
|
|
218
179
|
return routes;
|
|
219
180
|
};
|
|
220
|
-
|
|
221
181
|
exports.getClientRoutes = getClientRoutes;
|