@modern-js/app-tools 3.1.3 → 3.1.5

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 (33) hide show
  1. package/dist/cjs/commands/dev.js +1 -2
  2. package/dist/cjs/esm/register-esm.js +3 -8
  3. package/dist/cjs/esm/register-esm.mjs +3 -8
  4. package/dist/cjs/esm/ts-node-loader.js +6 -9
  5. package/dist/cjs/esm/ts-node-loader.mjs +6 -9
  6. package/dist/cjs/esm/ts-paths-loader.js +14 -36
  7. package/dist/cjs/esm/ts-paths-loader.mjs +14 -36
  8. package/dist/cjs/plugins/analyze/utils.js +25 -8
  9. package/dist/cjs/plugins/deploy/utils/generator.js +1 -1
  10. package/dist/cjs/utils/register.js +62 -29
  11. package/dist/esm/commands/dev.mjs +1 -2
  12. package/dist/esm/esm/register-esm.mjs +3 -8
  13. package/dist/esm/esm/ts-node-loader.mjs +6 -9
  14. package/dist/esm/esm/ts-paths-loader.mjs +14 -36
  15. package/dist/esm/plugins/analyze/utils.mjs +24 -7
  16. package/dist/esm/plugins/deploy/utils/generator.mjs +1 -1
  17. package/dist/esm/utils/register.mjs +63 -30
  18. package/dist/esm-node/commands/dev.mjs +1 -2
  19. package/dist/esm-node/esm/register-esm.mjs +3 -8
  20. package/dist/esm-node/esm/ts-node-loader.mjs +6 -9
  21. package/dist/esm-node/esm/ts-paths-loader.mjs +14 -36
  22. package/dist/esm-node/plugins/analyze/utils.mjs +24 -7
  23. package/dist/esm-node/plugins/deploy/utils/generator.mjs +1 -1
  24. package/dist/esm-node/utils/register.mjs +63 -30
  25. package/dist/types/esm/register-esm.d.mts +3 -2
  26. package/dist/types/esm/ts-node-loader.d.mts +3 -4
  27. package/dist/types/utils/register.d.ts +0 -1
  28. package/package.json +15 -16
  29. package/dist/cjs/esm/utils.js +0 -69
  30. package/dist/cjs/esm/utils.mjs +0 -31
  31. package/dist/esm/esm/utils.mjs +0 -32
  32. package/dist/esm-node/esm/utils.mjs +0 -33
  33. package/dist/types/esm/utils.d.mts +0 -5
@@ -1,11 +1,57 @@
1
1
  import node_path from "node:path";
2
- import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
2
+ import { fs, getAliasConfig, isDepExists, loadFromProject, mergeAlias, readTsConfigByFile } from "@modern-js/utils";
3
+ const normalizePathValue = ({ key, value, absoluteBaseUrl })=>{
4
+ let normalizedValue = value;
5
+ if (key.startsWith('@') && normalizedValue.startsWith('@')) try {
6
+ normalizedValue = require.resolve(normalizedValue, {
7
+ paths: [
8
+ process.cwd(),
9
+ ...module.paths
10
+ ]
11
+ });
12
+ } catch {}
13
+ return node_path.isAbsolute(normalizedValue) ? node_path.relative(absoluteBaseUrl, normalizedValue) : normalizedValue;
14
+ };
15
+ const normalizePathValues = ({ key, value, absoluteBaseUrl })=>{
16
+ const values = Array.isArray(value) ? value : [
17
+ value
18
+ ];
19
+ return values.map((item)=>normalizePathValue({
20
+ key,
21
+ value: item,
22
+ absoluteBaseUrl
23
+ }));
24
+ };
25
+ const addResolvedAlias = (paths, key, values)=>{
26
+ if (!key || paths[key]) return;
27
+ paths[key] = values;
28
+ };
29
+ const createRuntimePaths = ({ alias, paths, absoluteBaseUrl })=>{
30
+ const mergedAlias = mergeAlias(alias);
31
+ const normalizedPaths = Object.keys(paths).reduce((result, key)=>{
32
+ addResolvedAlias(result, key.endsWith('$') ? key.slice(0, -1) : key, normalizePathValues({
33
+ key,
34
+ value: paths[key],
35
+ absoluteBaseUrl
36
+ }));
37
+ return result;
38
+ }, {});
39
+ Object.keys(mergedAlias).forEach((key)=>{
40
+ if (key.includes('*') || key.endsWith('$')) return;
41
+ addResolvedAlias(normalizedPaths, `${key}/*`, normalizePathValues({
42
+ key,
43
+ value: mergedAlias[key],
44
+ absoluteBaseUrl
45
+ }).map((value)=>`${value}/*`));
46
+ });
47
+ return normalizedPaths;
48
+ };
3
49
  const resolveTsRuntimeRegisterMode = (hasTsNode)=>{
50
+ if (hasTsNode) return 'ts-node';
4
51
  const hasNativeTypeScriptSupport = process.features?.typescript;
5
52
  const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
6
53
  const supportsNativeTypeScript = void 0 === hasNativeTypeScriptSupport ? nodeMajorVersion >= 22 : false !== hasNativeTypeScriptSupport;
7
54
  if (supportsNativeTypeScript) return 'node-loader';
8
- if (hasTsNode) return 'ts-node';
9
55
  return 'unsupported';
10
56
  };
