@modern-js/app-tools 3.0.4 → 3.1.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 (113) hide show
  1. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  2. package/dist/cjs/config/default.js +1 -1
  3. package/dist/cjs/index.js +14 -5
  4. package/dist/cjs/plugins/analyze/utils.js +6 -6
  5. package/dist/cjs/plugins/deploy/index.js +10 -5
  6. package/dist/cjs/plugins/deploy/platforms/gh-pages.js +1 -1
  7. package/dist/cjs/plugins/deploy/platforms/netlify.js +17 -33
  8. package/dist/cjs/plugins/deploy/platforms/node.js +17 -38
  9. package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
  10. package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
  11. package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
  12. package/dist/{esm/plugins/deploy/platforms → cjs/plugins/deploy/platforms/templates}/node-entry.mjs +5 -27
  13. package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
  14. package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
  15. package/dist/cjs/plugins/deploy/platforms/vercel.js +15 -32
  16. package/dist/cjs/plugins/deploy/types.js +18 -0
  17. package/dist/cjs/plugins/deploy/utils/generator.js +103 -0
  18. package/dist/cjs/plugins/deploy/{utils.js → utils/index.js} +28 -24
  19. package/dist/cjs/rsbuild.js +74 -0
  20. package/dist/cjs/utils/getConfigFile.js +1 -1
  21. package/dist/cjs/utils/register.js +1 -9
  22. package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
  23. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  24. package/dist/esm/commands/build.mjs +3 -3
  25. package/dist/esm/commands/dev.mjs +5 -5
  26. package/dist/esm/commands/serve.mjs +2 -2
  27. package/dist/esm/config/default.mjs +1 -1
  28. package/dist/esm/esm/register-esm.mjs +3 -3
  29. package/dist/esm/index.mjs +2 -1
  30. package/dist/esm/plugins/analyze/utils.mjs +2 -2
  31. package/dist/esm/plugins/deploy/index.mjs +9 -4
  32. package/dist/esm/plugins/deploy/platforms/gh-pages.mjs +1 -1
  33. package/dist/esm/plugins/deploy/platforms/netlify.mjs +25 -41
  34. package/dist/esm/plugins/deploy/platforms/node.mjs +22 -43
  35. package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
  36. package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
  37. package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
  38. package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
  39. package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
  40. package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
  41. package/dist/esm/plugins/deploy/platforms/vercel.mjs +28 -45
  42. package/dist/esm/plugins/deploy/types.mjs +0 -0
  43. package/dist/esm/plugins/deploy/utils/generator.mjs +47 -0
  44. package/dist/esm/plugins/deploy/utils/index.mjs +40 -0
  45. package/dist/esm/rsbuild.mjs +40 -0
  46. package/dist/esm/utils/getConfigFile.mjs +1 -1
  47. package/dist/esm/utils/loadPlugins.mjs +4 -4
  48. package/dist/esm/utils/register.mjs +6 -14
  49. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
  50. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  51. package/dist/esm-node/commands/build.mjs +3 -3
  52. package/dist/esm-node/commands/dev.mjs +5 -5
  53. package/dist/esm-node/commands/serve.mjs +2 -2
  54. package/dist/esm-node/config/default.mjs +1 -1
  55. package/dist/esm-node/esm/register-esm.mjs +3 -3
  56. package/dist/esm-node/index.mjs +2 -1
  57. package/dist/esm-node/plugins/analyze/utils.mjs +2 -2
  58. package/dist/esm-node/plugins/deploy/index.mjs +9 -4
  59. package/dist/esm-node/plugins/deploy/platforms/gh-pages.mjs +1 -1
  60. package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +25 -44
  61. package/dist/esm-node/plugins/deploy/platforms/node.mjs +22 -46
  62. package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
  63. package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
  64. package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
  65. package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
  66. package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
  67. package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
  68. package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +28 -48
  69. package/dist/esm-node/plugins/deploy/types.mjs +1 -0
  70. package/dist/esm-node/plugins/deploy/utils/generator.mjs +48 -0
  71. package/dist/esm-node/plugins/deploy/utils/index.mjs +44 -0
  72. package/dist/esm-node/rsbuild.mjs +41 -0
  73. package/dist/esm-node/utils/getConfigFile.mjs +1 -1
  74. package/dist/esm-node/utils/loadPlugins.mjs +4 -4
  75. package/dist/esm-node/utils/register.mjs +6 -14
  76. package/dist/types/index.d.ts +1 -0
  77. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  78. package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -1
  79. package/dist/types/plugins/deploy/platforms/templates/netlify-entry.d.mts +2 -0
  80. package/dist/types/plugins/deploy/platforms/templates/node-entry.d.mts +1 -0
  81. package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.cts +2 -0
  82. package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.mts +2 -0
  83. package/dist/types/plugins/deploy/types.d.ts +3 -0
  84. package/dist/types/plugins/deploy/utils/generator.d.ts +24 -0
  85. package/dist/types/plugins/deploy/utils/index.d.ts +16 -0
  86. package/dist/types/rsbuild.d.ts +12 -0
  87. package/dist/types/utils/getConfigFile.d.ts +1 -1
  88. package/package.json +16 -15
  89. package/rslib.config.mts +19 -0
  90. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -36
  91. package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +0 -89
  92. package/dist/cjs/plugins/deploy/platforms/node-entry.js +0 -75
  93. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -37
  94. package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +0 -89
  95. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +0 -2
  96. package/dist/esm/plugins/deploy/platforms/netlify-handler.mjs +0 -85
  97. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +0 -3
  98. package/dist/esm/plugins/deploy/platforms/vercel-handler.mjs +0 -85
  99. package/dist/esm/plugins/deploy/utils.mjs +0 -39
  100. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +0 -3
  101. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.mjs +0 -89
  102. package/dist/esm-node/plugins/deploy/platforms/node-entry.mjs +0 -72
  103. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +0 -4
  104. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.mjs +0 -89
  105. package/dist/esm-node/plugins/deploy/utils.mjs +0 -40
  106. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -2
  107. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
  108. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
  109. package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +0 -2
  110. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
  111. package/dist/types/plugins/deploy/utils.d.ts +0 -23
  112. /package/dist/types/plugins/deploy/platforms/{netlify-handler.d.cts → templates/netlify-entry.d.cts} +0 -0
  113. /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → templates/node-entry.d.cts} +0 -0
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1,48 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { ROUTE_SPEC_FILE, SERVER_DIR, getMeta } from "@modern-js/utils";
4
+ import { merge } from "@modern-js/utils/lodash";
5
+ import { normalizePath } from "./index.mjs";
6
+ const serverAppContextTemplate = (appContext)=>{
7
+ const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
8
+ return {
9
+ sharedDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, sharedDirectory))}")`,
10
+ apiDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, apiDirectory))}")`,
11
+ lambdaDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, lambdaDirectory))}")`,
12
+ metaName,
13
+ bffRuntimeFramework: bffRuntimeFramework || 'hono'
14
+ };
15
+ };
16
+ const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
17
+ const im = isESM ? `import * as plugin_${index}_ns from '${name}'` : `const plugin_${index}_ns = require('${name}')`;
18
+ return `${im};const plugin_${index} = plugin_${index}_ns.default || plugin_${index}_ns`;
19
+ }).join(';\n');
20
+ const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
21
+ const getServerConfigPath = (meta)=>`"${normalizePath(node_path.join(SERVER_DIR, `${meta}.server`))}"`;
22
+ const generateHandler = async ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate = serverAppContextTemplate, genPluginImports = genPluginImportsCode, isESM })=>{
23
+ const { serverPlugins, metaName } = appContext;
24
+ const plugins = serverPlugins.map((plugin)=>[
25
+ plugin.name,
26
+ plugin.options
27
+ ]);
28
+ const serverConfig = merge({
29
+ bff: {
30
+ prefix: config?.bff?.prefix
31
+ },
32
+ output: {
33
+ distPath: {
34
+ root: '.'
35
+ }
36
+ }
37
+ }, modifyServerConfig || {});
38
+ const meta = getMeta(metaName);
39
+ const pluginImportCode = genPluginImports(plugins || [], Boolean(isESM));
40
+ const dynamicProdOptions = {
41
+ config: serverConfig
42
+ };
43
+ const serverConfigPath = getServerConfigPath(meta);
44
+ const pluginsCode = getPluginsCode(plugins);
45
+ const serverAppContext = genAppContextTemplate(appContext);
46
+ return template.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
47
+ };
48
+ export { genPluginImportsCode, generateHandler, getPluginsCode, getServerConfigPath, serverAppContextTemplate };
@@ -0,0 +1,44 @@
1
+ import "node:module";
2
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
3
+ import { dirname as __rspack_dirname } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import path from "path";
6
+ import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
7
+ var utils_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
8
+ const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
9
+ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
10
+ const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
11
+ const { routes } = fs.readJSONSync(routeJSON);
12
+ let useSSR = false;
13
+ let useAPI = false;
14
+ routes.forEach((route)=>{
15
+ if (route.isSSR) useSSR = true;
16
+ if (route.isApi) useAPI = true;
17
+ });
18
+ const meta = getMeta(metaName);
19
+ const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
20
+ const isServerConfigExists = [
21
+ '.ts',
22
+ '.js'
23
+ ].some((ex)=>fs.existsSync(`${serverConfigPath}${ex}`));
24
+ return {
25
+ useSSR,
26
+ useAPI,
27
+ useWebServer: isServerConfigExists
28
+ };
29
+ };
30
+ const getTemplatePath = (file)=>path.join(utils_dirname, '../platforms/templates', file);
31
+ const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
32
+ const resolveESMDependency = async (entry)=>{
33
+ const conditions = new Set([
34
+ 'node',
35
+ 'import',
36
+ 'module',
37
+ 'default'
38
+ ]);
39
+ try {
40
+ const { moduleResolve } = await import("import-meta-resolve");
41
+ return normalizePath(moduleResolve(entry, pathToFileURL(`${utils_dirname}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:'));
42
+ } catch (err) {}
43
+ };
44
+ export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
@@ -0,0 +1,41 @@
1
+ import "node:module";
2
+ import { parseRspackConfig } from "@modern-js/builder";
3
+ import { createConfigOptions } from "@modern-js/plugin/cli";
4
+ import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./builder/shared/builderPlugins/index.mjs";
5
+ import { DEFAULT_CONFIG_FILE } from "./constants.mjs";
6
+ import { getConfigFile } from "./utils/getConfigFile.mjs";
7
+ const MODERN_META_NAME = 'modern-js';
8
+ async function resolveModernRsbuildConfig(options) {
9
+ const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
10
+ const configFile = options.configPath || getConfigFile(void 0, cwd);
11
+ if (!configFile) throw new Error(`Cannot find config file in ${cwd}. Please make sure you have a ${DEFAULT_CONFIG_FILE} file in your project.`);
12
+ const { config: modernConfig, getAppContext } = await createConfigOptions({
13
+ command: options.command,
14
+ cwd,
15
+ configFile,
16
+ metaName,
17
+ modifyModernConfig: options.modifyModernConfig
18
+ });
19
+ const nonStandardConfig = {
20
+ ...modernConfig,
21
+ plugins: modernConfig.builderPlugins
22
+ };
23
+ const appContext = getAppContext();
24
+ const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, {
25
+ cwd
26
+ });
27
+ const adapterParams = {
28
+ appContext,
29
+ normalizedConfig: modernConfig
30
+ };
31
+ rsbuildConfig.plugins = [
32
+ ...rsbuildPlugins,
33
+ ...rsbuildConfig.plugins || [],
34
+ builderPluginAdapterBasic(adapterParams),
35
+ builderPluginAdapterHooks(adapterParams)
36
+ ];
37
+ return {
38
+ rsbuildConfig
39
+ };
40
+ }
41
+ export { resolveModernRsbuildConfig };
@@ -2,5 +2,5 @@ import "node:module";
2
2
  import path from "path";
3
3
  import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
4
4
  import { DEFAULT_CONFIG_FILE } from "../constants.mjs";
5
- const getConfigFile = (configFile)=>findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
5
+ const getConfigFile = (configFile, cwd = process.cwd())=>findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(cwd, `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
6
6
  export { getConfigFile };
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
+ import { loadServerPlugins } from "@modern-js/prod-server";
2
3
  import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
3
- import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
4
4
  const debug = createDebugger('load-plugins');
5
5
  async function getServerPlugins(api, metaName = 'modern-js') {
6
6
  const hooks = api.getHooks();
@@ -13,9 +13,9 @@ async function getServerPlugins(api, metaName = 'modern-js') {
13
13
  });
14
14
  return filtedPlugins;
15
15
  }
16
- async function loadServerPlugins(api, appDirectory, metaName) {
16
+ async function loadPlugins_loadServerPlugins(api, appDirectory, metaName) {
17
17
  const plugins = await getServerPlugins(api, metaName);
18
- const instances = await (0, __rspack_external__modern_js_prod_server_057184e2.loadServerPlugins)(plugins, appDirectory);
18
+ const instances = await loadServerPlugins(plugins, appDirectory);
19
19
  return instances;
20
20
  }
21
21
  const resolveCliPlugin = async (p, appDirectory)=>{
@@ -43,4 +43,4 @@ const loadInternalPlugins = async (appDirectory, internalPlugins)=>{
43
43
  }));
44
44
  return loadedPlugins;
45
45
  };
46
- export { getServerPlugins, loadInternalPlugins, loadServerPlugins };
46
+ export { getServerPlugins, loadInternalPlugins, loadPlugins_loadServerPlugins as loadServerPlugins };
@@ -1,20 +1,12 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
- import { fs, getAliasConfig, loadFromProject, readTsConfigByFile, tryResolve } from "@modern-js/utils";
4
- import * as __rspack_external_node_path_c5b9b54f from "node:path";
5
- const checkDepExist = (dep, appDir)=>{
6
- try {
7
- tryResolve(dep, appDir, process.cwd());
8
- return true;
9
- } catch {
10
- return false;
11
- }
12
- };
3
+ import node_path from "node:path";
4
+ import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
13
5
  const setupTsRuntime = async (appDir, distDir, alias)=>{
14
6
  const TS_CONFIG_FILENAME = "tsconfig.json";
15
- const tsconfigPath = __rspack_external_node_path_c5b9b54f["default"].resolve(appDir, TS_CONFIG_FILENAME);
7
+ const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
16
8
  const isTsProject = await fs.pathExists(tsconfigPath);
17
- const hasTsNode = checkDepExist('ts-node', appDir);
9
+ const hasTsNode = isDepExists(appDir, 'ts-node');
18
10
  if (!isTsProject || !hasTsNode) return;
19
11
  const aliasConfig = getAliasConfig(alias, {
20
12
  appDirectory: appDir,
@@ -31,7 +23,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
31
23
  ]
32
24
  });
33
25
  } catch {}
34
- if ('string' == typeof tsPath && __rspack_external_node_path_c5b9b54f["default"].isAbsolute(tsPath)) tsPath = __rspack_external_node_path_c5b9b54f["default"].relative(absoluteBaseUrl, tsPath);
26
+ if ('string' == typeof tsPath && node_path.isAbsolute(tsPath)) tsPath = node_path.relative(absoluteBaseUrl, tsPath);
35
27
  if ('string' == typeof tsPath) tsPath = [
36
28
  tsPath
37
29
  ];
@@ -50,7 +42,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
50
42
  transpileOnly: true,
51
43
  ignore: [
52
44
  '(?:^|/)node_modules/',
53
- `(?:^|/)${__rspack_external_node_path_c5b9b54f["default"].relative(appDir, distDir)}/`
45
+ `(?:^|/)${node_path.relative(appDir, distDir)}/`
54
46
  ],
55
47
  ...tsNodeOptions
56
48
  });
