@modern-js/server-utils 1.2.0 → 1.2.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.
- package/CHANGELOG.md +10 -0
- package/package.json +5 -5
- package/src/babel.ts +0 -151
- package/src/index.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @modern-js/server-utils
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 83166714: change .npmignore
|
|
8
|
+
- Updated dependencies [83166714]
|
|
9
|
+
- @modern-js/babel-preset-lib@1.2.1
|
|
10
|
+
- @modern-js/plugin@1.2.1
|
|
11
|
+
- @modern-js/utils@1.2.2
|
|
12
|
+
|
|
3
13
|
## 1.2.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"@babel/preset-env": "^7.15.0",
|
|
36
36
|
"@babel/preset-typescript": "^7.15.0",
|
|
37
37
|
"@babel/runtime": "^7",
|
|
38
|
-
"@modern-js/babel-preset-lib": "^1.2.
|
|
39
|
-
"@modern-js/plugin": "^1.2.
|
|
40
|
-
"@modern-js/utils": "^1.2.
|
|
38
|
+
"@modern-js/babel-preset-lib": "^1.2.1",
|
|
39
|
+
"@modern-js/plugin": "^1.2.1",
|
|
40
|
+
"@modern-js/utils": "^1.2.2",
|
|
41
41
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
42
42
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
43
43
|
"json5": "^2.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@modern-js/core": "^1.3.
|
|
46
|
+
"@modern-js/core": "^1.3.2",
|
|
47
47
|
"@types/babel__core": "^7.1.15",
|
|
48
48
|
"@types/jest": "^26",
|
|
49
49
|
"@types/node": "^14",
|
package/src/babel.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getBabelChain,
|
|
3
|
-
ILibPresetOption,
|
|
4
|
-
ISyntaxOption,
|
|
5
|
-
} from '@modern-js/babel-preset-lib';
|
|
6
|
-
import { TransformOptions } from '@babel/core';
|
|
7
|
-
import { applyOptionsChain, fs, getAlias } from '@modern-js/utils';
|
|
8
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
9
|
-
import json5 from 'json5';
|
|
10
|
-
|
|
11
|
-
export * from '@babel/core';
|
|
12
|
-
|
|
13
|
-
export interface ITsconfig {
|
|
14
|
-
compilerOptions?:
|
|
15
|
-
| {
|
|
16
|
-
rootDir?: string;
|
|
17
|
-
baseUrl?: string;
|
|
18
|
-
declaration?: boolean;
|
|
19
|
-
emitDeclarationOnly?: boolean;
|
|
20
|
-
isolatedModules?: boolean;
|
|
21
|
-
allowJs?: boolean;
|
|
22
|
-
outDir?: string;
|
|
23
|
-
paths?: Record<string, string[]>;
|
|
24
|
-
}
|
|
25
|
-
| undefined;
|
|
26
|
-
include?: string[];
|
|
27
|
-
exclude?: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const readTsConfig = <T extends null | ITsconfig>(
|
|
31
|
-
tsconfigPath: string,
|
|
32
|
-
noExistReturn: T = null as T,
|
|
33
|
-
): ITsconfig | T => {
|
|
34
|
-
// 如果不存在,则返回 noExistReturn
|
|
35
|
-
if (!fs.existsSync(tsconfigPath)) {
|
|
36
|
-
return noExistReturn;
|
|
37
|
-
}
|
|
38
|
-
const content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
39
|
-
return json5.parse(content);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const existTsConfigFile = (tsconfigAbsolutePath: string) => {
|
|
43
|
-
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
44
|
-
return Boolean(tsconfig);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const getBabelConfig = (
|
|
48
|
-
libPresetOption: ILibPresetOption,
|
|
49
|
-
syntaxOption: ISyntaxOption,
|
|
50
|
-
): TransformOptions => {
|
|
51
|
-
const chain = getBabelChain(libPresetOption, syntaxOption);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
sourceType: 'unambiguous',
|
|
55
|
-
...chain.toJSON(),
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export interface IPackageModeValue {
|
|
60
|
-
type: 'module' | 'commonjs';
|
|
61
|
-
syntax: 'es5' | 'es6+';
|
|
62
|
-
tsconfigPath: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const resolveBabelConfig = (
|
|
66
|
-
appDirectory: string,
|
|
67
|
-
modernConfig: NormalizedConfig,
|
|
68
|
-
option: IPackageModeValue,
|
|
69
|
-
// FIXME: babel type can't pass type checking
|
|
70
|
-
): any => {
|
|
71
|
-
const {
|
|
72
|
-
source: {
|
|
73
|
-
envVars,
|
|
74
|
-
globalVars,
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
76
|
-
// @ts-expect-error
|
|
77
|
-
jsxTransformRuntime = 'automatic',
|
|
78
|
-
},
|
|
79
|
-
tools: { lodash: userLodashOption },
|
|
80
|
-
} = modernConfig;
|
|
81
|
-
|
|
82
|
-
// alias config
|
|
83
|
-
const aliasConfig = getAlias(modernConfig.source.alias, {
|
|
84
|
-
appDirectory,
|
|
85
|
-
...option,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// lodash config
|
|
89
|
-
const lodashOptions = applyOptionsChain(
|
|
90
|
-
{ id: ['lodash', 'ramda'] },
|
|
91
|
-
// TODO: 需要处理类型问题
|
|
92
|
-
userLodashOption as any,
|
|
93
|
-
);
|
|
94
|
-
// babel config
|
|
95
|
-
const babelChain = getBabelChain(
|
|
96
|
-
{
|
|
97
|
-
appDirectory,
|
|
98
|
-
enableReactPreset: true,
|
|
99
|
-
enableTypescriptPreset: true,
|
|
100
|
-
alias: aliasConfig,
|
|
101
|
-
envVars,
|
|
102
|
-
globalVars,
|
|
103
|
-
lodashOptions,
|
|
104
|
-
jsxTransformRuntime,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
type: option.type,
|
|
108
|
-
syntax: option.syntax,
|
|
109
|
-
},
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const envOptions = babelChain.preset('@babel/preset-env').options();
|
|
113
|
-
babelChain
|
|
114
|
-
.preset('@babel/preset-env')
|
|
115
|
-
.use(require.resolve('@babel/preset-env'), [
|
|
116
|
-
{
|
|
117
|
-
...envOptions[0],
|
|
118
|
-
loose: true,
|
|
119
|
-
},
|
|
120
|
-
]);
|
|
121
|
-
|
|
122
|
-
babelChain.plugin('babel-plugin-transform-typescript-metadata').use(
|
|
123
|
-
require.resolve('babel-plugin-transform-typescript-metadata'),
|
|
124
|
-
|
|
125
|
-
[],
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
babelChain
|
|
129
|
-
.plugin('@babel/plugin-proposal-decorators')
|
|
130
|
-
.use(require.resolve('@babel/plugin-proposal-decorators'), [
|
|
131
|
-
{ legacy: true },
|
|
132
|
-
]);
|
|
133
|
-
|
|
134
|
-
babelChain.plugin('@babel/plugin-proposal-class-properties').use(
|
|
135
|
-
require.resolve('@babel/plugin-proposal-class-properties'),
|
|
136
|
-
|
|
137
|
-
[{ loose: true }],
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
const internalBabelConfig = { ...babelChain.toJSON() };
|
|
141
|
-
|
|
142
|
-
const userBabelConfig = modernConfig.tools.babel;
|
|
143
|
-
applyOptionsChain(
|
|
144
|
-
internalBabelConfig,
|
|
145
|
-
// TODO: 感觉 userBabelConfig 的类型应该是TransformOptions
|
|
146
|
-
userBabelConfig as any,
|
|
147
|
-
{ chain: babelChain },
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
return internalBabelConfig;
|
|
151
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './babel';
|