@modern-js/app-tools 2.62.2-alpha.0 → 2.63.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) 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 +20 -8
  9. package/dist/cjs/{new/compat → compat}/index.js +10 -2
  10. package/dist/cjs/{new/compat → compat}/utils.js +10 -1
  11. package/dist/cjs/index.js +156 -7
  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 +44 -50
  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/types/index.js → types/new.js} +2 -2
  21. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  22. package/dist/cjs/{new/context.js → utils/initAppContext.js} +5 -5
  23. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  24. package/dist/cjs/utils/loadPlugins.js +35 -4
  25. package/dist/cjs/utils/printInstructions.js +2 -2
  26. package/dist/cjs/utils/restart.js +4 -3
  27. package/dist/esm/commands/build.js +18 -12
  28. package/dist/esm/commands/deploy.js +6 -6
  29. package/dist/esm/commands/dev.js +10 -10
  30. package/dist/esm/commands/index.js +8 -8
  31. package/dist/esm/commands/inspect.js +1 -1
  32. package/dist/esm/commands/serve.js +5 -5
  33. package/dist/esm/{new/compat → compat}/hooks.js +65 -41
  34. package/dist/esm/{new/compat → compat}/index.js +13 -2
  35. package/dist/{esm-node/new → esm}/compat/utils.js +10 -1
  36. package/dist/esm/index.js +248 -5
  37. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  38. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  39. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  40. package/dist/esm/plugins/analyze/index.js +328 -331
  41. package/dist/esm/plugins/deploy/index.js +84 -88
  42. package/dist/esm/plugins/initialize/index.js +61 -64
  43. package/dist/esm/plugins/serverBuild.js +52 -56
  44. package/dist/esm/{new/run.js → run/index.js} +6 -6
  45. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  46. package/dist/esm/{new/context.js → utils/initAppContext.js} +3 -3
  47. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  48. package/dist/esm/utils/loadPlugins.js +95 -7
  49. package/dist/esm/utils/printInstructions.js +3 -3
  50. package/dist/esm/utils/restart.js +5 -4
  51. package/dist/esm-node/commands/build.js +19 -13
  52. package/dist/esm-node/commands/deploy.js +5 -5
  53. package/dist/esm-node/commands/dev.js +11 -11
  54. package/dist/esm-node/commands/index.js +6 -6
  55. package/dist/esm-node/commands/inspect.js +1 -1
  56. package/dist/esm-node/commands/serve.js +4 -4
  57. package/dist/esm-node/{new/compat → compat}/hooks.js +20 -8
  58. package/dist/esm-node/{new/compat → compat}/index.js +10 -2
  59. package/dist/{esm/new → esm-node}/compat/utils.js +10 -1
  60. package/dist/esm-node/index.js +143 -5
  61. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  62. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  63. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  64. package/dist/esm-node/plugins/analyze/index.js +128 -130
  65. package/dist/esm-node/plugins/deploy/index.js +12 -14
  66. package/dist/esm-node/plugins/initialize/index.js +44 -50
  67. package/dist/esm-node/plugins/serverBuild.js +30 -32
  68. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  69. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  70. package/dist/esm-node/{new/context.js → utils/initAppContext.js} +3 -3
  71. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  72. package/dist/esm-node/utils/loadPlugins.js +34 -4
  73. package/dist/esm-node/utils/printInstructions.js +2 -2
  74. package/dist/esm-node/utils/restart.js +4 -3
  75. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  76. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  77. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  78. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  79. package/dist/types/builder/index.d.ts +1 -1
  80. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  81. package/dist/types/builder/shared/types.d.ts +3 -2
  82. package/dist/types/commands/build.d.ts +2 -2
  83. package/dist/types/commands/deploy.d.ts +2 -2
  84. package/dist/types/commands/dev.d.ts +2 -2
  85. package/dist/types/commands/index.d.ts +6 -6
  86. package/dist/types/commands/inspect.d.ts +2 -2
  87. package/dist/types/commands/serve.d.ts +2 -2
  88. package/dist/types/compat/hooks.d.ts +7 -0
  89. package/dist/types/compat/index.d.ts +2 -0
  90. package/dist/types/config/default.d.ts +4 -3
  91. package/dist/types/config/initialize/index.d.ts +3 -2
  92. package/dist/types/config/initialize/inits.d.ts +4 -3
  93. package/dist/types/index.d.ts +8 -5
  94. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  95. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  96. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  97. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  98. package/dist/types/plugins/analyze/index.d.ts +2 -3
  99. package/dist/types/plugins/deploy/index.d.ts +2 -3
  100. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  101. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  102. package/dist/types/plugins/initialize/index.d.ts +2 -2
  103. package/dist/types/plugins/serverBuild.d.ts +2 -2
  104. package/dist/types/types/index.d.ts +7 -3
  105. package/dist/types/types/new.d.ts +157 -0
  106. package/dist/types/utils/env.d.ts +2 -2
  107. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  108. package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
  109. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  110. package/dist/types/utils/loadPlugins.d.ts +13 -3
  111. package/dist/types/utils/printInstructions.d.ts +3 -3
  112. package/dist/types/utils/restart.d.ts +2 -3
  113. package/dist/types/utils/routes.d.ts +2 -1
  114. package/lib/types.d.ts +82 -61
  115. package/package.json +24 -24
  116. package/dist/cjs/hooks.js +0 -60
  117. package/dist/cjs/new/index.js +0 -79
  118. package/dist/cjs/new/loadPlugins.js +0 -57
  119. package/dist/cjs/old.js +0 -179
  120. package/dist/esm/hooks.js +0 -36
  121. package/dist/esm/new/index.js +0 -55
  122. package/dist/esm/new/loadPlugins.js +0 -94
  123. package/dist/esm/old.js +0 -258
  124. package/dist/esm-node/hooks.js +0 -36
  125. package/dist/esm-node/new/index.js +0 -52
  126. package/dist/esm-node/new/loadPlugins.js +0 -33
  127. package/dist/esm-node/old.js +0 -140
  128. package/dist/types/hooks.d.ts +0 -2
  129. package/dist/types/new/compat/hooks.d.ts +0 -8
  130. package/dist/types/new/compat/index.d.ts +0 -4
  131. package/dist/types/new/index.d.ts +0 -9
  132. package/dist/types/new/loadPlugins.d.ts +0 -9
  133. package/dist/types/new/types/index.d.ts +0 -90
  134. package/dist/types/new/utils/index.d.ts +0 -1
  135. package/dist/types/old.d.ts +0 -13
  136. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  137. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  138. /package/dist/esm/{new/types/index.js → types/new.js} +0 -0
  139. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  140. /package/dist/esm-node/{new/types/index.js → types/new.js} +0 -0
  141. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  142. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  143. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  144. /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
  }