11
57
  const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
@@ -14,32 +60,17 @@ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
14
60
  const isTsProject = await fs.pathExists(tsconfigPath);
15
61
  const hasTsNode = isDepExists(appDir, 'ts-node');
16
62
  if (!isTsProject) return;
17
- const preferredRegisterMode = resolveTsRuntimeRegisterMode(hasTsNode);
18
- const registerMode = options.preferTsNodeForServerRuntime && hasTsNode ? 'ts-node' : preferredRegisterMode;
63
+ const registerMode = resolveTsRuntimeRegisterMode(hasTsNode);
19
64
  const aliasConfig = getAliasConfig(alias, {
20
65
  appDirectory: appDir,
21
66
  tsconfigPath
22
67
  });
23
68
  const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
24
- const tsPaths = Object.keys(paths).reduce((o, key)=>{
25
- let tsPath = paths[key];
26
- if ('string' == typeof tsPath && key.startsWith('@') && tsPath.startsWith('@')) try {
27
- tsPath = require.resolve(tsPath, {
28
- paths: [
29
- process.cwd(),
30
- ...module.paths
31
- ]
32
- });
33
- } catch {}
34
- if ('string' == typeof tsPath && node_path.isAbsolute(tsPath)) tsPath = node_path.relative(absoluteBaseUrl, tsPath);
35
- if ('string' == typeof tsPath) tsPath = [
36
- tsPath
37
- ];
38
- return {
39
- ...o,
40
- [`${key}`]: tsPath
41
- };
42
- }, {});
69
+ const runtimePaths = createRuntimePaths({
70
+ alias,
71
+ paths,
72
+ absoluteBaseUrl
73
+ });
43
74
  if ('unsupported' === registerMode) return;
44
75
  if ('ts-node' === registerMode) {
45
76
  if ('module' === options.moduleType) {
@@ -47,7 +78,14 @@ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
47
78
  await registerModuleHooks({
48
79
  appDir,
49
80
  distDir,
50
- alias: alias || {}
81
+ baseUrl: absoluteBaseUrl || './',
82
+ paths: runtimePaths
83
+ });
84
+ } else {
85
+ const { register } = await import("@modern-js/utils/tsconfig-paths");
86
+ register({
87
+ baseUrl: absoluteBaseUrl || './',
88
+ paths: runtimePaths
51
89
  });
52
90
  }
53
91
  const tsConfig = readTsConfigByFile(tsconfigPath);
@@ -69,13 +107,8 @@ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
69
107
  await registerPathsLoader({
70
108
  appDir,
71
109
  baseUrl: absoluteBaseUrl || './',
72
- paths: tsPaths
110
+ paths: runtimePaths
73
111
  });
74
112
  }
75
- const { register } = await import("@modern-js/utils/tsconfig-paths");
76
- register({
77
- baseUrl: absoluteBaseUrl || './',
78
- paths: tsPaths
79
- });
80
113
  };
81
114
  export { resolveTsRuntimeRegisterMode, setupTsRuntime };
@@ -15,8 +15,7 @@ const dev = async (api, options, devServerOptions)=>{
15
15
  const hooks = api.getHooks();
16
16
  const combinedAlias = [].concat(normalizedConfig?.resolve?.alias ?? []).concat(normalizedConfig?.source?.alias ?? []);
17
17
  await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias, {
18
- moduleType: appContext.moduleType,
19
- preferTsNodeForServerRuntime: true
18
+ moduleType: appContext.moduleType
20
19
  });
