@modern-js/server-utils 2.69.5 → 3.0.0-alpha.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.
Files changed (44) hide show
  1. package/dist/cjs/common/index.js +58 -62
  2. package/dist/cjs/compilers/babel/index.js +145 -101
  3. package/dist/cjs/compilers/babel/preset/alias.js +123 -105
  4. package/dist/cjs/compilers/babel/preset/index.js +102 -68
  5. package/dist/cjs/compilers/babel/preset/types.js +17 -15
  6. package/dist/cjs/compilers/typescript/index.js +112 -119
  7. package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +157 -191
  8. package/dist/cjs/compilers/typescript/typescriptLoader.js +47 -41
  9. package/dist/cjs/index.js +68 -28
  10. package/dist/esm/common/index.mjs +29 -0
  11. package/dist/esm/compilers/babel/index.mjs +57 -0
  12. package/dist/esm/compilers/babel/preset/alias.mjs +84 -0
  13. package/dist/esm/compilers/babel/preset/index.mjs +29 -0
  14. package/dist/esm/compilers/typescript/index.mjs +76 -0
  15. package/dist/esm/compilers/typescript/tsconfigPathsPlugin.mjs +126 -0
  16. package/dist/esm/compilers/typescript/typescriptLoader.mjs +20 -0
  17. package/dist/{esm-node/index.js → esm/index.mjs} +2 -4
  18. package/dist/esm-node/common/index.mjs +29 -0
  19. package/dist/esm-node/compilers/babel/index.mjs +57 -0
  20. package/dist/esm-node/compilers/babel/preset/alias.mjs +84 -0
  21. package/dist/esm-node/compilers/babel/preset/index.mjs +29 -0
  22. package/dist/esm-node/compilers/typescript/index.mjs +76 -0
  23. package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.mjs +126 -0
  24. package/dist/esm-node/compilers/typescript/typescriptLoader.mjs +20 -0
  25. package/dist/esm-node/index.mjs +3 -0
  26. package/package.json +32 -24
  27. package/rslib.config.mts +4 -0
  28. package/dist/esm/common/index.js +0 -97
  29. package/dist/esm/compilers/babel/index.js +0 -119
  30. package/dist/esm/compilers/babel/preset/alias.js +0 -70
  31. package/dist/esm/compilers/babel/preset/index.js +0 -36
  32. package/dist/esm/compilers/typescript/index.js +0 -202
  33. package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +0 -188
  34. package/dist/esm/compilers/typescript/typescriptLoader.js +0 -30
  35. package/dist/esm/index.js +0 -5
  36. package/dist/esm-node/common/index.js +0 -35
  37. package/dist/esm-node/compilers/babel/index.js +0 -66
  38. package/dist/esm-node/compilers/babel/preset/alias.js +0 -76
  39. package/dist/esm-node/compilers/babel/preset/index.js +0 -36
  40. package/dist/esm-node/compilers/typescript/index.js +0 -93
  41. package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +0 -170
  42. package/dist/esm-node/compilers/typescript/typescriptLoader.js +0 -24
  43. /package/dist/esm/compilers/babel/preset/{types.js → types.mjs} +0 -0
  44. /package/dist/esm-node/compilers/babel/preset/{types.js → types.mjs} +0 -0
@@ -1,70 +1,66 @@
1
1
  "use strict";
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 });
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 common_exports = {};
30
- __export(common_exports, {
31
- FILE_EXTENSIONS: () => FILE_EXTENSIONS,
32
- compile: () => compile
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ FILE_EXTENSIONS: ()=>FILE_EXTENSIONS,
28
+ compile: ()=>compile
33
29
  });
34
- module.exports = __toCommonJS(common_exports);
35
- var path = __toESM(require("path"));
36
- var import_utils = require("@modern-js/utils");
30
+ const external_path_namespaceObject = require("path");
31
+ const utils_namespaceObject = require("@modern-js/utils");
37
32
  const FILE_EXTENSIONS = [
38
- ".js",
39
- ".ts",
40
- ".mjs",
41
- ".ejs"
33
+ '.js',
34
+ '.ts',
35
+ '.mjs',
36
+ '.ejs'
42
37
  ];
