@modern-js/app-tools 2.63.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.
Files changed (135) hide show
  1. package/bin/modern.js +1 -1
  2. package/dist/cjs/commands/build.js +19 -13
  3. package/dist/cjs/commands/deploy.js +5 -5
  4. package/dist/cjs/commands/dev.js +11 -11
  5. package/dist/cjs/commands/index.js +6 -6
  6. package/dist/cjs/commands/inspect.js +1 -1
  7. package/dist/cjs/commands/serve.js +4 -4
  8. package/dist/cjs/{new/compat → compat}/hooks.js +15 -8
  9. package/dist/cjs/{new/compat → compat}/index.js +4 -1
  10. package/dist/cjs/{new/compat → compat}/utils.js +10 -1
  11. package/dist/cjs/index.js +154 -5
  12. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
  13. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
  14. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
  15. package/dist/cjs/plugins/analyze/index.js +128 -130
  16. package/dist/cjs/plugins/deploy/index.js +12 -14
  17. package/dist/cjs/plugins/initialize/index.js +1 -1
  18. package/dist/cjs/plugins/serverBuild.js +30 -32
  19. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  20. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  21. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -4
  22. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  23. package/dist/cjs/utils/loadPlugins.js +35 -4
  24. package/dist/cjs/utils/printInstructions.js +2 -2
  25. package/dist/cjs/utils/restart.js +4 -3
  26. package/dist/esm/commands/build.js +18 -12
  27. package/dist/esm/commands/deploy.js +6 -6
  28. package/dist/esm/commands/dev.js +10 -10
  29. package/dist/esm/commands/index.js +8 -8
  30. package/dist/esm/commands/inspect.js +1 -1
  31. package/dist/esm/commands/serve.js +5 -5
  32. package/dist/esm/{new/compat → compat}/hooks.js +41 -41
  33. package/dist/esm/{new/compat → compat}/index.js +4 -1
  34. package/dist/esm/{new/compat → compat}/utils.js +10 -1
  35. package/dist/esm/index.js +245 -2
  36. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  37. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  38. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  39. package/dist/esm/plugins/analyze/index.js +328 -331
  40. package/dist/esm/plugins/deploy/index.js +84 -88
  41. package/dist/esm/plugins/initialize/index.js +1 -1
  42. package/dist/esm/plugins/serverBuild.js +52 -56
  43. package/dist/esm/{new/run.js → run/index.js} +6 -6
  44. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  45. package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -1
  46. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  47. package/dist/esm/utils/loadPlugins.js +95 -7
  48. package/dist/esm/utils/printInstructions.js +3 -3
  49. package/dist/esm/utils/restart.js +5 -4
  50. package/dist/esm-node/commands/build.js +19 -13
  51. package/dist/esm-node/commands/deploy.js +5 -5
  52. package/dist/esm-node/commands/dev.js +11 -11
  53. package/dist/esm-node/commands/index.js +6 -6
  54. package/dist/esm-node/commands/inspect.js +1 -1
  55. package/dist/esm-node/commands/serve.js +4 -4
  56. package/dist/esm-node/{new/compat → compat}/hooks.js +15 -8
  57. package/dist/esm-node/{new/compat → compat}/index.js +4 -1
  58. package/dist/esm-node/{new/compat → compat}/utils.js +10 -1
  59. package/dist/esm-node/index.js +140 -2
  60. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  61. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  62. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  63. package/dist/esm-node/plugins/analyze/index.js +128 -130
  64. package/dist/esm-node/plugins/deploy/index.js +12 -14
  65. package/dist/esm-node/plugins/initialize/index.js +1 -1
  66. package/dist/esm-node/plugins/serverBuild.js +30 -32
  67. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  68. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  69. package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -1
  70. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  71. package/dist/esm-node/utils/loadPlugins.js +34 -4
  72. package/dist/esm-node/utils/printInstructions.js +2 -2
  73. package/dist/esm-node/utils/restart.js +4 -3
  74. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  75. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  76. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  77. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  78. package/dist/types/builder/index.d.ts +1 -1
  79. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  80. package/dist/types/builder/shared/types.d.ts +3 -2
  81. package/dist/types/commands/build.d.ts +2 -2
  82. package/dist/types/commands/deploy.d.ts +2 -2
  83. package/dist/types/commands/dev.d.ts +2 -2
  84. package/dist/types/commands/index.d.ts +6 -6
  85. package/dist/types/commands/inspect.d.ts +2 -2
  86. package/dist/types/commands/serve.d.ts +2 -2
  87. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  88. package/dist/types/compat/index.d.ts +2 -0
  89. package/dist/types/config/initialize/index.d.ts +3 -2
  90. package/dist/types/config/initialize/inits.d.ts +4 -3
  91. package/dist/types/index.d.ts +5 -3
  92. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  93. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  94. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  95. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  96. package/dist/types/plugins/analyze/index.d.ts +2 -3
  97. package/dist/types/plugins/deploy/index.d.ts +2 -3
  98. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  99. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  100. package/dist/types/plugins/serverBuild.d.ts +2 -2
  101. package/dist/types/types/index.d.ts +2 -0
  102. package/dist/types/types/new.d.ts +46 -34
  103. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  104. package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
  105. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  106. package/dist/types/utils/loadPlugins.d.ts +13 -3
  107. package/dist/types/utils/printInstructions.d.ts +3 -3
  108. package/dist/types/utils/restart.d.ts +2 -3
  109. package/dist/types/utils/routes.d.ts +2 -1
  110. package/package.json +14 -15
  111. package/dist/cjs/hooks.js +0 -60
  112. package/dist/cjs/new/index.js +0 -79
  113. package/dist/cjs/new/loadPlugins.js +0 -57
  114. package/dist/cjs/old.js +0 -179
  115. package/dist/esm/hooks.js +0 -36
  116. package/dist/esm/new/index.js +0 -55
  117. package/dist/esm/new/loadPlugins.js +0 -94
  118. package/dist/esm/old.js +0 -258
  119. package/dist/esm-node/hooks.js +0 -36
  120. package/dist/esm-node/new/index.js +0 -52
  121. package/dist/esm-node/new/loadPlugins.js +0 -33
  122. package/dist/esm-node/old.js +0 -140
  123. package/dist/types/hooks.d.ts +0 -2
  124. package/dist/types/new/compat/index.d.ts +0 -2
  125. package/dist/types/new/index.d.ts +0 -6
  126. package/dist/types/new/loadPlugins.d.ts +0 -9
  127. package/dist/types/new/utils/index.d.ts +0 -1
  128. package/dist/types/old.d.ts +0 -13
  129. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  130. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  131. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  132. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  133. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  134. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  135. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
