@modern-js/app-tools 2.63.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 (135) 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 +15 -8
  9. package/dist/cjs/{new/compat → compat}/index.js +4 -1
  10. package/dist/cjs/{new/compat → compat}/utils.js +10 -1
  11. package/dist/cjs/index.js +154 -5
  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 +1 -1
  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 → utils}/getConfigFile.js +1 -1
  21. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -4
  22. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  23. package/dist/cjs/utils/loadPlugins.js +35 -4
  24. package/dist/cjs/utils/printInstructions.js +2 -2
  25. package/dist/cjs/utils/restart.js +4 -3
  26. package/dist/esm/commands/build.js +18 -12
  27. package/dist/esm/commands/deploy.js +6 -6
  28. package/dist/esm/commands/dev.js +10 -10
  29. package/dist/esm/commands/index.js +8 -8
  30. package/dist/esm/commands/inspect.js +1 -1
  31. package/dist/esm/commands/serve.js +5 -5
  32. package/dist/esm/{new/compat → compat}/hooks.js +41 -41
  33. package/dist/esm/{new/compat → compat}/index.js +4 -1
  34. package/dist/esm/{new/compat → compat}/utils.js +10 -1
  35. package/dist/esm/index.js +245 -2
  36. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  37. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  38. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  39. package/dist/esm/plugins/analyze/index.js +328 -331
  40. package/dist/esm/plugins/deploy/index.js +84 -88
  41. package/dist/esm/plugins/initialize/index.js +1 -1
  42. package/dist/esm/plugins/serverBuild.js +52 -56
  43. package/dist/esm/{new/run.js → run/index.js} +6 -6
  44. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  45. package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -1
  46. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  47. package/dist/esm/utils/loadPlugins.js +95 -7
  48. package/dist/esm/utils/printInstructions.js +3 -3
  49. package/dist/esm/utils/restart.js +5 -4
  50. package/dist/esm-node/commands/build.js +19 -13
  51. package/dist/esm-node/commands/deploy.js +5 -5
  52. package/dist/esm-node/commands/dev.js +11 -11
  53. package/dist/esm-node/commands/index.js +6 -6
  54. package/dist/esm-node/commands/inspect.js +1 -1
  55. package/dist/esm-node/commands/serve.js +4 -4
  56. package/dist/esm-node/{new/compat → compat}/hooks.js +15 -8
  57. package/dist/esm-node/{new/compat → compat}/index.js +4 -1
  58. package/dist/esm-node/{new/compat → compat}/utils.js +10 -1
  59. package/dist/esm-node/index.js +140 -2
  60. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  61. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  62. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  63. package/dist/esm-node/plugins/analyze/index.js +128 -130
  64. package/dist/esm-node/plugins/deploy/index.js +12 -14
  65. package/dist/esm-node/plugins/initialize/index.js +1 -1
  66. package/dist/esm-node/plugins/serverBuild.js +30 -32
  67. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  68. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  69. package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -1
  70. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  71. package/dist/esm-node/utils/loadPlugins.js +34 -4
  72. package/dist/esm-node/utils/printInstructions.js +2 -2
  73. package/dist/esm-node/utils/restart.js +4 -3
  74. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  75. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  76. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  77. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  78. package/dist/types/builder/index.d.ts +1 -1
  79. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  80. package/dist/types/builder/shared/types.d.ts +3 -2
  81. package/dist/types/commands/build.d.ts +2 -2
  82. package/dist/types/commands/deploy.d.ts +2 -2
  83. package/dist/types/commands/dev.d.ts +2 -2
  84. package/dist/types/commands/index.d.ts +6 -6
  85. package/dist/types/commands/inspect.d.ts +2 -2
  86. package/dist/types/commands/serve.d.ts +2 -2
  87. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  88. package/dist/types/compat/index.d.ts +2 -0
  89. package/dist/types/config/initialize/index.d.ts +3 -2
  90. package/dist/types/config/initialize/inits.d.ts +4 -3
  91. package/dist/types/index.d.ts +5 -3
  92. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  93. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  94. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  95. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  96. package/dist/types/plugins/analyze/index.d.ts +2 -3
  97. package/dist/types/plugins/deploy/index.d.ts +2 -3
  98. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  99. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  100. package/dist/types/plugins/serverBuild.d.ts +2 -2
  101. package/dist/types/types/index.d.ts +2 -0
  102. package/dist/types/types/new.d.ts +46 -34
  103. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  104. package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
  105. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  106. package/dist/types/utils/loadPlugins.d.ts +13 -3
  107. package/dist/types/utils/printInstructions.d.ts +3 -3
  108. package/dist/types/utils/restart.d.ts +2 -3
  109. package/dist/types/utils/routes.d.ts +2 -1
  110. package/package.json +14 -15
  111. package/dist/cjs/hooks.js +0 -60
  112. package/dist/cjs/new/index.js +0 -79
  113. package/dist/cjs/new/loadPlugins.js +0 -57
  114. package/dist/cjs/old.js +0 -179
  115. package/dist/esm/hooks.js +0 -36
  116. package/dist/esm/new/index.js +0 -55
  117. package/dist/esm/new/loadPlugins.js +0 -94
  118. package/dist/esm/old.js +0 -258
  119. package/dist/esm-node/hooks.js +0 -36
  120. package/dist/esm-node/new/index.js +0 -52
  121. package/dist/esm-node/new/loadPlugins.js +0 -33
  122. package/dist/esm-node/old.js +0 -140
  123. package/dist/types/hooks.d.ts +0 -2
  124. package/dist/types/new/compat/index.d.ts +0 -2
  125. package/dist/types/new/index.d.ts +0 -6
  126. package/dist/types/new/loadPlugins.d.ts +0 -9
  127. package/dist/types/new/utils/index.d.ts +0 -1
  128. package/dist/types/old.d.ts +0 -13
  129. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  130. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  131. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  132. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  133. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  134. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  135. /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
  });
