@modern-js/app-tools 3.1.0 → 3.1.2

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 (57) hide show
  1. package/dist/cjs/commands/build.js +3 -9
  2. package/dist/cjs/commands/dev.js +4 -9
  3. package/dist/cjs/esm/register-esm.js +16 -12
  4. package/dist/cjs/esm/register-esm.mjs +11 -10
  5. package/dist/cjs/esm/ts-paths-loader.js +95 -0
  6. package/dist/cjs/esm/ts-paths-loader.mjs +57 -0
  7. package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +1 -1
  8. package/dist/cjs/plugins/deploy/utils/generator.js +4 -3
  9. package/dist/cjs/utils/register.js +48 -17
  10. package/dist/esm/builder/generator/createCopyPattern.mjs +1 -1
  11. package/dist/esm/builder/index.mjs +3 -3
  12. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  13. package/dist/esm/builder/shared/loaders/serverModuleLoader.mjs +1 -1
  14. package/dist/esm/commands/build.mjs +3 -9
  15. package/dist/esm/commands/dev.mjs +4 -9
  16. package/dist/esm/esm/register-esm.mjs +12 -11
  17. package/dist/esm/esm/ts-paths-loader.mjs +58 -0
  18. package/dist/esm/index.mjs +7 -6
  19. package/dist/esm/plugins/analyze/getHtmlTemplate.mjs +2 -2
  20. package/dist/esm/plugins/analyze/index.mjs +5 -5
  21. package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +2 -2
  22. package/dist/esm/plugins/deploy/index.mjs +1 -1
  23. package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +1 -1
  24. package/dist/esm/plugins/deploy/utils/generator.mjs +4 -3
  25. package/dist/esm/plugins/initialize/index.mjs +1 -1
  26. package/dist/esm/plugins/serverBuild.mjs +1 -1
  27. package/dist/esm/plugins/serverRuntime.mjs +1 -1
  28. package/dist/esm/utils/config.mjs +2 -2
  29. package/dist/esm/utils/register.mjs +45 -17
  30. package/dist/esm-node/builder/generator/createCopyPattern.mjs +1 -1
  31. package/dist/esm-node/builder/index.mjs +3 -3
  32. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
  33. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  34. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.mjs +1 -1
  35. package/dist/esm-node/commands/build.mjs +3 -9
  36. package/dist/esm-node/commands/dev.mjs +4 -9
  37. package/dist/esm-node/esm/register-esm.mjs +12 -11
  38. package/dist/esm-node/esm/ts-paths-loader.mjs +59 -0
  39. package/dist/esm-node/index.mjs +7 -6
  40. package/dist/esm-node/plugins/analyze/getHtmlTemplate.mjs +2 -2
  41. package/dist/esm-node/plugins/analyze/index.mjs +4 -4
  42. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +2 -2
  43. package/dist/esm-node/plugins/deploy/index.mjs +1 -1
  44. package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +1 -1
  45. package/dist/esm-node/plugins/deploy/utils/generator.mjs +4 -3
  46. package/dist/esm-node/plugins/deploy/utils/index.mjs +2 -2
  47. package/dist/esm-node/plugins/initialize/index.mjs +1 -1
  48. package/dist/esm-node/plugins/serverBuild.mjs +1 -1
  49. package/dist/esm-node/plugins/serverRuntime.mjs +1 -1
  50. package/dist/esm-node/utils/config.mjs +2 -2
  51. package/dist/esm-node/utils/register.mjs +45 -17
  52. package/dist/types/esm/register-esm.d.mts +5 -0
  53. package/dist/types/esm/ts-paths-loader.d.mts +6 -0
  54. package/dist/types/plugins/deploy/platforms/templates/netlify-entry.d.cts +2 -1
  55. package/dist/types/utils/register.d.ts +8 -1
  56. package/package.json +15 -15
  57. package/{rstest.config.ts → rstest.config.mts} +0 -4
@@ -1,5 +1,4 @@
1
1
  import { isPromise } from "node:util/types";
2
- import { extname, resolve } from "path";
3
2
  import { createDebugger, fs, getArgv, getMeta, isApiOnly, isDevCommand, minimist } from "@modern-js/utils";
