@modern-js/app-tools 2.63.1 → 2.63.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) 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 +5 -5
  9. package/dist/cjs/{new/compat → compat}/index.js +4 -1
  10. package/dist/cjs/config/default.js +6 -1
  11. package/dist/cjs/config/legacy/index.js +0 -1
  12. package/dist/cjs/index.js +154 -5
  13. package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
  14. package/dist/cjs/plugins/analyze/index.js +25 -10
  15. package/dist/cjs/plugins/analyze/utils.js +6 -0
  16. package/dist/cjs/plugins/serverBuild.js +30 -32
  17. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  18. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  19. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -3
  20. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  21. package/dist/cjs/utils/loadPlugins.js +35 -4
  22. package/dist/cjs/utils/printInstructions.js +2 -11
  23. package/dist/cjs/utils/restart.js +2 -2
  24. package/dist/esm/commands/build.js +18 -12
  25. package/dist/esm/commands/deploy.js +6 -6
  26. package/dist/esm/commands/dev.js +11 -11
  27. package/dist/esm/commands/index.js +8 -8
  28. package/dist/esm/commands/inspect.js +1 -1
  29. package/dist/esm/commands/serve.js +6 -6
  30. package/dist/esm/{new/compat → compat}/hooks.js +15 -25
  31. package/dist/esm/{new/compat → compat}/index.js +4 -1
  32. package/dist/esm/config/default.js +12 -1
  33. package/dist/esm/config/legacy/index.js +0 -1
  34. package/dist/esm/index.js +245 -2
  35. package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
  36. package/dist/esm/plugins/analyze/index.js +76 -34
  37. package/dist/esm/plugins/analyze/utils.js +5 -0
  38. package/dist/esm/plugins/serverBuild.js +52 -56
  39. package/dist/esm/{new/run.js → run/index.js} +6 -6
  40. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  41. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  42. package/dist/esm/utils/loadPlugins.js +95 -7
  43. package/dist/esm/utils/printInstructions.js +1 -28
  44. package/dist/esm/utils/restart.js +3 -3
  45. package/dist/esm-node/commands/build.js +19 -13
  46. package/dist/esm-node/commands/deploy.js +5 -5
  47. package/dist/esm-node/commands/dev.js +12 -12
  48. package/dist/esm-node/commands/index.js +6 -6
  49. package/dist/esm-node/commands/inspect.js +1 -1
  50. package/dist/esm-node/commands/serve.js +5 -5
  51. package/dist/esm-node/{new/compat → compat}/hooks.js +5 -5
  52. package/dist/esm-node/{new/compat → compat}/index.js +4 -1
  53. package/dist/esm-node/config/default.js +6 -1
  54. package/dist/esm-node/config/legacy/index.js +0 -1
  55. package/dist/esm-node/index.js +140 -2
  56. package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
  57. package/dist/esm-node/plugins/analyze/index.js +26 -11
  58. package/dist/esm-node/plugins/analyze/utils.js +5 -0
  59. package/dist/esm-node/plugins/serverBuild.js +30 -32
  60. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  61. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  62. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  63. package/dist/esm-node/utils/loadPlugins.js +34 -4
  64. package/dist/esm-node/utils/printInstructions.js +1 -9
  65. package/dist/esm-node/utils/restart.js +2 -2
  66. package/dist/types/commands/build.d.ts +2 -2
  67. package/dist/types/commands/deploy.d.ts +2 -2
  68. package/dist/types/commands/dev.d.ts +2 -2
  69. package/dist/types/commands/index.d.ts +6 -6
  70. package/dist/types/commands/inspect.d.ts +2 -2
  71. package/dist/types/commands/serve.d.ts +2 -2
  72. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  73. package/dist/types/compat/index.d.ts +2 -0
  74. package/dist/types/index.d.ts +5 -3
  75. package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
  76. package/dist/types/plugins/analyze/utils.d.ts +1 -0
  77. package/dist/types/plugins/serverBuild.d.ts +2 -2
  78. package/dist/types/types/config/index.d.ts +0 -1
  79. package/dist/types/types/index.d.ts +2 -0
  80. package/dist/types/types/new.d.ts +11 -16
  81. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  82. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  83. package/dist/types/utils/loadPlugins.d.ts +13 -3
  84. package/dist/types/utils/printInstructions.d.ts +1 -3
  85. package/dist/types/utils/restart.d.ts +2 -3
  86. package/package.json +23 -23
  87. package/dist/cjs/hooks.js +0 -60
  88. package/dist/cjs/new/index.js +0 -79
  89. package/dist/cjs/new/loadPlugins.js +0 -57
  90. package/dist/cjs/old.js +0 -179
  91. package/dist/esm/hooks.js +0 -36
  92. package/dist/esm/new/index.js +0 -55
  93. package/dist/esm/new/loadPlugins.js +0 -94
  94. package/dist/esm/old.js +0 -258
  95. package/dist/esm-node/hooks.js +0 -36
  96. package/dist/esm-node/new/index.js +0 -52
  97. package/dist/esm-node/new/loadPlugins.js +0 -33
  98. package/dist/esm-node/old.js +0 -140
  99. package/dist/types/hooks.d.ts +0 -2
  100. package/dist/types/new/compat/index.d.ts +0 -2
  101. package/dist/types/new/index.d.ts +0 -6
  102. package/dist/types/new/loadPlugins.d.ts +0 -9
  103. package/dist/types/new/utils/index.d.ts +0 -1
  104. package/dist/types/old.d.ts +0 -13
  105. /package/dist/cjs/{new/compat → compat}/utils.js +0 -0
  106. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  107. /package/dist/esm/{new/compat → compat}/utils.js +0 -0
  108. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  109. /package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -0
  110. /package/dist/esm-node/{new/compat → compat}/utils.js +0 -0
  111. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  112. /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -0
  113. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  114. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  115. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  116. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
  117. /package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -0
