@modern-js/server-utils 2.58.1 → 2.58.3
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.
- package/dist/cjs/compilers/babel/index.js +7 -5
- package/dist/cjs/compilers/babel/preset/alias.js +1 -1
- package/dist/cjs/compilers/babel/preset/index.js +2 -1
- package/dist/cjs/compilers/typescript/index.js +1 -1
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +1 -1
- package/dist/esm/compilers/babel/index.js +9 -7
- package/dist/esm/compilers/babel/preset/alias.js +1 -1
- package/dist/esm/compilers/babel/preset/index.js +2 -1
- package/dist/esm/compilers/typescript/index.js +2 -2
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +1 -1
- package/dist/esm-node/compilers/babel/index.js +8 -6
- package/dist/esm-node/compilers/babel/preset/alias.js +1 -1
- package/dist/esm-node/compilers/babel/preset/index.js +2 -1
- package/dist/esm-node/compilers/typescript/index.js +2 -2
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +1 -1
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/compilers/babel/index.d.ts +2 -2
- package/dist/types/compilers/babel/preset/alias.d.ts +1 -1
- package/dist/types/compilers/babel/preset/index.d.ts +1 -1
- package/dist/types/compilers/babel/preset/types.d.ts +1 -0
- package/package.json +8 -8
|
@@ -36,8 +36,8 @@ __export(babel_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(babel_exports);
|
|
38
38
|
var path = __toESM(require("path"));
|
|
39
|
-
var import_utils = require("@modern-js/utils");
|
|
40
39
|
var import_babel_compiler = require("@modern-js/babel-compiler");
|
|
40
|
+
var import_utils = require("@modern-js/utils");
|
|
41
41
|
var import_common = require("../../common");
|
|
42
42
|
var import_preset = require("./preset");
|
|
43
43
|
__reExport(babel_exports, require("@babel/core"), module.exports);
|
|
@@ -52,7 +52,7 @@ const existTsConfigFile = (tsconfigAbsolutePath) => {
|
|
|
52
52
|
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
53
53
|
return Boolean(tsconfig);
|
|
54
54
|
};
|
|
55
|
-
const resolveBabelConfig = (appDirectory, config, option) => {
|
|
55
|
+
const resolveBabelConfig = (appDirectory, config, option, isEsm) => {
|
|
56
56
|
const { alias, babelConfig } = config;
|
|
57
57
|
const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
|
|
58
58
|
appDirectory,
|
|
@@ -60,16 +60,18 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
60
60
|
});
|
|
61
61
|
const defaultBabelConfig = (0, import_preset.getBabelConfig)({
|
|
62
62
|
appDirectory,
|
|
63
|
-
alias: aliasConfig
|
|
63
|
+
alias: aliasConfig,
|
|
64
|
+
isEsm
|
|
64
65
|
});
|
|
65
66
|
return (0, import_preset.applyUserBabelConfig)(defaultBabelConfig, babelConfig);
|
|
66
67
|
};
|
|
67
68
|
const compileByBabel = async (appDirectory, config, compileOptions) => {
|
|
68
|
-
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
69
|
+
const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
|
|
70
|
+
const isEsm = moduleType === "module";
|
|
69
71
|
const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
|
|
70
72
|
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
71
73
|
tsconfigPath: tsconfigPath ? tsconfigPath : ""
|
|
72
|
-
});
|
|
74
|
+
}, isEsm);
|
|
73
75
|
if (await import_utils.fs.pathExists(sourceDir)) {
|
|
74
76
|
const basename = path.basename(sourceDir);
|
|
75
77
|
const targetDir = path.join(distDir, basename);
|
|
@@ -32,8 +32,8 @@ __export(alias_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(alias_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
|
|
36
35
|
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
|
|
37
37
|
const { resolvePath } = require("@modern-js/babel-plugin-module-resolver");
|
|
38
38
|
const defaultPaths = {
|
|
39
39
|
"@": [
|
|
@@ -39,10 +39,11 @@ __reExport(preset_exports, require("./types"), module.exports);
|
|
|
39
39
|
var import_utils = require("@modern-js/utils");
|
|
40
40
|
const getBabelConfig = (libPresetOption) => {
|
|
41
41
|
var _config_presets, _config_plugins;
|
|
42
|
+
const { isEsm } = libPresetOption;
|
|
42
43
|
const config = (0, import_node.getBabelConfigForNode)({
|
|
43
44
|
presetEnv: {
|
|
44
45
|
loose: true,
|
|
45
|
-
modules: "commonjs",
|
|
46
|
+
modules: isEsm ? false : "commonjs",
|
|
46
47
|
targets: [
|
|
47
48
|
"node >= 14"
|
|
48
49
|
]
|
|
@@ -33,8 +33,8 @@ __export(typescript_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(typescript_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var import_typescriptLoader = require("./typescriptLoader");
|
|
37
36
|
var import_tsconfigPathsPlugin = require("./tsconfigPathsPlugin");
|
|
37
|
+
var import_typescriptLoader = require("./typescriptLoader");
|
|
38
38
|
const readTsConfigByFile = (tsConfigFile, tsInstance) => {
|
|
39
39
|
const parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
|
|
40
40
|
const { options, fileNames, projectReferences } = parsedCmd;
|
|
@@ -33,8 +33,8 @@ __export(tsconfigPathsPlugin_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(tsconfigPathsPlugin_exports);
|
|
34
34
|
var os = __toESM(require("os"));
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
|
-
var ts = __toESM(require("typescript"));
|
|
37
36
|
var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
|
|
37
|
+
var ts = __toESM(require("typescript"));
|
|
38
38
|
const isRegExpKey = (str) => {
|
|
39
39
|
return str.startsWith("^") || str.endsWith("$");
|
|
40
40
|
};
|
|
@@ -2,10 +2,10 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import * as path from "path";
|
|
5
|
-
import { fs, json5, getAliasConfig } from "@modern-js/utils";
|
|
6
5
|
import { compiler } from "@modern-js/babel-compiler";
|
|
6
|
+
import { fs, getAliasConfig, json5 } from "@modern-js/utils";
|
|
7
7
|
import { FILE_EXTENSIONS } from "../../common";
|
|
8
|
-
import {
|
|
8
|
+
import { applyUserBabelConfig, getBabelConfig } from "./preset";
|
|
9
9
|
export * from "@babel/core";
|
|
10
10
|
var readTsConfig = function(tsconfigPath) {
|
|
11
11
|
var noExistReturn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
@@ -19,24 +19,26 @@ var existTsConfigFile = function(tsconfigAbsolutePath) {
|
|
|
19
19
|
var tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
20
20
|
return Boolean(tsconfig);
|
|
21
21
|
};
|
|
22
|
-
var resolveBabelConfig = function(appDirectory, config, option) {
|
|
22
|
+
var resolveBabelConfig = function(appDirectory, config, option, isEsm) {
|
|
23
23
|
var alias = config.alias, babelConfig = config.babelConfig;
|
|
24
24
|
var aliasConfig = getAliasConfig(alias, _object_spread({
|
|
25
25
|
appDirectory
|
|
26
26
|
}, option));
|
|
27
27
|
var defaultBabelConfig = getBabelConfig({
|
|
28
28
|
appDirectory,
|
|
29
|
-
alias: aliasConfig
|
|
29
|
+
alias: aliasConfig,
|
|
30
|
+
isEsm
|
|
30
31
|
});
|
|
31
32
|
return applyUserBabelConfig(defaultBabelConfig, babelConfig);
|
|
32
33
|
};
|
|
33
34
|
var compileByBabel = function() {
|
|
34
35
|
var _ref = _async_to_generator(function(appDirectory, config, compileOptions) {
|
|
35
|
-
var sourceDirs, distDir, tsconfigPath, results;
|
|
36
|
+
var sourceDirs, distDir, tsconfigPath, moduleType, isEsm, results;
|
|
36
37
|
return _ts_generator(this, function(_state) {
|
|
37
38
|
switch (_state.label) {
|
|
38
39
|
case 0:
|
|
39
|
-
sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath;
|
|
40
|
+
sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath, moduleType = compileOptions.moduleType;
|
|
41
|
+
isEsm = moduleType === "module";
|
|
40
42
|
return [
|
|
41
43
|
4,
|
|
42
44
|
Promise.all(sourceDirs.map(function() {
|
|
@@ -47,7 +49,7 @@ var compileByBabel = function() {
|
|
|
47
49
|
case 0:
|
|
48
50
|
babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
49
51
|
tsconfigPath: tsconfigPath ? tsconfigPath : ""
|
|
50
|
-
});
|
|
52
|
+
}, isEsm);
|
|
51
53
|
return [
|
|
52
54
|
4,
|
|
53
55
|
fs.pathExists(sourceDir)
|
|
@@ -2,8 +2,8 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
6
5
|
import { getUserAlias } from "@modern-js/utils";
|
|
6
|
+
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
7
7
|
var resolvePath = require("@modern-js/babel-plugin-module-resolver").resolvePath;
|
|
8
8
|
var defaultPaths = {
|
|
9
9
|
"@": [
|
|
@@ -2,10 +2,11 @@ import { getBabelConfigForNode } from "@modern-js/babel-preset/node";
|
|
|
2
2
|
import { aliasPlugin } from "./alias";
|
|
3
3
|
var getBabelConfig = function(libPresetOption) {
|
|
4
4
|
var _config_presets, _config_plugins;
|
|
5
|
+
var isEsm = libPresetOption.isEsm;
|
|
5
6
|
var config = getBabelConfigForNode({
|
|
6
7
|
presetEnv: {
|
|
7
8
|
loose: true,
|
|
8
|
-
modules: "commonjs",
|
|
9
|
+
modules: isEsm ? false : "commonjs",
|
|
9
10
|
targets: [
|
|
10
11
|
"node >= 14"
|
|
11
12
|
]
|
|
@@ -3,9 +3,9 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import {
|
|
7
|
-
import { TypescriptLoader } from "./typescriptLoader";
|
|
6
|
+
import { fs, getAliasConfig, logger } from "@modern-js/utils";
|
|
8
7
|
import { tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin";
|
|
8
|
+
import { TypescriptLoader } from "./typescriptLoader";
|
|
9
9
|
var readTsConfigByFile = function(tsConfigFile, tsInstance) {
|
|
10
10
|
var parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
|
|
11
11
|
var options = parsedCmd.options, fileNames = parsedCmd.fileNames, projectReferences = parsedCmd.projectReferences;
|
|
@@ -3,8 +3,8 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import * as os from "os";
|
|
5
5
|
import path, { dirname, posix } from "path";
|
|
6
|
-
import * as ts from "typescript";
|
|
7
6
|
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
7
|
+
import * as ts from "typescript";
|
|
8
8
|
var isRegExpKey = function(str) {
|
|
9
9
|
return str.startsWith("^") || str.endsWith("$");
|
|
10
10
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import { fs, json5, getAliasConfig } from "@modern-js/utils";
|
|
3
2
|
import { compiler } from "@modern-js/babel-compiler";
|
|
3
|
+
import { fs, getAliasConfig, json5 } from "@modern-js/utils";
|
|
4
4
|
import { FILE_EXTENSIONS } from "../../common";
|
|
5
|
-
import {
|
|
5
|
+
import { applyUserBabelConfig, getBabelConfig } from "./preset";
|
|
6
6
|
export * from "@babel/core";
|
|
7
7
|
const readTsConfig = (tsconfigPath, noExistReturn = null) => {
|
|
8
8
|
if (!fs.existsSync(tsconfigPath)) {
|
|
@@ -15,7 +15,7 @@ const existTsConfigFile = (tsconfigAbsolutePath) => {
|
|
|
15
15
|
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
16
16
|
return Boolean(tsconfig);
|
|
17
17
|
};
|
|
18
|
-
const resolveBabelConfig = (appDirectory, config, option) => {
|
|
18
|
+
const resolveBabelConfig = (appDirectory, config, option, isEsm) => {
|
|
19
19
|
const { alias, babelConfig } = config;
|
|
20
20
|
const aliasConfig = getAliasConfig(alias, {
|
|
21
21
|
appDirectory,
|
|
@@ -23,16 +23,18 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
23
23
|
});
|
|
24
24
|
const defaultBabelConfig = getBabelConfig({
|
|
25
25
|
appDirectory,
|
|
26
|
-
alias: aliasConfig
|
|
26
|
+
alias: aliasConfig,
|
|
27
|
+
isEsm
|
|
27
28
|
});
|
|
28
29
|
return applyUserBabelConfig(defaultBabelConfig, babelConfig);
|
|
29
30
|
};
|
|
30
31
|
const compileByBabel = async (appDirectory, config, compileOptions) => {
|
|
31
|
-
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
32
|
+
const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
|
|
33
|
+
const isEsm = moduleType === "module";
|
|
32
34
|
const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
|
|
33
35
|
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
34
36
|
tsconfigPath: tsconfigPath ? tsconfigPath : ""
|
|
35
|
-
});
|
|
37
|
+
}, isEsm);
|
|
36
38
|
if (await fs.pathExists(sourceDir)) {
|
|
37
39
|
const basename = path.basename(sourceDir);
|
|
38
40
|
const targetDir = path.join(distDir, basename);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
3
2
|
import { getUserAlias } from "@modern-js/utils";
|
|
3
|
+
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
4
4
|
const { resolvePath } = require("@modern-js/babel-plugin-module-resolver");
|
|
5
5
|
const defaultPaths = {
|
|
6
6
|
"@": [
|
|
@@ -2,10 +2,11 @@ import { getBabelConfigForNode } from "@modern-js/babel-preset/node";
|
|
|
2
2
|
import { aliasPlugin } from "./alias";
|
|
3
3
|
const getBabelConfig = (libPresetOption) => {
|
|
4
4
|
var _config_presets, _config_plugins;
|
|
5
|
+
const { isEsm } = libPresetOption;
|
|
5
6
|
const config = getBabelConfigForNode({
|
|
6
7
|
presetEnv: {
|
|
7
8
|
loose: true,
|
|
8
|
-
modules: "commonjs",
|
|
9
|
+
modules: isEsm ? false : "commonjs",
|
|
9
10
|
targets: [
|
|
10
11
|
"node >= 14"
|
|
11
12
|
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
import { TypescriptLoader } from "./typescriptLoader";
|
|
2
|
+
import { fs, getAliasConfig, logger } from "@modern-js/utils";
|
|
4
3
|
import { tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin";
|
|
4
|
+
import { TypescriptLoader } from "./typescriptLoader";
|
|
5
5
|
const readTsConfigByFile = (tsConfigFile, tsInstance) => {
|
|
6
6
|
const parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
|
|
7
7
|
const { options, fileNames, projectReferences } = parsedCmd;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as os from "os";
|
|
2
2
|
import path, { dirname, posix } from "path";
|
|
3
|
-
import * as ts from "typescript";
|
|
4
3
|
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
4
|
+
import * as ts from "typescript";
|
|
5
5
|
const isRegExpKey = (str) => {
|
|
6
6
|
return str.startsWith("^") || str.endsWith("$");
|
|
7
7
|
};
|
|
@@ -15,6 +15,7 @@ export interface CompileOptions {
|
|
|
15
15
|
sourceDirs: string[];
|
|
16
16
|
distDir: string;
|
|
17
17
|
tsconfigPath?: string;
|
|
18
|
+
moduleType?: 'module' | 'commonjs';
|
|
18
19
|
}
|
|
19
20
|
export type CompileFunc = (appDirectory: string, modernConfig: IConfig, compileOptions: CompileOptions) => Promise<void>;
|
|
20
21
|
export declare const FILE_EXTENSIONS: string[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompileFunc } from '../../common';
|
|
1
|
+
import { type CompileFunc } from '../../common';
|
|
2
2
|
export * from '@babel/core';
|
|
3
3
|
export interface ITsconfig {
|
|
4
4
|
compilerOptions?: {
|
|
@@ -19,5 +19,5 @@ export declare const existTsConfigFile: (tsconfigAbsolutePath: string) => boolea
|
|
|
19
19
|
export interface IPackageModeValue {
|
|
20
20
|
tsconfigPath: string;
|
|
21
21
|
}
|
|
22
|
-
export declare const resolveBabelConfig: (appDirectory: string, config: Parameters<CompileFunc>[1], option: IPackageModeValue) => any;
|
|
22
|
+
export declare const resolveBabelConfig: (appDirectory: string, config: Parameters<CompileFunc>[1], option: IPackageModeValue, isEsm?: boolean) => any;
|
|
23
23
|
export declare const compileByBabel: CompileFunc;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILibPresetOption } from './types';
|
|
1
|
+
import type { ILibPresetOption } from './types';
|
|
2
2
|
export declare const getBabelConfig: (libPresetOption: ILibPresetOption) => import("@babel/core").TransformOptions;
|
|
3
3
|
export * from './types';
|
|
4
4
|
export { applyUserBabelConfig } from '@modern-js/utils';
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.58.
|
|
18
|
+
"version": "2.58.3",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@babel/preset-typescript": "^7.24.7",
|
|
39
39
|
"@swc/helpers": "0.5.3",
|
|
40
40
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
41
|
-
"@modern-js/babel-compiler": "2.58.
|
|
42
|
-
"@modern-js/babel-
|
|
43
|
-
"@modern-js/babel-
|
|
44
|
-
"@modern-js/utils": "2.58.
|
|
41
|
+
"@modern-js/babel-compiler": "2.58.3",
|
|
42
|
+
"@modern-js/babel-plugin-module-resolver": "2.58.3",
|
|
43
|
+
"@modern-js/babel-preset": "2.58.3",
|
|
44
|
+
"@modern-js/utils": "2.58.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/babel__core": "^7.20.5",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"jest": "^29",
|
|
51
51
|
"ts-jest": "^29.1.0",
|
|
52
52
|
"typescript": "^5",
|
|
53
|
-
"@modern-js/server-core": "2.58.
|
|
54
|
-
"@scripts/build": "2.58.
|
|
55
|
-
"@scripts/jest-config": "2.58.
|
|
53
|
+
"@modern-js/server-core": "2.58.3",
|
|
54
|
+
"@scripts/build": "2.58.3",
|
|
55
|
+
"@scripts/jest-config": "2.58.3"
|
|
56
56
|
},
|
|
57
57
|
"sideEffects": false,
|
|
58
58
|
"publishConfig": {
|