owebjs 1.3.5 → 1.3.7
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/utils/generateFunctionFromTypescript.js +64 -16
- package/dist/uws_darwin_arm64_108.node +0 -0
- package/dist/uws_darwin_arm64_83.node +0 -0
- package/dist/uws_darwin_arm64_93.node +0 -0
- package/dist/uws_darwin_x64_108.node +0 -0
- package/dist/uws_darwin_x64_83.node +0 -0
- package/dist/uws_darwin_x64_93.node +0 -0
- package/dist/uws_linux_arm64_108.node +0 -0
- package/dist/uws_linux_arm64_83.node +0 -0
- package/dist/uws_linux_arm64_93.node +0 -0
- package/dist/uws_linux_x64_108.node +0 -0
- package/dist/uws_linux_x64_83.node +0 -0
- package/dist/uws_linux_x64_93.node +0 -0
- package/dist/uws_win32_x64_108.node +0 -0
- package/dist/uws_win32_x64_83.node +0 -0
- package/dist/uws_win32_x64_93.node +0 -0
- package/package.json +2 -2
|
@@ -7,13 +7,54 @@ import generate from "@babel/generator";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import babel from "@babel/core";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
|
-
import { writeFile, unlink } from "node:fs/promises";
|
|
10
|
+
import { writeFile, unlink, readFile } from "node:fs/promises";
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
11
12
|
import { tmpdir } from "node:os";
|
|
12
13
|
import { randomBytes } from "node:crypto";
|
|
13
14
|
import { createRequire } from "node:module";
|
|
14
15
|
import { error } from './logger.js';
|
|
15
16
|
const require2 = createRequire(import.meta.url);
|
|
17
|
+
async function getAliasesFromTsConfig(tsConfigPath) {
|
|
18
|
+
if (!existsSync(tsConfigPath)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const tsConfigFile = await readFile(tsConfigPath, "utf-8");
|
|
23
|
+
const json = JSON.parse(tsConfigFile.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, ""));
|
|
24
|
+
const compilerOptions = json.compilerOptions || {};
|
|
25
|
+
const baseUrl = path.resolve(path.dirname(tsConfigPath), compilerOptions.baseUrl || ".");
|
|
26
|
+
const paths = compilerOptions.paths || {};
|
|
27
|
+
return {
|
|
28
|
+
paths,
|
|
29
|
+
baseUrl
|
|
30
|
+
};
|
|
31
|
+
} catch (error2) {
|
|
32
|
+
console.error("Error reading or parsing tsconfig.json:", error2);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
__name(getAliasesFromTsConfig, "getAliasesFromTsConfig");
|
|
37
|
+
function resolveAlias(importPath, tsConfigPaths, baseUrl) {
|
|
38
|
+
for (const alias in tsConfigPaths) {
|
|
39
|
+
const aliasPattern = new RegExp(`^${alias.replace("*", "(.*)")}$`);
|
|
40
|
+
const match = importPath.match(aliasPattern);
|
|
41
|
+
if (match) {
|
|
42
|
+
const [_fullMatch, restOfPath] = match;
|
|
43
|
+
const targetPaths = tsConfigPaths[alias];
|
|
44
|
+
const targetPath = targetPaths[0];
|
|
45
|
+
if (!alias.endsWith("*")) {
|
|
46
|
+
return path.resolve(baseUrl, targetPath);
|
|
47
|
+
}
|
|
48
|
+
const resolvedPath = targetPath.replace("*", restOfPath);
|
|
49
|
+
return path.resolve(baseUrl, resolvedPath);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
__name(resolveAlias, "resolveAlias");
|
|
16
55
|
async function generateFunctionFromTypescript(tsCode, filePath) {
|
|
56
|
+
const tsConfigPath = path.join(process.cwd(), "tsconfig.json");
|
|
57
|
+
const tsConfig = await getAliasesFromTsConfig(tsConfigPath);
|
|
17
58
|
const result = babel.transformSync(tsCode, {
|
|
18
59
|
presets: [
|
|
19
60
|
"@babel/preset-typescript"
|
|
@@ -24,32 +65,39 @@ async function generateFunctionFromTypescript(tsCode, filePath) {
|
|
|
24
65
|
const ast = parse(jsCode, {
|
|
25
66
|
sourceType: "module"
|
|
26
67
|
});
|
|
68
|
+
const fileDir = path.dirname(filePath);
|
|
27
69
|
traverse.default(ast, {
|
|
28
70
|
ImportDeclaration(astPath) {
|
|
29
71
|
const importSourceNode = astPath.node.source;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
72
|
+
const importPath = importSourceNode.value;
|
|
73
|
+
let resolvedUrl = null;
|
|
74
|
+
if (tsConfig && tsConfig.paths) {
|
|
75
|
+
const resolvedAliasPath = resolveAlias(importPath, tsConfig.paths, tsConfig.baseUrl);
|
|
76
|
+
if (resolvedAliasPath) {
|
|
77
|
+
const finalPath = path.extname(resolvedAliasPath) === "" ? resolvedAliasPath + ".ts" : resolvedAliasPath;
|
|
78
|
+
resolvedUrl = pathToFileURL(finalPath).href;
|
|
35
79
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
80
|
+
}
|
|
81
|
+
if (!resolvedUrl && importPath.startsWith(".")) {
|
|
82
|
+
const resolvedPathWithExt = path.extname(importPath) === "" ? importPath + ".ts" : importPath;
|
|
83
|
+
const absoluteDepPath = path.resolve(fileDir, resolvedPathWithExt);
|
|
84
|
+
resolvedUrl = pathToFileURL(absoluteDepPath).href;
|
|
85
|
+
}
|
|
86
|
+
if (!resolvedUrl) {
|
|
41
87
|
try {
|
|
42
|
-
const
|
|
88
|
+
const resolvedNodeModulePath = require2.resolve(importPath, {
|
|
43
89
|
paths: [
|
|
44
|
-
|
|
90
|
+
fileDir
|
|
45
91
|
]
|
|
46
92
|
});
|
|
47
|
-
|
|
48
|
-
importSourceNode.value = resolvedUrl;
|
|
93
|
+
resolvedUrl = pathToFileURL(resolvedNodeModulePath).href;
|
|
49
94
|
} catch (_) {
|
|
50
|
-
error(`Could not resolve
|
|
95
|
+
error(`Could not resolve import path for: ${importPath} in ${filePath}.`, "HMR");
|
|
51
96
|
}
|
|
52
97
|
}
|
|
98
|
+
if (resolvedUrl) {
|
|
99
|
+
importSourceNode.value = resolvedUrl;
|
|
100
|
+
}
|
|
53
101
|
}
|
|
54
102
|
});
|
|
55
103
|
const { code: modifiedCode } = generate.default(ast);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owebjs",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "A flexible and modern web framework built on top of Fastify",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"start": "node .",
|
|
21
|
-
"build": "tsup",
|
|
21
|
+
"build": "tsup && node scripts/copyBinaries",
|
|
22
22
|
"dev": "tsup && node .",
|
|
23
23
|
"test": "tsup && node scripts/copyBinaries && node test/index.js",
|
|
24
24
|
"format": "prettier --write . --ignore-path .gitignore"
|