@@ -17,72 +17,69 @@ function initialize_default(param) {
17
17
  "@modern-js/plugin-polyfill"
18
18
  ],
19
19
  setup: function setup(api) {
20
- var config = function() {
21
- var appContext = api.useAppContext();
22
- var userConfig = api.useConfigContext();
23
- api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
20
+ api.config(function() {
21
+ var appContext = api.getAppContext();
22
+ var userConfig = api.getConfig();
23
+ api.updateAppContext({
24
24
  bundlerType: bundler
25
- }));
25
+ });
26
26
  return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
27
- };
28
- return {
29
- config,
30
- resolvedConfig: function resolvedConfig(param2) {
31
- var resolved = param2.resolved;
32
- return _async_to_generator(function() {
33
- var _resolved_output_distPath, appContext, userConfig, port, normalizedConfig, _normalizedConfig_autoLoadPlugins;
34
- return _ts_generator(this, function(_state) {
35
- switch (_state.label) {
36
- case 0:
37
- appContext = api.useAppContext();
38
- userConfig = api.useConfigContext();
39
- return [
40
- 4,
41
- getServerPort(resolved)
42
- ];
43
- case 1:
44
- port = _state.sent();
45
- appContext = _object_spread_props(_object_spread({}, appContext), {
46
- port,
47
- distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
48
- });
49
- api.setAppContext(appContext);
50
- normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
51
- resolved._raw = userConfig;
52
- resolved.server = _object_spread_props(_object_spread({}, normalizedConfig.server || {}), {
53
- port
54
- });
55
- resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
56
- stabilizeConfig(resolved, normalizedConfig, [
57
- "source",
58
- "bff",
59
- "dev",
60
- "html",
61
- "output",
62
- "tools",
63
- "testing",
64
- "plugins",
65
- "builderPlugins",
66
- "runtime",
67
- "runtimeByEntries",
68
- "deploy",
69
- "performance"
70
- ]);
71
- if (bundler === "webpack") {
72
- resolved.security = normalizedConfig.security || {};
73
- resolved.experiments = normalizedConfig.experiments;
74
- }
75
- return [
76
- 2,
77
- {
78
- resolved
79
- }
80
- ];
81
- }
82
- });
83
- })();
84
- }
85
- };
27
+ });
28
+ api.modifyResolvedConfig(function() {
29
+ var _ref = _async_to_generator(function(resolved) {
30
+ var _resolved_output_distPath, appContext, userConfig, port, normalizedConfig, _normalizedConfig_autoLoadPlugins;
31
+ return _ts_generator(this, function(_state) {
32
+ switch (_state.label) {
33
+ case 0:
34
+ appContext = api.getAppContext();
35
+ userConfig = api.getConfig();
36
+ return [
37
+ 4,
38
+ getServerPort(resolved)
39
+ ];
40
+ case 1:
41
+ port = _state.sent();
42
+ appContext = _object_spread_props(_object_spread({}, appContext), {
43
+ port,
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
+ });
46
+ api.updateAppContext(appContext);
47
+ normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
48
+ resolved._raw = userConfig;
49
+ resolved.server = _object_spread_props(_object_spread({}, normalizedConfig.server || {}), {
50
+ port
51
+ });
52
+ resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
53
+ stabilizeConfig(resolved, normalizedConfig, [
54
+ "source",
55
+ "bff",
56
+ "dev",
57
+ "html",
58
+ "output",
59
+ "tools",
60
+ "testing",
61
+ "plugins",
62
+ "builderPlugins",
63
+ "runtime",
64
+ "runtimeByEntries",
65
+ "deploy",
66
+ "performance"
67
+ ]);
68
+ if (bundler === "webpack") {
69
+ resolved.security = normalizedConfig.security || {};
70
+ resolved.experiments = normalizedConfig.experiments;
71
+ }
72
+ return [
73
+ 2,
74
+ resolved
75
+ ];
76
+ }
77
+ });
78
+ });
79
+ return function(resolved) {
80
+ return _ref.apply(this, arguments);
81
+ };
82
+ }());
86
83
  }
