@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,24 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var tsconfigPathsPlugin_exports = {};
|
|
30
|
+
__export(tsconfigPathsPlugin_exports, {
|
|
31
|
+
tsconfigPathsBeforeHookFactory: () => tsconfigPathsBeforeHookFactory
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
module.exports = __toCommonJS(tsconfigPathsPlugin_exports);
|
|
34
|
+
var os = __toESM(require("os"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var ts = __toESM(require("typescript"));
|
|
37
|
+
var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
|
|
16
38
|
const isRegExpKey = (str) => {
|
|
17
39
|
return str.startsWith("^") || str.endsWith("$");
|
|
18
40
|
};
|
|
19
41
|
const resolveAliasPath = (baseUrl, filePath) => {
|
|
20
42
|
if (filePath.startsWith(".") || filePath.startsWith("..")) {
|
|
21
|
-
return
|
|
43
|
+
return import_path.default.resolve(baseUrl, filePath);
|
|
22
44
|
}
|
|
23
45
|
return filePath;
|
|
24
46
|
};
|
|
@@ -60,7 +82,7 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
60
82
|
};
|
|
61
83
|
};
|
|
62
84
|
const isDynamicImport = (tsBinary, node) => {
|
|
63
|
-
return tsBinary.isCallExpression(node) && node.expression.kind ===
|
|
85
|
+
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
64
86
|
};
|
|
65
87
|
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
66
88
|
const tsPaths = {};
|
|
@@ -73,7 +95,7 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
73
95
|
}
|
|
74
96
|
});
|
|
75
97
|
const matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
76
|
-
const matchTsPath = (0,
|
|
98
|
+
const matchTsPath = (0, import_tsconfig_paths.createMatchPath)(baseUrl, tsPaths, [
|
|
77
99
|
"main"
|
|
78
100
|
]);
|
|
79
101
|
const matchPath = (requestedModule, readJSONSync, fileExists, extensions) => {
|
|
@@ -142,10 +164,10 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
142
164
|
if (!result) {
|
|
143
165
|
return;
|
|
144
166
|
}
|
|
145
|
-
if (
|
|
167
|
+
if (os.platform() === "win32") {
|
|
146
168
|
result = result.replace(/\\/g, "/");
|
|
147
169
|
}
|
|
148
|
-
if (!
|
|
170
|
+
if (!import_path.default.isAbsolute(result)) {
|
|
149
171
|
if (!result.startsWith(".") && !result.startsWith("..")) {
|
|
150
172
|
try {
|
|
151
173
|
const packagePath = require.resolve(result, {
|
|
@@ -173,6 +195,10 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
173
195
|
} catch {
|
|
174
196
|
}
|
|
175
197
|
}
|
|
176
|
-
const resolvedPath =
|
|
198
|
+
const resolvedPath = import_path.posix.relative((0, import_path.dirname)(sf.fileName), result) || "./";
|
|
177
199
|
return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
|
|
178
200
|
}
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
tsconfigPathsBeforeHookFactory
|
|
204
|
+
});
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var typescriptLoader_exports = {};
|
|
20
|
+
__export(typescriptLoader_exports, {
|
|
21
|
+
TypescriptLoader: () => TypescriptLoader
|
|
10
22
|
});
|
|
11
|
-
|
|
23
|
+
module.exports = __toCommonJS(typescriptLoader_exports);
|
|
24
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
12
25
|
class TypescriptLoader {
|
|
13
26
|
load() {
|
|
14
27
|
if (this.tsBinary) {
|
|
@@ -27,8 +40,12 @@ class TypescriptLoader {
|
|
|
27
40
|
}
|
|
28
41
|
}
|
|
29
42
|
constructor({ appDirectory }) {
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
(0, import_define_property._)(this, "tsBinary", void 0);
|
|
44
|
+
(0, import_define_property._)(this, "appDirectory", void 0);
|
|
32
45
|
this.appDirectory = appDirectory;
|
|
33
46
|
}
|
|
34
47
|
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
TypescriptLoader
|
|
51
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
compile: () => import_common.compile
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
__reExport(src_exports, require("./compilers/babel"), module.exports);
|
|
26
|
+
var import_common = require("./common");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
compile,
|
|
30
|
+
...require("./compilers/babel")
|
|
10
31
|
});
|
|
11
|
-
const _export_star = require("@swc/helpers/_/_export_star");
|
|
12
|
-
_export_star._(require("./compilers/babel"), exports);
|
|
13
|
-
const _common = require("./common");
|
package/dist/esm/common/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { fs } from "@modern-js/utils";
|
|
5
|
-
|
|
5
|
+
var FILE_EXTENSIONS = [
|
|
6
6
|
".js",
|
|
7
7
|
".ts",
|
|
8
8
|
".mjs",
|
|
@@ -18,7 +18,7 @@ var validateAbsolutePaths = function(filenames, messageFunc) {
|
|
|
18
18
|
return validateAbsolutePath(filename, messageFunc(filename));
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
var compile = function() {
|
|
22
22
|
var _ref = _async_to_generator(function(appDirectory, modernConfig, compileOptions) {
|
|
23
23
|
var _modernConfig_server, sourceDirs, distDir, tsconfigPath, compiler, isTsProject, _tmp, compileByBabel, compileByTs;
|
|
24
24
|
return _ts_generator(this, function(_state) {
|
|
@@ -91,3 +91,7 @@ export var compile = function() {
|
|
|
91
91
|
return _ref.apply(this, arguments);
|
|
92
92
|
};
|
|
93
93
|
}();
|
|
94
|
+
export {
|
|
95
|
+
FILE_EXTENSIONS,
|
|
96
|
+
compile
|
|
97
|
+
};
|
|
@@ -1,14 +1,13 @@
|
|
|
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 {
|
|
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;
|
|
13
12
|
if (!fs.existsSync(tsconfigPath)) {
|
|
14
13
|
return noExistReturn;
|
|
@@ -16,40 +15,22 @@ export var readTsConfig = function(tsconfigPath) {
|
|
|
16
15
|
var content = fs.readFileSync(tsconfigPath, "utf-8");
|
|
17
16
|
return json5.parse(content);
|
|
18
17
|
};
|
|
19
|
-
|
|
18
|
+
var existTsConfigFile = function(tsconfigAbsolutePath) {
|
|
20
19
|
var tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
21
20
|
return Boolean(tsconfig);
|
|
22
21
|
};
|
|
23
|
-
|
|
22
|
+
var resolveBabelConfig = function(appDirectory, config, option) {
|
|
24
23
|
var alias = config.alias, babelConfig = config.babelConfig;
|
|
25
24
|
var aliasConfig = getAliasConfig(alias, _object_spread({
|
|
26
|
-
appDirectory
|
|
25
|
+
appDirectory
|
|
27
26
|
}, option));
|
|
28
|
-
var
|
|
29
|
-
appDirectory
|
|
30
|
-
enableReactPreset: true,
|
|
31
|
-
enableTypescriptPreset: true,
|
|
27
|
+
var defaultBabelConfig = getBabelConfig({
|
|
28
|
+
appDirectory,
|
|
32
29
|
alias: aliasConfig
|
|
33
|
-
}, {
|
|
34
|
-
type: option.type,
|
|
35
|
-
syntax: option.syntax
|
|
36
30
|
});
|
|
37
|
-
|
|
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) {
|
|
54
35
|
var sourceDirs, distDir, tsconfigPath, results;
|
|
55
36
|
return _ts_generator(this, function(_state) {
|
|
@@ -65,9 +46,7 @@ export 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,
|
|
@@ -100,8 +79,8 @@ export var compileByBabel = function() {
|
|
|
100
79
|
2,
|
|
101
80
|
compiler({
|
|
102
81
|
rootDir: appDirectory,
|
|
103
|
-
distDir
|
|
104
|
-
sourceDir
|
|
82
|
+
distDir,
|
|
83
|
+
sourceDir,
|
|
105
84
|
extensions: FILE_EXTENSIONS
|
|
106
85
|
}, babelConfig)
|
|
107
86
|
];
|
|
@@ -130,3 +109,9 @@ export var compileByBabel = function() {
|
|
|
130
109
|
return _ref.apply(this, arguments);
|
|
131
110
|
};
|
|
132
111
|
}();
|
|
112
|
+
export {
|
|
113
|
+
compileByBabel,
|
|
114
|
+
existTsConfigFile,
|
|
115
|
+
readTsConfig,
|
|
116
|
+
resolveBabelConfig
|
|
117
|
+
};
|
|
@@ -10,7 +10,7 @@ var defaultPaths = {
|
|
|
10
10
|
"./src"
|
|
11
11
|
]
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
var aliasPlugin = function(alias) {
|
|
14
14
|
var absoluteBaseUrl = alias.absoluteBaseUrl, isTsPath = alias.isTsPath, _alias_isTsProject = alias.isTsProject, isTsProject = _alias_isTsProject === void 0 ? false : _alias_isTsProject;
|
|
15
15
|
var mergedPaths = isTsPath ? alias.paths || {} : _object_spread({}, defaultPaths, alias.paths || {});
|
|
16
16
|
var tsPaths = {};
|
|
@@ -56,7 +56,7 @@ export 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,
|
|
@@ -65,3 +65,6 @@ export var aliasPlugin = function(alias) {
|
|
|
65
65
|
}
|
|
66
66
|
];
|
|
67
67
|
};
|
|
68
|
+
export {
|
|
69
|
+
aliasPlugin
|
|
70
|
+
};
|
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getBaseBabelChain } from "@modern-js/babel-preset-base";
|
|
1
|
+
import { getBabelConfigForNode } from "@rsbuild/babel-preset/node";
|
|
3
2
|
import { aliasPlugin } from "./alias";
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
syntax: 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// for es5 code need helper functions
|
|
23
|
-
helpers: syntaxOption.syntax === "es5"
|
|
24
|
-
},
|
|
25
|
-
styledComponentsOptions: styledComponentsOptions
|
|
26
|
-
},
|
|
27
|
-
jsxTransformRuntime: 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
|
|
31
|
-
|
|
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
|
-
|
|
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";
|
|
29
|
+
export {
|
|
30
|
+
applyUserBabelConfig,
|
|
31
|
+
getBabelConfig
|
|
32
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -10,9 +10,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;
|
|
12
12
|
return {
|
|
13
|
-
options
|
|
14
|
-
fileNames
|
|
15
|
-
projectReferences
|
|
13
|
+
options,
|
|
14
|
+
fileNames,
|
|
15
|
+
projectReferences
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
var copyFiles = function() {
|
|
@@ -57,7 +57,7 @@ var copyFiles = function() {
|
|
|
57
57
|
return _ref.apply(this, arguments);
|
|
58
58
|
};
|
|
59
59
|
}();
|
|
60
|
-
|
|
60
|
+
var compileByTs = function() {
|
|
61
61
|
var _ref = _async_to_generator(function(appDirectory, config, compileOptions) {
|
|
62
62
|
var sourceDirs, distDir, tsconfigPath, ts, createProgram, formatHost, alias, aliasOption, _aliasOption_paths, paths, _aliasOption_absoluteBaseUrl, absoluteBaseUrl, _readTsConfigByFile, options, fileNames, projectReferences, sourcePosixPaths, rootNames, program, tsconfigPathsPlugin, emitResult, allDiagnostics, noEmitOnError, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, source, err;
|
|
63
63
|
return _ts_generator(this, function(_state) {
|
|
@@ -71,14 +71,14 @@ export var compileByTs = function() {
|
|
|
71
71
|
];
|
|
72
72
|
}
|
|
73
73
|
ts = new TypescriptLoader({
|
|
74
|
-
appDirectory
|
|
74
|
+
appDirectory
|
|
75
75
|
}).load();
|
|
76
76
|
createProgram = ts.createIncrementalProgram || ts.createProgram;
|
|
77
77
|
formatHost = getFormatHost(ts);
|
|
78
78
|
alias = config.alias;
|
|
79
79
|
aliasOption = getAliasConfig(alias, {
|
|
80
|
-
appDirectory
|
|
81
|
-
tsconfigPath
|
|
80
|
+
appDirectory,
|
|
81
|
+
tsconfigPath
|
|
82
82
|
});
|
|
83
83
|
_aliasOption_paths = aliasOption.paths, paths = _aliasOption_paths === void 0 ? {} : _aliasOption_paths, _aliasOption_absoluteBaseUrl = aliasOption.absoluteBaseUrl, absoluteBaseUrl = _aliasOption_absoluteBaseUrl === void 0 ? "./" : _aliasOption_absoluteBaseUrl;
|
|
84
84
|
_readTsConfigByFile = readTsConfigByFile(tsconfigPath, ts), options = _readTsConfigByFile.options, fileNames = _readTsConfigByFile.fileNames, projectReferences = _readTsConfigByFile.projectReferences;
|
|
@@ -91,8 +91,8 @@ export var compileByTs = function() {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
program = createProgram.call(ts, {
|
|
94
|
-
rootNames
|
|
95
|
-
projectReferences
|
|
94
|
+
rootNames,
|
|
95
|
+
projectReferences,
|
|
96
96
|
options: _object_spread({
|
|
97
97
|
rootDir: appDirectory,
|
|
98
98
|
outDir: distDir
|
|
@@ -192,3 +192,6 @@ var getFormatHost = function(ts) {
|
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
};
|
|
195
|
+
export {
|
|
196
|
+
compileByTs
|
|
197
|
+
};
|
|
@@ -71,7 +71,7 @@ var createAliasMatcher = function(baseUrl, alias) {
|
|
|
71
71
|
var isDynamicImport = function(tsBinary, node) {
|
|
72
72
|
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
73
73
|
};
|
|
74
|
-
|
|
74
|
+
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
75
75
|
var tsPaths = {};
|
|
76
76
|
var alias = {};
|
|
77
77
|
Object.keys(paths).forEach(function(key) {
|
|
@@ -183,3 +183,6 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
183
183
|
var resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
|
|
184
184
|
return resolvedPath[0] === "." ? resolvedPath : "./".concat(resolvedPath);
|
|
185
185
|
}
|
|
186
|
+
export {
|
|
187
|
+
tsconfigPathsBeforeHookFactory
|
|
188
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
2
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
3
3
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
|
-
|
|
4
|
+
var TypescriptLoader = /* @__PURE__ */ function() {
|
|
5
5
|
"use strict";
|
|
6
6
|
function TypescriptLoader2(param) {
|
|
7
7
|
var appDirectory = param.appDirectory;
|
|
@@ -33,3 +33,6 @@ export var TypescriptLoader = /* @__PURE__ */ function() {
|
|
|
33
33
|
]);
|
|
34
34
|
return TypescriptLoader2;
|
|
35
35
|
}();
|
|
36
|
+
export {
|
|
37
|
+
TypescriptLoader
|
|
38
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
const FILE_EXTENSIONS = [
|
|
4
4
|
".js",
|
|
5
5
|
".ts",
|
|
6
6
|
".mjs",
|
|
@@ -14,7 +14,7 @@ const validateAbsolutePath = (filename, message) => {
|
|
|
14
14
|
const validateAbsolutePaths = (filenames, messageFunc) => {
|
|
15
15
|
filenames.forEach((filename) => validateAbsolutePath(filename, messageFunc(filename)));
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
18
18
|
var _modernConfig_server;
|
|
19
19
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
20
20
|
validateAbsolutePaths(sourceDirs, (dir) => `source dir ${dir} is not an absolute path.`);
|
|
@@ -29,3 +29,7 @@ export const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
|
29
29
|
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
+
export {
|
|
33
|
+
FILE_EXTENSIONS,
|
|
34
|
+
compile
|
|
35
|
+
};
|
|
@@ -2,59 +2,36 @@ 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 {
|
|
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)) {
|
|
9
9
|
return noExistReturn;
|
|
10
10
|
}
|
|
11
11
|
const content = fs.readFileSync(tsconfigPath, "utf-8");
|
|
12
12
|
return json5.parse(content);
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
const existTsConfigFile = (tsconfigAbsolutePath) => {
|
|
15
15
|
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
16
16
|
return Boolean(tsconfig);
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
const resolveBabelConfig = (appDirectory, config, option) => {
|
|
19
19
|
const { alias, babelConfig } = config;
|
|
20
20
|
const aliasConfig = getAliasConfig(alias, {
|
|
21
21
|
appDirectory,
|
|
22
22
|
...option
|
|
23
23
|
});
|
|
24
|
-
const
|
|
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
|
-
|
|
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);
|
|
@@ -79,3 +56,9 @@ export const compileByBabel = async (appDirectory, config, compileOptions) => {
|
|
|
79
56
|
}
|
|
80
57
|
});
|
|
81
58
|
};
|
|
59
|
+
export {
|
|
60
|
+
compileByBabel,
|
|
61
|
+
existTsConfigFile,
|
|
62
|
+
readTsConfig,
|
|
63
|
+
resolveBabelConfig
|
|
64
|
+
};
|
|
@@ -7,7 +7,7 @@ const defaultPaths = {
|
|
|
7
7
|
"./src"
|
|
8
8
|
]
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
const aliasPlugin = (alias) => {
|
|
11
11
|
const { absoluteBaseUrl, isTsPath, isTsProject = false } = alias;
|
|
12
12
|
const mergedPaths = isTsPath ? alias.paths || {} : {
|
|
13
13
|
...defaultPaths,
|
|
@@ -62,7 +62,7 @@ export 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,
|
|
@@ -71,3 +71,6 @@ export const aliasPlugin = (alias) => {
|
|
|
71
71
|
}
|
|
72
72
|
];
|
|
73
73
|
};
|
|
74
|
+
export {
|
|
75
|
+
aliasPlugin
|
|
76
|
+
};
|