@modern-js/app-tools 2.63.1 → 2.63.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/modern.js +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 +21 -6
- package/dist/cjs/{new/compat → compat}/index.js +7 -2
- package/dist/cjs/{new/compat → compat}/utils.js +29 -8
- 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/deploy/platforms/netlify.js +7 -4
- package/dist/cjs/plugins/deploy/platforms/node.js +6 -3
- package/dist/cjs/plugins/deploy/platforms/vercel.js +7 -4
- 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 +98 -49
- package/dist/esm/{new/compat → compat}/index.js +8 -3
- package/dist/esm/{new/compat → compat}/utils.js +29 -8
- 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/deploy/platforms/netlify.js +6 -3
- package/dist/esm/plugins/deploy/platforms/node.js +5 -2
- package/dist/esm/plugins/deploy/platforms/vercel.js +6 -3
- 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 +21 -6
- package/dist/esm-node/{new/compat → compat}/index.js +8 -3
- package/dist/esm-node/{new/compat → compat}/utils.js +29 -8
- 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/deploy/platforms/netlify.js +6 -3
- package/dist/esm-node/plugins/deploy/platforms/node.js +5 -2
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -3
- 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/{new/compat → compat}/utils.d.ts +8 -1
- 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 +24 -28
- 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/cjs/plugins/deploy/dependencies/index.js +0 -237
- package/dist/cjs/plugins/deploy/dependencies/utils.js +0 -179
- package/dist/cjs/plugins/deploy/exports.js +0 -28
- 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/plugins/deploy/dependencies/index.js +0 -615
- package/dist/esm/plugins/deploy/dependencies/utils.js +0 -421
- package/dist/esm/plugins/deploy/exports.js +0 -4
- 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/esm-node/plugins/deploy/dependencies/index.js +0 -202
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -137
- package/dist/esm-node/plugins/deploy/exports.js +0 -4
- 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/types/plugins/deploy/dependencies/index.d.ts +0 -20
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +0 -44
- package/dist/types/plugins/deploy/exports.d.ts +0 -1
- /package/dist/cjs/{new/constants.js → constants.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/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +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
|
@@ -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;
|
|
@@ -47,6 +47,14 @@ function getHookRunners(context) {
|
|
|
47
47
|
const result = await (hooks === null || hooks === void 0 ? void 0 : hooks.appendEntryCode.call(params));
|
|
48
48
|
return result;
|
|
49
49
|
},
|
|
50
|
+
// test plugin hooks
|
|
51
|
+
jestConfig: async (utils) => {
|
|
52
|
+
const result = await (hooks === null || hooks === void 0 ? void 0 : hooks.jestConfig.call(utils, (utils2) => utils2));
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
afterTest: async () => {
|
|
56
|
+
return hooks.afterTest.call();
|
|
57
|
+
},
|
|
50
58
|
/**
|
|
51
59
|
* common hooks
|
|
52
60
|
*/
|
|
@@ -110,14 +118,14 @@ function getHookRunners(context) {
|
|
|
110
118
|
/**
|
|
111
119
|
* @deprecated
|
|
112
120
|
*/
|
|
113
|
-
registerDev: async (
|
|
114
|
-
return hooks.registerDev.call(
|
|
121
|
+
registerDev: async () => {
|
|
122
|
+
return hooks.registerDev.call();
|
|
115
123
|
},
|
|
116
124
|
/**
|
|
117
125
|
* @deprecated
|
|
118
126
|
*/
|
|
119
|
-
registerBuildPlatform: async (
|
|
120
|
-
return hooks.registerBuildPlatform.call(
|
|
127
|
+
registerBuildPlatform: async () => {
|
|
128
|
+
return hooks.registerBuildPlatform.call();
|
|
121
129
|
},
|
|
122
130
|
/**
|
|
123
131
|
* @deprecated
|
|
@@ -136,7 +144,14 @@ function handleSetupResult(setupResult, api) {
|
|
|
136
144
|
if (typeof fn === "function") {
|
|
137
145
|
const newAPI = transformHookRunner(key);
|
|
138
146
|
if (api[newAPI]) {
|
|
139
|
-
api[newAPI](async (params) =>
|
|
147
|
+
api[newAPI](async (...params) => {
|
|
148
|
+
const { isMultiple, params: transformParams } = transformHookParams(key, params);
|
|
149
|
+
if (isMultiple) {
|
|
150
|
+
return transformHookResult(key, await fn(...transformParams));
|
|
151
|
+
} else {
|
|
152
|
+
return transformHookResult(key, await fn(transformParams));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
140
155
|
}
|
|
141
156
|
}
|
|
142
157
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCollectAsyncHook } from "@modern-js/plugin-v2";
|
|
1
|
+
import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
|
|
2
2
|
import { getHookRunners } from "./hooks";
|
|
3
3
|
const compatPlugin = () => ({
|
|
4
4
|
name: "@modern-js/app-tools-compat",
|
|
@@ -26,9 +26,14 @@ const compatPlugin = () => ({
|
|
|
26
26
|
};
|
|
27
27
|
},
|
|
28
28
|
registryHooks: {
|
|
29
|
-
appendEntryCode: createCollectAsyncHook()
|
|
29
|
+
appendEntryCode: createCollectAsyncHook(),
|
|
30
|
+
jestConfig: createAsyncHook(),
|
|
31
|
+
afterTest: createAsyncHook()
|
|
30
32
|
},
|
|
31
|
-
setup: (
|
|
33
|
+
setup: (api) => {
|
|
34
|
+
api.updateAppContext({
|
|
35
|
+
toolsType: "app-tools"
|
|
36
|
+
});
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
39
|
export {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
|
|
1
2
|
function transformHookRunner(hookRunnerName) {
|
|
2
3
|
switch (hookRunnerName) {
|
|
3
4
|
case "beforeConfig":
|
|
@@ -48,25 +49,45 @@ function transformHookParams(hookRunnerName, params) {
|
|
|
48
49
|
switch (hookRunnerName) {
|
|
49
50
|
case "resolvedConfig":
|
|
50
51
|
return {
|
|
51
|
-
|
|
52
|
+
isMultiple: false,
|
|
53
|
+
params: {
|
|
54
|
+
resolved: params[0]
|
|
55
|
+
}
|
|
52
56
|
};
|
|
53
57
|
case "htmlPartials":
|
|
54
58
|
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
isMultiple: false,
|
|
60
|
+
params: {
|
|
61
|
+
partials: {
|
|
62
|
+
top: params[0].partials.top.current,
|
|
63
|
+
head: params[0].partials.head.current,
|
|
64
|
+
body: params[0].partials.body.current
|
|
65
|
+
},
|
|
66
|
+
entrypoint: params[0].entrypoint
|
|
67
|
+
}
|
|
61
68
|
};
|
|
69
|
+
case "jestConfig": {
|
|
70
|
+
return {
|
|
71
|
+
isMultiple: true,
|
|
72
|
+
params
|
|
73
|
+
};
|
|
74
|
+
}
|
|
62
75
|
default:
|
|
63
|
-
return
|
|
76
|
+
return {
|
|
77
|
+
isMultiple: false,
|
|
78
|
+
params: params[0]
|
|
79
|
+
};
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
82
|
function transformHookResult(hookRunnerName, result) {
|
|
67
83
|
switch (hookRunnerName) {
|
|
68
84
|
case "resolvedConfig":
|
|
69
85
|
return result.resolved;
|
|
86
|
+
case "htmlPartials":
|
|
87
|
+
return {
|
|
88
|
+
partials: getModifyHtmlPartials(result.partials),
|
|
89
|
+
entrypoint: result.entrypoint
|
|
90
|
+
};
|
|
70
91
|
default:
|
|
71
92
|
return result;
|
|
72
93
|
}
|
|
@@ -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: {
|