@@ -1,55 +0,0 @@
1
- import { createAsyncHook } from "@modern-js/plugin-v2";
2
- import { appTools as oldAppTools } from "../old";
3
- import { compatPlugin } from "./compat";
4
- import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
5
- import { initAppContext } from "./context";
6
- export * from "../defineConfig";
7
- var appTools = function() {
8
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
9
- // default webpack to be compatible with original projects
10
- bundler: "webpack"
11
- };
12
- return {
13
- name: "@modern-js/app-tools",
14
- usePlugins: [
15
- compatPlugin(),
16
- oldAppTools(options)
17
- ],
18
- post: [
19
- "@modern-js/app-tools-old"
20
- ],
21
- registryHooks: {
22
- onBeforeConfig: createAsyncHook(),
23
- onAfterPrepare: createAsyncHook(),
24
- deploy: createAsyncHook(),
25
- _internalRuntimePlugins: createAsyncHook(),
26
- _internalServerPlugins: createAsyncHook(),
27
- checkEntryPoint: createAsyncHook(),
28
- modifyEntrypoints: createAsyncHook(),
29
- modifyFileSystemRoutes: createAsyncHook(),
30
- modifyServerRoutes: createAsyncHook(),
31
- generateEntryCode: createAsyncHook(),
32
- onBeforeGenerateRoutes: createAsyncHook(),
33
- onBeforePrintInstructions: createAsyncHook(),
34
- registerDev: createAsyncHook(),
35
- registerBuildPlatform: createAsyncHook(),
36
- addRuntimeExports: createAsyncHook()
37
- },
38
- setup: function(api) {
39
- var _userConfig_output;
40
- var context = api.getAppContext();
41
- var userConfig = api.getConfig();
42
- api.updateAppContext(initAppContext({
43
- appDirectory: context.appDirectory,
44
- options: {},
45
- serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
46
- runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
47
- tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
48
- }));
49
- }
50
- };
51
- };
52
- export {
53
- appTools,
54
- initAppContext
55
- };
@@ -1,94 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
5
- var debug = createDebugger("load-plugins");
6
- var resolveCliPlugin = function() {
7
- var _ref = _async_to_generator(function(p, appDirectory) {
8
- var pkg, pluginOptions, path, module, e, ref, result;
9
- return _ts_generator(this, function(_state) {
10
- switch (_state.label) {
11
- case 0:
12
- pkg = typeof p === "string" ? p : p[0];
13
- pluginOptions = typeof p === "string" ? void 0 : p[1];
14
- path = tryResolve(pkg, appDirectory);
15
- _state.label = 1;
16
- case 1:
17
- _state.trys.push([
18
- 1,
19
- 3,
20
- ,
21
- 5
22
- ]);
23
- return [
24
- 4,
25
- compatibleRequire(path)
26
- ];
27
- case 2:
28
- module = _state.sent();
29
- return [
30
- 3,
31
- 5
32
- ];
33
- case 3:
34
- e = _state.sent();
35
- return [
36
- 4,
37
- dynamicImport(path)
38
- ];
39
- case 4:
40
- ref = _state.sent(), module = ref.default, ref;
41
- return [
42
- 3,
43
- 5
44
- ];
45
- case 5:
46
- if (typeof module === "function") {
47
- result = module(pluginOptions);
48
- return [
49
- 2,
50
- result
51
- ];
52
- }
53
- return [
54
- 2,
55
- module
56
- ];
57
- }
58
- });
59
- });
60
- return function resolveCliPlugin2(p, appDirectory) {
61
- return _ref.apply(this, arguments);
62
- };
63
- }();
64
- var loadInternalPlugins = function() {
65
- var _ref = _async_to_generator(function(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
66
- var plugins, loadedPlugins;
67
- return _ts_generator(this, function(_state) {
68
- switch (_state.label) {
69
- case 0:
70
- plugins = _to_consumable_array(autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : []).concat(_to_consumable_array(autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []));
71
- return [
72
- 4,
73
- Promise.all(plugins.map(function(plugin) {
74
- var loadedPlugin = resolveCliPlugin(plugin, appDirectory);
75
- debug("resolve plugin %s: %s", plugin, loadedPlugin);
76
- return loadedPlugin;
77
- }))
78
- ];
79
- case 1:
80
- loadedPlugins = _state.sent();
81
- return [
82
- 2,
83
- loadedPlugins
84
- ];
85
- }
86
- });
87
- });
88
- return function loadInternalPlugins2(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
89
- return _ref.apply(this, arguments);
90
- };
91
- }();
92
- export {
93
- loadInternalPlugins
94
- };
package/dist/esm/old.js DELETED
@@ -1,258 +0,0 @@
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";
4
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
- import path from "path";
7
- import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
8
- import { castArray } from "@modern-js/uni-builder";
9
- import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
10
- import { hooks } from "./hooks";
11
- import { i18n } from "./locale";
12
- import analyzePlugin from "./plugins/analyze";
13
- import deployPlugin from "./plugins/deploy";
14
- import initializePlugin from "./plugins/initialize";
15
- import serverBuildPlugin from "./plugins/serverBuild";
16
- import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
17
- import { generateWatchFiles } from "./utils/generateWatchFiles";
18
- import { restart } from "./utils/restart";
19
- import { dev } from "./commands/dev";
20
- import { mergeConfig } from "@modern-js/core";
21
- export * from "./defineConfig";
22
- export * from "./types";
23
- var appTools = function() {
24
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
25
- // default webpack to be compatible with original projects
26
- bundler: "webpack"
27
- };
28
- return {
29
- name: "@modern-js/app-tools-old",
30
- post: [
31
- "@modern-js/plugin-initialize",
32
- "@modern-js/plugin-analyze",
33
- "@modern-js/plugin-ssr",
34
- "@modern-js/plugin-document",
35
- "@modern-js/plugin-state",
36
- "@modern-js/plugin-router",
37
- "@modern-js/plugin-router-v5",
38
- "@modern-js/plugin-polyfill"
39
- ],
40
- registerHook: hooks,
41
- usePlugins: [
42
- initializePlugin({
43
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
44
- "rspack",
45
- "experimental-rspack"
46
- ].includes(options.bundler) ? "rspack" : "webpack"
47
- }),
48
- analyzePlugin({
49
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
50
- "rspack",
51
- "experimental-rspack"
52
- ].includes(options.bundler) ? "rspack" : "webpack"
53
- }),
54
- serverBuildPlugin(),
55
- deployPlugin()
56
- ],
57
- setup: function(api) {
58
- var appContext = api.useAppContext();
59
- api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
60
- toolsType: "app-tools"
61
- }));
62
- var locale = getLocaleLanguage();
63
- i18n.changeLanguage({
64
- locale
65
- });
66
- return {
67
- beforeConfig: function beforeConfig() {
68
- return _async_to_generator(function() {
69
- var _userConfig_output, userConfig, appContext2;
70
- return _ts_generator(this, function(_state) {
71
- userConfig = api.useConfigContext();
72
- appContext2 = api.useAppContext();
73
- if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
74
- api.setAppContext(_object_spread_props(_object_spread({}, appContext2), {
75
- internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
76
- }));
77
- }
78
- return [
79
- 2
80
- ];
81
- });
82
- })();
83
- },
84
- commands: function commands(param) {
85
- var program = param.program;
86
- return _async_to_generator(function() {
87
- return _ts_generator(this, function(_state) {
88
- switch (_state.label) {
89
- case 0:
90
- return [
91
- 4,
92
- devCommand(program, api)
93
- ];
94
- case 1:
95
- _state.sent();
96
- return [
97
- 4,
98
- buildCommand(program, api)
99
- ];
100
- case 2:
101
- _state.sent();
102
- serverCommand(program, api);
103
- deployCommand(program, api);
104
- newCommand(program, locale);
105
- inspectCommand(program, api);
106
- upgradeCommand(program);
107
- deprecatedCommands(program);
108
- return [
109
- 2
110
- ];
111
- }
112
- });
113
- })();
114
- },
115
- prepare: function prepare() {
116
- return _async_to_generator(function() {
117
- var command, isSkipBuild, resolvedConfig, appContext2;
118
- return _ts_generator(this, function(_state) {
119
- switch (_state.label) {
120
- case 0:
121
- command = getCommand();
122
- if (command === "deploy") {
123
- isSkipBuild = [
124
- "-s",
125
- "--skip-build"
126
- ].some(function(tag) {
127
- return getArgv().includes(tag);
128
- });
129
- if (isSkipBuild) {
130
- return [
131
- 2
132
- ];
133
- }
134
- }
135
- if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
136
- return [
137
- 3,
138
- 2
139
- ];
140
- resolvedConfig = api.useResolvedConfigContext();
141
- if (!resolvedConfig.output.cleanDistPath)
142
- return [
143
- 3,
144
- 2
145
- ];
146
- appContext2 = api.useAppContext();
147
- return [
148
- 4,
149
- emptyDir(appContext2.distDirectory)
150
- ];
151
- case 1:
152
- _state.sent();
153
- _state.label = 2;
154
- case 2:
155
- return [
156
- 2
157
- ];
158
- }
159
- });
160
- })();
161
- },
162
- watchFiles: function watchFiles() {
163
- return _async_to_generator(function() {
164
- var appContext2, config, files, watchFiles2;
165
- return _ts_generator(this, function(_state) {
166
- switch (_state.label) {
167
- case 0:
168
- appContext2 = api.useAppContext();
169
- config = api.useResolvedConfigContext();
170
- return [
171
- 4,
172
- generateWatchFiles(appContext2, config.source.configDir)
173
- ];
174
- case 1:
175
- files = _state.sent();
176
- watchFiles2 = castArray(config.dev.watchFiles);
177
- watchFiles2.forEach(function(param) {
178
- var type = param.type, paths = param.paths;
179
- if (type === "reload-server") {
180
- var _files;
181
- (_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
182
- paths
183
- ]));
184
- }
185
- });
186
- return [
187
- 2,
188
- files
189
- ];
190
- }
191
- });
192
- })();
193
- },
194
- fileChange: (
195
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
196
- function fileChange(e) {
197
- return _async_to_generator(function() {
198
- var filename, eventType, isPrivate, closeServer;
199
- return _ts_generator(this, function(_state) {
200
- switch (_state.label) {
201
- case 0:
202
- filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
203
- if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
204
- return [
205
- 3,
206
- 4
207
- ];
208
- return [
209
- 4,
210
- import("./utils/createServer.js")
211
- ];
212
- case 1:
213
- closeServer = _state.sent().closeServer;
214
- return [
215
- 4,
216
- closeServer()
217
- ];
218
- case 2:
219
- _state.sent();
220
- return [
221
- 4,
222
- restart(api.useHookRunners(), filename)
223
- ];
224
- case 3:
225
- _state.sent();
226
- _state.label = 4;
227
- case 4:
228
- return [
229
- 2
230
- ];
231
- }
232
- });
233
- })();
234
- }
235
- ),
236
- beforeRestart: function beforeRestart() {
237
- return _async_to_generator(function() {
238
- return _ts_generator(this, function(_state) {
239
- cleanRequireCache([
240
- require.resolve("./plugins/analyze")
241
- ]);
242
- return [
243
- 2
244
- ];
245
- });
246
- })();
247
- }
248
- };
249
- }
250
- };
251
- };
252
- var old_default = appTools;
253
- export {
254
- appTools,
255
- old_default as default,
256
- dev,
257
- mergeConfig
258
- };
@@ -1,36 +0,0 @@
1
- import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
- const hooks = {
3
- _internalRuntimePlugins: createAsyncWaterfall(),
4
- modifyFileSystemRoutes: createAsyncWaterfall(),
5
- modifyServerRoutes: createAsyncWaterfall(),
6
- /** add entry point info to entrypoints array */
7
- modifyEntrypoints: createAsyncWaterfall(),
8
- /** add entry type */
9
- checkEntryPoint: createAsyncWaterfall(),
10
- generateEntryCode: createAsyncWorkflow(),
11
- htmlPartials: createAsyncWaterfall(),
12
- beforeGenerateRoutes: createAsyncWaterfall(),
13
- _internalServerPlugins: createAsyncWaterfall(),
14
- beforeDev: createAsyncWorkflow(),
15
- afterDev: createAsyncWorkflow(),
16
- beforeCreateCompiler: createAsyncWorkflow(),
17
- afterCreateCompiler: createAsyncWorkflow(),
18
- beforePrintInstructions: createAsyncWaterfall(),
19
- beforeBuild: createAsyncWorkflow(),
20
- afterBuild: createAsyncWorkflow(),
21
- beforeDeploy: createAsyncWorkflow(),
22
- deploy: createAsyncWorkflow(),
23
- afterDeploy: createAsyncWorkflow(),
24
- beforeRestart: createAsyncWorkflow(),
25
- /**
26
- * @deprecated
27
- */
28
- registerDev: createParallelWorkflow(),
29
- /**
30
- * @deprecated
31
- */
32
- registerBuildPlatform: createParallelWorkflow()
33
- };
34
- export {
35
- hooks
36
- };
@@ -1,52 +0,0 @@
1
- import { createAsyncHook } from "@modern-js/plugin-v2";
2
- import { appTools as oldAppTools } from "../old";
3
- import { compatPlugin } from "./compat";
4
- import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
5
- import { initAppContext } from "./context";
6
- export * from "../defineConfig";
7
- const appTools = (options = {
8
- // default webpack to be compatible with original projects
9
- bundler: "webpack"
10
- }) => ({
11
- name: "@modern-js/app-tools",
12
- usePlugins: [
13
- compatPlugin(),
14
- oldAppTools(options)
15
- ],
16
- post: [
17
- "@modern-js/app-tools-old"
18
- ],
19
- registryHooks: {
20
- onBeforeConfig: createAsyncHook(),
21
- onAfterPrepare: createAsyncHook(),
22
- deploy: createAsyncHook(),
23
- _internalRuntimePlugins: createAsyncHook(),
24
- _internalServerPlugins: createAsyncHook(),
25
- checkEntryPoint: createAsyncHook(),
26
- modifyEntrypoints: createAsyncHook(),
27
- modifyFileSystemRoutes: createAsyncHook(),
28
- modifyServerRoutes: createAsyncHook(),
29
- generateEntryCode: createAsyncHook(),
30
- onBeforeGenerateRoutes: createAsyncHook(),
31
- onBeforePrintInstructions: createAsyncHook(),
32
- registerDev: createAsyncHook(),
33
- registerBuildPlatform: createAsyncHook(),
34
- addRuntimeExports: createAsyncHook()
35
- },
36
- setup: (api) => {
37
- var _userConfig_output;
38
- const context = api.getAppContext();
39
- const userConfig = api.getConfig();
40
- api.updateAppContext(initAppContext({
41
- appDirectory: context.appDirectory,
42
- options: {},
43
- serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
44
- runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
45
- tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
46
- }));
47
- }
48
- });
49
- export {
50
- appTools,
51
- initAppContext
52
- };
@@ -1,33 +0,0 @@
1
- import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
2
- const debug = createDebugger("load-plugins");
3
- const resolveCliPlugin = async (p, appDirectory) => {
4
- const pkg = typeof p === "string" ? p : p[0];
5
- const pluginOptions = typeof p === "string" ? void 0 : p[1];
6
- const path = tryResolve(pkg, appDirectory);
7
- let module;
8
- try {
9
- module = await compatibleRequire(path);
10
- } catch (e) {
11
- ({ default: module } = await dynamicImport(path));
12
- }
13
- if (typeof module === "function") {
14
- const result = module(pluginOptions);
15
- return result;
16
- }
17
- return module;
18
- };
19
- const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
20
- const plugins = [
21
- ...autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : [],
22
- ...autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []
23
- ];
24
- const loadedPlugins = await Promise.all(plugins.map((plugin) => {
25
- const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
26
- debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
27
- return loadedPlugin;
28
- }));
29
- return loadedPlugins;
30
- };
31
- export {
32
- loadInternalPlugins
33
- };
@@ -1,140 +0,0 @@
1
- import path from "path";
2
- import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
3
- import { castArray } from "@modern-js/uni-builder";
4
- import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
5
- import { hooks } from "./hooks";
6
- import { i18n } from "./locale";
7
- import analyzePlugin from "./plugins/analyze";
8
- import deployPlugin from "./plugins/deploy";
9
- import initializePlugin from "./plugins/initialize";
10
- import serverBuildPlugin from "./plugins/serverBuild";
11
- import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
12
- import { generateWatchFiles } from "./utils/generateWatchFiles";
13
- import { restart } from "./utils/restart";
14
- import { dev } from "./commands/dev";
15
- import { mergeConfig } from "@modern-js/core";
16
- export * from "./defineConfig";
17
- export * from "./types";
18
- const appTools = (options = {
19
- // default webpack to be compatible with original projects
20
- bundler: "webpack"
21
- }) => ({
22
- name: "@modern-js/app-tools-old",
23
- post: [
24
- "@modern-js/plugin-initialize",
25
- "@modern-js/plugin-analyze",
26
- "@modern-js/plugin-ssr",
27
- "@modern-js/plugin-document",
28
- "@modern-js/plugin-state",
29
- "@modern-js/plugin-router",
30
- "@modern-js/plugin-router-v5",
31
- "@modern-js/plugin-polyfill"
32
- ],
33
- registerHook: hooks,
34
- usePlugins: [
35
- initializePlugin({
36
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
37
- "rspack",
38
- "experimental-rspack"
39
- ].includes(options.bundler) ? "rspack" : "webpack"
40
- }),
41
- analyzePlugin({
42
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
43
- "rspack",
44
- "experimental-rspack"
45
- ].includes(options.bundler) ? "rspack" : "webpack"
46
- }),
47
- serverBuildPlugin(),
48
- deployPlugin()
49
- ],
50
- setup: (api) => {
51
- const appContext = api.useAppContext();
52
- api.setAppContext({
53
- ...appContext,
54
- toolsType: "app-tools"
55
- });
56
- const locale = getLocaleLanguage();
57
- i18n.changeLanguage({
58
- locale
59
- });
60
- return {
61
- async beforeConfig() {
62
- var _userConfig_output;
63
- const userConfig = api.useConfigContext();
64
- const appContext2 = api.useAppContext();
65
- if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
66
- api.setAppContext({
67
- ...appContext2,
68
- internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
69
- });
70
- }
71
- },
72
- async commands({ program }) {
73
- await devCommand(program, api);
74
- await buildCommand(program, api);
75
- serverCommand(program, api);
76
- deployCommand(program, api);
77
- newCommand(program, locale);
78
- inspectCommand(program, api);
79
- upgradeCommand(program);
80
- deprecatedCommands(program);
81
- },
82
- async prepare() {
83
- const command = getCommand();
84
- if (command === "deploy") {
85
- const isSkipBuild = [
86
- "-s",
87
- "--skip-build"
88
- ].some((tag) => {
89
- return getArgv().includes(tag);
90
- });
91
- if (isSkipBuild) {
92
- return;
93
- }
94
- }
95
- if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
96
- const resolvedConfig = api.useResolvedConfigContext();
97
- if (resolvedConfig.output.cleanDistPath) {
98
- const appContext2 = api.useAppContext();
99
- await emptyDir(appContext2.distDirectory);
100
- }
101
- }
102
- },
103
- async watchFiles() {
104
- const appContext2 = api.useAppContext();
105
- const config = api.useResolvedConfigContext();
106
- const files = await generateWatchFiles(appContext2, config.source.configDir);
107
- const watchFiles = castArray(config.dev.watchFiles);
108
- watchFiles.forEach(({ type, paths }) => {
109
- if (type === "reload-server") {
110
- files.push(...Array.isArray(paths) ? paths : [
111
- paths
112
- ]);
113
- }
114
- });
115
- return files;
116
- },
117
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
118
- async fileChange(e) {
119
- const { filename, eventType, isPrivate } = e;
120
- if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
121
- const { closeServer } = await import("./utils/createServer.js");
122
- await closeServer();
123
- await restart(api.useHookRunners(), filename);
124
- }
125
- },
126
- async beforeRestart() {
127
- cleanRequireCache([
128
- require.resolve("./plugins/analyze")
129
- ]);
130
- }
131
- };
132
- }
133
- });
134
- var old_default = appTools;
135
- export {
136
- appTools,
137
- old_default as default,
138
- dev,
139
- mergeConfig
140
- };
@@ -1,2 +0,0 @@
1
- import type { AppToolsHooks } from './types/hooks';
2
- export declare const hooks: AppToolsHooks;
@@ -1,2 +0,0 @@
1
- import type { AppTools, CliPluginFuture } from '../../types';
2
- export declare const compatPlugin: () => CliPluginFuture<AppTools>;
@@ -1,6 +0,0 @@
1
- import { type AppToolsOptions } from '../old';
2
- import type { AppTools, CliPluginFuture } from '../types';
3
- import { initAppContext } from './context';
4
- export * from '../defineConfig';
5
- export { initAppContext };
6
- export declare const appTools: (options?: AppToolsOptions) => CliPluginFuture<AppTools<'shared'>>;