@modern-js/app-tools 2.63.1 → 2.63.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) 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 +21 -6
  9. package/dist/cjs/{new/compat → compat}/index.js +7 -2
  10. package/dist/cjs/{new/compat → compat}/utils.js +29 -8
  11. package/dist/cjs/config/default.js +6 -1
  12. package/dist/cjs/config/legacy/index.js +0 -1
  13. package/dist/cjs/index.js +154 -5
  14. package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
  15. package/dist/cjs/plugins/analyze/index.js +25 -10
  16. package/dist/cjs/plugins/analyze/utils.js +6 -0
  17. package/dist/cjs/plugins/deploy/platforms/netlify.js +7 -4
  18. package/dist/cjs/plugins/deploy/platforms/node.js +6 -3
  19. package/dist/cjs/plugins/deploy/platforms/vercel.js +7 -4
  20. package/dist/cjs/plugins/serverBuild.js +30 -32
  21. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  22. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  23. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -3
  24. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  25. package/dist/cjs/utils/loadPlugins.js +35 -4
  26. package/dist/cjs/utils/printInstructions.js +2 -11
  27. package/dist/cjs/utils/restart.js +2 -2
  28. package/dist/esm/commands/build.js +18 -12
  29. package/dist/esm/commands/deploy.js +6 -6
  30. package/dist/esm/commands/dev.js +11 -11
  31. package/dist/esm/commands/index.js +8 -8
  32. package/dist/esm/commands/inspect.js +1 -1
  33. package/dist/esm/commands/serve.js +6 -6
  34. package/dist/esm/{new/compat → compat}/hooks.js +98 -49
  35. package/dist/esm/{new/compat → compat}/index.js +8 -3
  36. package/dist/esm/{new/compat → compat}/utils.js +29 -8
  37. package/dist/esm/config/default.js +12 -1
  38. package/dist/esm/config/legacy/index.js +0 -1
  39. package/dist/esm/index.js +245 -2
  40. package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
  41. package/dist/esm/plugins/analyze/index.js +76 -34
  42. package/dist/esm/plugins/analyze/utils.js +5 -0
  43. package/dist/esm/plugins/deploy/platforms/netlify.js +6 -3
  44. package/dist/esm/plugins/deploy/platforms/node.js +5 -2
  45. package/dist/esm/plugins/deploy/platforms/vercel.js +6 -3
  46. package/dist/esm/plugins/serverBuild.js +52 -56
  47. package/dist/esm/{new/run.js → run/index.js} +6 -6
  48. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  49. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  50. package/dist/esm/utils/loadPlugins.js +95 -7
  51. package/dist/esm/utils/printInstructions.js +1 -28
  52. package/dist/esm/utils/restart.js +3 -3
  53. package/dist/esm-node/commands/build.js +19 -13
  54. package/dist/esm-node/commands/deploy.js +5 -5
  55. package/dist/esm-node/commands/dev.js +12 -12
  56. package/dist/esm-node/commands/index.js +6 -6
  57. package/dist/esm-node/commands/inspect.js +1 -1
  58. package/dist/esm-node/commands/serve.js +5 -5
  59. package/dist/esm-node/{new/compat → compat}/hooks.js +21 -6
  60. package/dist/esm-node/{new/compat → compat}/index.js +8 -3
  61. package/dist/esm-node/{new/compat → compat}/utils.js +29 -8
  62. package/dist/esm-node/config/default.js +6 -1
  63. package/dist/esm-node/config/legacy/index.js +0 -1
  64. package/dist/esm-node/index.js +140 -2
  65. package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
  66. package/dist/esm-node/plugins/analyze/index.js +26 -11
  67. package/dist/esm-node/plugins/analyze/utils.js +5 -0
  68. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -3
  69. package/dist/esm-node/plugins/deploy/platforms/node.js +5 -2
  70. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -3
  71. package/dist/esm-node/plugins/serverBuild.js +30 -32
  72. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  73. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  74. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  75. package/dist/esm-node/utils/loadPlugins.js +34 -4
  76. package/dist/esm-node/utils/printInstructions.js +1 -9
  77. package/dist/esm-node/utils/restart.js +2 -2
  78. package/dist/types/commands/build.d.ts +2 -2
  79. package/dist/types/commands/deploy.d.ts +2 -2
  80. package/dist/types/commands/dev.d.ts +2 -2
  81. package/dist/types/commands/index.d.ts +6 -6
  82. package/dist/types/commands/inspect.d.ts +2 -2
  83. package/dist/types/commands/serve.d.ts +2 -2
  84. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  85. package/dist/types/compat/index.d.ts +2 -0
  86. package/dist/types/{new/compat → compat}/utils.d.ts +8 -1
  87. package/dist/types/index.d.ts +5 -3
  88. package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
  89. package/dist/types/plugins/analyze/utils.d.ts +1 -0
  90. package/dist/types/plugins/serverBuild.d.ts +2 -2
  91. package/dist/types/types/config/index.d.ts +0 -1
  92. package/dist/types/types/index.d.ts +2 -0
  93. package/dist/types/types/new.d.ts +11 -16
  94. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  95. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  96. package/dist/types/utils/loadPlugins.d.ts +13 -3
  97. package/dist/types/utils/printInstructions.d.ts +1 -3
  98. package/dist/types/utils/restart.d.ts +2 -3
  99. package/package.json +24 -28
  100. package/dist/cjs/hooks.js +0 -60
  101. package/dist/cjs/new/index.js +0 -79
  102. package/dist/cjs/new/loadPlugins.js +0 -57
  103. package/dist/cjs/old.js +0 -179
  104. package/dist/cjs/plugins/deploy/dependencies/index.js +0 -237
  105. package/dist/cjs/plugins/deploy/dependencies/utils.js +0 -179
  106. package/dist/cjs/plugins/deploy/exports.js +0 -28
  107. package/dist/esm/hooks.js +0 -36
  108. package/dist/esm/new/index.js +0 -55
  109. package/dist/esm/new/loadPlugins.js +0 -94
  110. package/dist/esm/old.js +0 -258
  111. package/dist/esm/plugins/deploy/dependencies/index.js +0 -615
  112. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -421
  113. package/dist/esm/plugins/deploy/exports.js +0 -4
  114. package/dist/esm-node/hooks.js +0 -36
  115. package/dist/esm-node/new/index.js +0 -52
  116. package/dist/esm-node/new/loadPlugins.js +0 -33
  117. package/dist/esm-node/old.js +0 -140
  118. package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -202
  119. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -137
  120. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  121. package/dist/types/hooks.d.ts +0 -2
  122. package/dist/types/new/compat/index.d.ts +0 -2
  123. package/dist/types/new/index.d.ts +0 -6
  124. package/dist/types/new/loadPlugins.d.ts +0 -9
  125. package/dist/types/new/utils/index.d.ts +0 -1
  126. package/dist/types/old.d.ts +0 -13
  127. package/dist/types/plugins/deploy/dependencies/index.d.ts +0 -20
  128. package/dist/types/plugins/deploy/dependencies/utils.d.ts +0 -44
  129. package/dist/types/plugins/deploy/exports.d.ts +0 -1
  130. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  131. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  132. /package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -0
  133. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  134. /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -0
  135. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  136. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  137. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
  138. /package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -0
