@modern-js/app-tools 2.35.0 → 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 (54) hide show
  1. package/dist/cjs/analyze/constants.js +1 -0
  2. package/dist/cjs/analyze/generateCode.js +3 -4
  3. package/dist/cjs/analyze/getFileSystemEntry.js +1 -2
  4. package/dist/cjs/analyze/getServerRoutes.js +4 -5
  5. package/dist/cjs/analyze/nestedRoutes.js +11 -2
  6. package/dist/cjs/analyze/templates.js +4 -4
  7. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -2
  8. package/dist/cjs/builder/index.js +1 -1
  9. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -20
  10. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -14
  11. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  12. package/dist/cjs/commands/build.js +2 -3
  13. package/dist/cjs/commands/inspect.js +1 -2
  14. package/dist/cjs/commands/serve.js +3 -3
  15. package/dist/cjs/index.js +127 -130
  16. package/dist/cjs/utils/config.js +1 -1
  17. package/dist/cjs/utils/printInstructions.js +1 -1
  18. package/dist/esm/analyze/constants.js +1 -0
  19. package/dist/esm/analyze/generateCode.js +4 -4
  20. package/dist/esm/analyze/getFileSystemEntry.js +1 -2
  21. package/dist/esm/analyze/getServerRoutes.js +4 -5
  22. package/dist/esm/analyze/nestedRoutes.js +11 -2
  23. package/dist/esm/analyze/templates.js +4 -4
  24. package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -2
  25. package/dist/esm/builder/index.js +1 -1
  26. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +12 -43
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +12 -14
  28. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  29. package/dist/esm/commands/build.js +3 -3
  30. package/dist/esm/commands/inspect.js +2 -2
  31. package/dist/esm/commands/serve.js +4 -4
  32. package/dist/esm/index.js +2 -3
  33. package/dist/esm/utils/config.js +2 -2
  34. package/dist/esm/utils/printInstructions.js +1 -1
  35. package/dist/esm-node/analyze/constants.js +1 -0
  36. package/dist/esm-node/analyze/generateCode.js +3 -4
  37. package/dist/esm-node/analyze/getFileSystemEntry.js +1 -2
  38. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  39. package/dist/esm-node/analyze/nestedRoutes.js +11 -2
  40. package/dist/esm-node/analyze/templates.js +4 -4
  41. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -2
  42. package/dist/esm-node/builder/index.js +1 -1
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +4 -19
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -14
  45. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  46. package/dist/esm-node/commands/build.js +2 -3
  47. package/dist/esm-node/commands/inspect.js +1 -2
  48. package/dist/esm-node/commands/serve.js +4 -4
  49. package/dist/esm-node/index.js +127 -130
  50. package/dist/esm-node/utils/config.js +2 -2
  51. package/dist/esm-node/utils/printInstructions.js +1 -1
  52. package/dist/types/analyze/constants.d.ts +1 -0
  53. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -0
  54. package/package.json +24 -25
@@ -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
  };
@@ -28,6 +28,7 @@ export declare const NESTED_ROUTE: {
28
28
  PAGE_DATA_FILE: string;
29
29
  PAGE_CLIENT_LOADER: string;
30
30
  SPLATE_FILE: string;
31
+ SPLATE_CONFIG_FILE: string;
31
32
  SPLATE_LOADER_FILE: string;
32
33
  SPLATE_DATA_FILE: string;
33
34
  SPLATE_CLIENT_DATA: string;
@@ -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.35.0",
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": "2.35.0",
77
- "@modern-js/builder-plugin-esbuild": "2.35.0",
78
- "@modern-js/builder-plugin-node-polyfill": "2.35.0",
79
- "@modern-js/builder-shared": "2.35.0",
80
- "@modern-js/builder-webpack-provider": "2.35.0",
81
- "@modern-js/core": "2.35.0",
82
- "@modern-js/new-action": "2.35.0",
83
- "@modern-js/node-bundle-require": "2.35.0",
84
- "@modern-js/plugin": "2.35.0",
85
- "@modern-js/plugin-data-loader": "2.35.0",
86
- "@modern-js/plugin-i18n": "2.35.0",
87
- "@modern-js/plugin-lint": "2.35.0",
88
- "@modern-js/prod-server": "2.35.0",
89
- "@modern-js/server": "2.35.0",
90
- "@modern-js/types": "2.35.0",
91
- "@modern-js/upgrade": "2.35.0",
92
- "@modern-js/utils": "2.35.0",
93
- "@modern-js/server-core": "2.35.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.35.0",
103
- "@modern-js/builder-rspack-provider": "2.35.0",
104
- "@scripts/build": "2.35.0",
105
- "@scripts/jest-config": "2.35.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.35.0"
107
+ "@modern-js/builder-rspack-provider": "^2.35.1"
109
108
  },
110
109
  "peerDependenciesMeta": {
111
110
  "@modern-js/builder-rspack-provider": {