21
20
  const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
22
21
  const meta = getMeta(metaName);
@@ -1,11 +1,8 @@
1
1
  import "node:module";
2
2
  import node_path from "node:path";
3
- import { fs } from "@modern-js/utils";
4
- const registerModuleHooks = async ({ appDir, distDir, alias })=>{
3
+ const registerModuleHooks = async ({ appDir, distDir, baseUrl, paths })=>{
5
4
  const TS_CONFIG_FILENAME = "tsconfig.json";
6
5
  const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
7
- const hasTsconfig = await fs.pathExists(tsconfigPath);
8
- if (!hasTsconfig) return;
9
6
  const { register } = await import("node:module");
10
7
  process.env.TS_NODE_TRANSPILE_ONLY = true;
11
8
  process.env.TS_NODE_PROJECT = tsconfigPath;
@@ -14,10 +11,8 @@ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
14
11
  process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${node_path.relative(appDir, distDir)}/`;
15
12
  register('./ts-node-loader.mjs', import.meta.url, {
16
13
  data: {
17
- appDir,
18
- distDir,
19
- alias,
20
- tsconfigPath
14
+ baseUrl,
15
+ paths
21
16
  }
22
17
  });
23
18
  };
@@ -1,18 +1,15 @@
1
1
  import "node:module";
2
2
  import { pathToFileURL } from "url";
3
+ import { findMatchedSourcePath, findSourceEntry } from "@modern-js/utils";
4
+ import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
3
5
  import { load, resolve } from "ts-node/esm";
4
- import { createMatchPath } from "./utils.mjs";
5
6
  let matchPath;
6
- async function initialize({ appDir, alias, tsconfigPath }) {
7
- matchPath = createMatchPath({
8
- alias,
9
- appDir,
10
- tsconfigPath
11
- });
7
+ async function initialize({ baseUrl, paths }) {
8
+ matchPath = createMatchPath(baseUrl || './', paths || {});
12
9
  }
13
10
  function ts_node_loader_resolve(specifier, context, defaultResolve) {
14
- const match = matchPath(specifier);
15
- return match ? resolve(pathToFileURL(match).href, context, defaultResolve) : resolve(specifier, context, defaultResolve);
11
+ const match = findMatchedSourcePath(matchPath, specifier);
12
+ return match ? resolve(pathToFileURL(findSourceEntry(match) || match).href, context, defaultResolve) : resolve(specifier, context, defaultResolve);
16
13
  }
17
14
  function ts_node_loader_load(url, context, defaultLoad) {
18
15
  const filePath = new URL(url).pathname;
@@ -2,58 +2,36 @@ import "node:module";
2
2
  import node_fs from "node:fs";
3
3
  import node_path from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "url";
5
+ import { findMatchedSourcePath, findSourceEntry } from "@modern-js/utils";
5
6
  import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
6
7
  let matchPath;
7
8
  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;
9
+ const getParentPath = (parentURL)=>{
10
+ if (!parentURL) return process.cwd();
11
+ if (node_path.isAbsolute(parentURL)) return node_path.dirname(parentURL);
12
+ try {
13
+ const url = new URL(parentURL);
14
+ if ('file:' === url.protocol) return node_path.dirname(fileURLToPath(url));
15
+ } catch {}
16
+ return process.cwd();
32
17
  };
33
18
  async function initialize({ appDir: currentAppDir, baseUrl, paths }) {
34
19
  appDir = node_path.resolve(currentAppDir);
35
20
  matchPath = createMatchPath(baseUrl || './', paths || {});
36
21
  }
37
22
  function resolve(specifier, context, defaultResolve) {
38
- const parentPath = context.parentURL ? node_path.dirname(fileURLToPath(context.parentURL)) : process.cwd();
23
+ const parentPath = getParentPath(context.parentURL);
39
24
  const relativeFromApp = appDir ? node_path.relative(appDir, parentPath) : '';
40
25
  const isAppFile = appDir && (parentPath === appDir || relativeFromApp && !relativeFromApp.startsWith('..') && !node_path.isAbsolute(relativeFromApp));
41
26
  if ((specifier.startsWith('./') || specifier.startsWith('../')) && !node_path.extname(specifier) && isAppFile) {
42
- const resolvedPath = resolvePathWithExtensions(node_path.resolve(parentPath, specifier));
27
+ const matchedPath = node_path.resolve(parentPath, specifier);
28
+ const resolvedPath = findSourceEntry(matchedPath) || matchedPath;
43
29
  if (resolvedPath && node_fs.existsSync(resolvedPath)) return defaultResolve(pathToFileURL(resolvedPath).href, context, defaultResolve);
44
30
  }
45
31
  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
- ]);
32
+ const match = findMatchedSourcePath(matchPath, specifier);
55
33
  if (!match) return defaultResolve(specifier, context, defaultResolve);
56
- const resolvedPath = resolvePathWithExtensions(match);
34
+ const resolvedPath = findSourceEntry(match) || match;
57
35
  return defaultResolve(pathToFileURL(resolvedPath).href, context, defaultResolve);
58
36
  }
59
37
  export { initialize, resolve };
@@ -2,8 +2,8 @@ import "node:module";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import { JS_EXTENSIONS, getCommand, normalizeToPosixPath } from "@modern-js/utils";
5
+ import { transform } from "@swc/core";
5
6
  import { parse } from "es-module-lexer";
6
- import { transform } from "esbuild";
7
7
  const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
8
8
  const filePath = path.join(dir, filename);
9
9
  if (fs.statSync(filePath).isDirectory()) return [
@@ -22,13 +22,30 @@ const replaceWithAlias = (base, filePath, alias)=>{
22
22
  const parseModule = async ({ source, filename })=>{
23
23
  let content = source;
24
24
  if (JS_EXTENSIONS.some((ext)=>filename.endsWith(ext))) {
25
+ const ext = path.extname(filename);
26
+ const isTs = '.ts' === ext || '.tsx' === ext;
27
+ const isJsx = '.jsx' === ext || '.tsx' === ext;
25
28
  const result = await transform(content, {
26
- loader: path.extname(filename).slice(1),
27
- format: 'esm',
28
- tsconfigRaw: {
29
- compilerOptions: {
30
- experimentalDecorators: true
31
- }
29
+ filename,
30
+ isModule: true,
31
+ module: {
32
+ type: 'es6'
33
+ },
34
+ jsc: {
35
+ parser: isTs ? {
36
+ syntax: "typescript",
37
+ tsx: isJsx,
38
+ decorators: true
39
+ } : {
40
+ syntax: "ecmascript",
41
+ jsx: isJsx,
42
+ decorators: true
43
+ },
44
+ transform: {
45
+ legacyDecorator: true
46
+ },
47
+ target: 'es2022',
48
+ keepClassNames: true
32
49
  }
33
50
  });
34
51
  content = result.code;
@@ -19,7 +19,7 @@ const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, optio
19
19
  return `${im};const plugin_${index} = plugin_${index}_ns.default || plugin_${index}_ns`;
20
20
  }).join(';\n');
21
21
  const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
22
- const getServerConfigPath = (meta)=>`"${normalizePath(node_path.join(SERVER_DIR, `${meta}.server`))}"`;
22
+ const getServerConfigPath = (meta)=>`path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
23
23
  const generateHandler = async ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate = serverAppContextTemplate, genPluginImports = genPluginImportsCode, isESM })=>{
24
24
  const { serverPlugins, metaName } = appContext;
25
25
  const plugins = serverPlugins.map((plugin)=>[
@@ -1,13 +1,59 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
3
  import node_path from "node:path";
4
- import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
4
+ import { fs, getAliasConfig, isDepExists, loadFromProject, mergeAlias, readTsConfigByFile } from "@modern-js/utils";
5
+ const normalizePathValue = ({ key, value, absoluteBaseUrl })=>{
6
+ let normalizedValue = value;
7
+ if (key.startsWith('@') && normalizedValue.startsWith('@')) try {
8
+ normalizedValue = require.resolve(normalizedValue, {
9
+ paths: [
10
+ process.cwd(),
11
+ ...module.paths
12
+ ]
13
+ });
14
+ } catch {}
15
+ return node_path.isAbsolute(normalizedValue) ? node_path.relative(absoluteBaseUrl, normalizedValue) : normalizedValue;
16
+ };
17
+ const normalizePathValues = ({ key, value, absoluteBaseUrl })=>{
18
+ const values = Array.isArray(value) ? value : [
19
+ value
20
+ ];
21
+ return values.map((item)=>normalizePathValue({
22
+ key,
23
+ value: item,
24
+ absoluteBaseUrl
25
+ }));
26
+ };
27
+ const addResolvedAlias = (paths, key, values)=>{
28
+ if (!key || paths[key]) return;
29
+ paths[key] = values;
30
+ };
31
+ const createRuntimePaths = ({ alias, paths, absoluteBaseUrl })=>{
32
+ const mergedAlias = mergeAlias(alias);
33
+ const normalizedPaths = Object.keys(paths).reduce((result, key)=>{
34
+ addResolvedAlias(result, key.endsWith('$') ? key.slice(0, -1) : key, normalizePathValues({
35
+ key,
36
+ value: paths[key],
37
+ absoluteBaseUrl
38
+ }));
39
+ return result;
40
+ }, {});
41
+ Object.keys(mergedAlias).forEach((key)=>{
42
+ if (key.includes('*') || key.endsWith('$')) return;
43
+ addResolvedAlias(normalizedPaths, `${key}/*`, normalizePathValues({
44
+ key,
45
+ value: mergedAlias[key],
46
+ absoluteBaseUrl
47
+ }).map((value)=>`${value}/*`));
48
+ });
49
+ return normalizedPaths;
50
+ };
5
51
  const resolveTsRuntimeRegisterMode = (hasTsNode)=>{
52
+ if (hasTsNode) return 'ts-node';
6
53
  const hasNativeTypeScriptSupport = process.features?.typescript;
7
54
  const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
8
55
  const supportsNativeTypeScript = void 0 === hasNativeTypeScriptSupport ? nodeMajorVersion >= 22 : false !== hasNativeTypeScriptSupport;
9
56
  if (supportsNativeTypeScript) return 'node-loader';
10
- if (hasTsNode) return 'ts-node';
11
57
  return 'unsupported';
12
58
  };
13
59
  const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
@@ -16,32 +62,17 @@ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
16
62
  const isTsProject = await fs.pathExists(tsconfigPath);
17
63
  const hasTsNode = isDepExists(appDir, 'ts-node');
18
64
  if (!isTsProject) return;
19
- const preferredRegisterMode = resolveTsRuntimeRegisterMode(hasTsNode);
20
- const registerMode = options.preferTsNodeForServerRuntime && hasTsNode ? 'ts-node' : preferredRegisterMode;
65
+ const registerMode = resolveTsRuntimeRegisterMode(hasTsNode);
21
66
  const aliasConfig = getAliasConfig(alias, {
22
67
  appDirectory: appDir,
23
68
  tsconfigPath
24
69
  });
25
70
  const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
26
- const tsPaths = Object.keys(paths).reduce((o, key)=>{
27
- let tsPath = paths[key];
28
- if ('string' == typeof tsPath && key.startsWith('@') && tsPath.startsWith('@')) try {
29
- tsPath = require.resolve(tsPath, {
30
- paths: [
31
- process.cwd(),
32
- ...module.paths
33
- ]
34
- });
35
- } catch {}
36
- if ('string' == typeof tsPath && node_path.isAbsolute(tsPath)) tsPath = node_path.relative(absoluteBaseUrl, tsPath);
37
- if ('string' == typeof tsPath) tsPath = [
38
- tsPath
39
- ];
40
- return {
41
- ...o,
42
- [`${key}`]: tsPath
43
- };
44
- }, {});
71
+ const runtimePaths = createRuntimePaths({
72
+ alias,
73
+ paths,
74
+ absoluteBaseUrl
75
+ });
45
76
  if ('unsupported' === registerMode) return;
46
77
  if ('ts-node' === registerMode) {
47
78
  if ('module' === options.moduleType) {
@@ -49,7 +80,14 @@ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
49
80
  await registerModuleHooks({
50
81
  appDir,
51
82
  distDir,
52
- alias: alias || {}
83
+ baseUrl: absoluteBaseUrl || './',
84
+ paths: runtimePaths
85
+ });
86
+ } else {
87
+ const { register } = await import("@modern-js/utils/tsconfig-paths");
88
+ register({
89
+ baseUrl: absoluteBaseUrl || './',
90
+ paths: runtimePaths
53
91
  });
54
92
  }
55
93
  const tsConfig = readTsConfigByFile(tsconfigPath);
@@ -71,13 +109,8 @@ const setupTsRuntime = async (appDir, distDir, alias, options = {})=>{
71
109
  await registerPathsLoader({
72
110
  appDir,
73
111
  baseUrl: absoluteBaseUrl || './',
74
- paths: tsPaths
112
+ paths: runtimePaths
75
113
  });
76
114
  }
77
- const { register } = await import("@modern-js/utils/tsconfig-paths");
78
- register({
79
- baseUrl: absoluteBaseUrl || './',
80
- paths: tsPaths
81
- });
82
115
  };
83
116
  export { resolveTsRuntimeRegisterMode, setupTsRuntime };
@@ -1,7 +1,8 @@
1
- export function registerModuleHooks({ appDir, distDir, alias }: {
1
+ export function registerModuleHooks({ appDir, distDir, baseUrl, paths, }: {
2
2
  appDir: any;
3
3
  distDir: any;
4
- alias: any;
4
+ baseUrl: any;
5
+ paths: any;
5
6
  }): Promise<void>;
6
7
  export function registerPathsLoader({ appDir, baseUrl, paths }: {
7
8
  appDir: any;
@@ -1,7 +1,6 @@
1
- export function initialize({ appDir, alias, tsconfigPath }: {
2
- appDir: any;
3
- alias: any;
4
- tsconfigPath: any;
1
+ export function initialize({ baseUrl, paths }: {
2
+ baseUrl: any;
3
+ paths: any;
5
4
  }): Promise<void>;
6
5
  export function resolve(specifier: any, context: any, defaultResolve: any): any;
7
6
  export function load(url: any, context: any, defaultLoad: any): any;
@@ -3,7 +3,6 @@ import type { ConfigChain } from '@rsbuild/core';
3
3
  type TsRuntimeRegisterMode = 'ts-node' | 'node-loader' | 'unsupported';
4
4
  interface TsRuntimeSetupOptions {
5
5
  moduleType?: string;
6
- preferTsNodeForServerRuntime?: boolean;
7
6
  }
8
7
  export declare const resolveTsRuntimeRegisterMode: (hasTsNode: boolean) => TsRuntimeRegisterMode;
9
8
  /**
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.1.3",
18
+ "version": "3.1.5",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -83,30 +83,29 @@
83
83
  "@babel/parser": "^7.29.2",
84
84
  "@babel/traverse": "^7.29.0",
85
85
  "@babel/types": "^7.29.0",
86
- "@rsbuild/core": "2.0.0-rc.0",
86
+ "@rsbuild/core": "2.0.0",
87
+ "@swc/core": "1.15.11",
87
88
  "@swc/helpers": "^0.5.17",
88
89
  "es-module-lexer": "^1.7.0",
89
- "esbuild": "0.25.5",
90
- "esbuild-register": "^3.6.0",
91
90
  "import-meta-resolve": "^4.2.0",
92
91
  "flatted": "^3.4.2",
93
- "mlly": "^1.8.0",
92
+ "mlly": "^1.8.2",
94
93
  "ndepe": "^0.1.13",
95
94
  "pkg-types": "^1.3.1",
96
95
  "std-env": "^3.10.0",
97
- "@modern-js/builder": "3.1.3",
98
- "@modern-js/i18n-utils": "3.1.3",
99
- "@modern-js/plugin-data-loader": "3.1.3",
100
- "@modern-js/plugin": "3.1.3",
101
- "@modern-js/prod-server": "3.1.3",
102
- "@modern-js/server": "3.1.3",
103
- "@modern-js/server-core": "3.1.3",
104
- "@modern-js/server-utils": "3.1.3",
105
- "@modern-js/types": "3.1.3",
106
- "@modern-js/utils": "3.1.3"
96
+ "@modern-js/builder": "3.1.5",
97
+ "@modern-js/i18n-utils": "3.1.5",
98
+ "@modern-js/prod-server": "3.1.5",
99
+ "@modern-js/plugin-data-loader": "3.1.5",
100
+ "@modern-js/plugin": "3.1.5",
101
+ "@modern-js/server": "3.1.5",
102
+ "@modern-js/server-core": "3.1.5",
103
+ "@modern-js/types": "3.1.5",
104
+ "@modern-js/server-utils": "3.1.5",
105
+ "@modern-js/utils": "3.1.5"
107
106
  },
108
107
  "devDependencies": {
109
- "@rslib/core": "0.21.0",
108
+ "@rslib/core": "0.21.2",
110
109
  "@types/babel__traverse": "7.28.0",
111
110
  "@types/node": "^20",
112
111
  "ts-node": "^10.9.2",
@@ -1,69 +0,0 @@
1
- "use strict";
2
- const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
- return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
- }();
5
- var __webpack_require__ = {};
6
- (()=>{
7
- __webpack_require__.d = (exports1, definition)=>{
8
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
9
- enumerable: true,
10
- get: definition[key]
11
- });
12
- };
13
- })();
14
- (()=>{
15
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
16
- })();
17
- (()=>{
18
- __webpack_require__.r = (exports1)=>{
19
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
- value: 'Module'
21
- });
22
- Object.defineProperty(exports1, '__esModule', {
23
- value: true
24
- });
25
- };
26
- })();
27
- var __webpack_exports__ = {};
28
- __webpack_require__.r(__webpack_exports__);
29
- __webpack_require__.d(__webpack_exports__, {
30
- createMatchPath: ()=>createMatchPath
31
- });
32
- const external_module_namespaceObject = require("module");
33
- const external_path_namespaceObject = require("path");
34
- const utils_namespaceObject = require("@modern-js/utils");
35
- const tsconfig_paths_namespaceObject = require("@modern-js/utils/tsconfig-paths");
36
- const utils_require = (0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
37
- function createMatchPath({ alias, appDir, tsconfigPath }) {
38
- const aliasConfig = (0, utils_namespaceObject.getAliasConfig)(alias, {
39
- appDirectory: appDir,
40
- tsconfigPath
41
- });
42
- const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
43
- const tsPaths = Object.keys(paths).reduce((o, key)=>{
44
- let tsPath = paths[key];
45
- if ('string' == typeof tsPath && key.startsWith('@') && tsPath.startsWith('@')) try {
46
- tsPath = utils_require.resolve(tsPath, {
47
- paths: [
48
- appDir
49
- ]
50
- });
51
- } catch {}
52
- if ('string' == typeof tsPath && external_path_namespaceObject.isAbsolute(tsPath)) tsPath = external_path_namespaceObject.relative(absoluteBaseUrl, tsPath);
53
- if ('string' == typeof tsPath) tsPath = [
54
- tsPath
55
- ];
56
- return {
57
- ...o,
58
- [`${key}`]: tsPath
59
- };
60
- }, {});
61
- return (0, tsconfig_paths_namespaceObject.createMatchPath)(absoluteBaseUrl, tsPaths);
62
- }
63
- exports.createMatchPath = __webpack_exports__.createMatchPath;
64
- for(var __rspack_i in __webpack_exports__)if (-1 === [
65
- "createMatchPath"
66
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
67
- Object.defineProperty(exports, '__esModule', {
68
- value: true
69
- });
@@ -1,31 +0,0 @@
1
- import { createRequire } from 'module';
2
- import path from 'path';
3
- import { getAliasConfig } from '@modern-js/utils';
4
- import { createMatchPath as oCreateMatchPath } from '@modern-js/utils/tsconfig-paths';
5
- const require = createRequire(import.meta.url);
6
- export function createMatchPath({ alias, appDir, tsconfigPath }) {
7
- const aliasConfig = getAliasConfig(alias, {
8
- appDirectory: appDir,
9
- tsconfigPath
10
- });
11
- const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
12
- const tsPaths = Object.keys(paths).reduce((o, key)=>{
13
- let tsPath = paths[key];
14
- if ('string' == typeof tsPath && key.startsWith('@') && tsPath.startsWith('@')) try {
15
- tsPath = require.resolve(tsPath, {
16
- paths: [
17
- appDir
18
- ]
19
- });
20
- } catch {}
21
- if ('string' == typeof tsPath && path.isAbsolute(tsPath)) tsPath = path.relative(absoluteBaseUrl, tsPath);
22
- if ('string' == typeof tsPath) tsPath = [
23
- tsPath
24
- ];
25
- return {
26
- ...o,
27
- [`${key}`]: tsPath
28
- };
29
- }, {});
30
- return oCreateMatchPath(absoluteBaseUrl, tsPaths);
31
- }