@modern-js/server-utils 2.35.1 → 2.37.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.
- package/dist/cjs/common/index.js +41 -22
- package/dist/cjs/compilers/babel/index.js +61 -66
- package/dist/cjs/compilers/babel/preset/alias.js +43 -17
- package/dist/cjs/compilers/babel/preset/index.js +60 -48
- package/dist/cjs/compilers/babel/preset/types.js +15 -3
- package/dist/cjs/compilers/typescript/index.js +51 -25
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +44 -18
- package/dist/cjs/compilers/typescript/typescriptLoader.js +27 -10
- package/dist/cjs/index.js +28 -10
- package/dist/esm/common/index.js +6 -2
- package/dist/esm/compilers/babel/index.js +18 -33
- package/dist/esm/compilers/babel/preset/alias.js +5 -2
- package/dist/esm/compilers/babel/preset/index.js +25 -31
- package/dist/esm/compilers/babel/preset/types.js +0 -1
- package/dist/esm/compilers/typescript/index.js +12 -9
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +4 -1
- package/dist/esm/compilers/typescript/typescriptLoader.js +4 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm-node/common/index.js +6 -2
- package/dist/esm-node/compilers/babel/index.js +14 -31
- package/dist/esm-node/compilers/babel/preset/alias.js +5 -2
- package/dist/esm-node/compilers/babel/preset/index.js +25 -30
- package/dist/esm-node/compilers/babel/preset/types.js +0 -1
- package/dist/esm-node/compilers/typescript/index.js +4 -1
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +4 -1
- package/dist/esm-node/compilers/typescript/typescriptLoader.js +4 -1
- package/dist/esm-node/index.js +4 -1
- package/dist/types/compilers/babel/index.d.ts +0 -2
- package/dist/types/compilers/babel/preset/index.d.ts +2 -2
- package/dist/types/compilers/babel/preset/types.d.ts +0 -9
- package/package.json +10 -9
|
@@ -1,37 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBabelConfigForNode } from "@rsbuild/babel-preset/node";
|
|
2
2
|
import { aliasPlugin } from "./alias";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
syntax,
|
|
10
|
-
presets: {
|
|
11
|
-
envOptions: true,
|
|
12
|
-
reactOptions: enableReactPreset,
|
|
13
|
-
typescriptOptions: enableTypescriptPreset ? {
|
|
14
|
-
allowDeclareFields: true,
|
|
15
|
-
allExtensions: true
|
|
16
|
-
} : false
|
|
3
|
+
const getBabelConfig = (libPresetOption) => {
|
|
4
|
+
var _config_presets, _config_plugins;
|
|
5
|
+
const config = getBabelConfigForNode({
|
|
6
|
+
presetEnv: {
|
|
7
|
+
loose: true,
|
|
8
|
+
modules: "commonjs"
|
|
17
9
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// for es5 code need helper functions
|
|
22
|
-
helpers: syntaxOption.syntax === "es5"
|
|
23
|
-
},
|
|
24
|
-
styledComponentsOptions
|
|
25
|
-
},
|
|
26
|
-
jsxTransformRuntime
|
|
10
|
+
pluginDecorators: {
|
|
11
|
+
version: "legacy"
|
|
12
|
+
}
|
|
27
13
|
});
|
|
14
|
+
(_config_presets = config.presets) === null || _config_presets === void 0 ? void 0 : _config_presets.push([
|
|
15
|
+
require.resolve("@babel/preset-react"),
|
|
16
|
+
{
|
|
17
|
+
runtime: "automatic"
|
|
18
|
+
}
|
|
19
|
+
]);
|
|
28
20
|
if (libPresetOption.alias) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
opt
|
|
32
|
-
]);
|
|
21
|
+
var _config_plugins1;
|
|
22
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(aliasPlugin(libPresetOption.alias));
|
|
33
23
|
}
|
|
34
|
-
|
|
24
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(require.resolve("babel-plugin-transform-typescript-metadata"));
|
|
25
|
+
return config;
|
|
35
26
|
};
|
|
36
27
|
export * from "./types";
|
|
37
|
-
|
|
28
|
+
import { applyUserBabelConfig } from "@modern-js/utils";
|
|
29
|
+
export {
|
|
30
|
+
applyUserBabelConfig,
|
|
31
|
+
getBabelConfig
|
|
32
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -22,7 +22,7 @@ const copyFiles = async (from, to, appDirectory, tsconfigPath) => {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
const compileByTs = async (appDirectory, config, compileOptions) => {
|
|
26
26
|
logger.info(`Running ts compile...`);
|
|
27
27
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
28
28
|
if (!tsconfigPath) {
|
|
@@ -83,3 +83,6 @@ const getFormatHost = (ts) => {
|
|
|
83
83
|
getNewLine: () => ts.sys.newLine
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
+
export {
|
|
87
|
+
compileByTs
|
|
88
|
+
};
|
|
@@ -51,7 +51,7 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
51
51
|
const isDynamicImport = (tsBinary, node) => {
|
|
52
52
|
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
53
53
|
};
|
|
54
|
-
|
|
54
|
+
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
55
55
|
const tsPaths = {};
|
|
56
56
|
const alias = {};
|
|
57
57
|
Object.keys(paths).forEach((key) => {
|
|
@@ -165,3 +165,6 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
165
165
|
const resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
|
|
166
166
|
return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
|
|
167
167
|
}
|
|
168
|
+
export {
|
|
169
|
+
tsconfigPathsBeforeHookFactory
|
|
170
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
|
|
2
|
+
class TypescriptLoader {
|
|
3
3
|
load() {
|
|
4
4
|
if (this.tsBinary) {
|
|
5
5
|
return this.tsBinary;
|
|
@@ -22,3 +22,6 @@ export class TypescriptLoader {
|
|
|
22
22
|
this.appDirectory = appDirectory;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export {
|
|
26
|
+
TypescriptLoader
|
|
27
|
+
};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -17,8 +17,6 @@ export interface ITsconfig {
|
|
|
17
17
|
export declare const readTsConfig: <T extends ITsconfig | null>(tsconfigPath: string, noExistReturn?: T) => ITsconfig | T;
|
|
18
18
|
export declare const existTsConfigFile: (tsconfigAbsolutePath: string) => boolean;
|
|
19
19
|
export interface IPackageModeValue {
|
|
20
|
-
type: 'module' | 'commonjs';
|
|
21
|
-
syntax: 'es5' | 'es6+';
|
|
22
20
|
tsconfigPath: string;
|
|
23
21
|
}
|
|
24
22
|
export declare const resolveBabelConfig: (appDirectory: string, config: Parameters<CompileFunc>[1], option: IPackageModeValue) => any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { ILibPresetOption } from './types';
|
|
2
|
+
export declare const getBabelConfig: (libPresetOption: ILibPresetOption) => import("@babel/core").TransformOptions;
|
|
3
3
|
export * from './types';
|
|
4
4
|
export { applyUserBabelConfig } from '@modern-js/utils';
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import type { IStyledComponentOptions } from '@modern-js/babel-preset-base';
|
|
2
|
-
export interface ISyntaxOption {
|
|
3
|
-
syntax: 'es5' | 'es6+';
|
|
4
|
-
type: 'module' | 'commonjs';
|
|
5
|
-
}
|
|
6
1
|
export interface AliasOption {
|
|
7
2
|
absoluteBaseUrl: string;
|
|
8
3
|
paths?: Record<string, string | string[]>;
|
|
@@ -11,10 +6,6 @@ export interface AliasOption {
|
|
|
11
6
|
}
|
|
12
7
|
export interface ILibPresetOption {
|
|
13
8
|
appDirectory: string;
|
|
14
|
-
enableTypescriptPreset?: boolean;
|
|
15
|
-
enableReactPreset?: boolean;
|
|
16
9
|
alias?: AliasOption;
|
|
17
|
-
jsxTransformRuntime?: JsxTransformRuntimeType;
|
|
18
|
-
styledComponentsOptions?: IStyledComponentOptions;
|
|
19
10
|
}
|
|
20
11
|
export type JsxTransformRuntimeType = 'automatic' | 'classic';
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.37.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -34,13 +34,14 @@
|
|
|
34
34
|
"@babel/core": "^7.22.15",
|
|
35
35
|
"@babel/plugin-proposal-decorators": "^7.22.15",
|
|
36
36
|
"@babel/preset-env": "^7.22.15",
|
|
37
|
+
"@babel/preset-react": "^7.22.15",
|
|
37
38
|
"@babel/preset-typescript": "^7.22.15",
|
|
38
|
-
"babel-
|
|
39
|
+
"@rsbuild/babel-preset": "0.0.7",
|
|
39
40
|
"@swc/helpers": "0.5.1",
|
|
40
|
-
"
|
|
41
|
-
"@modern-js/babel-
|
|
42
|
-
"@modern-js/utils": "2.
|
|
43
|
-
"@modern-js/babel-plugin-module-resolver": "2.
|
|
41
|
+
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
42
|
+
"@modern-js/babel-compiler": "2.37.0",
|
|
43
|
+
"@modern-js/utils": "2.37.0",
|
|
44
|
+
"@modern-js/babel-plugin-module-resolver": "2.37.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/babel__core": "^7.20.0",
|
|
@@ -49,9 +50,9 @@
|
|
|
49
50
|
"jest": "^29",
|
|
50
51
|
"ts-jest": "^29.1.0",
|
|
51
52
|
"typescript": "^5",
|
|
52
|
-
"@
|
|
53
|
-
"@scripts/
|
|
54
|
-
"@
|
|
53
|
+
"@modern-js/server-core": "2.37.0",
|
|
54
|
+
"@scripts/build": "2.37.0",
|
|
55
|
+
"@scripts/jest-config": "2.37.0"
|
|
55
56
|
},
|
|
56
57
|
"sideEffects": false,
|
|
57
58
|
"publishConfig": {
|