@modern-js/app-tools 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/dist/{js/node → cjs}/analyze/constants.js +0 -0
- package/dist/cjs/analyze/generateCode.js +249 -0
- package/dist/{js/node → cjs}/analyze/getBundleEntry.js +6 -0
- package/dist/{js/node → cjs}/analyze/getClientRoutes/getRoutes.js +1 -18
- package/dist/{js/node → cjs}/analyze/getClientRoutes/getRoutesLegacy.js +1 -18
- package/dist/{js/node → cjs}/analyze/getClientRoutes/index.js +0 -0
- package/dist/{js/node → cjs}/analyze/getClientRoutes/utils.js +0 -0
- package/dist/{js/node → cjs}/analyze/getFileSystemEntry.js +0 -0
- package/dist/{js/node → cjs}/analyze/getHtmlTemplate.js +4 -24
- package/dist/{js/node → cjs}/analyze/getServerRoutes.js +22 -42
- package/dist/cjs/analyze/index.js +290 -0
- package/dist/{js/node → cjs}/analyze/isDefaultExportFunction.js +0 -0
- package/dist/{js/node → cjs}/analyze/makeLegalIdentifier.js +0 -0
- package/dist/{js/node → cjs}/analyze/nestedRoutes.js +16 -50
- package/dist/{js/node → cjs}/analyze/templates.js +16 -49
- package/dist/{js/node → cjs}/analyze/utils.js +9 -29
- package/dist/{js/node → cjs}/builder/builder-rspack/index.js +0 -0
- package/dist/{js/node → cjs}/builder/builder-webpack/builderPlugins/compatModern.js +0 -0
- package/dist/{js/node → cjs}/builder/builder-webpack/index.js +22 -62
- package/dist/{js/node → cjs}/builder/builder-webpack/webpackPlugins/RouterPlugin.js +7 -24
- package/dist/{js/node → cjs}/builder/builder-webpack/webpackPlugins/index.js +0 -0
- package/dist/{js/node → cjs}/builder/generator/createBuilderOptions.js +0 -0
- package/dist/{js/node → cjs}/builder/generator/createBuilderProviderConfig.js +14 -25
- package/dist/{js/node → cjs}/builder/generator/getBuilderTargets.js +4 -0
- package/dist/cjs/builder/generator/index.js +58 -0
- package/dist/{js/node → cjs}/builder/index.js +12 -34
- package/dist/{js/node → cjs}/builder/shared/builderPlugins/adapterModern.js +35 -34
- package/dist/{js/node → cjs}/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -0
- package/dist/{js/node → cjs}/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -0
- package/dist/{js/node → cjs}/builder/shared/createCopyPattern.js +0 -0
- package/dist/{js/node → cjs}/builder/shared/index.js +0 -0
- package/dist/{js/node → cjs}/builder/shared/loaders/serverModuleLoader.js +0 -0
- package/dist/{js/node → cjs}/builder/shared/types.js +0 -0
- package/dist/{js/node → cjs}/commands/build.js +9 -46
- package/dist/cjs/commands/deploy.js +31 -0
- package/dist/{js/node → cjs}/commands/dev.js +17 -52
- package/dist/{js/node → cjs}/commands/index.js +0 -0
- package/dist/{js/node → cjs}/commands/inspect.js +2 -22
- package/dist/{js/node → cjs}/commands/serve.js +8 -28
- package/dist/{js/node → cjs}/config/default.js +15 -26
- package/dist/{js/node → cjs}/config/index.js +0 -0
- package/dist/{js/node → cjs}/config/initialize/index.js +0 -0
- package/dist/{js/node → cjs}/config/initialize/inits.js +4 -20
- package/dist/{js/node → cjs}/config/legacy/createHtmlConfig.js +0 -0
- package/dist/{js/node → cjs}/config/legacy/createOutputConfig.js +0 -0
- package/dist/{js/node → cjs}/config/legacy/createSourceConfig.js +0 -0
- package/dist/{js/node → cjs}/config/legacy/createToolsConfig.js +0 -0
- package/dist/{js/node → cjs}/config/legacy/index.js +0 -0
- package/dist/cjs/defineConfig.js +33 -0
- package/dist/{js/node → cjs}/exports/server.js +0 -0
- package/dist/{js/node → cjs}/hooks.js +0 -0
- package/dist/cjs/index.js +198 -0
- package/dist/cjs/initialize/index.js +102 -0
- package/dist/{js/node → cjs}/locale/en.js +0 -0
- package/dist/{js/node → cjs}/locale/index.js +0 -0
- package/dist/{js/node → cjs}/locale/zh.js +0 -0
- package/dist/{js/node → cjs}/schema/Schema.js +0 -0
- package/dist/{js/node → cjs}/schema/index.js +0 -0
- package/dist/{js/node → cjs}/schema/legacy.js +0 -0
- package/dist/{js/node → cjs}/types/config/deploy.js +0 -0
- package/dist/{js/node → cjs}/types/config/dev.js +0 -0
- package/dist/{js/node → cjs}/types/config/experiments.js +0 -0
- package/dist/{js/node → cjs}/types/config/html.js +0 -0
- package/dist/{js/node → cjs}/types/config/index.js +0 -0
- package/dist/{js/node → cjs}/types/config/output.js +0 -0
- package/dist/{js/node → cjs}/types/config/performance.js +0 -0
- package/dist/{js/node → cjs}/types/config/security.js +0 -0
- package/dist/{js/node → cjs}/types/config/source.js +0 -0
- package/dist/{js/node → cjs}/types/config/tools.js +0 -0
- package/dist/{js/node → cjs}/types/hooks.js +0 -0
- package/dist/{js/node → cjs}/types/index.js +0 -0
- package/dist/{js/node → cjs}/types/legacyConfig/deploy.js +0 -0
- package/dist/{js/node → cjs}/types/legacyConfig/dev.js +0 -0
- package/dist/{js/node → cjs}/types/legacyConfig/index.js +0 -0
- package/dist/{js/node → cjs}/types/legacyConfig/output.js +0 -0
- package/dist/{js/node → cjs}/types/legacyConfig/source.js +0 -0
- package/dist/{js/node → cjs}/types/legacyConfig/tools.js +0 -0
- package/dist/{js/node → cjs}/types/utils.js +0 -0
- package/dist/{js/node → cjs}/utils/config.js +19 -57
- package/dist/{js/node → cjs}/utils/createServer.js +10 -46
- package/dist/{js/node → cjs}/utils/env.js +0 -0
- package/dist/{js/node → cjs}/utils/generateWatchFiles.js +16 -38
- package/dist/{js/node → cjs}/utils/getSelectedEntries.js +3 -23
- package/dist/cjs/utils/getServerInternalPlugins.js +41 -0
- package/dist/{js/node → cjs}/utils/language.js +0 -0
- package/dist/{js/node → cjs}/utils/printInstructions.js +3 -23
- package/dist/cjs/utils/restart.js +45 -0
- package/dist/{js/node → cjs}/utils/routes.js +3 -23
- package/dist/{js/node → cjs}/utils/types.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/constants.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/generateCode.js +14 -14
- package/dist/{js/treeshaking → esm}/analyze/getBundleEntry.js +4 -2
- package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/index.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/utils.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/getFileSystemEntry.js +1 -1
- package/dist/{js/treeshaking → esm}/analyze/getHtmlTemplate.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/getServerRoutes.js +8 -6
- package/dist/{js/treeshaking → esm}/analyze/index.js +8 -8
- package/dist/{js/treeshaking → esm}/analyze/isDefaultExportFunction.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/makeLegalIdentifier.js +0 -0
- package/dist/{js/treeshaking → esm}/analyze/nestedRoutes.js +5 -5
- package/dist/{js/treeshaking → esm}/analyze/templates.js +8 -7
- package/dist/{js/treeshaking → esm}/analyze/utils.js +3 -3
- package/dist/{js/treeshaking → esm}/builder/builder-rspack/index.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/builder-webpack/builderPlugins/compatModern.js +4 -4
- package/dist/{js/treeshaking → esm}/builder/builder-webpack/index.js +2 -2
- package/dist/{js/treeshaking → esm}/builder/builder-webpack/webpackPlugins/RouterPlugin.js +5 -2
- package/dist/{js/treeshaking → esm}/builder/builder-webpack/webpackPlugins/index.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/generator/createBuilderOptions.js +2 -2
- package/dist/{js/treeshaking → esm}/builder/generator/createBuilderProviderConfig.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/generator/getBuilderTargets.js +5 -1
- package/dist/{js/treeshaking → esm}/builder/generator/index.js +2 -2
- package/dist/{js/treeshaking → esm}/builder/index.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/shared/builderPlugins/adapterModern.js +62 -13
- package/dist/{js/treeshaking → esm}/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -2
- package/dist/{js/treeshaking → esm}/builder/shared/createCopyPattern.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/shared/index.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/shared/loaders/serverModuleLoader.js +0 -0
- package/dist/{js/treeshaking → esm}/builder/shared/types.js +0 -0
- package/dist/{js/treeshaking → esm}/commands/build.js +0 -0
- package/dist/{js/treeshaking → esm}/commands/deploy.js +0 -0
- package/dist/{js/treeshaking → esm}/commands/dev.js +2 -2
- package/dist/{js/treeshaking → esm}/commands/index.js +0 -0
- package/dist/{js/treeshaking → esm}/commands/inspect.js +0 -0
- package/dist/{js/treeshaking → esm}/commands/serve.js +2 -2
- package/dist/{js/treeshaking → esm}/config/default.js +0 -0
- package/dist/{js/treeshaking → esm}/config/index.js +0 -0
- package/dist/{js/treeshaking → esm}/config/initialize/index.js +0 -0
- package/dist/{js/treeshaking → esm}/config/initialize/inits.js +2 -2
- package/dist/esm/config/legacy/createHtmlConfig.js +19 -0
- package/dist/{js/treeshaking → esm}/config/legacy/createOutputConfig.js +1 -1
- package/dist/{js/treeshaking → esm}/config/legacy/createSourceConfig.js +1 -1
- package/dist/{js/treeshaking → esm}/config/legacy/createToolsConfig.js +1 -1
- package/dist/{js/treeshaking → esm}/config/legacy/index.js +0 -0
- package/dist/{js/treeshaking → esm}/defineConfig.js +0 -0
- package/dist/{js/treeshaking → esm}/exports/server.js +0 -0
- package/dist/{js/treeshaking → esm}/hooks.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/initialize/index.js +2 -2
- package/dist/{js/treeshaking → esm}/locale/en.js +0 -0
- package/dist/{js/treeshaking → esm}/locale/index.js +0 -0
- package/dist/{js/treeshaking → esm}/locale/zh.js +0 -0
- package/dist/{js/treeshaking → esm}/schema/Schema.js +0 -0
- package/dist/{js/treeshaking → esm}/schema/index.js +0 -0
- package/dist/{js/treeshaking → esm}/schema/legacy.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/deploy.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/dev.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/experiments.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/html.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/index.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/output.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/performance.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/security.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/source.js +0 -0
- package/dist/{js/treeshaking → esm}/types/config/tools.js +0 -0
- package/dist/{js/treeshaking → esm}/types/hooks.js +0 -0
- package/dist/{js/treeshaking → esm}/types/index.js +0 -0
- package/dist/{js/treeshaking → esm}/types/legacyConfig/deploy.js +0 -0
- package/dist/{js/treeshaking → esm}/types/legacyConfig/dev.js +0 -0
- package/dist/{js/treeshaking → esm}/types/legacyConfig/index.js +0 -0
- package/dist/{js/treeshaking → esm}/types/legacyConfig/output.js +0 -0
- package/dist/{js/treeshaking → esm}/types/legacyConfig/source.js +0 -0
- package/dist/{js/treeshaking → esm}/types/legacyConfig/tools.js +0 -0
- package/dist/{js/treeshaking → esm}/types/utils.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/config.js +2 -2
- package/dist/{js/treeshaking → esm}/utils/createServer.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/env.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/generateWatchFiles.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/getSelectedEntries.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/getServerInternalPlugins.js +2 -2
- package/dist/{js/treeshaking → esm}/utils/language.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/printInstructions.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/restart.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/routes.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/types.js +0 -0
- package/dist/{js/modern → esm-node}/analyze/constants.js +0 -0
- package/dist/esm-node/analyze/generateCode.js +225 -0
- package/dist/{js/modern → esm-node}/analyze/getBundleEntry.js +6 -0
- package/dist/{js/modern → esm-node}/analyze/getClientRoutes/getRoutes.js +1 -20
- package/dist/{js/modern → esm-node}/analyze/getClientRoutes/getRoutesLegacy.js +1 -20
- package/dist/{js/modern → esm-node}/analyze/getClientRoutes/index.js +0 -0
- package/dist/{js/modern → esm-node}/analyze/getClientRoutes/utils.js +0 -0
- package/dist/{js/modern → esm-node}/analyze/getFileSystemEntry.js +0 -0
- package/dist/{js/modern → esm-node}/analyze/getHtmlTemplate.js +4 -24
- package/dist/{js/modern → esm-node}/analyze/getServerRoutes.js +24 -45
- package/dist/esm-node/analyze/index.js +281 -0
- package/dist/{js/modern → esm-node}/analyze/isDefaultExportFunction.js +0 -0
- package/dist/{js/modern → esm-node}/analyze/makeLegalIdentifier.js +0 -0
- package/dist/{js/modern → esm-node}/analyze/nestedRoutes.js +16 -52
- package/dist/{js/modern → esm-node}/analyze/templates.js +16 -51
- package/dist/{js/modern → esm-node}/analyze/utils.js +9 -29
- package/dist/{js/modern → esm-node}/builder/builder-rspack/index.js +0 -0
- package/dist/{js/modern → esm-node}/builder/builder-webpack/builderPlugins/compatModern.js +0 -0
- package/dist/esm-node/builder/builder-webpack/index.js +51 -0
- package/dist/{js/modern → esm-node}/builder/builder-webpack/webpackPlugins/RouterPlugin.js +7 -24
- package/dist/{js/modern → esm-node}/builder/builder-webpack/webpackPlugins/index.js +0 -0
- package/dist/{js/modern → esm-node}/builder/generator/createBuilderOptions.js +0 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +26 -0
- package/dist/{js/modern → esm-node}/builder/generator/getBuilderTargets.js +10 -1
- package/dist/esm-node/builder/generator/index.js +29 -0
- package/dist/esm-node/builder/index.js +17 -0
- package/dist/{js/modern → esm-node}/builder/shared/builderPlugins/adapterModern.js +35 -36
- package/dist/{js/modern → esm-node}/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -0
- package/dist/{js/modern → esm-node}/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -0
- package/dist/{js/modern → esm-node}/builder/shared/createCopyPattern.js +0 -0
- package/dist/{js/modern → esm-node}/builder/shared/index.js +0 -0
- package/dist/{js/modern → esm-node}/builder/shared/loaders/serverModuleLoader.js +0 -0
- package/dist/{js/modern → esm-node}/builder/shared/types.js +0 -0
- package/dist/esm-node/commands/build.js +52 -0
- package/dist/esm-node/commands/deploy.js +8 -0
- package/dist/esm-node/commands/dev.js +72 -0
- package/dist/{js/modern → esm-node}/commands/index.js +0 -0
- package/dist/esm-node/commands/inspect.js +18 -0
- package/dist/{js/modern → esm-node}/commands/serve.js +8 -28
- package/dist/{js/modern → esm-node}/config/default.js +15 -28
- package/dist/{js/modern → esm-node}/config/index.js +0 -0
- package/dist/{js/modern → esm-node}/config/initialize/index.js +0 -0
- package/dist/{js/modern → esm-node}/config/initialize/inits.js +4 -22
- package/dist/{js/modern → esm-node}/config/legacy/createHtmlConfig.js +0 -0
- package/dist/{js/modern → esm-node}/config/legacy/createOutputConfig.js +0 -0
- package/dist/{js/modern → esm-node}/config/legacy/createSourceConfig.js +0 -0
- package/dist/{js/modern → esm-node}/config/legacy/createToolsConfig.js +0 -0
- package/dist/{js/modern → esm-node}/config/legacy/index.js +0 -0
- package/dist/esm-node/defineConfig.js +9 -0
- package/dist/{js/modern → esm-node}/exports/server.js +0 -0
- package/dist/{js/modern → esm-node}/hooks.js +0 -0
- package/dist/esm-node/index.js +172 -0
- package/dist/esm-node/initialize/index.js +91 -0
- package/dist/{js/modern → esm-node}/locale/en.js +0 -0
- package/dist/{js/modern → esm-node}/locale/index.js +0 -0
- package/dist/{js/modern → esm-node}/locale/zh.js +0 -0
- package/dist/{js/modern → esm-node}/schema/Schema.js +0 -0
- package/dist/{js/modern → esm-node}/schema/index.js +0 -0
- package/dist/{js/modern → esm-node}/schema/legacy.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/deploy.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/dev.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/experiments.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/html.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/index.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/output.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/performance.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/security.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/source.js +0 -0
- package/dist/{js/modern → esm-node}/types/config/tools.js +0 -0
- package/dist/{js/modern → esm-node}/types/hooks.js +0 -0
- package/dist/{js/modern → esm-node}/types/index.js +0 -0
- package/dist/{js/modern → esm-node}/types/legacyConfig/deploy.js +0 -0
- package/dist/{js/modern → esm-node}/types/legacyConfig/dev.js +0 -0
- package/dist/{js/modern → esm-node}/types/legacyConfig/index.js +0 -0
- package/dist/{js/modern → esm-node}/types/legacyConfig/output.js +0 -0
- package/dist/{js/modern → esm-node}/types/legacyConfig/source.js +0 -0
- package/dist/{js/modern → esm-node}/types/legacyConfig/tools.js +0 -0
- package/dist/{js/modern → esm-node}/types/utils.js +0 -0
- package/dist/esm-node/utils/config.js +88 -0
- package/dist/esm-node/utils/createServer.js +37 -0
- package/dist/{js/modern → esm-node}/utils/env.js +0 -0
- package/dist/esm-node/utils/generateWatchFiles.js +33 -0
- package/dist/{js/modern → esm-node}/utils/getSelectedEntries.js +3 -23
- package/dist/esm-node/utils/getServerInternalPlugins.js +18 -0
- package/dist/{js/modern → esm-node}/utils/language.js +0 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +10 -0
- package/dist/{js/modern → esm-node}/utils/types.js +0 -0
- package/dist/types/types/config/tools.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +5 -4
- package/dist/types/types/index.d.ts +3 -1
- package/package.json +30 -31
- package/dist/js/modern/analyze/generateCode.js +0 -247
- package/dist/js/modern/analyze/index.js +0 -329
- package/dist/js/modern/builder/builder-webpack/index.js +0 -93
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +0 -39
- package/dist/js/modern/builder/generator/index.js +0 -53
- package/dist/js/modern/builder/index.js +0 -39
- package/dist/js/modern/commands/build.js +0 -91
- package/dist/js/modern/commands/deploy.js +0 -28
- package/dist/js/modern/commands/dev.js +0 -109
- package/dist/js/modern/commands/inspect.js +0 -38
- package/dist/js/modern/defineConfig.js +0 -27
- package/dist/js/modern/index.js +0 -221
- package/dist/js/modern/initialize/index.js +0 -132
- package/dist/js/modern/utils/config.js +0 -128
- package/dist/js/modern/utils/createServer.js +0 -75
- package/dist/js/modern/utils/generateWatchFiles.js +0 -55
- package/dist/js/modern/utils/getServerInternalPlugins.js +0 -58
- package/dist/js/modern/utils/printInstructions.js +0 -31
- package/dist/js/modern/utils/restart.js +0 -44
- package/dist/js/modern/utils/routes.js +0 -30
- package/dist/js/node/analyze/generateCode.js +0 -271
- package/dist/js/node/analyze/index.js +0 -336
- package/dist/js/node/builder/generator/index.js +0 -82
- package/dist/js/node/commands/deploy.js +0 -51
- package/dist/js/node/defineConfig.js +0 -49
- package/dist/js/node/index.js +0 -245
- package/dist/js/node/initialize/index.js +0 -141
- package/dist/js/node/utils/getServerInternalPlugins.js +0 -79
- package/dist/js/node/utils/restart.js +0 -67
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +0 -19
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import {
|
|
3
|
+
createDebugger,
|
|
4
|
+
findExists,
|
|
5
|
+
fs,
|
|
6
|
+
getEntryOptions,
|
|
7
|
+
isApiOnly,
|
|
8
|
+
minimist,
|
|
9
|
+
getCommand,
|
|
10
|
+
isDevCommand
|
|
11
|
+
} from "@modern-js/utils";
|
|
12
|
+
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
13
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
14
|
+
import { generateRoutes } from "../utils/routes";
|
|
15
|
+
import { emitResolvedConfig } from "../utils/config";
|
|
16
|
+
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
17
|
+
import { initialNormalizedConfig } from "../config";
|
|
18
|
+
import { createBuilderGenerator } from "../builder";
|
|
19
|
+
import {
|
|
20
|
+
getServerLoadersFile,
|
|
21
|
+
isPageComponentFile,
|
|
22
|
+
parseModule,
|
|
23
|
+
replaceWithAlias
|
|
24
|
+
} from "./utils";
|
|
25
|
+
import {
|
|
26
|
+
APP_CONFIG_NAME,
|
|
27
|
+
APP_INIT_EXPORTED,
|
|
28
|
+
APP_INIT_IMPORTED
|
|
29
|
+
} from "./constants";
|
|
30
|
+
const debug = createDebugger("plugin-analyze");
|
|
31
|
+
var analyze_default = ({
|
|
32
|
+
bundler
|
|
33
|
+
}) => ({
|
|
34
|
+
name: "@modern-js/plugin-analyze",
|
|
35
|
+
setup: (api) => {
|
|
36
|
+
let pagesDir = [];
|
|
37
|
+
let nestedRouteEntries = [];
|
|
38
|
+
let originEntrypoints = [];
|
|
39
|
+
return {
|
|
40
|
+
async prepare() {
|
|
41
|
+
var _a;
|
|
42
|
+
let appContext = api.useAppContext();
|
|
43
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
44
|
+
const hookRunners = api.useHookRunners();
|
|
45
|
+
try {
|
|
46
|
+
fs.emptydirSync(appContext.internalDirectory);
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
const apiOnly = await isApiOnly(
|
|
50
|
+
appContext.appDirectory,
|
|
51
|
+
(_a = resolvedConfig.source) == null ? void 0 : _a.entriesDir
|
|
52
|
+
);
|
|
53
|
+
await hookRunners.addRuntimeExports();
|
|
54
|
+
if (apiOnly) {
|
|
55
|
+
const { routes: routes2 } = await hookRunners.modifyServerRoutes({
|
|
56
|
+
routes: []
|
|
57
|
+
});
|
|
58
|
+
debug(`server routes: %o`, routes2);
|
|
59
|
+
appContext = {
|
|
60
|
+
...appContext,
|
|
61
|
+
apiOnly,
|
|
62
|
+
serverRoutes: routes2
|
|
63
|
+
};
|
|
64
|
+
api.setAppContext(appContext);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const [
|
|
68
|
+
{ getBundleEntry },
|
|
69
|
+
{ getServerRoutes },
|
|
70
|
+
{ generateCode },
|
|
71
|
+
{ getHtmlTemplate }
|
|
72
|
+
] = await Promise.all([
|
|
73
|
+
import("./getBundleEntry"),
|
|
74
|
+
import("./getServerRoutes"),
|
|
75
|
+
import("./generateCode"),
|
|
76
|
+
import("./getHtmlTemplate")
|
|
77
|
+
]);
|
|
78
|
+
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
79
|
+
debug(`entrypoints: %o`, entrypoints);
|
|
80
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
|
81
|
+
appContext,
|
|
82
|
+
config: resolvedConfig
|
|
83
|
+
});
|
|
84
|
+
const { routes } = await hookRunners.modifyServerRoutes({
|
|
85
|
+
routes: initialRoutes
|
|
86
|
+
});
|
|
87
|
+
debug(`server routes: %o`, routes);
|
|
88
|
+
appContext = {
|
|
89
|
+
...appContext,
|
|
90
|
+
entrypoints,
|
|
91
|
+
serverRoutes: routes
|
|
92
|
+
};
|
|
93
|
+
api.setAppContext(appContext);
|
|
94
|
+
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
95
|
+
pagesDir = entrypoints.map((point) => point.entry).filter(Boolean).concat(nestedRouteEntries);
|
|
96
|
+
originEntrypoints = cloneDeep(entrypoints);
|
|
97
|
+
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
98
|
+
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
|
99
|
+
appContext,
|
|
100
|
+
config: resolvedConfig
|
|
101
|
+
});
|
|
102
|
+
debug(`html templates: %o`, htmlTemplates);
|
|
103
|
+
await hookRunners.addDefineTypes();
|
|
104
|
+
debug(`add Define Types`);
|
|
105
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
106
|
+
if (isDevCommand()) {
|
|
107
|
+
const { entry } = minimist(process.argv.slice(2));
|
|
108
|
+
checkedEntries = await getSelectedEntries(
|
|
109
|
+
typeof entry === "string" ? entry.split(",") : entry,
|
|
110
|
+
entrypoints
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
appContext = {
|
|
114
|
+
...appContext,
|
|
115
|
+
entrypoints,
|
|
116
|
+
checkedEntries,
|
|
117
|
+
apiOnly,
|
|
118
|
+
serverRoutes: routes,
|
|
119
|
+
htmlTemplates
|
|
120
|
+
};
|
|
121
|
+
api.setAppContext(appContext);
|
|
122
|
+
const command = getCommand();
|
|
123
|
+
const buildCommands = ["dev", "start", "build", "inspect", "deploy"];
|
|
124
|
+
if (buildCommands.includes(command)) {
|
|
125
|
+
const normalizedConfig = api.useResolvedConfigContext();
|
|
126
|
+
const createBuilderForModern = await createBuilderGenerator(bundler);
|
|
127
|
+
const builder = await createBuilderForModern({
|
|
128
|
+
normalizedConfig,
|
|
129
|
+
appContext,
|
|
130
|
+
async onBeforeBuild({ bundlerConfigs }) {
|
|
131
|
+
const hookRunners2 = api.useHookRunners();
|
|
132
|
+
await generateRoutes(appContext);
|
|
133
|
+
await hookRunners2.beforeBuild({
|
|
134
|
+
bundlerConfigs
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
async onAfterBuild({ stats }) {
|
|
138
|
+
const hookRunners2 = api.useHookRunners();
|
|
139
|
+
await hookRunners2.afterBuild({ stats });
|
|
140
|
+
await emitResolvedConfig(
|
|
141
|
+
appContext.appDirectory,
|
|
142
|
+
normalizedConfig
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
async onDevCompileDone({ isFirstCompile }) {
|
|
146
|
+
const hookRunners2 = api.useHookRunners();
|
|
147
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
148
|
+
hookRunners2.afterDev();
|
|
149
|
+
if (isFirstCompile) {
|
|
150
|
+
printInstructions(hookRunners2, appContext, normalizedConfig);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async onBeforeCreateCompiler({ bundlerConfigs }) {
|
|
155
|
+
const hookRunners2 = api.useHookRunners();
|
|
156
|
+
await hookRunners2.beforeCreateCompiler({
|
|
157
|
+
bundlerConfigs
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
async onAfterCreateCompiler({ compiler }) {
|
|
161
|
+
const hookRunners2 = api.useHookRunners();
|
|
162
|
+
await hookRunners2.afterCreateCompiler({
|
|
163
|
+
compiler
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
168
|
+
appContext = {
|
|
169
|
+
...appContext,
|
|
170
|
+
builder
|
|
171
|
+
};
|
|
172
|
+
api.setAppContext(appContext);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
watchFiles() {
|
|
176
|
+
return pagesDir;
|
|
177
|
+
},
|
|
178
|
+
config() {
|
|
179
|
+
return {
|
|
180
|
+
tools: {
|
|
181
|
+
webpackChain: (chain, { name }) => {
|
|
182
|
+
const appContext = api.useAppContext();
|
|
183
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
184
|
+
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
185
|
+
entrypoints.forEach((entrypoint) => {
|
|
186
|
+
const { entryName } = entrypoint;
|
|
187
|
+
const ssr = getEntryOptions(
|
|
188
|
+
entryName,
|
|
189
|
+
resolvedConfig.server.ssr,
|
|
190
|
+
resolvedConfig.server.ssrByEntries,
|
|
191
|
+
packageName
|
|
192
|
+
);
|
|
193
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
194
|
+
const serverLoadersFile = getServerLoadersFile(
|
|
195
|
+
internalDirectory,
|
|
196
|
+
entryName
|
|
197
|
+
);
|
|
198
|
+
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
resolvedConfig({ resolved }) {
|
|
206
|
+
const appContext = api.useAppContext();
|
|
207
|
+
const config = initialNormalizedConfig(resolved, appContext, bundler);
|
|
208
|
+
return {
|
|
209
|
+
resolved: config
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
async modifyEntryImports({ entrypoint, imports }) {
|
|
213
|
+
const appContext = api.useAppContext();
|
|
214
|
+
const { srcDirectory, internalSrcAlias } = appContext;
|
|
215
|
+
const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
|
|
216
|
+
if (fileSystemRoutes && nestedRoutesEntry) {
|
|
217
|
+
const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
|
|
218
|
+
const rootLayoutFile = findExists(
|
|
219
|
+
[".js", ".ts", ".jsx", ".tsx"].map(
|
|
220
|
+
(ext) => `${rootLayoutPath}${ext}`
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
if (rootLayoutFile) {
|
|
224
|
+
const rootLayoutBuffer = await fs.readFile(rootLayoutFile);
|
|
225
|
+
const rootLayout = rootLayoutBuffer.toString();
|
|
226
|
+
const [, moduleExports] = await parseModule({
|
|
227
|
+
source: rootLayout.toString(),
|
|
228
|
+
filename: rootLayoutFile
|
|
229
|
+
});
|
|
230
|
+
const hasAppConfig = moduleExports.some(
|
|
231
|
+
(e) => e.n === APP_CONFIG_NAME
|
|
232
|
+
);
|
|
233
|
+
const generateLayoutPath = replaceWithAlias(
|
|
234
|
+
srcDirectory,
|
|
235
|
+
rootLayoutFile,
|
|
236
|
+
internalSrcAlias
|
|
237
|
+
);
|
|
238
|
+
if (hasAppConfig) {
|
|
239
|
+
imports.push({
|
|
240
|
+
value: generateLayoutPath,
|
|
241
|
+
specifiers: [{ imported: APP_CONFIG_NAME }]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const hasAppInit = moduleExports.some(
|
|
245
|
+
(e) => e.n === APP_INIT_EXPORTED
|
|
246
|
+
);
|
|
247
|
+
if (hasAppInit) {
|
|
248
|
+
imports.push({
|
|
249
|
+
value: generateLayoutPath,
|
|
250
|
+
specifiers: [
|
|
251
|
+
{ imported: APP_INIT_EXPORTED, local: APP_INIT_IMPORTED }
|
|
252
|
+
]
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
entrypoint,
|
|
259
|
+
imports
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
async fileChange(e) {
|
|
263
|
+
const appContext = api.useAppContext();
|
|
264
|
+
const { appDirectory } = appContext;
|
|
265
|
+
const { filename, eventType } = e;
|
|
266
|
+
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
267
|
+
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
268
|
+
const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
|
269
|
+
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
270
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
271
|
+
const { generateCode } = await import("./generateCode");
|
|
272
|
+
const entrypoints = cloneDeep(originEntrypoints);
|
|
273
|
+
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
export {
|
|
280
|
+
analyze_default as default
|
|
281
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -1,42 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
1
|
import * as path from "path";
|
|
41
2
|
import { fs, getRouteId } from "@modern-js/utils";
|
|
42
3
|
import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
|
|
@@ -47,10 +8,11 @@ const replaceDynamicPath = (routePath) => {
|
|
|
47
8
|
};
|
|
48
9
|
const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
49
10
|
return createRoute(
|
|
50
|
-
|
|
11
|
+
{
|
|
12
|
+
...routeInfo,
|
|
51
13
|
index: true,
|
|
52
14
|
children: void 0
|
|
53
|
-
}
|
|
15
|
+
},
|
|
54
16
|
rootDir,
|
|
55
17
|
filename,
|
|
56
18
|
entryName
|
|
@@ -58,17 +20,18 @@ const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
|
58
20
|
};
|
|
59
21
|
const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
60
22
|
const id = getRouteId(filename, rootDir, entryName);
|
|
61
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
...routeInfo,
|
|
62
25
|
id,
|
|
63
26
|
type: "nested"
|
|
64
|
-
}
|
|
27
|
+
};
|
|
65
28
|
};
|
|
66
|
-
const walk = (dirname, rootDir, alias, entryName) =>
|
|
29
|
+
const walk = async (dirname, rootDir, alias, entryName) => {
|
|
67
30
|
var _a, _b, _c, _d;
|
|
68
|
-
if (!
|
|
31
|
+
if (!await fs.pathExists(dirname)) {
|
|
69
32
|
return null;
|
|
70
33
|
}
|
|
71
|
-
const isDirectory = (
|
|
34
|
+
const isDirectory = (await fs.stat(dirname)).isDirectory();
|
|
72
35
|
if (!isDirectory) {
|
|
73
36
|
return null;
|
|
74
37
|
}
|
|
@@ -92,14 +55,14 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
92
55
|
let pageRoute = null;
|
|
93
56
|
let splatLoaderFile = "";
|
|
94
57
|
let splatRoute = null;
|
|
95
|
-
const items =
|
|
58
|
+
const items = await fs.readdir(dirname);
|
|
96
59
|
for (const item of items) {
|
|
97
60
|
const itemPath = path.join(dirname, item);
|
|
98
61
|
const extname = path.extname(item);
|
|
99
62
|
const itemWithoutExt = item.slice(0, -extname.length);
|
|
100
|
-
const isDirectory2 = (
|
|
63
|
+
const isDirectory2 = (await fs.stat(itemPath)).isDirectory();
|
|
101
64
|
if (isDirectory2) {
|
|
102
|
-
const childRoute =
|
|
65
|
+
const childRoute = await walk(itemPath, rootDir, alias, entryName);
|
|
103
66
|
if (childRoute) {
|
|
104
67
|
(_a = route.children) == null ? void 0 : _a.push(childRoute);
|
|
105
68
|
}
|
|
@@ -174,13 +137,14 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
174
137
|
const childRoute = finalRoute.children[0];
|
|
175
138
|
if (childRoute.path === "*") {
|
|
176
139
|
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
177
|
-
finalRoute =
|
|
140
|
+
finalRoute = {
|
|
141
|
+
...childRoute,
|
|
178
142
|
path: path2
|
|
179
|
-
}
|
|
143
|
+
};
|
|
180
144
|
}
|
|
181
145
|
}
|
|
182
146
|
return finalRoute;
|
|
183
|
-
}
|
|
147
|
+
};
|
|
184
148
|
export {
|
|
185
149
|
walk
|
|
186
150
|
};
|
|
@@ -1,42 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
1
|
import path from "path";
|
|
41
2
|
import { fs, slash } from "@modern-js/utils";
|
|
42
3
|
import { APP_CONFIG_NAME, TEMP_LOADERS_DIR } from "./constants";
|
|
@@ -69,6 +30,7 @@ const renderFunction = ({
|
|
|
69
30
|
customBootstrap,
|
|
70
31
|
fileSystemRoutes: fileSystemRoutes2
|
|
71
32
|
}) => {
|
|
33
|
+
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
|
72
34
|
return `
|
|
73
35
|
const finalAppConfig = {
|
|
74
36
|
...App.config,
|
|
@@ -90,7 +52,7 @@ const renderFunction = ({
|
|
|
90
52
|
|
|
91
53
|
|
|
92
54
|
if (IS_BROWSER) {
|
|
93
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` :
|
|
55
|
+
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
|
94
56
|
}
|
|
95
57
|
|
|
96
58
|
return AppWrapper
|
|
@@ -143,10 +105,11 @@ const routesForServer = ({
|
|
|
143
105
|
loader = `loader_${loaders.length - 1}`;
|
|
144
106
|
}
|
|
145
107
|
}
|
|
146
|
-
const finalRoute =
|
|
108
|
+
const finalRoute = {
|
|
109
|
+
...route,
|
|
147
110
|
loader,
|
|
148
111
|
children
|
|
149
|
-
}
|
|
112
|
+
};
|
|
150
113
|
return finalRoute;
|
|
151
114
|
};
|
|
152
115
|
let routesCode = `
|
|
@@ -176,13 +139,13 @@ const routesForServer = ({
|
|
|
176
139
|
${routesCode}
|
|
177
140
|
`;
|
|
178
141
|
};
|
|
179
|
-
const fileSystemRoutes =
|
|
142
|
+
const fileSystemRoutes = async ({
|
|
180
143
|
routes,
|
|
181
144
|
ssrMode,
|
|
182
145
|
nestedRoutesEntry,
|
|
183
146
|
entryName,
|
|
184
147
|
internalDirectory
|
|
185
|
-
}) {
|
|
148
|
+
}) => {
|
|
186
149
|
const loadings = [];
|
|
187
150
|
const errors = [];
|
|
188
151
|
const loaders = [];
|
|
@@ -256,13 +219,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
256
219
|
lazyImport = `() => import('${route._component}')`;
|
|
257
220
|
component = `loadable(${lazyImport})`;
|
|
258
221
|
}
|
|
259
|
-
const finalRoute =
|
|
222
|
+
const finalRoute = {
|
|
223
|
+
...route,
|
|
260
224
|
lazyImport,
|
|
261
225
|
loading,
|
|
262
226
|
loader,
|
|
263
227
|
error,
|
|
264
228
|
children
|
|
265
|
-
}
|
|
229
|
+
};
|
|
266
230
|
if (route._component) {
|
|
267
231
|
finalRoute.component = component;
|
|
268
232
|
}
|
|
@@ -277,9 +241,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
277
241
|
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
278
242
|
} else {
|
|
279
243
|
const component = `loadable(() => import('${route._component}'))`;
|
|
280
|
-
const finalRoute =
|
|
244
|
+
const finalRoute = {
|
|
245
|
+
...route,
|
|
281
246
|
component
|
|
282
|
-
}
|
|
247
|
+
};
|
|
283
248
|
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
|
|
284
249
|
}
|
|
285
250
|
}
|
|
@@ -307,8 +272,8 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
307
272
|
`;
|
|
308
273
|
}
|
|
309
274
|
}
|
|
310
|
-
|
|
311
|
-
|
|
275
|
+
await fs.ensureFile(loadersMapFile);
|
|
276
|
+
await fs.writeJSON(loadersMapFile, loadersMap);
|
|
312
277
|
return `
|
|
313
278
|
${importLazyCode}
|
|
314
279
|
${rootLayoutCode}
|
|
@@ -317,7 +282,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
317
282
|
${importLoadersCode}
|
|
318
283
|
${routeComponentsCode}
|
|
319
284
|
`;
|
|
320
|
-
}
|
|
285
|
+
};
|
|
321
286
|
export {
|
|
322
287
|
fileSystemRoutes,
|
|
323
288
|
html,
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
1
|
import fs from "fs";
|
|
22
2
|
import path from "path";
|
|
23
3
|
import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
|
|
@@ -105,28 +85,28 @@ const isPageComponentFile = (filePath) => {
|
|
|
105
85
|
return false;
|
|
106
86
|
};
|
|
107
87
|
const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
108
|
-
const parseModule =
|
|
88
|
+
const parseModule = async ({
|
|
109
89
|
source,
|
|
110
90
|
filename
|
|
111
|
-
}) {
|
|
91
|
+
}) => {
|
|
112
92
|
let content = source;
|
|
113
93
|
if (JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
|
|
114
|
-
const result =
|
|
94
|
+
const result = await transform(content, {
|
|
115
95
|
loader: path.extname(filename).slice(1),
|
|
116
96
|
format: "esm"
|
|
117
97
|
});
|
|
118
98
|
content = result.code;
|
|
119
99
|
}
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
const hasLoader = (filename) =>
|
|
123
|
-
const source =
|
|
124
|
-
const [, moduleExports] =
|
|
100
|
+
return await parse(content);
|
|
101
|
+
};
|
|
102
|
+
const hasLoader = async (filename) => {
|
|
103
|
+
const source = await fse.readFile(filename);
|
|
104
|
+
const [, moduleExports] = await parseModule({
|
|
125
105
|
source: source.toString(),
|
|
126
106
|
filename
|
|
127
107
|
});
|
|
128
108
|
return moduleExports.some((e) => e.n === LOADER_EXPORT_NAME);
|
|
129
|
-
}
|
|
109
|
+
};
|
|
130
110
|
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
131
111
|
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
132
112
|
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
builderWebpackProvider
|
|
3
|
+
} from "@modern-js/builder-webpack-provider";
|
|
4
|
+
import { applyOptionsChain } from "@modern-js/utils";
|
|
5
|
+
import { createCopyPattern } from "../shared";
|
|
6
|
+
import { generateBuilder } from "../generator";
|
|
7
|
+
import { PluginCompatModern } from "./builderPlugins/compatModern";
|
|
8
|
+
function createWebpackBuilderForModern(options) {
|
|
9
|
+
return generateBuilder(options, builderWebpackProvider, {
|
|
10
|
+
modifyBuilderConfig(config) {
|
|
11
|
+
modifyOutputConfig(config, options.appContext);
|
|
12
|
+
},
|
|
13
|
+
async modifyBuilderInstance(builder) {
|
|
14
|
+
await applyBuilderPlugins(builder, options);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function modifyOutputConfig(config, appContext) {
|
|
19
|
+
config.output = createOutputConfig(config, appContext);
|
|
20
|
+
function createOutputConfig(config2, appContext2) {
|
|
21
|
+
const defaultCopyPattern = createCopyPattern(appContext2, config2, "upload");
|
|
22
|
+
const { copy } = config2.output;
|
|
23
|
+
const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
|
|
24
|
+
const builderCopy = [...copyOptions || [], defaultCopyPattern];
|
|
25
|
+
return {
|
|
26
|
+
...config2.output,
|
|
27
|
+
copy: builderCopy
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function applyBuilderPlugins(builder, options) {
|
|
32
|
+
const { normalizedConfig } = options;
|
|
33
|
+
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
34
|
+
const { PluginNodePolyfill } = await import("@modern-js/builder-plugin-node-polyfill");
|
|
35
|
+
builder.addPlugins([PluginNodePolyfill()]);
|
|
36
|
+
}
|
|
37
|
+
if (normalizedConfig.tools.esbuild) {
|
|
38
|
+
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
39
|
+
const { PluginEsbuild } = await import("@modern-js/builder-plugin-esbuild");
|
|
40
|
+
builder.addPlugins([
|
|
41
|
+
PluginEsbuild({
|
|
42
|
+
loader: false,
|
|
43
|
+
minimize: applyOptionsChain({}, esbuildOptions)
|
|
44
|
+
})
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
builder.addPlugins([PluginCompatModern(options)]);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
createWebpackBuilderForModern
|
|
51
|
+
};
|