@@ -1,421 +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 _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import os from "node:os";
6
- import path from "path";
7
- import { fs as fse } from "@modern-js/utils";
8
- import { nodeFileTrace, resolve } from "@vercel/nft";
9
- import { parseNodeModulePath } from "mlly";
10
- function applyPublicCondition(pkg) {
11
- var _pkg_publishConfig;
12
- if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
13
- var _pkg_publishConfig1;
14
- pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
15
- }
16
- }
17
- var writePackage = function() {
18
- var _ref = _async_to_generator(function(options) {
19
- var pkg, version, projectDir, _pkgPath, pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
20
- return _ts_generator(this, function(_state) {
21
- switch (_state.label) {
22
- case 0:
23
- pkg = options.pkg, version = options.version, projectDir = options.projectDir, _pkgPath = options._pkgPath;
24
- pkgPath = _pkgPath || pkg.name;
25
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
26
- _state.label = 1;
27
- case 1:
28
- _state.trys.push([
29
- 1,
30
- 10,
31
- 11,
32
- 12
33
- ]);
34
- _iterator = pkg.versions[version].files[Symbol.iterator]();
35
- _state.label = 2;
36
- case 2:
37
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
38
- return [
39
- 3,
40
- 9
41
- ];
42
- src = _step.value;
43
- if (!src.includes("node_modules"))
44
- return [
45
- 3,
46
- 5
47
- ];
48
- subpath = parseNodeModulePath(src).subpath;
49
- dest = path.join(projectDir, "node_modules", pkgPath, subpath);
50
- dirname = path.dirname(dest);
51
- return [
52
- 4,
53
- fse.ensureDir(dirname)
54
- ];
55
- case 3:
56
- _state.sent();
57
- return [
58
- 4,
59
- fse.copyFile(src, dest)
60
- ];
61
- case 4:
62
- _state.sent();
63
- return [
64
- 3,
65
- 8
66
- ];
67
- case 5:
68
- subpath1 = path.relative(pkg.versions[version].path, src);
69
- dest1 = path.join(projectDir, "node_modules", pkgPath, subpath1);
70
- dirname1 = path.dirname(dest1);
71
- return [
72
- 4,
73
- fse.ensureDir(dirname1)
74
- ];
75
- case 6:
76
- _state.sent();
77
- return [
78
- 4,
79
- fse.copyFile(src, dest1)
80
- ];
81
- case 7:
82
- _state.sent();
83
- _state.label = 8;
84
- case 8:
85
- _iteratorNormalCompletion = true;
86
- return [
87
- 3,
88
- 2
89
- ];
90
- case 9:
91
- return [
92
- 3,
93
- 12
94
- ];
95
- case 10:
96
- err = _state.sent();
97
- _didIteratorError = true;
98
- _iteratorError = err;
99
- return [
100
- 3,
101
- 12
102
- ];
103
- case 11:
104
- try {
105
- if (!_iteratorNormalCompletion && _iterator.return != null) {
106
- _iterator.return();
107
- }
108
- } finally {
109
- if (_didIteratorError) {
110
- throw _iteratorError;
111
- }
112
- }
113
- return [
114
- 7
115
- ];
116
- case 12:
117
- pkgJSON = pkg.versions[version].pkgJSON;
118
- applyPublicCondition(pkgJSON);
119
- packageJsonPath = path.join(projectDir, "node_modules", pkgPath, "package.json");
120
- return [
121
- 4,
122
- fse.ensureDir(path.dirname(packageJsonPath))
123
- ];
124
- case 13:
125
- _state.sent();
126
- return [
127
- 4,
128
- fse.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2))
129
- ];
130
- case 14:
131
- _state.sent();
132
- return [
133
- 2
134
- ];
135
- }
136
- });
137
- });
138
- return function writePackage2(options) {
139
- return _ref.apply(this, arguments);
140
- };
141
- }();
142
- var isWindows = os.platform() === "win32";
143
- var linkPackage = function() {
144
- var _ref = _async_to_generator(function(from, to, projectRootDir) {
145
- var src, dest, dstStat, exists;
146
- return _ts_generator(this, function(_state) {
147
- switch (_state.label) {
148
- case 0:
149
- src = path.join(projectRootDir, "node_modules", from);
150
- dest = path.join(projectRootDir, "node_modules", to);
151
- return [
152
- 4,
153
- fse.lstat(dest).catch(function() {
154
- return null;
155
- })
156
- ];
157
- case 1:
158
- dstStat = _state.sent();
159
- exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
160
- if (exists) {
161
- return [
162
- 2
163
- ];
164
- }
165
- return [
166
- 4,
167
- fse.mkdir(path.dirname(dest), {
168
- recursive: true
169
- })
170
- ];
171
- case 2:
172
- _state.sent();
173
- return [
174
- 4,
175
- fse.symlink(path.relative(path.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch(function(error) {
176
- console.error("Cannot link", from, "to", to, error);
177
- })
178
- ];
179
- case 3:
180
- _state.sent();
181
- return [
182
- 2
183
- ];
184
- }
185
- });
186
- });
187
- return function linkPackage2(from, to, projectRootDir) {
188
- return _ref.apply(this, arguments);
189
- };
190
- }();
191
- var readDirRecursive = function() {
192
- var _ref = _async_to_generator(function(dir) {
193
- var options, filter, files, filesAndDirs;
194
- var _arguments = arguments;
195
- return _ts_generator(this, function(_state) {
196
- switch (_state.label) {
197
- case 0:
198
- options = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
199
- filter = options.filter;
200
- return [
201
- 4,
202
- fse.readdir(dir, {
203
- withFileTypes: true
204
- })
205
- ];
206
- case 1:
207
- files = _state.sent();
208
- return [
209
- 4,
210
- Promise.all(files.map(function() {
211
- var _ref2 = _async_to_generator(function(file) {
212
- var resolvedPath;
213
- return _ts_generator(this, function(_state2) {
214
- resolvedPath = path.resolve(dir, file.name);
215
- if (file.isDirectory()) {
216
- return [
217
- 2,
218
- readDirRecursive(resolvedPath, options)
219
- ];
220
- } else {
221
- return [
222
- 2,
223
- filter && !filter(resolvedPath) ? [] : resolvedPath
224
- ];
225
- }
226
- return [
227
- 2
228
- ];
229
- });
230
- });
231
- return function(file) {
232
- return _ref2.apply(this, arguments);
233
- };
234
- }()))
235
- ];
236
- case 2:
237
- filesAndDirs = _state.sent();
238
- return [
239
- 2,
240
- filesAndDirs.flat()
241
- ];
242
- }
243
- });
244
- });
245
- return function readDirRecursive2(dir) {
246
- return _ref.apply(this, arguments);
247
- };
248
- }();
249
- var isFile = function() {
250
- var _ref = _async_to_generator(function(file) {
251
- var stat, error;
252
- return _ts_generator(this, function(_state) {
253
- switch (_state.label) {
254
- case 0:
255
- _state.trys.push([
256
- 0,
257
- 2,
258
- ,
259
- 3
260
- ]);
261
- return [
262
- 4,
263
- fse.stat(file)
264
- ];
265
- case 1:
266
- stat = _state.sent();
267
- return [
268
- 2,
269
- stat.isFile()
270
- ];
271
- case 2:
272
- error = _state.sent();
273
- if (error.code === "ENOENT") {
274
- return [
275
- 2,
276
- false
277
- ];
278
- }
279
- throw error;
280
- case 3:
281
- return [
282
- 2
283
- ];
284
- }
285
- });
286
- });
287
- return function isFile2(file) {
288
- return _ref.apply(this, arguments);
289
- };
290
- }();
291
- var findEntryFiles = function() {
292
- var _ref = _async_to_generator(function(rootDir, entryFilter) {
293
- var files;
294
- return _ts_generator(this, function(_state) {
295
- switch (_state.label) {
296
- case 0:
297
- return [
298
- 4,
299
- readDirRecursive(rootDir, {
300
- filter: entryFilter
301
- })
302
- ];
303
- case 1:
304
- files = _state.sent();
305
- return [
306
- 2,
307
- files.filter(function(file) {
308
- return file.endsWith(".mjs") || file.endsWith(".cjs") || file.endsWith(".js");
309
- })
310
- ];
311
- }
312
- });
313
- });
314
- return function findEntryFiles2(rootDir, entryFilter) {
315
- return _ref.apply(this, arguments);
316
- };
317
- }();
318
- var findPackageParents = function(pkg, version, tracedFiles) {
319
- var versionFiles = pkg.versions[version].files.map(function(path2) {
320
- return tracedFiles[path2];
321
- });
322
- var parentPkgs = _to_consumable_array(new Set(versionFiles.flatMap(function(file) {
323
- return (
324
- // Because it supports copyWholePackage configuration, not all files exist.
325
- file === null || file === void 0 ? void 0 : file.parents.map(function(parentPath) {
326
- var parentFile = tracedFiles[parentPath];
327
- if (!parentFile || parentFile.pkgName === pkg.name) {
328
- return null;
329
- }
330
- return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
331
- }).filter(Boolean)
332
- );
333
- })));
334
- return parentPkgs.filter(function(parentPkg) {
335
- return parentPkg;
336
- });
337
- };
338
- var traceFiles = function() {
339
- var _ref = _async_to_generator(function(param) {
340
- var entryFiles, serverRootDir, _param_base, base, traceOptions;
341
- return _ts_generator(this, function(_state) {
342
- switch (_state.label) {
343
- case 0:
344
- entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, traceOptions = param.traceOptions;
345
- return [
346
- 4,
347
- nodeFileTrace(entryFiles, _object_spread({
348
- base,
349
- processCwd: serverRootDir,
350
- resolve: function() {
351
- var _ref2 = _async_to_generator(function(id, parent, job, isCjs) {
352
- return _ts_generator(this, function(_state2) {
353
- if (id.startsWith("@modern-js/prod-server")) {
354
- return [
355
- 2,
356
- require.resolve(id, {
357
- paths: [
358
- require.resolve("@modern-js/app-tools")
359
- ]
360
- })
361
- ];
362
- } else {
363
- return [
364
- 2,
365
- resolve(id, parent, job, isCjs)
366
- ];
367
- }
368
- return [
369
- 2
370
- ];
371
- });
372
- });
373
- return function(id, parent, job, isCjs) {
374
- return _ref2.apply(this, arguments);
375
- };
376
- }()
377
- }, traceOptions))
378
- ];
379
- case 1:
380
- return [
381
- 2,
382
- _state.sent()
383
- ];
384
- }
385
- });
386
- });
387
- return function traceFiles2(_) {
388
- return _ref.apply(this, arguments);
389
- };
390
- }();
391
- var resolveTracedPath = function() {
392
- var _ref = _async_to_generator(function(base, p) {
393
- return _ts_generator(this, function(_state) {
394
- return [
395
- 2,
396
- fse.realpath(path.resolve(base, p))
397
- ];
398
- });
399
- });
400
- return function resolveTracedPath2(base, p) {
401
- return _ref.apply(this, arguments);
402
- };
403
- }();
404
- var isSubPath = function(parentPath, childPath) {
405
- if (!parentPath || !childPath) {
406
- return false;
407
- }
408
- var relative = path.relative(parentPath, childPath);
409
- return relative && !relative.startsWith("..");
410
- };
411
- export {
412
- findEntryFiles,
413
- findPackageParents,
414
- isFile,
415
- isSubPath,
416
- linkPackage,
417
- readDirRecursive,
418
- resolveTracedPath,
419
- traceFiles,
420
- writePackage
421
- };
@@ -1,4 +0,0 @@
1
- import { handleDependencies } from "./dependencies";
2
- export {
3
- handleDependencies
4
- };
@@ -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
- };