@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
|
@@ -1,60 +1,35 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
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; }
|
|
4
|
-
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
import * as path from 'path';
|
|
8
|
-
import { createAsyncWaterfall } from '@modern-js/plugin';
|
|
9
5
|
import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
|
|
10
6
|
import { cloneDeep } from '@modern-js/utils/lodash';
|
|
7
|
+
import { createBuilderForEdenX } from "../builder";
|
|
8
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
9
|
+
import { generateRoutes } from "../utils/routes";
|
|
10
|
+
import { emitResolvedConfig } from "../utils/config";
|
|
11
|
+
import { getCommand } from "../utils/commands";
|
|
12
|
+
import { initialNormalizedConfig } from "../config";
|
|
11
13
|
import { isRouteComponentFile } from "./utils";
|
|
12
14
|
const debug = createDebugger('plugin-analyze');
|
|
13
|
-
export const modifyEntryImports = createAsyncWaterfall();
|
|
14
|
-
export const modifyEntryExport = createAsyncWaterfall();
|
|
15
|
-
export const addRuntimeExports = createAsyncWaterfall();
|
|
16
|
-
export const modifyEntryRuntimePlugins = createAsyncWaterfall();
|
|
17
|
-
export const modifyEntryRenderFunction = createAsyncWaterfall();
|
|
18
|
-
export const modifyAsyncEntry = createAsyncWaterfall();
|
|
19
|
-
export const modifyFileSystemRoutes = createAsyncWaterfall();
|
|
20
|
-
export const modifyServerRoutes = createAsyncWaterfall();
|
|
21
|
-
export const htmlPartials = createAsyncWaterfall();
|
|
22
|
-
export const beforeGenerateRoutes = createAsyncWaterfall();
|
|
23
|
-
export const addDefineTypes = createAsyncWaterfall();
|
|
24
15
|
export default (() => ({
|
|
25
16
|
name: '@modern-js/plugin-analyze',
|
|
26
|
-
registerHook: {
|
|
27
|
-
modifyAsyncEntry,
|
|
28
|
-
modifyEntryImports,
|
|
29
|
-
modifyEntryExport,
|
|
30
|
-
modifyEntryRuntimePlugins,
|
|
31
|
-
modifyEntryRenderFunction,
|
|
32
|
-
modifyFileSystemRoutes,
|
|
33
|
-
modifyServerRoutes,
|
|
34
|
-
htmlPartials,
|
|
35
|
-
addRuntimeExports,
|
|
36
|
-
beforeGenerateRoutes,
|
|
37
|
-
addDefineTypes
|
|
38
|
-
},
|
|
39
17
|
setup: api => {
|
|
40
18
|
let pagesDir = [];
|
|
41
19
|
let originEntrypoints = [];
|
|
42
20
|
return {
|
|
43
21
|
async prepare() {
|
|
44
22
|
var _resolvedConfig$sourc;
|
|
45
|
-
|
|
46
|
-
const appContext = api.useAppContext();
|
|
23
|
+
let appContext = api.useAppContext();
|
|
47
24
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
48
25
|
const hookRunners = api.useHookRunners();
|
|
49
|
-
|
|
50
26
|
try {
|
|
51
27
|
fs.emptydirSync(appContext.internalDirectory);
|
|
52
|
-
} catch (_unused) {
|
|
28
|
+
} catch (_unused) {
|
|
29
|
+
// FIXME:
|
|
53
30
|
}
|
|
54
|
-
|
|
55
|
-
const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
31
|
+
const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
56
32
|
await hookRunners.addRuntimeExports();
|
|
57
|
-
|
|
58
33
|
if (apiOnly) {
|
|
59
34
|
const {
|
|
60
35
|
routes
|
|
@@ -62,13 +37,13 @@ export default (() => ({
|
|
|
62
37
|
routes: []
|
|
63
38
|
});
|
|
64
39
|
debug(`server routes: %o`, routes);
|
|
65
|
-
|
|
40
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
66
41
|
apiOnly,
|
|
67
42
|
serverRoutes: routes
|
|
68
|
-
})
|
|
43
|
+
});
|
|
44
|
+
api.setAppContext(appContext);
|
|
69
45
|
return;
|
|
70
46
|
}
|
|
71
|
-
|
|
72
47
|
const [{
|
|
73
48
|
getBundleEntry
|
|
74
49
|
}, {
|
|
@@ -91,10 +66,11 @@ export default (() => ({
|
|
|
91
66
|
routes: initialRoutes
|
|
92
67
|
});
|
|
93
68
|
debug(`server routes: %o`, routes);
|
|
94
|
-
|
|
69
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
95
70
|
entrypoints,
|
|
96
71
|
serverRoutes: routes
|
|
97
|
-
})
|
|
72
|
+
});
|
|
73
|
+
api.setAppContext(appContext);
|
|
98
74
|
const nestedRouteEntries = entrypoints.map(point => point.nestedRoutesEntry).filter(Boolean);
|
|
99
75
|
pagesDir = entrypoints.map(point => point.entry).filter(Boolean).concat(nestedRouteEntries);
|
|
100
76
|
originEntrypoints = cloneDeep(entrypoints);
|
|
@@ -106,19 +82,89 @@ export default (() => ({
|
|
|
106
82
|
debug(`html templates: %o`, htmlTemplates);
|
|
107
83
|
await hookRunners.addDefineTypes();
|
|
108
84
|
debug(`add Define Types`);
|
|
109
|
-
|
|
85
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
110
86
|
entrypoints,
|
|
111
87
|
checkedEntries: defaultChecked,
|
|
112
88
|
apiOnly,
|
|
113
89
|
serverRoutes: routes,
|
|
114
90
|
htmlTemplates
|
|
115
|
-
})
|
|
91
|
+
});
|
|
92
|
+
api.setAppContext(appContext);
|
|
93
|
+
const command = getCommand();
|
|
94
|
+
const buildCommands = ['dev', 'build', 'inspect', 'deploy'];
|
|
95
|
+
if (buildCommands.includes(command)) {
|
|
96
|
+
const normalizedConfig = api.useResolvedConfigContext();
|
|
97
|
+
const builder = await createBuilderForEdenX({
|
|
98
|
+
normalizedConfig: normalizedConfig,
|
|
99
|
+
appContext,
|
|
100
|
+
compatPluginConfig: {
|
|
101
|
+
async onBeforeBuild({
|
|
102
|
+
bundlerConfigs
|
|
103
|
+
}) {
|
|
104
|
+
const hookRunners = api.useHookRunners();
|
|
105
|
+
await generateRoutes(appContext);
|
|
106
|
+
await hookRunners.beforeBuild({
|
|
107
|
+
bundlerConfigs
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
async onAfterBuild({
|
|
111
|
+
stats
|
|
112
|
+
}) {
|
|
113
|
+
const hookRunners = api.useHookRunners();
|
|
114
|
+
await hookRunners.afterBuild({
|
|
115
|
+
stats
|
|
116
|
+
});
|
|
117
|
+
await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
|
|
118
|
+
},
|
|
119
|
+
async onDevCompileDone({
|
|
120
|
+
isFirstCompile
|
|
121
|
+
}) {
|
|
122
|
+
const hookRunners = api.useHookRunners();
|
|
123
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
124
|
+
hookRunners.afterDev();
|
|
125
|
+
if (isFirstCompile) {
|
|
126
|
+
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
async onBeforeCreateCompiler({
|
|
131
|
+
bundlerConfigs
|
|
132
|
+
}) {
|
|
133
|
+
const hookRunners = api.useHookRunners();
|
|
134
|
+
// run modernjs framework `beforeCreateCompiler` hook
|
|
135
|
+
await hookRunners.beforeCreateCompiler({
|
|
136
|
+
bundlerConfigs
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
async onAfterCreateCompiler({
|
|
140
|
+
compiler
|
|
141
|
+
}) {
|
|
142
|
+
const hookRunners = api.useHookRunners();
|
|
143
|
+
// run modernjs framework afterCreateCompiler hooks
|
|
144
|
+
await hookRunners.afterCreateCompiler({
|
|
145
|
+
compiler
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
151
|
+
builder
|
|
152
|
+
});
|
|
153
|
+
api.setAppContext(appContext);
|
|
154
|
+
}
|
|
116
155
|
},
|
|
117
|
-
|
|
118
156
|
watchFiles() {
|
|
119
157
|
return pagesDir;
|
|
120
158
|
},
|
|
121
|
-
|
|
159
|
+
resolvedConfig({
|
|
160
|
+
resolved
|
|
161
|
+
}) {
|
|
162
|
+
const appContext = api.useAppContext();
|
|
163
|
+
const config = initialNormalizedConfig(resolved, appContext);
|
|
164
|
+
return {
|
|
165
|
+
resolved: config
|
|
166
|
+
};
|
|
167
|
+
},
|
|
122
168
|
async fileChange(e) {
|
|
123
169
|
const appContext = api.useAppContext();
|
|
124
170
|
const {
|
|
@@ -128,12 +174,9 @@ export default (() => ({
|
|
|
128
174
|
filename,
|
|
129
175
|
eventType
|
|
130
176
|
} = e;
|
|
131
|
-
|
|
132
177
|
const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
|
|
133
|
-
|
|
134
178
|
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
135
179
|
const isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
|
|
136
|
-
|
|
137
180
|
if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
|
|
138
181
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
139
182
|
const {
|
|
@@ -143,7 +186,6 @@ export default (() => ({
|
|
|
143
186
|
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
144
187
|
}
|
|
145
188
|
}
|
|
146
|
-
|
|
147
189
|
};
|
|
148
190
|
}
|
|
149
191
|
}));
|
|
@@ -2,14 +2,11 @@ import fs from 'fs';
|
|
|
2
2
|
import { parse } from '@babel/parser';
|
|
3
3
|
import traverse from '@babel/traverse';
|
|
4
4
|
import * as t from '@babel/types';
|
|
5
|
-
|
|
6
5
|
const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
|
7
|
-
|
|
8
6
|
export const isDefaultExportFunction = file => {
|
|
9
7
|
if (!file || !fs.existsSync(file)) {
|
|
10
8
|
return false;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
const ast = parse(fs.readFileSync(file, 'utf8'), {
|
|
14
11
|
sourceType: 'unambiguous',
|
|
15
12
|
plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
|
|
@@ -22,7 +19,6 @@ export const isDefaultExportFunction = file => {
|
|
|
22
19
|
const {
|
|
23
20
|
declaration
|
|
24
21
|
} = path.node;
|
|
25
|
-
|
|
26
22
|
if (isFunction(declaration)) {
|
|
27
23
|
isExportFunction = true;
|
|
28
24
|
}
|
|
@@ -7,10 +7,8 @@ const builtins = 'arguments Infinity NaN undefined null true false eval uneval i
|
|
|
7
7
|
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
8
8
|
export function makeLegalIdentifier(str) {
|
|
9
9
|
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
10
|
-
|
|
11
10
|
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
|
12
11
|
return `_${identifier}`;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
return identifier || '_';
|
|
16
14
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
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; }
|
|
4
|
-
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
import * as path from 'path';
|
|
8
5
|
import { fs, getRouteId } from '@modern-js/utils';
|
|
9
6
|
import { JS_EXTENSIONS } from "./constants";
|
|
@@ -14,37 +11,30 @@ const LOADING_FILE = 'loading';
|
|
|
14
11
|
const ERROR_FILE = 'error';
|
|
15
12
|
const LOADER_FILE = 'loader';
|
|
16
13
|
const conventionNames = [LAYOUT_FILE, PAGE_FILE, LOADING_FILE, ERROR_FILE, LOADER_FILE];
|
|
17
|
-
|
|
18
14
|
const replaceDynamicPath = routePath => {
|
|
19
15
|
return routePath.replace(/\[(.*?)\]/g, ':$1');
|
|
20
16
|
};
|
|
21
|
-
|
|
22
|
-
const createIndexRoute = (routeInfo, rootDir, filename) => {
|
|
17
|
+
const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
23
18
|
return createRoute(_objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
24
19
|
index: true,
|
|
25
20
|
children: undefined
|
|
26
|
-
}), rootDir, filename);
|
|
21
|
+
}), rootDir, filename, entryName);
|
|
27
22
|
};
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const id = getRouteId(filename, rootDir);
|
|
23
|
+
const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
24
|
+
const id = getRouteId(filename, rootDir, entryName);
|
|
31
25
|
return _objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
32
26
|
id,
|
|
33
27
|
type: 'nested'
|
|
34
28
|
});
|
|
35
29
|
};
|
|
36
|
-
|
|
37
|
-
export const walk = async (dirname, rootDir, alias) => {
|
|
30
|
+
export const walk = async (dirname, rootDir, alias, entryName) => {
|
|
38
31
|
if (!(await fs.pathExists(dirname))) {
|
|
39
32
|
return null;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
const isDirectory = (await fs.stat(dirname)).isDirectory();
|
|
43
|
-
|
|
44
35
|
if (!isDirectory) {
|
|
45
36
|
return null;
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
const relativeDir = path.relative(rootDir, dirname);
|
|
49
39
|
const pathSegments = relativeDir.split(path.sep);
|
|
50
40
|
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
@@ -52,65 +42,52 @@ export const walk = async (dirname, rootDir, alias) => {
|
|
|
52
42
|
const isPathlessLayout = lastSegment.startsWith('__');
|
|
53
43
|
const isWithoutLayoutPath = lastSegment.includes('.');
|
|
54
44
|
let routePath = isRoot || isPathlessLayout ? '/' : `${lastSegment}`;
|
|
55
|
-
|
|
56
45
|
if (isWithoutLayoutPath) {
|
|
57
46
|
routePath = lastSegment.split('.').join('/');
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
routePath = replaceDynamicPath(routePath);
|
|
61
49
|
const route = {
|
|
62
50
|
path: routePath,
|
|
63
51
|
children: []
|
|
64
52
|
};
|
|
65
53
|
const items = await fs.readdir(dirname);
|
|
66
|
-
|
|
67
54
|
for (const item of items) {
|
|
68
55
|
const itemPath = path.join(dirname, item);
|
|
69
56
|
const extname = path.extname(item);
|
|
70
57
|
const itemWithoutExt = item.slice(0, -extname.length);
|
|
71
58
|
const isDirectory = (await fs.stat(itemPath)).isDirectory();
|
|
72
|
-
|
|
73
59
|
if (isDirectory) {
|
|
74
|
-
const childRoute = await walk(itemPath, rootDir, alias);
|
|
75
|
-
|
|
60
|
+
const childRoute = await walk(itemPath, rootDir, alias, entryName);
|
|
76
61
|
if (childRoute) {
|
|
77
62
|
var _route$children;
|
|
78
|
-
|
|
79
63
|
(_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.push(childRoute);
|
|
80
64
|
}
|
|
81
65
|
}
|
|
82
|
-
|
|
83
66
|
if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
|
|
84
67
|
continue;
|
|
85
68
|
}
|
|
86
|
-
|
|
87
69
|
if (itemWithoutExt === LAYOUT_FILE) {
|
|
88
70
|
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
89
71
|
}
|
|
90
|
-
|
|
91
72
|
if (itemWithoutExt === PAGE_FILE) {
|
|
92
73
|
var _route$children2;
|
|
93
|
-
|
|
94
74
|
const childRoute = createIndexRoute({
|
|
95
75
|
_component: replaceWithAlias(alias.basename, itemPath, alias.name)
|
|
96
|
-
}, rootDir, itemPath);
|
|
76
|
+
}, rootDir, itemPath, entryName);
|
|
97
77
|
(_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.push(childRoute);
|
|
98
78
|
}
|
|
99
|
-
|
|
100
79
|
if (itemWithoutExt === LOADER_FILE) {
|
|
101
80
|
route.loader = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
102
81
|
}
|
|
103
|
-
|
|
104
82
|
if (itemWithoutExt === LOADING_FILE) {
|
|
105
83
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
106
84
|
}
|
|
107
|
-
|
|
108
85
|
if (itemWithoutExt === ERROR_FILE) {
|
|
109
86
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
110
87
|
}
|
|
111
88
|
}
|
|
89
|
+
const finalRoute = createRoute(route, rootDir, path.join(dirname, `${LAYOUT_FILE}.ts`), entryName);
|
|
112
90
|
|
|
113
|
-
const finalRoute = createRoute(route, rootDir, path.join(dirname, `${LAYOUT_FILE}.ts`));
|
|
114
91
|
/**
|
|
115
92
|
* when the url is /, the __auth/layout.tsx component should not be rendered
|
|
116
93
|
* - routes
|
|
@@ -118,10 +95,8 @@ export const walk = async (dirname, rootDir, alias) => {
|
|
|
118
95
|
* - layout.tsx
|
|
119
96
|
* - layout.tsx
|
|
120
97
|
*/
|
|
121
|
-
|
|
122
98
|
if (isPathlessLayout) {
|
|
123
99
|
delete finalRoute.path;
|
|
124
100
|
}
|
|
125
|
-
|
|
126
101
|
return finalRoute;
|
|
127
102
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
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; }
|
|
4
|
-
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
export const index = ({
|
|
8
5
|
mountId,
|
|
9
6
|
imports,
|
|
@@ -88,37 +85,28 @@ export const routesForServer = ({
|
|
|
88
85
|
basename
|
|
89
86
|
} = alias;
|
|
90
87
|
const loaders = [];
|
|
91
|
-
|
|
92
88
|
const traverseRouteTree = route => {
|
|
93
89
|
let children;
|
|
94
|
-
|
|
95
90
|
if ('children' in route && route.children) {
|
|
96
91
|
var _route$children;
|
|
97
|
-
|
|
98
92
|
children = route === null || route === void 0 ? void 0 : (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.map(traverseRouteTree);
|
|
99
93
|
}
|
|
100
|
-
|
|
101
94
|
let loader;
|
|
102
|
-
|
|
103
95
|
if (route.type === 'nested') {
|
|
104
96
|
if (route.loader) {
|
|
105
97
|
loaders.push(route.loader);
|
|
106
98
|
loader = `loader_${loaders.length - 1}`;
|
|
107
99
|
}
|
|
108
100
|
}
|
|
109
|
-
|
|
110
101
|
const finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
111
102
|
loader,
|
|
112
103
|
children
|
|
113
104
|
});
|
|
114
|
-
|
|
115
105
|
return finalRoute;
|
|
116
106
|
};
|
|
117
|
-
|
|
118
107
|
let routesCode = `
|
|
119
108
|
export const routes = [
|
|
120
109
|
`;
|
|
121
|
-
|
|
122
110
|
for (const route of routes) {
|
|
123
111
|
if ('type' in route) {
|
|
124
112
|
const newRoute = traverseRouteTree(route);
|
|
@@ -127,7 +115,6 @@ export const routesForServer = ({
|
|
|
127
115
|
routesCode += `${JSON.stringify(route, null, 2)}`;
|
|
128
116
|
}
|
|
129
117
|
}
|
|
130
|
-
|
|
131
118
|
routesCode += `\n];`;
|
|
132
119
|
const importLoadersCode = loaders.map((loader, index) => {
|
|
133
120
|
const realLoaderPath = loader.replace(name, basename);
|
|
@@ -141,87 +128,85 @@ export const routesForServer = ({
|
|
|
141
128
|
export const fileSystemRoutes = ({
|
|
142
129
|
routes,
|
|
143
130
|
ssrMode,
|
|
144
|
-
nestedRoutesEntry
|
|
131
|
+
nestedRoutesEntry,
|
|
132
|
+
entryName
|
|
145
133
|
}) => {
|
|
146
|
-
|
|
134
|
+
// The legacy mode and pages dir routes should use loadable
|
|
135
|
+
// nested routes + renderTostring should use loadable.lazy
|
|
136
|
+
// nested routes + renderToStream should use react.lazy
|
|
137
|
+
const importLazyCode = `
|
|
138
|
+
import { lazy } from "react";
|
|
139
|
+
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
140
|
+
`;
|
|
147
141
|
let dataLoaderPath = '';
|
|
148
|
-
|
|
149
142
|
if (ssrMode) {
|
|
150
143
|
dataLoaderPath = require.resolve(`@modern-js/plugin-data-loader/loader`);
|
|
151
|
-
|
|
152
144
|
if (nestedRoutesEntry) {
|
|
153
|
-
dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}!`;
|
|
145
|
+
dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&entryName=${entryName}!`;
|
|
154
146
|
}
|
|
155
147
|
}
|
|
156
|
-
|
|
157
148
|
const loadings = [];
|
|
158
149
|
const errors = [];
|
|
159
150
|
const loaders = [];
|
|
160
|
-
|
|
161
151
|
const traverseRouteTree = route => {
|
|
162
152
|
let children;
|
|
163
|
-
|
|
164
153
|
if ('children' in route && route.children) {
|
|
165
154
|
var _route$children2;
|
|
166
|
-
|
|
167
155
|
children = route === null || route === void 0 ? void 0 : (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.map(traverseRouteTree);
|
|
168
156
|
}
|
|
169
|
-
|
|
170
157
|
let loading;
|
|
171
158
|
let error;
|
|
172
159
|
let loader;
|
|
173
|
-
|
|
160
|
+
let component = '';
|
|
174
161
|
if (route.type === 'nested') {
|
|
175
162
|
if (route.loading) {
|
|
176
163
|
loadings.push(route.loading);
|
|
177
164
|
loading = `loading_${loadings.length - 1}`;
|
|
178
165
|
}
|
|
179
|
-
|
|
180
166
|
if (route.error) {
|
|
181
167
|
errors.push(route.error);
|
|
182
168
|
error = `error_${errors.length - 1}`;
|
|
183
169
|
}
|
|
184
|
-
|
|
185
170
|
if (route.loader) {
|
|
186
171
|
loaders.push(route.loader);
|
|
187
172
|
loader = `loader_${loaders.length - 1}`;
|
|
188
173
|
}
|
|
174
|
+
if (route._component) {
|
|
175
|
+
if (ssrMode === 'stream') {
|
|
176
|
+
component = `lazy(() => import(/* webpackChunkName: "${route.id}" */ /* webpackMode: "lazy-once" */ '${route._component}'))`;
|
|
177
|
+
} else {
|
|
178
|
+
component = `loadable(() => import(/* webpackChunkName: "${route.id}" */ /* webpackMode: "lazy-once" */ '${route._component}'))`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else if (route._component) {
|
|
182
|
+
component = `loadable(() => import('${route._component}'))`;
|
|
189
183
|
}
|
|
190
|
-
|
|
191
184
|
const finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
192
185
|
loading,
|
|
193
186
|
loader,
|
|
194
187
|
error,
|
|
195
188
|
children
|
|
196
189
|
});
|
|
197
|
-
|
|
198
190
|
if (route._component) {
|
|
199
|
-
const component = ssrMode === 'stream' ? `lazy(() => import('${route._component}'))` : `loadable(() => import('${route._component}'))`;
|
|
200
191
|
finalRoute.component = component;
|
|
201
192
|
}
|
|
202
|
-
|
|
203
193
|
return finalRoute;
|
|
204
194
|
};
|
|
205
|
-
|
|
206
195
|
let routeComponentsCode = `
|
|
207
196
|
export const routes = [
|
|
208
197
|
`;
|
|
209
|
-
|
|
210
198
|
for (const route of routes) {
|
|
211
199
|
if ('type' in route) {
|
|
212
200
|
const newRoute = traverseRouteTree(route);
|
|
213
|
-
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable
|
|
201
|
+
routeComponentsCode += `${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(/"(error_[^"])"/g, '$1').replace(/\\"/g, '"')},`;
|
|
214
202
|
} else {
|
|
215
|
-
const component =
|
|
216
|
-
|
|
203
|
+
const component = `loadable(() => import('${route._component}'))`;
|
|
217
204
|
const finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
218
205
|
component
|
|
219
206
|
});
|
|
220
|
-
|
|
221
207
|
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, '$1').replace(/"(lazy[^"]*)"/g, '$1')},`;
|
|
222
208
|
}
|
|
223
209
|
}
|
|
224
|
-
|
|
225
210
|
routeComponentsCode += `\n];`;
|
|
226
211
|
const importLoadingCode = loadings.map((loading, index) => {
|
|
227
212
|
return `import loading_${index} from '${loading}';\n`;
|
|
@@ -4,7 +4,6 @@ import { isReact18, normalizeToPosixPath } from '@modern-js/utils';
|
|
|
4
4
|
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
|
5
5
|
export const walkDirectory = dir => fs.readdirSync(dir).reduce((previous, filename) => {
|
|
6
6
|
const filePath = path.join(dir, filename);
|
|
7
|
-
|
|
8
7
|
if (fs.statSync(filePath).isDirectory()) {
|
|
9
8
|
return [...previous, ...walkDirectory(filePath)];
|
|
10
9
|
} else {
|
|
@@ -47,7 +46,6 @@ export const getDefaultImports = ({
|
|
|
47
46
|
}],
|
|
48
47
|
value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
|
49
48
|
}].filter(Boolean);
|
|
50
|
-
|
|
51
49
|
if (fileSystemRoutes) {
|
|
52
50
|
const route = {
|
|
53
51
|
specifiers: [{
|
|
@@ -55,7 +53,6 @@ export const getDefaultImports = ({
|
|
|
55
53
|
}],
|
|
56
54
|
value: normalizeToPosixPath(`${internalDirAlias}/${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`)
|
|
57
55
|
};
|
|
58
|
-
|
|
59
56
|
if (fileSystemRoutes.globalApp) {
|
|
60
57
|
imports.push({
|
|
61
58
|
specifiers: [{
|
|
@@ -66,7 +63,6 @@ export const getDefaultImports = ({
|
|
|
66
63
|
} else {
|
|
67
64
|
route.initialize = 'const App = false;';
|
|
68
65
|
}
|
|
69
|
-
|
|
70
66
|
imports.push(route);
|
|
71
67
|
} else {
|
|
72
68
|
imports.push({
|
|
@@ -76,18 +72,15 @@ export const getDefaultImports = ({
|
|
|
76
72
|
value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
|
|
77
73
|
});
|
|
78
74
|
}
|
|
79
|
-
|
|
80
75
|
return imports;
|
|
81
76
|
};
|
|
82
77
|
export const isRouteComponentFile = filePath => {
|
|
83
78
|
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
84
79
|
return false;
|
|
85
80
|
}
|
|
86
|
-
|
|
87
81
|
if (['.js', '.jsx', '.ts', '.tsx'].includes(path.extname(filePath))) {
|
|
88
82
|
return true;
|
|
89
83
|
}
|
|
90
|
-
|
|
91
84
|
return false;
|
|
92
85
|
};
|
|
93
86
|
export const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|