@modern-js/server-utils 1.20.1 → 1.21.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @modern-js/server-utils
2
2
 
3
+ ## 1.21.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 8f3674a: fix: reduce compile parameters for dev-server
8
+ fix: 减少 dev-server 编译所需参数
9
+ - Updated dependencies [28f0a4f]
10
+ - @modern-js/plugin@1.21.0
11
+ - @modern-js/utils@1.21.0
12
+ - @modern-js/babel-preset-lib@1.21.0
13
+ - @modern-js/babel-compiler@1.21.0
14
+
3
15
  ## 1.20.1
4
16
 
5
17
  ### Patch Changes
@@ -6,7 +6,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import * as path from 'path';
8
8
  import { getBabelChain, applyUserBabelConfig } from '@modern-js/babel-preset-lib';
9
- import { fs, json5, getAlias, applyOptionsChain } from '@modern-js/utils';
9
+ import { fs, json5, getAlias } from '@modern-js/utils';
10
10
  import { compiler } from '@modern-js/babel-compiler';
11
11
  import { FILE_EXTENSIONS } from "../../common";
12
12
  export * from '@babel/core';
@@ -29,29 +29,18 @@ export const getBabelConfig = (libPresetOption, syntaxOption) => {
29
29
  sourceType: 'unambiguous'
30
30
  }, chain.toJSON());
31
31
  };