4
3
  import { createBuilderGenerator } from "../../builder/index.mjs";
5
4
  import { initialNormalizedConfig } from "../../config/index.mjs";
@@ -8,6 +7,7 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries.mjs";
8
7
  import { printInstructions } from "../../utils/printInstructions.mjs";
9
8
  import { generateRoutes } from "../../utils/routes.mjs";
10
9
  import { checkIsBuildCommands, checkIsServeCommand } from "./utils.mjs";
10
+ import * as __rspack_external_path from "path";
11
11
  const debug = createDebugger('plugin-analyze');
12
12
  const analyze = ()=>({
13
13
  name: '@modern-js/plugin-analyze',
@@ -74,7 +74,7 @@ const analyze = ()=>({
74
74
  };
75
75
  api.updateAppContext(appContext);
76
76
  nestedRouteEntries = entrypoints.map((point)=>point.nestedRoutesEntry).filter(Boolean);
77
- pagesDir = entrypoints.map((point)=>point.entry).filter((entry)=>entry && !extname(entry)).concat(nestedRouteEntries);
77
+ pagesDir = entrypoints.map((point)=>point.entry).filter((entry)=>entry && !__rspack_external_path.extname(entry)).concat(nestedRouteEntries);
78
78
  const meta = getMeta(api.getAppContext().metaName);
79
79
  const possibleNames = [
80
80
  `${meta}.routes.ts`,
@@ -88,7 +88,7 @@ const analyze = ()=>({
88
88
  const { absoluteEntryDir } = entrypoint;
89
89
  if (!absoluteEntryDir) return;
90
90
  for (const filename of possibleNames){
91
- const filePath = resolve(absoluteEntryDir, filename);
91
+ const filePath = __rspack_external_path.resolve(absoluteEntryDir, filename);
92
92
  if (await fs.pathExists(filePath)) {
93
93
  const stats = await fs.stat(filePath);
94
94
  if (stats.isFile()) routesConfigFiles.push(filePath);
@@ -174,7 +174,7 @@ const analyze = ()=>({
174
174
  const getFlattenedPlugins = async (pluginOptions)=>{
175
175
  let plugins = pluginOptions;
176
176
  do plugins = (await Promise.all(plugins)).flat(1 / 0);
177
- while (plugins.some((v)=>isPromise(v)));
177
+ while (plugins.some((v)=>isPromise(v)))
178
178
  return plugins;
179
179
  };
180
180
  if (resolvedConfig.builderPlugins) {
@@ -200,4 +200,4 @@ const analyze = ()=>({
200
200
  });
201
201
  }
202
202
  });
203
- export { analyze as default };
203
+ export default analyze;
@@ -1,8 +1,8 @@
1
1
  import fs from "fs";
2
2
  import { parse } from "@babel/parser";
3
3
  import traverse from "@babel/traverse";
4
- import { isArrowFunctionExpression, isFunctionDeclaration, isFunctionExpression } from "@babel/types";
5
- const isFunction = (node)=>isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunctionExpression(node);
4
+ import * as __rspack_external__babel_types_69e65b52 from "@babel/types";
5
+ const isFunction = (node)=>__rspack_external__babel_types_69e65b52.isFunctionDeclaration(node) || __rspack_external__babel_types_69e65b52.isFunctionExpression(node) || __rspack_external__babel_types_69e65b52.isArrowFunctionExpression(node);
6
6
  const isDefaultExportFunction = (file)=>{
7
7
  if (!file || !fs.existsSync(file)) return false;
8
8
  const ast = parse(fs.readFileSync(file, 'utf8'), {
@@ -40,4 +40,4 @@ const deploy = ()=>({
40
40
  });
41
41
  }
42
42
  });
43
- export { deploy as default };
43
+ export default deploy;
@@ -54,4 +54,4 @@ const handler = async (request, context)=>{
54
54
  if (!requestHandler) await createHandler();
55
55
  return requestHandler(request, context);
56
56
  };
57
- exports.handler = handler;
57
+ module.exports.default = handler;
@@ -4,10 +4,11 @@ import { merge } from "@modern-js/utils/lodash";
4
4
  import { normalizePath } from "./index.mjs";
5
5
  const serverAppContextTemplate = (appContext)=>{
6
6
  const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
7
+ const getRelativePathTemplate = (targetDirectory)=>`path.join(__dirname, ${JSON.stringify(normalizePath(node_path.relative(appDirectory, targetDirectory)))})`;
7
8
  return {
8
- sharedDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, sharedDirectory))}")`,
9
- apiDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, apiDirectory))}")`,
10
- lambdaDirectory: `path.join(__dirname, "${normalizePath(node_path.relative(appDirectory, lambdaDirectory))}")`,
9
+ sharedDirectory: getRelativePathTemplate(sharedDirectory),
10
+ apiDirectory: getRelativePathTemplate(apiDirectory),
11
+ lambdaDirectory: getRelativePathTemplate(lambdaDirectory),
11
12
  metaName,
12
13
  bffRuntimeFramework: bffRuntimeFramework || 'hono'
13
14
  };
@@ -56,4 +56,4 @@ async function getServerPort(config) {
56
56
  if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
57
57
  return prodPort;
58
58
  }
59
- export { initialize as default };
59
+ export default initialize;
@@ -43,4 +43,4 @@ const serverBuild = ()=>({
43
43
  });
44
44
  }
45
45
  });
