@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
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var getHtmlTemplate_exports = {};
30
30
  __export(getHtmlTemplate_exports, {
31
- getHtmlTemplate: () => getHtmlTemplate
31
+ getHtmlTemplate: () => getHtmlTemplate,
32
+ getModifyHtmlPartials: () => getModifyHtmlPartials
32
33
  });
33
34
  module.exports = __toCommonJS(getHtmlTemplate_exports);
34
35
  var import_path = __toESM(require("path"));
@@ -54,7 +55,36 @@ const findPartials = (dir, entryName, position) => {
54
55
  }
55
56
  return null;
56
57
  };
57
- const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
58
+ const getModifyHtmlPartials = (partials) => {
59
+ const append = (type, ...script) => {
60
+ script.forEach((item) => {
61
+ partials[type].push(item);
62
+ });
63
+ };
64
+ const prepend = (type, ...script) => {
65
+ script.forEach((item) => {
66
+ partials[type].unshift(item);
67
+ });
68
+ };
69
+ return {
70
+ top: {
71
+ append: (...script) => append("top", ...script),
72
+ prepend: (...script) => prepend("top", ...script),
73
+ current: partials.top
74
+ },
75
+ head: {
76
+ append: (...script) => append("head", ...script),
77
+ prepend: (...script) => prepend("head", ...script),
78
+ current: partials.head
79
+ },
80
+ body: {
81
+ append: (...script) => append("body", ...script),
82
+ prepend: (...script) => prepend("body", ...script),
83
+ current: partials.body
84
+ }
85
+ };
86
+ };
87
+ const getHtmlTemplate = async (entrypoints, hooks, { appContext, config }) => {
58
88
  const { appDirectory, internalDirectory } = appContext;
59
89
  const { source: { configDir } } = config;
60
90
  const htmlDir = import_path.default.resolve(appDirectory, configDir || "", import_constants.HTML_PARTIALS_FOLDER);
@@ -67,24 +97,20 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
67
97
  if (customIndexTemplate) {
68
98
  htmlTemplates[entryName] = customIndexTemplate.file;
69
99
  } else {
70
- const hookRunners = api.useHookRunners();
71
- const { partials } = await hookRunners.htmlPartials({
100
+ const getPartialInitValue = (position) => {
101
+ const partial = findPartials(htmlDir, name, position);
102
+ return partial ? [
103
+ partial.content
104
+ ] : [];
105
+ };
106
+ const partials = {
107
+ top: getPartialInitValue("top"),
108
+ head: getPartialInitValue("head"),
109
+ body: getPartialInitValue("body")
110
+ };
111
+ await hooks.modifyHtmlPartials.call({
72
112
  entrypoint,
73
- partials: [
74
- "top",
75
- "head",
76
- "body"
77
- ].reduce((previous, position) => {
78
- const found = findPartials(htmlDir, name, position);
79
- previous[position] = found ? [
80
- found.content
81
- ] : [];
82
- return previous;
83
- }, {
84
- top: [],
85
- head: [],
86
- body: []
87
- })
113
+ partials: getModifyHtmlPartials(partials)
88
114
  });
89
115
  const templatePath = import_path.default.resolve(internalDirectory, entryName, "index.html");
90
116
  import_utils.fs.outputFileSync(templatePath, templates.html(partials), "utf8");
@@ -96,13 +122,13 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
96
122
  }
97
123
  }
98
124
  }
99
- api.setAppContext({
100
- ...api.useAppContext(),
101
- partialsByEntrypoint
102
- });
103
- return htmlTemplates;
125
+ return {
126
+ partialsByEntrypoint,
127
+ htmlTemplates
128
+ };
104
129
  };
105
130
  // Annotate the CommonJS export names for ESM import in node:
106
131
  0 && (module.exports = {
107
- getHtmlTemplate
132
+ getHtmlTemplate,
133
+ getModifyHtmlPartials
108
134
  });