@@ -50,7 +50,7 @@ var initialize_default = ({ bundler }) => ({
50
50
  appContext = {
51
51
  ...appContext,
52
52
  port,
53
- 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")
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
54
  };
55
55
  api.updateAppContext(appContext);
56
56
  const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_config.transformNormalizedConfig)(resolved) : resolved;
@@ -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,
@@ -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 = {
@@ -26,11 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var context_exports = {};
30
- __export(context_exports, {
29
+ var initAppContext_exports = {};
30
+ __export(initAppContext_exports, {
31
31
  initAppContext: () => initAppContext
32
32
  });
33
- module.exports = __toCommonJS(context_exports);
33
+ module.exports = __toCommonJS(initAppContext_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
36
  const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir }) => {
@@ -46,7 +46,6 @@ const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfig
46
46
  apiDirectory: import_path.default.resolve(appDirectory, apiDir),
47
47
  lambdaDirectory: import_path.default.resolve(appDirectory, apiDir, "lambda"),
48
48
  sharedDirectory: import_path.default.resolve(appDirectory, sharedDir),
49
- distDirectory: distDir,
50
49
  serverPlugins: [],
51
50
  internalDirectory: import_path.default.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
52
51
  htmlTemplates: {},
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var utils_exports = {};
20
- __export(utils_exports, {
21
- getIsAutoLoadPlugins: () => getIsAutoLoadPlugins
19
+ var isAutoLoadPlugins_exports = {};
20
+ __export(isAutoLoadPlugins_exports, {
21
+ isAutoLoadPlugins: () => isAutoLoadPlugins
22
22
  });
23
- module.exports = __toCommonJS(utils_exports);
23
+ module.exports = __toCommonJS(isAutoLoadPlugins_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
- async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
25
+ async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
26
26
  var _loaded_config;
27
27
  const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
28
28
  const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
@@ -30,5 +30,5 @@ async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts
30
30
  }
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
33
- getIsAutoLoadPlugins
33
+ isAutoLoadPlugins
34
34
  });
@@ -19,18 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var loadPlugins_exports = {};
20
20
  __export(loadPlugins_exports, {
21
21
  getServerPlugins: () => getServerPlugins,
22
+ loadInternalPlugins: () => loadInternalPlugins,
22
23
  loadServerPlugins: () => loadServerPlugins
23
24
  });
24
25
  module.exports = __toCommonJS(loadPlugins_exports);
25
26
  var import_prod_server = require("@modern-js/prod-server");
27
+ var import_utils = require("@modern-js/utils");
28
+ const debug = (0, import_utils.createDebugger)("load-plugins");
26
29
  async function getServerPlugins(api, metaName = "modern-js") {
27
- const runner = api.useHookRunners();
28
- const { plugins } = await runner._internalServerPlugins({
30
+ const hooks = api.getHooks();
31
+ const { plugins } = await hooks._internalServerPlugins.call({
29
32
  plugins: []
30
33
  });
31
34
  const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
32
- api.setAppContext({
33
- ...api.useAppContext(),
35
+ api.updateAppContext({
34
36
  serverPlugins: filtedPlugins
35
37
  });
36
38
  return filtedPlugins;
@@ -40,8 +42,37 @@ async function loadServerPlugins(api, appDirectory, metaName) {
40
42
  const instances = await (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
41
43
  return instances;
42
44
  }
45
+ const resolveCliPlugin = async (p, appDirectory) => {
46
+ const pkg = typeof p === "string" ? p : p[0];
47
+ const pluginOptions = typeof p === "string" ? void 0 : p[1];
48
+ const path = (0, import_utils.tryResolve)(pkg, appDirectory);
49
+ let module2;
50
+ try {
51
+ module2 = await (0, import_utils.compatibleRequire)(path);
52
+ } catch (e) {
53
+ ({ default: module2 } = await (0, import_utils.dynamicImport)(path));
54
+ }
55
+ if (typeof module2 === "function") {
56
+ const result = module2(pluginOptions);
57
+ return result;
58
+ }
59
+ return module2;
60
+ };
61
+ const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
62
+ const plugins = [
63
+ ...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
64
+ ...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
65
+ ];
66
+ const loadedPlugins = await Promise.all(plugins.map((plugin) => {
67
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
68
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
69
+ return loadedPlugin;
70
+ }));
71
+ return loadedPlugins;
72
+ };
43
73
  // Annotate the CommonJS export names for ESM import in node:
44
74
  0 && (module.exports = {
45
75
  getServerPlugins,
76
+ loadInternalPlugins,
46
77
  loadServerPlugins
47
78
  });
@@ -22,9 +22,9 @@ __export(printInstructions_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(printInstructions_exports);
24
24
  var import_utils = require("@modern-js/utils");
25
- const printInstructions = async (hookRunners, appContext, config) => {
25
+ const printInstructions = async (hooks, appContext, config) => {
26
26
  const message = (0, import_utils.prettyInstructions)(appContext, config);
27
- const { instructions } = await hookRunners.beforePrintInstructions({
27
+ const { instructions } = await hooks.onBeforePrintInstructions.call({
28
28
  instructions: message
29
29
  });
30
30
  import_utils.logger.log(instructions);