@modern-js/app-tools 2.62.2-alpha.0 → 2.63.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/modern.js +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 +20 -8
- package/dist/cjs/{new/compat → compat}/index.js +10 -2
- package/dist/cjs/{new/compat → compat}/utils.js +10 -1
- package/dist/cjs/index.js +156 -7
- package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
- package/dist/cjs/plugins/analyze/index.js +128 -130
- package/dist/cjs/plugins/deploy/index.js +12 -14
- package/dist/cjs/plugins/initialize/index.js +44 -50
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new/types/index.js → types/new.js} +2 -2
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +5 -5
- 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 -2
- package/dist/cjs/utils/restart.js +4 -3
- package/dist/esm/commands/build.js +18 -12
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +10 -10
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +5 -5
- package/dist/esm/{new/compat → compat}/hooks.js +65 -41
- package/dist/esm/{new/compat → compat}/index.js +13 -2
- package/dist/{esm-node/new → esm}/compat/utils.js +10 -1
- package/dist/esm/index.js +248 -5
- package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
- package/dist/esm/plugins/analyze/index.js +328 -331
- package/dist/esm/plugins/deploy/index.js +84 -88
- package/dist/esm/plugins/initialize/index.js +61 -64
- 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/context.js → utils/initAppContext.js} +3 -3
- 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 +3 -3
- package/dist/esm/utils/restart.js +5 -4
- 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 +11 -11
- 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 +4 -4
- package/dist/esm-node/{new/compat → compat}/hooks.js +20 -8
- package/dist/esm-node/{new/compat → compat}/index.js +10 -2
- package/dist/{esm/new → esm-node}/compat/utils.js +10 -1
- package/dist/esm-node/index.js +143 -5
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
- package/dist/esm-node/plugins/analyze/index.js +128 -130
- package/dist/esm-node/plugins/deploy/index.js +12 -14
- package/dist/esm-node/plugins/initialize/index.js +44 -50
- 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/context.js → utils/initAppContext.js} +3 -3
- 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 +2 -2
- package/dist/esm-node/utils/restart.js +4 -3
- package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
- package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
- package/dist/types/builder/shared/types.d.ts +3 -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/compat/hooks.d.ts +7 -0
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/config/default.d.ts +4 -3
- package/dist/types/config/initialize/index.d.ts +3 -2
- package/dist/types/config/initialize/inits.d.ts +4 -3
- package/dist/types/index.d.ts +8 -5
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
- package/dist/types/plugins/analyze/index.d.ts +2 -3
- package/dist/types/plugins/deploy/index.d.ts +2 -3
- package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
- package/dist/types/plugins/deploy/utils.d.ts +2 -2
- package/dist/types/plugins/initialize/index.d.ts +2 -2
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/index.d.ts +7 -3
- package/dist/types/types/new.d.ts +157 -0
- package/dist/types/utils/env.d.ts +2 -2
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
- 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 +3 -3
- package/dist/types/utils/restart.d.ts +2 -3
- package/dist/types/utils/routes.d.ts +2 -1
- package/lib/types.d.ts +82 -61
- package/package.json +24 -24
- 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/hooks.d.ts +0 -8
- package/dist/types/new/compat/index.d.ts +0 -4
- package/dist/types/new/index.d.ts +0 -9
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/types/index.d.ts +0 -90
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -13
- /package/dist/cjs/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/types/index.js → types/new.js} +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/types/index.js → types/new.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
|
@@ -26,26 +26,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var initAppContext_exports = {};
|
|
30
|
+
__export(initAppContext_exports, {
|
|
31
31
|
initAppContext: () => initAppContext
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(initAppContext_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
36
|
const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir }) => {
|
|
37
37
|
const { metaName = "modern-js", apiDir = "api", distDir = "", sharedDir = "shared" } = options || {};
|
|
38
|
+
const pkgPath = import_path.default.resolve(appDirectory, "./package.json");
|
|
38
39
|
return {
|
|
39
40
|
metaName,
|
|
40
41
|
runtimeConfigFile,
|
|
41
42
|
serverConfigFile,
|
|
42
43
|
ip: import_utils.address.ip(),
|
|
43
44
|
port: 0,
|
|
44
|
-
moduleType:
|
|
45
|
+
moduleType: import_utils.fs.existsSync(pkgPath) ? require(pkgPath).type || "commonjs" : "commonjs",
|
|
45
46
|
apiDirectory: import_path.default.resolve(appDirectory, apiDir),
|
|
46
47
|
lambdaDirectory: import_path.default.resolve(appDirectory, apiDir, "lambda"),
|
|
47
48
|
sharedDirectory: import_path.default.resolve(appDirectory, sharedDir),
|
|
48
|
-
distDirectory: distDir,
|
|
49
49
|
serverPlugins: [],
|
|
50
50
|
internalDirectory: import_path.default.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
|
|
51
51
|
htmlTemplates: {},
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var isAutoLoadPlugins_exports = {};
|
|
20
|
+
__export(isAutoLoadPlugins_exports, {
|
|
21
|
+
isAutoLoadPlugins: () => isAutoLoadPlugins
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(isAutoLoadPlugins_exports);
|
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
|
25
|
-
async function
|
|
25
|
+
async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
|
|
26
26
|
var _loaded_config;
|
|
27
27
|
const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
|
|
28
28
|
const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
|
|
@@ -30,5 +30,5 @@ async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts
|
|
|
30
30
|
}
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
|
-
|
|
33
|
+
isAutoLoadPlugins
|
|
34
34
|
});
|
|
@@ -19,18 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var loadPlugins_exports = {};
|
|
20
20
|
__export(loadPlugins_exports, {
|
|
21
21
|
getServerPlugins: () => getServerPlugins,
|
|
22
|
+
loadInternalPlugins: () => loadInternalPlugins,
|
|
22
23
|
loadServerPlugins: () => loadServerPlugins
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(loadPlugins_exports);
|
|
25
26
|
var import_prod_server = require("@modern-js/prod-server");
|
|
27
|
+
var import_utils = require("@modern-js/utils");
|
|
28
|
+
const debug = (0, import_utils.createDebugger)("load-plugins");
|
|
26
29
|
async function getServerPlugins(api, metaName = "modern-js") {
|
|
27
|
-
const
|
|
28
|
-
const { plugins } = await
|
|
30
|
+
const hooks = api.getHooks();
|
|
31
|
+
const { plugins } = await hooks._internalServerPlugins.call({
|
|
29
32
|
plugins: []
|
|
30
33
|
});
|
|
31
34
|
const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
|
|
32
|
-
api.
|
|
33
|
-
...api.useAppContext(),
|
|
35
|
+
api.updateAppContext({
|
|
34
36
|
serverPlugins: filtedPlugins
|
|
35
37
|
});
|
|
36
38
|
return filtedPlugins;
|
|
@@ -40,8 +42,37 @@ async function loadServerPlugins(api, appDirectory, metaName) {
|
|
|
40
42
|
const instances = await (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
|
|
41
43
|
return instances;
|
|
42
44
|
}
|
|
45
|
+
const resolveCliPlugin = async (p, appDirectory) => {
|
|
46
|
+
const pkg = typeof p === "string" ? p : p[0];
|
|
47
|
+
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
|
48
|
+
const path = (0, import_utils.tryResolve)(pkg, appDirectory);
|
|
49
|
+
let module2;
|
|
50
|
+
try {
|
|
51
|
+
module2 = await (0, import_utils.compatibleRequire)(path);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
({ default: module2 } = await (0, import_utils.dynamicImport)(path));
|
|
54
|
+
}
|
|
55
|
+
if (typeof module2 === "function") {
|
|
56
|
+
const result = module2(pluginOptions);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
return module2;
|
|
60
|
+
};
|
|
61
|
+
const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
|
|
62
|
+
const plugins = [
|
|
63
|
+
...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
|
|
64
|
+
...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
|
|
65
|
+
];
|
|
66
|
+
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
|
67
|
+
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
|
68
|
+
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
|
69
|
+
return loadedPlugin;
|
|
70
|
+
}));
|
|
71
|
+
return loadedPlugins;
|
|
72
|
+
};
|
|
43
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
74
|
0 && (module.exports = {
|
|
45
75
|
getServerPlugins,
|
|
76
|
+
loadInternalPlugins,
|
|
46
77
|
loadServerPlugins
|
|
47
78
|
});
|
|
@@ -22,9 +22,9 @@ __export(printInstructions_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(printInstructions_exports);
|
|
24
24
|
var import_utils = require("@modern-js/utils");
|
|
25
|
-
const printInstructions = async (
|
|
25
|
+
const printInstructions = async (hooks, appContext, config) => {
|
|
26
26
|
const message = (0, import_utils.prettyInstructions)(appContext, config);
|
|
27
|
-
const { instructions } = await
|
|
27
|
+
const { instructions } = await hooks.onBeforePrintInstructions.call({
|
|
28
28
|
instructions: message
|
|
29
29
|
});
|
|
30
30
|
import_utils.logger.log(instructions);
|
|
@@ -23,12 +23,13 @@ __export(restart_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(restart_exports);
|
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
|
25
25
|
var import_utils = require("@modern-js/utils");
|
|
26
|
-
|
|
26
|
+
var import_commander = require("@modern-js/utils/commander");
|
|
27
|
+
async function restart(hooks, filename) {
|
|
27
28
|
(0, import_utils.clearConsole)();
|
|
28
29
|
import_utils.logger.info(`Restart because ${import_utils.chalk.yellow(filename)} is changed...
|
|
29
30
|
`);
|
|
30
31
|
let hasGetError = false;
|
|
31
|
-
await
|
|
32
|
+
await hooks.onBeforeRestart.call();
|
|
32
33
|
try {
|
|
33
34
|
await import_cli.cli.init(import_cli.cli.getPrevInitOptions());
|
|
34
35
|
} catch (err) {
|
|
@@ -36,7 +37,7 @@ async function restart(hooksRunner, filename) {
|
|
|
36
37
|
hasGetError = true;
|
|
37
38
|
} finally {
|
|
38
39
|
if (!hasGetError) {
|
|
39
|
-
|
|
40
|
+
import_commander.program.parse((0, import_utils.getFullArgv)());
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -2,7 +2,6 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import { ResolvedConfigContext } from "@modern-js/core";
|
|
6
5
|
import { logger } from "@modern-js/utils";
|
|
7
6
|
import { buildServerConfig } from "../utils/config";
|
|
8
7
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
@@ -10,16 +9,16 @@ import { registerCompiler } from "../utils/register";
|
|
|
10
9
|
import { generateRoutes } from "../utils/routes";
|
|
11
10
|
var build = function() {
|
|
12
11
|
var _ref = _async_to_generator(function(api, options) {
|
|
13
|
-
var _resolvedConfig_source, resolvedConfig, appContext,
|
|
12
|
+
var _resolvedConfig_source, resolvedConfig, appContext, hooks, _resolvedConfig_source1, registerEsm, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
|
|
14
13
|
return _ts_generator(this, function(_state) {
|
|
15
14
|
switch (_state.label) {
|
|
16
15
|
case 0:
|
|
17
16
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
|
18
17
|
process.env.BUNDLE_ANALYZE = "true";
|
|
19
18
|
}
|
|
20
|
-
resolvedConfig = api.
|
|
21
|
-
appContext = api.
|
|
22
|
-
|
|
19
|
+
resolvedConfig = api.getNormalizedConfig();
|
|
20
|
+
appContext = api.getAppContext();
|
|
21
|
+
hooks = api.getHooks();
|
|
23
22
|
return [
|
|
24
23
|
4,
|
|
25
24
|
loadServerPlugins(api, appContext.appDirectory, appContext.metaName)
|
|
@@ -64,9 +63,12 @@ var build = function() {
|
|
|
64
63
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
|
|
65
64
|
return [
|
|
66
65
|
4,
|
|
67
|
-
|
|
66
|
+
hooks.onBeforeBuild.call({
|
|
67
|
+
environments: {},
|
|
68
68
|
// "null" bundlerConfigs
|
|
69
|
-
bundlerConfigs: void 0
|
|
69
|
+
bundlerConfigs: void 0,
|
|
70
|
+
isFirstCompile: false,
|
|
71
|
+
isWatch: false
|
|
70
72
|
})
|
|
71
73
|
];
|
|
72
74
|
case 6:
|
|
@@ -89,9 +91,12 @@ var build = function() {
|
|
|
89
91
|
_state.sent();
|
|
90
92
|
return [
|
|
91
93
|
4,
|
|
92
|
-
|
|
94
|
+
hooks.onAfterBuild.call({
|
|
95
|
+
environments: {},
|
|
93
96
|
// "null" stats
|
|
94
|
-
stats: void 0
|
|
97
|
+
stats: void 0,
|
|
98
|
+
isFirstCompile: false,
|
|
99
|
+
isWatch: false
|
|
95
100
|
})
|
|
96
101
|
];
|
|
97
102
|
case 9:
|
|
@@ -100,10 +105,11 @@ var build = function() {
|
|
|
100
105
|
2
|
|
101
106
|
];
|
|
102
107
|
case 10:
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
api.modifyResolvedConfig(function(config) {
|
|
109
|
+
return _object_spread_props(_object_spread({}, config), {
|
|
110
|
+
cliOptions: options
|
|
111
|
+
});
|
|
105
112
|
});
|
|
106
|
-
ResolvedConfigContext.set(resolvedConfig);
|
|
107
113
|
distDirectory1 = appContext.distDirectory, appDirectory1 = appContext.appDirectory, serverConfigFile1 = appContext.serverConfigFile;
|
|
108
114
|
return [
|
|
109
115
|
4,
|
|
@@ -3,12 +3,12 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
3
3
|
import { getServerPlugins } from "../utils/loadPlugins";
|
|
4
4
|
var deploy = function() {
|
|
5
5
|
var _ref = _async_to_generator(function(api, options) {
|
|
6
|
-
var
|
|
6
|
+
var hooks, metaName;
|
|
7
7
|
return _ts_generator(this, function(_state) {
|
|
8
8
|
switch (_state.label) {
|
|
9
9
|
case 0:
|
|
10
|
-
|
|
11
|
-
metaName = api.
|
|
10
|
+
hooks = api.getHooks();
|
|
11
|
+
metaName = api.getAppContext().metaName;
|
|
12
12
|
return [
|
|
13
13
|
4,
|
|
14
14
|
getServerPlugins(api, metaName)
|
|
@@ -17,19 +17,19 @@ var deploy = function() {
|
|
|
17
17
|
_state.sent();
|
|
18
18
|
return [
|
|
19
19
|
4,
|
|
20
|
-
|
|
20
|
+
hooks.onBeforeDeploy.call(options)
|
|
21
21
|
];
|
|
22
22
|
case 2:
|
|
23
23
|
_state.sent();
|
|
24
24
|
return [
|
|
25
25
|
4,
|
|
26
|
-
|
|
26
|
+
hooks.deploy.call()
|
|
27
27
|
];
|
|
28
28
|
case 3:
|
|
29
29
|
_state.sent();
|
|
30
30
|
return [
|
|
31
31
|
4,
|
|
32
|
-
|
|
32
|
+
hooks.onAfterDeploy.call(options)
|
|
33
33
|
];
|
|
34
34
|
case 4:
|
|
35
35
|
_state.sent();
|
package/dist/esm/commands/dev.js
CHANGED
|
@@ -3,7 +3,6 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { ResolvedConfigContext } from "@modern-js/core";
|
|
7
6
|
import { applyPlugins } from "@modern-js/prod-server";
|
|
8
7
|
import { createDevServer } from "@modern-js/server";
|
|
9
8
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
|
@@ -15,16 +14,16 @@ import { registerCompiler } from "../utils/register";
|
|
|
15
14
|
import { generateRoutes } from "../utils/routes";
|
|
16
15
|
var dev = function() {
|
|
17
16
|
var _ref = _async_to_generator(function(api, options, devServerOptions) {
|
|
18
|
-
var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext,
|
|
17
|
+
var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hooks, _normalizedConfig_source1, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, host, server, _ref2, server1, afterListen;
|
|
19
18
|
return _ts_generator(this, function(_state) {
|
|
20
19
|
switch (_state.label) {
|
|
21
20
|
case 0:
|
|
22
21
|
if (options.analyze) {
|
|
23
22
|
process.env.BUNDLE_ANALYZE = "true";
|
|
24
23
|
}
|
|
25
|
-
normalizedConfig = api.
|
|
26
|
-
appContext = api.
|
|
27
|
-
|
|
24
|
+
normalizedConfig = api.getNormalizedConfig();
|
|
25
|
+
appContext = api.getAppContext();
|
|
26
|
+
hooks = api.getHooks();
|
|
28
27
|
if (!(appContext.moduleType && appContext.moduleType === "module"))
|
|
29
28
|
return [
|
|
30
29
|
3,
|
|
@@ -54,10 +53,11 @@ var dev = function() {
|
|
|
54
53
|
];
|
|
55
54
|
case 4:
|
|
56
55
|
_state.sent();
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
api.modifyResolvedConfig(function(config) {
|
|
57
|
+
return _object_spread_props(_object_spread({}, config), {
|
|
58
|
+
cliOptions: options
|
|
59
|
+
});
|
|
59
60
|
});
|
|
60
|
-
ResolvedConfigContext.set(normalizedConfig);
|
|
61
61
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
|
|
62
62
|
return [
|
|
63
63
|
4,
|
|
@@ -74,7 +74,7 @@ var dev = function() {
|
|
|
74
74
|
serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
|
|
75
75
|
return [
|
|
76
76
|
4,
|
|
77
|
-
|
|
77
|
+
hooks.onBeforeDev.call()
|
|
78
78
|
];
|
|
79
79
|
case 6:
|
|
80
80
|
_state.sent();
|
|
@@ -132,7 +132,7 @@ var dev = function() {
|
|
|
132
132
|
port,
|
|
133
133
|
host
|
|
134
134
|
}, function() {
|
|
135
|
-
printInstructions(
|
|
135
|
+
printInstructions(hooks, appContext, normalizedConfig);
|
|
136
136
|
});
|
|
137
137
|
return [
|
|
138
138
|
3,
|
|
@@ -7,14 +7,14 @@ import { newAction, upgradeAction } from "@modern-js/utils";
|
|
|
7
7
|
import { i18n, localeKeys } from "../locale";
|
|
8
8
|
var devCommand = function() {
|
|
9
9
|
var _ref = _async_to_generator(function(program, api) {
|
|
10
|
-
var
|
|
10
|
+
var hooks, devToolMetas, devProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
|
|
11
11
|
return _ts_generator(this, function(_state) {
|
|
12
12
|
switch (_state.label) {
|
|
13
13
|
case 0:
|
|
14
|
-
|
|
14
|
+
hooks = api.getHooks();
|
|
15
15
|
return [
|
|
16
16
|
4,
|
|
17
|
-
|
|
17
|
+
hooks.registerDev.call()
|
|
18
18
|
];
|
|
19
19
|
case 1:
|
|
20
20
|
devToolMetas = _state.sent();
|
|
@@ -64,7 +64,7 @@ var devCommand = function() {
|
|
|
64
64
|
switch (_state2.label) {
|
|
65
65
|
case 0:
|
|
66
66
|
options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {};
|
|
67
|
-
appDirectory = api.
|
|
67
|
+
appDirectory = api.getAppContext().appDirectory;
|
|
68
68
|
return [
|
|
69
69
|
4,
|
|
70
70
|
import("@modern-js/utils")
|
|
@@ -129,14 +129,14 @@ var devCommand = function() {
|
|
|
129
129
|
}();
|
|
130
130
|
var buildCommand = function() {
|
|
131
131
|
var _ref = _async_to_generator(function(program, api) {
|
|
132
|
-
var
|
|
132
|
+
var hooks, platformBuilders, buildProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
|
|
133
133
|
return _ts_generator(this, function(_state) {
|
|
134
134
|
switch (_state.label) {
|
|
135
135
|
case 0:
|
|
136
|
-
|
|
136
|
+
hooks = api.getHooks();
|
|
137
137
|
return [
|
|
138
138
|
4,
|
|
139
|
-
|
|
139
|
+
hooks.registerBuildPlatform.call()
|
|
140
140
|
];
|
|
141
141
|
case 1:
|
|
142
142
|
platformBuilders = _state.sent();
|
|
@@ -182,7 +182,7 @@ var buildCommand = function() {
|
|
|
182
182
|
return _ts_generator(this, function(_state2) {
|
|
183
183
|
switch (_state2.label) {
|
|
184
184
|
case 0:
|
|
185
|
-
appDirectory = api.
|
|
185
|
+
appDirectory = api.getAppContext().appDirectory;
|
|
186
186
|
return [
|
|
187
187
|
4,
|
|
188
188
|
import("@modern-js/utils")
|
|
@@ -4,7 +4,7 @@ var inspect = function() {
|
|
|
4
4
|
var _ref = _async_to_generator(function(api, options) {
|
|
5
5
|
var appContext;
|
|
6
6
|
return _ts_generator(this, function(_state) {
|
|
7
|
-
appContext = api.
|
|
7
|
+
appContext = api.getAppContext();
|
|
8
8
|
if (!appContext.builder) {
|
|
9
9
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
10
10
|
}
|
|
@@ -9,13 +9,13 @@ import { loadServerPlugins } from "../utils/loadPlugins";
|
|
|
9
9
|
import { printInstructions } from "../utils/printInstructions";
|
|
10
10
|
var start = function() {
|
|
11
11
|
var _ref = _async_to_generator(function(api) {
|
|
12
|
-
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig,
|
|
12
|
+
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hooks, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
|
|
13
13
|
return _ts_generator(this, function(_state) {
|
|
14
14
|
switch (_state.label) {
|
|
15
15
|
case 0:
|
|
16
|
-
appContext = api.
|
|
17
|
-
userConfig = api.
|
|
18
|
-
|
|
16
|
+
appContext = api.getAppContext();
|
|
17
|
+
userConfig = api.getNormalizedConfig();
|
|
18
|
+
hooks = api.getHooks();
|
|
19
19
|
distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, internalDirectory = appContext.internalDirectory, port = appContext.port, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes, serverConfigFile = appContext.serverConfigFile;
|
|
20
20
|
logger.info("Starting production server...");
|
|
21
21
|
return [
|
|
@@ -69,7 +69,7 @@ var start = function() {
|
|
|
69
69
|
case 0:
|
|
70
70
|
return [
|
|
71
71
|
4,
|
|
72
|
-
printInstructions(
|
|
72
|
+
printInstructions(hooks, appContext, userConfig)
|
|
73
73
|
];
|
|
74
74
|
case 1:
|
|
75
75
|
_state2.sent();
|
|
@@ -1,5 +1,6 @@
|
|
|
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
|
+
import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
|
|
3
4
|
import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
|
|
4
5
|
function getHookRunners(context) {
|
|
5
6
|
var hooks = context.hooks;
|
|
@@ -148,6 +149,30 @@ function getHookRunners(context) {
|
|
|
148
149
|
return _ref.apply(this, arguments);
|
|
149
150
|
};
|
|
150
151
|
}(),
|
|
152
|
+
// garfish plugin hooks
|
|
153
|
+
appendEntryCode: function() {
|
|
154
|
+
var _ref = _async_to_generator(function(params) {
|
|
155
|
+
var result;
|
|
156
|
+
return _ts_generator(this, function(_state) {
|
|
157
|
+
switch (_state.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
return [
|
|
160
|
+
4,
|
|
161
|
+
hooks === null || hooks === void 0 ? void 0 : hooks.appendEntryCode.call(params)
|
|
162
|
+
];
|
|
163
|
+
case 1:
|
|
164
|
+
result = _state.sent();
|
|
165
|
+
return [
|
|
166
|
+
2,
|
|
167
|
+
result
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
return function(params) {
|
|
173
|
+
return _ref.apply(this, arguments);
|
|
174
|
+
};
|
|
175
|
+
}(),
|
|
151
176
|
/**
|
|
152
177
|
* common hooks
|
|
153
178
|
*/
|
|
@@ -165,10 +190,24 @@ function getHookRunners(context) {
|
|
|
165
190
|
htmlPartials: function() {
|
|
166
191
|
var _ref = _async_to_generator(function(params) {
|
|
167
192
|
return _ts_generator(this, function(_state) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
193
|
+
switch (_state.label) {
|
|
194
|
+
case 0:
|
|
195
|
+
return [
|
|
196
|
+
4,
|
|
197
|
+
hooks.modifyHtmlPartials.call({
|
|
198
|
+
entrypoint: params.entrypoint,
|
|
199
|
+
partials: getModifyHtmlPartials(params.partials)
|
|
200
|
+
})
|
|
201
|
+
];
|
|
202
|
+
case 1:
|
|
203
|
+
_state.sent();
|
|
204
|
+
return [
|
|
205
|
+
2,
|
|
206
|
+
{
|
|
207
|
+
partials: params.partials
|
|
208
|
+
}
|
|
209
|
+
];
|
|
210
|
+
}
|
|
172
211
|
});
|
|
173
212
|
});
|
|
174
213
|
return function(params) {
|
|
@@ -204,7 +243,7 @@ function getHookRunners(context) {
|
|
|
204
243
|
];
|
|
205
244
|
});
|
|
206
245
|
}),
|
|
207
|
-
|
|
246
|
+
fileChange: function() {
|
|
208
247
|
var _ref = _async_to_generator(function(params) {
|
|
209
248
|
return _ts_generator(this, function(_state) {
|
|
210
249
|
return [
|
|
@@ -335,51 +374,36 @@ function getHookRunners(context) {
|
|
|
335
374
|
/**
|
|
336
375
|
* @deprecated
|
|
337
376
|
*/
|
|
338
|
-
registerDev: function() {
|
|
339
|
-
|
|
340
|
-
return
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
];
|
|
345
|
-
});
|
|
377
|
+
registerDev: /* @__PURE__ */ _async_to_generator(function() {
|
|
378
|
+
return _ts_generator(this, function(_state) {
|
|
379
|
+
return [
|
|
380
|
+
2,
|
|
381
|
+
hooks.registerDev.call()
|
|
382
|
+
];
|
|
346
383
|
});
|
|
347
|
-
|
|
348
|
-
return _ref.apply(this, arguments);
|
|
349
|
-
};
|
|
350
|
-
}(),
|
|
384
|
+
}),
|
|
351
385
|
/**
|
|
352
386
|
* @deprecated
|
|
353
387
|
*/
|
|
354
|
-
registerBuildPlatform: function() {
|
|
355
|
-
|
|
356
|
-
return
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
];
|
|
361
|
-
});
|
|
388
|
+
registerBuildPlatform: /* @__PURE__ */ _async_to_generator(function() {
|
|
389
|
+
return _ts_generator(this, function(_state) {
|
|
390
|
+
return [
|
|
391
|
+
2,
|
|
392
|
+
hooks.registerBuildPlatform.call()
|
|
393
|
+
];
|
|
362
394
|
});
|
|
363
|
-
|
|
364
|
-
return _ref.apply(this, arguments);
|
|
365
|
-
};
|
|
366
|
-
}(),
|
|
395
|
+
}),
|
|
367
396
|
/**
|
|
368
397
|
* @deprecated
|
|
369
398
|
*/
|
|
370
|
-
addRuntimeExports: function() {
|
|
371
|
-
|
|
372
|
-
return
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
];
|
|
377
|
-
});
|
|
399
|
+
addRuntimeExports: /* @__PURE__ */ _async_to_generator(function() {
|
|
400
|
+
return _ts_generator(this, function(_state) {
|
|
401
|
+
return [
|
|
402
|
+
2,
|
|
403
|
+
hooks.addRuntimeExports.call()
|
|
404
|
+
];
|
|
378
405
|
});
|
|
379
|
-
|
|
380
|
-
return _ref.apply(this, arguments);
|
|
381
|
-
};
|
|
382
|
-
}()
|
|
406
|
+
})
|
|
383
407
|
};
|
|
384
408
|
}
|
|
385
409
|
function handleSetupResult(setupResult, api) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
2
|
+
import { createCollectAsyncHook } from "@modern-js/plugin-v2";
|
|
1
3
|
import { getHookRunners } from "./hooks";
|
|
2
4
|
var compatPlugin = function() {
|
|
3
5
|
return {
|
|
@@ -8,7 +10,10 @@ var compatPlugin = function() {
|
|
|
8
10
|
};
|
|
9
11
|
return {
|
|
10
12
|
useAppContext: function() {
|
|
11
|
-
|
|
13
|
+
var _getAppContext = getAppContext(), _internalContext = _getAppContext._internalContext, appContext = _object_without_properties(_getAppContext, [
|
|
14
|
+
"_internalContext"
|
|
15
|
+
]);
|
|
16
|
+
return appContext;
|
|
12
17
|
},
|
|
13
18
|
setAppContext: function(context) {
|
|
14
19
|
return updateAppContext(context);
|
|
@@ -24,7 +29,13 @@ var compatPlugin = function() {
|
|
|
24
29
|
}
|
|
25
30
|
};
|
|
26
31
|
},
|
|
27
|
-
|
|
32
|
+
registryHooks: {
|
|
33
|
+
appendEntryCode: createCollectAsyncHook()
|
|
34
|
+
},
|
|
35
|
+
setup: function(api) {
|
|
36
|
+
api.updateAppContext({
|
|
37
|
+
toolsType: "app-tools"
|
|
38
|
+
});
|
|
28
39
|
}
|
|
29
40
|
};
|
|
30
41
|
};
|
|
@@ -16,7 +16,7 @@ function transformHookRunner(hookRunnerName) {
|
|
|
16
16
|
return "addCommand";
|
|
17
17
|
case "watchFiles":
|
|
18
18
|
return "addWatchFiles";
|
|
19
|
-
case "
|
|
19
|
+
case "fileChange":
|
|
20
20
|
return "onFileChanged";
|
|
21
21
|
case "beforeCreateCompiler":
|
|
22
22
|
return "onBeforeCreateCompiler";
|
|
@@ -50,6 +50,15 @@ function transformHookParams(hookRunnerName, params) {
|
|
|
50
50
|
return {
|
|
51
51
|
resolved: params
|
|
52
52
|
};
|
|
53
|
+
case "htmlPartials":
|
|
54
|
+
return {
|
|
55
|
+
partials: {
|
|
56
|
+
top: params.partials.top.current,
|
|
57
|
+
head: params.partials.head.current,
|
|
58
|
+
body: params.partials.body.current
|
|
59
|
+
},
|
|
60
|
+
entrypoint: params.entrypoint
|
|
61
|
+
};
|
|
53
62
|
default:
|
|
54
63
|
return params;
|
|
55
64
|
}
|