43
- const validateAbsolutePath = (filename, message) => {
44
- if (!path.isAbsolute(filename)) {
45
- throw new Error(message);
46
- }
38
+ const validateAbsolutePath = (filename, message)=>{
39
+ if (!external_path_namespaceObject.isAbsolute(filename)) throw new Error(message);
47
40
  };
48
- const validateAbsolutePaths = (filenames, messageFunc) => {
49
- filenames.forEach((filename) => validateAbsolutePath(filename, messageFunc(filename)));
41
+ const validateAbsolutePaths = (filenames, messageFunc)=>{
42
+ filenames.forEach((filename)=>validateAbsolutePath(filename, messageFunc(filename)));
50
43
  };
51
- const compile = async (appDirectory, modernConfig, compileOptions) => {
52
- var _modernConfig_server;
53
- const { sourceDirs, distDir, tsconfigPath } = compileOptions;
54
- validateAbsolutePaths(sourceDirs, (dir) => `source dir ${dir} is not an absolute path.`);
55
- validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
56
- const compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_server = modernConfig.server) === null || _modernConfig_server === void 0 ? void 0 : _modernConfig_server.compiler;
57
- const isTsProject = tsconfigPath && await import_utils.fs.pathExists(tsconfigPath);
58
- if (!isTsProject || compiler === "babel") {
59
- const { compileByBabel } = await Promise.resolve().then(() => __toESM(require("../compilers/babel")));
60
- await compileByBabel(appDirectory, modernConfig, compileOptions);
61
- } else {
62
- const { compileByTs } = await Promise.resolve().then(() => __toESM(require("../compilers/typescript")));
63
- await compileByTs(appDirectory, modernConfig, compileOptions);
64
- }
44
+ const compile = async (appDirectory, modernConfig, compileOptions)=>{
45
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
46
+ validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
47
+ validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
48
+ const compiler = modernConfig?.server?.compiler;
49
+ const isTsProject = tsconfigPath && await utils_namespaceObject.fs.pathExists(tsconfigPath);
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
+ }
65
57
  };
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {
68
- FILE_EXTENSIONS,
69
- compile
58
+ exports.FILE_EXTENSIONS = __webpack_exports__.FILE_EXTENSIONS;
59
+ exports.compile = __webpack_exports__.compile;
60
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
61
+ "FILE_EXTENSIONS",
62
+ "compile"
63
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
64
+ Object.defineProperty(exports, '__esModule', {
65
+ value: true
70
66
  });
@@ -1,105 +1,149 @@
1
1
  "use strict";
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 });
17
- }
18
- return to;
19
- };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var babel_exports = {};
31
- __export(babel_exports, {
32
- compileByBabel: () => compileByBabel,
33
- existTsConfigFile: () => existTsConfigFile,
34
- readTsConfig: () => readTsConfig,
35
- resolveBabelConfig: () => resolveBabelConfig
36
- });
37
- module.exports = __toCommonJS(babel_exports);
38
- var path = __toESM(require("path"));
39
- var import_babel_compiler = require("@modern-js/babel-compiler");
40
- var import_utils = require("@modern-js/utils");
41
- var import_common = require("../../common");
42
- var import_preset = require("./preset");
43
- __reExport(babel_exports, require("@babel/core"), module.exports);
44
- const readTsConfig = (tsconfigPath, noExistReturn = null) => {
45
- if (!import_utils.fs.existsSync(tsconfigPath)) {
46
- return noExistReturn;
47
- }
48
- const content = import_utils.fs.readFileSync(tsconfigPath, "utf-8");
49
- return import_utils.json5.parse(content);
50
- };
51
- const existTsConfigFile = (tsconfigAbsolutePath) => {
52
- const tsconfig = readTsConfig(tsconfigAbsolutePath);
53
- return Boolean(tsconfig);
54
- };
55
- const resolveBabelConfig = (appDirectory, config, option, isEsm) => {
56
- const { alias, babelConfig } = config;
57
- const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
58
- appDirectory,
59
- ...option
60
- });
61
- const defaultBabelConfig = (0, import_preset.getBabelConfig)({
62
- appDirectory,
63
- alias: aliasConfig,
64
- isEsm
65
- });
66
- return (0, import_preset.applyUserBabelConfig)(defaultBabelConfig, babelConfig);
67
- };
68
- const compileByBabel = async (appDirectory, config, compileOptions) => {
69
- const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
70
- const isEsm = moduleType === "module";
71
- const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
72
- const babelConfig = resolveBabelConfig(appDirectory, config, {
73
- tsconfigPath: tsconfigPath ? tsconfigPath : ""
74
- }, isEsm);
75
- if (await import_utils.fs.pathExists(sourceDir)) {
76
- const basename = path.basename(sourceDir);
77
- const targetDir = path.join(distDir, basename);
78
- await import_utils.fs.copy(sourceDir, targetDir, {
79
- filter: (src) => ![
80
- ".ts",
81
- ".js"
82
- ].includes(path.extname(src)) && src !== tsconfigPath
83
- });
84
- }
85
- return (0, import_babel_compiler.compiler)({
86
- rootDir: appDirectory,
87
- distDir,
88
- sourceDir,
89
- extensions: import_common.FILE_EXTENSIONS
90
- }, babelConfig);
91
- }));
92
- results.forEach((result) => {
93
- if (result.code === 1) {
94
- throw new Error(result.message);
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");
95
20
  }
96
- });
97
21
  };
