@modern-js/server-utils 2.25.0 → 2.25.1-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.
@@ -0,0 +1,85 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var __async = (__this, __arguments, generator) => {
25
+ return new Promise((resolve, reject) => {
26
+ var fulfilled = (value) => {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var rejected = (value) => {
34
+ try {
35
+ step(generator.throw(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
+ step((generator = generator.apply(__this, __arguments)).next());
42
+ });
43
+ };
44
+ var common_exports = {};
45
+ __export(common_exports, {
46
+ FILE_EXTENSIONS: () => FILE_EXTENSIONS,
47
+ compile: () => compile
48
+ });
49
+ module.exports = __toCommonJS(common_exports);
50
+ var path = __toESM(require("path"));
51
+ var import_utils = require("@modern-js/utils");
52
+ var import_typescript = require("../compilers/typescript");
53
+ var import_babel = require("../compilers/babel");
54
+ const FILE_EXTENSIONS = [".js", ".ts", ".mjs", ".ejs"];
55
+ const validateAbsolutePath = (filename, message) => {
56
+ if (!path.isAbsolute(filename)) {
57
+ throw new Error(message);
58
+ }
59
+ };
60
+ const validateAbsolutePaths = (filenames, messageFunc) => {
61
+ filenames.forEach(
62
+ (filename) => validateAbsolutePath(filename, messageFunc(filename))
63
+ );
64
+ };
65
+ const compile = (appDirectory, modernConfig, compileOptions) => __async(void 0, null, function* () {
66
+ var _a;
67
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
68
+ validateAbsolutePaths(
69
+ sourceDirs,
70
+ (dir) => `source dir ${dir} is not an absolute path.`
71
+ );
72
+ validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
73
+ const compiler = (_a = modernConfig == null ? void 0 : modernConfig.server) == null ? void 0 : _a.compiler;
74
+ const isTsProject = tsconfigPath && (yield import_utils.fs.pathExists(tsconfigPath));
75
+ if (!isTsProject || compiler === "babel") {
76
+ yield (0, import_babel.compileByBabel)(appDirectory, modernConfig, compileOptions);
77
+ } else {
78
+ yield (0, import_typescript.compileByTs)(appDirectory, modernConfig, compileOptions);
79
+ }
80
+ });
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ FILE_EXTENSIONS,
84
+ compile
85
+ });
@@ -0,0 +1,178 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
62
+ var babel_exports = {};
63
+ __export(babel_exports, {
64
+ compileByBabel: () => compileByBabel,
65
+ existTsConfigFile: () => existTsConfigFile,
66
+ getBabelConfig: () => getBabelConfig,
67
+ readTsConfig: () => readTsConfig,
68
+ resolveBabelConfig: () => resolveBabelConfig
69
+ });
70
+ module.exports = __toCommonJS(babel_exports);
71
+ var path = __toESM(require("path"));
72
+ var import_babel_preset_lib = require("@modern-js/babel-preset-lib");
73
+ var import_utils = require("@modern-js/utils");
74
+ var import_babel_compiler = require("@modern-js/babel-compiler");
75
+ var import_common = require("../../common");
76
+ __reExport(babel_exports, require("@babel/core"), module.exports);
77
+ const readTsConfig = (tsconfigPath, noExistReturn = null) => {
78
+ if (!import_utils.fs.existsSync(tsconfigPath)) {
79
+ return noExistReturn;
80
+ }
81
+ const content = import_utils.fs.readFileSync(tsconfigPath, "utf-8");
82
+ return import_utils.json5.parse(content);
83
+ };
84
+ const existTsConfigFile = (tsconfigAbsolutePath) => {
85
+ const tsconfig = readTsConfig(tsconfigAbsolutePath);
86
+ return Boolean(tsconfig);
87
+ };
88
+ const getBabelConfig = (libPresetOption, syntaxOption) => {
89
+ const chain = (0, import_babel_preset_lib.getBabelChain)(libPresetOption, syntaxOption);
90
+ return __spreadValues({
91
+ sourceType: "unambiguous"
92
+ }, chain.toJSON());
93
+ };
94
+ const resolveBabelConfig = (appDirectory, config, option) => {
95
+ const { globalVars, alias, babelConfig, define } = config;
96
+ const globalDefineVars = define && Object.entries(define).reduce((object, [key, value]) => {
97
+ object[key] = JSON.stringify(value);
98
+ return object;
99
+ }, {});
100
+ const aliasConfig = (0, import_utils.getAliasConfig)(alias, __spreadValues({
101
+ appDirectory
102
+ }, option));
103
+ const babelChain = (0, import_babel_preset_lib.getBabelChain)(
104
+ {
105
+ appDirectory,
106
+ enableReactPreset: true,
107
+ enableTypescriptPreset: true,
108
+ alias: aliasConfig,
109
+ envVars: [],
110
+ globalVars: __spreadValues(__spreadValues({}, globalVars), globalDefineVars)
111
+ },
112
+ {
113
+ type: option.type,
114
+ syntax: option.syntax
115
+ }
116
+ );
117
+ const envOptions = babelChain.preset("@babel/preset-env").options();
118
+ babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
119
+ __spreadProps(__spreadValues({}, envOptions[0]), {
120
+ loose: true
121
+ })
122
+ ]);
123
+ babelChain.plugin("babel-plugin-transform-typescript-metadata").use(
124
+ require.resolve("babel-plugin-transform-typescript-metadata"),
125
+ []
126
+ );
127
+ babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
128
+ { legacy: true }
129
+ ]);
130
+ babelChain.plugin("@babel/plugin-proposal-class-properties").use(require.resolve("@babel/plugin-proposal-class-properties"), [
131
+ {
132
+ loose: true
133
+ }
134
+ ]);
135
+ const internalBabelConfig = __spreadValues({}, babelChain.toJSON());
136
+ return (0, import_babel_preset_lib.applyUserBabelConfig)(internalBabelConfig, babelConfig);
137
+ };
138
+ const compileByBabel = (appDirectory, config, compileOptions) => __async(void 0, null, function* () {
139
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
140
+ const results = yield Promise.all(
141
+ sourceDirs.map((sourceDir) => __async(void 0, null, function* () {
142
+ const babelConfig = resolveBabelConfig(appDirectory, config, {
143
+ tsconfigPath: tsconfigPath ? tsconfigPath : "",
144
+ syntax: "es6+",
145
+ type: "commonjs"
146
+ });
147
+ if (yield import_utils.fs.pathExists(sourceDir)) {
148
+ const basename = path.basename(sourceDir);
149
+ const targetDir = path.join(distDir, basename);
150
+ yield import_utils.fs.copy(sourceDir, targetDir, {
151
+ filter: (src) => ![".ts", ".js"].includes(path.extname(src)) && src !== tsconfigPath
152
+ });
153
+ }
154
+ return (0, import_babel_compiler.compiler)(
155
+ {
156
+ rootDir: appDirectory,
157
+ distDir,
158
+ sourceDir,
159
+ extensions: import_common.FILE_EXTENSIONS
160
+ },
161
+ babelConfig
162
+ );
163
+ }))
164
+ );
165
+ results.forEach((result) => {
166
+ if (result.code === 1) {
167
+ throw new Error(result.message);
168
+ }
169
+ });
170
+ });
171
+ // Annotate the CommonJS export names for ESM import in node:
172
+ 0 && (module.exports = {
173
+ compileByBabel,
174
+ existTsConfigFile,
175
+ getBabelConfig,
176
+ readTsConfig,
177
+ resolveBabelConfig
178
+ });
@@ -0,0 +1,150 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var __async = (__this, __arguments, generator) => {
39
+ return new Promise((resolve, reject) => {
40
+ var fulfilled = (value) => {
41
+ try {
42
+ step(generator.next(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var rejected = (value) => {
48
+ try {
49
+ step(generator.throw(value));
50
+ } catch (e) {
51
+ reject(e);
52
+ }
53
+ };
54
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
+ step((generator = generator.apply(__this, __arguments)).next());
56
+ });
57
+ };
58
+ var typescript_exports = {};
59
+ __export(typescript_exports, {
60
+ compileByTs: () => compileByTs
61
+ });
62
+ module.exports = __toCommonJS(typescript_exports);
63
+ var import_path = __toESM(require("path"));
64
+ var import_utils = require("@modern-js/utils");
65
+ var import_typescript = __toESM(require("typescript"));
66
+ var import_typescript_loader = require("./typescript-loader");
67
+ var import_tsconfig_paths_plugin = require("./tsconfig-paths-plugin");
68
+ const readTsConfigByFile = (tsConfigFile) => {
69
+ const parsedCmd = import_typescript.default.getParsedCommandLineOfConfigFile(
70
+ tsConfigFile,
71
+ void 0,
72
+ import_typescript.default.sys
73
+ );
74
+ const { options, fileNames, projectReferences } = parsedCmd;
75
+ return { options, fileNames, projectReferences };
76
+ };
77
+ const copyFiles = (from, to, tsconfigPath) => __async(void 0, null, function* () {
78
+ if (yield import_utils.fs.pathExists(from)) {
79
+ const basename = import_path.default.basename(from);
80
+ const targetDir = import_path.default.join(to, basename);
81
+ yield import_utils.fs.copy(from, targetDir, {
82
+ filter: (src) => ![".ts"].includes(import_path.default.extname(src)) && src !== tsconfigPath
83
+ });
84
+ }
85
+ });
86
+ const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, null, function* () {
87
+ import_utils.logger.info(`Running ts compile...`);
88
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
89
+ if (!tsconfigPath) {
90
+ return;
91
+ }
92
+ const ts2 = new import_typescript_loader.TypescriptLoader({
93
+ appDirectory
94
+ }).load();
95
+ const createProgram = ts2.createIncrementalProgram || ts2.createProgram;
96
+ const formatHost = getFormatHost(ts2);
97
+ const { alias } = config;
98
+ const aliasOption = (0, import_utils.getAliasConfig)(alias, {
99
+ appDirectory,
100
+ tsconfigPath
101
+ });
102
+ const { paths = {}, absoluteBaseUrl = "./" } = aliasOption;
103
+ const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath);
104
+ const sourcePosixPaths = sourceDirs.map(
105
+ (sourceDir) => sourceDir.split(import_path.default.sep).join(import_path.default.posix.sep)
106
+ );
107
+ const rootNames = fileNames.filter((fileName) => {
108
+ return fileName.endsWith(".d.ts") || sourcePosixPaths.some((sourceDir) => {
109
+ return fileName.includes(sourceDir);
110
+ });
111
+ });
112
+ const program = createProgram.call(ts2, {
113
+ rootNames,
114
+ projectReferences,
115
+ options: __spreadValues({
116
+ rootDir: appDirectory,
117
+ outDir: distDir
118
+ }, options)
119
+ });
120
+ const tsconfigPathsPlugin = (0, import_tsconfig_paths_plugin.tsconfigPathsBeforeHookFactory)(
121
+ ts2,
122
+ absoluteBaseUrl,
123
+ paths
124
+ );
125
+ const emitResult = program.emit(void 0, void 0, void 0, void 0, {
126
+ before: [tsconfigPathsPlugin]
127
+ });
128
+ const allDiagnostics = ts2.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
129
+ if (allDiagnostics.length > 0) {
130
+ import_utils.logger.error(
131
+ ts2.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost)
132
+ );
133
+ process.exit(1);
134
+ }
135
+ for (const source of sourceDirs) {
136
+ yield copyFiles(source, distDir, tsconfigPath);
137
+ }
138
+ import_utils.logger.info(`Ts compile succeed`);
139
+ });
140
+ const getFormatHost = (ts2) => {
141
+ return {
142
+ getCanonicalFileName: (path2) => path2,
143
+ getCurrentDirectory: ts2.sys.getCurrentDirectory,
144
+ getNewLine: () => ts2.sys.newLine
145
+ };
146
+ };
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ compileByTs
150
+ });
@@ -0,0 +1,216 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var tsconfig_paths_plugin_exports = {};
25
+ __export(tsconfig_paths_plugin_exports, {
26
+ tsconfigPathsBeforeHookFactory: () => tsconfigPathsBeforeHookFactory
27
+ });
28
+ module.exports = __toCommonJS(tsconfig_paths_plugin_exports);
29
+ var os = __toESM(require("os"));
30
+ var import_path = __toESM(require("path"));
31
+ var ts = __toESM(require("typescript"));
32
+ var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
33
+ const isRegExpKey = (str) => {
34
+ return str.startsWith("^") || str.endsWith("$");
35
+ };
36
+ const resolveAliasPath = (baseUrl, filePath) => {
37
+ if (filePath.startsWith(".") || filePath.startsWith("..")) {
38
+ return import_path.default.resolve(baseUrl, filePath);
39
+ }
40
+ return filePath;
41
+ };
42
+ const createAliasMatcher = (baseUrl, alias) => {
43
+ const aliasPairs = Object.keys(alias).reduce((o, key) => {
44
+ if (isRegExpKey(key)) {
45
+ const regexp = new RegExp(key);
46
+ const aliasPath = resolveAliasPath(baseUrl, alias[key]);
47
+ o.push([regexp, aliasPath]);
48
+ } else {
49
+ const aliasPath = resolveAliasPath(baseUrl, alias[key]);
50
+ o.push([key, aliasPath]);
51
+ }
52
+ return o;
53
+ }, []);
54
+ const cacheMap = /* @__PURE__ */ new Map();
55
+ return (requestedModule) => {
56
+ if (cacheMap.has(requestedModule)) {
57
+ return cacheMap.get(requestedModule);
58
+ }
59
+ for (const [key, value] of aliasPairs) {
60
+ if (key instanceof RegExp) {
61
+ if (key.test(requestedModule)) {
62
+ cacheMap.set(requestedModule, value);
63
+ return value;
64
+ }
65
+ }
66
+ if (requestedModule === key) {
67
+ cacheMap.set(requestedModule, value);
68
+ return value;
69
+ }
70
+ }
71
+ };
72
+ };
73
+ const isDynamicImport = (tsBinary, node) => {
74
+ return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
75
+ };
76
+ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
77
+ const tsPaths = {};
78
+ const alias = {};
79
+ Object.keys(paths).forEach((key) => {
80
+ if (Array.isArray(paths[key])) {
81
+ tsPaths[key] = paths[key];
82
+ } else {
83
+ alias[key] = paths[key];
84
+ }
85
+ });
86
+ const matchAliasPath = createAliasMatcher(baseUrl, alias);
87
+ const matchTsPath = (0, import_tsconfig_paths.createMatchPath)(baseUrl, tsPaths, ["main"]);
88
+ const matchPath = (requestedModule, readJSONSync, fileExists, extensions) => {
89
+ const result = matchTsPath(
90
+ requestedModule,
91
+ readJSONSync,
92
+ fileExists,
93
+ extensions
94
+ );
95
+ if (result) {
96
+ return result;
97
+ }
98
+ return matchAliasPath(requestedModule);
99
+ };
100
+ if (Object.keys(paths).length === 0) {
101
+ return void 0;
102
+ }
103
+ return (ctx) => {
104
+ return (sf) => {
105
+ const visitNode = (node) => {
106
+ var _a;
107
+ if (isDynamicImport(tsBinary, node)) {
108
+ const importPathWithQuotes = node.arguments[0].getText(sf);
109
+ const text = importPathWithQuotes.slice(
110
+ 1,
111
+ importPathWithQuotes.length - 1
112
+ );
113
+ const result = getNotAliasedPath(sf, matchPath, text);
114
+ if (!result) {
115
+ return node;
116
+ }
117
+ return tsBinary.factory.updateCallExpression(
118
+ node,
119
+ node.expression,
120
+ node.typeArguments,
121
+ tsBinary.factory.createNodeArray([
122
+ tsBinary.factory.createStringLiteral(result)
123
+ ])
124
+ );
125
+ }
126
+ if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
127
+ try {
128
+ const importPathWithQuotes = (_a = node == null ? void 0 : node.moduleSpecifier) == null ? void 0 : _a.getText();
129
+ if (!importPathWithQuotes) {
130
+ return node;
131
+ }
132
+ const text = importPathWithQuotes.substring(
133
+ 1,
134
+ importPathWithQuotes.length - 1
135
+ );
136
+ const result = getNotAliasedPath(sf, matchPath, text);
137
+ if (!result) {
138
+ return node;
139
+ }
140
+ const moduleSpecifier = tsBinary.factory.createStringLiteral(result);
141
+ moduleSpecifier.parent = node.moduleSpecifier.parent;
142
+ let newNode;
143
+ if (tsBinary.isImportDeclaration(node)) {
144
+ newNode = tsBinary.factory.updateImportDeclaration(
145
+ node,
146
+ node.decorators,
147
+ node.modifiers,
148
+ node.importClause,
149
+ moduleSpecifier,
150
+ node.assertClause
151
+ );
152
+ } else {
153
+ newNode = tsBinary.factory.updateExportDeclaration(
154
+ node,
155
+ node.decorators,
156
+ node.modifiers,
157
+ node.isTypeOnly,
158
+ node.exportClause,
159
+ moduleSpecifier,
160
+ node.assertClause
161
+ );
162
+ }
163
+ newNode.flags = node.flags;
164
+ return newNode;
165
+ } catch (e) {
166
+ return node;
167
+ }
168
+ }
169
+ return tsBinary.visitEachChild(node, visitNode, ctx);
170
+ };
171
+ return tsBinary.visitNode(sf, visitNode);
172
+ };
173
+ };
174
+ }
175
+ function getNotAliasedPath(sf, matcher, text) {
176
+ let result = matcher(text, void 0, void 0, [
177
+ ".ts",
178
+ ".tsx",
179
+ ".js",
180
+ ".jsx"
181
+ ]);
182
+ if (!result) {
183
+ return;
184
+ }
185
+ if (os.platform() === "win32") {
186
+ result = result.replace(/\\/g, "/");
187
+ }
188
+ if (!import_path.default.isAbsolute(result)) {
189
+ if (!result.startsWith(".") && !result.startsWith("..")) {
190
+ try {
191
+ const packagePath = require.resolve(result, {
192
+ paths: [process.cwd(), ...module.paths]
193
+ });
194
+ if (packagePath) {
195
+ return result;
196
+ }
197
+ } catch (e) {
198
+ }
199
+ }
200
+ try {
201
+ const packagePath = require.resolve(text, {
202
+ paths: [process.cwd(), ...module.paths]
203
+ });
204
+ if (packagePath) {
205
+ return text;
206
+ }
207
+ } catch (e) {
208
+ }
209
+ }
210
+ const resolvedPath = import_path.posix.relative((0, import_path.dirname)(sf.fileName), result) || "./";
211
+ return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
212
+ }
213
+ // Annotate the CommonJS export names for ESM import in node:
214
+ 0 && (module.exports = {
215
+ tsconfigPathsBeforeHookFactory
216
+ });
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var typescript_loader_exports = {};
19
+ __export(typescript_loader_exports, {
20
+ TypescriptLoader: () => TypescriptLoader
21
+ });
22
+ module.exports = __toCommonJS(typescript_loader_exports);
23
+ class TypescriptLoader {
24
+ constructor({ appDirectory }) {
25
+ this.appDirectory = appDirectory;
26
+ }
27
+ load() {
28
+ if (this.tsBinary) {
29
+ return this.tsBinary;
30
+ }
31
+ try {
32
+ const tsPath = require.resolve("typescript", {
33
+ paths: [this.appDirectory || process.cwd()]
34
+ });
35
+ const ts = require(tsPath);
36
+ return ts;
37
+ } catch (error) {
38
+ throw new Error(
39
+ 'TypeScript could not be found! Please, install "typescript" package.'
40
+ );
41
+ }
42
+ }
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ TypescriptLoader
47
+ });