@modern-js/app-tools 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +556 -0
- package/bin/modern.js +11 -1
- package/dist/js/modern/analyze/Builder.js +39 -0
- package/dist/js/modern/analyze/constants.js +38 -16
- package/dist/js/modern/analyze/generateCode.js +272 -211
- package/dist/js/modern/analyze/getBundleEntry.js +34 -32
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
- package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
- package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
- package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
- package/dist/js/modern/analyze/getServerRoutes.js +122 -126
- package/dist/js/modern/analyze/index.js +201 -160
- package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
- package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
- package/dist/js/modern/analyze/nestedRoutes.js +110 -53
- package/dist/js/modern/analyze/templates.js +191 -77
- package/dist/js/modern/analyze/utils.js +98 -51
- package/dist/js/modern/builder/builderPlugins/compatModern.js +125 -107
- package/dist/js/modern/builder/index.js +124 -89
- package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
- package/dist/js/modern/builder/share.js +23 -21
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +100 -84
- package/dist/js/modern/commands/build.js +67 -42
- package/dist/js/modern/commands/deploy.js +27 -4
- package/dist/js/modern/commands/dev.js +93 -47
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/inspect.js +30 -5
- package/dist/js/modern/commands/start.js +37 -16
- package/dist/js/modern/config/default.js +103 -114
- package/dist/js/modern/config/index.js +8 -2
- package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
- package/dist/js/modern/config/initial/createOutputConfig.js +11 -9
- package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
- package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
- package/dist/js/modern/config/initial/index.js +9 -4
- package/dist/js/modern/config/initial/inits.js +109 -73
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
- package/dist/js/modern/defineConfig.js +26 -11
- package/dist/js/modern/exports/server.js +4 -1
- package/dist/js/modern/hooks.js +15 -4
- package/dist/js/modern/index.js +178 -90
- package/dist/js/modern/initialize/index.js +98 -51
- package/dist/js/modern/locale/en.js +20 -21
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +21 -22
- package/dist/js/modern/schema/Schema.js +6 -5
- package/dist/js/modern/schema/index.js +51 -100
- package/dist/js/modern/schema/legacy.js +96 -231
- package/dist/js/modern/types/config/index.js +0 -1
- package/dist/js/modern/types/index.js +0 -1
- package/dist/js/modern/types/legacyConfig/output.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -2
- package/dist/js/modern/utils/config.js +102 -41
- package/dist/js/modern/utils/createFileWatcher.js +84 -51
- package/dist/js/modern/utils/createServer.js +63 -17
- package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
- package/dist/js/modern/utils/language.js +6 -3
- package/dist/js/modern/utils/printInstructions.js +27 -8
- package/dist/js/modern/utils/restart.js +43 -16
- package/dist/js/modern/utils/routes.js +29 -12
- package/dist/js/node/analyze/Builder.js +58 -0
- package/dist/js/node/analyze/constants.js +54 -35
- package/dist/js/node/analyze/generateCode.js +291 -228
- package/dist/js/node/analyze/getBundleEntry.js +58 -44
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
- package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
- package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
- package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
- package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
- package/dist/js/node/analyze/getServerRoutes.js +143 -137
- package/dist/js/node/analyze/index.js +247 -174
- package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
- package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
- package/dist/js/node/analyze/nestedRoutes.js +140 -67
- package/dist/js/node/analyze/templates.js +212 -84
- package/dist/js/node/analyze/utils.js +123 -62
- package/dist/js/node/builder/builderPlugins/compatModern.js +153 -120
- package/dist/js/node/builder/index.js +152 -98
- package/dist/js/node/builder/loaders/routerLoader.js +36 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +26 -0
- package/dist/js/node/builder/share.js +46 -26
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +118 -90
- package/dist/js/node/commands/build.js +89 -52
- package/dist/js/node/commands/deploy.js +45 -10
- package/dist/js/node/commands/dev.js +115 -61
- package/dist/js/node/commands/index.js +19 -38
- package/dist/js/node/commands/inspect.js +48 -11
- package/dist/js/node/commands/start.js +65 -27
- package/dist/js/node/config/default.js +119 -118
- package/dist/js/node/config/index.js +25 -29
- package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
- package/dist/js/node/config/initial/createOutputConfig.js +28 -13
- package/dist/js/node/config/initial/createSourceConfig.js +22 -6
- package/dist/js/node/config/initial/createToolsConfig.js +24 -10
- package/dist/js/node/config/initial/index.js +28 -17
- package/dist/js/node/config/initial/inits.js +126 -81
- package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
- package/dist/js/node/defineConfig.js +43 -17
- package/dist/js/node/exports/server.js +21 -10
- package/dist/js/node/hooks.js +48 -29
- package/dist/js/node/index.js +225 -128
- package/dist/js/node/initialize/index.js +116 -61
- package/dist/js/node/locale/en.js +36 -25
- package/dist/js/node/locale/index.js +27 -15
- package/dist/js/node/locale/zh.js +37 -26
- package/dist/js/node/schema/Schema.js +23 -10
- package/dist/js/node/schema/index.js +77 -114
- package/dist/js/node/schema/legacy.js +117 -240
- package/dist/js/node/types/config/index.js +17 -16
- package/dist/js/node/types/index.js +19 -38
- package/dist/js/node/types/legacyConfig/output.js +0 -5
- package/dist/js/node/utils/commands.js +21 -6
- package/dist/js/node/utils/config.js +120 -51
- package/dist/js/node/utils/createFileWatcher.js +104 -60
- package/dist/js/node/utils/createServer.js +86 -25
- package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
- package/dist/js/node/utils/language.js +24 -8
- package/dist/js/node/utils/printInstructions.js +47 -16
- package/dist/js/node/utils/restart.js +61 -21
- package/dist/js/node/utils/routes.js +53 -18
- package/dist/js/treeshaking/analyze/Builder.js +199 -0
- package/dist/js/treeshaking/analyze/constants.js +28 -16
- package/dist/js/treeshaking/analyze/generateCode.js +605 -355
- package/dist/js/treeshaking/analyze/getBundleEntry.js +55 -63
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
- package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -146
- package/dist/js/treeshaking/analyze/index.js +571 -304
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
- package/dist/js/treeshaking/analyze/nestedRoutes.js +414 -160
- package/dist/js/treeshaking/analyze/templates.js +432 -161
- package/dist/js/treeshaking/analyze/utils.js +361 -80
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +282 -195
- package/dist/js/treeshaking/builder/index.js +371 -167
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
- package/dist/js/treeshaking/builder/share.js +38 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +334 -112
- package/dist/js/treeshaking/commands/build.js +286 -88
- package/dist/js/treeshaking/commands/deploy.js +153 -25
- package/dist/js/treeshaking/commands/dev.js +318 -132
- package/dist/js/treeshaking/commands/index.js +1 -1
- package/dist/js/treeshaking/commands/inspect.js +147 -32
- package/dist/js/treeshaking/commands/start.js +190 -68
- package/dist/js/treeshaking/config/default.js +210 -199
- package/dist/js/treeshaking/config/index.js +3 -2
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -67
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
- package/dist/js/treeshaking/config/initial/index.js +10 -9
- package/dist/js/treeshaking/config/initial/inits.js +205 -106
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
- package/dist/js/treeshaking/defineConfig.js +60 -13
- package/dist/js/treeshaking/exports/server.js +2 -1
- package/dist/js/treeshaking/hooks.js +30 -25
- package/dist/js/treeshaking/index.js +681 -256
- package/dist/js/treeshaking/initialize/index.js +290 -112
- package/dist/js/treeshaking/locale/en.js +34 -33
- package/dist/js/treeshaking/locale/index.js +5 -5
- package/dist/js/treeshaking/locale/zh.js +34 -33
- package/dist/js/treeshaking/schema/Schema.js +267 -69
- package/dist/js/treeshaking/schema/index.js +165 -121
- package/dist/js/treeshaking/schema/legacy.js +323 -256
- package/dist/js/treeshaking/types/config/deploy.js +1 -0
- package/dist/js/treeshaking/types/config/dev.js +1 -0
- package/dist/js/treeshaking/types/config/experiments.js +1 -0
- package/dist/js/treeshaking/types/config/html.js +1 -0
- package/dist/js/treeshaking/types/config/index.js +0 -1
- package/dist/js/treeshaking/types/config/output.js +1 -0
- package/dist/js/treeshaking/types/config/performance.js +1 -0
- package/dist/js/treeshaking/types/config/security.js +1 -0
- package/dist/js/treeshaking/types/config/source.js +1 -0
- package/dist/js/treeshaking/types/config/tools.js +1 -0
- package/dist/js/treeshaking/types/hooks.js +1 -0
- package/dist/js/treeshaking/types/index.js +0 -1
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
- package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
- package/dist/js/treeshaking/utils/commands.js +6 -5
- package/dist/js/treeshaking/utils/config.js +295 -117
- package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
- package/dist/js/treeshaking/utils/createServer.js +252 -67
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
- package/dist/js/treeshaking/utils/language.js +6 -5
- package/dist/js/treeshaking/utils/printInstructions.js +151 -29
- package/dist/js/treeshaking/utils/restart.js +184 -42
- package/dist/js/treeshaking/utils/routes.js +151 -27
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/dist/types/analyze/Builder.d.ts +8 -0
- package/dist/types/analyze/constants.d.ts +2 -0
- package/dist/types/analyze/index.d.ts +2 -0
- package/dist/types/analyze/templates.d.ts +10 -7
- package/dist/types/analyze/utils.d.ts +9 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
- package/dist/types/builder/index.d.ts +3 -3
- package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
- package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
- package/dist/types/defineConfig.d.ts +1 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/initialize/index.d.ts +2 -0
- package/dist/types/types/config/dev.d.ts +2 -2
- package/dist/types/types/config/index.d.ts +1 -0
- package/dist/types/types/config/output.d.ts +0 -1
- package/dist/types/types/config/source.d.ts +1 -0
- package/dist/types/types/config/tools.d.ts +10 -1
- package/dist/types/types/hooks.d.ts +7 -1
- package/dist/types/types/legacyConfig/dev.d.ts +1 -0
- package/dist/types/types/legacyConfig/output.d.ts +1 -1
- package/dist/types/types/legacyConfig/source.d.ts +1 -0
- package/dist/types/types/legacyConfig/tools.d.ts +1 -0
- package/dist/types/utils/config.d.ts +1 -0
- package/dist/types/utils/createFileWatcher.d.ts +2 -1
- package/dist/types/utils/createServer.d.ts +1 -0
- package/dist/types/utils/restart.d.ts +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +26 -22
|
@@ -1,66 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { ResolvedConfigContext } from "@modern-js/core";
|
|
41
|
+
import { logger, printBuildError } from "@modern-js/utils";
|
|
6
42
|
import { generateRoutes } from "../utils/routes";
|
|
7
43
|
import { buildServerConfig } from "../utils/config";
|
|
8
|
-
|
|
9
|
-
if (options
|
|
10
|
-
|
|
11
|
-
process.env.BUNDLE_ANALYZE = 'true';
|
|
44
|
+
const build = (api, options) => __async(void 0, null, function* () {
|
|
45
|
+
if (options == null ? void 0 : options.analyze) {
|
|
46
|
+
process.env.BUNDLE_ANALYZE = "true";
|
|
12
47
|
}
|
|
13
48
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
14
49
|
const appContext = api.useAppContext();
|
|
15
50
|
const hookRunners = api.useHookRunners();
|
|
16
|
-
const {
|
|
17
|
-
apiOnly
|
|
18
|
-
} = appContext;
|
|
51
|
+
const { apiOnly } = appContext;
|
|
19
52
|
if (apiOnly) {
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
serverConfigFile
|
|
24
|
-
} = appContext;
|
|
25
|
-
await hookRunners.beforeBuild({
|
|
26
|
-
// "null" bundlerConfigs
|
|
27
|
-
bundlerConfigs: undefined
|
|
53
|
+
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
|
54
|
+
yield hookRunners.beforeBuild({
|
|
55
|
+
bundlerConfigs: void 0
|
|
28
56
|
});
|
|
29
|
-
|
|
30
|
-
appDirectory,
|
|
31
|
-
distDirectory,
|
|
32
|
-
configFile:
|
|
57
|
+
yield buildServerConfig({
|
|
58
|
+
appDirectory: appDirectory2,
|
|
59
|
+
distDirectory: distDirectory2,
|
|
60
|
+
configFile: serverConfigFile2
|
|
33
61
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
stats: undefined
|
|
62
|
+
yield generateRoutes(appContext);
|
|
63
|
+
yield hookRunners.afterBuild({
|
|
64
|
+
stats: void 0
|
|
38
65
|
});
|
|
39
66
|
return;
|
|
40
67
|
}
|
|
41
|
-
resolvedConfig =
|
|
42
|
-
cliOptions: options
|
|
43
|
-
});
|
|
68
|
+
resolvedConfig = __spreadProps(__spreadValues({}, resolvedConfig), { cliOptions: options });
|
|
44
69
|
ResolvedConfigContext.set(resolvedConfig);
|
|
45
|
-
const {
|
|
46
|
-
|
|
47
|
-
appDirectory,
|
|
48
|
-
serverConfigFile
|
|
49
|
-
} = appContext;
|
|
50
|
-
await buildServerConfig({
|
|
70
|
+
const { distDirectory, appDirectory, serverConfigFile } = appContext;
|
|
71
|
+
yield buildServerConfig({
|
|
51
72
|
appDirectory,
|
|
52
73
|
distDirectory,
|
|
53
74
|
configFile: serverConfigFile
|
|
54
75
|
});
|
|
55
76
|
try {
|
|
56
|
-
logger.info(
|
|
77
|
+
logger.info("Create a production build...\n");
|
|
57
78
|
if (!appContext.builder) {
|
|
58
|
-
throw new Error(
|
|
79
|
+
throw new Error(
|
|
80
|
+
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
81
|
+
);
|
|
59
82
|
}
|
|
60
|
-
|
|
83
|
+
yield appContext.builder.build();
|
|
61
84
|
} catch (error) {
|
|
62
85
|
printBuildError(error);
|
|
63
|
-
// eslint-disable-next-line no-process-exit
|
|
64
86
|
process.exit(1);
|
|
65
87
|
}
|
|
66
|
-
};
|
|
88
|
+
});
|
|
89
|
+
export {
|
|
90
|
+
build
|
|
91
|
+
};
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const deploy = (api, options) => __async(void 0, null, function* () {
|
|
2
22
|
const hookRunners = api.useHookRunners();
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
23
|
+
yield hookRunners.beforeDeploy(options);
|
|
24
|
+
yield hookRunners.afterDeploy(options);
|
|
25
|
+
});
|
|
26
|
+
export {
|
|
27
|
+
deploy
|
|
28
|
+
};
|
|
@@ -1,26 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { ResolvedConfigContext } from "@modern-js/core";
|
|
6
41
|
import { createFileWatcher } from "../utils/createFileWatcher";
|
|
7
42
|
import { printInstructions } from "../utils/printInstructions";
|
|
8
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
setServer,
|
|
45
|
+
createServer,
|
|
46
|
+
injectDataLoaderPlugin
|
|
47
|
+
} from "../utils/createServer";
|
|
9
48
|
import { generateRoutes } from "../utils/routes";
|
|
10
49
|
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
11
50
|
import { buildServerConfig } from "../utils/config";
|
|
12
|
-
|
|
13
|
-
var
|
|
51
|
+
const dev = (api, options) => __async(void 0, null, function* () {
|
|
52
|
+
var _a;
|
|
14
53
|
if (options.analyze) {
|
|
15
|
-
|
|
16
|
-
process.env.BUNDLE_ANALYZE = 'true';
|
|
54
|
+
process.env.BUNDLE_ANALYZE = "true";
|
|
17
55
|
}
|
|
18
56
|
let normalizedConfig = api.useResolvedConfigContext();
|
|
19
57
|
const appContext = api.useAppContext();
|
|
20
58
|
const hookRunners = api.useHookRunners();
|
|
21
|
-
normalizedConfig =
|
|
22
|
-
cliOptions: options
|
|
23
|
-
});
|
|
59
|
+
normalizedConfig = __spreadProps(__spreadValues({}, normalizedConfig), { cliOptions: options });
|
|
24
60
|
ResolvedConfigContext.set(normalizedConfig);
|
|
25
61
|
const {
|
|
26
62
|
appDirectory,
|
|
@@ -31,12 +67,15 @@ export const dev = async (api, options) => {
|
|
|
31
67
|
serverConfigFile,
|
|
32
68
|
serverInternalPlugins
|
|
33
69
|
} = appContext;
|
|
34
|
-
const checkedEntries =
|
|
35
|
-
|
|
70
|
+
const checkedEntries = yield getSpecifiedEntries(
|
|
71
|
+
options.entry || false,
|
|
72
|
+
entrypoints
|
|
73
|
+
);
|
|
74
|
+
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
36
75
|
checkedEntries
|
|
37
76
|
}));
|
|
38
77
|
appContext.checkedEntries = checkedEntries;
|
|
39
|
-
|
|
78
|
+
yield buildServerConfig({
|
|
40
79
|
appDirectory,
|
|
41
80
|
distDirectory,
|
|
42
81
|
configFile: serverConfigFile,
|
|
@@ -46,43 +85,50 @@ export const dev = async (api, options) => {
|
|
|
46
85
|
}
|
|
47
86
|
}
|
|
48
87
|
});
|
|
49
|
-
|
|
50
|
-
let compiler
|
|
88
|
+
yield hookRunners.beforeDev();
|
|
89
|
+
let compiler;
|
|
90
|
+
if (!appContext.builder && !apiOnly) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
51
95
|
if (!apiOnly) {
|
|
52
|
-
|
|
53
|
-
throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
54
|
-
}
|
|
55
|
-
compiler = await appContext.builder.createCompiler();
|
|
96
|
+
compiler = yield appContext.builder.createCompiler();
|
|
56
97
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
dev:
|
|
60
|
-
client: {
|
|
61
|
-
port: port.toString()
|
|
62
|
-
},
|
|
63
|
-
devMiddleware: {
|
|
64
|
-
writeToDisk: file => !file.includes('.hot-update.')
|
|
65
|
-
},
|
|
66
|
-
hot: true,
|
|
67
|
-
liveReload: true,
|
|
98
|
+
yield generateRoutes(appContext);
|
|
99
|
+
const serverOptions = {
|
|
100
|
+
dev: __spreadValues({
|
|
68
101
|
port,
|
|
69
102
|
https: normalizedConfig.dev.https
|
|
70
|
-
}
|
|
71
|
-
compiler,
|
|
103
|
+
}, (_a = normalizedConfig.tools) == null ? void 0 : _a.devServer),
|
|
104
|
+
compiler: compiler || null,
|
|
72
105
|
pwd: appDirectory,
|
|
73
106
|
config: normalizedConfig,
|
|
74
107
|
serverConfigFile,
|
|
75
108
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} else {
|
|
109
|
+
};
|
|
110
|
+
if (apiOnly) {
|
|
111
|
+
const app = yield createServer(serverOptions);
|
|
112
|
+
app.listen(port, (err) => __async(void 0, null, function* () {
|
|
113
|
+
if (err) {
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
84
116
|
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
117
|
+
}));
|
|
118
|
+
} else {
|
|
119
|
+
const { server } = yield appContext.builder.startDevServer({
|
|
120
|
+
compiler,
|
|
121
|
+
printURLs: false,
|
|
122
|
+
serverOptions
|
|
123
|
+
});
|
|
124
|
+
setServer(server);
|
|
125
|
+
}
|
|
126
|
+
yield createFileWatcher(
|
|
127
|
+
appContext,
|
|
128
|
+
normalizedConfig.source.configDir,
|
|
129
|
+
hookRunners
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
export {
|
|
133
|
+
dev
|
|
134
|
+
};
|
|
@@ -1,13 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { join } from "path";
|
|
22
|
+
const inspect = (api, options) => __async(void 0, null, function* () {
|
|
3
23
|
const appContext = api.useAppContext();
|
|
4
24
|
if (!appContext.builder) {
|
|
5
|
-
throw new Error(
|
|
25
|
+
throw new Error(
|
|
26
|
+
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
27
|
+
);
|
|
6
28
|
}
|
|
7
29
|
return appContext.builder.inspectConfig({
|
|
8
30
|
env: options.env,
|
|
9
31
|
verbose: options.verbose,
|
|
10
|
-
outputPath: join(appContext
|
|
32
|
+
outputPath: join(appContext == null ? void 0 : appContext.builder.context.distPath, options.output),
|
|
11
33
|
writeToDisk: true
|
|
12
34
|
});
|
|
13
|
-
};
|
|
35
|
+
});
|
|
36
|
+
export {
|
|
37
|
+
inspect
|
|
38
|
+
};
|
|
@@ -1,31 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { logger, chalk, isApiOnly } from "@modern-js/utils";
|
|
22
|
+
import server from "@modern-js/prod-server";
|
|
3
23
|
import { printInstructions } from "../utils/printInstructions";
|
|
4
24
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
5
|
-
|
|
6
|
-
var
|
|
25
|
+
const start = (api) => __async(void 0, null, function* () {
|
|
26
|
+
var _a;
|
|
7
27
|
const appContext = api.useAppContext();
|
|
8
28
|
const userConfig = api.useResolvedConfigContext();
|
|
9
29
|
const hookRunners = api.useHookRunners();
|
|
10
|
-
const {
|
|
11
|
-
appDirectory,
|
|
12
|
-
port,
|
|
13
|
-
serverConfigFile
|
|
14
|
-
} = appContext;
|
|
30
|
+
const { appDirectory, port, serverConfigFile } = appContext;
|
|
15
31
|
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
16
|
-
const apiOnly =
|
|
17
|
-
|
|
32
|
+
const apiOnly = yield isApiOnly(
|
|
33
|
+
appContext.appDirectory,
|
|
34
|
+
(_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.entriesDir
|
|
35
|
+
);
|
|
36
|
+
const app = yield server({
|
|
18
37
|
pwd: appDirectory,
|
|
19
|
-
// FIXME: remove the `any` type
|
|
20
38
|
config: userConfig,
|
|
21
39
|
serverConfigFile,
|
|
22
40
|
internalPlugins: injectDataLoaderPlugin(appContext.serverInternalPlugins),
|
|
23
41
|
apiOnly
|
|
24
42
|
});
|
|
25
|
-
app.listen(port,
|
|
43
|
+
app.listen(port, (err) => __async(void 0, null, function* () {
|
|
26
44
|
if (err) {
|
|
27
45
|
throw err;
|
|
28
46
|
}
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
};
|
|
47
|
+
yield printInstructions(hookRunners, appContext, userConfig);
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
export {
|
|
51
|
+
start
|
|
52
|
+
};
|