@modern-js/app-tools 2.53.1-alpha.3 → 2.54.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/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/dependencies/index.js +16 -25
- package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
- package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
- 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/dependencies/index.js +69 -94
- package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
- package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
- package/dist/esm/plugins/deploy/platforms/node.js +8 -14
- package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
- 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/dependencies/index.js +18 -27
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
- package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
- 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/plugins/deploy/dependencies/index.d.ts +1 -9
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
- 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 -30
- 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/cjs/plugins/deploy/exports.js +0 -28
- 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/plugins/deploy/exports.js +0 -4
- 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/plugins/deploy/exports.js +0 -4
- package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
- package/dist/js/modern/analyze/constants.js +0 -15
- package/dist/js/modern/analyze/generateCode.js +0 -179
- package/dist/js/modern/analyze/getBundleEntry.js +0 -75
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
- package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
- package/dist/js/modern/analyze/getServerRoutes.js +0 -192
- package/dist/js/modern/analyze/index.js +0 -148
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
- package/dist/js/modern/analyze/templates.js +0 -88
- package/dist/js/modern/analyze/utils.js +0 -92
- package/dist/js/modern/commands/build.js +0 -154
- package/dist/js/modern/commands/deploy.js +0 -5
- package/dist/js/modern/commands/dev.js +0 -95
- package/dist/js/modern/commands/index.js +0 -3
- package/dist/js/modern/commands/inspect.js +0 -69
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/hooks.js +0 -21
- package/dist/js/modern/index.js +0 -109
- package/dist/js/modern/locale/en.js +0 -35
- package/dist/js/modern/locale/index.js +0 -9
- package/dist/js/modern/locale/zh.js +0 -35
- package/dist/js/modern/utils/config.js +0 -78
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/modern/utils/createServer.js +0 -18
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
- package/dist/js/modern/utils/language.js +0 -5
- package/dist/js/modern/utils/printInstructions.js +0 -11
- package/dist/js/modern/utils/routes.js +0 -15
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +0 -36
- package/dist/js/node/analyze/generateCode.js +0 -208
- package/dist/js/node/analyze/getBundleEntry.js +0 -89
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
- package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
- package/dist/js/node/analyze/getServerRoutes.js +0 -208
- package/dist/js/node/analyze/index.js +0 -178
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
- package/dist/js/node/analyze/templates.js +0 -106
- package/dist/js/node/analyze/utils.js +0 -113
- package/dist/js/node/commands/build.js +0 -174
- package/dist/js/node/commands/deploy.js +0 -14
- package/dist/js/node/commands/dev.js +0 -120
- package/dist/js/node/commands/index.js +0 -44
- package/dist/js/node/commands/inspect.js +0 -98
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/exports/server.js +0 -13
- package/dist/js/node/hooks.js +0 -39
- package/dist/js/node/index.js +0 -141
- package/dist/js/node/locale/en.js +0 -42
- package/dist/js/node/locale/index.js +0 -20
- package/dist/js/node/locale/zh.js +0 -42
- package/dist/js/node/utils/config.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/js/node/utils/createServer.js +0 -35
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
- package/dist/js/node/utils/language.js +0 -13
- package/dist/js/node/utils/printInstructions.js +0 -22
- package/dist/js/node/utils/routes.js +0 -25
- package/dist/js/node/utils/types.js +0 -0
- 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/plugins/deploy/exports.d.ts +0 -1
- 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
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
2
|
-
import { DEFAULT_DEV_HOST } from "@modern-js/utils";
|
|
3
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
|
|
3
4
|
import { createDevServer } from "@modern-js/server";
|
|
4
|
-
import {
|
|
5
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
|
6
|
+
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
5
7
|
import { registerCompiler } from "../utils/register";
|
|
6
8
|
import { printInstructions } from "../utils/printInstructions";
|
|
7
9
|
import { setServer } from "../utils/createServer";
|
|
8
10
|
import { generateRoutes } from "../utils/routes";
|
|
9
11
|
import { buildServerConfig } from "../utils/config";
|
|
10
|
-
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
11
12
|
const dev = async (api, options, devServerOptions = {}) => {
|
|
12
13
|
var _normalizedConfig_source, _normalizedConfig_tools;
|
|
13
14
|
if (options.analyze) {
|
|
@@ -29,12 +30,14 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
|
29
30
|
configFile: serverConfigFile,
|
|
30
31
|
watch: true
|
|
31
32
|
});
|
|
33
|
+
const meta = getMeta(metaName);
|
|
34
|
+
const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
32
35
|
await hookRunners.beforeDev();
|
|
33
36
|
if (!appContext.builder && !apiOnly) {
|
|
34
37
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
35
38
|
}
|
|
36
39
|
await generateRoutes(appContext);
|
|
37
|
-
const
|
|
40
|
+
const pluginInstances = await loadServerPlugins(api, appDirectory);
|
|
38
41
|
const serverOptions = {
|
|
39
42
|
metaName,
|
|
40
43
|
dev: {
|
|
@@ -49,16 +52,17 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
|
49
52
|
lambdaDirectory: appContext.lambdaDirectory,
|
|
50
53
|
sharedDirectory: appContext.sharedDirectory
|
|
51
54
|
},
|
|
55
|
+
serverConfigPath,
|
|
52
56
|
routes: serverRoutes,
|
|
53
57
|
pwd: appDirectory,
|
|
54
58
|
config: normalizedConfig,
|
|
55
59
|
serverConfigFile,
|
|
56
|
-
|
|
60
|
+
plugins: pluginInstances,
|
|
57
61
|
...devServerOptions
|
|
58
62
|
};
|
|
59
63
|
if (apiOnly) {
|
|
60
64
|
var _normalizedConfig_dev;
|
|
61
|
-
const app = await createDevServer(serverOptions,
|
|
65
|
+
const app = await createDevServer(serverOptions, applyPlugins);
|
|
62
66
|
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
63
67
|
app.listen({
|
|
64
68
|
port,
|
|
@@ -69,7 +73,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
|
69
73
|
} else {
|
|
70
74
|
const { server } = await appContext.builder.startDevServer({
|
|
71
75
|
serverOptions,
|
|
72
|
-
|
|
76
|
+
applyPlugins
|
|
73
77
|
});
|
|
74
78
|
setServer(server);
|
|
75
79
|
}
|
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { newAction, upgradeAction } from "@modern-js/utils";
|
|
2
|
+
import { castArray } from "@rsbuild/shared";
|
|
3
|
+
import { i18n, localeKeys } from "../locale";
|
|
4
|
+
const devCommand = async (program, api) => {
|
|
5
|
+
const runner = api.useHookRunners();
|
|
6
|
+
const devToolMetas = await runner.registerDev();
|
|
7
|
+
const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
8
|
+
const { dev } = await import("./dev");
|
|
9
|
+
await dev(api, options);
|
|
10
|
+
});
|
|
11
|
+
for (const meta of devToolMetas) {
|
|
12
|
+
if (!meta.subCommands) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
for (const subCmd of meta.subCommands) {
|
|
16
|
+
devProgram.command(subCmd).action(async (options = {}) => {
|
|
17
|
+
const { appDirectory } = api.useAppContext();
|
|
18
|
+
const { isTypescript } = await import("@modern-js/utils");
|
|
19
|
+
await runner.beforeDevTask(meta);
|
|
20
|
+
await meta.action(options, {
|
|
21
|
+
isTsProject: isTypescript(appDirectory)
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const buildCommand = async (program, api) => {
|
|
28
|
+
const runner = api.useHookRunners();
|
|
29
|
+
const platformBuilders = await runner.registerBuildPlatform();
|
|
30
|
+
const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
|
|
31
|
+
const { build } = await import("./build");
|
|
32
|
+
await build(api, options);
|
|
33
|
+
});
|
|
34
|
+
for (const platformBuilder of platformBuilders) {
|
|
35
|
+
const platforms = castArray(platformBuilder.platform);
|
|
36
|
+
for (const platform of platforms) {
|
|
37
|
+
buildProgram.command(platform).action(async () => {
|
|
38
|
+
const { appDirectory } = api.useAppContext();
|
|
39
|
+
const { isTypescript } = await import("@modern-js/utils");
|
|
40
|
+
await runner.beforeBuildPlatform(platformBuilders);
|
|
41
|
+
await platformBuilder.build(platform, {
|
|
42
|
+
isTsProject: isTypescript(appDirectory)
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const serverCommand = (program, api) => {
|
|
49
|
+
program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
|
|
50
|
+
const { start } = await import("./serve");
|
|
51
|
+
await start(api);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const deployCommand = (program, api) => {
|
|
55
|
+
program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options) => {
|
|
56
|
+
if (!options.skipBuild) {
|
|
57
|
+
const { build } = await import("./build");
|
|
58
|
+
await build(api);
|
|
59
|
+
}
|
|
60
|
+
const { deploy } = await import("./deploy");
|
|
61
|
+
await deploy(api, options);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const newCommand = (program, locale) => {
|
|
66
|
+
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--config-file <configFile>", i18n.t(localeKeys.command.shared.config)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)).action(async (options) => {
|
|
67
|
+
await newAction({
|
|
68
|
+
...options,
|
|
69
|
+
locale: options.lang || locale
|
|
70
|
+
}, "mwa");
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const inspectCommand = (program, api) => {
|
|
74
|
+
program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options) => {
|
|
75
|
+
const { inspect } = await import("./inspect");
|
|
76
|
+
inspect(api, options);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const upgradeCommand = (program) => {
|
|
80
|
+
program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(async () => {
|
|
81
|
+
await upgradeAction();
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export {
|
|
85
|
+
buildCommand,
|
|
86
|
+
deployCommand,
|
|
87
|
+
devCommand,
|
|
88
|
+
inspectCommand,
|
|
89
|
+
newCommand,
|
|
90
|
+
serverCommand,
|
|
91
|
+
upgradeCommand
|
|
92
|
+
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { logger, isApiOnly, getTargetDir, getMeta, SERVER_DIR } from "@modern-js/utils";
|
|
2
3
|
import { createProdServer } from "@modern-js/prod-server";
|
|
3
4
|
import { printInstructions } from "../utils/printInstructions";
|
|
4
|
-
import {
|
|
5
|
+
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
5
6
|
const start = async (api) => {
|
|
6
7
|
var _userConfig_source, _userConfig_output_distPath;
|
|
7
8
|
const appContext = api.useAppContext();
|
|
8
9
|
const userConfig = api.useResolvedConfigContext();
|
|
9
10
|
const hookRunners = api.useHookRunners();
|
|
10
|
-
const { distDirectory, appDirectory, port,
|
|
11
|
+
const { distDirectory, appDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
|
|
11
12
|
logger.info(`Starting production server...`);
|
|
12
13
|
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
|
13
14
|
let runMode;
|
|
14
15
|
if (apiOnly) {
|
|
15
16
|
runMode = "apiOnly";
|
|
16
17
|
}
|
|
17
|
-
const
|
|
18
|
+
const meta = getMeta(metaName);
|
|
19
|
+
const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
|
|
20
|
+
const pluginInstances = await loadServerPlugins(api, appDirectory);
|
|
18
21
|
const app = await createProdServer({
|
|
19
22
|
metaName,
|
|
20
23
|
pwd: distDirectory,
|
|
@@ -27,14 +30,15 @@ const start = async (api) => {
|
|
|
27
30
|
}
|
|
28
31
|
},
|
|
29
32
|
routes: serverRoutes,
|
|
33
|
+
plugins: pluginInstances,
|
|
34
|
+
serverConfigFile,
|
|
35
|
+
serverConfigPath,
|
|
30
36
|
appContext: {
|
|
31
37
|
appDirectory,
|
|
32
38
|
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
33
39
|
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
34
40
|
lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
|
35
41
|
},
|
|
36
|
-
serverConfigFile,
|
|
37
|
-
internalPlugins: serverInternalPlugins,
|
|
38
42
|
runMode
|
|
39
43
|
});
|
|
40
44
|
app.listen(port, async () => {
|
package/dist/esm-node/hooks.js
CHANGED
|
@@ -7,10 +7,15 @@ const hooks = {
|
|
|
7
7
|
modifyAsyncEntry: createAsyncWaterfall(),
|
|
8
8
|
modifyFileSystemRoutes: createAsyncWaterfall(),
|
|
9
9
|
modifyServerRoutes: createAsyncWaterfall(),
|
|
10
|
+
/** add entry point info to entrypoints array */
|
|
11
|
+
modifyEntrypoints: createAsyncWaterfall(),
|
|
12
|
+
/** add entry type */
|
|
13
|
+
checkEntryPoint: createAsyncWaterfall(),
|
|
10
14
|
htmlPartials: createAsyncWaterfall(),
|
|
11
15
|
beforeGenerateRoutes: createAsyncWaterfall(),
|
|
12
16
|
addDefineTypes: createAsyncWaterfall(),
|
|
13
17
|
collectServerPlugins: createAsyncWaterfall(),
|
|
18
|
+
_internalServerPlugins: createAsyncWaterfall(),
|
|
14
19
|
beforeDev: createAsyncWorkflow(),
|
|
15
20
|
afterDev: createAsyncWorkflow(),
|
|
16
21
|
beforeCreateCompiler: createAsyncWorkflow(),
|
package/dist/esm-node/index.js
CHANGED
|
@@ -1,64 +1,20 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { lintPlugin } from "@modern-js/plugin-lint";
|
|
3
|
-
import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE
|
|
4
|
-
import { castArray } from "@modern-js/utils/lodash";
|
|
3
|
+
import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
5
4
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { hooks } from "./hooks";
|
|
9
|
-
import { i18n, localeKeys } from "./locale";
|
|
5
|
+
import initializePlugin from "./plugins/initialize";
|
|
6
|
+
import analyzePlugin from "./plugins/analyze";
|
|
10
7
|
import serverBuildPlugin from "./plugins/serverBuild";
|
|
11
8
|
import deployPlugin from "./plugins/deploy";
|
|
9
|
+
import { hooks } from "./hooks";
|
|
10
|
+
import { i18n } from "./locale";
|
|
12
11
|
import { restart } from "./utils/restart";
|
|
13
12
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
13
|
+
import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
|
|
14
|
+
import { dev } from "./commands/dev";
|
|
14
15
|
import { mergeConfig } from "@modern-js/core";
|
|
15
|
-
import { dev } from "./commands";
|
|
16
16
|
export * from "./defineConfig";
|
|
17
17
|
export * from "./types";
|
|
18
|
-
const devCommand = async (program, api) => {
|
|
19
|
-
const runner = api.useHookRunners();
|
|
20
|
-
const devToolMetas = await runner.registerDev();
|
|
21
|
-
const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
22
|
-
const { dev: dev2 } = await import("./commands/dev");
|
|
23
|
-
await dev2(api, options);
|
|
24
|
-
});
|
|
25
|
-
for (const meta of devToolMetas) {
|
|
26
|
-
if (!meta.subCommands) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
for (const subCmd of meta.subCommands) {
|
|
30
|
-
devProgram.command(subCmd).action(async (options = {}) => {
|
|
31
|
-
const { appDirectory } = api.useAppContext();
|
|
32
|
-
const { isTypescript } = await import("@modern-js/utils");
|
|
33
|
-
await runner.beforeDevTask(meta);
|
|
34
|
-
await meta.action(options, {
|
|
35
|
-
isTsProject: isTypescript(appDirectory)
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const buildCommand = async (program, api) => {
|
|
42
|
-
const runner = api.useHookRunners();
|
|
43
|
-
const platformBuilders = await runner.registerBuildPlatform();
|
|
44
|
-
const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
|
|
45
|
-
const { build } = await import("./commands/build");
|
|
46
|
-
await build(api, options);
|
|
47
|
-
});
|
|
48
|
-
for (const platformBuilder of platformBuilders) {
|
|
49
|
-
const platforms = castArray(platformBuilder.platform);
|
|
50
|
-
for (const platform of platforms) {
|
|
51
|
-
buildProgram.command(platform).action(async () => {
|
|
52
|
-
const { appDirectory } = api.useAppContext();
|
|
53
|
-
const { isTypescript } = await import("@modern-js/utils");
|
|
54
|
-
await runner.beforeBuildPlatform(platformBuilders);
|
|
55
|
-
await platformBuilder.build(platform, {
|
|
56
|
-
isTsProject: isTypescript(appDirectory)
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
18
|
const appTools = (options = {
|
|
63
19
|
bundler: "webpack"
|
|
64
20
|
}) => ({
|
|
@@ -111,32 +67,11 @@ const appTools = (options = {
|
|
|
111
67
|
async commands({ program }) {
|
|
112
68
|
await devCommand(program, api);
|
|
113
69
|
await buildCommand(program, api);
|
|
114
|
-
program
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
program
|
|
119
|
-
if (!options2.skipBuild) {
|
|
120
|
-
const { build } = await import("./commands/build");
|
|
121
|
-
await build(api);
|
|
122
|
-
}
|
|
123
|
-
const { deploy } = await import("./commands/deploy");
|
|
124
|
-
await deploy(api, options2);
|
|
125
|
-
process.exit(0);
|
|
126
|
-
});
|
|
127
|
-
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--config-file <configFile>", i18n.t(localeKeys.command.shared.config)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
|
|
128
|
-
await newAction({
|
|
129
|
-
...options2,
|
|
130
|
-
locale: options2.lang || locale
|
|
131
|
-
}, "mwa");
|
|
132
|
-
});
|
|
133
|
-
program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options2) => {
|
|
134
|
-
const { inspect } = await import("./commands/inspect");
|
|
135
|
-
inspect(api, options2);
|
|
136
|
-
});
|
|
137
|
-
program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(async () => {
|
|
138
|
-
await upgradeAction();
|
|
139
|
-
});
|
|
70
|
+
serverCommand(program, api);
|
|
71
|
+
deployCommand(program, api);
|
|
72
|
+
newCommand(program, locale);
|
|
73
|
+
inspectCommand(program, api);
|
|
74
|
+
upgradeCommand(program);
|
|
140
75
|
},
|
|
141
76
|
async prepare() {
|
|
142
77
|
const command = getCommand();
|
|
@@ -199,9 +134,7 @@ const appTools = (options = {
|
|
|
199
134
|
var src_default = appTools;
|
|
200
135
|
export {
|
|
201
136
|
appTools,
|
|
202
|
-
buildCommand,
|
|
203
137
|
src_default as default,
|
|
204
138
|
dev,
|
|
205
|
-
devCommand,
|
|
206
139
|
mergeConfig
|
|
207
140
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const INDEX_FILE_NAME = "index";
|
|
2
|
+
const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
3
|
+
const ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
4
|
+
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
5
|
+
const HTML_PARTIALS_FOLDER = "html";
|
|
6
|
+
const HTML_PARTIALS_EXTENSIONS = [
|
|
7
|
+
".htm",
|
|
8
|
+
".html",
|
|
9
|
+
".ejs"
|
|
10
|
+
];
|
|
11
|
+
const APP_CONFIG_NAME = "config";
|
|
12
|
+
const APP_INIT_EXPORTED = "init";
|
|
13
|
+
const APP_INIT_IMPORTED = "appInit";
|
|
14
|
+
export {
|
|
15
|
+
APP_CONFIG_NAME,
|
|
16
|
+
APP_INIT_EXPORTED,
|
|
17
|
+
APP_INIT_IMPORTED,
|
|
18
|
+
ENTRY_BOOTSTRAP_FILE_NAME,
|
|
19
|
+
ENTRY_POINT_FILE_NAME,
|
|
20
|
+
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
21
|
+
HTML_PARTIALS_EXTENSIONS,
|
|
22
|
+
HTML_PARTIALS_FOLDER,
|
|
23
|
+
INDEX_FILE_NAME
|
|
24
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, getEntryOptions,
|
|
2
|
+
import { findExists, fs, getEntryOptions, JS_EXTENSIONS, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
|
|
3
3
|
import * as templates from "./templates";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getDefaultImports, getServerLoadersFile, getServerCombinedModueFile } from "./utils";
|
|
7
|
-
import { walk } from "./nestedRoutes";
|
|
4
|
+
import { ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
5
|
+
import { getDefaultImports } from "./utils";
|
|
8
6
|
const createImportSpecifier = (specifiers) => {
|
|
9
7
|
let defaults = "";
|
|
10
8
|
const named = [];
|
|
@@ -50,92 +48,17 @@ ${initialize || ""}`);
|
|
|
50
48
|
${initialize || ""}`).join("\n");
|
|
51
49
|
};
|
|
52
50
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
53
|
-
const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias,
|
|
51
|
+
const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile } = appContext;
|
|
54
52
|
const hookRunners = api.useHookRunners();
|
|
55
|
-
const
|
|
56
|
-
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
53
|
+
const customRuntimeConfig = findExists(JS_EXTENSIONS.map((ext) => path.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
|
|
57
54
|
const importsStatemets = /* @__PURE__ */ new Map();
|
|
58
|
-
|
|
59
|
-
await Promise.all(entrypoints.map(generateEntryCode));
|
|
55
|
+
await Promise.all(entrypoints.map((entrypoint) => generateEntryCode(entrypoint, customRuntimeConfig)));
|
|
60
56
|
return {
|
|
61
57
|
importsStatemets
|
|
62
58
|
};
|
|
63
|
-
async function generateEntryCode(entrypoint) {
|
|
64
|
-
const { entryName,
|
|
59
|
+
async function generateEntryCode(entrypoint, customRuntimeConfig2) {
|
|
60
|
+
const { entryName, isAutoMount } = entrypoint;
|
|
65
61
|
if (isAutoMount) {
|
|
66
|
-
if (fileSystemRoutes) {
|
|
67
|
-
var _config_output;
|
|
68
|
-
let initialRoutes = [];
|
|
69
|
-
let nestedRoutes = null;
|
|
70
|
-
if (entrypoint.entry) {
|
|
71
|
-
initialRoutes = getRoutes({
|
|
72
|
-
entrypoint,
|
|
73
|
-
srcDirectory,
|
|
74
|
-
srcAlias: internalSrcAlias,
|
|
75
|
-
internalDirectory,
|
|
76
|
-
internalDirAlias
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
if (!isV5 && entrypoint.nestedRoutesEntry) {
|
|
80
|
-
nestedRoutes = await walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
81
|
-
name: internalSrcAlias,
|
|
82
|
-
basename: srcDirectory
|
|
83
|
-
}, entrypoint.entryName, entrypoint.isMainEntry, oldVersion);
|
|
84
|
-
if (nestedRoutes) {
|
|
85
|
-
if (!Array.isArray(nestedRoutes)) {
|
|
86
|
-
nestedRoutes = [
|
|
87
|
-
nestedRoutes
|
|
88
|
-
];
|
|
89
|
-
}
|
|
90
|
-
for (const route of nestedRoutes) {
|
|
91
|
-
initialRoutes.unshift(route);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
96
|
-
entrypoint,
|
|
97
|
-
routes: initialRoutes
|
|
98
|
-
});
|
|
99
|
-
const config2 = api.useResolvedConfigContext();
|
|
100
|
-
const ssr = getEntryOptions(entryName, isMainEntry, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
101
|
-
const useSSG = isSSGEntry(config2, entryName, entrypoints);
|
|
102
|
-
let mode;
|
|
103
|
-
if (ssr) {
|
|
104
|
-
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
105
|
-
}
|
|
106
|
-
if (mode === "stream") {
|
|
107
|
-
const hasPageRoute = routes.some((route) => "type" in route && route.type === "page");
|
|
108
|
-
if (hasPageRoute) {
|
|
109
|
-
logger.error("Streaming ssr is not supported when pages dir exists");
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const { code } = await hookRunners.beforeGenerateRoutes({
|
|
114
|
-
entrypoint,
|
|
115
|
-
code: await templates.fileSystemRoutes({
|
|
116
|
-
routes,
|
|
117
|
-
ssrMode: useSSG ? "string" : mode,
|
|
118
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
119
|
-
entryName: entrypoint.entryName,
|
|
120
|
-
internalDirectory,
|
|
121
|
-
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
122
|
-
})
|
|
123
|
-
});
|
|
124
|
-
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
|
|
125
|
-
const routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
126
|
-
const code2 = templates.routesForServer({
|
|
127
|
-
routes
|
|
128
|
-
});
|
|
129
|
-
await fs.ensureFile(routesServerFile);
|
|
130
|
-
await fs.writeFile(routesServerFile, code2);
|
|
131
|
-
}
|
|
132
|
-
const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
133
|
-
if (serverLoaderCombined) {
|
|
134
|
-
const serverLoaderFile = getServerCombinedModueFile(internalDirectory, entryName);
|
|
135
|
-
await fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
136
|
-
}
|
|
137
|
-
fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`), code, "utf8");
|
|
138
|
-
}
|
|
139
62
|
const { imports } = await hookRunners.modifyEntryImports({
|
|
140
63
|
entrypoint,
|
|
141
64
|
imports: getDefaultImports({
|
|
@@ -143,7 +66,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
143
66
|
srcDirectory,
|
|
144
67
|
appDirectory,
|
|
145
68
|
internalSrcAlias,
|
|
146
|
-
internalDirAlias
|
|
69
|
+
internalDirAlias,
|
|
70
|
+
runtimeConfigFile,
|
|
71
|
+
customRuntimeConfig: customRuntimeConfig2
|
|
147
72
|
})
|
|
148
73
|
});
|
|
149
74
|
importsStatemets.set(entryName, imports);
|
|
@@ -155,7 +80,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
155
80
|
const generateIndexCode = async ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs }) => {
|
|
156
81
|
const hookRunners = api.useHookRunners();
|
|
157
82
|
const { mountId } = config.html;
|
|
158
|
-
const { internalDirectory, packageName } = appContext;
|
|
83
|
+
const { internalDirectory, packageName, srcDirectory, runtimeConfigFile } = appContext;
|
|
84
|
+
const customRuntimeConfig = findExists(JS_EXTENSIONS.map((ext) => path.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
|
|
159
85
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
160
86
|
const { entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
|
161
87
|
if (isAutoMount) {
|
|
@@ -169,6 +95,7 @@ const generateIndexCode = async ({ appContext, api, entrypoints, config, imports
|
|
|
169
95
|
code: templates.renderFunction({
|
|
170
96
|
plugins,
|
|
171
97
|
customBootstrap,
|
|
98
|
+
customRuntimeConfig,
|
|
172
99
|
fileSystemRoutes
|
|
173
100
|
})
|
|
174
101
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME,
|
|
2
|
+
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME, JS_EXTENSIONS } from "@modern-js/utils";
|
|
3
3
|
import { getFileSystemEntry } from "./getFileSystemEntry";
|
|
4
|
-
import { JS_EXTENSIONS } from "./constants";
|
|
5
4
|
import { isSubDirOrEqual } from "./utils";
|
|
6
5
|
const ensureExtensions = (file) => {
|
|
7
6
|
if (!path.extname(file)) {
|
|
@@ -23,32 +22,24 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
|
|
|
23
22
|
}
|
|
24
23
|
return false;
|
|
25
24
|
});
|
|
26
|
-
const getBundleEntry = (appContext, config) => {
|
|
25
|
+
const getBundleEntry = async (hookRunners, appContext, config) => {
|
|
27
26
|
const { appDirectory, packageName } = appContext;
|
|
28
27
|
const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
|
|
29
|
-
const defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
|
|
28
|
+
const defaults = disableDefaultEntries ? [] : await getFileSystemEntry(hookRunners, appContext, config);
|
|
30
29
|
if (entries) {
|
|
31
30
|
Object.keys(entries).forEach((name) => {
|
|
32
31
|
const value = entries[name];
|
|
33
|
-
const
|
|
32
|
+
const entryName = typeof value === "string" ? value : value.entry;
|
|
33
|
+
const isAutoMount = typeof value === "string" ? true : !value.disableMount;
|
|
34
|
+
const entrypoint = {
|
|
34
35
|
entryName: name,
|
|
35
36
|
isMainEntry: false,
|
|
36
|
-
entry: ensureAbsolutePath(appDirectory,
|
|
37
|
-
absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory,
|
|
38
|
-
isAutoMount
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
entryName: name,
|
|
42
|
-
isMainEntry: false,
|
|
43
|
-
entry: ensureAbsolutePath(appDirectory, value.entry),
|
|
44
|
-
absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, value.entry)) ? ensureAbsolutePath(appDirectory, value.entry) : path.dirname(ensureAbsolutePath(appDirectory, value.entry)),
|
|
45
|
-
isAutoMount: !value.disableMount,
|
|
46
|
-
customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
|
47
|
-
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
37
|
+
entry: ensureAbsolutePath(appDirectory, entryName),
|
|
38
|
+
absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, entryName)) ? ensureAbsolutePath(appDirectory, entryName) : path.dirname(ensureAbsolutePath(appDirectory, entryName)),
|
|
39
|
+
isAutoMount,
|
|
40
|
+
customBootstrap: typeof value === "string" ? false : value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
|
41
|
+
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0
|
|
48
42
|
};
|
|
49
|
-
if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
|
|
50
|
-
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
51
|
-
}
|
|
52
43
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
53
44
|
defaults.push(entrypoint);
|
|
54
45
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { findExists, ensureAbsolutePath, JS_EXTENSIONS } from "@modern-js/utils";
|
|
4
|
+
import { INDEX_FILE_NAME } from "./constants";
|
|
5
|
+
import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
|
6
|
+
const hasIndex = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
|
|
7
|
+
const isBundleEntry = async (hookRunners, dir) => {
|
|
8
|
+
return (await hookRunners.checkEntryPoint({
|
|
9
|
+
path: dir,
|
|
10
|
+
entry: false
|
|
11
|
+
})).entry || hasIndex(dir);
|
|
12
|
+
};
|
|
13
|
+
const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
|
|
14
|
+
const indexFile = hasIndex(dir);
|
|
15
|
+
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
|
16
|
+
const entryName = path.basename(dir);
|
|
17
|
+
if (indexFile && !customBootstrap) {
|
|
18
|
+
return {
|
|
19
|
+
entryName,
|
|
20
|
+
isMainEntry: false,
|
|
21
|
+
entry: indexFile,
|
|
22
|
+
absoluteEntryDir: path.resolve(dir),
|
|
23
|
+
isAutoMount: false,
|
|
24
|
+
customBootstrap
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const entryFile = (await hookRunners.checkEntryPoint({
|
|
28
|
+
path: dir,
|
|
29
|
+
entry: false
|
|
30
|
+
})).entry;
|
|
31
|
+
if (entryFile) {
|
|
32
|
+
return {
|
|
33
|
+
entryName,
|
|
34
|
+
isMainEntry: false,
|
|
35
|
+
entry: entryFile,
|
|
36
|
+
absoluteEntryDir: path.resolve(dir),
|
|
37
|
+
isAutoMount: true,
|
|
38
|
+
customBootstrap
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
throw Error("There is no valid entry point in the current project!");
|
|
42
|
+
}));
|
|
43
|
+
const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
|
44
|
+
const { appDirectory } = appContext;
|
|
45
|
+
const { source: { entriesDir, disableEntryDirs } } = config;
|
|
46
|
+
let disabledDirs = [];
|
|
47
|
+
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
48
|
+
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
|
|
49
|
+
}
|
|
50
|
+
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
|
51
|
+
if (fs.existsSync(src)) {
|
|
52
|
+
if (fs.statSync(src).isDirectory()) {
|
|
53
|
+
if (await isBundleEntry(hookRunners, src)) {
|
|
54
|
+
return scanDir(hookRunners, [
|
|
55
|
+
src
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
const dirs = [];
|
|
59
|
+
await Promise.all(fs.readdirSync(src).map(async (filename) => {
|
|
60
|
+
const file = path.join(src, filename);
|
|
61
|
+
if (fs.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file) && !disabledDirs.includes(file)) {
|
|
62
|
+
dirs.push(file);
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
return scanDir(hookRunners, dirs);
|
|
66
|
+
} else {
|
|
67
|
+
throw Error(`source.entriesDir accept a directory.`);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
throw Error(`src dir ${entriesDir} not found.`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
getFileSystemEntry
|
|
75
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
4
|
-
import { isMainEntry } from "
|
|
4
|
+
import { isMainEntry } from "../../utils/routes";
|
|
5
5
|
import { walkDirectory } from "./utils";
|
|
6
6
|
const applyBaseUrl = (baseUrl, routes) => {
|
|
7
7
|
if (baseUrl) {
|