@modern-js/app-tools 2.63.1 → 2.63.2
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +1 -1
- package/dist/cjs/commands/build.js +19 -13
- package/dist/cjs/commands/deploy.js +5 -5
- package/dist/cjs/commands/dev.js +11 -11
- package/dist/cjs/commands/index.js +6 -6
- package/dist/cjs/commands/inspect.js +1 -1
- package/dist/cjs/commands/serve.js +4 -4
- package/dist/cjs/{new/compat → compat}/hooks.js +5 -5
- package/dist/cjs/{new/compat → compat}/index.js +4 -1
- package/dist/cjs/config/default.js +6 -1
- package/dist/cjs/config/legacy/index.js +0 -1
- package/dist/cjs/index.js +154 -5
- package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
- package/dist/cjs/plugins/analyze/index.js +25 -10
- package/dist/cjs/plugins/analyze/utils.js +6 -0
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -3
- package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/cjs/utils/loadPlugins.js +35 -4
- package/dist/cjs/utils/printInstructions.js +2 -11
- package/dist/cjs/utils/restart.js +2 -2
- package/dist/esm/commands/build.js +18 -12
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +11 -11
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +6 -6
- package/dist/esm/{new/compat → compat}/hooks.js +15 -25
- package/dist/esm/{new/compat → compat}/index.js +4 -1
- package/dist/esm/config/default.js +12 -1
- package/dist/esm/config/legacy/index.js +0 -1
- package/dist/esm/index.js +245 -2
- package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
- package/dist/esm/plugins/analyze/index.js +76 -34
- package/dist/esm/plugins/analyze/utils.js +5 -0
- package/dist/esm/plugins/serverBuild.js +52 -56
- package/dist/esm/{new/run.js → run/index.js} +6 -6
- package/dist/esm/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/esm/utils/loadPlugins.js +95 -7
- package/dist/esm/utils/printInstructions.js +1 -28
- package/dist/esm/utils/restart.js +3 -3
- package/dist/esm-node/commands/build.js +19 -13
- package/dist/esm-node/commands/deploy.js +5 -5
- package/dist/esm-node/commands/dev.js +12 -12
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/commands/inspect.js +1 -1
- package/dist/esm-node/commands/serve.js +5 -5
- package/dist/esm-node/{new/compat → compat}/hooks.js +5 -5
- package/dist/esm-node/{new/compat → compat}/index.js +4 -1
- package/dist/esm-node/config/default.js +6 -1
- package/dist/esm-node/config/legacy/index.js +0 -1
- package/dist/esm-node/index.js +140 -2
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
- package/dist/esm-node/plugins/analyze/index.js +26 -11
- package/dist/esm-node/plugins/analyze/utils.js +5 -0
- package/dist/esm-node/plugins/serverBuild.js +30 -32
- package/dist/esm-node/{new/run.js → run/index.js} +6 -6
- package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
- package/dist/esm-node/utils/loadPlugins.js +34 -4
- package/dist/esm-node/utils/printInstructions.js +1 -9
- package/dist/esm-node/utils/restart.js +2 -2
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/index.d.ts +6 -6
- package/dist/types/commands/inspect.d.ts +2 -2
- package/dist/types/commands/serve.d.ts +2 -2
- package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
- package/dist/types/plugins/analyze/utils.d.ts +1 -0
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/config/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/new.d.ts +11 -16
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
- package/dist/types/utils/loadPlugins.d.ts +13 -3
- package/dist/types/utils/printInstructions.d.ts +1 -3
- package/dist/types/utils/restart.d.ts +2 -3
- package/package.json +23 -23
- package/dist/cjs/hooks.js +0 -60
- package/dist/cjs/new/index.js +0 -79
- package/dist/cjs/new/loadPlugins.js +0 -57
- package/dist/cjs/old.js +0 -179
- package/dist/esm/hooks.js +0 -36
- package/dist/esm/new/index.js +0 -55
- package/dist/esm/new/loadPlugins.js +0 -94
- package/dist/esm/old.js +0 -258
- package/dist/esm-node/hooks.js +0 -36
- package/dist/esm-node/new/index.js +0 -52
- package/dist/esm-node/new/loadPlugins.js +0 -33
- package/dist/esm-node/old.js +0 -140
- package/dist/types/hooks.d.ts +0 -2
- package/dist/types/new/compat/index.d.ts +0 -2
- package/dist/types/new/index.d.ts +0 -6
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -13
- /package/dist/cjs/{new/compat → compat}/utils.js +0 -0
- /package/dist/cjs/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/compat → compat}/utils.js +0 -0
- /package/dist/esm/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -0
- /package/dist/esm-node/{new/compat → compat}/utils.js +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -0
- /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
- /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
- /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
- /package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -0
@@ -21,63 +21,59 @@ function serverBuild_default() {
|
|
21
21
|
return {
|
22
22
|
name: "@modern-js/server-build",
|
23
23
|
setup: function setup(api) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
];
|
24
|
+
api.onAfterBuild(/* @__PURE__ */ _async_to_generator(function() {
|
25
|
+
var _api_getAppContext, appDirectory, distDirectory, metaName, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
26
|
+
return _ts_generator(this, function(_state) {
|
27
|
+
switch (_state.label) {
|
28
|
+
case 0:
|
29
|
+
_api_getAppContext = api.getAppContext(), appDirectory = _api_getAppContext.appDirectory, distDirectory = _api_getAppContext.distDirectory, metaName = _api_getAppContext.metaName;
|
30
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
31
|
+
return [
|
32
|
+
2
|
33
|
+
];
|
76
34
|
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
35
|
+
modernConfig = api.getNormalizedConfig();
|
36
|
+
distDir = path.resolve(distDirectory);
|
37
|
+
serverDir = path.resolve(appDirectory, SERVER_DIR);
|
38
|
+
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
39
|
+
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
40
|
+
sourceDirs = [];
|
41
|
+
if (fs.existsSync(serverDir)) {
|
42
|
+
sourceDirs.push(serverDir);
|
43
|
+
if (fs.existsSync(sharedDir)) {
|
44
|
+
sourceDirs.push(sharedDir);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
server = modernConfig.server;
|
48
|
+
alias = modernConfig.source.alias;
|
49
|
+
babel = modernConfig.tools.babel;
|
50
|
+
if (!(sourceDirs.length > 0))
|
51
|
+
return [
|
52
|
+
3,
|
53
|
+
2
|
54
|
+
];
|
55
|
+
return [
|
56
|
+
4,
|
57
|
+
compile(appDirectory, {
|
58
|
+
server,
|
59
|
+
alias,
|
60
|
+
babelConfig: babel
|
61
|
+
}, {
|
62
|
+
sourceDirs,
|
63
|
+
distDir,
|
64
|
+
tsconfigPath
|
65
|
+
})
|
66
|
+
];
|
67
|
+
case 1:
|
68
|
+
_state.sent();
|
69
|
+
_state.label = 2;
|
70
|
+
case 2:
|
71
|
+
return [
|
72
|
+
2
|
73
|
+
];
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}));
|
81
77
|
}
|
82
78
|
};
|
83
79
|
}
|
@@ -3,11 +3,11 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { initAppDir } from "@modern-js/plugin-v2/cli";
|
4
4
|
import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
|
5
5
|
import { minimist } from "@modern-js/utils";
|
6
|
-
import { handleSetupResult } from "
|
7
|
-
import { PACKAGE_JSON_CONFIG_NAME } from "
|
8
|
-
import { getConfigFile } from "
|
9
|
-
import {
|
10
|
-
import {
|
6
|
+
import { handleSetupResult } from "../compat/hooks";
|
7
|
+
import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
|
8
|
+
import { getConfigFile } from "../utils/getConfigFile";
|
9
|
+
import { isAutoLoadPlugins } from "../utils/isAutoLoadPlugins";
|
10
|
+
import { loadInternalPlugins } from "../utils/loadPlugins";
|
11
11
|
function run(_) {
|
12
12
|
return _run.apply(this, arguments);
|
13
13
|
}
|
@@ -44,7 +44,7 @@ function _run() {
|
|
44
44
|
finalConfigFile = customConfigFile || getConfigFile(configFile);
|
45
45
|
return [
|
46
46
|
4,
|
47
|
-
|
47
|
+
isAutoLoadPlugins(appDirectory, finalConfigFile)
|
48
48
|
];
|
49
49
|
case 2:
|
50
50
|
autoLoadPlugins = _state.sent();
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
|
3
|
-
import { DEFAULT_CONFIG_FILE } from "
|
3
|
+
import { DEFAULT_CONFIG_FILE } from "../constants";
|
4
4
|
var getConfigFile = function(configFile) {
|
5
5
|
return findExists(CONFIG_FILE_EXTENSIONS.map(function(extension) {
|
6
6
|
return path.resolve(process.cwd(), "".concat(configFile || DEFAULT_CONFIG_FILE).concat(extension));
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
|
4
|
-
function
|
5
|
-
return
|
4
|
+
function isAutoLoadPlugins(appDirectory) {
|
5
|
+
return _isAutoLoadPlugins.apply(this, arguments);
|
6
6
|
}
|
7
|
-
function
|
8
|
-
|
7
|
+
function _isAutoLoadPlugins() {
|
8
|
+
_isAutoLoadPlugins = _async_to_generator(function(appDirectory) {
|
9
9
|
var configFile, packageJsonConfig, _loaded_config, loaded, autoLoadPlugins;
|
10
10
|
var _arguments = arguments;
|
11
11
|
return _ts_generator(this, function(_state) {
|
@@ -26,8 +26,8 @@ function _getIsAutoLoadPlugins() {
|
|
26
26
|
}
|
27
27
|
});
|
28
28
|
});
|
29
|
-
return
|
29
|
+
return _isAutoLoadPlugins.apply(this, arguments);
|
30
30
|
}
|
31
31
|
export {
|
32
|
-
|
32
|
+
isAutoLoadPlugins
|
33
33
|
};
|
@@ -1,23 +1,24 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
-
import { _ as
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
4
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
4
|
import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
|
5
|
+
import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
|
6
|
+
var debug = createDebugger("load-plugins");
|
6
7
|
function getServerPlugins(api) {
|
7
8
|
return _getServerPlugins.apply(this, arguments);
|
8
9
|
}
|
9
10
|
function _getServerPlugins() {
|
10
11
|
_getServerPlugins = _async_to_generator(function(api) {
|
11
|
-
var metaName,
|
12
|
+
var metaName, hooks, plugins, filtedPlugins;
|
12
13
|
var _arguments = arguments;
|
13
14
|
return _ts_generator(this, function(_state) {
|
14
15
|
switch (_state.label) {
|
15
16
|
case 0:
|
16
17
|
metaName = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern-js";
|
17
|
-
|
18
|
+
hooks = api.getHooks();
|
18
19
|
return [
|
19
20
|
4,
|
20
|
-
|
21
|
+
hooks._internalServerPlugins.call({
|
21
22
|
plugins: []
|
22
23
|
})
|
23
24
|
];
|
@@ -26,9 +27,9 @@ function _getServerPlugins() {
|
|
26
27
|
filtedPlugins = plugins.filter(function(plugin) {
|
27
28
|
return plugin.name.includes(metaName);
|
28
29
|
});
|
29
|
-
api.
|
30
|
+
api.updateAppContext({
|
30
31
|
serverPlugins: filtedPlugins
|
31
|
-
})
|
32
|
+
});
|
32
33
|
return [
|
33
34
|
2,
|
34
35
|
filtedPlugins
|
@@ -68,7 +69,94 @@ function _loadServerPlugins() {
|
|
68
69
|
});
|
69
70
|
return _loadServerPlugins.apply(this, arguments);
|
70
71
|
}
|
72
|
+
var resolveCliPlugin = function() {
|
73
|
+
var _ref = _async_to_generator(function(p, appDirectory) {
|
74
|
+
var pkg, pluginOptions, path, module, e, ref, result;
|
75
|
+
return _ts_generator(this, function(_state) {
|
76
|
+
switch (_state.label) {
|
77
|
+
case 0:
|
78
|
+
pkg = typeof p === "string" ? p : p[0];
|
79
|
+
pluginOptions = typeof p === "string" ? void 0 : p[1];
|
80
|
+
path = tryResolve(pkg, appDirectory);
|
81
|
+
_state.label = 1;
|
82
|
+
case 1:
|
83
|
+
_state.trys.push([
|
84
|
+
1,
|
85
|
+
3,
|
86
|
+
,
|
87
|
+
5
|
88
|
+
]);
|
89
|
+
return [
|
90
|
+
4,
|
91
|
+
compatibleRequire(path)
|
92
|
+
];
|
93
|
+
case 2:
|
94
|
+
module = _state.sent();
|
95
|
+
return [
|
96
|
+
3,
|
97
|
+
5
|
98
|
+
];
|
99
|
+
case 3:
|
100
|
+
e = _state.sent();
|
101
|
+
return [
|
102
|
+
4,
|
103
|
+
dynamicImport(path)
|
104
|
+
];
|
105
|
+
case 4:
|
106
|
+
ref = _state.sent(), module = ref.default, ref;
|
107
|
+
return [
|
108
|
+
3,
|
109
|
+
5
|
110
|
+
];
|
111
|
+
case 5:
|
112
|
+
if (typeof module === "function") {
|
113
|
+
result = module(pluginOptions);
|
114
|
+
return [
|
115
|
+
2,
|
116
|
+
result
|
117
|
+
];
|
118
|
+
}
|
119
|
+
return [
|
120
|
+
2,
|
121
|
+
module
|
122
|
+
];
|
123
|
+
}
|
124
|
+
});
|
125
|
+
});
|
126
|
+
return function resolveCliPlugin2(p, appDirectory) {
|
127
|
+
return _ref.apply(this, arguments);
|
128
|
+
};
|
129
|
+
}();
|
130
|
+
var loadInternalPlugins = function() {
|
131
|
+
var _ref = _async_to_generator(function(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
|
132
|
+
var plugins, loadedPlugins;
|
133
|
+
return _ts_generator(this, function(_state) {
|
134
|
+
switch (_state.label) {
|
135
|
+
case 0:
|
136
|
+
plugins = _to_consumable_array(autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : []).concat(_to_consumable_array(autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []));
|
137
|
+
return [
|
138
|
+
4,
|
139
|
+
Promise.all(plugins.map(function(plugin) {
|
140
|
+
var loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
141
|
+
debug("resolve plugin %s: %s", plugin, loadedPlugin);
|
142
|
+
return loadedPlugin;
|
143
|
+
}))
|
144
|
+
];
|
145
|
+
case 1:
|
146
|
+
loadedPlugins = _state.sent();
|
147
|
+
return [
|
148
|
+
2,
|
149
|
+
loadedPlugins
|
150
|
+
];
|
151
|
+
}
|
152
|
+
});
|
153
|
+
});
|
154
|
+
return function loadInternalPlugins2(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
|
155
|
+
return _ref.apply(this, arguments);
|
156
|
+
};
|
157
|
+
}();
|
71
158
|
export {
|
72
159
|
getServerPlugins,
|
160
|
+
loadInternalPlugins,
|
73
161
|
loadServerPlugins
|
74
162
|
};
|
@@ -27,33 +27,6 @@ var printInstructions = function() {
|
|
27
27
|
return _ref.apply(this, arguments);
|
28
28
|
};
|
29
29
|
}();
|
30
|
-
var printInstructionsCompat = function() {
|
31
|
-
var _ref = _async_to_generator(function(hookRunners, appContext, config) {
|
32
|
-
var message, instructions;
|
33
|
-
return _ts_generator(this, function(_state) {
|
34
|
-
switch (_state.label) {
|
35
|
-
case 0:
|
36
|
-
message = prettyInstructions(appContext, config);
|
37
|
-
return [
|
38
|
-
4,
|
39
|
-
hookRunners.beforePrintInstructions({
|
40
|
-
instructions: message
|
41
|
-
})
|
42
|
-
];
|
43
|
-
case 1:
|
44
|
-
instructions = _state.sent().instructions;
|
45
|
-
logger.log(instructions);
|
46
|
-
return [
|
47
|
-
2
|
48
|
-
];
|
49
|
-
}
|
50
|
-
});
|
51
|
-
});
|
52
|
-
return function printInstructionsCompat2(hookRunners, appContext, config) {
|
53
|
-
return _ref.apply(this, arguments);
|
54
|
-
};
|
55
|
-
}();
|
56
30
|
export {
|
57
|
-
printInstructions
|
58
|
-
printInstructionsCompat
|
31
|
+
printInstructions
|
59
32
|
};
|
@@ -3,11 +3,11 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { cli } from "@modern-js/plugin-v2/cli";
|
4
4
|
import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
|
5
5
|
import { program } from "@modern-js/utils/commander";
|
6
|
-
function restart(
|
6
|
+
function restart(hooks, filename) {
|
7
7
|
return _restart.apply(this, arguments);
|
8
8
|
}
|
9
9
|
function _restart() {
|
10
|
-
_restart = _async_to_generator(function(
|
10
|
+
_restart = _async_to_generator(function(hooks, filename) {
|
11
11
|
var hasGetError, err;
|
12
12
|
return _ts_generator(this, function(_state) {
|
13
13
|
switch (_state.label) {
|
@@ -17,7 +17,7 @@ function _restart() {
|
|
17
17
|
hasGetError = false;
|
18
18
|
return [
|
19
19
|
4,
|
20
|
-
|
20
|
+
hooks.onBeforeRestart.call()
|
21
21
|
];
|
22
22
|
case 1:
|
23
23
|
_state.sent();
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { ResolvedConfigContext } from "@modern-js/core";
|
2
1
|
import { logger } from "@modern-js/utils";
|
3
2
|
import { buildServerConfig } from "../utils/config";
|
4
3
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
@@ -9,9 +8,9 @@ const build = async (api, options) => {
|
|
9
8
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
10
9
|
process.env.BUNDLE_ANALYZE = "true";
|
11
10
|
}
|
12
|
-
|
13
|
-
const appContext = api.
|
14
|
-
const
|
11
|
+
const resolvedConfig = api.getNormalizedConfig();
|
12
|
+
const appContext = api.getAppContext();
|
13
|
+
const hooks = api.getHooks();
|
15
14
|
await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
|
16
15
|
if (appContext.moduleType && appContext.moduleType === "module") {
|
17
16
|
var _resolvedConfig_source1;
|
@@ -26,9 +25,12 @@ const build = async (api, options) => {
|
|
26
25
|
const { apiOnly } = appContext;
|
27
26
|
if (apiOnly) {
|
28
27
|
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
29
|
-
await
|
28
|
+
await hooks.onBeforeBuild.call({
|
29
|
+
environments: {},
|
30
30
|
// "null" bundlerConfigs
|
31
|
-
bundlerConfigs: void 0
|
31
|
+
bundlerConfigs: void 0,
|
32
|
+
isFirstCompile: false,
|
33
|
+
isWatch: false
|
32
34
|
});
|
33
35
|
await buildServerConfig({
|
34
36
|
appDirectory: appDirectory2,
|
@@ -36,17 +38,21 @@ const build = async (api, options) => {
|
|
36
38
|
configFile: serverConfigFile2
|
37
39
|
});
|
38
40
|
await generateRoutes(appContext);
|
39
|
-
await
|
41
|
+
await hooks.onAfterBuild.call({
|
42
|
+
environments: {},
|
40
43
|
// "null" stats
|
41
|
-
stats: void 0
|
44
|
+
stats: void 0,
|
45
|
+
isFirstCompile: false,
|
46
|
+
isWatch: false
|
42
47
|
});
|
43
48
|
return;
|
44
49
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
api.modifyResolvedConfig((config) => {
|
51
|
+
return {
|
52
|
+
...config,
|
53
|
+
cliOptions: options
|
54
|
+
};
|
55
|
+
});
|
50
56
|
const { distDirectory, appDirectory, serverConfigFile } = appContext;
|
51
57
|
await buildServerConfig({
|
52
58
|
appDirectory,
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { getServerPlugins } from "../utils/loadPlugins";
|
2
2
|
const deploy = async (api, options) => {
|
3
|
-
const
|
4
|
-
const { metaName } = api.
|
3
|
+
const hooks = api.getHooks();
|
4
|
+
const { metaName } = api.getAppContext();
|
5
5
|
await getServerPlugins(api, metaName);
|
6
|
-
await
|
7
|
-
await
|
8
|
-
await
|
6
|
+
await hooks.onBeforeDeploy.call(options);
|
7
|
+
await hooks.deploy.call();
|
8
|
+
await hooks.onAfterDeploy.call(options);
|
9
9
|
};
|
10
10
|
export {
|
11
11
|
deploy
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { ResolvedConfigContext } from "@modern-js/core";
|
3
2
|
import { applyPlugins } from "@modern-js/prod-server";
|
4
3
|
import { createDevServer } from "@modern-js/server";
|
5
4
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
6
5
|
import { buildServerConfig } from "../utils/config";
|
7
6
|
import { setServer } from "../utils/createServer";
|
8
7
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
9
|
-
import {
|
8
|
+
import { printInstructions } from "../utils/printInstructions";
|
10
9
|
import { registerCompiler } from "../utils/register";
|
11
10
|
import { generateRoutes } from "../utils/routes";
|
12
11
|
const dev = async (api, options, devServerOptions) => {
|
@@ -14,9 +13,9 @@ const dev = async (api, options, devServerOptions) => {
|
|
14
13
|
if (options.analyze) {
|
15
14
|
process.env.BUNDLE_ANALYZE = "true";
|
16
15
|
}
|
17
|
-
|
18
|
-
const appContext = api.
|
19
|
-
const
|
16
|
+
const normalizedConfig = api.getNormalizedConfig();
|
17
|
+
const appContext = api.getAppContext();
|
18
|
+
const hooks = api.getHooks();
|
20
19
|
if (appContext.moduleType && appContext.moduleType === "module") {
|
21
20
|
var _normalizedConfig_source1;
|
22
21
|
const { registerEsm } = await import("../esm/register-esm.mjs");
|
@@ -27,11 +26,12 @@ const dev = async (api, options, devServerOptions) => {
|
|
27
26
|
});
|
28
27
|
}
|
29
28
|
await registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
api.modifyResolvedConfig((config) => {
|
30
|
+
return {
|
31
|
+
...config,
|
32
|
+
cliOptions: options
|
33
|
+
};
|
34
|
+
});
|
35
35
|
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
|
36
36
|
await buildServerConfig({
|
37
37
|
appDirectory,
|
@@ -41,7 +41,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
41
41
|
});
|
42
42
|
const meta = getMeta(metaName);
|
43
43
|
const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
44
|
-
await
|
44
|
+
await hooks.onBeforeDev.call();
|
45
45
|
if (!appContext.builder && !apiOnly) {
|
46
46
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
47
47
|
}
|
@@ -80,7 +80,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
80
80
|
port,
|
81
81
|
host
|
82
82
|
}, () => {
|
83
|
-
|
83
|
+
printInstructions(hooks, appContext, normalizedConfig);
|
84
84
|
});
|
85
85
|
} else {
|
86
86
|
const { server, afterListen } = await createDevServer({
|
@@ -2,8 +2,8 @@ import { castArray } from "@modern-js/uni-builder";
|
|
2
2
|
import { newAction, upgradeAction } from "@modern-js/utils";
|
3
3
|
import { i18n, localeKeys } from "../locale";
|
4
4
|
const devCommand = async (program, api) => {
|
5
|
-
const
|
6
|
-
const devToolMetas = await
|
5
|
+
const hooks = api.getHooks();
|
6
|
+
const devToolMetas = await hooks.registerDev.call();
|
7
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
8
|
const { dev } = await import("./dev.js");
|
9
9
|
await dev(api, options);
|
@@ -14,7 +14,7 @@ const devCommand = async (program, api) => {
|
|
14
14
|
}
|
15
15
|
for (const subCmd of meta.subCommands) {
|
16
16
|
devProgram.command(subCmd).action(async (options = {}) => {
|
17
|
-
const { appDirectory } = api.
|
17
|
+
const { appDirectory } = api.getAppContext();
|
18
18
|
const { isTypescript } = await import("@modern-js/utils");
|
19
19
|
await meta.action(options, {
|
20
20
|
isTsProject: isTypescript(appDirectory)
|
@@ -24,8 +24,8 @@ const devCommand = async (program, api) => {
|
|
24
24
|
}
|
25
25
|
};
|
26
26
|
const buildCommand = async (program, api) => {
|
27
|
-
const
|
28
|
-
const platformBuilders = await
|
27
|
+
const hooks = api.getHooks();
|
28
|
+
const platformBuilders = await hooks.registerBuildPlatform.call();
|
29
29
|
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) => {
|
30
30
|
const { build } = await import("./build.js");
|
31
31
|
await build(api, options);
|
@@ -34,7 +34,7 @@ const buildCommand = async (program, api) => {
|
|
34
34
|
const platforms = castArray(platformBuilder.platform);
|
35
35
|
for (const platform of platforms) {
|
36
36
|
buildProgram.command(platform).action(async () => {
|
37
|
-
const { appDirectory } = api.
|
37
|
+
const { appDirectory } = api.getAppContext();
|
38
38
|
const { isTypescript } = await import("@modern-js/utils");
|
39
39
|
await platformBuilder.build(platform, {
|
40
40
|
isTsProject: isTypescript(appDirectory)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
const inspect = async (api, options) => {
|
2
|
-
const appContext = api.
|
2
|
+
const appContext = api.getAppContext();
|
3
3
|
if (!appContext.builder) {
|
4
4
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
5
5
|
}
|
@@ -2,12 +2,12 @@ import path from "path";
|
|
2
2
|
import { createProdServer } from "@modern-js/prod-server";
|
3
3
|
import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
|
4
4
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
5
|
-
import {
|
5
|
+
import { printInstructions } from "../utils/printInstructions";
|
6
6
|
const start = async (api) => {
|
7
7
|
var _userConfig_source, _userConfig_output_distPath;
|
8
|
-
const appContext = api.
|
9
|
-
const userConfig = api.
|
10
|
-
const
|
8
|
+
const appContext = api.getAppContext();
|
9
|
+
const userConfig = api.getNormalizedConfig();
|
10
|
+
const hooks = api.getHooks();
|
11
11
|
const { distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
|
12
12
|
logger.info(`Starting production server...`);
|
13
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);
|
@@ -44,7 +44,7 @@ const start = async (api) => {
|
|
44
44
|
runMode
|
45
45
|
});
|
46
46
|
app.listen(port, async () => {
|
47
|
-
await
|
47
|
+
await printInstructions(hooks, appContext, userConfig);
|
48
48
|
});
|
49
49
|
};
|
50
50
|
export {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getModifyHtmlPartials } from "
|
1
|
+
import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
|
2
2
|
import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
|
3
3
|
function getHookRunners(context) {
|
4
4
|
const { hooks } = context;
|
@@ -110,14 +110,14 @@ function getHookRunners(context) {
|
|
110
110
|
/**
|
111
111
|
* @deprecated
|
112
112
|
*/
|
113
|
-
registerDev: async (
|
114
|
-
return hooks.registerDev.call(
|
113
|
+
registerDev: async () => {
|
114
|
+
return hooks.registerDev.call();
|
115
115
|
},
|
116
116
|
/**
|
117
117
|
* @deprecated
|
118
118
|
*/
|
119
|
-
registerBuildPlatform: async (
|
120
|
-
return hooks.registerBuildPlatform.call(
|
119
|
+
registerBuildPlatform: async () => {
|
120
|
+
return hooks.registerBuildPlatform.call();
|
121
121
|
},
|
122
122
|
/**
|
123
123
|
* @deprecated
|
@@ -4,7 +4,12 @@ function createDefaultConfig(appContext) {
|
|
4
4
|
const dev = {
|
5
5
|
// `dev.port` should not have a default value
|
6
6
|
// because we will use `server.port` by default
|
7
|
-
port: void 0
|
7
|
+
port: void 0,
|
8
|
+
cliShortcuts: {
|
9
|
+
help: false,
|
10
|
+
// does not support restart server and print urls yet
|
11
|
+
custom: (shortcuts = []) => shortcuts.filter(({ key }) => key !== "r" && key !== "u")
|
12
|
+
}
|
8
13
|
};
|
9
14
|
const output = {
|
10
15
|
distPath: {
|