@modern-js/server-utils 2.36.0 → 2.37.1

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.
@@ -58,40 +58,17 @@ const resolveBabelConfig = (appDirectory, config, option) => {
58
58
  appDirectory,
59
59
  ...option
60
60
  });
61
- const babelChain = (0, import_preset.getBabelChain)({
61
+ const defaultBabelConfig = (0, import_preset.getBabelConfig)({
62
62
  appDirectory,
63
- enableReactPreset: true,
64
- enableTypescriptPreset: true,
65
63
  alias: aliasConfig
66
- }, {
67
- type: option.type,
68
- syntax: option.syntax
69
64
  });
70
- const envOptions = babelChain.preset("@babel/preset-env").options();
71
- babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
72
- {
73
- ...envOptions[0],
74
- loose: true
75
- }
76
- ]);
77
- babelChain.plugin("babel-plugin-transform-typescript-metadata").use(require.resolve("babel-plugin-transform-typescript-metadata"), []);
78
- babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
79
- {
80
- legacy: true
81
- }
82
- ]);
83
- const internalBabelConfig = {
84
- ...babelChain.toJSON()
85
- };
86
- return (0, import_preset.applyUserBabelConfig)(internalBabelConfig, babelConfig);
65
+ return (0, import_preset.applyUserBabelConfig)(defaultBabelConfig, babelConfig);
87
66
  };
