@modern-js/app-tools 2.3.1-alpha.2 → 2.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +115 -0
- package/README.md +14 -18
- package/dist/cjs/analyze/constants.js +100 -0
- package/dist/cjs/analyze/generateCode.js +251 -0
- package/dist/cjs/analyze/getBundleEntry.js +101 -0
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +225 -0
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +221 -0
- package/dist/cjs/analyze/getClientRoutes/index.js +30 -0
- package/dist/cjs/analyze/getClientRoutes/utils.js +58 -0
- package/dist/cjs/analyze/getFileSystemEntry.js +131 -0
- package/dist/cjs/analyze/getHtmlTemplate.js +124 -0
- package/dist/cjs/analyze/getServerRoutes.js +174 -0
- package/dist/cjs/analyze/index.js +294 -0
- package/dist/cjs/analyze/isDefaultExportFunction.js +71 -0
- package/dist/cjs/analyze/makeLegalIdentifier.js +36 -0
- package/dist/cjs/analyze/nestedRoutes.js +179 -0
- package/dist/cjs/analyze/templates.js +330 -0
- package/dist/cjs/analyze/utils.js +152 -0
- package/dist/cjs/builder/builder-rspack/index.js +31 -0
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/cjs/builder/builder-webpack/index.js +78 -0
- package/dist/cjs/builder/builder-webpack/webpackPlugins/RouterPlugin.js +120 -0
- package/dist/cjs/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/cjs/builder/generator/createBuilderOptions.js +47 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +49 -0
- package/dist/cjs/builder/generator/getBuilderTargets.js +39 -0
- package/dist/cjs/builder/generator/index.js +58 -0
- package/dist/cjs/builder/index.js +46 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +230 -0
- package/dist/{js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js → cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/{js/node/builder/webpackPlugins/htmlBottomTemplate.js → cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/{js/node/builder/share.js → cjs/builder/shared/createCopyPattern.js} +3 -3
- package/dist/cjs/builder/shared/index.js +19 -0
- package/dist/{js/node/builder → cjs/builder/shared}/loaders/serverModuleLoader.js +0 -0
- package/dist/cjs/builder/shared/types.js +15 -0
- package/dist/cjs/commands/build.js +75 -0
- package/dist/cjs/commands/deploy.js +31 -0
- package/dist/cjs/commands/dev.js +91 -0
- package/dist/cjs/commands/index.js +19 -0
- package/dist/cjs/commands/inspect.js +41 -0
- package/dist/cjs/commands/serve.js +63 -0
- package/dist/cjs/config/default.js +186 -0
- package/dist/cjs/config/index.js +19 -0
- package/dist/{js/node/config/initial → cjs/config/initialize}/index.js +10 -16
- package/dist/cjs/config/initialize/inits.js +161 -0
- package/dist/{js/node/config/initial → cjs/config/legacy}/createHtmlConfig.js +0 -0
- package/dist/{js/node/config/initial → cjs/config/legacy}/createOutputConfig.js +0 -0
- package/dist/{js/node/config/initial → cjs/config/legacy}/createSourceConfig.js +0 -0
- package/dist/{js/node/config/initial → cjs/config/legacy}/createToolsConfig.js +0 -0
- package/dist/{js/node/config/initial/transformNormalizedConfig.js → cjs/config/legacy/index.js} +8 -3
- package/dist/cjs/defineConfig.js +33 -0
- package/dist/cjs/exports/server.js +27 -0
- package/dist/cjs/hooks.js +54 -0
- package/dist/cjs/index.js +198 -0
- package/dist/cjs/initialize/index.js +102 -0
- package/dist/cjs/locale/en.js +59 -0
- package/dist/cjs/locale/index.js +33 -0
- package/dist/cjs/locale/zh.js +59 -0
- package/dist/cjs/schema/Schema.js +63 -0
- package/dist/cjs/schema/index.js +118 -0
- package/dist/cjs/schema/legacy.js +169 -0
- package/dist/cjs/types/config/deploy.js +15 -0
- package/dist/cjs/types/config/dev.js +15 -0
- package/dist/cjs/types/config/experiments.js +15 -0
- package/dist/cjs/types/config/html.js +15 -0
- package/dist/cjs/types/config/index.js +17 -0
- package/dist/cjs/types/config/output.js +15 -0
- package/dist/cjs/types/config/performance.js +15 -0
- package/dist/cjs/types/config/security.js +15 -0
- package/dist/cjs/types/config/source.js +15 -0
- package/dist/cjs/types/config/tools.js +15 -0
- package/dist/cjs/types/hooks.js +15 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/legacyConfig/deploy.js +15 -0
- package/dist/cjs/types/legacyConfig/dev.js +15 -0
- package/dist/cjs/types/legacyConfig/index.js +15 -0
- package/dist/cjs/types/legacyConfig/output.js +15 -0
- package/dist/cjs/types/legacyConfig/source.js +15 -0
- package/dist/cjs/types/legacyConfig/tools.js +15 -0
- package/dist/cjs/types/utils.js +15 -0
- package/dist/cjs/utils/config.js +115 -0
- package/dist/cjs/utils/createServer.js +70 -0
- package/dist/cjs/utils/env.js +38 -0
- package/dist/cjs/utils/generateWatchFiles.js +63 -0
- package/dist/cjs/utils/getSelectedEntries.js +61 -0
- package/dist/cjs/utils/getServerInternalPlugins.js +41 -0
- package/dist/cjs/utils/language.js +31 -0
- package/dist/cjs/utils/printInstructions.js +34 -0
- package/dist/cjs/utils/restart.js +45 -0
- package/dist/cjs/utils/routes.js +39 -0
- package/dist/cjs/utils/types.js +15 -0
- package/dist/esm/analyze/constants.js +42 -0
- package/dist/esm/analyze/generateCode.js +486 -0
- package/dist/esm/analyze/getBundleEntry.js +64 -0
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +233 -0
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
- package/dist/esm/analyze/getClientRoutes/index.js +3 -0
- package/dist/esm/analyze/getClientRoutes/utils.js +23 -0
- package/dist/esm/analyze/getFileSystemEntry.js +107 -0
- package/dist/esm/analyze/getHtmlTemplate.js +302 -0
- package/dist/esm/analyze/getServerRoutes.js +224 -0
- package/dist/esm/analyze/index.js +703 -0
- package/dist/esm/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm/analyze/makeLegalIdentifier.js +13 -0
- package/dist/esm/analyze/nestedRoutes.js +409 -0
- package/dist/esm/analyze/templates.js +466 -0
- package/dist/esm/analyze/utils.js +374 -0
- package/dist/esm/builder/builder-rspack/index.js +6 -0
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/esm/builder/builder-webpack/index.js +301 -0
- package/dist/esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js +346 -0
- package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/esm/builder/generator/createBuilderOptions.js +41 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/esm/builder/generator/getBuilderTargets.js +16 -0
- package/dist/esm/builder/generator/index.js +199 -0
- package/dist/esm/builder/index.js +175 -0
- package/dist/esm/builder/shared/builderPlugins/adapterModern.js +300 -0
- package/dist/{js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js → esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +72 -0
- package/dist/{js/treeshaking/builder/share.js → esm/builder/shared/createCopyPattern.js} +0 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/{js/treeshaking/builder → esm/builder/shared}/loaders/serverModuleLoader.js +0 -0
- package/dist/esm/builder/shared/types.js +1 -0
- package/dist/esm/commands/build.js +291 -0
- package/dist/esm/commands/deploy.js +154 -0
- package/dist/esm/commands/dev.js +301 -0
- package/dist/esm/commands/index.js +3 -0
- package/dist/esm/commands/inspect.js +149 -0
- package/dist/esm/commands/serve.js +199 -0
- package/dist/esm/config/default.js +210 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +10 -0
- package/dist/esm/config/initialize/inits.js +211 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +19 -0
- package/dist/esm/config/legacy/createOutputConfig.js +41 -0
- package/dist/esm/config/legacy/createSourceConfig.js +42 -0
- package/dist/esm/config/legacy/createToolsConfig.js +23 -0
- package/dist/{js/treeshaking/config/initial/transformNormalizedConfig.js → esm/config/legacy/index.js} +4 -1
- package/dist/esm/defineConfig.js +61 -0
- package/dist/esm/exports/server.js +2 -0
- package/dist/esm/hooks.js +29 -0
- package/dist/esm/index.js +713 -0
- package/dist/esm/initialize/index.js +284 -0
- package/dist/esm/locale/en.js +38 -0
- package/dist/esm/locale/index.js +9 -0
- package/dist/esm/locale/zh.js +38 -0
- package/dist/esm/schema/Schema.js +273 -0
- package/dist/esm/schema/index.js +181 -0
- package/dist/esm/schema/legacy.js +337 -0
- package/dist/esm/types/config/deploy.js +1 -0
- package/dist/esm/types/config/dev.js +1 -0
- package/dist/esm/types/config/experiments.js +1 -0
- package/dist/esm/types/config/html.js +1 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +1 -0
- package/dist/esm/types/config/performance.js +1 -0
- package/dist/esm/types/config/security.js +1 -0
- package/dist/esm/types/config/source.js +1 -0
- package/dist/esm/types/config/tools.js +1 -0
- package/dist/esm/types/hooks.js +1 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +1 -0
- package/dist/esm/types/legacyConfig/dev.js +1 -0
- package/dist/esm/types/legacyConfig/index.js +1 -0
- package/dist/esm/types/legacyConfig/output.js +1 -0
- package/dist/esm/types/legacyConfig/source.js +1 -0
- package/dist/esm/types/legacyConfig/tools.js +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/utils/config.js +302 -0
- package/dist/esm/utils/createServer.js +258 -0
- package/dist/esm/utils/env.js +13 -0
- package/dist/esm/utils/generateWatchFiles.js +214 -0
- package/dist/esm/utils/getSelectedEntries.js +186 -0
- package/dist/esm/utils/getServerInternalPlugins.js +210 -0
- package/dist/esm/utils/language.js +6 -0
- package/dist/esm/utils/printInstructions.js +152 -0
- package/dist/esm/utils/restart.js +187 -0
- package/dist/esm/utils/routes.js +153 -0
- package/dist/esm/utils/types.js +1 -0
- package/dist/esm-node/analyze/constants.js +56 -0
- package/dist/esm-node/analyze/generateCode.js +227 -0
- package/dist/esm-node/analyze/getBundleEntry.js +77 -0
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +201 -0
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +197 -0
- package/dist/esm-node/analyze/getClientRoutes/index.js +6 -0
- package/dist/esm-node/analyze/getClientRoutes/utils.js +31 -0
- package/dist/esm-node/analyze/getFileSystemEntry.js +109 -0
- package/dist/esm-node/analyze/getHtmlTemplate.js +95 -0
- package/dist/esm-node/analyze/getServerRoutes.js +154 -0
- package/dist/esm-node/analyze/index.js +285 -0
- package/dist/esm-node/analyze/isDefaultExportFunction.js +42 -0
- package/dist/esm-node/analyze/makeLegalIdentifier.js +13 -0
- package/dist/esm-node/analyze/nestedRoutes.js +150 -0
- package/dist/esm-node/analyze/templates.js +297 -0
- package/dist/esm-node/analyze/utils.js +121 -0
- package/dist/esm-node/builder/builder-rspack/index.js +8 -0
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +51 -0
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +96 -0
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/esm-node/builder/generator/createBuilderOptions.js +24 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +26 -0
- package/dist/esm-node/builder/generator/getBuilderTargets.js +21 -0
- package/dist/esm-node/builder/generator/index.js +29 -0
- package/dist/esm-node/builder/index.js +17 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +202 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/{js/modern/builder/share.js → esm-node/builder/shared/createCopyPattern.js} +0 -0
- package/dist/esm-node/builder/shared/index.js +3 -0
- package/dist/{js/modern/builder → esm-node/builder/shared}/loaders/serverModuleLoader.js +0 -0
- package/dist/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/esm-node/commands/index.js +3 -0
- package/dist/esm-node/commands/inspect.js +18 -0
- package/dist/esm-node/commands/serve.js +34 -0
- package/dist/esm-node/config/default.js +162 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +12 -0
- package/dist/esm-node/config/initialize/inits.js +136 -0
- package/dist/{js/modern/config/initial → esm-node/config/legacy}/createHtmlConfig.js +0 -0
- package/dist/{js/modern/config/initial → esm-node/config/legacy}/createOutputConfig.js +0 -0
- package/dist/{js/modern/config/initial → esm-node/config/legacy}/createSourceConfig.js +0 -0
- package/dist/{js/modern/config/initial → esm-node/config/legacy}/createToolsConfig.js +0 -0
- package/dist/{js/modern/config/initial/transformNormalizedConfig.js → esm-node/config/legacy/index.js} +4 -0
- package/dist/esm-node/defineConfig.js +9 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +35 -0
- package/dist/esm-node/index.js +172 -0
- package/dist/esm-node/initialize/index.js +91 -0
- package/dist/esm-node/locale/en.js +36 -0
- package/dist/esm-node/locale/index.js +9 -0
- package/dist/esm-node/locale/zh.js +36 -0
- package/dist/esm-node/schema/Schema.js +40 -0
- package/dist/esm-node/schema/index.js +88 -0
- package/dist/esm-node/schema/legacy.js +148 -0
- package/dist/esm-node/types/config/deploy.js +0 -0
- package/dist/esm-node/types/config/dev.js +0 -0
- package/dist/esm-node/types/config/experiments.js +0 -0
- package/dist/esm-node/types/config/html.js +0 -0
- package/dist/esm-node/types/config/index.js +1 -0
- package/dist/esm-node/types/config/output.js +0 -0
- package/dist/esm-node/types/config/performance.js +0 -0
- package/dist/esm-node/types/config/security.js +0 -0
- package/dist/esm-node/types/config/source.js +0 -0
- package/dist/esm-node/types/config/tools.js +0 -0
- package/dist/esm-node/types/hooks.js +0 -0
- package/dist/esm-node/types/index.js +3 -0
- package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
- package/dist/esm-node/types/legacyConfig/dev.js +0 -0
- package/dist/esm-node/types/legacyConfig/index.js +0 -0
- package/dist/esm-node/types/legacyConfig/output.js +0 -0
- package/dist/esm-node/types/legacyConfig/source.js +0 -0
- package/dist/esm-node/types/legacyConfig/tools.js +0 -0
- package/dist/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/esm-node/utils/env.js +15 -0
- package/dist/esm-node/utils/generateWatchFiles.js +33 -0
- package/dist/esm-node/utils/getSelectedEntries.js +38 -0
- package/dist/esm-node/utils/getServerInternalPlugins.js +18 -0
- package/dist/esm-node/utils/language.js +8 -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/esm-node/utils/types.js +0 -0
- package/dist/js/modern/analyze/index.js +45 -48
- package/dist/js/modern/analyze/nestedRoutes.js +1 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +1 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +12 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +81 -111
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/createCopyPattern.js +46 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/legacy/createHtmlConfig.js +35 -0
- package/dist/js/modern/config/legacy/createOutputConfig.js +68 -0
- package/dist/js/modern/config/legacy/createSourceConfig.js +39 -0
- package/dist/js/modern/config/legacy/createToolsConfig.js +42 -0
- package/dist/js/modern/config/legacy/index.js +51 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/index.js +46 -49
- package/dist/js/node/analyze/nestedRoutes.js +1 -10
- package/dist/js/node/builder/builder-rspack/index.js +31 -0
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +7 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +35 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +86 -115
- package/dist/js/node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +50 -0
- package/dist/js/node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +57 -0
- package/dist/js/node/builder/shared/createCopyPattern.js +75 -0
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/loaders/serverModuleLoader.js +28 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/config/initialize/index.js +35 -0
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/legacy/createHtmlConfig.js +58 -0
- package/dist/js/node/config/legacy/createOutputConfig.js +91 -0
- package/dist/js/node/config/legacy/createSourceConfig.js +62 -0
- package/dist/js/node/config/legacy/createToolsConfig.js +65 -0
- package/dist/js/node/config/legacy/index.js +75 -0
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/index.js +135 -130
- package/dist/js/treeshaking/analyze/nestedRoutes.js +1 -10
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +1 -1
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +12 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +103 -156
- package/dist/js/treeshaking/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +110 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +0 -0
- package/dist/js/treeshaking/builder/shared/createCopyPattern.js +40 -0
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/loaders/serverModuleLoader.js +5 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/treeshaking/config/{initial → legacy}/createHtmlConfig.js +0 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +0 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +0 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +0 -0
- package/dist/js/treeshaking/config/legacy/index.js +38 -0
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +34 -26
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/types/analyze/generateCode.d.ts +1 -1
- package/dist/types/analyze/getBundleEntry.d.ts +1 -1
- package/dist/types/analyze/getFileSystemEntry.d.ts +1 -1
- package/dist/types/analyze/getHtmlTemplate.d.ts +2 -2
- package/dist/types/analyze/getServerRoutes.d.ts +1 -1
- package/dist/types/analyze/index.d.ts +5 -1
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/builder/builder-rspack/index.d.ts +2 -0
- package/dist/types/builder/{builderPlugins → builder-webpack/builderPlugins}/compatModern.d.ts +2 -2
- package/dist/types/builder/builder-webpack/index.d.ts +4 -0
- package/dist/types/builder/{webpackPlugins/routerPlugin.d.ts → builder-webpack/webpackPlugins/RouterPlugin.d.ts} +1 -1
- package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +1 -0
- package/dist/types/builder/generator/createBuilderOptions.d.ts +3 -0
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +2 -0
- package/dist/types/builder/generator/getBuilderTargets.d.ts +3 -0
- package/dist/types/builder/generator/index.d.ts +17 -0
- package/dist/types/builder/index.d.ts +1 -18
- package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +13 -0
- package/dist/types/builder/{webpackPlugins/htmlAsyncChunkPlugin.d.ts → shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts} +2 -1
- package/dist/types/builder/{webpackPlugins/htmlBottomTemplate.d.ts → shared/bundlerPlugins/HtmlBottomTemplate.d.ts} +2 -1
- package/dist/types/builder/{share.d.ts → shared/createCopyPattern.d.ts} +1 -1
- package/dist/types/builder/shared/index.d.ts +3 -0
- package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +4 -0
- package/dist/types/builder/shared/types.d.ts +16 -0
- package/dist/types/commands/build.d.ts +1 -1
- package/dist/types/commands/deploy.d.ts +1 -1
- package/dist/types/commands/dev.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/commands/serve.d.ts +1 -1
- package/dist/types/config/default.d.ts +1 -1
- package/dist/types/config/index.d.ts +3 -2
- package/dist/types/config/initialize/index.d.ts +2 -0
- package/dist/types/config/{initial → initialize}/inits.d.ts +3 -3
- package/dist/types/config/{initial → legacy}/createHtmlConfig.d.ts +1 -1
- package/dist/types/config/{initial → legacy}/createOutputConfig.d.ts +1 -1
- package/dist/types/config/{initial → legacy}/createSourceConfig.d.ts +1 -1
- package/dist/types/config/{initial → legacy}/createToolsConfig.d.ts +1 -1
- package/dist/types/config/legacy/index.d.ts +3 -0
- package/dist/types/defineConfig.d.ts +2 -2
- package/dist/types/index.d.ts +7 -3
- package/dist/types/initialize/index.d.ts +6 -2
- package/dist/types/types/config/deploy.d.ts +1 -2
- package/dist/types/types/config/dev.d.ts +2 -3
- package/dist/types/types/config/experiments.d.ts +1 -2
- package/dist/types/types/config/html.d.ts +5 -3
- package/dist/types/types/config/index.d.ts +41 -48
- package/dist/types/types/config/output.d.ts +8 -3
- package/dist/types/types/config/performance.d.ts +6 -3
- package/dist/types/types/config/security.d.ts +3 -3
- package/dist/types/types/config/source.d.ts +7 -3
- package/dist/types/types/config/tools.d.ts +10 -4
- package/dist/types/types/hooks.d.ts +6 -4
- package/dist/types/types/index.d.ts +19 -7
- package/dist/types/types/utils.d.ts +7 -0
- package/dist/types/utils/config.d.ts +1 -1
- package/dist/types/utils/getServerInternalPlugins.d.ts +1 -1
- package/dist/types/utils/printInstructions.d.ts +1 -1
- package/package.json +40 -32
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- package/dist/types/builder/loaders/serverModuleLoader.d.ts +0 -3
- package/dist/types/config/initial/index.d.ts +0 -4
- package/dist/types/config/initial/transformNormalizedConfig.d.ts +0 -2
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var getRoutes_exports = {};
|
|
25
|
+
__export(getRoutes_exports, {
|
|
26
|
+
getClientRoutes: () => getClientRoutes
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(getRoutes_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_makeLegalIdentifier = require("../makeLegalIdentifier");
|
|
32
|
+
var import_constants = require("../constants");
|
|
33
|
+
var import_utils2 = require("../utils");
|
|
34
|
+
var import_utils3 = require("./utils");
|
|
35
|
+
const compName = (srcDirectory, filePath) => {
|
|
36
|
+
const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(
|
|
37
|
+
import_path.default.relative(srcDirectory, filePath)
|
|
38
|
+
);
|
|
39
|
+
return `Comp_${legalCompName}`;
|
|
40
|
+
};
|
|
41
|
+
const layoutNameAbbr = (filePath) => {
|
|
42
|
+
const prefix = "L_";
|
|
43
|
+
const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
|
|
44
|
+
return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
|
|
45
|
+
};
|
|
46
|
+
const parents = [];
|
|
47
|
+
const recursiveReadDir = ({
|
|
48
|
+
dir,
|
|
49
|
+
routes,
|
|
50
|
+
basePath = "/",
|
|
51
|
+
srcDirectory,
|
|
52
|
+
srcAlias
|
|
53
|
+
}) => {
|
|
54
|
+
let hasDynamicRoute = false;
|
|
55
|
+
let resetParent = false;
|
|
56
|
+
let parent = parents[parents.length - 1];
|
|
57
|
+
const layout = (0, import_utils3.findLayout)(dir);
|
|
58
|
+
if (layout) {
|
|
59
|
+
if (basePath === "/") {
|
|
60
|
+
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
61
|
+
} else {
|
|
62
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
|
|
63
|
+
const componentName = compName(srcDirectory, layout);
|
|
64
|
+
const route = {
|
|
65
|
+
path: `${basePath.substring(0, basePath.length - 1)}`,
|
|
66
|
+
children: [],
|
|
67
|
+
_component: alias,
|
|
68
|
+
component: componentName,
|
|
69
|
+
parent,
|
|
70
|
+
type: "page"
|
|
71
|
+
};
|
|
72
|
+
parent = route;
|
|
73
|
+
resetParent = true;
|
|
74
|
+
routes.push(route);
|
|
75
|
+
parents.push(route);
|
|
76
|
+
routes = route.children;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const relative of import_utils.fs.readdirSync(dir)) {
|
|
80
|
+
const filePath = import_path.default.join(dir, relative);
|
|
81
|
+
if (!(0, import_utils3.shouldSkip)(filePath)) {
|
|
82
|
+
const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
|
|
83
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
|
|
84
|
+
const componentName = compName(srcDirectory, filePath);
|
|
85
|
+
const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
86
|
+
if (dynamicRouteMatched) {
|
|
87
|
+
if (hasDynamicRoute) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Can't set two dynamic route in one directory: ${dir}`
|
|
90
|
+
);
|
|
91
|
+
} else {
|
|
92
|
+
hasDynamicRoute = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const route = {
|
|
96
|
+
path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
97
|
+
_component: alias,
|
|
98
|
+
component: componentName,
|
|
99
|
+
parent,
|
|
100
|
+
type: "page"
|
|
101
|
+
};
|
|
102
|
+
if (import_utils.fs.statSync(filePath).isDirectory()) {
|
|
103
|
+
recursiveReadDir({
|
|
104
|
+
dir: filePath,
|
|
105
|
+
routes,
|
|
106
|
+
basePath: `${route.path}/`,
|
|
107
|
+
srcDirectory,
|
|
108
|
+
srcAlias
|
|
109
|
+
});
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
|
|
116
|
+
route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
|
|
117
|
+
}
|
|
118
|
+
if (filename === "404" && basePath === "/") {
|
|
119
|
+
route.path = "*";
|
|
120
|
+
}
|
|
121
|
+
routes.push(route);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (resetParent) {
|
|
125
|
+
parents.pop();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
129
|
+
const flat = (routes) => routes.reduce(
|
|
130
|
+
(memo, route) => memo.concat(
|
|
131
|
+
Array.isArray(route.children) ? flat(route.children) : [route]
|
|
132
|
+
),
|
|
133
|
+
[]
|
|
134
|
+
);
|
|
135
|
+
const generate = (route) => {
|
|
136
|
+
const codes = [];
|
|
137
|
+
let lastComponent = route.component;
|
|
138
|
+
const imports = [
|
|
139
|
+
`import React from 'react';`,
|
|
140
|
+
`import ${lastComponent} from '${route._component}'`
|
|
141
|
+
];
|
|
142
|
+
while (route = route.parent) {
|
|
143
|
+
const layoutComponent = route.component;
|
|
144
|
+
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
145
|
+
imports.push(`import ${layoutComponent} from '${route._component}';`);
|
|
146
|
+
const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
|
|
147
|
+
codes.push(
|
|
148
|
+
`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`
|
|
149
|
+
);
|
|
150
|
+
lastComponent = currentComponent;
|
|
151
|
+
}
|
|
152
|
+
const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
153
|
+
import_utils.fs.outputFileSync(
|
|
154
|
+
file,
|
|
155
|
+
`${imports.join("\n")}
|
|
156
|
+
${codes.join(
|
|
157
|
+
"\n"
|
|
158
|
+
)}
|
|
159
|
+
export default ${lastComponent}`
|
|
160
|
+
);
|
|
161
|
+
return {
|
|
162
|
+
component: lastComponent,
|
|
163
|
+
_component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
const normalized = flat(nested).map(
|
|
167
|
+
(route) => route.parent ? { ...route, ...generate(route), parent: void 0 } : { ...route, parent: void 0 }
|
|
168
|
+
);
|
|
169
|
+
return normalized;
|
|
170
|
+
};
|
|
171
|
+
const getClientRoutes = ({
|
|
172
|
+
entrypoint,
|
|
173
|
+
srcDirectory,
|
|
174
|
+
srcAlias,
|
|
175
|
+
internalDirectory,
|
|
176
|
+
internalDirAlias
|
|
177
|
+
}) => {
|
|
178
|
+
const { entryName, pageRoutesEntry } = entrypoint;
|
|
179
|
+
if (!pageRoutesEntry) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
if (!import_utils.fs.existsSync(pageRoutesEntry)) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`generate file system routes error, ${pageRoutesEntry} directory not found.`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (!(import_utils.fs.existsSync(pageRoutesEntry) && import_utils.fs.statSync(pageRoutesEntry).isDirectory())) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`generate file system routes error, ${pageRoutesEntry} should be directory.`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
let routes = [];
|
|
193
|
+
recursiveReadDir({
|
|
194
|
+
dir: pageRoutesEntry,
|
|
195
|
+
routes,
|
|
196
|
+
basePath: "/",
|
|
197
|
+
srcDirectory,
|
|
198
|
+
srcAlias
|
|
199
|
+
});
|
|
200
|
+
const internalComponentsDir = import_path.default.resolve(
|
|
201
|
+
internalDirectory,
|
|
202
|
+
`${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`
|
|
203
|
+
);
|
|
204
|
+
import_utils.fs.emptyDirSync(internalComponentsDir);
|
|
205
|
+
routes = normalizeNestedRoutes(
|
|
206
|
+
routes,
|
|
207
|
+
internalComponentsDir,
|
|
208
|
+
internalDirectory,
|
|
209
|
+
internalDirAlias
|
|
210
|
+
);
|
|
211
|
+
parents.length = 0;
|
|
212
|
+
routes.sort((a, b) => {
|
|
213
|
+
const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
|
|
214
|
+
if (delta === 0) {
|
|
215
|
+
return a.path.length - b.path.length;
|
|
216
|
+
}
|
|
217
|
+
return delta;
|
|
218
|
+
});
|
|
219
|
+
(0, import_utils3.debug)(`fileSystem routes: %o`, routes);
|
|
220
|
+
return routes;
|
|
221
|
+
};
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
getClientRoutes
|
|
225
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var getRoutesLegacy_exports = {};
|
|
25
|
+
__export(getRoutesLegacy_exports, {
|
|
26
|
+
getClientRoutes: () => getClientRoutes
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(getRoutesLegacy_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_makeLegalIdentifier = require("../makeLegalIdentifier");
|
|
32
|
+
var import_constants = require("../constants");
|
|
33
|
+
var import_utils2 = require("../utils");
|
|
34
|
+
var import_utils3 = require("./utils");
|
|
35
|
+
const compName = (srcDirectory, filePath) => {
|
|
36
|
+
const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(
|
|
37
|
+
import_path.default.relative(srcDirectory, filePath)
|
|
38
|
+
);
|
|
39
|
+
return `Comp_${legalCompName}`;
|
|
40
|
+
};
|
|
41
|
+
const layoutNameAbbr = (filePath) => {
|
|
42
|
+
const prefix = "L_";
|
|
43
|
+
const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
|
|
44
|
+
return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
|
|
45
|
+
};
|
|
46
|
+
const parents = [];
|
|
47
|
+
const recursiveReadDirLegacy = ({
|
|
48
|
+
dir,
|
|
49
|
+
routes,
|
|
50
|
+
basePath = "/",
|
|
51
|
+
srcDirectory,
|
|
52
|
+
srcAlias
|
|
53
|
+
}) => {
|
|
54
|
+
let hasDynamicRoute = false;
|
|
55
|
+
let resetParent = false;
|
|
56
|
+
let parent = parents[parents.length - 1];
|
|
57
|
+
const layout = (0, import_utils3.findLayout)(dir);
|
|
58
|
+
if (layout) {
|
|
59
|
+
if (basePath === "/") {
|
|
60
|
+
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
61
|
+
} else {
|
|
62
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
|
|
63
|
+
const componentName = compName(srcDirectory, layout);
|
|
64
|
+
const route = {
|
|
65
|
+
path: `${basePath.substring(0, basePath.length - 1)}`,
|
|
66
|
+
exact: false,
|
|
67
|
+
routes: [],
|
|
68
|
+
_component: alias,
|
|
69
|
+
component: componentName,
|
|
70
|
+
parent
|
|
71
|
+
};
|
|
72
|
+
parent = route;
|
|
73
|
+
resetParent = true;
|
|
74
|
+
routes.push(route);
|
|
75
|
+
parents.push(route);
|
|
76
|
+
routes = route.routes;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const relative of import_utils.fs.readdirSync(dir)) {
|
|
80
|
+
const filePath = import_path.default.join(dir, relative);
|
|
81
|
+
if (!(0, import_utils3.shouldSkip)(filePath)) {
|
|
82
|
+
const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
|
|
83
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
|
|
84
|
+
const componentName = compName(srcDirectory, filePath);
|
|
85
|
+
const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
86
|
+
if (dynamicRouteMatched) {
|
|
87
|
+
if (hasDynamicRoute) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Can't set two dynamic route in one directory: ${dir}`
|
|
90
|
+
);
|
|
91
|
+
} else {
|
|
92
|
+
hasDynamicRoute = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const route = {
|
|
96
|
+
path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
97
|
+
_component: alias,
|
|
98
|
+
component: componentName,
|
|
99
|
+
exact: true,
|
|
100
|
+
parent
|
|
101
|
+
};
|
|
102
|
+
if (import_utils.fs.statSync(filePath).isDirectory()) {
|
|
103
|
+
recursiveReadDirLegacy({
|
|
104
|
+
dir: filePath,
|
|
105
|
+
routes,
|
|
106
|
+
basePath: `${route.path}/`,
|
|
107
|
+
srcDirectory,
|
|
108
|
+
srcAlias
|
|
109
|
+
});
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
|
|
116
|
+
route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
|
|
117
|
+
}
|
|
118
|
+
if (filename === "404" && basePath === "/") {
|
|
119
|
+
route.path = "*";
|
|
120
|
+
route.exact = false;
|
|
121
|
+
}
|
|
122
|
+
routes.push(route);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (resetParent) {
|
|
126
|
+
parents.pop();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
130
|
+
const flat = (routes) => routes.reduce(
|
|
131
|
+
(memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [route]),
|
|
132
|
+
[]
|
|
133
|
+
);
|
|
134
|
+
const generate = (route) => {
|
|
135
|
+
const codes = [];
|
|
136
|
+
let lastComponent = route.component;
|
|
137
|
+
const imports = [
|
|
138
|
+
`import React from 'react';`,
|
|
139
|
+
`import ${lastComponent} from '${route._component}'`
|
|
140
|
+
];
|
|
141
|
+
while (route = route.parent) {
|
|
142
|
+
const layoutComponent = route.component;
|
|
143
|
+
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
144
|
+
imports.push(`import ${layoutComponent} from '${route._component}';`);
|
|
145
|
+
const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
|
|
146
|
+
codes.push(
|
|
147
|
+
`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`
|
|
148
|
+
);
|
|
149
|
+
lastComponent = currentComponent;
|
|
150
|
+
}
|
|
151
|
+
const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
152
|
+
import_utils.fs.outputFileSync(
|
|
153
|
+
file,
|
|
154
|
+
`${imports.join("\n")}
|
|
155
|
+
${codes.join(
|
|
156
|
+
"\n"
|
|
157
|
+
)}
|
|
158
|
+
export default ${lastComponent}`
|
|
159
|
+
);
|
|
160
|
+
return {
|
|
161
|
+
component: lastComponent,
|
|
162
|
+
_component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
const normalized = flat(nested).map(
|
|
166
|
+
(route) => route.parent ? { ...route, ...generate(route), parent: void 0 } : { ...route, parent: void 0 }
|
|
167
|
+
);
|
|
168
|
+
return normalized;
|
|
169
|
+
};
|
|
170
|
+
const getClientRoutes = ({
|
|
171
|
+
entrypoint,
|
|
172
|
+
srcDirectory,
|
|
173
|
+
srcAlias,
|
|
174
|
+
internalDirectory,
|
|
175
|
+
internalDirAlias
|
|
176
|
+
}) => {
|
|
177
|
+
const { entry, entryName } = entrypoint;
|
|
178
|
+
if (!import_utils.fs.existsSync(entry)) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`generate file system routes error, ${entry} directory not found.`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (!(import_utils.fs.existsSync(entry) && import_utils.fs.statSync(entry).isDirectory())) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`generate file system routes error, ${entry} should be directory.`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
let routes = [];
|
|
189
|
+
recursiveReadDirLegacy({
|
|
190
|
+
dir: entry,
|
|
191
|
+
routes,
|
|
192
|
+
basePath: "/",
|
|
193
|
+
srcDirectory,
|
|
194
|
+
srcAlias
|
|
195
|
+
});
|
|
196
|
+
const internalComponentsDir = import_path.default.resolve(
|
|
197
|
+
internalDirectory,
|
|
198
|
+
`${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`
|
|
199
|
+
);
|
|
200
|
+
import_utils.fs.emptyDirSync(internalComponentsDir);
|
|
201
|
+
routes = normalizeNestedRoutes(
|
|
202
|
+
routes,
|
|
203
|
+
internalComponentsDir,
|
|
204
|
+
internalDirectory,
|
|
205
|
+
internalDirAlias
|
|
206
|
+
);
|
|
207
|
+
parents.length = 0;
|
|
208
|
+
routes.sort((a, b) => {
|
|
209
|
+
const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
|
|
210
|
+
if (delta === 0) {
|
|
211
|
+
return a.path.length - b.path.length;
|
|
212
|
+
}
|
|
213
|
+
return delta;
|
|
214
|
+
});
|
|
215
|
+
(0, import_utils3.debug)(`fileSystem routes: %o`, routes);
|
|
216
|
+
return routes;
|
|
217
|
+
};
|
|
218
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
219
|
+
0 && (module.exports = {
|
|
220
|
+
getClientRoutes
|
|
221
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var getClientRoutes_exports = {};
|
|
19
|
+
__export(getClientRoutes_exports, {
|
|
20
|
+
getClientRoutes: () => import_getRoutes.getClientRoutes,
|
|
21
|
+
getClientRoutesLegacy: () => import_getRoutesLegacy.getClientRoutes
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getClientRoutes_exports);
|
|
24
|
+
var import_getRoutes = require("./getRoutes");
|
|
25
|
+
var import_getRoutesLegacy = require("./getRoutesLegacy");
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
getClientRoutes,
|
|
29
|
+
getClientRoutesLegacy
|
|
30
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var utils_exports = {};
|
|
25
|
+
__export(utils_exports, {
|
|
26
|
+
debug: () => debug,
|
|
27
|
+
findLayout: () => findLayout,
|
|
28
|
+
getRouteWeight: () => getRouteWeight,
|
|
29
|
+
shouldSkip: () => shouldSkip
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(utils_exports);
|
|
32
|
+
var import_path = __toESM(require("path"));
|
|
33
|
+
var import_utils = require("@modern-js/utils");
|
|
34
|
+
var import_constants = require("../constants");
|
|
35
|
+
const debug = (0, import_utils.createDebugger)("get-client-routes");
|
|
36
|
+
const findLayout = (dir) => (0, import_utils.findExists)(
|
|
37
|
+
import_constants.JS_EXTENSIONS.map(
|
|
38
|
+
(ext) => import_path.default.resolve(dir, `${import_constants.FILE_SYSTEM_ROUTES_LAYOUT}${ext}`)
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
const getRouteWeight = (route) => route === "*" ? 999 : route.split(":").length - 1;
|
|
42
|
+
const shouldSkip = (file) => {
|
|
43
|
+
if (import_utils.fs.statSync(file).isDirectory()) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const ext = import_path.default.extname(file);
|
|
47
|
+
if (import_constants.FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !import_constants.JS_EXTENSIONS.includes(ext) || import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === import_path.default.basename(file, ext)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
debug,
|
|
55
|
+
findLayout,
|
|
56
|
+
getRouteWeight,
|
|
57
|
+
shouldSkip
|
|
58
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var getFileSystemEntry_exports = {};
|
|
25
|
+
__export(getFileSystemEntry_exports, {
|
|
26
|
+
getFileSystemEntry: () => getFileSystemEntry
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(getFileSystemEntry_exports);
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
31
|
+
var import_utils = require("@modern-js/utils");
|
|
32
|
+
var import_isDefaultExportFunction = require("./isDefaultExportFunction");
|
|
33
|
+
var import_constants = require("./constants");
|
|
34
|
+
const hasIndex = (dir) => (0, import_utils.findExists)(
|
|
35
|
+
import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`))
|
|
36
|
+
);
|
|
37
|
+
const hasApp = (dir) => (0, import_utils.findExists)(
|
|
38
|
+
import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.APP_FILE_NAME}${ext}`))
|
|
39
|
+
);
|
|
40
|
+
const hasPages = (dir) => import_fs.default.existsSync(import_path.default.join(dir, import_constants.PAGES_DIR_NAME));
|
|
41
|
+
const hasNestedRoutes = (dir) => import_fs.default.existsSync(import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR));
|
|
42
|
+
const isBundleEntry = (dir) => hasApp(dir) || hasPages(dir) || hasIndex(dir) || hasNestedRoutes(dir);
|
|
43
|
+
const scanDir = (dirs) => dirs.map((dir) => {
|
|
44
|
+
const indexFile = hasIndex(dir);
|
|
45
|
+
const customBootstrap = (0, import_isDefaultExportFunction.isDefaultExportFunction)(indexFile) ? indexFile : false;
|
|
46
|
+
const entryName = import_path.default.basename(dir);
|
|
47
|
+
if (indexFile && !customBootstrap) {
|
|
48
|
+
return {
|
|
49
|
+
entryName,
|
|
50
|
+
entry: indexFile,
|
|
51
|
+
absoluteEntryDir: import_path.default.resolve(dir),
|
|
52
|
+
isAutoMount: false
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const isHasApp = hasApp(dir);
|
|
56
|
+
if (isHasApp) {
|
|
57
|
+
return {
|
|
58
|
+
entryName,
|
|
59
|
+
entry: import_path.default.join(dir, import_constants.APP_FILE_NAME),
|
|
60
|
+
isAutoMount: true,
|
|
61
|
+
absoluteEntryDir: import_path.default.resolve(dir),
|
|
62
|
+
customBootstrap
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const isHasNestedRoutes = hasNestedRoutes(dir);
|
|
66
|
+
const isHasPages = hasPages(dir);
|
|
67
|
+
if (isHasNestedRoutes || isHasPages) {
|
|
68
|
+
const entrypoint = {
|
|
69
|
+
entryName,
|
|
70
|
+
entry: "",
|
|
71
|
+
fileSystemRoutes: {
|
|
72
|
+
globalApp: (0, import_utils.findExists)(
|
|
73
|
+
import_constants.JS_EXTENSIONS.map(
|
|
74
|
+
(ext) => import_path.default.resolve(
|
|
75
|
+
dir,
|
|
76
|
+
`./${import_constants.PAGES_DIR_NAME}/${import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
},
|
|
81
|
+
isAutoMount: true,
|
|
82
|
+
absoluteEntryDir: import_path.default.resolve(dir),
|
|
83
|
+
customBootstrap
|
|
84
|
+
};
|
|
85
|
+
if (isHasPages) {
|
|
86
|
+
entrypoint.entry = import_path.default.join(dir, import_constants.PAGES_DIR_NAME);
|
|
87
|
+
entrypoint.pageRoutesEntry = entrypoint.entry;
|
|
88
|
+
}
|
|
89
|
+
if (isHasNestedRoutes) {
|
|
90
|
+
entrypoint.entry = import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR);
|
|
91
|
+
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
92
|
+
}
|
|
93
|
+
return entrypoint;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
entryName,
|
|
97
|
+
entry: indexFile,
|
|
98
|
+
absoluteEntryDir: import_path.default.resolve(dir),
|
|
99
|
+
isAutoMount: false
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const getFileSystemEntry = (appContext, config) => {
|
|
103
|
+
const { appDirectory } = appContext;
|
|
104
|
+
const {
|
|
105
|
+
source: { entriesDir, disableEntryDirs }
|
|
106
|
+
} = config;
|
|
107
|
+
let disabledDirs = [];
|
|
108
|
+
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
109
|
+
disabledDirs = disableEntryDirs == null ? void 0 : disableEntryDirs.map(
|
|
110
|
+
(dir) => (0, import_utils.ensureAbsolutePath)(appDirectory, dir)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
const src = (0, import_utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
|
|
114
|
+
if (import_fs.default.existsSync(src)) {
|
|
115
|
+
if (import_fs.default.statSync(src).isDirectory()) {
|
|
116
|
+
return scanDir(
|
|
117
|
+
isBundleEntry(src) ? [src] : import_fs.default.readdirSync(src).map((file) => import_path.default.join(src, file)).filter(
|
|
118
|
+
(file) => import_fs.default.statSync(file).isDirectory() && isBundleEntry(file) && !disabledDirs.includes(file)
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
throw Error(`source.entriesDir accept a directory.`);
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
throw Error(`src dir ${entriesDir} not found.`);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
getFileSystemEntry
|
|
131
|
+
});
|