87
84
  };
88
85
  }
@@ -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));
@@ -1,19 +1,19 @@
1
1
  import path from "path";
2
- import { address } from "@modern-js/utils";
2
+ import { fs, address } from "@modern-js/utils";
3
3
  var initAppContext = function(param) {
4
4
  var appDirectory = param.appDirectory, runtimeConfigFile = param.runtimeConfigFile, options = param.options, serverConfigFile = param.serverConfigFile, tempDir = param.tempDir;
5
5
  var _ref = options || {}, _ref_metaName = _ref.metaName, metaName = _ref_metaName === void 0 ? "modern-js" : _ref_metaName, _ref_apiDir = _ref.apiDir, apiDir = _ref_apiDir === void 0 ? "api" : _ref_apiDir, _ref_distDir = _ref.distDir, distDir = _ref_distDir === void 0 ? "" : _ref_distDir, _ref_sharedDir = _ref.sharedDir, sharedDir = _ref_sharedDir === void 0 ? "shared" : _ref_sharedDir;
6
+ var pkgPath = path.resolve(appDirectory, "./package.json");
6
7
  return {
7
8
  metaName,
8
9
  runtimeConfigFile,
9
10
  serverConfigFile,
10
11
  ip: address.ip(),
11
12
  port: 0,
12
- moduleType: require(path.resolve(appDirectory, "./package.json")).type || "commonjs",
13
+ moduleType: fs.existsSync(pkgPath) ? require(pkgPath).type || "commonjs" : "commonjs",
13
14
  apiDirectory: path.resolve(appDirectory, apiDir),
14
15
  lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
15
16
  sharedDirectory: path.resolve(appDirectory, sharedDir),
16
- distDirectory: distDir,
17
17
  serverPlugins: [],
18
18
  internalDirectory: path.resolve(appDirectory, tempDir || "./node_modules/.".concat(metaName)),
19
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
  };