@modern-js/app-tools 2.63.0 → 2.63.1

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 (61) hide show
  1. package/dist/cjs/commands/dev.js +1 -1
  2. package/dist/cjs/commands/serve.js +1 -1
  3. package/dist/cjs/new/compat/hooks.js +11 -4
  4. package/dist/cjs/new/compat/utils.js +10 -1
  5. package/dist/cjs/new/context.js +0 -1
  6. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
  7. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
  8. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
  9. package/dist/cjs/plugins/analyze/index.js +128 -130
  10. package/dist/cjs/plugins/deploy/index.js +12 -14
  11. package/dist/cjs/plugins/initialize/index.js +1 -1
  12. package/dist/cjs/utils/printInstructions.js +12 -3
  13. package/dist/cjs/utils/restart.js +2 -1
  14. package/dist/esm/commands/dev.js +2 -2
  15. package/dist/esm/commands/serve.js +2 -2
  16. package/dist/esm/new/compat/hooks.js +27 -17
  17. package/dist/esm/new/compat/utils.js +10 -1
  18. package/dist/esm/new/context.js +0 -1
  19. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  20. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  21. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  22. package/dist/esm/plugins/analyze/index.js +328 -331
  23. package/dist/esm/plugins/deploy/index.js +84 -88
  24. package/dist/esm/plugins/initialize/index.js +1 -1
  25. package/dist/esm/utils/printInstructions.js +29 -2
  26. package/dist/esm/utils/restart.js +2 -1
  27. package/dist/esm-node/commands/dev.js +2 -2
  28. package/dist/esm-node/commands/serve.js +2 -2
  29. package/dist/esm-node/new/compat/hooks.js +11 -4
  30. package/dist/esm-node/new/compat/utils.js +10 -1
  31. package/dist/esm-node/new/context.js +0 -1
  32. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  33. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  34. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  35. package/dist/esm-node/plugins/analyze/index.js +128 -130
  36. package/dist/esm-node/plugins/deploy/index.js +12 -14
  37. package/dist/esm-node/plugins/initialize/index.js +1 -1
  38. package/dist/esm-node/utils/printInstructions.js +10 -2
  39. package/dist/esm-node/utils/restart.js +2 -1
  40. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  41. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  42. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  43. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  44. package/dist/types/builder/index.d.ts +1 -1
  45. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  46. package/dist/types/builder/shared/types.d.ts +3 -2
  47. package/dist/types/config/initialize/index.d.ts +3 -2
  48. package/dist/types/config/initialize/inits.d.ts +4 -3
  49. package/dist/types/new/context.d.ts +0 -1
  50. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  51. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  52. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  53. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  54. package/dist/types/plugins/analyze/index.d.ts +2 -3
  55. package/dist/types/plugins/deploy/index.d.ts +2 -3
  56. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  57. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  58. package/dist/types/types/new.d.ts +38 -21
  59. package/dist/types/utils/printInstructions.d.ts +3 -1
  60. package/dist/types/utils/routes.d.ts +2 -1
  61. package/package.json +20 -20
@@ -10,7 +10,7 @@ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils"
10
10
  import { buildServerConfig } from "../utils/config";
11
11
  import { setServer } from "../utils/createServer";
12
12
  import { loadServerPlugins } from "../utils/loadPlugins";
13
- import { printInstructions } from "../utils/printInstructions";
13
+ import { printInstructionsCompat } from "../utils/printInstructions";
14
14
  import { registerCompiler } from "../utils/register";
15
15
  import { generateRoutes } from "../utils/routes";
16
16
  var dev = function() {
@@ -132,7 +132,7 @@ var dev = function() {
132
132
  port,
133
133
  host
134
134
  }, function() {
135
- printInstructions(hookRunners, appContext, normalizedConfig);
135
+ printInstructionsCompat(hookRunners, appContext, normalizedConfig);
136
136
  });
