@modern-js/server-utils 3.0.0-alpha.1 → 3.0.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 +2 -10
- package/dist/cjs/index.js +6 -41
- package/dist/esm/common/index.mjs +2 -10
- package/dist/esm/compilers/typescript/index.mjs +2 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm-node/common/index.mjs +3 -10
- package/dist/esm-node/compilers/typescript/index.mjs +1 -0
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.mjs +2 -0
- package/dist/esm-node/compilers/typescript/typescriptLoader.mjs +2 -0
- package/dist/esm-node/index.mjs +1 -1
- package/dist/types/common/index.d.ts +3 -4
- package/dist/types/index.d.ts +0 -1
- package/package.json +9 -24
- package/rstest.config.ts +6 -0
- package/dist/cjs/compilers/babel/index.js +0 -149
- package/dist/cjs/compilers/babel/preset/alias.js +0 -128
- package/dist/cjs/compilers/babel/preset/index.js +0 -107
- package/dist/cjs/compilers/babel/preset/types.js +0 -18
- package/dist/esm/compilers/babel/index.mjs +0 -57
- package/dist/esm/compilers/babel/preset/alias.mjs +0 -84
- package/dist/esm/compilers/babel/preset/index.mjs +0 -29
- package/dist/esm/compilers/babel/preset/types.mjs +0 -0
- package/dist/esm-node/compilers/babel/index.mjs +0 -57
- package/dist/esm-node/compilers/babel/preset/alias.mjs +0 -84
- package/dist/esm-node/compilers/babel/preset/index.mjs +0 -29
- package/dist/esm-node/compilers/babel/preset/types.mjs +0 -0
- package/dist/types/compilers/babel/index.d.ts +0 -23
- package/dist/types/compilers/babel/preset/alias.d.ts +0 -3
- package/dist/types/compilers/babel/preset/index.d.ts +0 -4
- package/dist/types/compilers/babel/preset/types.d.ts +0 -12
package/dist/cjs/common/index.js
CHANGED
|
@@ -28,7 +28,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
compile: ()=>compile
|
|
29
29
|
});
|
|
30
30
|
const external_path_namespaceObject = require("path");
|
|
31
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
32
31
|
const FILE_EXTENSIONS = [
|
|
33
32
|
'.js',
|
|
34
33
|
'.ts',
|
|
@@ -45,15 +44,8 @@ const compile = async (appDirectory, modernConfig, compileOptions)=>{
|
|
|
45
44
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
46
45
|
validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
|
|
47
46
|
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
if (isTsProject && 'babel' !== compiler) {
|
|
51
|
-
const { compileByTs } = await import("../compilers/typescript/index.js");
|
|
52
|
-
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
53
|
-
} else {
|
|
54
|
-
const { compileByBabel } = await import("../compilers/babel/index.js");
|
|
55
|
-
await compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
56
|
-
}
|
|
47
|
+
const { compileByTs } = await import("../compilers/typescript/index.js");
|
|
48
|
+
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
57
49
|
};
|
|
58
50
|
exports.FILE_EXTENSIONS = __webpack_exports__.FILE_EXTENSIONS;
|
|
59
51
|
exports.compile = __webpack_exports__.compile;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,31 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
"./common" (module) {
|
|
4
|
-
module.exports = require("./common/index.js");
|
|
5
|
-
},
|
|
6
|
-
"./compilers/babel" (module) {
|
|
7
|
-
module.exports = require("./compilers/babel/index.js");
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var __webpack_module_cache__ = {};
|
|
11
|
-
function __webpack_require__(moduleId) {
|
|
12
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
-
exports: {}
|
|
16
|
-
};
|
|
17
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
-
return module.exports;
|
|
19
|
-
}
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.n = (module)=>{
|
|
22
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
-
__webpack_require__.d(getter, {
|
|
24
|
-
a: getter
|
|
25
|
-
});
|
|
26
|
-
return getter;
|
|
27
|
-
};
|
|
28
|
-
})();
|
|
2
|
+
var __webpack_require__ = {};
|
|
29
3
|
(()=>{
|
|
30
4
|
__webpack_require__.d = (exports1, definition)=>{
|
|
31
5
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -48,20 +22,11 @@ function __webpack_require__(moduleId) {
|
|
|
48
22
|
};
|
|
49
23
|
})();
|
|
50
24
|
var __webpack_exports__ = {};
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var _compilers_babel__rspack_import_0 = __webpack_require__("./compilers/babel");
|
|
57
|
-
var __rspack_reexport = {};
|
|
58
|
-
for(const __rspack_import_key in _compilers_babel__rspack_import_0)if ([
|
|
59
|
-
"compile",
|
|
60
|
-
"default"
|
|
61
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_compilers_babel__rspack_import_0[__rspack_import_key];
|
|
62
|
-
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
63
|
-
var _common__rspack_import_1 = __webpack_require__("./common");
|
|
64
|
-
})();
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
compile: ()=>index_js_namespaceObject.compile
|
|
28
|
+
});
|
|
29
|
+
const index_js_namespaceObject = require("./common/index.js");
|
|
65
30
|
exports.compile = __webpack_exports__.compile;
|
|
66
31
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
67
32
|
"compile"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isAbsolute } from "path";
|
|
2
|
-
import { fs } from "@modern-js/utils";
|
|
3
2
|
const FILE_EXTENSIONS = [
|
|
4
3
|
'.js',
|
|
5
4
|
'.ts',
|
|
@@ -16,14 +15,7 @@ const compile = async (appDirectory, modernConfig, compileOptions)=>{
|
|
|
16
15
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
17
16
|
validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
|
|
18
17
|
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if (isTsProject && 'babel' !== compiler) {
|
|
22
|
-
const { compileByTs } = await import("../compilers/typescript");
|
|
23
|
-
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
24
|
-
} else {
|
|
25
|
-
const { compileByBabel } = await import("../compilers/babel");
|
|
26
|
-
await compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
27
|
-
}
|
|
18
|
+
const { compileByTs } = await import("../compilers/typescript/index.mjs");
|
|
19
|
+
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
28
20
|
};
|
|
29
21
|
export { FILE_EXTENSIONS, compile };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path_0 from "path";
|
|
2
2
|
import { fs, getAliasConfig, logger } from "@modern-js/utils";
|
|
3
|
-
import { tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin";
|
|
4
|
-
import { TypescriptLoader } from "./typescriptLoader";
|
|
3
|
+
import { tsconfigPathsBeforeHookFactory } from "./tsconfigPathsPlugin.mjs";
|
|
4
|
+
import { TypescriptLoader } from "./typescriptLoader.mjs";
|
|
5
5
|
const readTsConfigByFile = (tsConfigFile, tsInstance)=>{
|
|
6
6
|
const parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
|
|
7
7
|
const { options, fileNames, projectReferences } = parsedCmd;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import "node:module";
|
|
1
2
|
import { isAbsolute } from "path";
|
|
2
|
-
import { fs } from "@modern-js/utils";
|
|
3
3
|
const FILE_EXTENSIONS = [
|
|
4
4
|
'.js',
|
|
5
5
|
'.ts',
|
|
@@ -16,14 +16,7 @@ const compile = async (appDirectory, modernConfig, compileOptions)=>{
|
|
|
16
16
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
17
17
|
validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
|
|
18
18
|
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if (isTsProject && 'babel' !== compiler) {
|
|
22
|
-
const { compileByTs } = await import("../compilers/typescript/index.mjs");
|
|
23
|
-
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
24
|
-
} else {
|
|
25
|
-
const { compileByBabel } = await import("../compilers/babel/index.mjs");
|
|
26
|
-
await compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
27
|
-
}
|
|
19
|
+
const { compileByTs } = await import("../compilers/typescript/index.mjs");
|
|
20
|
+
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
28
21
|
};
|
|
29
22
|
export { FILE_EXTENSIONS, compile };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import __rslib_shim_module__ from "node:module";
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
1
3
|
import { platform } from "os";
|
|
2
4
|
import path, { dirname, posix } from "path";
|
|
3
5
|
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SourceNormalizedConfig
|
|
1
|
+
import type { SourceNormalizedConfig } from '@modern-js/server-core';
|
|
2
2
|
export interface Pattern {
|
|
3
3
|
from: string;
|
|
4
4
|
to: string;
|
|
@@ -6,9 +6,8 @@ export interface Pattern {
|
|
|
6
6
|
}
|
|
7
7
|
export interface IConfig {
|
|
8
8
|
alias?: SourceNormalizedConfig['alias'];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
compiler?: 'babel' | 'typescript';
|
|
9
|
+
server?: {
|
|
10
|
+
compiler?: 'typescript';
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
13
|
export interface CompileOptions {
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -15,20 +15,18 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.0.0
|
|
19
|
-
"jsnext:source": "./src/index.ts",
|
|
18
|
+
"version": "3.0.0",
|
|
20
19
|
"types": "./dist/types/index.d.ts",
|
|
21
20
|
"main": "./dist/cjs/index.js",
|
|
22
|
-
"module": "./dist/esm/index.mjs",
|
|
23
21
|
"exports": {
|
|
24
22
|
".": {
|
|
25
23
|
"types": "./dist/types/index.d.ts",
|
|
26
|
-
"
|
|
24
|
+
"modern:source": "./src/index.ts",
|
|
27
25
|
"node": {
|
|
28
26
|
"import": "./dist/esm-node/index.mjs",
|
|
29
27
|
"require": "./dist/cjs/index.js"
|
|
30
28
|
},
|
|
31
|
-
"default": "./dist/
|
|
29
|
+
"default": "./dist/cjs/index.js"
|
|
32
30
|
}
|
|
33
31
|
},
|
|
34
32
|
"typesVersions": {
|
|
@@ -39,29 +37,16 @@
|
|
|
39
37
|
}
|
|
40
38
|
},
|
|
41
39
|
"dependencies": {
|
|
42
|
-
"@babel/core": "^7.28.5",
|
|
43
|
-
"@babel/plugin-proposal-decorators": "^7.28.0",
|
|
44
|
-
"@babel/preset-env": "^7.28.5",
|
|
45
|
-
"@babel/preset-react": "^7.28.5",
|
|
46
|
-
"@babel/preset-typescript": "^7.28.5",
|
|
47
40
|
"@swc/helpers": "^0.5.17",
|
|
48
|
-
"
|
|
49
|
-
"@modern-js/babel-compiler": "3.0.0-alpha.1",
|
|
50
|
-
"@modern-js/babel-plugin-module-resolver": "3.0.0-alpha.1",
|
|
51
|
-
"@modern-js/babel-preset": "3.0.0-alpha.1",
|
|
52
|
-
"@modern-js/utils": "3.0.0-alpha.1"
|
|
41
|
+
"@modern-js/utils": "3.0.0"
|
|
53
42
|
},
|
|
54
43
|
"devDependencies": {
|
|
55
|
-
"@rslib/core": "0.19.
|
|
56
|
-
"@types/babel__core": "^7.20.5",
|
|
57
|
-
"@types/jest": "^29.5.14",
|
|
44
|
+
"@rslib/core": "0.19.4",
|
|
58
45
|
"@types/node": "^20",
|
|
59
|
-
"jest": "^29.7.0",
|
|
60
|
-
"ts-jest": "^29.4.6",
|
|
61
46
|
"typescript": "^5",
|
|
62
|
-
"@modern-js/
|
|
63
|
-
"@scripts/
|
|
64
|
-
"@modern-js/
|
|
47
|
+
"@modern-js/rslib": "2.68.10",
|
|
48
|
+
"@scripts/rstest-config": "2.66.0",
|
|
49
|
+
"@modern-js/server-core": "3.0.0"
|
|
65
50
|
},
|
|
66
51
|
"sideEffects": false,
|
|
67
52
|
"publishConfig": {
|
|
@@ -71,6 +56,6 @@
|
|
|
71
56
|
"scripts": {
|
|
72
57
|
"dev": "rslib build --watch",
|
|
73
58
|
"build": "rslib build",
|
|
74
|
-
"test": "
|
|
59
|
+
"test": "rstest --passWithNoTests"
|
|
75
60
|
}
|
|
76
61
|
}
|
package/rstest.config.ts
ADDED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_modules__ = {
|
|
3
|
-
"../../common" (module) {
|
|
4
|
-
module.exports = require("../../common/index.js");
|
|
5
|
-
},
|
|
6
|
-
"./preset" (module) {
|
|
7
|
-
module.exports = require("./preset/index.js");
|
|
8
|
-
},
|
|
9
|
-
"@babel/core" (module) {
|
|
10
|
-
module.exports = require("@babel/core");
|
|
11
|
-
},
|
|
12
|
-
"@modern-js/babel-compiler" (module) {
|
|
13
|
-
module.exports = require("@modern-js/babel-compiler");
|
|
14
|
-
},
|
|
15
|
-
"@modern-js/utils" (module) {
|
|
16
|
-
module.exports = require("@modern-js/utils");
|
|
17
|
-
},
|
|
18
|
-
path (module) {
|
|
19
|
-
module.exports = require("path");
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var __webpack_module_cache__ = {};
|
|
23
|
-
function __webpack_require__(moduleId) {
|
|
24
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
25
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
26
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
27
|
-
exports: {}
|
|
28
|
-
};
|
|
29
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
30
|
-
return module.exports;
|
|
31
|
-
}
|
|
32
|
-
(()=>{
|
|
33
|
-
__webpack_require__.n = (module)=>{
|
|
34
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
35
|
-
__webpack_require__.d(getter, {
|
|
36
|
-
a: getter
|
|
37
|
-
});
|
|
38
|
-
return getter;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
(()=>{
|
|
42
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
43
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: definition[key]
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
})();
|
|
49
|
-
(()=>{
|
|
50
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
51
|
-
})();
|
|
52
|
-
(()=>{
|
|
53
|
-
__webpack_require__.r = (exports1)=>{
|
|
54
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
55
|
-
value: 'Module'
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
58
|
-
value: true
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
})();
|
|
62
|
-
var __webpack_exports__ = {};
|
|
63
|
-
(()=>{
|
|
64
|
-
__webpack_require__.r(__webpack_exports__);
|
|
65
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
66
|
-
compileByBabel: ()=>compileByBabel,
|
|
67
|
-
existTsConfigFile: ()=>existTsConfigFile,
|
|
68
|
-
readTsConfig: ()=>readTsConfig,
|
|
69
|
-
resolveBabelConfig: ()=>resolveBabelConfig
|
|
70
|
-
});
|
|
71
|
-
var path__rspack_import_0 = __webpack_require__("path");
|
|
72
|
-
var _modern_js_babel_compiler__rspack_import_1 = __webpack_require__("@modern-js/babel-compiler");
|
|
73
|
-
var _modern_js_utils__rspack_import_2 = __webpack_require__("@modern-js/utils");
|
|
74
|
-
var _common__rspack_import_3 = __webpack_require__("../../common");
|
|
75
|
-
var _preset__rspack_import_4 = __webpack_require__("./preset");
|
|
76
|
-
var _babel_core__rspack_import_5 = __webpack_require__("@babel/core");
|
|
77
|
-
var __rspack_reexport = {};
|
|
78
|
-
for(const __rspack_import_key in _babel_core__rspack_import_5)if ([
|
|
79
|
-
"existTsConfigFile",
|
|
80
|
-
"readTsConfig",
|
|
81
|
-
"resolveBabelConfig",
|
|
82
|
-
"compileByBabel",
|
|
83
|
-
"default"
|
|
84
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_babel_core__rspack_import_5[__rspack_import_key];
|
|
85
|
-
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
86
|
-
const readTsConfig = (tsconfigPath, noExistReturn = null)=>{
|
|
87
|
-
if (!_modern_js_utils__rspack_import_2.fs.existsSync(tsconfigPath)) return noExistReturn;
|
|
88
|
-
const content = _modern_js_utils__rspack_import_2.fs.readFileSync(tsconfigPath, 'utf-8');
|
|
89
|
-
return _modern_js_utils__rspack_import_2.json5.parse(content);
|
|
90
|
-
};
|
|
91
|
-
const existTsConfigFile = (tsconfigAbsolutePath)=>{
|
|
92
|
-
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
93
|
-
return Boolean(tsconfig);
|
|
94
|
-
};
|
|
95
|
-
const resolveBabelConfig = (appDirectory, config, option, isEsm)=>{
|
|
96
|
-
const { alias, babelConfig } = config;
|
|
97
|
-
const aliasConfig = (0, _modern_js_utils__rspack_import_2.getAliasConfig)(alias, {
|
|
98
|
-
appDirectory,
|
|
99
|
-
...option
|
|
100
|
-
});
|
|
101
|
-
const defaultBabelConfig = (0, _preset__rspack_import_4.getBabelConfig)({
|
|
102
|
-
appDirectory,
|
|
103
|
-
alias: aliasConfig,
|
|
104
|
-
isEsm
|
|
105
|
-
});
|
|
106
|
-
return (0, _preset__rspack_import_4.applyUserBabelConfig)(defaultBabelConfig, babelConfig);
|
|
107
|
-
};
|
|
108
|
-
const compileByBabel = async (appDirectory, config, compileOptions)=>{
|
|
109
|
-
const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
|
|
110
|
-
const isEsm = 'module' === moduleType;
|
|
111
|
-
const results = await Promise.all(sourceDirs.map(async (sourceDir)=>{
|
|
112
|
-
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
113
|
-
tsconfigPath: tsconfigPath ? tsconfigPath : ''
|
|
114
|
-
}, isEsm);
|
|
115
|
-
if (await _modern_js_utils__rspack_import_2.fs.pathExists(sourceDir)) {
|
|
116
|
-
const basename = path__rspack_import_0.basename(sourceDir);
|
|
117
|
-
const targetDir = path__rspack_import_0.join(distDir, basename);
|
|
118
|
-
await _modern_js_utils__rspack_import_2.fs.copy(sourceDir, targetDir, {
|
|
119
|
-
filter: (src)=>![
|
|
120
|
-
'.ts',
|
|
121
|
-
'.js'
|
|
122
|
-
].includes(path__rspack_import_0.extname(src)) && src !== tsconfigPath
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return (0, _modern_js_babel_compiler__rspack_import_1.compiler)({
|
|
126
|
-
rootDir: appDirectory,
|
|
127
|
-
distDir,
|
|
128
|
-
sourceDir,
|
|
129
|
-
extensions: _common__rspack_import_3.FILE_EXTENSIONS
|
|
130
|
-
}, babelConfig);
|
|
131
|
-
}));
|
|
132
|
-
results.forEach((result)=>{
|
|
133
|
-
if (1 === result.code) throw new Error(result.message);
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
})();
|
|
137
|
-
exports.compileByBabel = __webpack_exports__.compileByBabel;
|
|
138
|
-
exports.existTsConfigFile = __webpack_exports__.existTsConfigFile;
|
|
139
|
-
exports.readTsConfig = __webpack_exports__.readTsConfig;
|
|
140
|
-
exports.resolveBabelConfig = __webpack_exports__.resolveBabelConfig;
|
|
141
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
142
|
-
"compileByBabel",
|
|
143
|
-
"existTsConfigFile",
|
|
144
|
-
"readTsConfig",
|
|
145
|
-
"resolveBabelConfig"
|
|
146
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
147
|
-
Object.defineProperty(exports, '__esModule', {
|
|
148
|
-
value: true
|
|
149
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_modules__ = {
|
|
3
|
-
"@modern-js/babel-plugin-module-resolver" (module) {
|
|
4
|
-
module.exports = require("@modern-js/babel-plugin-module-resolver");
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
var __webpack_module_cache__ = {};
|
|
8
|
-
function __webpack_require__(moduleId) {
|
|
9
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
-
exports: {}
|
|
13
|
-
};
|
|
14
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
-
return module.exports;
|
|
16
|
-
}
|
|
17
|
-
(()=>{
|
|
18
|
-
__webpack_require__.n = (module)=>{
|
|
19
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
-
__webpack_require__.d(getter, {
|
|
21
|
-
a: getter
|
|
22
|
-
});
|
|
23
|
-
return getter;
|
|
24
|
-
};
|
|
25
|
-
})();
|
|
26
|
-
(()=>{
|
|
27
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: definition[key]
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
})();
|
|
34
|
-
(()=>{
|
|
35
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
-
})();
|
|
37
|
-
(()=>{
|
|
38
|
-
__webpack_require__.r = (exports1)=>{
|
|
39
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
-
value: 'Module'
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
-
value: true
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
})();
|
|
47
|
-
var __webpack_exports__ = {};
|
|
48
|
-
(()=>{
|
|
49
|
-
__webpack_require__.r(__webpack_exports__);
|
|
50
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
-
aliasPlugin: ()=>aliasPlugin
|
|
52
|
-
});
|
|
53
|
-
const external_path_namespaceObject = require("path");
|
|
54
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
55
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
56
|
-
const tsconfig_paths_namespaceObject = require("@modern-js/utils/tsconfig-paths");
|
|
57
|
-
const { resolvePath } = __webpack_require__("@modern-js/babel-plugin-module-resolver");
|
|
58
|
-
const defaultPaths = {
|
|
59
|
-
'@': [
|
|
60
|
-
'./src'
|
|
61
|
-
]
|
|
62
|
-
};
|
|
63
|
-
const aliasPlugin = (alias)=>{
|
|
64
|
-
const { absoluteBaseUrl, isTsPath, isTsProject = false } = alias;
|
|
65
|
-
const mergedPaths = isTsPath ? alias.paths || {} : {
|
|
66
|
-
...defaultPaths,
|
|
67
|
-
...alias.paths || {}
|
|
68
|
-
};
|
|
69
|
-
let tsPaths = {};
|
|
70
|
-
if (isTsProject) tsPaths = (0, utils_namespaceObject.getUserAlias)(mergedPaths);
|
|
71
|
-
tsPaths = Object.keys(tsPaths).reduce((o, key)=>{
|
|
72
|
-
if ('string' == typeof tsPaths[key]) return {
|
|
73
|
-
...o,
|
|
74
|
-
[`${key}`]: [
|
|
75
|
-
tsPaths[key]
|
|
76
|
-
]
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
...o,
|
|
80
|
-
[`${key}`]: tsPaths[key]
|
|
81
|
-
};
|
|
82
|
-
}, {});
|
|
83
|
-
const resolvePathFn = (sourcePath, currentFile, opts)=>{
|
|
84
|
-
if ('.' === sourcePath || './' === sourcePath) return sourcePath;
|
|
85
|
-
const matchPath = (0, tsconfig_paths_namespaceObject.createMatchPath)(absoluteBaseUrl, tsPaths, [
|
|
86
|
-
'index'
|
|
87
|
-
]);
|
|
88
|
-
const result = matchPath(sourcePath, void 0, void 0, [
|
|
89
|
-
'.js',
|
|
90
|
-
'.jsx',
|
|
91
|
-
'.ts',
|
|
92
|
-
'.tsx'
|
|
93
|
-
]);
|
|
94
|
-
if (result) {
|
|
95
|
-
const relativePath = external_path_default().relative(external_path_default().dirname(currentFile), external_path_default().dirname(result));
|
|
96
|
-
const fileName = external_path_default().basename(result);
|
|
97
|
-
const filePath = external_path_default().normalize(`${0 === relativePath.length ? '.' : relativePath}/${fileName}`).replace(/\\/, '/');
|
|
98
|
-
return filePath.startsWith('.') ? filePath : `./${filePath}`;
|
|
99
|
-
}
|
|
100
|
-
return resolvePath(sourcePath, currentFile, opts);
|
|
101
|
-
};
|
|
102
|
-
const typescriptExts = [
|
|
103
|
-
'.ts',
|
|
104
|
-
'.tsx',
|
|
105
|
-
'.js',
|
|
106
|
-
'.jsx',
|
|
107
|
-
'.es',
|
|
108
|
-
'.es6',
|
|
109
|
-
'.mjs'
|
|
110
|
-
];
|
|
111
|
-
return [
|
|
112
|
-
require.resolve('@modern-js/babel-plugin-module-resolver'),
|
|
113
|
-
{
|
|
114
|
-
root: absoluteBaseUrl,
|
|
115
|
-
alias: mergedPaths,
|
|
116
|
-
resolvePath: isTsPath ? resolvePathFn : void 0,
|
|
117
|
-
extensions: isTsProject ? typescriptExts : void 0
|
|
118
|
-
}
|
|
119
|
-
];
|
|
120
|
-
};
|
|
121
|
-
})();
|
|
122
|
-
exports.aliasPlugin = __webpack_exports__.aliasPlugin;
|
|
123
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
124
|
-
"aliasPlugin"
|
|
125
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
126
|
-
Object.defineProperty(exports, '__esModule', {
|
|
127
|
-
value: true
|
|
128
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_modules__ = {
|
|
3
|
-
"./alias" (module) {
|
|
4
|
-
module.exports = require("./alias.js");
|
|
5
|
-
},
|
|
6
|
-
"./types" (module) {
|
|
7
|
-
module.exports = require("./types.js");
|
|
8
|
-
},
|
|
9
|
-
"@modern-js/babel-preset/node" (module) {
|
|
10
|
-
module.exports = require("@modern-js/babel-preset/node");
|
|
11
|
-
},
|
|
12
|
-
"@modern-js/utils" (module) {
|
|
13
|
-
module.exports = require("@modern-js/utils");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
var __webpack_module_cache__ = {};
|
|
17
|
-
function __webpack_require__(moduleId) {
|
|
18
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
19
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
20
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
21
|
-
exports: {}
|
|
22
|
-
};
|
|
23
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
24
|
-
return module.exports;
|
|
25
|
-
}
|
|
26
|
-
(()=>{
|
|
27
|
-
__webpack_require__.n = (module)=>{
|
|
28
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
29
|
-
__webpack_require__.d(getter, {
|
|
30
|
-
a: getter
|
|
31
|
-
});
|
|
32
|
-
return getter;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
(()=>{
|
|
36
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
37
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: definition[key]
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
})();
|
|
43
|
-
(()=>{
|
|
44
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
45
|
-
})();
|
|
46
|
-
(()=>{
|
|
47
|
-
__webpack_require__.r = (exports1)=>{
|
|
48
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
49
|
-
value: 'Module'
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
52
|
-
value: true
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
})();
|
|
56
|
-
var __webpack_exports__ = {};
|
|
57
|
-
(()=>{
|
|
58
|
-
__webpack_require__.r(__webpack_exports__);
|
|
59
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
60
|
-
applyUserBabelConfig: ()=>_modern_js_utils__rspack_import_3.applyUserBabelConfig,
|
|
61
|
-
getBabelConfig: ()=>getBabelConfig
|
|
62
|
-
});
|
|
63
|
-
var _modern_js_babel_preset_node__rspack_import_0 = __webpack_require__("@modern-js/babel-preset/node");
|
|
64
|
-
var _alias__rspack_import_1 = __webpack_require__("./alias");
|
|
65
|
-
var _types__rspack_import_2 = __webpack_require__("./types");
|
|
66
|
-
var __rspack_reexport = {};
|
|
67
|
-
for(const __rspack_import_key in _types__rspack_import_2)if ([
|
|
68
|
-
"applyUserBabelConfig",
|
|
69
|
-
"getBabelConfig",
|
|
70
|
-
"default"
|
|
71
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_2[__rspack_import_key];
|
|
72
|
-
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
73
|
-
var _modern_js_utils__rspack_import_3 = __webpack_require__("@modern-js/utils");
|
|
74
|
-
const getBabelConfig = (libPresetOption)=>{
|
|
75
|
-
const { isEsm } = libPresetOption;
|
|
76
|
-
const config = (0, _modern_js_babel_preset_node__rspack_import_0.getBabelConfigForNode)({
|
|
77
|
-
presetEnv: {
|
|
78
|
-
loose: true,
|
|
79
|
-
modules: isEsm ? false : 'commonjs',
|
|
80
|
-
targets: [
|
|
81
|
-
'node >= 14'
|
|
82
|
-
]
|
|
83
|
-
},
|
|
84
|
-
pluginDecorators: {
|
|
85
|
-
version: 'legacy'
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
config.presets?.push([
|
|
89
|
-
require.resolve('@babel/preset-react'),
|
|
90
|
-
{
|
|
91
|
-
runtime: 'automatic'
|
|
92
|
-
}
|
|
93
|
-
]);
|
|
94
|
-
if (libPresetOption.alias) config.plugins?.push((0, _alias__rspack_import_1.aliasPlugin)(libPresetOption.alias));
|
|
95
|
-
config.plugins?.push(require.resolve("babel-plugin-transform-typescript-metadata"));
|
|
96
|
-
return config;
|
|
97
|
-
};
|
|
98
|
-
})();
|
|
99
|
-
exports.applyUserBabelConfig = __webpack_exports__.applyUserBabelConfig;
|
|
100
|
-
exports.getBabelConfig = __webpack_exports__.getBabelConfig;
|
|
101
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
102
|
-
"applyUserBabelConfig",
|
|
103
|
-
"getBabelConfig"
|
|
104
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
105
|
-
Object.defineProperty(exports, '__esModule', {
|
|
106
|
-
value: true
|
|
107
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.r = (exports1)=>{
|
|
5
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
-
value: 'Module'
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
-
value: true
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
})();
|
|
13
|
-
var __webpack_exports__ = {};
|
|
14
|
-
__webpack_require__.r(__webpack_exports__);
|
|
15
|
-
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
-
Object.defineProperty(exports, '__esModule', {
|
|
17
|
-
value: true
|
|
18
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { basename as external_path_basename, extname, join } from "path";
|
|
2
|
-
import { compiler } from "@modern-js/babel-compiler";
|
|
3
|
-
import { fs, getAliasConfig, json5 } from "@modern-js/utils";
|
|
4
|
-
import { FILE_EXTENSIONS } from "../../common";
|
|
5
|
-
import { applyUserBabelConfig, getBabelConfig } from "./preset";
|
|
6
|
-
export * from "@babel/core";
|
|
7
|
-
const readTsConfig = (tsconfigPath, noExistReturn = null)=>{
|
|
8
|
-
if (!fs.existsSync(tsconfigPath)) return noExistReturn;
|
|
9
|
-
const content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
10
|
-
return json5.parse(content);
|
|
11
|
-
};
|
|
12
|
-
const existTsConfigFile = (tsconfigAbsolutePath)=>{
|
|
13
|
-
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
14
|
-
return Boolean(tsconfig);
|
|
15
|
-
};
|
|
16
|
-
const resolveBabelConfig = (appDirectory, config, option, isEsm)=>{
|
|
17
|
-
const { alias, babelConfig } = config;
|
|
18
|
-
const aliasConfig = getAliasConfig(alias, {
|
|
19
|
-
appDirectory,
|
|
20
|
-
...option
|
|
21
|
-
});
|
|
22
|
-
const defaultBabelConfig = getBabelConfig({
|
|
23
|
-
appDirectory,
|
|
24
|
-
alias: aliasConfig,
|
|
25
|
-
isEsm
|
|
26
|
-
});
|
|
27
|
-
return applyUserBabelConfig(defaultBabelConfig, babelConfig);
|
|
28
|
-
};
|
|
29
|
-
const compileByBabel = async (appDirectory, config, compileOptions)=>{
|
|
30
|
-
const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
|
|
31
|
-
const isEsm = 'module' === moduleType;
|
|
32
|
-
const results = await Promise.all(sourceDirs.map(async (sourceDir)=>{
|
|
33
|
-
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
34
|
-
tsconfigPath: tsconfigPath ? tsconfigPath : ''
|
|
35
|
-
}, isEsm);
|
|
36
|
-
if (await fs.pathExists(sourceDir)) {
|
|
37
|
-
const basename = external_path_basename(sourceDir);
|
|
38
|
-
const targetDir = join(distDir, basename);
|
|
39
|
-
await fs.copy(sourceDir, targetDir, {
|
|
40
|
-
filter: (src)=>![
|
|
41
|
-
'.ts',
|
|
42
|
-
'.js'
|
|
43
|
-
].includes(extname(src)) && src !== tsconfigPath
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return compiler({
|
|
47
|
-
rootDir: appDirectory,
|
|
48
|
-
distDir,
|
|
49
|
-
sourceDir,
|
|
50
|
-
extensions: FILE_EXTENSIONS
|
|
51
|
-
}, babelConfig);
|
|
52
|
-
}));
|
|
53
|
-
results.forEach((result)=>{
|
|
54
|
-
if (1 === result.code) throw new Error(result.message);
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
export { compileByBabel, existTsConfigFile, readTsConfig, resolveBabelConfig };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as __rspack_external__modern_js_babel_plugin_module_resolver_fc5e2536 from "@modern-js/babel-plugin-module-resolver";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { getUserAlias } from "@modern-js/utils";
|
|
4
|
-
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
5
|
-
var __webpack_modules__ = {
|
|
6
|
-
"@modern-js/babel-plugin-module-resolver" (module) {
|
|
7
|
-
module.exports = __rspack_external__modern_js_babel_plugin_module_resolver_fc5e2536;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var __webpack_module_cache__ = {};
|
|
11
|
-
function __webpack_require__(moduleId) {
|
|
12
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
-
exports: {}
|
|
16
|
-
};
|
|
17
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
-
return module.exports;
|
|
19
|
-
}
|
|
20
|
-
const { resolvePath } = __webpack_require__("@modern-js/babel-plugin-module-resolver");
|
|
21
|
-
const defaultPaths = {
|
|
22
|
-
'@': [
|
|
23
|
-
'./src'
|
|
24
|
-
]
|
|
25
|
-
};
|
|
26
|
-
const aliasPlugin = (alias)=>{
|
|
27
|
-
const { absoluteBaseUrl, isTsPath, isTsProject = false } = alias;
|
|
28
|
-
const mergedPaths = isTsPath ? alias.paths || {} : {
|
|
29
|
-
...defaultPaths,
|
|
30
|
-
...alias.paths || {}
|
|
31
|
-
};
|
|
32
|
-
let tsPaths = {};
|
|
33
|
-
if (isTsProject) tsPaths = getUserAlias(mergedPaths);
|
|
34
|
-
tsPaths = Object.keys(tsPaths).reduce((o, key)=>{
|
|
35
|
-
if ('string' == typeof tsPaths[key]) return {
|
|
36
|
-
...o,
|
|
37
|
-
[`${key}`]: [
|
|
38
|
-
tsPaths[key]
|
|
39
|
-
]
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
...o,
|
|
43
|
-
[`${key}`]: tsPaths[key]
|
|
44
|
-
};
|
|
45
|
-
}, {});
|
|
46
|
-
const resolvePathFn = (sourcePath, currentFile, opts)=>{
|
|
47
|
-
if ('.' === sourcePath || './' === sourcePath) return sourcePath;
|
|
48
|
-
const matchPath = createMatchPath(absoluteBaseUrl, tsPaths, [
|
|
49
|
-
'index'
|
|
50
|
-
]);
|
|
51
|
-
const result = matchPath(sourcePath, void 0, void 0, [
|
|
52
|
-
'.js',
|
|
53
|
-
'.jsx',
|
|
54
|
-
'.ts',
|
|
55
|
-
'.tsx'
|
|
56
|
-
]);
|
|
57
|
-
if (result) {
|
|
58
|
-
const relativePath = path.relative(path.dirname(currentFile), path.dirname(result));
|
|
59
|
-
const fileName = path.basename(result);
|
|
60
|
-
const filePath = path.normalize(`${0 === relativePath.length ? '.' : relativePath}/${fileName}`).replace(/\\/, '/');
|
|
61
|
-
return filePath.startsWith('.') ? filePath : `./${filePath}`;
|
|
62
|
-
}
|
|
63
|
-
return resolvePath(sourcePath, currentFile, opts);
|
|
64
|
-
};
|
|
65
|
-
const typescriptExts = [
|
|
66
|
-
'.ts',
|
|
67
|
-
'.tsx',
|
|
68
|
-
'.js',
|
|
69
|
-
'.jsx',
|
|
70
|
-
'.es',
|
|
71
|
-
'.es6',
|
|
72
|
-
'.mjs'
|
|
73
|
-
];
|
|
74
|
-
return [
|
|
75
|
-
require.resolve('@modern-js/babel-plugin-module-resolver'),
|
|
76
|
-
{
|
|
77
|
-
root: absoluteBaseUrl,
|
|
78
|
-
alias: mergedPaths,
|
|
79
|
-
resolvePath: isTsPath ? resolvePathFn : void 0,
|
|
80
|
-
extensions: isTsProject ? typescriptExts : void 0
|
|
81
|
-
}
|
|
82
|
-
];
|
|
83
|
-
};
|
|
84
|
-
export { aliasPlugin };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getBabelConfigForNode } from "@modern-js/babel-preset/node";
|
|
2
|
-
import { aliasPlugin } from "./alias";
|
|
3
|
-
import { applyUserBabelConfig } from "@modern-js/utils";
|
|
4
|
-
export * from "./types";
|
|
5
|
-
const getBabelConfig = (libPresetOption)=>{
|
|
6
|
-
const { isEsm } = libPresetOption;
|
|
7
|
-
const config = getBabelConfigForNode({
|
|
8
|
-
presetEnv: {
|
|
9
|
-
loose: true,
|
|
10
|
-
modules: isEsm ? false : 'commonjs',
|
|
11
|
-
targets: [
|
|
12
|
-
'node >= 14'
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
pluginDecorators: {
|
|
16
|
-
version: 'legacy'
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
config.presets?.push([
|
|
20
|
-
require.resolve('@babel/preset-react'),
|
|
21
|
-
{
|
|
22
|
-
runtime: 'automatic'
|
|
23
|
-
}
|
|
24
|
-
]);
|
|
25
|
-
if (libPresetOption.alias) config.plugins?.push(aliasPlugin(libPresetOption.alias));
|
|
26
|
-
config.plugins?.push(require.resolve("babel-plugin-transform-typescript-metadata"));
|
|
27
|
-
return config;
|
|
28
|
-
};
|
|
29
|
-
export { applyUserBabelConfig, getBabelConfig };
|
|
File without changes
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { basename as external_path_basename, extname, join } from "path";
|
|
2
|
-
import { compiler } from "@modern-js/babel-compiler";
|
|
3
|
-
import { fs, getAliasConfig, json5 } from "@modern-js/utils";
|
|
4
|
-
import { FILE_EXTENSIONS } from "../../common/index.mjs";
|
|
5
|
-
import { applyUserBabelConfig, getBabelConfig } from "./preset/index.mjs";
|
|
6
|
-
export * from "@babel/core";
|
|
7
|
-
const readTsConfig = (tsconfigPath, noExistReturn = null)=>{
|
|
8
|
-
if (!fs.existsSync(tsconfigPath)) return noExistReturn;
|
|
9
|
-
const content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
10
|
-
return json5.parse(content);
|
|
11
|
-
};
|
|
12
|
-
const existTsConfigFile = (tsconfigAbsolutePath)=>{
|
|
13
|
-
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
14
|
-
return Boolean(tsconfig);
|
|
15
|
-
};
|
|
16
|
-
const resolveBabelConfig = (appDirectory, config, option, isEsm)=>{
|
|
17
|
-
const { alias, babelConfig } = config;
|
|
18
|
-
const aliasConfig = getAliasConfig(alias, {
|
|
19
|
-
appDirectory,
|
|
20
|
-
...option
|
|
21
|
-
});
|
|
22
|
-
const defaultBabelConfig = getBabelConfig({
|
|
23
|
-
appDirectory,
|
|
24
|
-
alias: aliasConfig,
|
|
25
|
-
isEsm
|
|
26
|
-
});
|
|
27
|
-
return applyUserBabelConfig(defaultBabelConfig, babelConfig);
|
|
28
|
-
};
|
|
29
|
-
const compileByBabel = async (appDirectory, config, compileOptions)=>{
|
|
30
|
-
const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
|
|
31
|
-
const isEsm = 'module' === moduleType;
|
|
32
|
-
const results = await Promise.all(sourceDirs.map(async (sourceDir)=>{
|
|
33
|
-
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
34
|
-
tsconfigPath: tsconfigPath ? tsconfigPath : ''
|
|
35
|
-
}, isEsm);
|
|
36
|
-
if (await fs.pathExists(sourceDir)) {
|
|
37
|
-
const basename = external_path_basename(sourceDir);
|
|
38
|
-
const targetDir = join(distDir, basename);
|
|
39
|
-
await fs.copy(sourceDir, targetDir, {
|
|
40
|
-
filter: (src)=>![
|
|
41
|
-
'.ts',
|
|
42
|
-
'.js'
|
|
43
|
-
].includes(extname(src)) && src !== tsconfigPath
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return compiler({
|
|
47
|
-
rootDir: appDirectory,
|
|
48
|
-
distDir,
|
|
49
|
-
sourceDir,
|
|
50
|
-
extensions: FILE_EXTENSIONS
|
|
51
|
-
}, babelConfig);
|
|
52
|
-
}));
|
|
53
|
-
results.forEach((result)=>{
|
|
54
|
-
if (1 === result.code) throw new Error(result.message);
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
export { compileByBabel, existTsConfigFile, readTsConfig, resolveBabelConfig };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as __rspack_external__modern_js_babel_plugin_module_resolver_fc5e2536 from "@modern-js/babel-plugin-module-resolver";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { getUserAlias } from "@modern-js/utils";
|
|
4
|
-
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
5
|
-
var __webpack_modules__ = {
|
|
6
|
-
"@modern-js/babel-plugin-module-resolver" (module) {
|
|
7
|
-
module.exports = __rspack_external__modern_js_babel_plugin_module_resolver_fc5e2536;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var __webpack_module_cache__ = {};
|
|
11
|
-
function __webpack_require__(moduleId) {
|
|
12
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
-
exports: {}
|
|
16
|
-
};
|
|
17
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
-
return module.exports;
|
|
19
|
-
}
|
|
20
|
-
const { resolvePath } = __webpack_require__("@modern-js/babel-plugin-module-resolver");
|
|
21
|
-
const defaultPaths = {
|
|
22
|
-
'@': [
|
|
23
|
-
'./src'
|
|
24
|
-
]
|
|
25
|
-
};
|
|
26
|
-
const aliasPlugin = (alias)=>{
|
|
27
|
-
const { absoluteBaseUrl, isTsPath, isTsProject = false } = alias;
|
|
28
|
-
const mergedPaths = isTsPath ? alias.paths || {} : {
|
|
29
|
-
...defaultPaths,
|
|
30
|
-
...alias.paths || {}
|
|
31
|
-
};
|
|
32
|
-
let tsPaths = {};
|
|
33
|
-
if (isTsProject) tsPaths = getUserAlias(mergedPaths);
|
|
34
|
-
tsPaths = Object.keys(tsPaths).reduce((o, key)=>{
|
|
35
|
-
if ('string' == typeof tsPaths[key]) return {
|
|
36
|
-
...o,
|
|
37
|
-
[`${key}`]: [
|
|
38
|
-
tsPaths[key]
|
|
39
|
-
]
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
...o,
|
|
43
|
-
[`${key}`]: tsPaths[key]
|
|
44
|
-
};
|
|
45
|
-
}, {});
|
|
46
|
-
const resolvePathFn = (sourcePath, currentFile, opts)=>{
|
|
47
|
-
if ('.' === sourcePath || './' === sourcePath) return sourcePath;
|
|
48
|
-
const matchPath = createMatchPath(absoluteBaseUrl, tsPaths, [
|
|
49
|
-
'index'
|
|
50
|
-
]);
|
|
51
|
-
const result = matchPath(sourcePath, void 0, void 0, [
|
|
52
|
-
'.js',
|
|
53
|
-
'.jsx',
|
|
54
|
-
'.ts',
|
|
55
|
-
'.tsx'
|
|
56
|
-
]);
|
|
57
|
-
if (result) {
|
|
58
|
-
const relativePath = path.relative(path.dirname(currentFile), path.dirname(result));
|
|
59
|
-
const fileName = path.basename(result);
|
|
60
|
-
const filePath = path.normalize(`${0 === relativePath.length ? '.' : relativePath}/${fileName}`).replace(/\\/, '/');
|
|
61
|
-
return filePath.startsWith('.') ? filePath : `./${filePath}`;
|
|
62
|
-
}
|
|
63
|
-
return resolvePath(sourcePath, currentFile, opts);
|
|
64
|
-
};
|
|
65
|
-
const typescriptExts = [
|
|
66
|
-
'.ts',
|
|
67
|
-
'.tsx',
|
|
68
|
-
'.js',
|
|
69
|
-
'.jsx',
|
|
70
|
-
'.es',
|
|
71
|
-
'.es6',
|
|
72
|
-
'.mjs'
|
|
73
|
-
];
|
|
74
|
-
return [
|
|
75
|
-
require.resolve('@modern-js/babel-plugin-module-resolver'),
|
|
76
|
-
{
|
|
77
|
-
root: absoluteBaseUrl,
|
|
78
|
-
alias: mergedPaths,
|
|
79
|
-
resolvePath: isTsPath ? resolvePathFn : void 0,
|
|
80
|
-
extensions: isTsProject ? typescriptExts : void 0
|
|
81
|
-
}
|
|
82
|
-
];
|
|
83
|
-
};
|
|
84
|
-
export { aliasPlugin };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getBabelConfigForNode } from "@modern-js/babel-preset/node";
|
|
2
|
-
import { aliasPlugin } from "./alias.mjs";
|
|
3
|
-
import { applyUserBabelConfig } from "@modern-js/utils";
|
|
4
|
-
export * from "./types.mjs";
|
|
5
|
-
const getBabelConfig = (libPresetOption)=>{
|
|
6
|
-
const { isEsm } = libPresetOption;
|
|
7
|
-
const config = getBabelConfigForNode({
|
|
8
|
-
presetEnv: {
|
|
9
|
-
loose: true,
|
|
10
|
-
modules: isEsm ? false : 'commonjs',
|
|
11
|
-
targets: [
|
|
12
|
-
'node >= 14'
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
pluginDecorators: {
|
|
16
|
-
version: 'legacy'
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
config.presets?.push([
|
|
20
|
-
require.resolve('@babel/preset-react'),
|
|
21
|
-
{
|
|
22
|
-
runtime: 'automatic'
|
|
23
|
-
}
|
|
24
|
-
]);
|
|
25
|
-
if (libPresetOption.alias) config.plugins?.push(aliasPlugin(libPresetOption.alias));
|
|
26
|
-
config.plugins?.push(require.resolve("babel-plugin-transform-typescript-metadata"));
|
|
27
|
-
return config;
|
|
28
|
-
};
|
|
29
|
-
export { applyUserBabelConfig, getBabelConfig };
|
|
File without changes
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type CompileFunc } from '../../common';
|
|
2
|
-
export * from '@babel/core';
|
|
3
|
-
export interface ITsconfig {
|
|
4
|
-
compilerOptions?: {
|
|
5
|
-
rootDir?: string;
|
|
6
|
-
baseUrl?: string;
|
|
7
|
-
declaration?: boolean;
|
|
8
|
-
emitDeclarationOnly?: boolean;
|
|
9
|
-
isolatedModules?: boolean;
|
|
10
|
-
allowJs?: boolean;
|
|
11
|
-
outDir?: string;
|
|
12
|
-
paths?: Record<string, string[]>;
|
|
13
|
-
} | undefined;
|
|
14
|
-
include?: string[];
|
|
15
|
-
exclude?: string[];
|
|
16
|
-
}
|
|
17
|
-
export declare const readTsConfig: <T extends null | ITsconfig>(tsconfigPath: string, noExistReturn?: T) => ITsconfig | T;
|
|
18
|
-
export declare const existTsConfigFile: (tsconfigAbsolutePath: string) => boolean;
|
|
19
|
-
export interface IPackageModeValue {
|
|
20
|
-
tsconfigPath: string;
|
|
21
|
-
}
|
|
22
|
-
export declare const resolveBabelConfig: (appDirectory: string, config: Parameters<CompileFunc>[1], option: IPackageModeValue, isEsm?: boolean) => any;
|
|
23
|
-
export declare const compileByBabel: CompileFunc;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface AliasOption {
|
|
2
|
-
absoluteBaseUrl: string;
|
|
3
|
-
paths?: Record<string, string | string[]>;
|
|
4
|
-
isTsPath?: boolean;
|
|
5
|
-
isTsProject?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface ILibPresetOption {
|
|
8
|
-
appDirectory: string;
|
|
9
|
-
alias?: AliasOption;
|
|
10
|
-
isEsm?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export type JsxTransformRuntimeType = 'automatic' | 'classic';
|