@@ -49,146 +49,144 @@ var analyze_default = ({ bundler }) => ({
49
49
  setup: (api) => {
50
50
  let pagesDir = [];
51
51
  let nestedRouteEntries = [];
52
- return {
53
- async prepare() {
54
- var _resolvedConfig_source;
55
- let appContext = api.useAppContext();
56
- const resolvedConfig = api.useResolvedConfigContext();
57
- const hookRunners = api.useHookRunners();
58
- try {
59
- if ((0, import_utils2.checkIsBuildCommands)()) {
60
- import_utils.fs.emptydirSync(appContext.internalDirectory);
61
- }
62
- } catch {
63
- }
64
- const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
65
- await hookRunners.addRuntimeExports();
66
- if (apiOnly) {
67
- const { routes: routes2 } = await hookRunners.modifyServerRoutes({
68
- routes: []
69
- });
70
- debug(`server routes: %o`, routes2);
71
- appContext = {
72
- ...api.useAppContext(),
73
- apiOnly,
74
- serverRoutes: routes2
75
- };
76
- api.setAppContext(appContext);
77
- return;
52
+ api.onPrepare(async () => {
53
+ var _resolvedConfig_source;
54
+ let appContext = api.getAppContext();
55
+ const resolvedConfig = api.getNormalizedConfig();
56
+ const hooks = api.getHooks();
57
+ try {
58
+ if ((0, import_utils2.checkIsBuildCommands)()) {
59
+ import_utils.fs.emptydirSync(appContext.internalDirectory);
78
60
  }
79
- const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
80
- import("./getBundleEntry.js"),
81
- import("./getServerRoutes.js"),
82
- import("./getHtmlTemplate.js")
83
- ]);
84
- const { entrypoints } = await hookRunners.modifyEntrypoints({
85
- entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
61
+ } catch {
62
+ }
63
+ const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
64
+ await hooks.addRuntimeExports.call();
65
+ if (apiOnly) {
66
+ const { routes: routes2 } = await hooks.modifyServerRoutes.call({
67
+ routes: []
86
68
  });
87
- debug(`entrypoints: %o`, entrypoints);
88
- const initialRoutes = getServerRoutes(entrypoints, {
89
- appContext,
90
- config: resolvedConfig
69
+ debug(`server routes: %o`, routes2);
70
+ api.updateAppContext({
71
+ apiOnly,
72
+ serverRoutes: routes2
91
73
  });
92
- const { routes } = await hookRunners.modifyServerRoutes({
93
- routes: initialRoutes
74
+ return;
75
+ }
76
+ const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
77
+ import("./getBundleEntry.js"),
78
+ import("./getServerRoutes.js"),
79
+ import("./getHtmlTemplate.js")
80
+ ]);
81
+ const { entrypoints } = await hooks.modifyEntrypoints.call({
82
+ entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
83
+ });
84
+ debug(`entrypoints: %o`, entrypoints);
85
+ const initialRoutes = getServerRoutes(entrypoints, {
86
+ appContext,
87
+ config: resolvedConfig
88
+ });
89
+ const { routes } = await hooks.modifyServerRoutes.call({
90
+ routes: initialRoutes
91
+ });
92
+ debug(`server routes: %o`, routes);
93
+ appContext = {
94
+ ...api.getAppContext(),
95
+ entrypoints,
96
+ serverRoutes: routes
97
+ };
98
+ api.updateAppContext(appContext);
99
+ nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
100
+ pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
101
+ const { partialsByEntrypoint, htmlTemplates } = await getHtmlTemplate(entrypoints, hooks, {
102
+ appContext,
103
+ config: resolvedConfig
104
+ });
105
+ debug(`html templates: %o`, htmlTemplates);
106
+ api.updateAppContext({
107
+ partialsByEntrypoint
108
+ });
109
+ let checkedEntries = entrypoints.map((point) => point.entryName);
110
+ if ((0, import_utils.isDevCommand)()) {
111
+ const { entry } = (0, import_utils.minimist)((0, import_utils.getArgv)());
112
+ checkedEntries = await (0, import_getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
113
+ }
114
+ appContext = {
115
+ ...api.getAppContext(),
116
+ entrypoints,
117
+ checkedEntries,
118
+ apiOnly,
119
+ serverRoutes: routes,
120
+ htmlTemplates
121
+ };
122
+ api.updateAppContext(appContext);
123
+ if ((0, import_utils2.checkIsBuildCommands)()) {
124
+ await hooks.generateEntryCode.call({
125
+ entrypoints
94
126
  });
95
- debug(`server routes: %o`, routes);
96
- appContext = {
97
- ...api.useAppContext(),
98
- entrypoints,
99
- serverRoutes: routes
100
- };
101
- api.setAppContext(appContext);
102
- nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
103
- pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
104
- const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
105
- appContext,
106
- config: resolvedConfig
127
+ const normalizedConfig = api.getNormalizedConfig();
128
+ const createBuilderForModern = await (0, import_builder.createBuilderGenerator)(bundler);
129
+ const builder = await createBuilderForModern({
130
+ normalizedConfig,
131
+ appContext
107
132
  });
108
- debug(`html templates: %o`, htmlTemplates);
109
- let checkedEntries = entrypoints.map((point) => point.entryName);
110
- if ((0, import_utils.isDevCommand)()) {
111
- const { entry } = (0, import_utils.minimist)((0, import_utils.getArgv)());
112
- checkedEntries = await (0, import_getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
113
- }
114
- appContext = {
115
- ...api.useAppContext(),
116
- entrypoints,
117
- checkedEntries,
118
- apiOnly,
119
- serverRoutes: routes,
120
- htmlTemplates
121
- };
122
- api.setAppContext(appContext);
123
- if ((0, import_utils2.checkIsBuildCommands)()) {
124
- await hookRunners.generateEntryCode({
125
- entrypoints
126
- });
127
- const normalizedConfig = api.useResolvedConfigContext();
128
- const createBuilderForModern = await (0, import_builder.createBuilderGenerator)(bundler);
129
- const builder = await createBuilderForModern({
130
- normalizedConfig,
131
- appContext
132
- });
133
- builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
134
- if (!isFirstCompile) {
135
- return;
136
- }
137
- const hookRunners2 = api.useHookRunners();
138
- await (0, import_routes.generateRoutes)(appContext);
139
- await hookRunners2.beforeBuild({
140
- bundlerConfigs
141
- });
133
+ builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch }) => {
134
+ if (!isFirstCompile) {
135
+ return;
136
+ }
137
+ await (0, import_routes.generateRoutes)(appContext);
138
+ await hooks.onBeforeBuild.call({
139
+ isFirstCompile,
140
+ isWatch,
141
+ environments,
142
+ bundlerConfigs
142
143
  });
143
- builder.onAfterBuild(async ({ stats }) => {
144
- const hookRunners2 = api.useHookRunners();
145
- await hookRunners2.afterBuild({
146
- stats
147
- });
148
- await (0, import_config2.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
144
+ });
145
+ builder.onAfterBuild(async ({ stats, environments, isFirstCompile, isWatch }) => {
146
+ await hooks.onAfterBuild.call({
147
+ stats,
148
+ environments,
149
+ isFirstCompile,
150
+ isWatch
149
151
  });
150
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
151
- const hookRunners2 = api.useHookRunners();
152
- hookRunners2.afterDev({
153
- isFirstCompile
154
- });
155
- if (isFirstCompile) {
156
- (0, import_printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
157
- }
152
+ await (0, import_config2.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
153
+ });
154
+ builder.onDevCompileDone(async ({ isFirstCompile }) => {
155
+ hooks.onAfterDev.call({
156
+ isFirstCompile
158
157
  });
159
- builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
160
- const hookRunners2 = api.useHookRunners();
161
- await hookRunners2.beforeCreateCompiler({
162
- bundlerConfigs
163
- });
158
+ if (isFirstCompile) {
159
+ (0, import_printInstructions.printInstructions)(hooks, appContext, normalizedConfig);
160
+ }
161
+ });
162
+ builder.onBeforeCreateCompiler(async ({ bundlerConfigs, environments }) => {
163
+ await hooks.onBeforeCreateCompiler.call({
164
+ environments,
165
+ bundlerConfigs
164
166
  });
165
- builder.onAfterCreateCompiler(async ({ compiler }) => {
166
- const hookRunners2 = api.useHookRunners();
167
- await hookRunners2.afterCreateCompiler({
168
- compiler
169
- });
167
+ });
168
+ builder.onAfterCreateCompiler(async ({ compiler, environments }) => {
169
+ await hooks.onAfterCreateCompiler.call({
170
+ environments,
171
+ compiler
170
172
  });
171
- builder.addPlugins(resolvedConfig.builderPlugins);
172
- appContext = {
173
- ...api.useAppContext(),
174
- builder
175
- };
176
- api.setAppContext(appContext);
177
- }
178
- },
179
- watchFiles() {
180
- return {
181
- files: pagesDir,
182
- isPrivate: true
183
- };
184
- },
185
- resolvedConfig({ resolved }) {
186
- const appContext = api.useAppContext();
187
- const config = (0, import_config.initialNormalizedConfig)(resolved, appContext, bundler);
188
- return {
189
- resolved: config
190
- };
173
+ });
174
+ builder.addPlugins(resolvedConfig.builderPlugins);
175
+ api.updateAppContext({
176
+ builder
177
+ });
191
178
  }
192
- };
179
+ });
180
+ api.addWatchFiles(() => {
181
+ return {
182
+ files: pagesDir,
183
+ isPrivate: true
184
+ };
185
+ });
186
+ api.modifyResolvedConfig((resolved) => {
187
+ const appContext = api.getAppContext();
188
+ const config = (0, import_config.initialNormalizedConfig)(resolved, appContext, bundler);
189
+ return config;
190
+ });
193
191
  }
194
192
  });
@@ -45,20 +45,18 @@ var deploy_default = () => ({
45
45
  name: "@modern-js/plugin-deploy",
46
46
  setup: (api) => {
47
47
  const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
48
- return {
49
- async deploy() {
50
- const appContext = api.useAppContext();
51
- const { metaName } = appContext;
52
- if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
53
- return;
54
- }
55
- const modernConfig = api.useResolvedConfigContext();
56
- const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
57
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
58
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
59
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
60
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
48
+ api.deploy(async () => {
49
+ const appContext = api.getAppContext();
50
+ const { metaName } = appContext;
51
+ if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
52
+ return;
61
53
  }
62
- };
54
+ const modernConfig = api.getNormalizedConfig();
55
+ const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
56
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
57
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
58
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
59
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
60
+ });
63
61
  }
64
62
  });
@@ -34,60 +34,54 @@ var initialize_default = ({ bundler }) => ({
34
34
  "@modern-js/plugin-polyfill"
35
35
  ],
36
36
  setup(api) {
37
- const config = () => {
38
- const appContext = api.useAppContext();
39
- const userConfig = api.useConfigContext();
40
- api.setAppContext({
41
- ...appContext,
37
+ api.config(() => {
38
+ const appContext = api.getAppContext();
39
+ const userConfig = api.getConfig();
40
+ api.updateAppContext({
42
41
  bundlerType: bundler
43
42
  });
44
43
  return (0, import_config.checkIsLegacyConfig)(userConfig) ? (0, import_config.createLegacyDefaultConfig)(appContext) : (0, import_config.createDefaultConfig)(appContext);
45
- };
46
- return {
47
- config,
48
- async resolvedConfig({ resolved }) {
49
- var _resolved_output_distPath;
50
- let appContext = api.useAppContext();
51
- const userConfig = api.useConfigContext();
52
- const port = await getServerPort(resolved);
53
- appContext = {
54
- ...appContext,
55
- port,
56
- distDirectory: (0, import_utils.ensureAbsolutePath)(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
57
- };
58
- api.setAppContext(appContext);
59
- const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_config.transformNormalizedConfig)(resolved) : resolved;
60
- resolved._raw = userConfig;
61
- resolved.server = {
62
- ...normalizedConfig.server || {},
63
- port
64
- };
65
- var _normalizedConfig_autoLoadPlugins;
66
- resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
67
- stabilizeConfig(resolved, normalizedConfig, [
68
- "source",
69
- "bff",
70
- "dev",
71
- "html",
72
- "output",
73
- "tools",
74
- "testing",
75
- "plugins",
76
- "builderPlugins",
77
- "runtime",
78
- "runtimeByEntries",
79
- "deploy",
80
- "performance"
81
- ]);
82
- if (bundler === "webpack") {
83
- resolved.security = normalizedConfig.security || {};
84
- resolved.experiments = normalizedConfig.experiments;
85
- }
86
- return {
87
- resolved
88
- };
44
+ });
45
+ api.modifyResolvedConfig(async (resolved) => {
46
+ var _resolved_output_distPath;
47
+ let appContext = api.getAppContext();
48
+ const userConfig = api.getConfig();
49
+ const port = await getServerPort(resolved);
50
+ appContext = {
51
+ ...appContext,
52
+ port,
53
+ distDirectory: (0, import_utils.ensureAbsolutePath)(appContext.appDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
54
+ };
55
+ api.updateAppContext(appContext);
56
+ const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_config.transformNormalizedConfig)(resolved) : resolved;
57
+ resolved._raw = userConfig;
58
+ resolved.server = {
59
+ ...normalizedConfig.server || {},
60
+ port
61
+ };
62
+ var _normalizedConfig_autoLoadPlugins;
63
+ resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
64
+ stabilizeConfig(resolved, normalizedConfig, [
65
+ "source",
66
+ "bff",
67
+ "dev",
68
+ "html",
69
+ "output",
70
+ "tools",
71
+ "testing",
72
+ "plugins",
73
+ "builderPlugins",
74
+ "runtime",
75
+ "runtimeByEntries",
76
+ "deploy",
77
+ "performance"
78
+ ]);
79
+ if (bundler === "webpack") {
80
+ resolved.security = normalizedConfig.security || {};
81
+ resolved.experiments = normalizedConfig.experiments;
89
82
  }
90
- };
83
+ return resolved;
84
+ });
91
85
  }
92
86
  });
93
87
  function stabilizeConfig(resolve, config, keys) {
@@ -50,39 +50,37 @@ function checkHasConfig(appDir, metaName = "modern-js") {
50
50
  var serverBuild_default = () => ({
51
51
  name: "@modern-js/server-build",
52
52
  setup(api) {
53
- return {
54
- async afterBuild() {
55
- const { appDirectory, distDirectory, metaName } = api.useAppContext();
56
- if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
57
- return;
58
- }
59
- const modernConfig = api.useResolvedConfigContext();
60
- const distDir = import_path.default.resolve(distDirectory);
61
- const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
62
- const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
63
- const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
64
- const sourceDirs = [];
65
- if (import_fs.default.existsSync(serverDir)) {
66
- sourceDirs.push(serverDir);
67
- if (import_fs.default.existsSync(sharedDir)) {
68
- sourceDirs.push(sharedDir);
69
- }
70
- }
71
- const { server } = modernConfig;
72
- const { alias } = modernConfig.source;
73
- const { babel } = modernConfig.tools;
74
- if (sourceDirs.length > 0) {
75
- await (0, import_server_utils.compile)(appDirectory, {
76
- server,
77
- alias,
78
- babelConfig: babel
79
- }, {
80
- sourceDirs,
81
- distDir,
82
- tsconfigPath
83
- });
53
+ api.onAfterBuild(async () => {
54
+ const { appDirectory, distDirectory, metaName } = api.getAppContext();
55
+ if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
56
+ return;
57
+ }
58
+ const modernConfig = api.getNormalizedConfig();
59
+ const distDir = import_path.default.resolve(distDirectory);
60
+ const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
61
+ const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
62
+ const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
63
+ const sourceDirs = [];
64
+ if (import_fs.default.existsSync(serverDir)) {
65
+ sourceDirs.push(serverDir);
66
+ if (import_fs.default.existsSync(sharedDir)) {
67
+ sourceDirs.push(sharedDir);
84
68
  }
85
69
  }
86
- };
70
+ const { server } = modernConfig;
71
+ const { alias } = modernConfig.source;
72
+ const { babel } = modernConfig.tools;
73
+ if (sourceDirs.length > 0) {
74
+ await (0, import_server_utils.compile)(appDirectory, {
75
+ server,
76
+ alias,
77
+ babelConfig: babel
78
+ }, {
79
+ sourceDirs,
80
+ distDir,
81
+ tsconfigPath
82
+ });
83
+ }
84
+ });
87
85
  }
88
86
  });
@@ -24,11 +24,11 @@ module.exports = __toCommonJS(run_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
25
  var import_run = require("@modern-js/plugin-v2/run");
26
26
  var import_utils = require("@modern-js/utils");
27
- var import_hooks = require("./compat/hooks");
28
- var import_constants = require("./constants");
29
- var import_getConfigFile = require("./getConfigFile");
30
- var import_loadPlugins = require("./loadPlugins");
31
- var import_utils2 = require("./utils");
27
+ var import_hooks = require("../compat/hooks");
28
+ var import_constants = require("../constants");
29
+ var import_getConfigFile = require("../utils/getConfigFile");
30
+ var import_isAutoLoadPlugins = require("../utils/isAutoLoadPlugins");
31
+ var import_loadPlugins = require("../utils/loadPlugins");
32
32
  async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
33
33
  const command = process.argv[2];
34
34
  const cliParams = (0, import_utils.minimist)(process.argv.slice(2));
@@ -50,7 +50,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
50
50
  }
51
51
  const appDirectory = await (0, import_cli.initAppDir)(cwd);
52
52
  const finalConfigFile = customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile);
53
- const autoLoadPlugins = await (0, import_utils2.getIsAutoLoadPlugins)(appDirectory, finalConfigFile);
53
+ const autoLoadPlugins = await (0, import_isAutoLoadPlugins.isAutoLoadPlugins)(appDirectory, finalConfigFile);
54
54
  const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
55
55
  await (0, import_run.run)({
56
56
  cwd,
@@ -12,5 +12,5 @@ var __copyProps = (to, from, except, desc) => {
12
12
  return to;
13
13
  };
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
15
+ var new_exports = {};
16
+ module.exports = __toCommonJS(new_exports);
@@ -33,7 +33,7 @@ __export(getConfigFile_exports, {
33
33
  module.exports = __toCommonJS(getConfigFile_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
- var import_constants = require("./constants");
36
+ var import_constants = require("../constants");
37
37
  const getConfigFile = (configFile) => (0, import_utils.findExists)(import_utils.CONFIG_FILE_EXTENSIONS.map((extension) => import_path.default.resolve(process.cwd(), `${configFile || import_constants.DEFAULT_CONFIG_FILE}${extension}`)));
38
38
  // Annotate the CommonJS export names for ESM import in node:
39
39
  0 && (module.exports = {