98
- // Annotate the CommonJS export names for ESM import in node:
99
- 0 && (module.exports = {
100
- compileByBabel,
101
- existTsConfigFile,
102
- readTsConfig,
103
- resolveBabelConfig,
104
- ...require("@babel/core")
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
105
149
  });
@@ -1,110 +1,128 @@
1
1
  "use strict";
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 });
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 alias_exports = {};
30
- __export(alias_exports, {
31
- aliasPlugin: () => aliasPlugin
32
- });
33
- module.exports = __toCommonJS(alias_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
37
- const { resolvePath } = require("@modern-js/babel-plugin-module-resolver");
38
- const defaultPaths = {
39
- "@": [
40
- "./src"
41
- ]
2
+ var __webpack_modules__ = {
3
+ "@modern-js/babel-plugin-module-resolver" (module) {
4
+ module.exports = require("@modern-js/babel-plugin-module-resolver");
5
+ }
42
6
  };
43
- const aliasPlugin = (alias) => {
44
- const { absoluteBaseUrl, isTsPath, isTsProject = false } = alias;
45
- const mergedPaths = isTsPath ? alias.paths || {} : {
46
- ...defaultPaths,
47
- ...alias.paths || {}
48
- };
49
- let tsPaths = {};
50
- if (isTsProject) {
51
- tsPaths = (0, import_utils.getUserAlias)(mergedPaths);
52
- }
53
- tsPaths = Object.keys(tsPaths).reduce((o, key) => {
54
- if (typeof tsPaths[key] === "string") {
55
- return {
56
- ...o,
57
- [`${key}`]: [
58
- tsPaths[key]
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'
59
61
  ]
60
- };
61
- }
62
- return {
63
- ...o,
64
- [`${key}`]: tsPaths[key]
65
62
  };
66
- }, {});
67
- const resolvePathFn = (sourcePath, currentFile, opts) => {
68
- if (sourcePath === "." || sourcePath === "./") {
69
- return sourcePath;
70
- }
71
- const matchPath = (0, import_tsconfig_paths.createMatchPath)(absoluteBaseUrl, tsPaths, [
72
- "index"
73
- ]);
74
- const result = matchPath(sourcePath, void 0, void 0, [
75
- ".js",
76
- ".jsx",
77
- ".ts",
78
- ".tsx"
79
- ]);
80
- if (result) {
81
- const relativePath = import_path.default.relative(import_path.default.dirname(currentFile), import_path.default.dirname(result));
82
- const fileName = import_path.default.basename(result);
83
- const filePath = import_path.default.normalize(`${relativePath.length === 0 ? "." : relativePath}/${fileName}`).replace(/\\/, "/");
84
- return filePath.startsWith(".") ? filePath : `./${filePath}`;
85
- }
86
- return resolvePath(sourcePath, currentFile, opts);
87
- };
88
- const typescriptExts = [
89
- ".ts",
90
- ".tsx",
91
- ".js",
92
- ".jsx",
93
- ".es",
94
- ".es6",
95
- ".mjs"
96
- ];
97
- return [
98
- require.resolve("@modern-js/babel-plugin-module-resolver"),
99
- {
100
- root: absoluteBaseUrl,
101
- alias: mergedPaths,
102
- resolvePath: isTsPath ? resolvePathFn : void 0,
103
- extensions: isTsProject ? typescriptExts : void 0
104
- }
105
- ];
106
- };
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- aliasPlugin
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
110
128
  });