@@ -7,6 +7,7 @@ export { dev } from './commands/dev';
7
7
  export { serve } from './commands/serve';
8
8
  export type { DevOptions } from './utils/types';
9
9
  export { generateWatchFiles } from './utils/generateWatchFiles';
10
+ export { resolveModernRsbuildConfig, type ResolveModernRsbuildConfigOptions, } from './rsbuild';
10
11
  export * from './types';
11
12
  export { initAppContext };
12
13
  export default appTools;
@@ -4,7 +4,7 @@ export declare const parseModule: ({ source, filename, }: {
4
4
  source: string;
5
5
  filename: string;
6
6
  }) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean]>;
7
- export declare const getServerCombinedModueFile: (internalDirectory: string, entryName: string) => string;
7
+ export declare const getServerCombinedModuleFile: (internalDirectory: string, entryName: string) => string;
8
8
  export declare const checkIsBuildCommands: () => boolean;
9
9
  export declare const checkIsServeCommand: () => boolean;
10
10
  export declare const isSubDirOrEqual: (parent: string, child: string) => boolean;
@@ -1,6 +1,13 @@
1
1
  import type { AppToolsNormalizedConfig } from '../../../types';
2
2
  import type { AppToolsContext } from '../../../types/plugin';
3
- export type CreatePreset = (appContext: AppToolsContext, config: AppToolsNormalizedConfig, needModernServer?: boolean) => DeployPreset;
3
+ import type { PluginAPI } from '../types';
4
+ interface CreatePresetParams {
5
+ appContext: AppToolsContext;
6
+ modernConfig: AppToolsNormalizedConfig;
7
+ api: PluginAPI;
8
+ needModernServer?: boolean;
9
+ }
10
+ export type CreatePreset = (params: CreatePresetParams) => DeployPreset;
4
11
  type DeployPreset = {
5
12
  prepare?: () => Promise<void>;
6
13
  writeOutput?: () => Promise<void>;
@@ -0,0 +1,2 @@
1
+ export default handler;
2
+ declare function handler(request: any, context: any): Promise<any>;
@@ -0,0 +1,2 @@
1
+ export = handler;
2
+ declare function handler(req: any, res: any): Promise<any>;
@@ -0,0 +1,2 @@
1
+ export default handler;
2
+ declare function handler(req: any, res: any): Promise<any>;
@@ -0,0 +1,3 @@
1
+ import type { AppTools, CliPlugin } from '../../types';
2
+ export type Setup = NonNullable<CliPlugin<AppTools>['setup']>;
3
+ export type PluginAPI = Parameters<Setup>[0];
@@ -0,0 +1,24 @@
1
+ import type { ProdServerOptions } from '@modern-js/prod-server';
2
+ import type { AppToolsNormalizedConfig } from '../../../types';
3
+ import type { AppToolsContext } from '../../../types/plugin';
4
+ export declare const serverAppContextTemplate: (appContext: AppToolsContext) => {
5
+ sharedDirectory: string;
6
+ apiDirectory: string;
7
+ lambdaDirectory: string;
8
+ metaName: string;
9
+ bffRuntimeFramework: string;
10
+ };
11
+ export type PluginItem = [string, Record<string, any> | undefined];
12
+ export declare const genPluginImportsCode: (plugins: PluginItem[], isESM?: boolean) => string;
13
+ export declare const getPluginsCode: (plugins: PluginItem[]) => string;
14
+ export declare const getServerConfigPath: (meta: string) => string;
15
+ export interface GenerateHandlerOptions {
16
+ template: string;
17
+ appContext: AppToolsContext;
18
+ config: AppToolsNormalizedConfig;
19
+ serverConfig?: Partial<ProdServerOptions>;
20
+ genAppContextTemplate?: typeof serverAppContextTemplate;
21
+ genPluginImports?: typeof genPluginImportsCode;
22
+ isESM?: boolean;
23
+ }
24
+ export declare const generateHandler: ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate, genPluginImports, isESM, }: GenerateHandlerOptions) => Promise<string>;
@@ -0,0 +1,16 @@
1
+ export type ServerAppContext = {
2
+ sharedDirectory: string;
3
+ apiDirectory: string;
4
+ lambdaDirectory: string;
5
+ metaName: string;
6
+ bffRuntimeFramework: string;
7
+ };
8
+ export declare const normalizePath: (filePath: string) => string;
9
+ export declare const getProjectUsage: (appDirectory: string, distDirectory: string, metaName: string) => {
10
+ useSSR: boolean;
11
+ useAPI: boolean;
12
+ useWebServer: boolean;
13
+ };
14
+ export declare const getTemplatePath: (file: string) => string;
15
+ export declare const readTemplate: (file: string) => Promise<string>;
16
+ export declare const resolveESMDependency: (entry: string) => Promise<string | undefined>;
@@ -0,0 +1,12 @@
1
+ import type { AppUserConfig } from './types';
2
+ type ResolveModernRsbuildConfigOptions = {
3
+ command: string;
4
+ configPath?: string;
5
+ cwd?: string;
6
+ metaName?: string;
7
+ modifyModernConfig?: (config: AppUserConfig) => AppUserConfig | Promise<AppUserConfig>;
8
+ };
9
+ export declare function resolveModernRsbuildConfig(options: ResolveModernRsbuildConfigOptions): Promise<{
10
+ rsbuildConfig: import("@modern-js/builder").RsbuildConfig;
11
+ }>;
12
+ export type { ResolveModernRsbuildConfigOptions };
@@ -1 +1 @@
1
- export declare const getConfigFile: (configFile?: string) => string | false;
1
+ export declare const getConfigFile: (configFile?: string, cwd?: string) => string | false;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.0.4",
18
+ "version": "3.1.0",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -80,29 +80,30 @@
80
80
  "modern-app": "./bin/modern.js"
