@modern-js/app-tools 2.34.1-alpha.1 → 2.35.1

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 (50) hide show
  1. package/dist/cjs/analyze/generateCode.js +3 -4
  2. package/dist/cjs/analyze/getFileSystemEntry.js +1 -2
  3. package/dist/cjs/analyze/getServerRoutes.js +4 -5
  4. package/dist/cjs/analyze/nestedRoutes.js +2 -2
  5. package/dist/cjs/analyze/templates.js +4 -4
  6. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -2
  7. package/dist/cjs/builder/index.js +1 -1
  8. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -20
  9. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -14
  10. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  11. package/dist/cjs/commands/build.js +2 -3
  12. package/dist/cjs/commands/inspect.js +1 -2
  13. package/dist/cjs/commands/serve.js +3 -3
  14. package/dist/cjs/index.js +127 -130
  15. package/dist/cjs/utils/config.js +1 -1
  16. package/dist/cjs/utils/printInstructions.js +1 -1
  17. package/dist/esm/analyze/generateCode.js +4 -4
  18. package/dist/esm/analyze/getFileSystemEntry.js +1 -2
  19. package/dist/esm/analyze/getServerRoutes.js +4 -5
  20. package/dist/esm/analyze/nestedRoutes.js +2 -2
  21. package/dist/esm/analyze/templates.js +4 -4
  22. package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -2
  23. package/dist/esm/builder/index.js +1 -1
  24. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +12 -43
  25. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +12 -14
  26. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  27. package/dist/esm/commands/build.js +3 -3
  28. package/dist/esm/commands/inspect.js +2 -2
  29. package/dist/esm/commands/serve.js +4 -4
  30. package/dist/esm/index.js +2 -3
  31. package/dist/esm/utils/config.js +2 -2
  32. package/dist/esm/utils/printInstructions.js +1 -1
  33. package/dist/esm-node/analyze/generateCode.js +3 -4
  34. package/dist/esm-node/analyze/getFileSystemEntry.js +1 -2
  35. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  36. package/dist/esm-node/analyze/nestedRoutes.js +2 -2
  37. package/dist/esm-node/analyze/templates.js +4 -4
  38. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -2
  39. package/dist/esm-node/builder/index.js +1 -1
  40. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +4 -19
  41. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -14
  42. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  43. package/dist/esm-node/commands/build.js +2 -3
  44. package/dist/esm-node/commands/inspect.js +1 -2
  45. package/dist/esm-node/commands/serve.js +4 -4
  46. package/dist/esm-node/index.js +127 -130
  47. package/dist/esm-node/utils/config.js +2 -2
  48. package/dist/esm-node/utils/printInstructions.js +1 -1
  49. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -0
  50. package/package.json +24 -25
@@ -16,35 +16,20 @@ export const builderPluginAdapterHtml = (options) => ({
16
16
  HtmlBundlerPlugin
17
17
  });
18
18
  await injectAssetPrefix({
19
- api,
20
19
  chain
21
20
  });
22
21
  }
23
22
  });
24
23
  }
25
24
  });
26
- async function injectAssetPrefix({ api, chain }) {
25
+ async function injectAssetPrefix({ chain }) {
27
26
  const entries = chain.entryPoints.entries() || {};
28
27
  const entryNames = Object.keys(entries);
29
28
  const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
30
29
  const code = `window.__assetPrefix__ = '${assetPrefix}';`;
31
- const isRspack = api.context.bundlerType === "rspack";
32
- if (isRspack) {
33
- const fileName = "rspack-asset-prefix";
34
- const { default: RspackVirtualModulePlugin } = await import("rspack-plugin-virtual-module");
35
- entryNames.forEach((entryName) => {
36
- entries[entryName].prepend(fileName);
37
- chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
38
- {
39
- [fileName]: code
40
- }
41
- ]);
42
- });
43
- } else {
44
- entryNames.forEach((entryName) => {
45
- entries[entryName].prepend(createVirtualModule(code));
46
- });
47
- }
30
+ entryNames.forEach((entryName) => {
31
+ entries[entryName].prepend(createVirtualModule(code));
32
+ });
48
33
  }
49
34
  function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
50
35
  const { normalizedConfig: modernConfig, appContext } = options;