32
- export const resolveBabelConfig = (appDirectory, modernConfig, option // FIXME: babel type can't pass type checking
32
+ export const resolveBabelConfig = (appDirectory, config, option // FIXME: babel type can't pass type checking
33
33
  ) => {
34
34
  const {
35
- source: {
36
- envVars,
37
- globalVars,
38
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
- // @ts-expect-error
40
- jsxTransformRuntime = 'automatic'
41
- },
42
- tools: {
43
- lodash: userLodashOption
44
- }
45
- } = modernConfig; // alias config
35
+ envVars,
36
+ globalVars,
37
+ alias,
38
+ babelConfig
39
+ } = config; // alias config
46
40
 
47
- const aliasConfig = getAlias(modernConfig.source.alias, _objectSpread({
41
+ const aliasConfig = getAlias(alias, _objectSpread({
48
42
  appDirectory
49
- }, option)); // lodash config
50
-
51
- const lodashOptions = applyOptionsChain({
52
- id: ['lodash', 'ramda']
53
- }, // TODO: 需要处理类型问题
54
- userLodashOption); // babel config
43
+ }, option)); // babel config
55
44
 
56
45
  const babelChain = getBabelChain({
57
46
  appDirectory,
@@ -59,9 +48,7 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option // FIXME:
59
48
  enableTypescriptPreset: true,
60
49
  alias: aliasConfig,
61
50
  envVars,
62
- globalVars,
63
- lodashOptions,
64
- jsxTransformRuntime
51
+ globalVars
65
52
  }, {
66
53
  type: option.type,
67
54
  syntax: option.syntax
@@ -81,17 +68,16 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option // FIXME:
81
68
 
82
69
  const internalBabelConfig = _objectSpread({}, babelChain.toJSON());
83
70
 
84
- const userBabelConfig = modernConfig.tools.babel;
85
- return applyUserBabelConfig(internalBabelConfig, userBabelConfig);
71
+ return applyUserBabelConfig(internalBabelConfig, babelConfig);
86
72
  };
87
- export const compileByBabel = async (appDirectory, modernConfig, compileOptions) => {
73
+ export const compileByBabel = async (appDirectory, config, compileOptions) => {
88
74
  const {
89
75
  sourceDirs,
90
76
  distDir,
91
77
  tsconfigPath
92
78
  } = compileOptions;
93
79
  const results = await Promise.all(sourceDirs.map(async sourceDir => {
94
- const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
80
+ const babelConfig = resolveBabelConfig(appDirectory, config, {
95
81
  tsconfigPath: tsconfigPath ? tsconfigPath : '',
96
82
  syntax: 'es6+',
97
83
  type: 'commonjs'
@@ -34,7 +34,7 @@ const copyFiles = async (from, to, tsconfigPath) => {
34
34
  }
35
35
  };
36
36
 
37
- export const compileByTs = async (appDirectory, modernConfig, compileOptions) => {
37
+ export const compileByTs = async (appDirectory, config, compileOptions) => {
38
38
  logger.info(`Running ts compile...`);
39
39
  const {
40
40
  sourceDirs,
@@ -53,7 +53,7 @@ export const compileByTs = async (appDirectory, modernConfig, compileOptions) =>
53
53
  const formatHost = getFormatHost(ts);
54
54
  const {
55
55
  alias
56
- } = modernConfig.source;
56
+ } = config;
57
57
  const aliasOption = getAlias(alias || {}, {
58
58
  appDirectory,
59
59
  tsconfigPath
@@ -96,6 +96,8 @@ export const compileByTs = async (appDirectory, modernConfig, compileOptions) =>
96
96
  for (const source of sourceDirs) {
97
97
  await copyFiles(source, distDir, tsconfigPath);
98
98
  }
99
+
100
+ logger.info(`Ts compile succeed`);
99
101
  };
100
102
 
101
103
  const getFormatHost = ts => {
@@ -75,29 +75,18 @@ const getBabelConfig = (libPresetOption, syntaxOption) => {
75
75
 
76
76
  exports.getBabelConfig = getBabelConfig;
77
77
 
78
- const resolveBabelConfig = (appDirectory, modernConfig, option // FIXME: babel type can't pass type checking
78
+ const resolveBabelConfig = (appDirectory, config, option // FIXME: babel type can't pass type checking
79
79
  ) => {
80
80
  const {
81
- source: {
82
- envVars,
83
- globalVars,
84
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
85
- // @ts-expect-error
86
- jsxTransformRuntime = 'automatic'
87
- },
88
- tools: {
89
- lodash: userLodashOption
90
- }
91
- } = modernConfig; // alias config
81
+ envVars,
82
+ globalVars,
83
+ alias,
84
+ babelConfig
85
+ } = config; // alias config
92
86
 
93
- const aliasConfig = (0, _utils.getAlias)(modernConfig.source.alias, _objectSpread({
87
+ const aliasConfig = (0, _utils.getAlias)(alias, _objectSpread({
94
88
  appDirectory
95
- }, option)); // lodash config
96
-
97
- const lodashOptions = (0, _utils.applyOptionsChain)({
98
- id: ['lodash', 'ramda']
99
- }, // TODO: 需要处理类型问题
100
- userLodashOption); // babel config
89
+ }, option)); // babel config
101
90
 
102
91
  const babelChain = (0, _babelPresetLib.getBabelChain)({
103
92
  appDirectory,
@@ -105,9 +94,7 @@ const resolveBabelConfig = (appDirectory, modernConfig, option // FIXME: babel t
105
94
  enableTypescriptPreset: true,
106
95
  alias: aliasConfig,
107
96
  envVars,
108
- globalVars,
109
- lodashOptions,
110
- jsxTransformRuntime
97
+ globalVars
111
98
  }, {
112
99
  type: option.type,
113
100
  syntax: option.syntax
@@ -127,20 +114,19 @@ const resolveBabelConfig = (appDirectory, modernConfig, option // FIXME: babel t
127
114
 
128
115
  const internalBabelConfig = _objectSpread({}, babelChain.toJSON());
129
116
 
130
- const userBabelConfig = modernConfig.tools.babel;
131
- return (0, _babelPresetLib.applyUserBabelConfig)(internalBabelConfig, userBabelConfig);
117
+ return (0, _babelPresetLib.applyUserBabelConfig)(internalBabelConfig, babelConfig);
132
118
  };
133
119
 
134
120
  exports.resolveBabelConfig = resolveBabelConfig;
135
121
 
136
- const compileByBabel = async (appDirectory, modernConfig, compileOptions) => {
122
+ const compileByBabel = async (appDirectory, config, compileOptions) => {
137
123
  const {
138
124
  sourceDirs,
139
125
  distDir,
140
126
  tsconfigPath
141
127
  } = compileOptions;
142
128
  const results = await Promise.all(sourceDirs.map(async sourceDir => {
143
- const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
129
+ const babelConfig = resolveBabelConfig(appDirectory, config, {
144
130
  tsconfigPath: tsconfigPath ? tsconfigPath : '',
145
131
  syntax: 'es6+',
146
132
  type: 'commonjs'
@@ -50,7 +50,7 @@ const copyFiles = async (from, to, tsconfigPath) => {
50
50
  }
51
51
  };
52
52
 
53
- const compileByTs = async (appDirectory, modernConfig, compileOptions) => {
53
+ const compileByTs = async (appDirectory, config, compileOptions) => {
54
54
  _utils.logger.info(`Running ts compile...`);
55
55
 
56
56
  const {
@@ -70,7 +70,7 @@ const compileByTs = async (appDirectory, modernConfig, compileOptions) => {
70
70
  const formatHost = getFormatHost(ts);
71
71
  const {
72
72
  alias
73
- } = modernConfig.source;
73
+ } = config;
74
74
  const aliasOption = (0, _utils.getAlias)(alias || {}, {
75
75
  appDirectory,
76
76
  tsconfigPath
@@ -114,6 +114,8 @@ const compileByTs = async (appDirectory, modernConfig, compileOptions) => {
114
114
  for (const source of sourceDirs) {
115
115
  await copyFiles(source, distDir, tsconfigPath);
116
116
  }
117
+
118
+ _utils.logger.info(`Ts compile succeed`);
117
119
  };
118
120
 
119
121
  exports.compileByTs = compileByTs;
@@ -3,7 +3,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import * as path from 'path';
5
5
  import { getBabelChain, applyUserBabelConfig } from '@modern-js/babel-preset-lib';
6
- import { fs, json5, getAlias, applyOptionsChain } from '@modern-js/utils';
6
+ import { fs, json5, getAlias } from '@modern-js/utils';
7
7
  import { compiler } from '@modern-js/babel-compiler';
8
8
  import { FILE_EXTENSIONS } from "../../common";
9
9
  export * from '@babel/core';
@@ -28,23 +28,16 @@ export var getBabelConfig = function getBabelConfig(libPresetOption, syntaxOptio
28
28
  sourceType: 'unambiguous'
29
29
  }, chain.toJSON());
30
30
  };
31
- export var resolveBabelConfig = function resolveBabelConfig(appDirectory, modernConfig, option // FIXME: babel type can't pass type checking
31
+ export var resolveBabelConfig = function resolveBabelConfig(appDirectory, config, option // FIXME: babel type can't pass type checking
32
32
  ) {
33
- var _modernConfig$source = modernConfig.source,
34
- envVars = _modernConfig$source.envVars,
35
- globalVars = _modernConfig$source.globalVars,
36
- _modernConfig$source$ = _modernConfig$source.jsxTransformRuntime,
37
- jsxTransformRuntime = _modernConfig$source$ === void 0 ? 'automatic' : _modernConfig$source$,
38
- userLodashOption = modernConfig.tools.lodash; // alias config
33
+ var envVars = config.envVars,
34
+ globalVars = config.globalVars,
35
+ alias = config.alias,
36
+ babelConfig = config.babelConfig; // alias config
39
37
 
40
- var aliasConfig = getAlias(modernConfig.source.alias, _objectSpread({
38
+ var aliasConfig = getAlias(alias, _objectSpread({
41
39
  appDirectory: appDirectory
42
- }, option)); // lodash config
43
-
44
- var lodashOptions = applyOptionsChain({
45
- id: ['lodash', 'ramda']
46
- }, // TODO: 需要处理类型问题
47
- userLodashOption); // babel config
40
+ }, option)); // babel config
48
41
 
49
42
  var babelChain = getBabelChain({
50
43
  appDirectory: appDirectory,
@@ -52,9 +45,7 @@ export var resolveBabelConfig = function resolveBabelConfig(appDirectory, modern
52
45
  enableTypescriptPreset: true,
53
46
  alias: aliasConfig,
54
47
  envVars: envVars,
55
- globalVars: globalVars,
56
- lodashOptions: lodashOptions,
57
- jsxTransformRuntime: jsxTransformRuntime
48
+ globalVars: globalVars
58
49
  }, {
59
50
  type: option.type,
60
51
  syntax: option.syntax
@@ -74,11 +65,10 @@ export var resolveBabelConfig = function resolveBabelConfig(appDirectory, modern
74
65
 
75
66
  var internalBabelConfig = _objectSpread({}, babelChain.toJSON());
76
67
 
77
- var userBabelConfig = modernConfig.tools.babel;
78
- return applyUserBabelConfig(internalBabelConfig, userBabelConfig);
68
+ return applyUserBabelConfig(internalBabelConfig, babelConfig);
79
69
  };
80
70
  export var compileByBabel = /*#__PURE__*/function () {
81
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(appDirectory, modernConfig, compileOptions) {
71
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(appDirectory, config, compileOptions) {
82
72
  var sourceDirs, distDir, tsconfigPath, results;
83
73
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
84
74
  while (1) {
@@ -93,7 +83,7 @@ export var compileByBabel = /*#__PURE__*/function () {
93
83
  while (1) {
94
84
  switch (_context.prev = _context.next) {
95
85
  case 0:
96
- babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
86
+ babelConfig = resolveBabelConfig(appDirectory, config, {
97
87
  tsconfigPath: tsconfigPath ? tsconfigPath : '',
98
88
  syntax: 'es6+',
99
89
  type: 'commonjs'
@@ -60,7 +60,7 @@ var copyFiles = /*#__PURE__*/function () {
60
60
  }();
61
61
 
62
62
  export var compileByTs = /*#__PURE__*/function () {
63
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(appDirectory, modernConfig, compileOptions) {
63
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(appDirectory, config, compileOptions) {
64
64
  var sourceDirs, distDir, tsconfigPath, ts, createProgram, formatHost, alias, aliasOption, _aliasOption$paths, paths, _aliasOption$absolute, absoluteBaseUrl, _readTsConfigByFile, options, fileNames, projectReferences, sourcePosixPaths, rootNames, program, tsconfigPathsPlugin, emitResult, allDiagnostics, _iterator, _step, source;
65
65
 
66
66
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -83,7 +83,7 @@ export var compileByTs = /*#__PURE__*/function () {
83
83
  }).load();
84
84
  createProgram = ts.createIncrementalProgram || ts.createProgram;
85
85
  formatHost = getFormatHost(ts);
86
- alias = modernConfig.source.alias;
86
+ alias = config.alias;
87
87
  aliasOption = getAlias(alias || {}, {
88
88
  appDirectory: appDirectory,
89
89
  tsconfigPath: tsconfigPath
@@ -155,6 +155,9 @@ export var compileByTs = /*#__PURE__*/function () {
155
155
  return _context2.finish(32);
156
156
 
157
157
  case 35:
158
+ logger.info("Ts compile succeed");
159
+
160
+ case 36:
158
161
  case "end":
159
162
  return _context2.stop();
160
163
  }
@@ -4,11 +4,20 @@ export interface Pattern {
4
4
  to: string;
5
5
  tsconfigPath?: string;
6
6
  }
7
+ export interface IConfig {
8
+ alias?: NormalizedConfig['source']['alias'];
9
+ envVars?: NormalizedConfig['source']['envVars'];
10
+ globalVars?: NormalizedConfig['source']['globalVars'];
11
+ babelConfig?: NormalizedConfig['tools']['babel'];
12
+ server: {
13
+ compiler?: 'babel' | 'typescript';
14
+ };
15
+ }
7
16
  export interface CompileOptions {
8
17
  sourceDirs: string[];
9
18
  distDir: string;
10
19
  tsconfigPath?: string;
11
20
  }
12
- export declare type CompileFunc = (appDirectory: string, modernConfig: NormalizedConfig, compileOptions: CompileOptions) => Promise<void>;
21
+ export declare type CompileFunc = (appDirectory: string, modernConfig: IConfig, compileOptions: CompileOptions) => Promise<void>;
13
22
  export declare const FILE_EXTENSIONS: string[];
14
23
  export declare const compile: CompileFunc;
@@ -1,6 +1,5 @@
1
1
  import { ILibPresetOption, ISyntaxOption } from '@modern-js/babel-preset-lib';
2
2
  import { TransformOptions } from '@babel/core';
3
- import type { NormalizedConfig } from '@modern-js/core';
4
3
  import { CompileFunc } from '../../common';
5
4
  export * from '@babel/core';
6
5
  export interface ITsconfig {
@@ -25,5 +24,5 @@ export interface IPackageModeValue {
25
24
  syntax: 'es5' | 'es6+';
26
25
  tsconfigPath: string;
27
26
  }
28
- export declare const resolveBabelConfig: (appDirectory: string, modernConfig: NormalizedConfig, option: IPackageModeValue) => any;
27
+ export declare const resolveBabelConfig: (appDirectory: string, config: Parameters<CompileFunc>[1], option: IPackageModeValue) => any;
29
28
  export declare const compileByBabel: CompileFunc;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.20.1",
14
+ "version": "1.21.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -35,18 +35,18 @@
35
35
  "@babel/preset-env": "^7.18.0",
36
36
  "@babel/preset-typescript": "^7.17.12",
37
37
  "@babel/runtime": "^7.18.0",
38
- "@modern-js/babel-compiler": "^1.20.1",
39
- "@modern-js/babel-preset-lib": "1.20.1",
40
- "@modern-js/plugin": "1.20.1",
41
- "@modern-js/utils": "1.20.1",
38
+ "@modern-js/babel-compiler": "^1.21.0",
39
+ "@modern-js/babel-preset-lib": "1.21.0",
40
+ "@modern-js/plugin": "1.21.0",
41
+ "@modern-js/utils": "1.21.0",
42
42
  "babel-plugin-module-resolver": "^4.1.0",
43
43
  "babel-plugin-transform-typescript-metadata": "^0.3.2",
44
44
  "tsconfig-paths": "3.14.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@modern-js/core": "1.20.1",
48
- "@scripts/build": "1.20.1",
49
- "@scripts/jest-config": "1.20.1",
47
+ "@modern-js/core": "1.21.0",
48
+ "@scripts/build": "1.21.0",
49
+ "@scripts/jest-config": "1.21.0",
50
50
  "@types/babel__core": "^7.1.15",
51
51
  "@types/jest": "^27",
52
52
  "@types/node": "^14",