@modern-js/server-utils 3.9.0 → 3.9.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.
@@ -71,8 +71,10 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
71
71
  utils_namespaceObject.logger.info("Running ts compile...");
72
72
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
73
73
  if (!tsconfigPath) return;
74
+ const tsConfig = (0, utils_namespaceObject.readTsConfigByFile)(tsconfigPath);
74
75
  const ts = new external_typescriptLoader_js_namespaceObject.TypescriptLoader({
75
- appDirectory
76
+ appDirectory,
77
+ compiler: tsConfig['ts-node']?.compiler
76
78
  }).load();
77
79
  const createProgram = ts.createIncrementalProgram || ts.createProgram;
78
80
  const formatHost = getFormatHost(ts);
@@ -45,7 +45,6 @@ const external_path_namespaceObject = require("path");
45
45
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
46
46
  const utils_namespaceObject = require("@modern-js/utils");
47
47
  const tsconfig_paths_namespaceObject = require("@modern-js/utils/tsconfig-paths");
48
- const external_typescript_namespaceObject = require("typescript");
49
48
  const COMPILED_TO_JS_EXTENSIONS = new Set([
50
49
  '.ts',
51
50
  '.tsx',
@@ -104,7 +103,7 @@ const createAliasMatcher = (baseUrl, alias)=>{
104
103
  }
105
104
  };
106
105
  };
