@modern-js/app-tools 2.62.2-alpha.0 → 2.63.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -21,7 +21,36 @@ const findPartials = (dir, entryName, position) => {
21
21
  }
22
22
  return null;
23
23
  };
24
- const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
24
+ const getModifyHtmlPartials = (partials) => {
25
+ const append = (type, ...script) => {
26
+ script.forEach((item) => {
27
+ partials[type].push(item);
28
+ });
29
+ };
30
+ const prepend = (type, ...script) => {
31
+ script.forEach((item) => {
32
+ partials[type].unshift(item);
33
+ });
34
+ };
35
+ return {
36
+ top: {
37
+ append: (...script) => append("top", ...script),
38
+ prepend: (...script) => prepend("top", ...script),
39
+ current: partials.top
40
+ },
41
+ head: {
42
+ append: (...script) => append("head", ...script),
43
+ prepend: (...script) => prepend("head", ...script),
44
+ current: partials.head
45
+ },
46
+ body: {
47
+ append: (...script) => append("body", ...script),
48
+ prepend: (...script) => prepend("body", ...script),
49
+ current: partials.body
50
+ }
51
+ };
52
+ };
53
+ const getHtmlTemplate = async (entrypoints, hooks, { appContext, config }) => {
25
54
  const { appDirectory, internalDirectory } = appContext;
26
55
  const { source: { configDir } } = config;
27
56
  const htmlDir = path.resolve(appDirectory, configDir || "", HTML_PARTIALS_FOLDER);
@@ -34,24 +63,20 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
34
63
  if (customIndexTemplate) {
35
64
  htmlTemplates[entryName] = customIndexTemplate.file;
36
65
  } else {
37
- const hookRunners = api.useHookRunners();
38
- const { partials } = await hookRunners.htmlPartials({
66
+ const getPartialInitValue = (position) => {
67
+ const partial = findPartials(htmlDir, name, position);
68
+ return partial ? [
69
+ partial.content
70
+ ] : [];
71
+ };
72
+ const partials = {
73
+ top: getPartialInitValue("top"),
74
+ head: getPartialInitValue("head"),
75
+ body: getPartialInitValue("body")
76
+ };
77
+ await hooks.modifyHtmlPartials.call({
39
78
  entrypoint,
40
- partials: [
41
- "top",
42
- "head",
43
- "body"
44
- ].reduce((previous, position) => {
45
- const found = findPartials(htmlDir, name, position);
46
- previous[position] = found ? [
47
- found.content
48
- ] : [];
49
- return previous;
50
- }, {
51
- top: [],
52
- head: [],
53
- body: []
54
- })
79
+ partials: getModifyHtmlPartials(partials)
55
80
  });
56
81
  const templatePath = path.resolve(internalDirectory, entryName, "index.html");
57
82
  fs.outputFileSync(templatePath, templates.html(partials), "utf8");
@@ -63,12 +88,12 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
63
88
  }
64
89
  }
65
90
  }
66
- api.setAppContext({
67
- ...api.useAppContext(),
68
- partialsByEntrypoint
69
- });
70
- return htmlTemplates;
91
+ return {
92
+ partialsByEntrypoint,
93
+ htmlTemplates
94
+ };
71
95
  };
72
96
  export {
73
- getHtmlTemplate
97
+ getHtmlTemplate,
98
+ getModifyHtmlPartials
74
99
  };