@@ -20,7 +20,7 @@ export const builderPluginAdapterSSR = (options) => ({
20
20
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
21
21
  const builderConfig = api.getNormalizedConfig();
22
22
  const { normalizedConfig: normalizedConfig2 } = options;
23
- applyRouterPlugin(chain, options, HtmlBundlerPlugin);
23
+ applyRouterPlugin(chain, CHAIN_ID.PLUGIN.ROUTER_MANIFEST, options, HtmlBundlerPlugin);
24
24
  if (isSSR(normalizedConfig2)) {
25
25
  await applySSRLoaderEntry(chain, options, isServer);
26
26
  applySSRDataLoader(chain, options);
@@ -47,13 +47,12 @@ export const builderPluginAdapterSSR = (options) => ({
47
47
  }
48
48
  });
49
49
  const isStreamingSSR = (userConfig) => {
50
- var _server;
51
50
  const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
52
51
  const { server } = userConfig;
53
52
  if (isStreaming(server.ssr)) {
54
53
  return true;
55
54
  }
56
- if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
55
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
57
56
  for (const name of Object.keys(server.ssrByEntries)) {
58
57
  if (isStreaming(server.ssrByEntries[name])) {
59
58
  return true;
@@ -69,17 +68,17 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
69
68
  ]);
70
69
  }
71
70
  }
72
- function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
73
- var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
71
+ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
72
+ var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
74
73
  const { appContext, normalizedConfig } = options;
75
74
  const { entrypoints } = appContext;
76
75
  const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
77
- const routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
78
- const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
76
+ const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
77
+ const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
79
78
  const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
80
79
  if (existNestedRoutes || routerManifest || workerSSR) {
81
80
  var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
82
- chain.plugin("route-plugin").use(RouterPlugin, [
81
+ chain.plugin(pluginName).use(RouterPlugin, [
83
82
  {
84
83
  HtmlBundlerPlugin,
85
84
  enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
@@ -92,21 +91,21 @@ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
92
91
  }
93
92
  }
94
93
  function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
95
- var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
94
+ var _this;
96
95
  const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
97
96
  const entries = chain.entryPoints.entries();
98
- if (isProd && (((_outputConfig = outputConfig) === null || _outputConfig === void 0 ? void 0 : _outputConfig.ssg) === true || typeof ((_this = (_outputConfig1 = outputConfig) === null || _outputConfig1 === void 0 ? void 0 : _outputConfig1.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
97
+ if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_this = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
99
98
  return;
100
99
  }
101
100
  if (typeof entries === "undefined") {
102
101
  throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
103
102
  }
104
103
  const entryNames = Object.keys(entries);
105
- if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
104
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
106
105
  return;
107
106
  }
108
107
  const ssgEntries = [];
109
- if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
108
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
110
109
  const { ssg } = outputConfig;
111
110
  entryNames.forEach((name) => {
112
111
  if (ssg[name]) {
@@ -116,8 +115,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
116
115
  }
117
116
  const { ssr, ssrByEntries } = serverConfig || {};
118
117
  entryNames.forEach((name) => {
119
- var _ssrByEntries, _ssrByEntries1;
120
- if (!ssgEntries.includes(name) && (ssr && ((_ssrByEntries = ssrByEntries) === null || _ssrByEntries === void 0 ? void 0 : _ssrByEntries[name]) === false || !ssr && !((_ssrByEntries1 = ssrByEntries) === null || _ssrByEntries1 === void 0 ? void 0 : _ssrByEntries1[name]))) {
118
+ if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
121
119
  chain.entryPoints.delete(name);
122
120
  }
123
121
  });
@@ -119,10 +119,9 @@ export class RouterPlugin {
119
119
  let relatedAssets = {};
120
120
  if (entryChunkFiles.length > 1) {
121
121
  Object.keys(routeAssets).forEach((routeId) => {
122
- var _chunkNames;
123
122
  const segments = routeId.split("_");
124
123
  const chunkName = segments[0];
125
- if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
124
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
126
125
  relatedAssets[routeId] = routeAssets[routeId];
127
126
  }
128
127
  });
@@ -194,6 +193,7 @@ export class RouterPlugin {
194
193
  });
195
194
  }
196
195
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
196
+ _define_property(this, "name", "RouterPlugin");
197
197
  _define_property(this, "HtmlBundlerPlugin", void 0);
198
198
  _define_property(this, "enableInlineRouteManifests", void 0);
199
199
  _define_property(this, "staticJsDir", void 0);
@@ -3,8 +3,7 @@ import { logger } from "@modern-js/utils";
3
3
  import { generateRoutes } from "../utils/routes";
4
4
  import { buildServerConfig } from "../utils/config";
5
5
  export const build = async (api, options) => {
6
- var _options;
7
- if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
6
+ if (options === null || options === void 0 ? void 0 : options.analyze) {
8
7
  process.env.BUNDLE_ANALYZE = "true";
9
8
  }
10
9
  let resolvedConfig = api.useResolvedConfigContext();
@@ -40,7 +39,7 @@ export const build = async (api, options) => {
40
39
  distDirectory,
41
40
  configFile: serverConfigFile
42
41
  });
43
- logger.info("Create a production build...\n");
42
+ logger.info("Starting production build...");
44
43
  if (!appContext.builder) {
45
44
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
46
45
  }
@@ -1,6 +1,5 @@
1
1
  import { join } from "path";
2
2
  export const inspect = async (api, options) => {
3
- var _appContext;
4
3
  const appContext = api.useAppContext();
5
4
  if (!appContext.builder) {
6
5
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -8,7 +7,7 @@ export const inspect = async (api, options) => {
8
7
  return appContext.builder.inspectConfig({
9
8
  env: options.env,
10
9
  verbose: options.verbose,
11
- outputPath: join((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
10
+ outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
12
11
  writeToDisk: true
13
12
  });
14
13
  };
@@ -1,16 +1,16 @@
1
- import { logger, chalk, isApiOnly, getTargetDir } from "@modern-js/utils";
1
+ import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
2
2
  import server from "@modern-js/prod-server";
3
3
  import { printInstructions } from "../utils/printInstructions";
4
4
  import { injectDataLoaderPlugin } from "../utils/createServer";
5
5
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
6
6
  export const start = async (api) => {
7
- var _userConfig_source, _userConfig, _userConfig_output_distPath;
7
+ var _userConfig_source, _userConfig_output_distPath;
8
8
  const appContext = api.useAppContext();
9
9
  const userConfig = api.useResolvedConfigContext();
10
10
  const hookRunners = api.useHookRunners();
11
11
  const { appDirectory, port, serverConfigFile, metaName } = appContext;
12
- logger.log(chalk.cyan(`Starting the modern server...`));
13
- const apiOnly = await isApiOnly(appContext.appDirectory, (_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_source = _userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
12
+ logger.info(`Starting production server...`);
13
+ const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
14
14
  const serverInternalPlugins = await getServerInternalPlugins(api);
15
15
  const app = await server({
16
16
  pwd: appDirectory,
@@ -59,140 +59,137 @@ export const buildCommand = async (program, api) => {
59
59
  };
60
60
  export const appTools = (options = {
61
61
  bundler: "webpack"
62
- }) => {
63
- var _options, _options1;
64
- return {
65
- name: "@modern-js/app-tools",
66
- post: [
67
- "@modern-js/plugin-initialize",
68
- "@modern-js/plugin-analyze",
69
- "@modern-js/plugin-ssr",
70
- "@modern-js/plugin-document",
71
- "@modern-js/plugin-state",
72
- "@modern-js/plugin-router",
73
- "@modern-js/plugin-router-v5",
74
- "@modern-js/plugin-polyfill"
75
- ],
76
- registerHook: hooks,
77
- usePlugins: [
78
- initializePlugin({
79
- bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
80
- }),
81
- analyzePlugin({
82
- bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
83
- }),
84
- lintPlugin()
85
- ],
86
- setup: (api) => {
87
- const appContext = api.useAppContext();
88
- api.setAppContext({
89
- ...appContext,
90
- toolsType: "app-tools"
91
- });
92
- const nestedRoutes = {};
93
- const locale = getLocaleLanguage();
94
- i18n.changeLanguage({
95
- locale
96
- });
97
- return {
98
- async beforeConfig() {
99
- var _userConfig_output;
100
- const userConfig = api.useConfigContext();
101
- const appContext2 = api.useAppContext();
102
- if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
103
- api.setAppContext({
104
- ...appContext2,
105
- internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
106
- });
107
- }
108
- },
109
- async commands({ program }) {
110
- await devCommand(program, api);
111
- await buildCommand(program, api);
112
- program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
113
- const { start } = await import("./commands/serve");
114
- await start(api);
115
- });
116
- program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
117
- if (!options2.skipBuild) {
118
- const { build } = await import("./commands/build");
119
- await build(api);
120
- }
121
- const { deploy } = await import("./commands/deploy");
122
- await deploy(api, options2);
123
- process.exit(0);
62
+ }) => ({
63
+ name: "@modern-js/app-tools",
64
+ post: [
65
+ "@modern-js/plugin-initialize",
66
+ "@modern-js/plugin-analyze",
67
+ "@modern-js/plugin-ssr",
68
+ "@modern-js/plugin-document",
69
+ "@modern-js/plugin-state",
70
+ "@modern-js/plugin-router",
71
+ "@modern-js/plugin-router-v5",
72
+ "@modern-js/plugin-polyfill"
73
+ ],
74
+ registerHook: hooks,
75
+ usePlugins: [
76
+ initializePlugin({
77
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
78
+ }),
79
+ analyzePlugin({
80
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
81
+ }),
82
+ lintPlugin()
83
+ ],
84
+ setup: (api) => {
85
+ const appContext = api.useAppContext();
86
+ api.setAppContext({
87
+ ...appContext,
88
+ toolsType: "app-tools"
89
+ });
90
+ const nestedRoutes = {};
91
+ const locale = getLocaleLanguage();
92
+ i18n.changeLanguage({
93
+ locale
94
+ });
95
+ return {
96
+ async beforeConfig() {
97
+ var _userConfig_output;
98
+ const userConfig = api.useConfigContext();
99
+ const appContext2 = api.useAppContext();
100
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
101
+ api.setAppContext({
102
+ ...appContext2,
103
+ internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
124
104
  });
125
- program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--config-file <configFile>", i18n.t(localeKeys.command.shared.config)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
126
- const { MWANewAction } = await import("@modern-js/new-action");
127
- await MWANewAction({
128
- ...options2,
129
- locale: options2.lang || locale
130
- });
105
+ }
106
+ },
107
+ async commands({ program }) {
108
+ await devCommand(program, api);
109
+ await buildCommand(program, api);
110
+ program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
111
+ const { start } = await import("./commands/serve");
112
+ await start(api);
113
+ });
114
+ program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
115
+ if (!options2.skipBuild) {
116
+ const { build } = await import("./commands/build");
117
+ await build(api);
118
+ }
119
+ const { deploy } = await import("./commands/deploy");
120
+ await deploy(api, options2);
121
+ process.exit(0);
122
+ });
123
+ program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--config-file <configFile>", i18n.t(localeKeys.command.shared.config)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
124
+ const { MWANewAction } = await import("@modern-js/new-action");
125
+ await MWANewAction({
126
+ ...options2,
127
+ locale: options2.lang || locale
131
128
  });
132
- program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options2) => {
133
- const { inspect } = await import("./commands/inspect");
134
- inspect(api, options2);
129
+ });
130
+ program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options2) => {
131
+ const { inspect } = await import("./commands/inspect");
132
+ inspect(api, options2);
133
+ });
134
+ const { defineCommand } = await import("@modern-js/upgrade");
135
+ defineCommand(program.command("upgrade").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)));
136
+ },
137
+ async prepare() {
138
+ const command = getCommand();
139
+ if (command === "deploy") {
140
+ const isSkipBuild = [
141
+ "-s",
142
+ "--skip-build"
143
+ ].some((tag) => {
144
+ return getArgv().includes(tag);
135
145
  });
136
- const { defineCommand } = await import("@modern-js/upgrade");
137
- defineCommand(program.command("upgrade").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)));
138
- },
139
- async prepare() {
140
- const command = getCommand();
141
- if (command === "deploy") {
142
- const isSkipBuild = [
143
- "-s",
144
- "--skip-build"
145
- ].some((tag) => {
146
- return getArgv().includes(tag);
147
- });
148
- if (isSkipBuild) {
149
- return;
150
- }
146
+ if (isSkipBuild) {
147
+ return;
151
148
  }
152
- if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
153
- const resolvedConfig = api.useResolvedConfigContext();
154
- if (resolvedConfig.output.cleanDistPath) {
155
- const appContext2 = api.useAppContext();
156
- await emptyDir(appContext2.distDirectory);
157
- }
158
- }
159
- },
160
- async watchFiles() {
161
- const appContext2 = api.useAppContext();
162
- const config = api.useResolvedConfigContext();
163
- return await generateWatchFiles(appContext2, config.source.configDir);
164
- },
165
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
166
- async fileChange(e) {
167
- const { filename, eventType, isPrivate } = e;
168
- if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
169
- const { closeServer } = await import("./utils/createServer");
170
- await closeServer();
171
- await restart(api.useHookRunners(), filename);
149
+ }
150
+ if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
151
+ const resolvedConfig = api.useResolvedConfigContext();
152
+ if (resolvedConfig.output.cleanDistPath) {
153
+ const appContext2 = api.useAppContext();
154
+ await emptyDir(appContext2.distDirectory);
172
155
  }
173
- },
174
- async beforeRestart() {
175
- cleanRequireCache([
176
- require.resolve("./analyze")
177
- ]);
178
- },
179
- async modifyFileSystemRoutes({ entrypoint, routes }) {
180
- nestedRoutes[entrypoint.entryName] = routes;
181
- return {
182
- entrypoint,
183
- routes
184
- };
185
- },
186
- async beforeGenerateRoutes({ entrypoint, code }) {
187
- const { distDirectory } = api.useAppContext();
188
- await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
189
- return {
190
- entrypoint,
191
- code
192
- };
193
156
  }
194
- };
195
- }
196
- };
197
- };
157
+ },
158
+ async watchFiles() {
159
+ const appContext2 = api.useAppContext();
160
+ const config = api.useResolvedConfigContext();
161
+ return await generateWatchFiles(appContext2, config.source.configDir);
162
+ },
163
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
164
+ async fileChange(e) {
165
+ const { filename, eventType, isPrivate } = e;
166
+ if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
167
+ const { closeServer } = await import("./utils/createServer");
168
+ await closeServer();
169
+ await restart(api.useHookRunners(), filename);
170
+ }
171
+ },
172
+ async beforeRestart() {
173
+ cleanRequireCache([
174
+ require.resolve("./analyze")
175
+ ]);
176
+ },
177
+ async modifyFileSystemRoutes({ entrypoint, routes }) {
178
+ nestedRoutes[entrypoint.entryName] = routes;
179
+ return {
180
+ entrypoint,
181
+ routes
182
+ };
183
+ },
184
+ async beforeGenerateRoutes({ entrypoint, code }) {
185
+ const { distDirectory } = api.useAppContext();
186
+ await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
187
+ return {
188
+ entrypoint,
189
+ code
190
+ };
191
+ }
192
+ };
193
+ }
194
+ });
198
195
  export default appTools;