81
81
  },
82
82
  "dependencies": {
83
- "@babel/parser": "^7.28.6",
84
- "@babel/traverse": "^7.28.6",
85
- "@babel/types": "^7.28.6",
83
+ "@babel/parser": "^7.29.0",
84
+ "@babel/traverse": "^7.29.0",
85
+ "@babel/types": "^7.29.0",
86
86
  "@rsbuild/core": "2.0.0-beta.4",
87
87
  "@swc/helpers": "^0.5.17",
88
88
  "es-module-lexer": "^1.7.0",
89
89
  "esbuild": "0.25.5",
90
90
  "esbuild-register": "^3.6.0",
91
- "flatted": "^3.3.3",
91
+ "import-meta-resolve": "^4.2.0",
92
+ "flatted": "^3.4.0",
92
93
  "mlly": "^1.8.0",
93
94
  "ndepe": "^0.1.13",
94
95
  "pkg-types": "^1.3.1",
95
96
  "std-env": "^3.10.0",
96
- "@modern-js/builder": "3.0.4",
97
- "@modern-js/i18n-utils": "3.0.4",
98
- "@modern-js/plugin-data-loader": "3.0.4",
99
- "@modern-js/plugin": "3.0.4",
100
- "@modern-js/server": "3.0.4",
101
- "@modern-js/server-core": "3.0.4",
102
- "@modern-js/prod-server": "3.0.4",
103
- "@modern-js/server-utils": "3.0.4",
104
- "@modern-js/types": "3.0.4",
105
- "@modern-js/utils": "3.0.4"
97
+ "@modern-js/builder": "3.1.0",
98
+ "@modern-js/i18n-utils": "3.1.0",
99
+ "@modern-js/plugin": "3.1.0",
100
+ "@modern-js/plugin-data-loader": "3.1.0",
101
+ "@modern-js/prod-server": "3.1.0",
102
+ "@modern-js/server": "3.1.0",
103
+ "@modern-js/server-utils": "3.1.0",
104
+ "@modern-js/server-core": "3.1.0",
105
+ "@modern-js/types": "3.1.0",
106
+ "@modern-js/utils": "3.1.0"
106
107
  },
