wurzel 0.0.5 → 0.0.6
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/lib/index.d.ts +6 -2
- package/dist/lib/index.js +39 -20
- package/package.json +2 -2
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { TResolveImportPathFunc } from "es6-debug-server";
|
|
1
2
|
import type Express from "express";
|
|
2
|
-
declare const
|
|
3
|
+
declare const defaultResolveImportPath: TResolveImportPathFunc;
|
|
4
|
+
declare const expressRouter: ({ express, baseFolder, fileEndings, maxAnalyzeCacheSize, maxTranspileCacheSize, resolveImportPath }: {
|
|
3
5
|
express: typeof Express;
|
|
4
6
|
baseFolder: string;
|
|
5
7
|
fileEndings?: string[];
|
|
6
8
|
maxAnalyzeCacheSize?: number;
|
|
7
9
|
maxTranspileCacheSize?: number;
|
|
10
|
+
resolveImportPath?: TResolveImportPathFunc;
|
|
8
11
|
}) => any;
|
|
9
|
-
export { expressRouter, };
|
|
12
|
+
export { expressRouter, defaultResolveImportPath };
|
|
13
|
+
export type { TResolveImportPathFunc };
|
package/dist/lib/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
create as createServer,
|
|
3
|
+
ETryReadErrorCode,
|
|
4
|
+
defaultCodeAnalyzer
|
|
5
|
+
} from "es6-debug-server";
|
|
6
|
+
/*import type {
|
|
7
|
+
ICodeAnalyzeResult,
|
|
8
|
+
TResolveImportPathFunc,
|
|
9
|
+
} from "es6-debug-server";*/
|
|
2
10
|
import { readFile } from "node:fs/promises";
|
|
3
11
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
4
12
|
import { createHash } from "node:crypto";
|
|
@@ -6,7 +14,6 @@ import { resolve as resolveImport } from "import-meta-resolve";
|
|
|
6
14
|
// @ts-expect-error missing types
|
|
7
15
|
import { transpileCode } from "commentscript";
|
|
8
16
|
import { LRUCache } from "lru-cache";
|
|
9
|
-
/*import type { ICodeAnalyzeResult } from "es6-debug-server";*/
|
|
10
17
|
/*import type Express from "express";*/
|
|
11
18
|
|
|
12
19
|
const md5 = ({ content }/*: { content: string }*/) => {
|
|
@@ -25,6 +32,25 @@ const md5 = ({ content }/*: { content: string }*/) => {
|
|
|
25
32
|
|
|
26
33
|
/*type TTranspileResult = ITranspileErrorResult | ITranspileSuccessResult;*/
|
|
27
34
|
|
|
35
|
+
const defaultResolveImportPath/*: TResolveImportPathFunc*/ = async ({ importer, specifier }) => {
|
|
36
|
+
const parentUrl = pathToFileURL(importer);
|
|
37
|
+
let resolvedUrl/*: string | undefined*/ = undefined;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
resolvedUrl = resolveImport(specifier, parentUrl.toString());
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
error: error/* as Error*/
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const resolvedPath = fileURLToPath(resolvedUrl);
|
|
48
|
+
return {
|
|
49
|
+
error: undefined,
|
|
50
|
+
filePath: resolvedPath
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
28
54
|
const expressRouter = ({
|
|
29
55
|
express,
|
|
30
56
|
baseFolder,
|
|
@@ -32,6 +58,8 @@ const expressRouter = ({
|
|
|
32
58
|
|
|
33
59
|
maxAnalyzeCacheSize = 1 * 1024 * 1024,
|
|
34
60
|
maxTranspileCacheSize = 64 * 1024 * 1024,
|
|
61
|
+
|
|
62
|
+
resolveImportPath = defaultResolveImportPath
|
|
35
63
|
}/*: {
|
|
36
64
|
express: typeof Express,
|
|
37
65
|
baseFolder: string,
|
|
@@ -39,6 +67,8 @@ const expressRouter = ({
|
|
|
39
67
|
|
|
40
68
|
maxAnalyzeCacheSize?: number,
|
|
41
69
|
maxTranspileCacheSize?: number,
|
|
70
|
+
|
|
71
|
+
resolveImportPath?: TResolveImportPathFunc
|
|
42
72
|
}*/) => {
|
|
43
73
|
|
|
44
74
|
const router = express.Router();
|
|
@@ -174,24 +204,7 @@ const expressRouter = ({
|
|
|
174
204
|
return analyzeResult;
|
|
175
205
|
},
|
|
176
206
|
|
|
177
|
-
resolveImportPath
|
|
178
|
-
const parentUrl = pathToFileURL(importer);
|
|
179
|
-
let resolvedUrl/*: string | undefined*/ = undefined;
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
resolvedUrl = resolveImport(specifier, parentUrl.toString());
|
|
183
|
-
} catch (error) {
|
|
184
|
-
return {
|
|
185
|
-
error: error/* as Error*/
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const resolvedPath = fileURLToPath(resolvedUrl);
|
|
190
|
-
return {
|
|
191
|
-
error: undefined,
|
|
192
|
-
filePath: resolvedPath
|
|
193
|
-
};
|
|
194
|
-
},
|
|
207
|
+
resolveImportPath
|
|
195
208
|
});
|
|
196
209
|
|
|
197
210
|
router.use((req, res, next) => {
|
|
@@ -241,4 +254,10 @@ const expressRouter = ({
|
|
|
241
254
|
|
|
242
255
|
export {
|
|
243
256
|
expressRouter,
|
|
257
|
+
|
|
258
|
+
defaultResolveImportPath
|
|
244
259
|
};
|
|
260
|
+
|
|
261
|
+
/*export type {
|
|
262
|
+
TResolveImportPathFunc
|
|
263
|
+
};*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wurzel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"main": "dist/lib/index.js",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"commentscript": "^0.0.5",
|
|
11
|
-
"es6-debug-server": "^0.0.
|
|
11
|
+
"es6-debug-server": "^0.0.4",
|
|
12
12
|
"esm-resource": "^0.0.1",
|
|
13
13
|
"express": "^4.19.2",
|
|
14
14
|
"import-meta-resolve": "^4.0.0",
|