@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +0 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/cjs/commands/build.js +2 -0
- package/dist/cjs/commands/deploy.js +2 -2
- package/dist/cjs/commands/dev.js +19 -5
- package/dist/cjs/commands/index.js +113 -7
- package/dist/cjs/commands/serve.js +19 -5
- package/dist/cjs/hooks.js +5 -0
- package/dist/cjs/index.js +14 -83
- package/dist/cjs/plugins/analyze/constants.js +56 -0
- package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
- package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
- package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
- package/dist/cjs/plugins/analyze/templates.js +101 -0
- package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
- package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
- package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +10 -4
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/deploy.js +2 -2
- package/dist/esm/commands/dev.js +13 -9
- package/dist/esm/commands/index.js +411 -3
- package/dist/esm/commands/serve.js +12 -8
- package/dist/esm/hooks.js +5 -0
- package/dist/esm/index.js +12 -394
- package/dist/esm/plugins/analyze/constants.js +24 -0
- package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
- package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
- package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
- package/dist/esm/plugins/analyze/templates.js +22 -0
- package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
- package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
- package/dist/esm/plugins/deploy/platforms/node.js +5 -3
- package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
- package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +13 -6
- package/dist/esm/utils/createServer.js +2 -2
- package/dist/esm/utils/loadPlugins.js +64 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm-node/commands/build.js +2 -0
- package/dist/esm-node/commands/deploy.js +2 -2
- package/dist/esm-node/commands/dev.js +11 -7
- package/dist/esm-node/commands/index.js +92 -3
- package/dist/esm-node/commands/serve.js +10 -6
- package/dist/esm-node/hooks.js +5 -0
- package/dist/esm-node/index.js +12 -79
- package/dist/esm-node/plugins/analyze/constants.js +24 -0
- package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
- package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
- package/dist/esm-node/plugins/analyze/templates.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
- package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
- package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +11 -5
- package/dist/esm-node/utils/createServer.js +2 -2
- package/dist/esm-node/utils/loadPlugins.js +21 -0
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
- package/dist/types/commands/index.d.ts +10 -3
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/exports/server.d.ts +4 -0
- package/dist/types/index.d.ts +2 -5
- package/dist/types/plugins/analyze/constants.d.ts +9 -0
- package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
- package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
- package/dist/types/plugins/analyze/templates.d.ts +19 -0
- package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
- package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +11 -1
- package/dist/types/utils/loadPlugins.d.ts +5 -0
- package/package.json +22 -22
- package/dist/cjs/analyze/constants.js +0 -122
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
- package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
- package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
- package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
- package/dist/cjs/analyze/nestedRoutes.js +0 -295
- package/dist/cjs/analyze/templates.js +0 -444
- package/dist/esm/analyze/constants.js +0 -76
- package/dist/esm/analyze/getBundleEntry.js +0 -75
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
- package/dist/esm/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
- package/dist/esm/analyze/getFileSystemEntry.js +0 -113
- package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
- package/dist/esm/analyze/nestedRoutes.js +0 -398
- package/dist/esm/analyze/templates.js +0 -435
- package/dist/esm/utils/getServerInternalPlugins.js +0 -40
- package/dist/esm-node/analyze/constants.js +0 -76
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
- package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
- package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
- package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
- package/dist/esm-node/analyze/nestedRoutes.js +0 -259
- package/dist/esm-node/analyze/templates.js +0 -405
- package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
- package/dist/types/analyze/constants.d.ts +0 -42
- package/dist/types/analyze/getBundleEntry.d.ts +0 -3
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
- package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
- package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
- package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
- package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
- package/dist/types/analyze/nestedRoutes.d.ts +0 -7
- package/dist/types/analyze/templates.d.ts +0 -30
- package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
- /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -36,10 +36,8 @@ module.exports = __toCommonJS(generateCode_exports);
|
|
36
36
|
var import_path = __toESM(require("path"));
|
37
37
|
var import_utils = require("@modern-js/utils");
|
38
38
|
var templates = __toESM(require("./templates"));
|
39
|
-
var import_getClientRoutes = require("./getClientRoutes");
|
40
39
|
var import_constants = require("./constants");
|
41
40
|
var import_utils2 = require("./utils");
|
42
|
-
var import_nestedRoutes = require("./nestedRoutes");
|
43
41
|
const createImportSpecifier = (specifiers) => {
|
44
42
|
let defaults = "";
|
45
43
|
const named = [];
|
@@ -85,92 +83,17 @@ ${initialize || ""}`);
|
|
85
83
|
${initialize || ""}`).join("\n");
|
86
84
|
};
|
87
85
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
88
|
-
const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias,
|
86
|
+
const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile } = appContext;
|
89
87
|
const hookRunners = api.useHookRunners();
|
90
|
-
const
|
91
|
-
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
88
|
+
const customRuntimeConfig = (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
|
92
89
|
const importsStatemets = /* @__PURE__ */ new Map();
|
93
|
-
|
94
|
-
await Promise.all(entrypoints.map(generateEntryCode));
|
90
|
+
await Promise.all(entrypoints.map((entrypoint) => generateEntryCode(entrypoint, customRuntimeConfig)));
|
95
91
|
return {
|
96
92
|
importsStatemets
|
97
93
|
};
|
98
|
-
async function generateEntryCode(entrypoint) {
|
99
|
-
const { entryName,
|
94
|
+
async function generateEntryCode(entrypoint, customRuntimeConfig2) {
|
95
|
+
const { entryName, isAutoMount } = entrypoint;
|
100
96
|
if (isAutoMount) {
|
101
|
-
if (fileSystemRoutes) {
|
102
|
-
var _config_output;
|
103
|
-
let initialRoutes = [];
|
104
|
-
let nestedRoutes = null;
|
105
|
-
if (entrypoint.entry) {
|
106
|
-
initialRoutes = getRoutes({
|
107
|
-
entrypoint,
|
108
|
-
srcDirectory,
|
109
|
-
srcAlias: internalSrcAlias,
|
110
|
-
internalDirectory,
|
111
|
-
internalDirAlias
|
112
|
-
});
|
113
|
-
}
|
114
|
-
if (!isV5 && entrypoint.nestedRoutesEntry) {
|
115
|
-
nestedRoutes = await (0, import_nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
116
|
-
name: internalSrcAlias,
|
117
|
-
basename: srcDirectory
|
118
|
-
}, entrypoint.entryName, entrypoint.isMainEntry, oldVersion);
|
119
|
-
if (nestedRoutes) {
|
120
|
-
if (!Array.isArray(nestedRoutes)) {
|
121
|
-
nestedRoutes = [
|
122
|
-
nestedRoutes
|
123
|
-
];
|
124
|
-
}
|
125
|
-
for (const route of nestedRoutes) {
|
126
|
-
initialRoutes.unshift(route);
|
127
|
-
}
|
128
|
-
}
|
129
|
-
}
|
130
|
-
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
131
|
-
entrypoint,
|
132
|
-
routes: initialRoutes
|
133
|
-
});
|
134
|
-
const config2 = api.useResolvedConfigContext();
|
135
|
-
const ssr = (0, import_utils.getEntryOptions)(entryName, isMainEntry, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
136
|
-
const useSSG = (0, import_utils.isSSGEntry)(config2, entryName, entrypoints);
|
137
|
-
let mode;
|
138
|
-
if (ssr) {
|
139
|
-
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
140
|
-
}
|
141
|
-
if (mode === "stream") {
|
142
|
-
const hasPageRoute = routes.some((route) => "type" in route && route.type === "page");
|
143
|
-
if (hasPageRoute) {
|
144
|
-
import_utils.logger.error("Streaming ssr is not supported when pages dir exists");
|
145
|
-
process.exit(1);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
const { code } = await hookRunners.beforeGenerateRoutes({
|
149
|
-
entrypoint,
|
150
|
-
code: await templates.fileSystemRoutes({
|
151
|
-
routes,
|
152
|
-
ssrMode: useSSG ? "string" : mode,
|
153
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
154
|
-
entryName: entrypoint.entryName,
|
155
|
-
internalDirectory,
|
156
|
-
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
157
|
-
})
|
158
|
-
});
|
159
|
-
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
160
|
-
const routesServerFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
|
161
|
-
const code2 = templates.routesForServer({
|
162
|
-
routes
|
163
|
-
});
|
164
|
-
await import_utils.fs.ensureFile(routesServerFile);
|
165
|
-
await import_utils.fs.writeFile(routesServerFile, code2);
|
166
|
-
}
|
167
|
-
const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
168
|
-
if (serverLoaderCombined) {
|
169
|
-
const serverLoaderFile = (0, import_utils2.getServerCombinedModueFile)(internalDirectory, entryName);
|
170
|
-
await import_utils.fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
171
|
-
}
|
172
|
-
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, "utf8");
|
173
|
-
}
|
174
97
|
const { imports } = await hookRunners.modifyEntryImports({
|
175
98
|
entrypoint,
|
176
99
|
imports: (0, import_utils2.getDefaultImports)({
|
@@ -178,7 +101,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
178
101
|
srcDirectory,
|
179
102
|
appDirectory,
|
180
103
|
internalSrcAlias,
|
181
|
-
internalDirAlias
|
104
|
+
internalDirAlias,
|
105
|
+
runtimeConfigFile,
|
106
|
+
customRuntimeConfig: customRuntimeConfig2
|
182
107
|
})
|
183
108
|
});
|
184
109
|
importsStatemets.set(entryName, imports);
|
@@ -190,7 +115,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
190
115
|
const generateIndexCode = async ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs }) => {
|
191
116
|
const hookRunners = api.useHookRunners();
|
192
117
|
const { mountId } = config.html;
|
193
|
-
const { internalDirectory, packageName } = appContext;
|
118
|
+
const { internalDirectory, packageName, srcDirectory, runtimeConfigFile } = appContext;
|
119
|
+
const customRuntimeConfig = (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
|
194
120
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
195
121
|
const { entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
196
122
|
if (isAutoMount) {
|
@@ -204,6 +130,7 @@ const generateIndexCode = async ({ appContext, api, entrypoints, config, imports
|
|
204
130
|
code: templates.renderFunction({
|
205
131
|
plugins,
|
206
132
|
customBootstrap,
|
133
|
+
customRuntimeConfig,
|
207
134
|
fileSystemRoutes
|
208
135
|
})
|
209
136
|
});
|
@@ -34,11 +34,10 @@ module.exports = __toCommonJS(getBundleEntry_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
36
|
var import_getFileSystemEntry = require("./getFileSystemEntry");
|
37
|
-
var import_constants = require("./constants");
|
38
37
|
var import_utils2 = require("./utils");
|
39
38
|
const ensureExtensions = (file) => {
|
40
39
|
if (!import_path.default.extname(file)) {
|
41
|
-
return (0, import_utils.findExists)(
|
40
|
+
return (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => `${file}${ext}`)) || file;
|
42
41
|
}
|
43
42
|
return file;
|
44
43
|
};
|
@@ -56,32 +55,24 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
|
|
56
55
|
}
|
57
56
|
return false;
|
58
57
|
});
|
59
|
-
const getBundleEntry = (appContext, config) => {
|
58
|
+
const getBundleEntry = async (hookRunners, appContext, config) => {
|
60
59
|
const { appDirectory, packageName } = appContext;
|
61
60
|
const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
|
62
|
-
const defaults = disableDefaultEntries ? [] : (0, import_getFileSystemEntry.getFileSystemEntry)(appContext, config);
|
61
|
+
const defaults = disableDefaultEntries ? [] : await (0, import_getFileSystemEntry.getFileSystemEntry)(hookRunners, appContext, config);
|
63
62
|
if (entries) {
|
64
63
|
Object.keys(entries).forEach((name) => {
|
65
64
|
const value = entries[name];
|
66
|
-
const
|
65
|
+
const entryName = typeof value === "string" ? value : value.entry;
|
66
|
+
const isAutoMount = typeof value === "string" ? true : !value.disableMount;
|
67
|
+
const entrypoint = {
|
67
68
|
entryName: name,
|
68
69
|
isMainEntry: false,
|
69
|
-
entry: (0, import_utils.ensureAbsolutePath)(appDirectory,
|
70
|
-
absoluteEntryDir: isDirectory((0, import_utils.ensureAbsolutePath)(appDirectory,
|
71
|
-
isAutoMount
|
72
|
-
|
73
|
-
|
74
|
-
entryName: name,
|
75
|
-
isMainEntry: false,
|
76
|
-
entry: (0, import_utils.ensureAbsolutePath)(appDirectory, value.entry),
|
77
|
-
absoluteEntryDir: isDirectory((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)) ? (0, import_utils.ensureAbsolutePath)(appDirectory, value.entry) : import_path.default.dirname((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)),
|
78
|
-
isAutoMount: !value.disableMount,
|
79
|
-
customBootstrap: value.customBootstrap && (0, import_utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
|
80
|
-
fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
70
|
+
entry: (0, import_utils.ensureAbsolutePath)(appDirectory, entryName),
|
71
|
+
absoluteEntryDir: isDirectory((0, import_utils.ensureAbsolutePath)(appDirectory, entryName)) ? (0, import_utils.ensureAbsolutePath)(appDirectory, entryName) : import_path.default.dirname((0, import_utils.ensureAbsolutePath)(appDirectory, entryName)),
|
72
|
+
isAutoMount,
|
73
|
+
customBootstrap: typeof value === "string" ? false : value.customBootstrap && (0, import_utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
|
74
|
+
fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, entryName)).isDirectory() ? {} : void 0
|
81
75
|
};
|
82
|
-
if (entrypoint.fileSystemRoutes && !(0, import_utils.isRouterV5)(config)) {
|
83
|
-
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
84
|
-
}
|
85
76
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
86
77
|
defaults.push(entrypoint);
|
87
78
|
}
|
@@ -34,14 +34,16 @@ module.exports = __toCommonJS(getFileSystemEntry_exports);
|
|
34
34
|
var import_fs = __toESM(require("fs"));
|
35
35
|
var import_path = __toESM(require("path"));
|
36
36
|
var import_utils = require("@modern-js/utils");
|
37
|
-
var import_isDefaultExportFunction = require("./isDefaultExportFunction");
|
38
37
|
var import_constants = require("./constants");
|
39
|
-
|
40
|
-
const
|
41
|
-
const
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
var import_isDefaultExportFunction = require("./isDefaultExportFunction");
|
39
|
+
const hasIndex = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`)));
|
40
|
+
const isBundleEntry = async (hookRunners, dir) => {
|
41
|
+
return (await hookRunners.checkEntryPoint({
|
42
|
+
path: dir,
|
43
|
+
entry: false
|
44
|
+
})).entry || hasIndex(dir);
|
45
|
+
};
|
46
|
+
const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
|
45
47
|
const indexFile = hasIndex(dir);
|
46
48
|
const customBootstrap = (0, import_isDefaultExportFunction.isDefaultExportFunction)(indexFile) ? indexFile : false;
|
47
49
|
const entryName = import_path.default.basename(dir);
|
@@ -51,53 +53,27 @@ const scanDir = (dirs) => dirs.map((dir) => {
|
|
51
53
|
isMainEntry: false,
|
52
54
|
entry: indexFile,
|
53
55
|
absoluteEntryDir: import_path.default.resolve(dir),
|
54
|
-
isAutoMount: false
|
56
|
+
isAutoMount: false,
|
57
|
+
customBootstrap
|
55
58
|
};
|
56
59
|
}
|
57
|
-
const
|
58
|
-
|
60
|
+
const entryFile = (await hookRunners.checkEntryPoint({
|
61
|
+
path: dir,
|
62
|
+
entry: false
|
63
|
+
})).entry;
|
64
|
+
if (entryFile) {
|
59
65
|
return {
|
60
66
|
entryName,
|
61
67
|
isMainEntry: false,
|
62
|
-
entry:
|
63
|
-
isAutoMount: true,
|
68
|
+
entry: entryFile,
|
64
69
|
absoluteEntryDir: import_path.default.resolve(dir),
|
65
|
-
customBootstrap
|
66
|
-
};
|
67
|
-
}
|
68
|
-
const isHasNestedRoutes = hasNestedRoutes(dir);
|
69
|
-
const isHasPages = hasPages(dir);
|
70
|
-
if (isHasNestedRoutes || isHasPages) {
|
71
|
-
const entrypoint = {
|
72
|
-
entryName,
|
73
|
-
isMainEntry: false,
|
74
|
-
entry: "",
|
75
|
-
fileSystemRoutes: {
|
76
|
-
globalApp: (0, import_utils.findExists)(import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `./${import_constants.PAGES_DIR_NAME}/${import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
|
77
|
-
},
|
78
70
|
isAutoMount: true,
|
79
|
-
absoluteEntryDir: import_path.default.resolve(dir),
|
80
71
|
customBootstrap
|
81
72
|
};
|
82
|
-
if (isHasPages) {
|
83
|
-
entrypoint.entry = import_path.default.join(dir, import_constants.PAGES_DIR_NAME);
|
84
|
-
entrypoint.pageRoutesEntry = entrypoint.entry;
|
85
|
-
}
|
86
|
-
if (isHasNestedRoutes) {
|
87
|
-
entrypoint.entry = import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR);
|
88
|
-
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
89
|
-
}
|
90
|
-
return entrypoint;
|
91
73
|
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
entry: indexFile,
|
96
|
-
absoluteEntryDir: import_path.default.resolve(dir),
|
97
|
-
isAutoMount: false
|
98
|
-
};
|
99
|
-
});
|
100
|
-
const getFileSystemEntry = (appContext, config) => {
|
74
|
+
throw Error("There is no valid entry point in the current project!");
|
75
|
+
}));
|
76
|
+
const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
101
77
|
const { appDirectory } = appContext;
|
102
78
|
const { source: { entriesDir, disableEntryDirs } } = config;
|
103
79
|
let disabledDirs = [];
|
@@ -107,9 +83,19 @@ const getFileSystemEntry = (appContext, config) => {
|
|
107
83
|
const src = (0, import_utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
|
108
84
|
if (import_fs.default.existsSync(src)) {
|
109
85
|
if (import_fs.default.statSync(src).isDirectory()) {
|
110
|
-
|
111
|
-
|
112
|
-
|
86
|
+
if (await isBundleEntry(hookRunners, src)) {
|
87
|
+
return scanDir(hookRunners, [
|
88
|
+
src
|
89
|
+
]);
|
90
|
+
}
|
91
|
+
const dirs = [];
|
92
|
+
await Promise.all(import_fs.default.readdirSync(src).map(async (filename) => {
|
93
|
+
const file = import_path.default.join(src, filename);
|
94
|
+
if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file) && !disabledDirs.includes(file)) {
|
95
|
+
dirs.push(file);
|
96
|
+
}
|
97
|
+
}));
|
98
|
+
return scanDir(hookRunners, dirs);
|
113
99
|
} else {
|
114
100
|
throw Error(`source.entriesDir accept a directory.`);
|
115
101
|
}
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(getServerRoutes_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
35
35
|
var import_fs = __toESM(require("fs"));
|
36
36
|
var import_utils = require("@modern-js/utils");
|
37
|
-
var import_routes = require("
|
37
|
+
var import_routes = require("../../utils/routes");
|
38
38
|
var import_utils2 = require("./utils");
|
39
39
|
const applyBaseUrl = (baseUrl, routes) => {
|
40
40
|
if (baseUrl) {
|
@@ -33,13 +33,12 @@ __export(analyze_exports, {
|
|
33
33
|
module.exports = __toCommonJS(analyze_exports);
|
34
34
|
var path = __toESM(require("path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
|
-
var
|
37
|
-
var
|
38
|
-
var
|
39
|
-
var
|
40
|
-
var
|
41
|
-
var
|
42
|
-
var import_builder = require("../builder");
|
36
|
+
var import_printInstructions = require("../../utils/printInstructions");
|
37
|
+
var import_routes = require("../../utils/routes");
|
38
|
+
var import_config = require("../../utils/config");
|
39
|
+
var import_getSelectedEntries = require("../../utils/getSelectedEntries");
|
40
|
+
var import_config2 = require("../../config");
|
41
|
+
var import_builder = require("../../builder");
|
43
42
|
var import_utils2 = require("./utils");
|
44
43
|
var import_constants = require("./constants");
|
45
44
|
var import_generateCode = require("./generateCode");
|
@@ -49,7 +48,6 @@ var analyze_default = ({ bundler }) => ({
|
|
49
48
|
setup: (api) => {
|
50
49
|
let pagesDir = [];
|
51
50
|
let nestedRouteEntries = [];
|
52
|
-
let originEntrypoints = [];
|
53
51
|
return {
|
54
52
|
async prepare() {
|
55
53
|
var _resolvedConfig_source;
|
@@ -83,7 +81,9 @@ var analyze_default = ({ bundler }) => ({
|
|
83
81
|
Promise.resolve().then(() => __toESM(require("./generateCode"))),
|
84
82
|
Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
|
85
83
|
]);
|
86
|
-
const entrypoints =
|
84
|
+
const { entrypoints } = await hookRunners.modifyEntrypoints({
|
85
|
+
entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
|
86
|
+
});
|
87
87
|
debug(`entrypoints: %o`, entrypoints);
|
88
88
|
const initialRoutes = getServerRoutes(entrypoints, {
|
89
89
|
appContext,
|
@@ -101,7 +101,6 @@ var analyze_default = ({ bundler }) => ({
|
|
101
101
|
api.setAppContext(appContext);
|
102
102
|
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
103
103
|
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
104
|
-
originEntrypoints = (0, import_lodash.cloneDeep)(entrypoints);
|
105
104
|
const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
|
106
105
|
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
107
106
|
appContext,
|
@@ -245,20 +244,6 @@ var analyze_default = ({ bundler }) => ({
|
|
245
244
|
entrypoint,
|
246
245
|
imports
|
247
246
|
};
|
248
|
-
},
|
249
|
-
async fileChange(e) {
|
250
|
-
const appContext = api.useAppContext();
|
251
|
-
const { appDirectory } = appContext;
|
252
|
-
const { filename, eventType } = e;
|
253
|
-
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
254
|
-
const absoluteFilePath = path.resolve(appDirectory, filename);
|
255
|
-
const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils2.isPageComponentFile)(absoluteFilePath);
|
256
|
-
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
257
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
258
|
-
const { generateCode } = await Promise.resolve().then(() => __toESM(require("./generateCode")));
|
259
|
-
const entrypoints = (0, import_lodash.cloneDeep)(originEntrypoints);
|
260
|
-
generateCode(appContext, resolvedConfig, entrypoints, api);
|
261
|
-
}
|
262
247
|
}
|
263
248
|
};
|
264
249
|
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var templates_exports = {};
|
20
|
+
__export(templates_exports, {
|
21
|
+
html: () => html,
|
22
|
+
index: () => index,
|
23
|
+
renderFunction: () => renderFunction
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(templates_exports);
|
26
|
+
var import_constants = require("./constants");
|
27
|
+
const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
|
28
|
+
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
29
|
+
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
30
|
+
const MOUNT_ID = '${mountId}';
|
31
|
+
|
32
|
+
${imports}
|
33
|
+
|
34
|
+
let AppWrapper = null;
|
35
|
+
|
36
|
+
let root = null;
|
37
|
+
|
38
|
+
function render() {
|
39
|
+
${renderFunction2}
|
40
|
+
}
|
41
|
+
|
42
|
+
AppWrapper = render();
|
43
|
+
|
44
|
+
${exportStatement};
|
45
|
+
`;
|
46
|
+
const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig }) => {
|
47
|
+
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
48
|
+
const runtimePlugins = `...(runtimeConfig?.plugins || []),`;
|
49
|
+
return `
|
50
|
+
const finalAppConfig = {
|
51
|
+
...App.config,
|
52
|
+
...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
|
53
|
+
}
|
54
|
+
|
55
|
+
AppWrapper = createApp({
|
56
|
+
plugins: [
|
57
|
+
${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
|
58
|
+
${customRuntimeConfig ? runtimePlugins : ""}
|
59
|
+
]
|
60
|
+
})(${fileSystemRoutes ? "" : `App`})
|
61
|
+
|
62
|
+
|
63
|
+
if(!AppWrapper.init && typeof appInit !== 'undefined') {
|
64
|
+
AppWrapper.init = appInit;
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
if (IS_BROWSER) {
|
69
|
+
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
70
|
+
}
|
71
|
+
|
72
|
+
return AppWrapper
|
73
|
+
`;
|
74
|
+
};
|
75
|
+
const html = (partials) => `
|
76
|
+
<!DOCTYPE html>
|
77
|
+
<html>
|
78
|
+
<head>
|
79
|
+
|
80
|
+
${partials.top.join("\n")}
|
81
|
+
|
82
|
+
${partials.head.join("\n")}
|
83
|
+
|
84
|
+
</head>
|
85
|
+
|
86
|
+
<body>
|
87
|
+
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
88
|
+
${partials.body.join("\n")}
|
89
|
+
<!--<?- chunksMap.js ?>-->
|
90
|
+
<!--<?- SSRDataScript ?>-->
|
91
|
+
<!--<?- bottomTemplate ?>-->
|
92
|
+
</body>
|
93
|
+
|
94
|
+
</html>
|
95
|
+
`;
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
97
|
+
0 && (module.exports = {
|
98
|
+
html,
|
99
|
+
index,
|
100
|
+
renderFunction
|
101
|
+
});
|
@@ -31,10 +31,6 @@ __export(utils_exports, {
|
|
31
31
|
checkIsBuildCommands: () => checkIsBuildCommands,
|
32
32
|
getDefaultImports: () => getDefaultImports,
|
33
33
|
getServerCombinedModueFile: () => getServerCombinedModueFile,
|
34
|
-
getServerLoadersFile: () => getServerLoadersFile,
|
35
|
-
hasAction: () => hasAction,
|
36
|
-
hasLoader: () => hasLoader,
|
37
|
-
isPageComponentFile: () => isPageComponentFile,
|
38
34
|
isSubDirOrEqual: () => isSubDirOrEqual,
|
39
35
|
parseModule: () => parseModule,
|
40
36
|
replaceWithAlias: () => replaceWithAlias,
|
@@ -61,7 +57,7 @@ const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previo
|
|
61
57
|
];
|
62
58
|
}
|
63
59
|
}, []);
|
64
|
-
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias }) => {
|
60
|
+
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig }) => {
|
65
61
|
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
66
62
|
const imports = [
|
67
63
|
{
|
@@ -132,21 +128,17 @@ const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrc
|
|
132
128
|
value: (0, import_utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
|
133
129
|
});
|
134
130
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
".ts",
|
145
|
-
".tsx"
|
146
|
-
].includes(import_path.default.extname(filePath))) {
|
147
|
-
return true;
|
131
|
+
if (customRuntimeConfig) {
|
132
|
+
imports.push({
|
133
|
+
specifiers: [
|
134
|
+
{
|
135
|
+
local: "runtimeConfig"
|
136
|
+
}
|
137
|
+
],
|
138
|
+
value: import_path.default.join(internalSrcAlias, runtimeConfigFile || "")
|
139
|
+
});
|
148
140
|
}
|
149
|
-
return
|
141
|
+
return imports;
|
150
142
|
};
|
151
143
|
const replaceWithAlias = (base, filePath, alias) => {
|
152
144
|
if (filePath.includes(base)) {
|
@@ -157,7 +149,7 @@ const replaceWithAlias = (base, filePath, alias) => {
|
|
157
149
|
};
|
158
150
|
const parseModule = async ({ source, filename }) => {
|
159
151
|
let content = source;
|
160
|
-
if (
|
152
|
+
if (import_utils.JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
|
161
153
|
const result = await (0, import_esbuild.transform)(content, {
|
162
154
|
loader: import_path.default.extname(filename).slice(1),
|
163
155
|
format: "esm"
|
@@ -166,37 +158,6 @@ const parseModule = async ({ source, filename }) => {
|
|
166
158
|
}
|
167
159
|
return await (0, import_es_module_lexer.parse)(content);
|
168
160
|
};
|
169
|
-
const hasLoader = async (filename, source) => {
|
170
|
-
let content = source;
|
171
|
-
if (!source) {
|
172
|
-
content = (await import_utils.fs.readFile(filename, "utf-8")).toString();
|
173
|
-
}
|
174
|
-
if (content) {
|
175
|
-
const [, moduleExports] = await parseModule({
|
176
|
-
source: content.toString(),
|
177
|
-
filename
|
178
|
-
});
|
179
|
-
return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
|
180
|
-
}
|
181
|
-
return false;
|
182
|
-
};
|
183
|
-
const hasAction = async (filename, source) => {
|
184
|
-
let content = source;
|
185
|
-
if (!source) {
|
186
|
-
content = (await import_utils.fs.readFile(filename, "utf-8")).toString();
|
187
|
-
}
|
188
|
-
if (content) {
|
189
|
-
const [, moduleExports] = await parseModule({
|
190
|
-
source: content.toString(),
|
191
|
-
filename
|
192
|
-
});
|
193
|
-
return moduleExports.some((e) => e.n === import_constants.ACTION_EXPORT_NAME);
|
194
|
-
}
|
195
|
-
return false;
|
196
|
-
};
|
197
|
-
const getServerLoadersFile = (internalDirectory, entryName) => {
|
198
|
-
return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
|
199
|
-
};
|
200
161
|
const getServerCombinedModueFile = (internalDirectory, entryName) => {
|
201
162
|
return import_path.default.join(internalDirectory, entryName, "server-loader-combined.js");
|
202
163
|
};
|
@@ -225,10 +186,6 @@ const isSubDirOrEqual = (parent, child) => {
|
|
225
186
|
checkIsBuildCommands,
|
226
187
|
getDefaultImports,
|
227
188
|
getServerCombinedModueFile,
|
228
|
-
getServerLoadersFile,
|
229
|
-
hasAction,
|
230
|
-
hasLoader,
|
231
|
-
isPageComponentFile,
|
232
189
|
isSubDirOrEqual,
|
233
190
|
parseModule,
|
234
191
|
replaceWithAlias,
|
@@ -50,8 +50,8 @@ async function cleanDistDirectory(dir) {
|
|
50
50
|
}
|
51
51
|
}
|
52
52
|
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
53
|
-
const { appDirectory, distDirectory,
|
54
|
-
const plugins = (
|
53
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
54
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
55
55
|
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
56
56
|
const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
|
57
57
|
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
@@ -36,8 +36,8 @@ var import_utils = require("@modern-js/utils");
|
|
36
36
|
var import_utils2 = require("../utils");
|
37
37
|
var import_dependencies = require("../dependencies");
|
38
38
|
const createNodePreset = (appContext, config) => {
|
39
|
-
const { appDirectory, distDirectory,
|
40
|
-
const plugins = (
|
39
|
+
const { appDirectory, distDirectory, serverPlugins } = appContext;
|
40
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
41
41
|
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
42
42
|
const staticDirectory = import_node_path.default.join(outputDirectory, "static");
|
43
43
|
const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
|
@@ -37,8 +37,8 @@ var import_routes = require("../../../utils/routes");
|
|
37
37
|
var import_utils2 = require("../utils");
|
38
38
|
var import_dependencies = require("../dependencies");
|
39
39
|
const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
40
|
-
const { appDirectory, distDirectory,
|
41
|
-
const plugins = (
|
40
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
41
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
42
42
|
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
43
43
|
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
44
44
|
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
@@ -22,7 +22,7 @@ __export(initialize_exports, {
|
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(initialize_exports);
|
24
24
|
var import_utils = require("@modern-js/utils");
|
25
|
-
var import_config = require("
|
25
|
+
var import_config = require("../../config");
|
26
26
|
var initialize_default = ({ bundler }) => ({
|
27
27
|
name: "@modern-js/plugin-initialize",
|
28
28
|
post: [
|