@@ -16,147 +16,145 @@ var analyze_default = ({ bundler }) => ({
16
16
  setup: (api) => {
17
17
  let pagesDir = [];
18
18
  let nestedRouteEntries = [];
19
- return {
20
- async prepare() {
21
- var _resolvedConfig_source;
22
- let appContext = api.useAppContext();
23
- const resolvedConfig = api.useResolvedConfigContext();
24
- const hookRunners = api.useHookRunners();
25
- try {
26
- if (checkIsBuildCommands()) {
27
- fs.emptydirSync(appContext.internalDirectory);
28
- }
29
- } catch {
30
- }
31
- const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
32
- await hookRunners.addRuntimeExports();
33
- if (apiOnly) {
34
- const { routes: routes2 } = await hookRunners.modifyServerRoutes({
35
- routes: []
36
- });
37
- debug(`server routes: %o`, routes2);
38
- appContext = {
39
- ...api.useAppContext(),
40
- apiOnly,
41
- serverRoutes: routes2
42
- };
43
- api.setAppContext(appContext);
44
- return;
19
+ api.onPrepare(async () => {
20
+ var _resolvedConfig_source;
21
+ let appContext = api.getAppContext();
22
+ const resolvedConfig = api.getNormalizedConfig();
23
+ const hooks = api.getHooks();
24
+ try {
25
+ if (checkIsBuildCommands()) {
26
+ fs.emptydirSync(appContext.internalDirectory);
45
27
  }
46
- const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
47
- import("./getBundleEntry.js"),
48
- import("./getServerRoutes.js"),
49
- import("./getHtmlTemplate.js")
50
- ]);
51
- const { entrypoints } = await hookRunners.modifyEntrypoints({
52
- entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
28
+ } catch {
29
+ }
30
+ const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
31
+ await hooks.addRuntimeExports.call();
32
+ if (apiOnly) {
33
+ const { routes: routes2 } = await hooks.modifyServerRoutes.call({
34
+ routes: []
53
35
  });
54
- debug(`entrypoints: %o`, entrypoints);
55
- const initialRoutes = getServerRoutes(entrypoints, {
56
- appContext,
57
- config: resolvedConfig
36
+ debug(`server routes: %o`, routes2);
37
+ api.updateAppContext({
38
+ apiOnly,
39
+ serverRoutes: routes2
58
40
  });
59
- const { routes } = await hookRunners.modifyServerRoutes({
60
- routes: initialRoutes
41
+ return;
42
+ }
43
+ const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
44
+ import("./getBundleEntry.js"),
45
+ import("./getServerRoutes.js"),
46
+ import("./getHtmlTemplate.js")
47
+ ]);
48
+ const { entrypoints } = await hooks.modifyEntrypoints.call({
49
+ entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
50
+ });
51
+ debug(`entrypoints: %o`, entrypoints);
52
+ const initialRoutes = getServerRoutes(entrypoints, {
53
+ appContext,
54
+ config: resolvedConfig
55
+ });
56
+ const { routes } = await hooks.modifyServerRoutes.call({
57
+ routes: initialRoutes
58
+ });
59
+ debug(`server routes: %o`, routes);
60
+ appContext = {
61
+ ...api.getAppContext(),
62
+ entrypoints,
63
+ serverRoutes: routes
64
+ };
65
+ api.updateAppContext(appContext);
66
+ nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
67
+ pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
68
+ const { partialsByEntrypoint, htmlTemplates } = await getHtmlTemplate(entrypoints, hooks, {
69
+ appContext,
70
+ config: resolvedConfig
71
+ });
72
+ debug(`html templates: %o`, htmlTemplates);
73
+ api.updateAppContext({
74
+ partialsByEntrypoint
75
+ });
76
+ let checkedEntries = entrypoints.map((point) => point.entryName);
77
+ if (isDevCommand()) {
78
+ const { entry } = minimist(getArgv());
79
+ checkedEntries = await getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
80
+ }
81
+ appContext = {
82
+ ...api.getAppContext(),
83
+ entrypoints,
84
+ checkedEntries,
85
+ apiOnly,
86
+ serverRoutes: routes,
87
+ htmlTemplates
88
+ };
89
+ api.updateAppContext(appContext);
90
+ if (checkIsBuildCommands()) {
91
+ await hooks.generateEntryCode.call({
92
+ entrypoints
61
93
  });
62
- debug(`server routes: %o`, routes);
63
- appContext = {
64
- ...api.useAppContext(),
65
- entrypoints,
66
- serverRoutes: routes
67
- };
68
- api.setAppContext(appContext);
69
- nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
70
- pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
71
- const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
72
- appContext,
73
- config: resolvedConfig
94
+ const normalizedConfig = api.getNormalizedConfig();
95
+ const createBuilderForModern = await createBuilderGenerator(bundler);
96
+ const builder = await createBuilderForModern({
97
+ normalizedConfig,
98
+ appContext
74
99
  });
75
- debug(`html templates: %o`, htmlTemplates);
76
- let checkedEntries = entrypoints.map((point) => point.entryName);
77
- if (isDevCommand()) {
78
- const { entry } = minimist(getArgv());
79
- checkedEntries = await getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
80
- }
81
- appContext = {
82
- ...api.useAppContext(),
83
- entrypoints,
84
- checkedEntries,
85
- apiOnly,
86
- serverRoutes: routes,
87
- htmlTemplates
88
- };
89
- api.setAppContext(appContext);
90
- if (checkIsBuildCommands()) {
91
- await hookRunners.generateEntryCode({
92
- entrypoints
93
- });
94
- const normalizedConfig = api.useResolvedConfigContext();
95
- const createBuilderForModern = await createBuilderGenerator(bundler);
96
- const builder = await createBuilderForModern({
97
- normalizedConfig,
98
- appContext
99
- });
100
- builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
101
- if (!isFirstCompile) {
102
- return;
103
- }
104
- const hookRunners2 = api.useHookRunners();
105
- await generateRoutes(appContext);
106
- await hookRunners2.beforeBuild({
107
- bundlerConfigs
108
- });
100
+ builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch }) => {
101
+ if (!isFirstCompile) {
102
+ return;
103
+ }
104
+ await generateRoutes(appContext);
105
+ await hooks.onBeforeBuild.call({
106
+ isFirstCompile,
107
+ isWatch,
108
+ environments,
109
+ bundlerConfigs
109
110
  });
110
- builder.onAfterBuild(async ({ stats }) => {
111
- const hookRunners2 = api.useHookRunners();
112
- await hookRunners2.afterBuild({
113
- stats
114
- });
115
- await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
111
+ });
112
+ builder.onAfterBuild(async ({ stats, environments, isFirstCompile, isWatch }) => {
113
+ await hooks.onAfterBuild.call({
114
+ stats,
115
+ environments,
116
+ isFirstCompile,
117
+ isWatch
116
118
  });
117
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
118
- const hookRunners2 = api.useHookRunners();
119
- hookRunners2.afterDev({
120
- isFirstCompile
121
- });
122
- if (isFirstCompile) {
123
- printInstructions(hookRunners2, appContext, normalizedConfig);
124
- }
119
+ await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
120
+ });
121
+ builder.onDevCompileDone(async ({ isFirstCompile }) => {
122
+ hooks.onAfterDev.call({
123
+ isFirstCompile
125
124
  });
126
- builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
127
- const hookRunners2 = api.useHookRunners();
128
- await hookRunners2.beforeCreateCompiler({
129
- bundlerConfigs
130
- });
125
+ if (isFirstCompile) {
126
+ printInstructions(hooks, appContext, normalizedConfig);
127
+ }
128
+ });
129
+ builder.onBeforeCreateCompiler(async ({ bundlerConfigs, environments }) => {
130
+ await hooks.onBeforeCreateCompiler.call({
131
+ environments,
132
+ bundlerConfigs
131
133
  });
132
- builder.onAfterCreateCompiler(async ({ compiler }) => {
133
- const hookRunners2 = api.useHookRunners();
134
- await hookRunners2.afterCreateCompiler({
135
- compiler
136
- });
134
+ });
135
+ builder.onAfterCreateCompiler(async ({ compiler, environments }) => {
136
+ await hooks.onAfterCreateCompiler.call({
137
+ environments,
138
+ compiler
137
139
  });
138
- builder.addPlugins(resolvedConfig.builderPlugins);
139
- appContext = {
140
- ...api.useAppContext(),
141
- builder
142
- };
143
- api.setAppContext(appContext);
144
- }
145
- },
146
- watchFiles() {
147
- return {
148
- files: pagesDir,
149
- isPrivate: true
150
- };
151
- },
152
- resolvedConfig({ resolved }) {
153
- const appContext = api.useAppContext();
154
- const config = initialNormalizedConfig(resolved, appContext, bundler);
155
- return {
156
- resolved: config
157
- };
140
+ });
141
+ builder.addPlugins(resolvedConfig.builderPlugins);
142
+ api.updateAppContext({
143
+ builder
144
+ });
158
145
  }
159
- };
146
+ });
147
+ api.addWatchFiles(() => {
148
+ return {
149
+ files: pagesDir,
150
+ isPrivate: true
151
+ };
152
+ });
153
+ api.modifyResolvedConfig((resolved) => {
154
+ const appContext = api.getAppContext();
155
+ const config = initialNormalizedConfig(resolved, appContext, bundler);
156
+ return config;
157
+ });
160
158
  }
161
159
  });
162
160
  export {
@@ -22,21 +22,19 @@ var deploy_default = () => ({
22
22
  name: "@modern-js/plugin-deploy",
23
23
  setup: (api) => {
24
24
  const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
25
- return {
26
- async deploy() {
27
- const appContext = api.useAppContext();
28
- const { metaName } = appContext;
29
- if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
30
- return;
31
- }
32
- const modernConfig = api.useResolvedConfigContext();
33
- const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
34
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
35
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
36
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
37
- (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
25
+ api.deploy(async () => {
26
+ const appContext = api.getAppContext();
27
+ const { metaName } = appContext;
28
+ if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
29
+ return;
38
30
  }
39
- };
31
+ const modernConfig = api.getNormalizedConfig();
32
+ const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
33
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
34
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
35
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
36
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
37
+ });
40
38
  }
41
39
  });
42
40
  export {
@@ -11,60 +11,54 @@ var initialize_default = ({ bundler }) => ({
11
11
  "@modern-js/plugin-polyfill"
12
12
  ],
13
13
  setup(api) {
14
- const config = () => {
15
- const appContext = api.useAppContext();
16
- const userConfig = api.useConfigContext();
17
- api.setAppContext({
18
- ...appContext,
14
+ api.config(() => {
15
+ const appContext = api.getAppContext();
16
+ const userConfig = api.getConfig();
17
+ api.updateAppContext({
19
18
  bundlerType: bundler
20
19
  });
21
20
  return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext);
22
- };
23
- return {
24
- config,
25
- async resolvedConfig({ resolved }) {
26
- var _resolved_output_distPath;
27
- let appContext = api.useAppContext();
28
- const userConfig = api.useConfigContext();
29
- const port = await getServerPort(resolved);
30
- appContext = {
31
- ...appContext,
32
- port,
33
- distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
34
- };
35
- api.setAppContext(appContext);
36
- const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
37
- resolved._raw = userConfig;
38
- resolved.server = {
39
- ...normalizedConfig.server || {},
40
- port
41
- };
42
- var _normalizedConfig_autoLoadPlugins;
43
- resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
44
- stabilizeConfig(resolved, normalizedConfig, [
45
- "source",
46
- "bff",
47
- "dev",
48
- "html",
49
- "output",
50
- "tools",
51
- "testing",
52
- "plugins",
53
- "builderPlugins",
54
- "runtime",
55
- "runtimeByEntries",
56
- "deploy",
57
- "performance"
58
- ]);
59
- if (bundler === "webpack") {
60
- resolved.security = normalizedConfig.security || {};
61
- resolved.experiments = normalizedConfig.experiments;
62
- }
63
- return {
64
- resolved
65
- };
21
+ });
22
+ api.modifyResolvedConfig(async (resolved) => {
23
+ var _resolved_output_distPath;
24
+ let appContext = api.getAppContext();
25
+ const userConfig = api.getConfig();
26
+ const port = await getServerPort(resolved);
27
+ appContext = {
28
+ ...appContext,
29
+ port,
30
+ distDirectory: ensureAbsolutePath(appContext.appDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
31
+ };
32
+ api.updateAppContext(appContext);
33
+ const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
34
+ resolved._raw = userConfig;
35
+ resolved.server = {
36
+ ...normalizedConfig.server || {},
37
+ port
38
+ };
39
+ var _normalizedConfig_autoLoadPlugins;
40
+ resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
41
+ stabilizeConfig(resolved, normalizedConfig, [
42
+ "source",
43
+ "bff",
44
+ "dev",
45
+ "html",
46
+ "output",
47
+ "tools",
48
+ "testing",
49
+ "plugins",
50
+ "builderPlugins",
51
+ "runtime",
52
+ "runtimeByEntries",
53
+ "deploy",
54
+ "performance"
55
+ ]);
56
+ if (bundler === "webpack") {
57
+ resolved.security = normalizedConfig.security || {};
58
+ resolved.experiments = normalizedConfig.experiments;
66
59
  }
67
- };
60
+ return resolved;
61
+ });
68
62
  }
69
63
  });
70
64
  function stabilizeConfig(resolve, config, keys) {
@@ -17,40 +17,38 @@ function checkHasConfig(appDir, metaName = "modern-js") {
17
17
  var serverBuild_default = () => ({
18
18
  name: "@modern-js/server-build",
19
19
  setup(api) {
20
- return {
21
- async afterBuild() {
22
- const { appDirectory, distDirectory, metaName } = api.useAppContext();
23
- if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
24
- return;
25
- }
26
- const modernConfig = api.useResolvedConfigContext();
27
- const distDir = path.resolve(distDirectory);
28
- const serverDir = path.resolve(appDirectory, SERVER_DIR);
29
- const sharedDir = path.resolve(appDirectory, SHARED_DIR);
30
- const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
31
- const sourceDirs = [];
32
- if (fs.existsSync(serverDir)) {
33
- sourceDirs.push(serverDir);
34
- if (fs.existsSync(sharedDir)) {
35
- sourceDirs.push(sharedDir);
36
- }
37
- }
38
- const { server } = modernConfig;
39
- const { alias } = modernConfig.source;
40
- const { babel } = modernConfig.tools;
41
- if (sourceDirs.length > 0) {
42
- await compile(appDirectory, {
43
- server,
44
- alias,
45
- babelConfig: babel
46
- }, {
47
- sourceDirs,
48
- distDir,
49
- tsconfigPath
50
- });
20
+ api.onAfterBuild(async () => {
21
+ const { appDirectory, distDirectory, metaName } = api.getAppContext();
22
+ if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
23
+ return;
24
+ }
25
+ const modernConfig = api.getNormalizedConfig();
26
+ const distDir = path.resolve(distDirectory);
27
+ const serverDir = path.resolve(appDirectory, SERVER_DIR);
28
+ const sharedDir = path.resolve(appDirectory, SHARED_DIR);
29
+ const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
30
+ const sourceDirs = [];
31
+ if (fs.existsSync(serverDir)) {
32
+ sourceDirs.push(serverDir);
33
+ if (fs.existsSync(sharedDir)) {
34
+ sourceDirs.push(sharedDir);
51
35
  }
52
36
  }
53
- };
37
+ const { server } = modernConfig;
38
+ const { alias } = modernConfig.source;
39
+ const { babel } = modernConfig.tools;
40
+ if (sourceDirs.length > 0) {
41
+ await compile(appDirectory, {
42
+ server,
43
+ alias,
44
+ babelConfig: babel
45
+ }, {
46
+ sourceDirs,
47
+ distDir,
48
+ tsconfigPath
49
+ });
50
+ }
51
+ });
54
52
  }
55
53
  });
56
54
  export {
@@ -1,11 +1,11 @@
1
1
  import { initAppDir } from "@modern-js/plugin-v2/cli";
2
2
  import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
3
3
  import { minimist } from "@modern-js/utils";
4
- import { handleSetupResult } from "./compat/hooks";
5
- import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
6
- import { getConfigFile } from "./getConfigFile";
7
- import { loadInternalPlugins } from "./loadPlugins";
8
- import { getIsAutoLoadPlugins } from "./utils";
4
+ import { handleSetupResult } from "../compat/hooks";
5
+ import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
6
+ import { getConfigFile } from "../utils/getConfigFile";
7
+ import { isAutoLoadPlugins } from "../utils/isAutoLoadPlugins";
8
+ import { loadInternalPlugins } from "../utils/loadPlugins";
9
9
  async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
10
10
  const command = process.argv[2];
11
11
  const cliParams = minimist(process.argv.slice(2));
@@ -27,7 +27,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
27
27
  }
28
28
  const appDirectory = await initAppDir(cwd);
29
29
  const finalConfigFile = customConfigFile || getConfigFile(configFile);
30
- const autoLoadPlugins = await getIsAutoLoadPlugins(appDirectory, finalConfigFile);
30
+ const autoLoadPlugins = await isAutoLoadPlugins(appDirectory, finalConfigFile);
31
31
  const plugins = await loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
32
32
  await CLIPluginRun({
33
33
  cwd,
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
3
- import { DEFAULT_CONFIG_FILE } from "./constants";
3
+ import { DEFAULT_CONFIG_FILE } from "../constants";
4
4
  const getConfigFile = (configFile) => findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
5
5
  export {
6
6
  getConfigFile
@@ -1,18 +1,18 @@
1
1
  import path from "path";
2
- import { address } from "@modern-js/utils";
2
+ import { fs, address } from "@modern-js/utils";
3
3
  const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir }) => {
4
4
  const { metaName = "modern-js", apiDir = "api", distDir = "", sharedDir = "shared" } = options || {};
5
+ const pkgPath = path.resolve(appDirectory, "./package.json");
5
6
  return {
6
7
  metaName,
7
8
  runtimeConfigFile,
8
9
  serverConfigFile,
9
10
  ip: address.ip(),
10
11
  port: 0,
11
- moduleType: require(path.resolve(appDirectory, "./package.json")).type || "commonjs",
12
+ moduleType: fs.existsSync(pkgPath) ? require(pkgPath).type || "commonjs" : "commonjs",
12
13
  apiDirectory: path.resolve(appDirectory, apiDir),
13
14
  lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
14
15
  sharedDirectory: path.resolve(appDirectory, sharedDir),
15
- distDirectory: distDir,
16
16
  serverPlugins: [],
17
17
  internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
18
18
  htmlTemplates: {},
@@ -1,10 +1,10 @@
1
1
  import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
2
- async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
2
+ async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
3
3
  var _loaded_config;
4
4
  const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig);
5
5
  const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
6
6
  return autoLoadPlugins || false;
7
7
  }
8
8
  export {
9
- getIsAutoLoadPlugins
9
+ isAutoLoadPlugins
10
10
  };