46
- export { serverBuild as default };
46
+ export default serverBuild;
@@ -12,4 +12,4 @@ const serverRuntime = ()=>({
12
12
  }));
13
13
  }
14
14
  });
15
- export { serverRuntime as default };
15
+ export default serverRuntime;
@@ -1,8 +1,8 @@
1
- import { join } from "path";
2
1
  import { OUTPUT_CONFIG_FILE, ensureAbsolutePath, fs } from "@modern-js/utils";
3
2
  import { stringify } from "flatted";
3
+ import * as __rspack_external_path from "path";
4
4
  const emitResolvedConfig = async (appDirectory, resolvedConfig)=>{
5
- const outputPath = ensureAbsolutePath(appDirectory, join(resolvedConfig.output.distPath?.root || './dist', OUTPUT_CONFIG_FILE));
5
+ const outputPath = ensureAbsolutePath(appDirectory, __rspack_external_path.join(resolvedConfig.output.distPath?.root || './dist', OUTPUT_CONFIG_FILE));
6
6
  const output = stringify(resolvedConfig);
7
7
  await fs.writeFile(outputPath, output, {
8
8
  encoding: 'utf-8'
@@ -1,11 +1,21 @@
1
1
  import node_path from "node:path";
2
2
  import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
3
- const setupTsRuntime = async (appDir, distDir, alias)=>{
3
+ const resolveTsRuntimeRegisterMode = (hasTsNode)=>{
4
+ const hasNativeTypeScriptSupport = process.features?.typescript;
5
+ const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
6
+ const supportsNativeTypeScript = void 0 === hasNativeTypeScriptSupport ? nodeMajorVersion >= 22 : false !== hasNativeTypeScriptSupport;
7
+ if (supportsNativeTypeScript) return 'node-loader';
8
+ if (hasTsNode) return 'ts-node';
9
+ return 'unsupported';
10
+ };
11
+ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
4
12
  const TS_CONFIG_FILENAME = "tsconfig.json";
5
13
  const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
6
14
  const isTsProject = await fs.pathExists(tsconfigPath);
7
15
  const hasTsNode = isDepExists(appDir, 'ts-node');
8
- if (!isTsProject || !hasTsNode) return;
16
+ if (!isTsProject) return;
17
+ const preferredRegisterMode = resolveTsRuntimeRegisterMode(hasTsNode);
18
+ const registerMode = options.preferTsNodeForServerRuntime && hasTsNode ? 'ts-node' : preferredRegisterMode;
9
19
  const aliasConfig = getAliasConfig(alias, {
10
20
  appDirectory: appDir,
11
21
  tsconfigPath
@@ -30,24 +40,42 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
30
40
  [`${key}`]: tsPath
31
41
  };
32
42
  }, {});
33
- const tsConfig = readTsConfigByFile(tsconfigPath);
34
- const tsNode = await loadFromProject('ts-node', appDir);
35
- const tsNodeOptions = tsConfig['ts-node'];
36
- tsNode.register({
37
- project: tsconfigPath,
38
- scope: true,
39
- files: true,
40
- transpileOnly: true,
41
- ignore: [
42
- '(?:^|/)node_modules/',
43
- `(?:^|/)${node_path.relative(appDir, distDir)}/`
44
- ],
45
- ...tsNodeOptions
46
- });
43
+ if ('unsupported' === registerMode) return;
44
+ if ('ts-node' === registerMode) {
45
+ if ('module' === options.moduleType) {
46
+ const { registerModuleHooks } = await import("../esm/register-esm.mjs");
47
+ await registerModuleHooks({
48
+ appDir,
49
+ distDir,
50
+ alias: alias || {}
51
+ });
52
+ }
53
+ const tsConfig = readTsConfigByFile(tsconfigPath);
54
+ const tsNode = await loadFromProject('ts-node', appDir);
55
+ const tsNodeOptions = tsConfig['ts-node'];
56
+ tsNode.register({
57
+ project: tsconfigPath,
58
+ scope: true,
59
+ files: true,
60
+ transpileOnly: true,
61
+ ignore: [
62
+ '(?:^|/)node_modules/',
63
+ `(?:^|/)${node_path.relative(appDir, distDir)}/`
64
+ ],
65
+ ...tsNodeOptions
66
+ });
67
+ } else if ('node-loader' === registerMode) {
68
+ const { registerPathsLoader } = await import("../esm/register-esm.mjs");
69
+ await registerPathsLoader({
70
+ appDir,
71
+ baseUrl: absoluteBaseUrl || './',
72
+ paths: tsPaths
73
+ });
74
+ }
47
75
  const { register } = await import("@modern-js/utils/tsconfig-paths");
48
76
  register({
49
77
  baseUrl: absoluteBaseUrl || './',
50
78
  paths: tsPaths
51
79
  });
52
80
  };
53
- export { setupTsRuntime };
81
+ export { resolveTsRuntimeRegisterMode, setupTsRuntime };
@@ -8,7 +8,7 @@ const info = (file)=>({
8
8
  function createPublicPattern(appContext, config, chain) {
9
9
  const { publicDir } = createCopyInfo(appContext, config);
10
10
  return {
11
- info,
11
+ info: info,
12
12
  from: '**/*',
13
13
  to: 'public',
14
14
  context: publicDir,
@@ -1,8 +1,8 @@
1
1
  import "node:module";
2
- import { parseRspackConfig } from "@modern-js/builder";
3
- import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./shared/builderPlugins/index.mjs";
4
2
  async function createBuilderGenerator() {
5
3
  const { createRspackBuilderForModern } = await import("./builder-rspack/index.mjs");
6
4
  return createRspackBuilderForModern;
7
5
  }
8
- export { builderPluginAdapterBasic, builderPluginAdapterHooks, createBuilderGenerator, parseRspackConfig };
6
+ export { parseRspackConfig } from "@modern-js/builder";
7
+ export { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./shared/builderPlugins/index.mjs";
8
+ export { createBuilderGenerator };
@@ -1,8 +1,8 @@
1
1
  import "node:module";
2
- import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
3
- import { dirname as __rspack_dirname } from "node:path";
4
2
  import node_path from "node:path";
5
3
  import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/builder";
4
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
5
+ import { dirname as __rspack_dirname } from "node:path";
6
6
  var adapterBasic_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
7
7
  const builderPluginAdapterBasic = (options)=>({
8
8
  name: 'builder-plugin-adapter-modern-basic',
@@ -1,11 +1,11 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
- import { resolve, sep } from "path";
4
3
  import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
5
4
  import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
6
5
  import { mergeRsbuildConfig } from "@rsbuild/core";
7
6
  import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
8
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
8
+ import * as __rspack_external_path from "path";
9
9
  const builderPluginAdapterSSR = (options)=>({
10
10
  name: 'builder-plugin-adapter-modern-ssr',
11
11
  setup (api) {
@@ -112,7 +112,7 @@ function applySSRDataLoader(chain, options) {
112
112
  const { normalizedConfig, appContext } = options;
113
113
  const { appDirectory } = appContext;
114
114
  const { entriesDir = './src' } = normalizedConfig.source;
115
- const absolutePath = resolve(appDirectory, entriesDir).split(sep).join('(\\\\|/)');
115
+ const absolutePath = __rspack_external_path.resolve(appDirectory, entriesDir).split(__rspack_external_path.sep).join('(\\\\|/)');
116
116
  const reg = new RegExp(`${absolutePath}.*\\.(loader|data|data.client)\\.[t|j]sx?$`);
117
117
  chain.module.rule('ssr-data-loader').test(reg).use('data-loader').loader(require.resolve('@modern-js/plugin-data-loader/loader')).end();
118
118
  }
@@ -3,4 +3,4 @@ function loader() {
3
3
  return "module.exports = {}";
4
4
  }
5
5
  const serverModuleLoader = loader;
6
- export { serverModuleLoader as default };
6
+ export default serverModuleLoader;
@@ -33,15 +33,9 @@ const build = async (api, options)=>{
33
33
  const hooks = api.getHooks();
34
34
  const combinedAlias = [].concat(resolvedConfig?.resolve?.alias ?? []).concat(resolvedConfig?.source?.alias ?? []);
35
35
  await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
36
- if (appContext.moduleType && 'module' === appContext.moduleType) {
37
- const { registerModuleHooks } = await import("../esm/register-esm.mjs");
38
- await registerModuleHooks({
39
- appDir: appContext.appDirectory,
40
- distDir: appContext.distDirectory,
41
- alias: {}
42
- });
43
- }
44
- await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias);
36
+ await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias, {
37
+ moduleType: appContext.moduleType
38
+ });
45
39
  const { apiOnly } = appContext;
46
40
  if (apiOnly) {
47
41
  await hooks.onBeforeBuild.call({
@@ -14,15 +14,10 @@ const dev = async (api, options, devServerOptions)=>{
14
14
  const appContext = api.getAppContext();
15
15
  const hooks = api.getHooks();
16
16
  const combinedAlias = [].concat(normalizedConfig?.resolve?.alias ?? []).concat(normalizedConfig?.source?.alias ?? []);
17
- if (appContext.moduleType && 'module' === appContext.moduleType) {
18
- const { registerModuleHooks } = await import("../esm/register-esm.mjs");
19
- await registerModuleHooks({
20
- appDir: appContext.appDirectory,
21
- distDir: appContext.distDirectory,
22
- alias: {}
23
- });
24
- }
25
- await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias);
17
+ await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias, {
18
+ moduleType: appContext.moduleType,
19
+ preferTsNodeForServerRuntime: true
20
+ });
26
21
  const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
27
22
  const meta = getMeta(metaName);
28
23
  const serverConfigPath = node_path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
@@ -1,20 +1,11 @@
1
1
  import "node:module";
2
2
  import node_path from "node:path";
3
3
  import { fs } from "@modern-js/utils";
4
- const checkDepExist = async (dep)=>{
5
- try {
6
- await import(dep);
7
- return true;
8
- } catch {
9
- return false;
10
- }
11
- };
12
4
  const registerModuleHooks = async ({ appDir, distDir, alias })=>{
13
5
  const TS_CONFIG_FILENAME = "tsconfig.json";
14
6
  const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
15
7
  const hasTsconfig = await fs.pathExists(tsconfigPath);
16
- const hasTsNode = await checkDepExist('ts-node');
17
- if (!hasTsconfig || !hasTsNode) return;
8
+ if (!hasTsconfig) return;
18
9
  const { register } = await import("node:module");
19
10
  process.env.TS_NODE_TRANSPILE_ONLY = true;
20
11
  process.env.TS_NODE_PROJECT = tsconfigPath;
@@ -30,4 +21,14 @@ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
30
21
  }
31
22
  });
32
23
  };
33
- export { registerModuleHooks };
24
+ const registerPathsLoader = async ({ appDir, baseUrl, paths })=>{
25
+ const { register } = await import("node:module");
26
+ register('./ts-paths-loader.mjs', import.meta.url, {
27
+ data: {
28
+ appDir,
29
+ baseUrl,
30
+ paths
31
+ }
32
+ });
33
+ };
34
+ export { registerModuleHooks, registerPathsLoader };
@@ -0,0 +1,59 @@
1
+ import "node:module";
2
+ import node_fs from "node:fs";
3
+ import node_path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "url";
5
+ import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
6
+ let matchPath;
7
+ let appDir;
8
+ const resolvePathWithExtensions = (matchedPath)=>{
9
+ if (node_path.extname(matchedPath)) return matchedPath;
10
+ const fileCandidates = [
11
+ matchedPath,
12
+ `${matchedPath}.ts`,
13
+ `${matchedPath}.tsx`,
14
+ `${matchedPath}.mts`,
15
+ `${matchedPath}.cts`,
16
+ `${matchedPath}.js`,
17
+ `${matchedPath}.mjs`,
18
+ `${matchedPath}.cjs`
19
+ ];
20
+ for (const candidate of fileCandidates)if (node_fs.existsSync(candidate) && node_fs.statSync(candidate).isFile()) return candidate;
21
+ const indexCandidates = [
22
+ node_path.join(matchedPath, 'index.ts'),
23
+ node_path.join(matchedPath, 'index.tsx'),
24
+ node_path.join(matchedPath, 'index.mts'),
25
+ node_path.join(matchedPath, 'index.cts'),
26
+ node_path.join(matchedPath, 'index.js'),
27
+ node_path.join(matchedPath, 'index.mjs'),
28
+ node_path.join(matchedPath, 'index.cjs')
29
+ ];
30
+ for (const candidate of indexCandidates)if (node_fs.existsSync(candidate) && node_fs.statSync(candidate).isFile()) return candidate;
31
+ return matchedPath;
32
+ };
33
+ async function initialize({ appDir: currentAppDir, baseUrl, paths }) {
34
+ appDir = node_path.resolve(currentAppDir);
35
+ matchPath = createMatchPath(baseUrl || './', paths || {});
36
+ }
37
+ function resolve(specifier, context, defaultResolve) {
38
+ const parentPath = context.parentURL ? node_path.dirname(fileURLToPath(context.parentURL)) : process.cwd();
39
+ const relativeFromApp = appDir ? node_path.relative(appDir, parentPath) : '';
40
+ const isAppFile = appDir && (parentPath === appDir || relativeFromApp && !relativeFromApp.startsWith('..') && !node_path.isAbsolute(relativeFromApp));
41
+ if ((specifier.startsWith('./') || specifier.startsWith('../')) && !node_path.extname(specifier) && isAppFile) {
42
+ const resolvedPath = resolvePathWithExtensions(node_path.resolve(parentPath, specifier));
43
+ if (resolvedPath && node_fs.existsSync(resolvedPath)) return defaultResolve(pathToFileURL(resolvedPath).href, context, defaultResolve);
44
+ }
45
+ if (!matchPath) return defaultResolve(specifier, context, defaultResolve);
46
+ const match = matchPath(specifier, void 0, void 0, [
47
+ '.ts',
48
+ '.tsx',
49
+ '.mts',
50
+ '.cts',
51
+ '.js',
52
+ '.mjs',
53
+ '.cjs'
54
+ ]);
55
+ if (!match) return defaultResolve(specifier, context, defaultResolve);
56
+ const resolvedPath = resolvePathWithExtensions(match);
57
+ return defaultResolve(pathToFileURL(resolvedPath).href, context, defaultResolve);
58
+ }
59
+ export { initialize, resolve };
@@ -17,11 +17,6 @@ import serverRuntime from "./plugins/serverRuntime.mjs";
17
17
  import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
18
18
  import { initAppContext } from "./utils/initAppContext.mjs";
19
19
  import { restart } from "./utils/restart.mjs";
20
- import { defineConfig } from "./defineConfig.mjs";
21
- import { dev } from "./commands/dev.mjs";
22
- import { serve } from "./commands/serve.mjs";
23
- import { resolveModernRsbuildConfig } from "./rsbuild.mjs";
24
- import { mergeConfig } from "@modern-js/plugin/cli";
25
20
  export * from "./defineConfig.mjs";
26
21
  export * from "./types/index.mjs";
27
22
  const appTools = ()=>({
@@ -122,4 +117,10 @@ const appTools = ()=>({
122
117
  }
123
118
  });
124
119
  const src = appTools;
125
- export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, resolveModernRsbuildConfig, serve };
120
+ export { defineConfig } from "./defineConfig.mjs";
121
+ export { dev } from "./commands/dev.mjs";
122
+ export { serve } from "./commands/serve.mjs";
123
+ export { resolveModernRsbuildConfig } from "./rsbuild.mjs";
124
+ export { mergeConfig } from "@modern-js/plugin/cli";
125
+ export default src;
126
+ export { appTools, generateWatchFiles, initAppContext };
@@ -2,7 +2,7 @@ import "node:module";
2
2
  import path from "path";
3
3
  import { findExists, fs } from "@modern-js/utils";
4
4
  import { HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER } from "./constants.mjs";
5
- import { html } from "./templates.mjs";
5
+ import * as __rspack_external__templates_mjs_4da4c6c8 from "./templates.mjs";
6
6
  const findPartials = (dir, entryName, position)=>{
7
7
  if (fs.existsSync(dir)) {
8
8
  const base = findExists(HTML_PARTIALS_EXTENSIONS.map((ext)=>path.resolve(dir, `${position}${ext}`)));
@@ -71,7 +71,7 @@ const getHtmlTemplate = async (entrypoints, hooks, { appContext, config })=>{
71
71
  partials: getModifyHtmlPartials(partials)
72
72
  });
73
73
  const templatePath = path.resolve(internalDirectory, entryName, 'index.html');
74
- fs.outputFileSync(templatePath, html(partials), 'utf8');
74
+ fs.outputFileSync(templatePath, __rspack_external__templates_mjs_4da4c6c8.html(partials), 'utf8');
75
75
  htmlTemplates[entryName] = templatePath.replace(/\\/g, '/');
76
76
  partialsByEntrypoint[entryName] = partials;
77
77
  const bottomTemplate = findPartials(htmlDir, name, "bottom");
@@ -1,6 +1,5 @@
1
1
  import "node:module";
2
2
  import { isPromise } from "node:util/types";
3
- import { extname, resolve } from "path";
4
3
  import { createDebugger, fs, getArgv, getMeta, isApiOnly, isDevCommand, minimist } from "@modern-js/utils";
5
4
  import { createBuilderGenerator } from "../../builder/index.mjs";
6
5
  import { initialNormalizedConfig } from "../../config/index.mjs";
@@ -9,6 +8,7 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries.mjs";
9
8
  import { printInstructions } from "../../utils/printInstructions.mjs";
10
9
  import { generateRoutes } from "../../utils/routes.mjs";
11
10
  import { checkIsBuildCommands, checkIsServeCommand } from "./utils.mjs";
11
+ import * as __rspack_external_path from "path";
12
12
  const debug = createDebugger('plugin-analyze');
13
13
  const analyze = ()=>({
14
14
  name: '@modern-js/plugin-analyze',
@@ -75,7 +75,7 @@ const analyze = ()=>({
75
75
  };
76
76
  api.updateAppContext(appContext);
77
77
  nestedRouteEntries = entrypoints.map((point)=>point.nestedRoutesEntry).filter(Boolean);
78
- pagesDir = entrypoints.map((point)=>point.entry).filter((entry)=>entry && !extname(entry)).concat(nestedRouteEntries);
78
+ pagesDir = entrypoints.map((point)=>point.entry).filter((entry)=>entry && !__rspack_external_path.extname(entry)).concat(nestedRouteEntries);
79
79
  const meta = getMeta(api.getAppContext().metaName);
80
80
  const possibleNames = [
81
81
  `${meta}.routes.ts`,
@@ -89,7 +89,7 @@ const analyze = ()=>({
89
89
  const { absoluteEntryDir } = entrypoint;
90
90
  if (!absoluteEntryDir) return;
91
91
  for (const filename of possibleNames){
92
- const filePath = resolve(absoluteEntryDir, filename);
92
+ const filePath = __rspack_external_path.resolve(absoluteEntryDir, filename);
93
93
  if (await fs.pathExists(filePath)) {
94
94
  const stats = await fs.stat(filePath);
95
95
  if (stats.isFile()) routesConfigFiles.push(filePath);
@@ -201,4 +201,4 @@ const analyze = ()=>({
201
201
  });
202
202
  }
203
203
  });
204
- export { analyze as default };
204
+ export default analyze;
@@ -2,8 +2,8 @@ import "node:module";
2
2
  import fs from "fs";
3
3
  import { parse } from "@babel/parser";
4
4
  import traverse from "@babel/traverse";
5
- import { isArrowFunctionExpression, isFunctionDeclaration, isFunctionExpression } from "@babel/types";
6
- const isFunction = (node)=>isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunctionExpression(node);
5
+ import * as __rspack_external__babel_types_69e65b52 from "@babel/types";
6
+ const isFunction = (node)=>__rspack_external__babel_types_69e65b52.isFunctionDeclaration(node) || __rspack_external__babel_types_69e65b52.isFunctionExpression(node) || __rspack_external__babel_types_69e65b52.isArrowFunctionExpression(node);
7
7
  const isDefaultExportFunction = (file)=>{
8
8
  if (!file || !fs.existsSync(file)) return false;
9
9
  const ast = parse(fs.readFileSync(file, 'utf8'), {
@@ -41,4 +41,4 @@ const deploy = ()=>({
41
41
  });
42
42
  }
43
43
  });
44
- export { deploy as default };
44
+ export default deploy;
@@ -54,4 +54,4 @@ const handler = async (request, context)=>{
54
54
  if (!requestHandler) await createHandler();
55
55
  return requestHandler(request, context);
56
56
  };
57
- exports.handler = handler;
57
+ module.exports.default = handler;
@@ -5,10 +5,11 @@ import { merge } from "@modern-js/utils/lodash";
5
5
  import { normalizePath } from "./index.mjs";
6
6
  const serverAppContextTemplate = (appContext)=>{
7
7
  const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
8
+ const getRelativePathTemplate = (targetDirectory)=>`path.join(__dirname, ${JSON.stringify(normalizePath(node_path.relative(appDirectory, targetDirectory)))})`;
8
9
  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))}")`,
10
+ sharedDirectory: getRelativePathTemplate(sharedDirectory),
11
+ apiDirectory: getRelativePathTemplate(apiDirectory),
12
+ lambdaDirectory: getRelativePathTemplate(lambdaDirectory),
12
13
  metaName,
13
14
  bffRuntimeFramework: bffRuntimeFramework || 'hono'
14
15
  };
@@ -1,9 +1,9 @@
1
1
  import "node:module";
2
- import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
3
- import { dirname as __rspack_dirname } from "node:path";
4
2
  import { pathToFileURL } from "node:url";
5
3
  import path from "path";
6
4
  import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
5
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
6
+ import { dirname as __rspack_dirname } from "node:path";
7
7
  var utils_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
8
8
  const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
9
9
  const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
@@ -57,4 +57,4 @@ async function getServerPort(config) {
57
57
  if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
58
58
  return prodPort;
59
59
  }
60
- export { initialize as default };
60
+ export default initialize;
@@ -44,4 +44,4 @@ const serverBuild = ()=>({
44
44
  });
45
45
  }
46
46
  });
47
- export { serverBuild as default };
47
+ export default serverBuild;
@@ -13,4 +13,4 @@ const serverRuntime = ()=>({
13
13
  }));
14
14
  }
15
15
  });
16
- export { serverRuntime as default };
16
+ export default serverRuntime;
@@ -1,9 +1,9 @@
1
1
  import "node:module";
2
- import { join } from "path";
3
2
  import { OUTPUT_CONFIG_FILE, ensureAbsolutePath, fs } from "@modern-js/utils";
4
3
  import { stringify } from "flatted";
4
+ import * as __rspack_external_path from "path";
5
5
  const emitResolvedConfig = async (appDirectory, resolvedConfig)=>{
6
- const outputPath = ensureAbsolutePath(appDirectory, join(resolvedConfig.output.distPath?.root || './dist', OUTPUT_CONFIG_FILE));
6
+ const outputPath = ensureAbsolutePath(appDirectory, __rspack_external_path.join(resolvedConfig.output.distPath?.root || './dist', OUTPUT_CONFIG_FILE));
7
7
  const output = stringify(resolvedConfig);
8
8
  await fs.writeFile(outputPath, output, {
9
9
  encoding: 'utf-8'