@@ -1,6 +1,6 @@
1
1
  import * as path from "path";
2
2
  import { bundle } from "@modern-js/node-bundle-require";
3
- import { CONFIG_FILE_EXTENSIONS, fs, getServerConfig, OUTPUT_CONFIG_FILE } from "@modern-js/utils";
3
+ import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
4
4
  export const defineServerConfig = (config) => config;
5
5
  export const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
6
6
  const configFilePath = await getServerConfig(appDirectory, configFile);
@@ -50,7 +50,7 @@ export const safeReplacer = () => {
50
50
  };
51
51
  export const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
52
52
  var _resolvedConfig_output_distPath;
53
- const outputPath = path.join(appDirectory, ((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE);
53
+ const outputPath = ensureAbsolutePath(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE));
54
54
  await fs.writeJSON(outputPath, resolvedConfig, {
55
55
  spaces: 2,
56
56
  replacer: safeReplacer()
@@ -4,5 +4,5 @@ export const printInstructions = async (hookRunners, appContext, config) => {
4
4
  const { instructions } = await hookRunners.beforePrintInstructions({
5
5
  instructions: message
6
6
  });
7
- logger.info(instructions);
7
+ logger.log(instructions);
8
8
  };
@@ -19,6 +19,7 @@ type Options = {
19
19
  nonce?: string;
20
20
  };
21
21
  export declare class RouterPlugin {
22
+ readonly name: string;
22
23
  private HtmlBundlerPlugin;
23
24
  private enableInlineRouteManifests;
24
25
  private staticJsDir;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.34.1-alpha.1",
18
+ "version": "2.35.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -71,26 +71,25 @@
71
71
  "@babel/types": "^7.22.15",
72
72
  "es-module-lexer": "^1.1.0",
73
73
  "esbuild": "0.17.19",
74
- "rspack-plugin-virtual-module": "0.1.7",
75
74
  "@swc/helpers": "0.5.1",
76
- "@modern-js/builder-webpack-provider": "2.34.0",
77
- "@modern-js/builder-plugin-node-polyfill": "2.34.0",
78
- "@modern-js/core": "2.34.0",
79
- "@modern-js/builder": "2.34.0",
80
- "@modern-js/builder-shared": "2.34.0",
81
- "@modern-js/new-action": "2.34.0",
82
- "@modern-js/node-bundle-require": "2.34.0",
83
- "@modern-js/plugin": "2.34.0",
84
- "@modern-js/plugin-data-loader": "2.34.0",
85
- "@modern-js/plugin-i18n": "2.34.0",
86
- "@modern-js/builder-plugin-esbuild": "2.34.0",
87
- "@modern-js/prod-server": "2.34.0",
88
- "@modern-js/plugin-lint": "2.34.0",
89
- "@modern-js/types": "2.34.0",
90
- "@modern-js/upgrade": "2.34.0",
91
- "@modern-js/server": "2.34.0",
92
- "@modern-js/server-core": "2.34.0",
93
- "@modern-js/utils": "2.34.0"
75
+ "@modern-js/builder": "2.35.1",
76
+ "@modern-js/builder-plugin-esbuild": "2.35.1",
77
+ "@modern-js/builder-plugin-node-polyfill": "2.35.1",
78
+ "@modern-js/builder-shared": "2.35.1",
79
+ "@modern-js/builder-webpack-provider": "2.35.1",
80
+ "@modern-js/core": "2.35.1",
81
+ "@modern-js/new-action": "2.35.1",
82
+ "@modern-js/node-bundle-require": "2.35.1",
83
+ "@modern-js/plugin": "2.35.1",
84
+ "@modern-js/plugin-data-loader": "2.35.1",
85
+ "@modern-js/plugin-i18n": "2.35.1",
86
+ "@modern-js/plugin-lint": "2.35.1",
87
+ "@modern-js/prod-server": "2.35.1",
88
+ "@modern-js/server": "2.35.1",
89
+ "@modern-js/types": "2.35.1",
90
+ "@modern-js/upgrade": "2.35.1",
91
+ "@modern-js/utils": "2.35.1",
92
+ "@modern-js/server-core": "2.35.1"
94
93
  },
95
94
  "devDependencies": {
96
95
  "@types/babel__traverse": "^7.14.2",
@@ -99,13 +98,13 @@
99
98
  "jest": "^29",
100
99
  "typescript": "^5",
101
100
  "webpack": "^5.88.1",
102
- "@modern-js/builder-plugin-swc": "2.34.0",
103
- "@scripts/build": "2.34.0",
104
- "@modern-js/builder-rspack-provider": "2.34.0",
105
- "@scripts/jest-config": "2.34.0"
101
+ "@modern-js/builder-plugin-swc": "2.35.1",
102
+ "@modern-js/builder-rspack-provider": "2.35.1",
103
+ "@scripts/build": "2.35.1",
104
+ "@scripts/jest-config": "2.35.1"
106
105
  },
107
106
  "peerDependencies": {
108
- "@modern-js/builder-rspack-provider": "^2.34.0"
107
+ "@modern-js/builder-rspack-provider": "^2.35.1"
109
108
  },
110
109
  "peerDependenciesMeta": {
111
110
  "@modern-js/builder-rspack-provider": {