107
- const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === external_typescript_namespaceObject.SyntaxKind.ImportKeyword;
106
+ const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === tsBinary.SyntaxKind.ImportKeyword;
108
107
  const createTsMatchPath = (baseUrl, paths)=>{
109
108
  const tsPaths = {};
110
109
  const alias = {};
@@ -31,7 +31,7 @@ class TypescriptLoader {
31
31
  load() {
32
32
  if (this.tsBinary) return this.tsBinary;
33
33
  try {
34
- const tsPath = require.resolve("typescript", {
34
+ const tsPath = require.resolve(this.compiler || "typescript", {
35
35
  paths: [
36
36
  this.appDirectory || process.cwd()
37
37
  ]
@@ -42,8 +42,9 @@ class TypescriptLoader {
42
42
  throw new Error('TypeScript could not be found! Please, install "typescript" package.');
43
43
  }
44
44
  }
45
- constructor({ appDirectory }){
45
+ constructor({ appDirectory, compiler }){
46
46
  this.appDirectory = appDirectory;
47
+ this.compiler = compiler;
47
48
  }
48
49
  }
49
50
  __webpack_require__.d(__webpack_exports__, {
@@ -1,8 +1,8 @@
1
1
  import path_0 from "path";
2
- import { fs, getAliasConfig, logger } from "@modern-js/utils";
2
+ import { fs, getAliasConfig, logger, readTsConfigByFile } from "@modern-js/utils";
3
3
  import { tsconfigPathsAfterDeclarationsHookFactory, tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin.mjs";
4
4
  import { TypescriptLoader } from "./typescriptLoader.mjs";
5
- const readTsConfigByFile = (tsConfigFile, tsInstance)=>{
5
+ const typescript_readTsConfigByFile = (tsConfigFile, tsInstance)=>{
6
6
  const parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
7
7
  const { options, fileNames, projectReferences } = parsedCmd;
8
8
  return {
@@ -29,8 +29,10 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
29
29
  logger.info("Running ts compile...");
30
30
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
31
31
  if (!tsconfigPath) return;
32
+ const tsConfig = readTsConfigByFile(tsconfigPath);
32
33
  const ts = new TypescriptLoader({
33
- appDirectory
34
+ appDirectory,
35
+ compiler: tsConfig['ts-node']?.compiler
34
36
  }).load();
35
37
  const createProgram = ts.createIncrementalProgram || ts.createProgram;
36
38
  const formatHost = getFormatHost(ts);
@@ -40,7 +42,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
40
42
  tsconfigPath
41
43
  });
42
44
  const { paths = {}, absoluteBaseUrl = './' } = aliasOption;
43
- const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath, ts);
45
+ const { options, fileNames, projectReferences } = typescript_readTsConfigByFile(tsconfigPath, ts);
44
46
  const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(path_0.sep).join(path_0.posix.sep));
45
47
  const rootNames = fileNames.filter((fileName)=>fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>fileName.includes(sourceDir)));
46
48
  const program = createProgram.call(ts, {
@@ -2,7 +2,6 @@ import path, { dirname, posix } from "path";
2
2
  import { findMatchedSourcePath, findSourceEntry } from "@modern-js/utils";
3
3
  import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
4
4
  import * as __rspack_external_os from "os";
5
- import * as __rspack_external_typescript from "typescript";
6
5
  const COMPILED_TO_JS_EXTENSIONS = new Set([
7
6
  '.ts',
8
7
  '.tsx',
@@ -61,7 +60,7 @@ const createAliasMatcher = (baseUrl, alias)=>{
61
60
  }
62
61
  };
63
62
  };
64
- const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === __rspack_external_typescript.SyntaxKind.ImportKeyword;
63
+ const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === tsBinary.SyntaxKind.ImportKeyword;
65
64
  const createTsMatchPath = (baseUrl, paths)=>{
66
65
  const tsPaths = {};
67
66
  const alias = {};
@@ -2,7 +2,7 @@ class TypescriptLoader {
2
2
  load() {
3
3
  if (this.tsBinary) return this.tsBinary;
4
4
  try {
5
- const tsPath = require.resolve("typescript", {
5
+ const tsPath = require.resolve(this.compiler || "typescript", {
6
6
  paths: [
7
7
  this.appDirectory || process.cwd()
8
8
  ]
@@ -13,8 +13,9 @@ class TypescriptLoader {
13
13
  throw new Error('TypeScript could not be found! Please, install "typescript" package.');
14
14
  }
15
15
  }
16
- constructor({ appDirectory }){
16
+ constructor({ appDirectory, compiler }){
17
17
  this.appDirectory = appDirectory;
18
+ this.compiler = compiler;
18
19
  }
19
20
  }
20
21
  export { TypescriptLoader };
@@ -1,9 +1,9 @@
1
1
  import "node:module";
2
2
  import path_0 from "path";
3
- import { fs, getAliasConfig, logger } from "@modern-js/utils";
3
+ import { fs, getAliasConfig, logger, readTsConfigByFile } from "@modern-js/utils";
4
4
  import { tsconfigPathsAfterDeclarationsHookFactory, tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin.mjs";
5
5
  import { TypescriptLoader } from "./typescriptLoader.mjs";
6
- const readTsConfigByFile = (tsConfigFile, tsInstance)=>{
6
+ const typescript_readTsConfigByFile = (tsConfigFile, tsInstance)=>{
7
7
  const parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
8
8
  const { options, fileNames, projectReferences } = parsedCmd;
9
9
  return {
@@ -30,8 +30,10 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
30
30
  logger.info("Running ts compile...");
31
31
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
32
32
  if (!tsconfigPath) return;
33
+ const tsConfig = readTsConfigByFile(tsconfigPath);
33
34
  const ts = new TypescriptLoader({
34
- appDirectory
35
+ appDirectory,
36
+ compiler: tsConfig['ts-node']?.compiler
35
37
  }).load();
36
38
  const createProgram = ts.createIncrementalProgram || ts.createProgram;
37
39
  const formatHost = getFormatHost(ts);
@@ -41,7 +43,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
41
43
  tsconfigPath
42
44
  });
43
45
  const { paths = {}, absoluteBaseUrl = './' } = aliasOption;
44
- const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath, ts);
46
+ const { options, fileNames, projectReferences } = typescript_readTsConfigByFile(tsconfigPath, ts);
45
47
  const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(path_0.sep).join(path_0.posix.sep));
46
48
  const rootNames = fileNames.filter((fileName)=>fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>fileName.includes(sourceDir)));
47
49
  const program = createProgram.call(ts, {
@@ -4,7 +4,6 @@ import path, { dirname, posix } from "path";
4
4
  import { findMatchedSourcePath, findSourceEntry } from "@modern-js/utils";
5
5
  import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
6
6
  import * as __rspack_external_os from "os";
7
- import * as __rspack_external_typescript from "typescript";
8
7
  const COMPILED_TO_JS_EXTENSIONS = new Set([
9
8
  '.ts',
10
9
  '.tsx',
@@ -63,7 +62,7 @@ const createAliasMatcher = (baseUrl, alias)=>{
63
62
  }
64
63
  };
65
64
  };
66
- const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === __rspack_external_typescript.SyntaxKind.ImportKeyword;
65
+ const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === tsBinary.SyntaxKind.ImportKeyword;
67
66
  const createTsMatchPath = (baseUrl, paths)=>{
68
67
  const tsPaths = {};
69
68
  const alias = {};
@@ -4,7 +4,7 @@ class TypescriptLoader {
4
4
  load() {
5
5
  if (this.tsBinary) return this.tsBinary;
6
6
  try {
7
- const tsPath = require.resolve("typescript", {
7
+ const tsPath = require.resolve(this.compiler || "typescript", {
8
8
  paths: [
9
9
  this.appDirectory || process.cwd()
10
10
  ]
@@ -15,8 +15,9 @@ class TypescriptLoader {
15
15
  throw new Error('TypeScript could not be found! Please, install "typescript" package.');
16
16
  }
17
17
  }
18
- constructor({ appDirectory }){
18
+ constructor({ appDirectory, compiler }){
19
19
  this.appDirectory = appDirectory;
20
+ this.compiler = compiler;
20
21
  }
21
22
  }
22
23
  export { TypescriptLoader };
@@ -1,2 +1,2 @@
1
- import type { CompileFunc } from '../../common';
1
+ import type { CompileFunc } from '../../common/index.js';
2
2
  export declare const compileByTs: CompileFunc;
@@ -1,3 +1,3 @@
1
- import * as ts from 'typescript';
1
+ import type * as ts from 'typescript';
2
2
  export declare function tsconfigPathsBeforeHookFactory(tsBinary: typeof ts, baseUrl: string, paths: Record<string, string[] | string>, moduleType?: 'module' | 'commonjs'): ((ctx: ts.TransformationContext) => ts.Transformer<any>) | undefined;
3
3
  export declare function tsconfigPathsAfterDeclarationsHookFactory(tsBinary: typeof ts, baseUrl: string, paths: Record<string, string[] | string>, moduleType?: 'module' | 'commonjs'): ((ctx: ts.TransformationContext) => ts.Transformer<ts.SourceFile | ts.Bundle>) | undefined;
@@ -2,8 +2,10 @@ import type ts from 'typescript';
2
2
  export declare class TypescriptLoader {
3
3
  private tsBinary?;
4
4
  private appDirectory?;
5
- constructor({ appDirectory }: {
5
+ private compiler?;
6
+ constructor({ appDirectory, compiler, }: {
6
7
  appDirectory: string;
8
+ compiler?: string;
7
9
  });
8
10
  load(): typeof ts;
9
11
  }
@@ -1 +1 @@
1
- export { compile } from './common';
1
+ export { compile } from './common/index.js';
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.9.0",
18
+ "version": "3.9.2",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -38,14 +38,14 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@swc/helpers": "^0.5.17",
41
- "@modern-js/utils": "3.9.0"
41
+ "@modern-js/utils": "3.9.2"
42
42
  },
43
43
  "devDependencies": {
44
- "@rslib/core": "0.23.2",
44
+ "@rslib/core": "1.0.0",
45
45
  "@types/node": "^20",
46
46
  "typescript": "^5",
47
47
  "@modern-js/rslib": "2.68.10",
48
- "@modern-js/server-core": "3.9.0",
48
+ "@modern-js/server-core": "3.9.2",
49
49
  "@scripts/rstest-config": "2.66.0"
50
50
  },
51
51
  "sideEffects": false,