137
137
  return [
138
138
  3,
@@ -6,7 +6,7 @@ import path from "path";
6
6
  import { createProdServer } from "@modern-js/prod-server";
7
7
  import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
8
8
  import { loadServerPlugins } from "../utils/loadPlugins";
9
- import { printInstructions } from "../utils/printInstructions";
9
+ import { printInstructionsCompat } from "../utils/printInstructions";
10
10
  var start = function() {
11
11
  var _ref = _async_to_generator(function(api) {
12
12
  var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
@@ -69,7 +69,7 @@ var start = function() {
69
69
  case 0:
70
70
  return [
71
71
  4,
72
- printInstructions(hookRunners, appContext, userConfig)
72
+ printInstructionsCompat(hookRunners, appContext, userConfig)
73
73
  ];
74
74
  case 1:
75
75
  _state2.sent();
@@ -1,5 +1,6 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { getModifyHtmlPartials } from "../../plugins/analyze/getHtmlTemplate";
3
4
  import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
4
5
  function getHookRunners(context) {
5
6
  var hooks = context.hooks;
@@ -189,10 +190,24 @@ function getHookRunners(context) {
189
190
  htmlPartials: function() {
190
191
  var _ref = _async_to_generator(function(params) {
191
192
  return _ts_generator(this, function(_state) {
192
- return [
193
- 2,
194
- hooks.modifyHtmlPartials.call(params)
195
- ];
193
+ switch (_state.label) {
194
+ case 0:
195
+ return [
196
+ 4,
197
+ hooks.modifyHtmlPartials.call({
198
+ entrypoint: params.entrypoint,
199
+ partials: getModifyHtmlPartials(params.partials)
200
+ })
201
+ ];
202
+ case 1:
203
+ _state.sent();
204
+ return [
205
+ 2,
206
+ {
207
+ partials: params.partials
208
+ }
209
+ ];
210
+ }
196
211
  });
197
212
  });
198
213
  return function(params) {
@@ -228,7 +243,7 @@ function getHookRunners(context) {
228
243
  ];
229
244
  });
230
245
  }),
231
- filedChange: function() {
246
+ fileChange: function() {
232
247
  var _ref = _async_to_generator(function(params) {
233
248
  return _ts_generator(this, function(_state) {
234
249
  return [
@@ -391,19 +406,14 @@ function getHookRunners(context) {
391
406
  /**
392
407
  * @deprecated
393
408
  */
394
- addRuntimeExports: function() {
395
- var _ref = _async_to_generator(function(params) {
396
- return _ts_generator(this, function(_state) {
397
- return [
398
- 2,
399
- hooks.addRuntimeExports.call(params)
400
- ];
401
- });
409
+ addRuntimeExports: /* @__PURE__ */ _async_to_generator(function() {
410
+ return _ts_generator(this, function(_state) {
411
+ return [
412
+ 2,
413
+ hooks.addRuntimeExports.call()
414
+ ];
402
415
  });
403
- return function(params) {
404
- return _ref.apply(this, arguments);
405
- };
406
- }()
416
+ })
407
417
  };
408
418
  }
409
419
  function handleSetupResult(setupResult, api) {
@@ -16,7 +16,7 @@ function transformHookRunner(hookRunnerName) {
16
16
  return "addCommand";
17
17
  case "watchFiles":
18
18
  return "addWatchFiles";
19
- case "filedChange":
19
+ case "fileChange":
20
20
  return "onFileChanged";
21
21
  case "beforeCreateCompiler":
22
22
  return "onBeforeCreateCompiler";
@@ -50,6 +50,15 @@ function transformHookParams(hookRunnerName, params) {
50
50
  return {
51
51
  resolved: params
52
52
  };
53
+ case "htmlPartials":
54
+ return {
55
+ partials: {
56
+ top: params.partials.top.current,
57
+ head: params.partials.head.current,
58
+ body: params.partials.body.current
59
+ },
60
+ entrypoint: params.entrypoint
61
+ };
53
62
  default:
54
63
  return params;
55
64
  }
@@ -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: {},
@@ -28,7 +28,7 @@ var ifAlreadyExists = function(entrypoints, checked) {
28
28
  });
29
29
  };
30
30
  var getBundleEntry = function() {
31
- var _ref = _async_to_generator(function(hookRunners, appContext, config) {
31
+ var _ref = _async_to_generator(function(hooks, appContext, config) {
32
32
  var appDirectory, packageName, _config_source, disableDefaultEntries, entries, entriesDir, mainEntryName, defaults, _tmp, entriesDirAbs, found;
33
33
  return _ts_generator(this, function(_state) {
34
34
  switch (_state.label) {
@@ -48,7 +48,7 @@ var getBundleEntry = function() {
48
48
  case 1:
49
49
  return [
50
50
  4,
51
- getFileSystemEntry(hookRunners, appContext, config)
51
+ getFileSystemEntry(hooks, appContext, config)
52
52
  ];
53
53
  case 2:
54
54
  _tmp = _state.sent();
@@ -93,7 +93,7 @@ var getBundleEntry = function() {
93
93
  }
94
94
  });
95
95
  });
96
- return function getBundleEntry2(hookRunners, appContext, config) {
96
+ return function getBundleEntry2(hooks, appContext, config) {
97
97
  return _ref.apply(this, arguments);
98
98
  };
99
99
  }();
@@ -21,14 +21,14 @@ var hasServerEntry = function(dir) {
21
21
  }));
22
22
  };
23
23
  var isBundleEntry = function() {
24
- var _ref = _async_to_generator(function(hookRunners, dir, enableCustomEntry) {
24
+ var _ref = _async_to_generator(function(hooks, dir, enableCustomEntry) {
25
25
  var entry, customEntry;
26
26
  return _ts_generator(this, function(_state) {
27
27
  switch (_state.label) {
28
28
  case 0:
29
29
  return [
30
30
  4,
31
- hookRunners.checkEntryPoint({
31
+ hooks.checkEntryPoint.call({
32
32
  path: dir,
33
33
  entry: false
34
34
  })
@@ -55,12 +55,12 @@ var isBundleEntry = function() {
55
55
  }
56
56
  });
57
57
  });
58
- return function isBundleEntry2(hookRunners, dir, enableCustomEntry) {
58
+ return function isBundleEntry2(hooks, dir, enableCustomEntry) {
59
59
  return _ref.apply(this, arguments);
60
60
  };
61
61
  }();
62
62
  var scanDir = function() {
63
- var _ref = _async_to_generator(function(hookRunners, dirs, enableCustomEntry) {
63
+ var _ref = _async_to_generator(function(hooks, dirs, enableCustomEntry) {
64
64
  var entries;
65
65
  return _ts_generator(this, function(_state) {
66
66
  switch (_state.label) {
@@ -93,7 +93,7 @@ var scanDir = function() {
93
93
  }
94
94
  return [
95
95
  4,
96
- hookRunners.checkEntryPoint({
96
+ hooks.checkEntryPoint.call({
97
97
  path: dir,
98
98
  entry: false
99
99
  })
@@ -155,12 +155,12 @@ var scanDir = function() {
155
155
  }
156
156
  });
157
157
  });
158
- return function scanDir2(hookRunners, dirs, enableCustomEntry) {
158
+ return function scanDir2(hooks, dirs, enableCustomEntry) {
159
159
  return _ref.apply(this, arguments);
160
160
  };
161
161
  }();
162
162
  var getFileSystemEntry = function() {
163
- var _ref = _async_to_generator(function(hookRunners, appContext, config) {
163
+ var _ref = _async_to_generator(function(hooks, appContext, config) {
164
164
  var appDirectory, _config_source, entriesDir, disableEntryDirs, enableCustomEntry, disabledDirs, src, dirs;
165
165
  return _ts_generator(this, function(_state) {
166
166
  switch (_state.label) {
@@ -186,13 +186,13 @@ var getFileSystemEntry = function() {
186
186
  ];
187
187
  return [
188
188
  4,
189
- isBundleEntry(hookRunners, src, enableCustomEntry)
189
+ isBundleEntry(hooks, src, enableCustomEntry)
190
190
  ];
191
191
  case 1:
192
192
  if (_state.sent()) {
193
193
  return [
194
194
  2,
195
- scanDir(hookRunners, [
195
+ scanDir(hooks, [
196
196
  src
197
197
  ], enableCustomEntry)
198
198
  ];
@@ -215,7 +215,7 @@ var getFileSystemEntry = function() {
215
215
  ];
216
216
  return [
217
217
  4,
218
- isBundleEntry(hookRunners, file, enableCustomEntry)
218
+ isBundleEntry(hooks, file, enableCustomEntry)
219
219
  ];
220
220
  case 1:
221
221
  _tmp = _state2.sent();
@@ -239,7 +239,7 @@ var getFileSystemEntry = function() {
239
239
  _state.sent();
240
240
  return [
241
241
  2,
242
- scanDir(hookRunners, dirs, enableCustomEntry)
242
+ scanDir(hooks, dirs, enableCustomEntry)
243
243
  ];
244
244
  case 3:
245
245
  throw Error("source.entriesDir accept a directory.");
@@ -257,7 +257,7 @@ var getFileSystemEntry = function() {
257
257
  }
258
258
  });
259
259
  });
260
- return function getFileSystemEntry2(hookRunners, appContext, config) {
260
+ return function getFileSystemEntry2(hooks, appContext, config) {
261
261
  return _ref.apply(this, arguments);
262
262
  };
263
263
  }();
@@ -1,6 +1,5 @@
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 { _ as _ts_values } from "@swc/helpers/_/_ts_values";
6
5
  import path from "path";
@@ -30,8 +29,85 @@ var findPartials = function(dir, entryName, position) {
30
29
  }
31
30
  return null;
32
31
  };
32
+ var getModifyHtmlPartials = function(partials) {
33
+ var append = function(type) {
34
+ for (var _len = arguments.length, script = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
35
+ script[_key - 1] = arguments[_key];
36
+ }
37
+ script.forEach(function(item) {
38
+ partials[type].push(item);
39
+ });
40
+ };
41
+ var prepend = function(type) {
42
+ for (var _len = arguments.length, script = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
43
+ script[_key - 1] = arguments[_key];
44
+ }
45
+ script.forEach(function(item) {
46
+ partials[type].unshift(item);
47
+ });
48
+ };
49
+ return {
50
+ top: {
51
+ append: function() {
52
+ for (var _len = arguments.length, script = new Array(_len), _key = 0; _key < _len; _key++) {
53
+ script[_key] = arguments[_key];
54
+ }
55
+ return append.apply(void 0, [
56
+ "top"
57
+ ].concat(_to_consumable_array(script)));
58
+ },
59
+ prepend: function() {
60
+ for (var _len = arguments.length, script = new Array(_len), _key = 0; _key < _len; _key++) {
61
+ script[_key] = arguments[_key];
62
+ }
63
+ return prepend.apply(void 0, [
64
+ "top"
65
+ ].concat(_to_consumable_array(script)));
66
+ },
67
+ current: partials.top
68
+ },
69
+ head: {
70
+ append: function() {
71
+ for (var _len = arguments.length, script = new Array(_len), _key = 0; _key < _len; _key++) {
72
+ script[_key] = arguments[_key];
73
+ }
74
+ return append.apply(void 0, [
75
+ "head"
76
+ ].concat(_to_consumable_array(script)));
77
+ },
78
+ prepend: function() {
79
+ for (var _len = arguments.length, script = new Array(_len), _key = 0; _key < _len; _key++) {
80
+ script[_key] = arguments[_key];
81
+ }
82
+ return prepend.apply(void 0, [
83
+ "head"
84
+ ].concat(_to_consumable_array(script)));
85
+ },
86
+ current: partials.head
87
+ },
88
+ body: {
89
+ append: function() {
90
+ for (var _len = arguments.length, script = new Array(_len), _key = 0; _key < _len; _key++) {
91
+ script[_key] = arguments[_key];
92
+ }
93
+ return append.apply(void 0, [
94
+ "body"
95
+ ].concat(_to_consumable_array(script)));
96
+ },
97
+ prepend: function() {
98
+ for (var _len = arguments.length, script = new Array(_len), _key = 0; _key < _len; _key++) {
99
+ script[_key] = arguments[_key];
100
+ }
101
+ return prepend.apply(void 0, [
102
+ "body"
103
+ ].concat(_to_consumable_array(script)));
104
+ },
105
+ current: partials.body
106
+ }
107
+ };
108
+ };
33
109
  var getHtmlTemplate = function() {
34
- var _ref = _async_to_generator(function(entrypoints, api, param) {
110
+ var _ref = _async_to_generator(function(entrypoints, hooks, param) {
35
111
  var appContext, config, appDirectory, internalDirectory, configDir, htmlDir, htmlTemplates, partialsByEntrypoint, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err;
36
112
  return _ts_generator(this, function(_state) {
37
113
  switch (_state.label) {
@@ -52,7 +128,7 @@ var getHtmlTemplate = function() {
52
128
  8
53
129
  ]);
54
130
  _loop = function() {
55
- var entrypoint, entryName, isMainEntry, name, customIndexTemplate, hookRunners, partials, templatePath, bottomTemplate;
131
+ var entrypoint, entryName, isMainEntry, name, customIndexTemplate, getPartialInitValue, partials, templatePath, bottomTemplate;
56
132
  return _ts_generator(this, function(_state2) {
57
133
  switch (_state2.label) {
58
134
  case 0:
@@ -71,30 +147,26 @@ var getHtmlTemplate = function() {
71
147
  3
72
148
  ];
73
149
  case 1:
74
- hookRunners = api.useHookRunners();
150
+ getPartialInitValue = function(position) {
151
+ var partial = findPartials(htmlDir, name, position);
152
+ return partial ? [
153
+ partial.content
154
+ ] : [];
155
+ };
156
+ partials = {
157
+ top: getPartialInitValue("top"),
158
+ head: getPartialInitValue("head"),
159
+ body: getPartialInitValue("body")
160
+ };
75
161
  return [
76
162
  4,
77
- hookRunners.htmlPartials({
163
+ hooks.modifyHtmlPartials.call({
78
164
  entrypoint,
79
- partials: [
80
- "top",
81
- "head",
82
- "body"
83
- ].reduce(function(previous, position) {
84
- var found = findPartials(htmlDir, name, position);
85
- previous[position] = found ? [
86
- found.content
87
- ] : [];
88
- return previous;
89
- }, {
90
- top: [],
91
- head: [],
92
- body: []
93
- })
165
+ partials: getModifyHtmlPartials(partials)
94
166
  })
95
167
  ];
96
168
  case 2:
97
- partials = _state2.sent().partials;
169
+ _state2.sent();
98
170
  templatePath = path.resolve(internalDirectory, entryName, "index.html");
99
171
  fs.outputFileSync(templatePath, templates.html(partials), "utf8");
100
172
  htmlTemplates[entryName] = templatePath;
@@ -159,20 +231,21 @@ var getHtmlTemplate = function() {
159
231
  7
160
232
  ];
161
233
  case 8:
162
- api.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
163
- partialsByEntrypoint
164
- }));
165
234
  return [
166
235
  2,
167
- htmlTemplates
236
+ {
237
+ partialsByEntrypoint,
238
+ htmlTemplates
239
+ }
168
240
  ];
169
241
  }
170
242
  });
171
243
  });
172
- return function getHtmlTemplate2(entrypoints, api, _) {
244
+ return function getHtmlTemplate2(entrypoints, hooks, _) {
173
245
  return _ref.apply(this, arguments);
174
246
  };
175
247
  }();
176
248
  export {
177
- getHtmlTemplate
249
+ getHtmlTemplate,
250
+ getModifyHtmlPartials
178
251
  };