@modern-js/app-tools 2.63.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 (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
@@ -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 {
@@ -27,7 +27,7 @@ var initialize_default = ({ bundler }) => ({
27
27
  appContext = {
28
28
  ...appContext,
29
29
  port,
30
- distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
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
31
  };
32
32
  api.updateAppContext(appContext);
33
33
  const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
@@ -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
@@ -13,7 +13,6 @@ const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfig
13
13
  apiDirectory: path.resolve(appDirectory, apiDir),
14
14
  lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
15
15
  sharedDirectory: path.resolve(appDirectory, sharedDir),
16
- distDirectory: distDir,
17
16
  serverPlugins: [],
18
17
  internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
19
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
  };
@@ -1,12 +1,13 @@
1
1
  import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
2
+ import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
3
+ const debug = createDebugger("load-plugins");
2
4
  async function getServerPlugins(api, metaName = "modern-js") {
3
- const runner = api.useHookRunners();
4
- const { plugins } = await runner._internalServerPlugins({
5
+ const hooks = api.getHooks();
6
+ const { plugins } = await hooks._internalServerPlugins.call({
5
7
  plugins: []
6
8
  });
7
9
  const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
8
- api.setAppContext({
9
- ...api.useAppContext(),
10
+ api.updateAppContext({
10
11
  serverPlugins: filtedPlugins
11
12
  });
12
13
  return filtedPlugins;
@@ -16,7 +17,36 @@ async function loadServerPlugins(api, appDirectory, metaName) {
16
17
  const instances = await loadServerPluginInstances(plugins, appDirectory);
17
18
  return instances;
18
19
  }
20
+ const resolveCliPlugin = async (p, appDirectory) => {
21
+ const pkg = typeof p === "string" ? p : p[0];
22
+ const pluginOptions = typeof p === "string" ? void 0 : p[1];
23
+ const path = tryResolve(pkg, appDirectory);
24
+ let module;
25
+ try {
26
+ module = await compatibleRequire(path);
27
+ } catch (e) {
28
+ ({ default: module } = await dynamicImport(path));
29
+ }
30
+ if (typeof module === "function") {
31
+ const result = module(pluginOptions);
32
+ return result;
33
+ }
34
+ return module;
35
+ };
36
+ const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
37
+ const plugins = [
38
+ ...autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : [],
39
+ ...autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []
40
+ ];
41
+ const loadedPlugins = await Promise.all(plugins.map((plugin) => {
42
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
43
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
44
+ return loadedPlugin;
45
+ }));
46
+ return loadedPlugins;
47
+ };
19
48
  export {
20
49
  getServerPlugins,
50
+ loadInternalPlugins,
21
51
  loadServerPlugins
22
52
  };
@@ -1,7 +1,7 @@
1
1
  import { logger, prettyInstructions } from "@modern-js/utils";
2
- const printInstructions = async (hookRunners, appContext, config) => {
2
+ const printInstructions = async (hooks, appContext, config) => {
3
3
  const message = prettyInstructions(appContext, config);
4
- const { instructions } = await hookRunners.beforePrintInstructions({
4
+ const { instructions } = await hooks.onBeforePrintInstructions.call({
5
5
  instructions: message
6
6
  });
7
7
  logger.log(instructions);
@@ -1,11 +1,12 @@
1
1
  import { cli } from "@modern-js/plugin-v2/cli";
2
- import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
3
- async function restart(hooksRunner, filename) {
2
+ import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
3
+ import { program } from "@modern-js/utils/commander";
4
+ async function restart(hooks, filename) {
4
5
  clearConsole();
5
6
  logger.info(`Restart because ${chalk.yellow(filename)} is changed...
6
7
  `);
7
8
  let hasGetError = false;
8
- await hooksRunner.beforeRestart();
9
+ await hooks.onBeforeRestart.call();
9
10
  try {
10
11
  await cli.init(cli.getPrevInitOptions());
11
12
  } catch (err) {
@@ -1,3 +1,4 @@
1
1
  import type { RsbuildPlugin } from '@modern-js/uni-builder';
2
+ import type { Bundler } from '../../types';
2
3
  import type { BuilderOptions } from '../shared';
3
- export declare const builderPluginAdapterCopy: (options: BuilderOptions<'shared'>) => RsbuildPlugin;
4
+ export declare const builderPluginAdapterCopy: <B extends Bundler>(options: BuilderOptions<B>) => RsbuildPlugin;
@@ -1,2 +1,3 @@
1
- import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
2
- export declare function createBuilderProviderConfig<B extends Bundler>(resolveConfig: AppNormalizedConfig<B>, appContext: IAppContext): Omit<AppNormalizedConfig<B>, 'plugins'>;
1
+ import type { AppNormalizedConfig, Bundler } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function createBuilderProviderConfig<B extends Bundler>(resolveConfig: AppNormalizedConfig<B>, appContext: AppToolsContext<B>): Omit<AppNormalizedConfig<B>, 'plugins'>;
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import type { Rspack, RspackChain } from '@rsbuild/core';
3
- import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
4
- export declare function createPublicPattern(appContext: IAppContext, config: AppNormalizedConfig, chain: RspackChain): {
3
+ import type { AppNormalizedConfig, Bundler } from '../../types';
4
+ import type { AppToolsContext } from '../../types/new';
5
+ export declare function createPublicPattern<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig, chain: RspackChain): {
5
6
  info: (file: {
6
7
  sourceFilename: string;
7
8
  }) => {
@@ -13,4 +14,4 @@ export declare function createPublicPattern(appContext: IAppContext, config: App
13
14
  noErrorOnMissing: boolean;
14
15
  transform: (content: Buffer, absoluteFrom: string) => string | Buffer;
15
16
  };
16
- export declare function createUploadPattern<B extends Bundler>(appContext: IAppContext, config: AppNormalizedConfig<B>): Rspack.CopyRspackPluginOptions['patterns']['0'];
17
+ export declare function createUploadPattern<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig<B>): Rspack.CopyRspackPluginOptions['patterns']['0'];
@@ -1,6 +1,6 @@
1
- import type { IAppContext } from '@modern-js/core';
2
1
  import type { AppNormalizedConfig, Bundler } from '../../types';
3
- export declare function getBuilderEnvironments<B extends Bundler>(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext, tempBuilderConfig: Omit<AppNormalizedConfig<B>, 'plugins'>): {
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function getBuilderEnvironments<B extends Bundler>(normalizedConfig: AppNormalizedConfig<B>, appContext: AppToolsContext<B>, tempBuilderConfig: Omit<AppNormalizedConfig<B>, 'plugins'>): {
4
4
  environments: {
5
5
  [name: string]: import("@rsbuild/core").EnvironmentConfig;
6
6
  };
@@ -1 +1 @@
1
- export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
1
+ export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern | typeof import("./builder-webpack/index.js").createWebpackBuilderForModern>;
@@ -1,5 +1,6 @@
1
- import type { AppNormalizedConfig, IAppContext } from '../../types';
2
- export declare function createCopyInfo(appContext: IAppContext, config: AppNormalizedConfig<'shared'>): {
1
+ import type { AppNormalizedConfig, Bundler } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
3
+ export declare function createCopyInfo<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig<B>): {
3
4
  configDir: string;
4
5
  uploadDir: string;
5
6
  publicDir: string;
@@ -1,5 +1,6 @@
1
- import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
1
+ import type { AppNormalizedConfig, Bundler } from '../../types';
2
+ import type { AppToolsContext } from '../../types/new';
2
3
  export type BuilderOptions<B extends Bundler> = {
3
4
  normalizedConfig: AppNormalizedConfig<B>;
4
- appContext: IAppContext;
5
+ appContext: AppToolsContext<B>;
5
6
  };
@@ -1,4 +1,4 @@
1
- import { type PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
3
  import type { BuildOptions } from '../utils/types';
4
- export declare const build: (api: PluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
4
+ export declare const build: (api: CLIPluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
- export declare const deploy: (api: PluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
3
+ export declare const deploy: (api: CLIPluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
@@ -1,8 +1,8 @@
1
- import { type PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import { type ApplyPlugins } from '@modern-js/server';
3
3
  import type { AppTools } from '../types';
4
4
  import type { DevOptions } from '../utils/types';
5
5
  export interface ExtraServerOptions {
6
6
  applyPlugins?: ApplyPlugins;
7
7
  }
8
- export declare const dev: (api: PluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
8
+ export declare const dev: (api: CLIPluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;