88
67
  const compileByBabel = async (appDirectory, config, compileOptions) => {
89
68
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
90
69
  const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
91
70
  const babelConfig = resolveBabelConfig(appDirectory, config, {
92
- tsconfigPath: tsconfigPath ? tsconfigPath : "",
93
- syntax: "es6+",
94
- type: "commonjs"
71
+ tsconfigPath: tsconfigPath ? tsconfigPath : ""
95
72
  });
96
73
  if (await import_utils.fs.pathExists(sourceDir)) {
97
74
  const basename = path.basename(sourceDir);
@@ -95,7 +95,7 @@ const aliasPlugin = (alias) => {
95
95
  ".mjs"
96
96
  ];
97
97
  return [
98
- "@modern-js/babel-plugin-module-resolver",
98
+ require.resolve("@modern-js/babel-plugin-module-resolver"),
99
99
  {
100
100
  root: absoluteBaseUrl,
101
101
  alias: mergedPaths,
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -16,53 +18,52 @@ var __copyProps = (to, from, except, desc) => {
16
18
  return to;
17
19
  };
18
20
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var preset_exports = {};
21
31
  __export(preset_exports, {
22
32
  applyUserBabelConfig: () => import_utils.applyUserBabelConfig,
23
- getBabelChain: () => getBabelChain
33
+ getBabelConfig: () => getBabelConfig
24
34
  });
25
35
  module.exports = __toCommonJS(preset_exports);
26
- var import_babel_preset_base = require("@modern-js/babel-preset-base");
36
+ var import_node = require("@rsbuild/babel-preset/node");
27
37
  var import_alias = require("./alias");
28
38
  __reExport(preset_exports, require("./types"), module.exports);
29
39
  var import_utils = require("@modern-js/utils");
30
- const getBabelChain = (libPresetOption, syntaxOption) => {
31
- const { appDirectory, jsxTransformRuntime, enableReactPreset, enableTypescriptPreset, styledComponentsOptions } = libPresetOption;
32
- const { syntax, type } = syntaxOption;
33
- const chain = (0, import_babel_preset_base.getBaseBabelChain)({
34
- appDirectory,
35
- type,
36
- syntax,
37
- presets: {
38
- envOptions: true,
39
- reactOptions: enableReactPreset,
40
- typescriptOptions: enableTypescriptPreset ? {
41
- allowDeclareFields: true,
42
- allExtensions: true
43
- } : false
40
+ const getBabelConfig = (libPresetOption) => {
41
+ var _config_presets, _config_plugins;
42
+ const config = (0, import_node.getBabelConfigForNode)({
43
+ presetEnv: {
44
+ loose: true,
45
+ modules: "commonjs"
44
46
  },
45
- plugins: {
46
- transformRuntime: {
47
- corejs: false,
48
- // for es5 code need helper functions
49
- helpers: syntaxOption.syntax === "es5"
50
- },
51
- styledComponentsOptions
52
- },
53
- jsxTransformRuntime
47
+ pluginDecorators: {
48
+ version: "legacy"
49
+ }
54
50
  });
51
+ (_config_presets = config.presets) === null || _config_presets === void 0 ? void 0 : _config_presets.push([
52
+ require.resolve("@babel/preset-react"),
53
+ {
54
+ runtime: "automatic"
55
+ }
56
+ ]);
55
57
  if (libPresetOption.alias) {
56
- const [name, opt] = (0, import_alias.aliasPlugin)(libPresetOption.alias);
57
- chain.plugin(name).use(require.resolve(name), [
58
- opt
59
- ]);
58
+ var _config_plugins1;
59
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push((0, import_alias.aliasPlugin)(libPresetOption.alias));
60
60
  }
61
- return chain;
61
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(require.resolve("babel-plugin-transform-typescript-metadata"));
62
+ return config;
62
63
  };
63
64
  // Annotate the CommonJS export names for ESM import in node:
64
65
  0 && (module.exports = {
65
66
  applyUserBabelConfig,
66
- getBabelChain,
67
+ getBabelConfig,
67
68
  ...require("./types")
68
69
  });
@@ -1,12 +1,11 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
4
  import * as path from "path";
6
5
  import { fs, json5, getAliasConfig } from "@modern-js/utils";
7
6
  import { compiler } from "@modern-js/babel-compiler";
8
7
  import { FILE_EXTENSIONS } from "../../common";
9
- import { getBabelChain, applyUserBabelConfig } from "./preset";
8
+ import { getBabelConfig, applyUserBabelConfig } from "./preset";
10
9
  export * from "@babel/core";
11
10
  var readTsConfig = function(tsconfigPath) {
12
11
  var noExistReturn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
@@ -25,29 +24,11 @@ var resolveBabelConfig = function(appDirectory, config, option) {
25
24
  var aliasConfig = getAliasConfig(alias, _object_spread({
26
25
  appDirectory
27
26
  }, option));
28
- var babelChain = getBabelChain({
27
+ var defaultBabelConfig = getBabelConfig({
29
28
  appDirectory,
30
- enableReactPreset: true,
31
- enableTypescriptPreset: true,
32
29
  alias: aliasConfig
33
- }, {
34
- type: option.type,
35
- syntax: option.syntax
36
30
  });
37
- var envOptions = babelChain.preset("@babel/preset-env").options();
38
- babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
39
- _object_spread_props(_object_spread({}, envOptions[0]), {
40
- loose: true
41
- })
42
- ]);
43
- babelChain.plugin("babel-plugin-transform-typescript-metadata").use(require.resolve("babel-plugin-transform-typescript-metadata"), []);
44
- babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
45
- {
46
- legacy: true
47
- }
48
- ]);
49
- var internalBabelConfig = _object_spread({}, babelChain.toJSON());
50
- return applyUserBabelConfig(internalBabelConfig, babelConfig);
31
+ return applyUserBabelConfig(defaultBabelConfig, babelConfig);
51
32
  };
52
33
  var compileByBabel = function() {
53
34
  var _ref = _async_to_generator(function(appDirectory, config, compileOptions) {
@@ -65,9 +46,7 @@ var compileByBabel = function() {
65
46
  switch (_state2.label) {
66
47
  case 0:
67
48
  babelConfig = resolveBabelConfig(appDirectory, config, {
68
- tsconfigPath: tsconfigPath ? tsconfigPath : "",
69
- syntax: "es6+",
70
- type: "commonjs"
49
+ tsconfigPath: tsconfigPath ? tsconfigPath : ""
71
50
  });
72
51
  return [
73
52
  4,
@@ -56,7 +56,7 @@ var aliasPlugin = function(alias) {
56
56
  ".mjs"
57
57
  ];
58
58
  return [
59
- "@modern-js/babel-plugin-module-resolver",
59
+ require.resolve("@modern-js/babel-plugin-module-resolver"),
60
60
  {
61
61
  root: absoluteBaseUrl,
62
62
  alias: mergedPaths,
@@ -1,42 +1,32 @@
1
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
- import { getBaseBabelChain } from "@modern-js/babel-preset-base";
1
+ import { getBabelConfigForNode } from "@rsbuild/babel-preset/node";
3
2
  import { aliasPlugin } from "./alias";
4
- var getBabelChain = function(libPresetOption, syntaxOption) {
5
- var appDirectory = libPresetOption.appDirectory, jsxTransformRuntime = libPresetOption.jsxTransformRuntime, enableReactPreset = libPresetOption.enableReactPreset, enableTypescriptPreset = libPresetOption.enableTypescriptPreset, styledComponentsOptions = libPresetOption.styledComponentsOptions;
6
- var syntax = syntaxOption.syntax, type = syntaxOption.type;
7
- var chain = getBaseBabelChain({
8
- appDirectory,
9
- type,
10
- syntax,
11
- presets: {
12
- envOptions: true,
13
- reactOptions: enableReactPreset,
14
- typescriptOptions: enableTypescriptPreset ? {
15
- allowDeclareFields: true,
16
- allExtensions: true
17
- } : false
3
+ var getBabelConfig = function(libPresetOption) {
4
+ var _config_presets, _config_plugins;
5
+ var config = getBabelConfigForNode({
6
+ presetEnv: {
7
+ loose: true,
8
+ modules: "commonjs"
18
9
  },
19
- plugins: {
20
- transformRuntime: {
21
- corejs: false,
22
- // for es5 code need helper functions
23
- helpers: syntaxOption.syntax === "es5"
24
- },
25
- styledComponentsOptions
26
- },
27
- jsxTransformRuntime
10
+ pluginDecorators: {
11
+ version: "legacy"
12
+ }
28
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
+ ]);
29
20
  if (libPresetOption.alias) {
30
- var _aliasPlugin = _sliced_to_array(aliasPlugin(libPresetOption.alias), 2), name = _aliasPlugin[0], opt = _aliasPlugin[1];
31
- chain.plugin(name).use(require.resolve(name), [
32
- opt
33
- ]);
21
+ var _config_plugins1;
22
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(aliasPlugin(libPresetOption.alias));
34
23
  }
35
- return chain;
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;
36
26
  };
37
27
  export * from "./types";
38
28
  import { applyUserBabelConfig } from "@modern-js/utils";
39
29
  export {
40
30
  applyUserBabelConfig,
41
- getBabelChain
31
+ getBabelConfig
42
32
  };
@@ -2,7 +2,7 @@ import * as path from "path";
2
2
  import { fs, json5, getAliasConfig } from "@modern-js/utils";
3
3
  import { compiler } from "@modern-js/babel-compiler";
4
4
  import { FILE_EXTENSIONS } from "../../common";
5
- import { getBabelChain, applyUserBabelConfig } from "./preset";
5
+ import { getBabelConfig, applyUserBabelConfig } from "./preset";
6
6
  export * from "@babel/core";
7
7
  const readTsConfig = (tsconfigPath, noExistReturn = null) => {
8
8
  if (!fs.existsSync(tsconfigPath)) {
@@ -21,40 +21,17 @@ const resolveBabelConfig = (appDirectory, config, option) => {
21
21
  appDirectory,
22
22
  ...option
23
23
  });
24
- const babelChain = getBabelChain({
24
+ const defaultBabelConfig = getBabelConfig({
25
25
  appDirectory,
26
- enableReactPreset: true,
27
- enableTypescriptPreset: true,
28
26
  alias: aliasConfig
29
- }, {
30
- type: option.type,
31
- syntax: option.syntax
32
27
  });
33
- const envOptions = babelChain.preset("@babel/preset-env").options();
34
- babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
35
- {
36
- ...envOptions[0],
37
- loose: true
38
- }
39
- ]);
40
- babelChain.plugin("babel-plugin-transform-typescript-metadata").use(require.resolve("babel-plugin-transform-typescript-metadata"), []);
41
- babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
42
- {
43
- legacy: true
44
- }
45
- ]);
46
- const internalBabelConfig = {
47
- ...babelChain.toJSON()
48
- };
49
- return applyUserBabelConfig(internalBabelConfig, babelConfig);
28
+ return applyUserBabelConfig(defaultBabelConfig, babelConfig);
50
29
  };
51
30
  const compileByBabel = async (appDirectory, config, compileOptions) => {
52
31
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
53
32
  const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
54
33
  const babelConfig = resolveBabelConfig(appDirectory, config, {
55
- tsconfigPath: tsconfigPath ? tsconfigPath : "",
56
- syntax: "es6+",
57
- type: "commonjs"
34
+ tsconfigPath: tsconfigPath ? tsconfigPath : ""
58
35
  });
59
36
  if (await fs.pathExists(sourceDir)) {
60
37
  const basename = path.basename(sourceDir);
@@ -62,7 +62,7 @@ const aliasPlugin = (alias) => {
62
62
  ".mjs"
63
63
  ];
64
64
  return [
65
- "@modern-js/babel-plugin-module-resolver",
65
+ require.resolve("@modern-js/babel-plugin-module-resolver"),
66
66
  {
67
67
  root: absoluteBaseUrl,
68
68
  alias: mergedPaths,
@@ -1,41 +1,32 @@
1
- import { getBaseBabelChain } from "@modern-js/babel-preset-base";
1
+ import { getBabelConfigForNode } from "@rsbuild/babel-preset/node";
2
2
  import { aliasPlugin } from "./alias";
3
- const getBabelChain = (libPresetOption, syntaxOption) => {
4
- const { appDirectory, jsxTransformRuntime, enableReactPreset, enableTypescriptPreset, styledComponentsOptions } = libPresetOption;
5
- const { syntax, type } = syntaxOption;
6
- const chain = getBaseBabelChain({
7
- appDirectory,
8
- type,
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
- plugins: {
19
- transformRuntime: {
20
- corejs: false,
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
- const [name, opt] = aliasPlugin(libPresetOption.alias);
30
- chain.plugin(name).use(require.resolve(name), [
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
- return chain;
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";
38
29
  export {
39
30
  applyUserBabelConfig,
40
- getBabelChain
31
+ getBabelConfig
41
32
  };
@@ -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 { ISyntaxOption, ILibPresetOption } from './types';
2
- export declare const getBabelChain: (libPresetOption: ILibPresetOption, syntaxOption: ISyntaxOption) => import("@modern-js/babel-preset-base").BabelChain;
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.36.0",
18
+ "version": "2.37.1",
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-plugin-transform-typescript-metadata": "^0.3.2",
39
+ "@rsbuild/babel-preset": "0.0.7",
39
40
  "@swc/helpers": "0.5.1",
40
- "@modern-js/babel-compiler": "2.36.0",
41
- "@modern-js/babel-preset-base": "2.36.0",
42
- "@modern-js/utils": "2.36.0",
43
- "@modern-js/babel-plugin-module-resolver": "2.36.0"
41
+ "babel-plugin-transform-typescript-metadata": "^0.3.2",
42
+ "@modern-js/babel-compiler": "2.37.1",
43
+ "@modern-js/utils": "2.37.1",
44
+ "@modern-js/babel-plugin-module-resolver": "2.37.1"
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
- "@modern-js/server-core": "2.36.0",
53
- "@scripts/build": "2.36.0",
54
- "@scripts/jest-config": "2.36.0"
53
+ "@modern-js/server-core": "2.37.1",
54
+ "@scripts/build": "2.37.1",
55
+ "@scripts/jest-config": "2.37.1"
55
56
  },
56
57
  "sideEffects": false,
57
58
  "publishConfig": {