@modern-js/app-tools 2.58.2 → 2.59.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -3
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
- package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/cjs/commands/build.js +2 -2
- package/dist/cjs/commands/dev.js +6 -5
- package/dist/cjs/commands/index.js +1 -1
- package/dist/cjs/commands/serve.js +4 -3
- package/dist/cjs/config/legacy/index.js +3 -3
- package/dist/cjs/esm/register-esm.mjs +2 -3
- package/dist/cjs/esm/utils.mjs +2 -2
- package/dist/cjs/index.js +17 -10
- package/dist/cjs/locale/index.js +1 -1
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
- package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
- package/dist/cjs/plugins/analyze/index.js +6 -6
- package/dist/cjs/plugins/analyze/utils.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
- package/dist/cjs/plugins/deploy/index.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +2 -2
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
- package/dist/esm/builder/builder-rspack/index.js +34 -0
- package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
- package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
- package/dist/esm/builder/builder-webpack/index.js +52 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
- package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
- package/dist/esm/builder/generator/index.js +93 -0
- package/dist/esm/builder/index.js +45 -0
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
- package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm/builder/shared/types.js +0 -0
- package/dist/esm/commands/build.js +140 -0
- package/dist/esm/commands/deploy.js +48 -0
- package/dist/esm/commands/dev.js +193 -0
- package/dist/esm/commands/index.js +411 -0
- package/dist/esm/commands/inspect.js +28 -0
- package/dist/esm/commands/serve.js +94 -0
- package/dist/esm/config/default.js +190 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +9 -0
- package/dist/esm/config/initialize/inits.js +89 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm/config/legacy/createSourceConfig.js +46 -0
- package/dist/esm/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm/config/legacy/index.js +43 -0
- package/dist/esm/defineConfig.js +16 -0
- package/dist/esm/esm/esbuild-loader.mjs +20 -0
- package/dist/esm/esm/register-esm.mjs +66 -0
- package/dist/esm/esm/ts-node-loader.mjs +21 -0
- package/dist/esm/esm/utils.mjs +43 -0
- package/dist/esm/exports/server.js +4 -0
- package/dist/esm/hooks.js +34 -0
- package/dist/esm/index.js +246 -0
- package/dist/esm/locale/en.js +43 -0
- package/dist/esm/locale/index.js +12 -0
- package/dist/esm/locale/zh.js +43 -0
- package/dist/esm/plugins/analyze/constants.js +14 -0
- package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
- package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm/plugins/analyze/index.js +380 -0
- package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
- package/dist/esm/plugins/analyze/templates.js +6 -0
- package/dist/esm/plugins/analyze/utils.js +101 -0
- package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
- package/dist/esm/plugins/deploy/exports.js +4 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
- package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
- package/dist/esm/plugins/deploy/platforms/node.js +161 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/plugins/initialize/index.js +119 -0
- package/dist/esm/plugins/serverBuild.js +87 -0
- package/dist/esm/types/config/deploy.js +0 -0
- package/dist/esm/types/config/dev.js +0 -0
- package/dist/esm/types/config/experiments.js +0 -0
- package/dist/esm/types/config/html.js +0 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +0 -0
- package/dist/esm/types/config/performance.js +0 -0
- package/dist/esm/types/config/security.js +0 -0
- package/dist/esm/types/config/source.js +0 -0
- package/dist/esm/types/config/testing.js +0 -0
- package/dist/esm/types/config/tools.js +0 -0
- package/dist/esm/types/hooks.js +0 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +0 -0
- package/dist/esm/types/legacyConfig/dev.js +0 -0
- package/dist/esm/types/legacyConfig/index.js +0 -0
- package/dist/esm/types/legacyConfig/output.js +0 -0
- package/dist/esm/types/legacyConfig/source.js +0 -0
- package/dist/esm/types/legacyConfig/testing.js +0 -0
- package/dist/esm/types/legacyConfig/tools.js +0 -0
- package/dist/esm/types/utils.js +0 -0
- package/dist/esm/utils/config.js +122 -0
- package/dist/esm/utils/createServer.js +58 -0
- package/dist/esm/utils/env.js +16 -0
- package/dist/esm/utils/generateWatchFiles.js +71 -0
- package/dist/esm/utils/getSelectedEntries.js +67 -0
- package/dist/esm/utils/loadPlugins.js +74 -0
- package/dist/esm/utils/printInstructions.js +32 -0
- package/dist/esm/utils/register.js +188 -0
- package/dist/esm/utils/restart.js +67 -0
- package/dist/esm/utils/routes.js +42 -0
- package/dist/esm/utils/types.js +0 -0
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
- package/dist/esm-node/builder/builder-rspack/index.js +12 -0
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
- package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +20 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
- package/dist/esm-node/builder/generator/index.js +36 -0
- package/dist/esm-node/builder/index.js +11 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/createCopyInfo.js +14 -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 +64 -0
- package/dist/esm-node/commands/deploy.js +12 -0
- package/dist/esm-node/commands/dev.js +105 -0
- package/dist/esm-node/commands/index.js +92 -0
- package/dist/esm-node/commands/inspect.js +15 -0
- package/dist/esm-node/commands/serve.js +52 -0
- package/dist/esm-node/config/default.js +197 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +9 -0
- package/dist/esm-node/config/initialize/inits.js +79 -0
- package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm-node/config/legacy/index.js +43 -0
- package/dist/esm-node/defineConfig.js +13 -0
- package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
- package/dist/esm-node/esm/register-esm.mjs +66 -0
- package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
- package/dist/esm-node/esm/utils.mjs +43 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +34 -0
- package/dist/esm-node/index.js +131 -0
- package/dist/esm-node/locale/en.js +43 -0
- package/dist/esm-node/locale/index.js +12 -0
- package/dist/esm-node/locale/zh.js +43 -0
- package/dist/esm-node/plugins/analyze/constants.js +14 -0
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm-node/plugins/analyze/index.js +166 -0
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm-node/plugins/analyze/templates.js +24 -0
- package/dist/esm-node/plugins/analyze/utils.js +68 -0
- package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
- package/dist/esm-node/plugins/deploy/exports.js +4 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
- package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/plugins/initialize/index.js +84 -0
- package/dist/esm-node/plugins/serverBuild.js +58 -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/testing.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/testing.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 +49 -0
- package/dist/esm-node/utils/createServer.js +26 -0
- package/dist/esm-node/utils/env.js +16 -0
- package/dist/esm-node/utils/generateWatchFiles.js +30 -0
- package/dist/esm-node/utils/getSelectedEntries.js +34 -0
- package/dist/esm-node/utils/loadPlugins.js +22 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/register.js +96 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +21 -0
- package/dist/esm-node/utils/types.js +0 -0
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +2 -2
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
- package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +1 -1
- package/dist/types/commands/build.d.ts +1 -1
- package/dist/types/commands/dev.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/config/default.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
- package/dist/types/plugins/initialize/index.d.ts +1 -1
- package/dist/types/plugins/serverBuild.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +8 -8
- package/dist/types/types/config/output.d.ts +1 -1
- package/dist/types/types/config/tools.d.ts +3 -3
- package/dist/types/types/hooks.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/legacyConfig/index.d.ts +3 -3
- package/dist/types/types/legacyConfig/tools.d.ts +1 -1
- package/dist/types/utils/printInstructions.d.ts +1 -1
- package/package.json +20 -20
- package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
- package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,119 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
|
6
|
+
import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig, transformNormalizedConfig } from "../../config";
|
7
|
+
function initialize_default(param) {
|
8
|
+
var bundler = param.bundler;
|
9
|
+
return {
|
10
|
+
name: "@modern-js/plugin-initialize",
|
11
|
+
post: [
|
12
|
+
"@modern-js/plugin-ssr",
|
13
|
+
"@modern-js/plugin-document",
|
14
|
+
"@modern-js/plugin-state",
|
15
|
+
"@modern-js/plugin-router",
|
16
|
+
"@modern-js/plugin-router-v5",
|
17
|
+
"@modern-js/plugin-polyfill"
|
18
|
+
],
|
19
|
+
setup: function setup(api) {
|
20
|
+
var config = function() {
|
21
|
+
var appContext = api.useAppContext();
|
22
|
+
var userConfig = api.useConfigContext();
|
23
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
|
24
|
+
bundlerType: bundler
|
25
|
+
}));
|
26
|
+
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
|
27
|
+
};
|
28
|
+
return {
|
29
|
+
config,
|
30
|
+
resolvedConfig: function resolvedConfig(param2) {
|
31
|
+
var resolved = param2.resolved;
|
32
|
+
return _async_to_generator(function() {
|
33
|
+
var _resolved_output_distPath, appContext, userConfig, port, normalizedConfig, _normalizedConfig_autoLoadPlugins;
|
34
|
+
return _ts_generator(this, function(_state) {
|
35
|
+
switch (_state.label) {
|
36
|
+
case 0:
|
37
|
+
appContext = api.useAppContext();
|
38
|
+
userConfig = api.useConfigContext();
|
39
|
+
return [
|
40
|
+
4,
|
41
|
+
getServerPort(resolved)
|
42
|
+
];
|
43
|
+
case 1:
|
44
|
+
port = _state.sent();
|
45
|
+
appContext = _object_spread_props(_object_spread({}, appContext), {
|
46
|
+
port,
|
47
|
+
distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
48
|
+
});
|
49
|
+
api.setAppContext(appContext);
|
50
|
+
normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
51
|
+
resolved._raw = userConfig;
|
52
|
+
resolved.server = _object_spread_props(_object_spread({}, normalizedConfig.server || {}), {
|
53
|
+
port
|
54
|
+
});
|
55
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
56
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
57
|
+
"source",
|
58
|
+
"bff",
|
59
|
+
"dev",
|
60
|
+
"html",
|
61
|
+
"output",
|
62
|
+
"tools",
|
63
|
+
"testing",
|
64
|
+
"plugins",
|
65
|
+
"builderPlugins",
|
66
|
+
"runtime",
|
67
|
+
"runtimeByEntries",
|
68
|
+
"deploy",
|
69
|
+
"performance"
|
70
|
+
]);
|
71
|
+
if (bundler === "webpack") {
|
72
|
+
resolved.security = normalizedConfig.security || {};
|
73
|
+
resolved.experiments = normalizedConfig.experiments;
|
74
|
+
}
|
75
|
+
return [
|
76
|
+
2,
|
77
|
+
{
|
78
|
+
resolved
|
79
|
+
}
|
80
|
+
];
|
81
|
+
}
|
82
|
+
});
|
83
|
+
})();
|
84
|
+
}
|
85
|
+
};
|
86
|
+
}
|
87
|
+
};
|
88
|
+
}
|
89
|
+
;
|
90
|
+
function stabilizeConfig(resolve, config, keys) {
|
91
|
+
keys.forEach(function(key) {
|
92
|
+
resolve[key] = config[key] || {};
|
93
|
+
});
|
94
|
+
}
|
95
|
+
function getServerPort(config) {
|
96
|
+
return _getServerPort.apply(this, arguments);
|
97
|
+
}
|
98
|
+
function _getServerPort() {
|
99
|
+
_getServerPort = _async_to_generator(function(config) {
|
100
|
+
var prodPort;
|
101
|
+
return _ts_generator(this, function(_state) {
|
102
|
+
prodPort = Number(process.env.PORT) || config.server.port || 8080;
|
103
|
+
if (isDev() && isDevCommand()) {
|
104
|
+
return [
|
105
|
+
2,
|
106
|
+
getPort(Number(process.env.PORT) || config.dev.port || prodPort)
|
107
|
+
];
|
108
|
+
}
|
109
|
+
return [
|
110
|
+
2,
|
111
|
+
prodPort
|
112
|
+
];
|
113
|
+
});
|
114
|
+
});
|
115
|
+
return _getServerPort.apply(this, arguments);
|
116
|
+
}
|
117
|
+
export {
|
118
|
+
initialize_default as default
|
119
|
+
};
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import fs from "fs";
|
4
|
+
import path from "path";
|
5
|
+
import { compile } from "@modern-js/server-utils";
|
6
|
+
import { SERVER_DIR, SHARED_DIR, getMeta } from "@modern-js/utils";
|
7
|
+
var TS_CONFIG_FILENAME = "tsconfig.json";
|
8
|
+
function checkHasCache(appDir) {
|
9
|
+
var tsFilepath = path.resolve(appDir, SERVER_DIR, "cache.ts");
|
10
|
+
var jsfilepath = path.resolve(appDir, SERVER_DIR, "cache.js");
|
11
|
+
return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
|
12
|
+
}
|
13
|
+
function checkHasConfig(appDir) {
|
14
|
+
var metaName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "modern-js";
|
15
|
+
var meta = getMeta(metaName);
|
16
|
+
var tsFilepath = path.resolve(appDir, SERVER_DIR, "".concat(meta, ".server.ts"));
|
17
|
+
var jsfilepath = path.resolve(appDir, SERVER_DIR, "".concat(meta, ".server.js"));
|
18
|
+
return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
|
19
|
+
}
|
20
|
+
function serverBuild_default() {
|
21
|
+
return {
|
22
|
+
name: "@modern-js/server-build",
|
23
|
+
setup: function setup(api) {
|
24
|
+
return {
|
25
|
+
afterBuild: function afterBuild() {
|
26
|
+
return _async_to_generator(function() {
|
27
|
+
var _api_useAppContext, appDirectory, distDirectory, metaName, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
28
|
+
return _ts_generator(this, function(_state) {
|
29
|
+
switch (_state.label) {
|
30
|
+
case 0:
|
31
|
+
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, metaName = _api_useAppContext.metaName;
|
32
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
33
|
+
return [
|
34
|
+
2
|
35
|
+
];
|
36
|
+
}
|
37
|
+
modernConfig = api.useResolvedConfigContext();
|
38
|
+
distDir = path.resolve(distDirectory);
|
39
|
+
serverDir = path.resolve(appDirectory, SERVER_DIR);
|
40
|
+
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
41
|
+
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
42
|
+
sourceDirs = [];
|
43
|
+
if (fs.existsSync(serverDir)) {
|
44
|
+
sourceDirs.push(serverDir);
|
45
|
+
if (fs.existsSync(sharedDir)) {
|
46
|
+
sourceDirs.push(sharedDir);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
server = modernConfig.server;
|
50
|
+
alias = modernConfig.source.alias;
|
51
|
+
babel = modernConfig.tools.babel;
|
52
|
+
if (!(sourceDirs.length > 0))
|
53
|
+
return [
|
54
|
+
3,
|
55
|
+
2
|
56
|
+
];
|
57
|
+
return [
|
58
|
+
4,
|
59
|
+
compile(appDirectory, {
|
60
|
+
server,
|
61
|
+
alias,
|
62
|
+
babelConfig: babel
|
63
|
+
}, {
|
64
|
+
sourceDirs,
|
65
|
+
distDir,
|
66
|
+
tsconfigPath
|
67
|
+
})
|
68
|
+
];
|
69
|
+
case 1:
|
70
|
+
_state.sent();
|
71
|
+
_state.label = 2;
|
72
|
+
case 2:
|
73
|
+
return [
|
74
|
+
2
|
75
|
+
];
|
76
|
+
}
|
77
|
+
});
|
78
|
+
})();
|
79
|
+
}
|
80
|
+
};
|
81
|
+
}
|
82
|
+
};
|
83
|
+
}
|
84
|
+
;
|
85
|
+
export {
|
86
|
+
serverBuild_default as default
|
87
|
+
};
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./output";
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import * as path from "path";
|
6
|
+
import { bundle } from "@modern-js/node-bundle-require";
|
7
|
+
import { fs, CONFIG_FILE_EXTENSIONS, OUTPUT_CONFIG_FILE, ensureAbsolutePath, getServerConfig } from "@modern-js/utils";
|
8
|
+
import { stringify } from "flatted";
|
9
|
+
var defineServerConfig = function(config) {
|
10
|
+
return config;
|
11
|
+
};
|
12
|
+
var buildServerConfig = function() {
|
13
|
+
var _ref = _async_to_generator(function(param) {
|
14
|
+
var appDirectory, distDirectory, configFile, options, watch, configFilePath, getOutputFile, configHelperFilePath, helperCode;
|
15
|
+
return _ts_generator(this, function(_state) {
|
16
|
+
switch (_state.label) {
|
17
|
+
case 0:
|
18
|
+
appDirectory = param.appDirectory, distDirectory = param.distDirectory, configFile = param.configFile, options = param.options, watch = param.watch;
|
19
|
+
return [
|
20
|
+
4,
|
21
|
+
getServerConfig(appDirectory, configFile)
|
22
|
+
];
|
23
|
+
case 1:
|
24
|
+
configFilePath = _state.sent();
|
25
|
+
getOutputFile = function() {
|
26
|
+
var _ref2 = _async_to_generator(function(filepath) {
|
27
|
+
return _ts_generator(this, function(_state2) {
|
28
|
+
return [
|
29
|
+
2,
|
30
|
+
path.resolve(distDirectory, "".concat(filepath.replace(new RegExp(CONFIG_FILE_EXTENSIONS.join("|")), ""), ".cjs"))
|
31
|
+
];
|
32
|
+
});
|
33
|
+
});
|
34
|
+
return function getOutputFile2(filepath) {
|
35
|
+
return _ref2.apply(this, arguments);
|
36
|
+
};
|
37
|
+
}();
|
38
|
+
if (!configFilePath)
|
39
|
+
return [
|
40
|
+
3,
|
41
|
+
5
|
42
|
+
];
|
43
|
+
configHelperFilePath = path.normalize(path.join(distDirectory, "./config-helper.js"));
|
44
|
+
helperCode = "\n export const defineConfig = (config) => config;\n ";
|
45
|
+
return [
|
46
|
+
4,
|
47
|
+
fs.ensureDir(distDirectory)
|
48
|
+
];
|
49
|
+
case 2:
|
50
|
+
_state.sent();
|
51
|
+
return [
|
52
|
+
4,
|
53
|
+
fs.writeFile(configHelperFilePath, helperCode)
|
54
|
+
];
|
55
|
+
case 3:
|
56
|
+
_state.sent();
|
57
|
+
return [
|
58
|
+
4,
|
59
|
+
bundle(configFilePath, _object_spread_props(_object_spread({}, options), {
|
60
|
+
watch,
|
61
|
+
getOutputFile,
|
62
|
+
esbuildPlugins: [
|
63
|
+
{
|
64
|
+
name: "native-build-config",
|
65
|
+
setup: function setup(ctx) {
|
66
|
+
ctx.onResolve({
|
67
|
+
filter: /app-tools\/server/
|
68
|
+
}, function() {
|
69
|
+
return {
|
70
|
+
path: configHelperFilePath
|
71
|
+
};
|
72
|
+
});
|
73
|
+
}
|
74
|
+
}
|
75
|
+
]
|
76
|
+
}))
|
77
|
+
];
|
78
|
+
case 4:
|
79
|
+
_state.sent();
|
80
|
+
_state.label = 5;
|
81
|
+
case 5:
|
82
|
+
return [
|
83
|
+
2
|
84
|
+
];
|
85
|
+
}
|
86
|
+
});
|
87
|
+
});
|
88
|
+
return function buildServerConfig2(_) {
|
89
|
+
return _ref.apply(this, arguments);
|
90
|
+
};
|
91
|
+
}();
|
92
|
+
var emitResolvedConfig = function() {
|
93
|
+
var _ref = _async_to_generator(function(appDirectory, resolvedConfig) {
|
94
|
+
var _resolvedConfig_output_distPath, outputPath, output;
|
95
|
+
return _ts_generator(this, function(_state) {
|
96
|
+
switch (_state.label) {
|
97
|
+
case 0:
|
98
|
+
outputPath = ensureAbsolutePath(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE));
|
99
|
+
output = stringify(resolvedConfig);
|
100
|
+
return [
|
101
|
+
4,
|
102
|
+
fs.writeFile(outputPath, output, {
|
103
|
+
encoding: "utf-8"
|
104
|
+
})
|
105
|
+
];
|
106
|
+
case 1:
|
107
|
+
_state.sent();
|
108
|
+
return [
|
109
|
+
2
|
110
|
+
];
|
111
|
+
}
|
112
|
+
});
|
113
|
+
});
|
114
|
+
return function emitResolvedConfig2(appDirectory, resolvedConfig) {
|
115
|
+
return _ref.apply(this, arguments);
|
116
|
+
};
|
117
|
+
}();
|
118
|
+
export {
|
119
|
+
buildServerConfig,
|
120
|
+
defineServerConfig,
|
121
|
+
emitResolvedConfig
|
122
|
+
};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
4
|
+
import { createDevServer } from "@modern-js/server";
|
5
|
+
var server = null;
|
6
|
+
var getServer = function() {
|
7
|
+
return server;
|
8
|
+
};
|
9
|
+
var setServer = function(newServer) {
|
10
|
+
server = newServer;
|
11
|
+
};
|
12
|
+
var closeServer = function() {
|
13
|
+
var _ref = _async_to_generator(function() {
|
14
|
+
return _ts_generator(this, function(_state) {
|
15
|
+
if (server) {
|
16
|
+
server.close();
|
17
|
+
server = null;
|
18
|
+
}
|
19
|
+
return [
|
20
|
+
2
|
21
|
+
];
|
22
|
+
});
|
23
|
+
});
|
24
|
+
return function closeServer2() {
|
25
|
+
return _ref.apply(this, arguments);
|
26
|
+
};
|
27
|
+
}();
|
28
|
+
var createServer = function() {
|
29
|
+
var _ref = _async_to_generator(function(options) {
|
30
|
+
return _ts_generator(this, function(_state) {
|
31
|
+
switch (_state.label) {
|
32
|
+
case 0:
|
33
|
+
if (server) {
|
34
|
+
server.close();
|
35
|
+
}
|
36
|
+
return [
|
37
|
+
4,
|
38
|
+
createDevServer(options, applyPlugins)
|
39
|
+
];
|
40
|
+
case 1:
|
41
|
+
server = _state.sent().server;
|
42
|
+
return [
|
43
|
+
2,
|
44
|
+
server
|
45
|
+
];
|
46
|
+
}
|
47
|
+
});
|
48
|
+
});
|
49
|
+
return function createServer2(options) {
|
50
|
+
return _ref.apply(this, arguments);
|
51
|
+
};
|
52
|
+
}();
|
53
|
+
export {
|
54
|
+
closeServer,
|
55
|
+
createServer,
|
56
|
+
getServer,
|
57
|
+
setServer
|
58
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { cutNameByHyphen } from "@modern-js/utils/universal";
|
2
|
+
function getAutoInjectEnv(appContext) {
|
3
|
+
var metaName = appContext.metaName;
|
4
|
+
var prefix = "".concat(cutNameByHyphen(metaName), "_").toUpperCase();
|
5
|
+
var envReg = new RegExp("^".concat(prefix));
|
6
|
+
return Object.keys(process.env).reduce(function(prev, key) {
|
7
|
+
var value = process.env[key];
|
8
|
+
if (envReg.test(key) && typeof value !== "undefined") {
|
9
|
+
prev["process.env.".concat(key)] = value;
|
10
|
+
}
|
11
|
+
return prev;
|
12
|
+
}, {});
|
13
|
+
}
|
14
|
+
export {
|
15
|
+
getAutoInjectEnv
|
16
|
+
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
4
|
+
import path from "path";
|
5
|
+
import { fs, getServerConfig } from "@modern-js/utils";
|
6
|
+
var getPackageConfig = function(appDirectory, packageJsonConfig) {
|
7
|
+
var PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
8
|
+
var json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8"));
|
9
|
+
return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
10
|
+
};
|
11
|
+
var addServerConfigToDeps = function() {
|
12
|
+
var _ref = _async_to_generator(function(dependencies, appDirectory, serverConfigFile) {
|
13
|
+
var serverConfig;
|
14
|
+
return _ts_generator(this, function(_state) {
|
15
|
+
switch (_state.label) {
|
16
|
+
case 0:
|
17
|
+
return [
|
18
|
+
4,
|
19
|
+
getServerConfig(appDirectory, serverConfigFile)
|
20
|
+
];
|
21
|
+
case 1:
|
22
|
+
serverConfig = _state.sent();
|
23
|
+
if (serverConfig) {
|
24
|
+
dependencies.push(serverConfig);
|
25
|
+
}
|
26
|
+
return [
|
27
|
+
2
|
28
|
+
];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
return function addServerConfigToDeps2(dependencies, appDirectory, serverConfigFile) {
|
33
|
+
return _ref.apply(this, arguments);
|
34
|
+
};
|
35
|
+
}();
|
36
|
+
function generateWatchFiles(appContext, configDir) {
|
37
|
+
return _generateWatchFiles.apply(this, arguments);
|
38
|
+
}
|
39
|
+
function _generateWatchFiles() {
|
40
|
+
_generateWatchFiles = _async_to_generator(function(appContext, configDir) {
|
41
|
+
var appDirectory, configFile, configPath, dependencies;
|
42
|
+
return _ts_generator(this, function(_state) {
|
43
|
+
switch (_state.label) {
|
44
|
+
case 0:
|
45
|
+
appDirectory = appContext.appDirectory, configFile = appContext.configFile;
|
46
|
+
configPath = path.join(appDirectory, configDir || "");
|
47
|
+
dependencies = getPackageConfig(appContext.appDirectory, appContext.packageName) ? [
|
48
|
+
path.resolve(appDirectory, "./package.json")
|
49
|
+
] : [];
|
50
|
+
return [
|
51
|
+
4,
|
52
|
+
addServerConfigToDeps(dependencies, appContext.appDirectory, appContext.serverConfigFile)
|
53
|
+
];
|
54
|
+
case 1:
|
55
|
+
_state.sent();
|
56
|
+
return [
|
57
|
+
2,
|
58
|
+
[
|
59
|
+
"".concat(configPath, "/html"),
|
60
|
+
configFile || "./config"
|
61
|
+
].concat(_to_consumable_array(dependencies))
|
62
|
+
];
|
63
|
+
}
|
64
|
+
});
|
65
|
+
});
|
66
|
+
return _generateWatchFiles.apply(this, arguments);
|
67
|
+
}
|
68
|
+
export {
|
69
|
+
addServerConfigToDeps,
|
70
|
+
generateWatchFiles
|
71
|
+
};
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import { chalk, inquirer } from "@modern-js/utils";
|
4
|
+
import { i18n, localeKeys } from "../locale";
|
5
|
+
var getSelectedEntries = function() {
|
6
|
+
var _ref = _async_to_generator(function(entry, entrypoints) {
|
7
|
+
var entryNames, selected;
|
8
|
+
return _ts_generator(this, function(_state) {
|
9
|
+
switch (_state.label) {
|
10
|
+
case 0:
|
11
|
+
entryNames = entrypoints.map(function(e) {
|
12
|
+
return e.entryName;
|
13
|
+
});
|
14
|
+
if (!entry) {
|
15
|
+
return [
|
16
|
+
2,
|
17
|
+
entryNames
|
18
|
+
];
|
19
|
+
}
|
20
|
+
if (!(typeof entry === "boolean"))
|
21
|
+
return [
|
22
|
+
3,
|
23
|
+
2
|
24
|
+
];
|
25
|
+
return [
|
26
|
+
4,
|
27
|
+
inquirer.prompt([
|
28
|
+
{
|
29
|
+
type: "checkbox",
|
30
|
+
name: "selected",
|
31
|
+
choices: entryNames,
|
32
|
+
message: i18n.t(localeKeys.command.dev.selectEntry),
|
33
|
+
validate: function validate(answer) {
|
34
|
+
if (answer.length < 1) {
|
35
|
+
return i18n.t(localeKeys.command.dev.requireEntry);
|
36
|
+
}
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
])
|
41
|
+
];
|
42
|
+
case 1:
|
43
|
+
selected = _state.sent().selected;
|
44
|
+
return [
|
45
|
+
2,
|
46
|
+
selected
|
47
|
+
];
|
48
|
+
case 2:
|
49
|
+
entry.forEach(function(name) {
|
50
|
+
if (!entryNames.includes(name)) {
|
51
|
+
throw new Error("Can not found entry ".concat(chalk.yellow(name), ", the entry should be one of ").concat(chalk.yellow(entryNames.join(", "))));
|
52
|
+
}
|
53
|
+
});
|
54
|
+
return [
|
55
|
+
2,
|
56
|
+
entry
|
57
|
+
];
|
58
|
+
}
|
59
|
+
});
|
60
|
+
});
|
61
|
+
return function getSelectedEntries2(entry, entrypoints) {
|
62
|
+
return _ref.apply(this, arguments);
|
63
|
+
};
|
64
|
+
}();
|
65
|
+
export {
|
66
|
+
getSelectedEntries
|
67
|
+
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
|
6
|
+
function getServerPlugins(api) {
|
7
|
+
return _getServerPlugins.apply(this, arguments);
|
8
|
+
}
|
9
|
+
function _getServerPlugins() {
|
10
|
+
_getServerPlugins = _async_to_generator(function(api) {
|
11
|
+
var metaName, runner, plugins, filtedPlugins;
|
12
|
+
var _arguments = arguments;
|
13
|
+
return _ts_generator(this, function(_state) {
|
14
|
+
switch (_state.label) {
|
15
|
+
case 0:
|
16
|
+
metaName = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern-js";
|
17
|
+
runner = api.useHookRunners();
|
18
|
+
return [
|
19
|
+
4,
|
20
|
+
runner._internalServerPlugins({
|
21
|
+
plugins: []
|
22
|
+
})
|
23
|
+
];
|
24
|
+
case 1:
|
25
|
+
plugins = _state.sent().plugins;
|
26
|
+
filtedPlugins = plugins.filter(function(plugin) {
|
27
|
+
return plugin.name.includes(metaName);
|
28
|
+
});
|
29
|
+
api.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
|
30
|
+
serverPlugins: filtedPlugins
|
31
|
+
}));
|
32
|
+
return [
|
33
|
+
2,
|
34
|
+
filtedPlugins
|
35
|
+
];
|
36
|
+
}
|
37
|
+
});
|
38
|
+
});
|
39
|
+
return _getServerPlugins.apply(this, arguments);
|
40
|
+
}
|
41
|
+
function loadServerPlugins(api, appDirectory, metaName) {
|
42
|
+
return _loadServerPlugins.apply(this, arguments);
|
43
|
+
}
|
44
|
+
function _loadServerPlugins() {
|
45
|
+
_loadServerPlugins = _async_to_generator(function(api, appDirectory, metaName) {
|
46
|
+
var plugins, instances;
|
47
|
+
return _ts_generator(this, function(_state) {
|
48
|
+
switch (_state.label) {
|
49
|
+
case 0:
|
50
|
+
return [
|
51
|
+
4,
|
52
|
+
getServerPlugins(api, metaName)
|
53
|
+
];
|
54
|
+
case 1:
|
55
|
+
plugins = _state.sent();
|
56
|
+
return [
|
57
|
+
4,
|
58
|
+
loadServerPluginInstances(plugins, appDirectory)
|
59
|
+
];
|
60
|
+
case 2:
|
61
|
+
instances = _state.sent();
|
62
|
+
return [
|
63
|
+
2,
|
64
|
+
instances
|
65
|
+
];
|
66
|
+
}
|
67
|
+
});
|
68
|
+
});
|
69
|
+
return _loadServerPlugins.apply(this, arguments);
|
70
|
+
}
|
71
|
+
export {
|
72
|
+
getServerPlugins,
|
73
|
+
loadServerPlugins
|
74
|
+
};
|