@@ -37,95 +37,91 @@ function deploy_default() {
37
37
  name: "@modern-js/plugin-deploy",
38
38
  setup: function(api) {
39
39
  var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
40
- return {
41
- deploy: function deploy() {
42
- return _async_to_generator(function() {
43
- var appContext, metaName, modernConfig, deployPreset, _tmp, _tmp1, _tmp2, _tmp3;
44
- return _ts_generator(this, function(_state) {
45
- switch (_state.label) {
46
- case 0:
47
- appContext = api.useAppContext();
48
- metaName = appContext.metaName;
49
- if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
50
- return [
51
- 2
52
- ];
53
- }
54
- modernConfig = api.useResolvedConfigContext();
55
- return [
56
- 4,
57
- getDeployPreset(appContext, modernConfig, deployTarget)
58
- ];
59
- case 1:
60
- deployPreset = _state.sent();
61
- _tmp = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare;
62
- if (!_tmp)
63
- return [
64
- 3,
65
- 3
66
- ];
67
- return [
68
- 4,
69
- deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare()
70
- ];
71
- case 2:
72
- _tmp = _state.sent();
73
- _state.label = 3;
74
- case 3:
75
- _tmp;
76
- _tmp1 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput;
77
- if (!_tmp1)
78
- return [
79
- 3,
80
- 5
81
- ];
82
- return [
83
- 4,
84
- deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput()
85
- ];
86
- case 4:
87
- _tmp1 = _state.sent();
88
- _state.label = 5;
89
- case 5:
90
- _tmp1;
91
- _tmp2 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry;
92
- if (!_tmp2)
93
- return [
94
- 3,
95
- 7
96
- ];
97
- return [
98
- 4,
99
- deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry()
100
- ];
101
- case 6:
102
- _tmp2 = _state.sent();
103
- _state.label = 7;
104
- case 7:
105
- _tmp2;
106
- _tmp3 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end;
107
- if (!_tmp3)
108
- return [
109
- 3,
110
- 9
111
- ];
112
- return [
113
- 4,
114
- deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end()
115
- ];
116
- case 8:
117
- _tmp3 = _state.sent();
118
- _state.label = 9;
119
- case 9:
120
- _tmp3;
121
- return [
122
- 2
123
- ];
40
+ api.deploy(/* @__PURE__ */ _async_to_generator(function() {
41
+ var appContext, metaName, modernConfig, deployPreset, _tmp, _tmp1, _tmp2, _tmp3;
42
+ return _ts_generator(this, function(_state) {
43
+ switch (_state.label) {
44
+ case 0:
45
+ appContext = api.getAppContext();
46
+ metaName = appContext.metaName;
47
+ if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
48
+ return [
49
+ 2
50
+ ];
124
51
  }
125
- });
126
- })();
127
- }
128
- };
52
+ modernConfig = api.getNormalizedConfig();
53
+ return [
54
+ 4,
55
+ getDeployPreset(appContext, modernConfig, deployTarget)
56
+ ];
57
+ case 1:
58
+ deployPreset = _state.sent();
59
+ _tmp = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare;
60
+ if (!_tmp)
61
+ return [
62
+ 3,
63
+ 3
64
+ ];
65
+ return [
66
+ 4,
67
+ deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare()
68
+ ];
69
+ case 2:
70
+ _tmp = _state.sent();
71
+ _state.label = 3;
72
+ case 3:
73
+ _tmp;
74
+ _tmp1 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput;
75
+ if (!_tmp1)
76
+ return [
77
+ 3,
78
+ 5
79
+ ];
80
+ return [
81
+ 4,
82
+ deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput()
83
+ ];
84
+ case 4:
85
+ _tmp1 = _state.sent();
86
+ _state.label = 5;
87
+ case 5:
88
+ _tmp1;
89
+ _tmp2 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry;
90
+ if (!_tmp2)
91
+ return [
92
+ 3,
93
+ 7
94
+ ];
95
+ return [
96
+ 4,
97
+ deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry()
98
+ ];
99
+ case 6:
100
+ _tmp2 = _state.sent();
101
+ _state.label = 7;
102
+ case 7:
103
+ _tmp2;
104
+ _tmp3 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end;
105
+ if (!_tmp3)
106
+ return [
107
+ 3,
108
+ 9
109
+ ];
110
+ return [
111
+ 4,
112
+ deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end()
113
+ ];
114
+ case 8:
115
+ _tmp3 = _state.sent();
116
+ _state.label = 9;
117
+ case 9:
118
+ _tmp3;
119
+ return [
120
+ 2
121
+ ];
122
+ }
123
+ });
124
+ }));
129
125
  }
