@modern-js/app-tools 2.4.0 → 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 +59 -0
- 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/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +50 -0
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +57 -0
- package/dist/cjs/builder/shared/createCopyPattern.js +75 -0
- package/dist/cjs/builder/shared/index.js +19 -0
- package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +28 -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/cjs/config/initialize/index.js +35 -0
- package/dist/cjs/config/initialize/inits.js +161 -0
- package/dist/cjs/config/legacy/createHtmlConfig.js +58 -0
- package/dist/cjs/config/legacy/createOutputConfig.js +91 -0
- package/dist/cjs/config/legacy/createSourceConfig.js +62 -0
- package/dist/cjs/config/legacy/createToolsConfig.js +65 -0
- package/dist/cjs/config/legacy/index.js +75 -0
- 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/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +110 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +72 -0
- package/dist/esm/builder/shared/createCopyPattern.js +40 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +5 -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/esm/config/legacy/index.js +38 -0
- 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/esm-node/builder/shared/createCopyPattern.js +46 -0
- package/dist/esm-node/builder/shared/index.js +3 -0
- package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -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/esm-node/config/legacy/createHtmlConfig.js +35 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +68 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +39 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +42 -0
- package/dist/esm-node/config/legacy/index.js +51 -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/nestedRoutes.js +1 -10
- package/dist/js/node/analyze/nestedRoutes.js +1 -10
- package/dist/js/treeshaking/analyze/nestedRoutes.js +1 -10
- package/dist/types/analyze/templates.d.ts +3 -1
- 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
|
@@ -0,0 +1,124 @@
|
|
|
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 getHtmlTemplate_exports = {};
|
|
25
|
+
__export(getHtmlTemplate_exports, {
|
|
26
|
+
getHtmlTemplate: () => getHtmlTemplate
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(getHtmlTemplate_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_constants = require("./constants");
|
|
32
|
+
var templates = __toESM(require("./templates"));
|
|
33
|
+
var PartialPosition = /* @__PURE__ */ ((PartialPosition2) => {
|
|
34
|
+
PartialPosition2["TOP"] = "top";
|
|
35
|
+
PartialPosition2["HEAD"] = "head";
|
|
36
|
+
PartialPosition2["BODY"] = "body";
|
|
37
|
+
PartialPosition2["BOTTOM"] = "bottom";
|
|
38
|
+
PartialPosition2["INDEX"] = "index";
|
|
39
|
+
return PartialPosition2;
|
|
40
|
+
})(PartialPosition || {});
|
|
41
|
+
const findPartials = (dir, entryName, position) => {
|
|
42
|
+
if (import_utils.fs.existsSync(dir)) {
|
|
43
|
+
const base = (0, import_utils.findExists)(
|
|
44
|
+
import_constants.HTML_PARTIALS_EXTENSIONS.map(
|
|
45
|
+
(ext) => import_path.default.resolve(dir, `${position}${ext}`)
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
const file = entryName ? (0, import_utils.findExists)(
|
|
49
|
+
import_constants.HTML_PARTIALS_EXTENSIONS.map(
|
|
50
|
+
(ext) => import_path.default.resolve(dir, entryName, `${position}${ext}`)
|
|
51
|
+
)
|
|
52
|
+
) || base : base;
|
|
53
|
+
return file ? { file, content: import_utils.fs.readFileSync(file, "utf8") } : null;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
const getHtmlTemplate = async (entrypoints, api, {
|
|
58
|
+
appContext,
|
|
59
|
+
config
|
|
60
|
+
}) => {
|
|
61
|
+
const { appDirectory, internalDirectory } = appContext;
|
|
62
|
+
const {
|
|
63
|
+
source: { configDir }
|
|
64
|
+
} = config;
|
|
65
|
+
const htmlDir = import_path.default.resolve(
|
|
66
|
+
appDirectory,
|
|
67
|
+
configDir || "",
|
|
68
|
+
import_constants.HTML_PARTIALS_FOLDER
|
|
69
|
+
);
|
|
70
|
+
const htmlTemplates = {};
|
|
71
|
+
for (const entrypoint of entrypoints) {
|
|
72
|
+
const { entryName } = entrypoint;
|
|
73
|
+
const name = entrypoints.length === 1 && entryName === import_utils.MAIN_ENTRY_NAME ? "" : entryName;
|
|
74
|
+
const customIndexTemplate = findPartials(
|
|
75
|
+
htmlDir,
|
|
76
|
+
name,
|
|
77
|
+
"index" /* INDEX */
|
|
78
|
+
);
|
|
79
|
+
if (customIndexTemplate) {
|
|
80
|
+
htmlTemplates[entryName] = customIndexTemplate.file;
|
|
81
|
+
} else {
|
|
82
|
+
const hookRunners = api.useHookRunners();
|
|
83
|
+
const { partials } = await hookRunners.htmlPartials({
|
|
84
|
+
entrypoint,
|
|
85
|
+
partials: [
|
|
86
|
+
"top" /* TOP */,
|
|
87
|
+
"head" /* HEAD */,
|
|
88
|
+
"body" /* BODY */
|
|
89
|
+
].reduce(
|
|
90
|
+
(previous, position) => {
|
|
91
|
+
const found = findPartials(htmlDir, name, position);
|
|
92
|
+
previous[position] = found ? [found.content] : [];
|
|
93
|
+
return previous;
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
top: [],
|
|
97
|
+
head: [],
|
|
98
|
+
body: []
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
});
|
|
102
|
+
const templatePath = import_path.default.resolve(
|
|
103
|
+
internalDirectory,
|
|
104
|
+
entryName,
|
|
105
|
+
"index.html"
|
|
106
|
+
);
|
|
107
|
+
import_utils.fs.outputFileSync(templatePath, templates.html(partials), "utf8");
|
|
108
|
+
htmlTemplates[entryName] = templatePath;
|
|
109
|
+
const bottomTemplate = findPartials(
|
|
110
|
+
htmlDir,
|
|
111
|
+
name,
|
|
112
|
+
"bottom" /* BOTTOM */
|
|
113
|
+
);
|
|
114
|
+
if (bottomTemplate) {
|
|
115
|
+
htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return htmlTemplates;
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
getHtmlTemplate
|
|
124
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
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 getServerRoutes_exports = {};
|
|
25
|
+
__export(getServerRoutes_exports, {
|
|
26
|
+
getServerRoutes: () => getServerRoutes
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(getServerRoutes_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_fs = __toESM(require("fs"));
|
|
31
|
+
var import_utils = require("@modern-js/utils");
|
|
32
|
+
var import_utils2 = require("./utils");
|
|
33
|
+
const applyBaseUrl = (baseUrl, routes) => {
|
|
34
|
+
if (baseUrl) {
|
|
35
|
+
if (Array.isArray(baseUrl)) {
|
|
36
|
+
return baseUrl.reduce(
|
|
37
|
+
(previous, current) => [...previous, ...applyBaseUrl(current, routes)],
|
|
38
|
+
[]
|
|
39
|
+
);
|
|
40
|
+
} else {
|
|
41
|
+
return routes.map((route) => {
|
|
42
|
+
const urlPath = (0, import_utils.urlJoin)(baseUrl, route.urlPath);
|
|
43
|
+
return {
|
|
44
|
+
...route,
|
|
45
|
+
urlPath: urlPath === "/" ? urlPath : (0, import_utils.removeTailSlash)(urlPath)
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return routes;
|
|
51
|
+
};
|
|
52
|
+
const applyRouteOptions = (original, routeOptions) => {
|
|
53
|
+
const { route, disableSpa } = routeOptions;
|
|
54
|
+
original.isSPA = !disableSpa;
|
|
55
|
+
!original.isSPA && (original.entryPath = import_path.default.dirname(original.entryPath));
|
|
56
|
+
let routes;
|
|
57
|
+
if (route) {
|
|
58
|
+
if (Array.isArray(route)) {
|
|
59
|
+
routes = route.map((url) => {
|
|
60
|
+
if ((0, import_utils.isPlainObject)(url)) {
|
|
61
|
+
const { path: urlPath, ...other } = url;
|
|
62
|
+
return {
|
|
63
|
+
...original,
|
|
64
|
+
...other,
|
|
65
|
+
urlPath
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
return {
|
|
69
|
+
...original,
|
|
70
|
+
urlPath: url
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
} else if ((0, import_utils.isPlainObject)(route)) {
|
|
75
|
+
const { path: urlPath, ...other } = route;
|
|
76
|
+
routes = [
|
|
77
|
+
{
|
|
78
|
+
...original,
|
|
79
|
+
...other,
|
|
80
|
+
urlPath
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
} else {
|
|
84
|
+
routes = [
|
|
85
|
+
{
|
|
86
|
+
...original,
|
|
87
|
+
urlPath: route
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
routes = [original];
|
|
93
|
+
}
|
|
94
|
+
return routes;
|
|
95
|
+
};
|
|
96
|
+
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
97
|
+
const {
|
|
98
|
+
html: { disableHtmlFolder },
|
|
99
|
+
output: { distPath: { html: htmlPath } = {} },
|
|
100
|
+
server: { baseUrl, routes, ssr, ssrByEntries, worker }
|
|
101
|
+
} = config;
|
|
102
|
+
const { packageName } = appContext;
|
|
103
|
+
let htmlRoutes = entrypoints.reduce(
|
|
104
|
+
(previous, { entryName }) => {
|
|
105
|
+
const entryOptions = (0, import_utils.getEntryOptions)(
|
|
106
|
+
entryName,
|
|
107
|
+
ssr,
|
|
108
|
+
ssrByEntries,
|
|
109
|
+
packageName
|
|
110
|
+
);
|
|
111
|
+
const isSSR = Boolean(entryOptions);
|
|
112
|
+
const isWorker = Boolean(worker);
|
|
113
|
+
const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
|
|
114
|
+
let route = {
|
|
115
|
+
urlPath: `/${entryName === import_utils.MAIN_ENTRY_NAME ? "" : entryName}`,
|
|
116
|
+
entryName,
|
|
117
|
+
entryPath: (0, import_utils.removeLeadingSlash)(
|
|
118
|
+
import_path.default.posix.normalize(
|
|
119
|
+
`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`
|
|
120
|
+
)
|
|
121
|
+
),
|
|
122
|
+
isSPA: true,
|
|
123
|
+
isSSR,
|
|
124
|
+
responseHeaders: resHeaders,
|
|
125
|
+
worker: isWorker ? `${import_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
|
|
126
|
+
bundle: isSSR ? `${import_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
|
|
127
|
+
};
|
|
128
|
+
if (routes == null ? void 0 : routes.hasOwnProperty(entryName)) {
|
|
129
|
+
const routeOptions = (0, import_utils.isPlainObject)(routes[entryName]) ? routes[entryName] : { route: routes[entryName] };
|
|
130
|
+
route = applyRouteOptions(route, routeOptions);
|
|
131
|
+
}
|
|
132
|
+
return Array.isArray(route) ? [...previous, ...route] : [...previous, route];
|
|
133
|
+
},
|
|
134
|
+
[]
|
|
135
|
+
);
|
|
136
|
+
htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
|
|
137
|
+
return htmlRoutes;
|
|
138
|
+
};
|
|
139
|
+
const collectStaticRoutes = (appContext, config) => {
|
|
140
|
+
const { appDirectory } = appContext;
|
|
141
|
+
const {
|
|
142
|
+
source: { configDir },
|
|
143
|
+
server: { publicRoutes = {} }
|
|
144
|
+
} = config;
|
|
145
|
+
const publicFolder = import_path.default.resolve(appDirectory, configDir || "", "public");
|
|
146
|
+
return import_fs.default.existsSync(publicFolder) ? (0, import_utils2.walkDirectory)(publicFolder).map((filePath) => {
|
|
147
|
+
const urlPath = `${(0, import_utils.urlJoin)(
|
|
148
|
+
toPosix(filePath).slice(toPosix(publicFolder).length)
|
|
149
|
+
)}`;
|
|
150
|
+
return {
|
|
151
|
+
urlPath: publicRoutes[(0, import_utils.removeLeadingSlash)(urlPath)] || urlPath,
|
|
152
|
+
isSPA: true,
|
|
153
|
+
isSSR: false,
|
|
154
|
+
entryPath: toPosix(
|
|
155
|
+
import_path.default.relative(
|
|
156
|
+
import_path.default.resolve(appDirectory, configDir || ""),
|
|
157
|
+
filePath
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
};
|
|
161
|
+
}) : [];
|
|
162
|
+
};
|
|
163
|
+
const getServerRoutes = (entrypoints, {
|
|
164
|
+
appContext,
|
|
165
|
+
config
|
|
166
|
+
}) => [
|
|
167
|
+
...collectHtmlRoutes(entrypoints, appContext, config),
|
|
168
|
+
...collectStaticRoutes(appContext, config)
|
|
169
|
+
];
|
|
170
|
+
const toPosix = (pathStr) => pathStr.split(import_path.default.sep).join(import_path.default.posix.sep);
|
|
171
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
172
|
+
0 && (module.exports = {
|
|
173
|
+
getServerRoutes
|
|
174
|
+
});
|
|
@@ -0,0 +1,294 @@
|
|
|
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 analyze_exports = {};
|
|
25
|
+
__export(analyze_exports, {
|
|
26
|
+
default: () => analyze_default
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(analyze_exports);
|
|
29
|
+
var path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_lodash = require("@modern-js/utils/lodash");
|
|
32
|
+
var import_printInstructions = require("../utils/printInstructions");
|
|
33
|
+
var import_routes = require("../utils/routes");
|
|
34
|
+
var import_config = require("../utils/config");
|
|
35
|
+
var import_getSelectedEntries = require("../utils/getSelectedEntries");
|
|
36
|
+
var import_config2 = require("../config");
|
|
37
|
+
var import_builder = require("../builder");
|
|
38
|
+
var import_utils2 = require("./utils");
|
|
39
|
+
var import_constants = require("./constants");
|
|
40
|
+
const debug = (0, import_utils.createDebugger)("plugin-analyze");
|
|
41
|
+
var analyze_default = ({
|
|
42
|
+
bundler
|
|
43
|
+
}) => ({
|
|
44
|
+
name: "@modern-js/plugin-analyze",
|
|
45
|
+
setup: (api) => {
|
|
46
|
+
let pagesDir = [];
|
|
47
|
+
let nestedRouteEntries = [];
|
|
48
|
+
let originEntrypoints = [];
|
|
49
|
+
return {
|
|
50
|
+
async prepare() {
|
|
51
|
+
var _a;
|
|
52
|
+
let appContext = api.useAppContext();
|
|
53
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
54
|
+
const hookRunners = api.useHookRunners();
|
|
55
|
+
try {
|
|
56
|
+
import_utils.fs.emptydirSync(appContext.internalDirectory);
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
const apiOnly = await (0, import_utils.isApiOnly)(
|
|
60
|
+
appContext.appDirectory,
|
|
61
|
+
(_a = resolvedConfig.source) == null ? void 0 : _a.entriesDir
|
|
62
|
+
);
|
|
63
|
+
await hookRunners.addRuntimeExports();
|
|
64
|
+
if (apiOnly) {
|
|
65
|
+
const { routes: routes2 } = await hookRunners.modifyServerRoutes({
|
|
66
|
+
routes: []
|
|
67
|
+
});
|
|
68
|
+
debug(`server routes: %o`, routes2);
|
|
69
|
+
appContext = {
|
|
70
|
+
...appContext,
|
|
71
|
+
apiOnly,
|
|
72
|
+
serverRoutes: routes2
|
|
73
|
+
};
|
|
74
|
+
api.setAppContext(appContext);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const [
|
|
78
|
+
{ getBundleEntry },
|
|
79
|
+
{ getServerRoutes },
|
|
80
|
+
{ generateCode },
|
|
81
|
+
{ getHtmlTemplate }
|
|
82
|
+
] = await Promise.all([
|
|
83
|
+
Promise.resolve().then(() => __toESM(require("./getBundleEntry"))),
|
|
84
|
+
Promise.resolve().then(() => __toESM(require("./getServerRoutes"))),
|
|
85
|
+
Promise.resolve().then(() => __toESM(require("./generateCode"))),
|
|
86
|
+
Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
|
|
87
|
+
]);
|
|
88
|
+
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
89
|
+
debug(`entrypoints: %o`, entrypoints);
|
|
90
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
|
91
|
+
appContext,
|
|
92
|
+
config: resolvedConfig
|
|
93
|
+
});
|
|
94
|
+
const { routes } = await hookRunners.modifyServerRoutes({
|
|
95
|
+
routes: initialRoutes
|
|
96
|
+
});
|
|
97
|
+
debug(`server routes: %o`, routes);
|
|
98
|
+
appContext = {
|
|
99
|
+
...appContext,
|
|
100
|
+
entrypoints,
|
|
101
|
+
serverRoutes: routes
|
|
102
|
+
};
|
|
103
|
+
api.setAppContext(appContext);
|
|
104
|
+
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
105
|
+
pagesDir = entrypoints.map((point) => point.entry).filter(Boolean).concat(nestedRouteEntries);
|
|
106
|
+
originEntrypoints = (0, import_lodash.cloneDeep)(entrypoints);
|
|
107
|
+
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
108
|
+
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
|
109
|
+
appContext,
|
|
110
|
+
config: resolvedConfig
|
|
111
|
+
});
|
|
112
|
+
debug(`html templates: %o`, htmlTemplates);
|
|
113
|
+
await hookRunners.addDefineTypes();
|
|
114
|
+
debug(`add Define Types`);
|
|
115
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
116
|
+
if ((0, import_utils.isDevCommand)()) {
|
|
117
|
+
const { entry } = (0, import_utils.minimist)(process.argv.slice(2));
|
|
118
|
+
checkedEntries = await (0, import_getSelectedEntries.getSelectedEntries)(
|
|
119
|
+
typeof entry === "string" ? entry.split(",") : entry,
|
|
120
|
+
entrypoints
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
appContext = {
|
|
124
|
+
...appContext,
|
|
125
|
+
entrypoints,
|
|
126
|
+
checkedEntries,
|
|
127
|
+
apiOnly,
|
|
128
|
+
serverRoutes: routes,
|
|
129
|
+
htmlTemplates
|
|
130
|
+
};
|
|
131
|
+
api.setAppContext(appContext);
|
|
132
|
+
const command = (0, import_utils.getCommand)();
|
|
133
|
+
const buildCommands = ["dev", "start", "build", "inspect", "deploy"];
|
|
134
|
+
if (buildCommands.includes(command)) {
|
|
135
|
+
const normalizedConfig = api.useResolvedConfigContext();
|
|
136
|
+
const createBuilderForModern = await (0, import_builder.createBuilderGenerator)(bundler);
|
|
137
|
+
const builder = await createBuilderForModern({
|
|
138
|
+
normalizedConfig,
|
|
139
|
+
appContext,
|
|
140
|
+
async onBeforeBuild({ bundlerConfigs }) {
|
|
141
|
+
const hookRunners2 = api.useHookRunners();
|
|
142
|
+
await (0, import_routes.generateRoutes)(appContext);
|
|
143
|
+
await hookRunners2.beforeBuild({
|
|
144
|
+
bundlerConfigs
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
async onAfterBuild({ stats }) {
|
|
148
|
+
const hookRunners2 = api.useHookRunners();
|
|
149
|
+
await hookRunners2.afterBuild({ stats });
|
|
150
|
+
await (0, import_config.emitResolvedConfig)(
|
|
151
|
+
appContext.appDirectory,
|
|
152
|
+
normalizedConfig
|
|
153
|
+
);
|
|
154
|
+
},
|
|
155
|
+
async onDevCompileDone({ isFirstCompile }) {
|
|
156
|
+
const hookRunners2 = api.useHookRunners();
|
|
157
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
158
|
+
hookRunners2.afterDev();
|
|
159
|
+
if (isFirstCompile) {
|
|
160
|
+
(0, import_printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
async onBeforeCreateCompiler({ bundlerConfigs }) {
|
|
165
|
+
const hookRunners2 = api.useHookRunners();
|
|
166
|
+
await hookRunners2.beforeCreateCompiler({
|
|
167
|
+
bundlerConfigs
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
async onAfterCreateCompiler({ compiler }) {
|
|
171
|
+
const hookRunners2 = api.useHookRunners();
|
|
172
|
+
await hookRunners2.afterCreateCompiler({
|
|
173
|
+
compiler
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
178
|
+
appContext = {
|
|
179
|
+
...appContext,
|
|
180
|
+
builder
|
|
181
|
+
};
|
|
182
|
+
api.setAppContext(appContext);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
watchFiles() {
|
|
186
|
+
return pagesDir;
|
|
187
|
+
},
|
|
188
|
+
config() {
|
|
189
|
+
return {
|
|
190
|
+
tools: {
|
|
191
|
+
webpackChain: (chain, { name }) => {
|
|
192
|
+
const appContext = api.useAppContext();
|
|
193
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
194
|
+
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
195
|
+
entrypoints.forEach((entrypoint) => {
|
|
196
|
+
const { entryName } = entrypoint;
|
|
197
|
+
const ssr = (0, import_utils.getEntryOptions)(
|
|
198
|
+
entryName,
|
|
199
|
+
resolvedConfig.server.ssr,
|
|
200
|
+
resolvedConfig.server.ssrByEntries,
|
|
201
|
+
packageName
|
|
202
|
+
);
|
|
203
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
204
|
+
const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
|
|
205
|
+
internalDirectory,
|
|
206
|
+
entryName
|
|
207
|
+
);
|
|
208
|
+
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
209
|
+
chain.resolve.alias.set(
|
|
210
|
+
"@modern-js/plugin-data-loader/runtime",
|
|
211
|
+
require.resolve("@modern-js/plugin-data-loader/runtime")
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
resolvedConfig({ resolved }) {
|
|
220
|
+
const appContext = api.useAppContext();
|
|
221
|
+
const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext, bundler);
|
|
222
|
+
return {
|
|
223
|
+
resolved: config
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
async modifyEntryImports({ entrypoint, imports }) {
|
|
227
|
+
const appContext = api.useAppContext();
|
|
228
|
+
const { srcDirectory, internalSrcAlias } = appContext;
|
|
229
|
+
const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
|
|
230
|
+
if (fileSystemRoutes && nestedRoutesEntry) {
|
|
231
|
+
const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
|
|
232
|
+
const rootLayoutFile = (0, import_utils.findExists)(
|
|
233
|
+
[".js", ".ts", ".jsx", ".tsx"].map(
|
|
234
|
+
(ext) => `${rootLayoutPath}${ext}`
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
if (rootLayoutFile) {
|
|
238
|
+
const rootLayoutBuffer = await import_utils.fs.readFile(rootLayoutFile);
|
|
239
|
+
const rootLayout = rootLayoutBuffer.toString();
|
|
240
|
+
const [, moduleExports] = await (0, import_utils2.parseModule)({
|
|
241
|
+
source: rootLayout.toString(),
|
|
242
|
+
filename: rootLayoutFile
|
|
243
|
+
});
|
|
244
|
+
const hasAppConfig = moduleExports.some(
|
|
245
|
+
(e) => e.n === import_constants.APP_CONFIG_NAME
|
|
246
|
+
);
|
|
247
|
+
const generateLayoutPath = (0, import_utils2.replaceWithAlias)(
|
|
248
|
+
srcDirectory,
|
|
249
|
+
rootLayoutFile,
|
|
250
|
+
internalSrcAlias
|
|
251
|
+
);
|
|
252
|
+
if (hasAppConfig) {
|
|
253
|
+
imports.push({
|
|
254
|
+
value: generateLayoutPath,
|
|
255
|
+
specifiers: [{ imported: import_constants.APP_CONFIG_NAME }]
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
const hasAppInit = moduleExports.some(
|
|
259
|
+
(e) => e.n === import_constants.APP_INIT_EXPORTED
|
|
260
|
+
);
|
|
261
|
+
if (hasAppInit) {
|
|
262
|
+
imports.push({
|
|
263
|
+
value: generateLayoutPath,
|
|
264
|
+
specifiers: [
|
|
265
|
+
{ imported: import_constants.APP_INIT_EXPORTED, local: import_constants.APP_INIT_IMPORTED }
|
|
266
|
+
]
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
entrypoint,
|
|
273
|
+
imports
|
|
274
|
+
};
|
|
275
|
+
},
|
|
276
|
+
async fileChange(e) {
|
|
277
|
+
const appContext = api.useAppContext();
|
|
278
|
+
const { appDirectory } = appContext;
|
|
279
|
+
const { filename, eventType } = e;
|
|
280
|
+
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
281
|
+
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
282
|
+
const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils2.isPageComponentFile)(absoluteFilePath);
|
|
283
|
+
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
284
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
285
|
+
const { generateCode } = await Promise.resolve().then(() => __toESM(require("./generateCode")));
|
|
286
|
+
const entrypoints = (0, import_lodash.cloneDeep)(originEntrypoints);
|
|
287
|
+
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
294
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,71 @@
|
|
|
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 isDefaultExportFunction_exports = {};
|
|
25
|
+
__export(isDefaultExportFunction_exports, {
|
|
26
|
+
isDefaultExportFunction: () => isDefaultExportFunction
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(isDefaultExportFunction_exports);
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_parser = require("@babel/parser");
|
|
31
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
32
|
+
var t = __toESM(require("@babel/types"));
|
|
33
|
+
const isFunction = (node) => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
|
34
|
+
const isDefaultExportFunction = (file) => {
|
|
35
|
+
if (!file || !import_fs.default.existsSync(file)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const ast = (0, import_parser.parse)(import_fs.default.readFileSync(file, "utf8"), {
|
|
39
|
+
sourceType: "unambiguous",
|
|
40
|
+
plugins: [
|
|
41
|
+
"jsx",
|
|
42
|
+
"typescript",
|
|
43
|
+
"classProperties",
|
|
44
|
+
"dynamicImport",
|
|
45
|
+
"exportDefaultFrom",
|
|
46
|
+
"exportNamespaceFrom",
|
|
47
|
+
"decorators-legacy",
|
|
48
|
+
"functionBind",
|
|
49
|
+
"classPrivateMethods",
|
|
50
|
+
["pipelineOperator", { proposal: "minimal" }],
|
|
51
|
+
"optionalChaining",
|
|
52
|
+
"optionalCatchBinding",
|
|
53
|
+
"objectRestSpread",
|
|
54
|
+
"numericSeparator"
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
let isExportFunction = false;
|
|
58
|
+
(0, import_traverse.default)(ast, {
|
|
59
|
+
ExportDefaultDeclaration: (path) => {
|
|
60
|
+
const { declaration } = path.node;
|
|
61
|
+
if (isFunction(declaration)) {
|
|
62
|
+
isExportFunction = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return isExportFunction;
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
isDefaultExportFunction
|
|
71
|
+
});
|