@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
package/dist/esm/index.js CHANGED
@@ -1,12 +1,255 @@
1
- import { appTools } from "./new/index";
2
- import { appTools as appTools2, initAppContext } from "./new/index";
3
- import { dev } from "./commands/dev";
4
- import { mergeConfig } from "@modern-js/core";
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 { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
5
+ import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
6
+ import { castArray } from "@modern-js/uni-builder";
7
+ import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
8
+ import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
9
+ import { compatPlugin } from "./compat";
10
+ import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
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 { generateWatchFiles } from "./utils/generateWatchFiles";
17
+ import { initAppContext } from "./utils/initAppContext";
18
+ import { restart } from "./utils/restart";
19
+ export * from "./defineConfig";
20
+ var appTools = function() {
21
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
22
+ // default webpack to be compatible with original projects
23
+ bundler: "webpack"
24
+ };
25
+ return {
26
+ name: "@modern-js/app-tools",
27
+ usePlugins: [
28
+ compatPlugin(),
29
+ initializePlugin({
30
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
31
+ "rspack",
32
+ "experimental-rspack"
33
+ ].includes(options.bundler) ? "rspack" : "webpack"
34
+ }),
35
+ analyzePlugin({
36
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
37
+ "rspack",
38
+ "experimental-rspack"
39
+ ].includes(options.bundler) ? "rspack" : "webpack"
40
+ }),
41
+ serverBuildPlugin(),
42
+ deployPlugin()
43
+ ],
44
+ post: [
45
+ "@modern-js/plugin-initialize",
46
+ "@modern-js/plugin-analyze",
47
+ "@modern-js/plugin-ssr",
48
+ "@modern-js/plugin-document",
49
+ "@modern-js/plugin-state",
50
+ "@modern-js/plugin-router",
51
+ "@modern-js/plugin-router-v5",
52
+ "@modern-js/plugin-polyfill"
53
+ ],
54
+ registryHooks: {
55
+ onBeforeConfig: createAsyncHook(),
56
+ onAfterPrepare: createAsyncHook(),
57
+ deploy: createAsyncHook(),
58
+ _internalRuntimePlugins: createAsyncHook(),
59
+ _internalServerPlugins: createAsyncHook(),
60
+ checkEntryPoint: createAsyncHook(),
61
+ modifyEntrypoints: createAsyncHook(),
62
+ modifyFileSystemRoutes: createAsyncHook(),
63
+ modifyServerRoutes: createAsyncHook(),
64
+ generateEntryCode: createAsyncHook(),
65
+ onBeforeGenerateRoutes: createAsyncHook(),
66
+ onBeforePrintInstructions: createAsyncHook(),
67
+ registerDev: createCollectAsyncHook(),
68
+ registerBuildPlatform: createCollectAsyncHook(),
69
+ addRuntimeExports: createAsyncHook()
70
+ },
71
+ setup: function(api) {
72
+ var _userConfig_output;
73
+ var context = api.getAppContext();
74
+ var userConfig = api.getConfig();
75
+ var locale = getLocaleLanguage();
76
+ i18n.changeLanguage({
77
+ locale
78
+ });
79
+ api.updateAppContext(initAppContext({
80
+ appDirectory: context.appDirectory,
81
+ options: {},
82
+ serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
83
+ runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
84
+ tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
85
+ }));
86
+ api.addCommand(function() {
87
+ var _ref = _async_to_generator(function(param) {
88
+ var program;
89
+ return _ts_generator(this, function(_state) {
90
+ switch (_state.label) {
91
+ case 0:
92
+ program = param.program;
93
+ return [
94
+ 4,
95
+ devCommand(program, api)
96
+ ];
97
+ case 1:
98
+ _state.sent();
99
+ return [
100
+ 4,
101
+ buildCommand(program, api)
102
+ ];
103
+ case 2:
104
+ _state.sent();
105
+ serverCommand(program, api);
106
+ deployCommand(program, api);
107
+ newCommand(program, locale);
108
+ inspectCommand(program, api);
109
+ upgradeCommand(program);
110
+ deprecatedCommands(program);
111
+ return [
112
+ 2
113
+ ];
114
+ }
115
+ });
116
+ });
117
+ return function(_) {
118
+ return _ref.apply(this, arguments);
119
+ };
120
+ }());
121
+ api.onPrepare(/* @__PURE__ */ _async_to_generator(function() {
122
+ var command, isSkipBuild, resolvedConfig, appContext;
123
+ return _ts_generator(this, function(_state) {
124
+ switch (_state.label) {
125
+ case 0:
126
+ command = getCommand();
127
+ if (command === "deploy") {
128
+ isSkipBuild = [
129
+ "-s",
130
+ "--skip-build"
131
+ ].some(function(tag) {
132
+ return getArgv().includes(tag);
133
+ });
134
+ if (isSkipBuild) {
135
+ return [
136
+ 2
137
+ ];
138
+ }
139
+ }
140
+ if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
141
+ return [
142
+ 3,
143
+ 2
144
+ ];
145
+ resolvedConfig = api.getNormalizedConfig();
146
+ if (!resolvedConfig.output.cleanDistPath)
147
+ return [
148
+ 3,
149
+ 2
150
+ ];
151
+ appContext = api.getAppContext();
152
+ return [
153
+ 4,
154
+ emptyDir(appContext.distDirectory)
155
+ ];
156
+ case 1:
157
+ _state.sent();
158
+ _state.label = 2;
159
+ case 2:
160
+ return [
161
+ 2
162
+ ];
163
+ }
164
+ });
165
+ }));
166
+ api.addWatchFiles(/* @__PURE__ */ _async_to_generator(function() {
167
+ var appContext, config, files, watchFiles;
168
+ return _ts_generator(this, function(_state) {
169
+ switch (_state.label) {
170
+ case 0:
171
+ appContext = api.getAppContext();
172
+ config = api.getNormalizedConfig();
173
+ return [
174
+ 4,
175
+ generateWatchFiles(appContext, config.source.configDir)
176
+ ];
177
+ case 1:
178
+ files = _state.sent();
179
+ watchFiles = castArray(config.dev.watchFiles);
180
+ watchFiles.forEach(function(param) {
181
+ var type = param.type, paths = param.paths;
182
+ if (type === "reload-server") {
183
+ var _files;
184
+ (_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
185
+ paths
186
+ ]));
187
+ }
188
+ });
189
+ return [
190
+ 2,
191
+ files
192
+ ];
193
+ }
194
+ });
195
+ }));
196
+ api.onFileChanged(function() {
197
+ var _ref = _async_to_generator(function(e) {
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.getHooks(), filename)
223
+ ];
224
+ case 3:
225
+ _state.sent();
226
+ _state.label = 4;
227
+ case 4:
228
+ return [
229
+ 2
230
+ ];
231
+ }
232
+ });
233
+ });
234
+ return function(e) {
235
+ return _ref.apply(this, arguments);
236
+ };
237
+ }());
238
+ api.onBeforeRestart(function() {
239
+ cleanRequireCache([
240
+ require.resolve("./plugins/analyze")
241
+ ]);
242
+ });
243
+ }
244
+ };
245
+ };
5
246
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
247
+ import { mergeConfig } from "@modern-js/core";
248
+ import { dev } from "./commands/dev";
6
249
  export * from "./types";
7
250
  var src_default = appTools;
8
251
  export {
9
- appTools2 as appTools,
252
+ appTools,
10
253
  src_default as default,
11
254
  defineConfig,
12
255
  defineLegacyConfig,
@@ -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
  };