130
126
  };
131
127
  }
@@ -41,7 +41,7 @@ function initialize_default(param) {
41
41
  port = _state.sent();
42
42
  appContext = _object_spread_props(_object_spread({}, appContext), {
43
43
  port,
44
- distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
44
+ distDirectory: ensureAbsolutePath(appContext.appDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
45
45
  });
46
46
  api.updateAppContext(appContext);
47
47
  normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
@@ -21,63 +21,59 @@ function serverBuild_default() {
21
21
  return {
22
22
  name: "@modern-js/server-build",
23
23
  setup: function setup(api) {
24
- return {
25
- afterBuild: function afterBuild() {
26
- return _async_to_generator(function() {
27
- var _api_useAppContext, appDirectory, distDirectory, metaName, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
28
- return _ts_generator(this, function(_state) {
29
- switch (_state.label) {
30
- case 0:
31
- _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, metaName = _api_useAppContext.metaName;
32
- if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
33
- return [
34
- 2
35
- ];
36
- }
37
- modernConfig = api.useResolvedConfigContext();
38
- distDir = path.resolve(distDirectory);
39
- serverDir = path.resolve(appDirectory, SERVER_DIR);
40
- sharedDir = path.resolve(appDirectory, SHARED_DIR);
41
- tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
42
- sourceDirs = [];
43
- if (fs.existsSync(serverDir)) {
44
- sourceDirs.push(serverDir);
45
- if (fs.existsSync(sharedDir)) {
46
- sourceDirs.push(sharedDir);
47
- }
48
- }
49
- server = modernConfig.server;
50
- alias = modernConfig.source.alias;
51
- babel = modernConfig.tools.babel;
52
- if (!(sourceDirs.length > 0))
53
- return [
54
- 3,
55
- 2
56
- ];
57
- return [
58
- 4,
59
- compile(appDirectory, {
60
- server,
61
- alias,
62
- babelConfig: babel
63
- }, {
64
- sourceDirs,
65
- distDir,
66
- tsconfigPath
67
- })
68
- ];
69
- case 1:
70
- _state.sent();
71
- _state.label = 2;
72
- case 2:
73
- return [
74
- 2
75
- ];
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 "./compat/hooks";
7
- import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
8
- import { getConfigFile } from "./getConfigFile";
9
- import { loadInternalPlugins } from "./loadPlugins";
10
- import { getIsAutoLoadPlugins } from "./utils";
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
- getIsAutoLoadPlugins(appDirectory, finalConfigFile)
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 "./constants";
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));
@@ -14,7 +14,6 @@ var initAppContext = function(param) {
14
14
  apiDirectory: path.resolve(appDirectory, apiDir),
15
15
  lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
16
16
  sharedDirectory: path.resolve(appDirectory, sharedDir),
17
- distDirectory: distDir,
18
17
  serverPlugins: [],
19
18
  internalDirectory: path.resolve(appDirectory, tempDir || "./node_modules/.".concat(metaName)),
20
19
  htmlTemplates: {},
@@ -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 getIsAutoLoadPlugins(appDirectory) {
5
- return _getIsAutoLoadPlugins.apply(this, arguments);
4
+ function isAutoLoadPlugins(appDirectory) {
5
+ return _isAutoLoadPlugins.apply(this, arguments);
6
6
  }
7
- function _getIsAutoLoadPlugins() {
8
- _getIsAutoLoadPlugins = _async_to_generator(function(appDirectory) {
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 _getIsAutoLoadPlugins.apply(this, arguments);
29
+ return _isAutoLoadPlugins.apply(this, arguments);
30
30
  }
31
31
  export {
32
- getIsAutoLoadPlugins
32
+ isAutoLoadPlugins
33
33
  };
@@ -1,23 +1,24 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
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, runner, plugins, filtedPlugins;
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
- runner = api.useHookRunners();
18
+ hooks = api.getHooks();
18
19
  return [
19
20
  4,
20
- runner._internalServerPlugins({
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.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
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
  };
@@ -2,7 +2,7 @@ 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 { logger, prettyInstructions } from "@modern-js/utils";
4
4
  var printInstructions = function() {
5
- var _ref = _async_to_generator(function(hookRunners, appContext, config) {
5
+ var _ref = _async_to_generator(function(hooks, appContext, config) {
6
6
  var message, instructions;
7
7
  return _ts_generator(this, function(_state) {
8
8
  switch (_state.label) {
@@ -10,7 +10,7 @@ var printInstructions = function() {
10
10
  message = prettyInstructions(appContext, config);
11
11
  return [
12
12
  4,
13
- hookRunners.beforePrintInstructions({
13
+ hooks.onBeforePrintInstructions.call({
14
14
  instructions: message
15
15
  })
16
16
  ];
@@ -23,7 +23,7 @@ var printInstructions = function() {
23
23
  }
24
24
  });
25
25
  });
26
- return function printInstructions2(hookRunners, appContext, config) {
26
+ return function printInstructions2(hooks, appContext, config) {
27
27
  return _ref.apply(this, arguments);
28
28
  };
29
29
  }();
@@ -1,12 +1,13 @@
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 { cli } from "@modern-js/plugin-v2/cli";
4
- import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
5
- function restart(hooksRunner, filename) {
4
+ import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
5
+ import { program } from "@modern-js/utils/commander";
6
+ function restart(hooks, filename) {
6
7
  return _restart.apply(this, arguments);
7
8
  }
8
9
  function _restart() {
9
- _restart = _async_to_generator(function(hooksRunner, filename) {
10
+ _restart = _async_to_generator(function(hooks, filename) {
10
11
  var hasGetError, err;
11
12
  return _ts_generator(this, function(_state) {
12
13
  switch (_state.label) {
@@ -16,7 +17,7 @@ function _restart() {
16
17
  hasGetError = false;
17
18
  return [
18
19
  4,
19
- hooksRunner.beforeRestart()
20
+ hooks.onBeforeRestart.call()
20
21
  ];
21
22
  case 1:
22
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
- let resolvedConfig = api.useResolvedConfigContext();
13
- const appContext = api.useAppContext();
14
- const hookRunners = api.useHookRunners();
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 hookRunners.beforeBuild({
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 hookRunners.afterBuild({
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
- resolvedConfig = {
46
- ...resolvedConfig,
47
- cliOptions: options
48
- };
49
- ResolvedConfigContext.set(resolvedConfig);
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 hookRunners = api.useHookRunners();
4
- const { metaName } = api.useAppContext();
3
+ const hooks = api.getHooks();
4
+ const { metaName } = api.getAppContext();
5
5
  await getServerPlugins(api, metaName);
6
- await hookRunners.beforeDeploy(options);
7
- await hookRunners.deploy(options);
8
- await hookRunners.afterDeploy(options);
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