107
108
  "devDependencies": {
108
109
  "@rslib/core": "0.19.6",
package/rslib.config.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import path from 'path';
1
2
  import { rslibConfig } from '@modern-js/rslib';
2
3
  import { defineConfig } from '@rslib/core';
3
4
 
@@ -6,6 +7,16 @@ export default defineConfig({
6
7
  lib: rslibConfig.lib?.map(libConfig => {
7
8
  return {
8
9
  ...libConfig,
10
+ source: {
11
+ ...libConfig.source,
12
+ entry: {
13
+ index: [
14
+ './src/**',
15
+ '!src/plugins/deploy/platforms/templates/*.mjs',
16
+ '!src/plugins/deploy/platforms/templates/*.cjs',
17
+ ],
18
+ },
19
+ },
9
20
  output: {
10
21
  ...libConfig.output,
11
22
  copy: [
@@ -13,6 +24,14 @@ export default defineConfig({
13
24
  from: './src/esm',
14
25
  to: './esm',
15
26
  },
27
+ {
28
+ from: 'plugins/deploy/platforms/templates/*.cjs',
29
+ context: path.join(__dirname, 'src'),
30
+ },
31
+ {
32
+ from: 'plugins/deploy/platforms/templates/*.mjs',
33
+ context: path.join(__dirname, 'src'),
34
+ },
16
35
  ],
17
36
  },
18
37
  };
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- default: ()=>external_netlify_handler_js_namespaceObject.handler
28
- });
29
- const external_netlify_handler_js_namespaceObject = require("./netlify-handler.js");
30
- exports["default"] = __webpack_exports__["default"];
31
- for(var __rspack_i in __webpack_exports__)if (-1 === [
32
- "default"
33
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
34
- Object.defineProperty(exports, '__esModule', {
35
- value: true
36
- });
@@ -1,89 +0,0 @@
1
- var __webpack_modules__ = {
2
- "@modern-js/prod-server/netlify" (module) {
3
- "use strict";
4
- module.exports = require("@modern-js/prod-server/netlify");
5
- },
6
- "node:fs/promises" (module) {
7
- "use strict";
8
- module.exports = require("node:fs/promises");
9
- },
10
- "node:path" (module) {
11
- "use strict";
12
- module.exports = require("node:path");
13
- },
14
- "./src/plugins/deploy/platforms/netlify-handler.cjs" (module, __unused_rspack_exports, __webpack_require__) {
15
- const fs = __webpack_require__("node:fs/promises");
16
- const path = __webpack_require__("node:path");
17
- const { createNetlifyFunction } = __webpack_require__("@modern-js/prod-server/netlify");
18
- p_genPluginImportsCode;
19
- if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
20
- let requestHandler = null;
21
- let handlerCreationPromise = null;
22
- async function loadRoutes(routeFilepath) {
23
- try {
24
- await fs.access(routeFilepath);
25
- const content = await fs.readFile(routeFilepath, 'utf-8');
26
- const routeSpec = JSON.parse(content);
27
- return routeSpec.routes || [];
28
- } catch (error) {
29
- console.warn('route.json not found or invalid, continuing with empty routes.');
30
- return [];
31
- }
32
- }
33
- async function initServer() {
34
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
35
- const routes = await loadRoutes(routeFilepath);
36
- const dynamicProdOptions = p_dynamicProdOptions;
37
- const prodServerOptions = {
38
- pwd: __dirname,
39
- routes,
40
- disableCustomHook: true,
41
- appContext: {
42
- sharedDirectory: p_sharedDirectory,
43
- apiDirectory: p_apiDirectory,
44
- lambdaDirectory: p_lambdaDirectory,
45
- bffRuntimeFramework: p_bffRuntimeFramework
46
- },
47
- plugins: p_plugins,
48
- serverConfigPath: p_serverDirectory,
49
- ...dynamicProdOptions
50
- };
51
- const requestHandler = await createNetlifyFunction(prodServerOptions);
52
- return requestHandler;
53
- }
54
- async function createHandler() {
55
- if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
56
- try {
57
- requestHandler = await initServer();
58
- } catch (error) {
59
- console.error('Error creating server:', error);
60
- process.exit(1);
61
- }
62
- })();
63
- await handlerCreationPromise;
64
- return requestHandler;
65
- }
66
- createHandler();
67
- module.exports = {
68
- handler: async (request, context)=>{
69
- if (!requestHandler) await createHandler();
70
- return requestHandler(request, context);
71
- }
72
- };
73
- }
74
- };
75
- var __webpack_module_cache__ = {};
76
- function __webpack_require__(moduleId) {
77
- var cachedModule = __webpack_module_cache__[moduleId];
78
- if (void 0 !== cachedModule) return cachedModule.exports;
79
- var module = __webpack_module_cache__[moduleId] = {
80
- exports: {}
81
- };
82
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
83
- return module.exports;
84
- }
85
- var __webpack_exports__ = __webpack_require__("./src/plugins/deploy/platforms/netlify-handler.cjs");
86
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
87
- Object.defineProperty(exports, '__esModule', {
88
- value: true
89
- });
@@ -1,75 +0,0 @@
1
- var __webpack_modules__ = {
2
- "@modern-js/prod-server" (module) {
3
- "use strict";
4
- module.exports = require("@modern-js/prod-server");
5
- },
6
- "node:fs/promises" (module) {
7
- "use strict";
8
- module.exports = require("node:fs/promises");
9
- },
10
- "node:path" (module) {
11
- "use strict";
12
- module.exports = require("node:path");
13
- }
14
- };
15
- var __webpack_module_cache__ = {};
16
- function __webpack_require__(moduleId) {
17
- var cachedModule = __webpack_module_cache__[moduleId];
18
- if (void 0 !== cachedModule) return cachedModule.exports;
19
- var module = __webpack_module_cache__[moduleId] = {
20
- exports: {}
21
- };
22
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
23
- return module.exports;
24
- }
25
- var __webpack_exports__ = {};
26
- (()=>{
27
- const fs = __webpack_require__("node:fs/promises");
28
- const path = __webpack_require__("node:path");
29
- const { createProdServer } = __webpack_require__("@modern-js/prod-server");
30
- p_genPluginImportsCode;
31
- if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
32
- async function loadRoutes(routeFilepath) {
33
- try {
34
- await fs.access(routeFilepath);
35
- const content = await fs.readFile(routeFilepath, 'utf-8');
36
- const routeSpec = JSON.parse(content);
37
- return routeSpec.routes || [];
38
- } catch (error) {
39
- console.warn('route.json not found or invalid, continuing with empty routes.');
40
- return [];
41
- }
42
- }
43
- async function main() {
44
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
45
- const routes = await loadRoutes(routeFilepath);
46
- const dynamicProdOptions = p_dynamicProdOptions;
47
- const prodServerOptions = {
48
- pwd: __dirname,
49
- routes,
50
- disableCustomHook: true,
51
- appContext: {
52
- sharedDirectory: p_sharedDirectory,
53
- apiDirectory: p_apiDirectory,
54
- lambdaDirectory: p_lambdaDirectory,
55
- bffRuntimeFramework: p_bffRuntimeFramework
56
- },
57
- plugins: p_plugins,
58
- serverConfigPath: p_serverDirectory,
59
- ...dynamicProdOptions
60
- };
61
- const app = await createProdServer(prodServerOptions);
62
- const port = process.env.PORT || 8080;
63
- app.listen({
64
- host: '::',
65
- port
66
- }, ()=>{
67
- console.log(`\x1b[32mServer is listening on http://[::]:${port}`, '\x1b[0m');
68
- });
69
- }
70
- main();
71
- })();
72
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
73
- Object.defineProperty(exports, '__esModule', {
74
- value: true
75
- });