wurzel 0.0.10 → 0.0.11
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/bin/wurzel.js
CHANGED
|
@@ -12,6 +12,12 @@ app.use("/", wurzel({ express, baseFolder: rootFolder }));
|
|
|
12
12
|
|
|
13
13
|
const port = 8080;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// @ts-expect-error wrong type definition for listen callback
|
|
16
|
+
app.listen(port, (err/*: Error*/) => {
|
|
17
|
+
if (err) {
|
|
18
|
+
console.error("Error starting server:", err);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
console.log(`listening on :${port}`);
|
|
17
23
|
});
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { TResolveImportPathFunc } from "es6-debug-server";
|
|
2
2
|
import type Express from "express";
|
|
3
|
+
type TFileType = "script" | "script-resource" | "other";
|
|
3
4
|
declare const defaultResolveImportPath: TResolveImportPathFunc;
|
|
4
|
-
declare const expressRouter: ({ express, baseFolder,
|
|
5
|
+
declare const expressRouter: ({ express, baseFolder, maxAnalyzeCacheSize, maxTranspileCacheSize, determineFileTypeByPath, resolveImportPath }: {
|
|
5
6
|
express: typeof Express;
|
|
6
7
|
baseFolder: string;
|
|
7
|
-
fileEndings?: string[];
|
|
8
8
|
maxAnalyzeCacheSize?: number;
|
|
9
9
|
maxTranspileCacheSize?: number;
|
|
10
|
+
determineFileTypeByPath?: (args: {
|
|
11
|
+
filePath: string;
|
|
12
|
+
}) => TFileType;
|
|
10
13
|
resolveImportPath?: TResolveImportPathFunc;
|
|
11
14
|
}) => any;
|
|
12
15
|
export { expressRouter, defaultResolveImportPath };
|
|
13
|
-
export type { TResolveImportPathFunc };
|
|
16
|
+
export type { TResolveImportPathFunc, TFileType };
|
package/dist/lib/index.js
CHANGED
|
@@ -33,6 +33,8 @@ const md5 = ({ content }/*: { content: string }*/) => {
|
|
|
33
33
|
|
|
34
34
|
/*type TTranspileResult = ITranspileErrorResult | ITranspileSuccessResult;*/
|
|
35
35
|
|
|
36
|
+
/*type TFileType = "script" | "script-resource" | "other";*/
|
|
37
|
+
|
|
36
38
|
const defaultResolveImportPath/*: TResolveImportPathFunc*/ = async ({ importer, specifier }) => {
|
|
37
39
|
const parentUrl = pathToFileURL(importer);
|
|
38
40
|
// eslint-disable-next-line no-useless-assignment
|
|
@@ -65,23 +67,38 @@ const defaultResolveImportPath/*: TResolveImportPathFunc*/ = async ({ importer,
|
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
69
|
|
|
70
|
+
const defaultScriptFileEndings = [".js", ".ts", ".cjs", ".mjs", ".cts", ".mts"];
|
|
71
|
+
|
|
72
|
+
const defaultDetermineFileTypeByPath = ({ filePath }/*: { filePath: string }*/)/*: TFileType*/ => {
|
|
73
|
+
const isScript = defaultScriptFileEndings.some((ending) => {
|
|
74
|
+
return filePath.endsWith(ending);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (isScript) {
|
|
78
|
+
return "script";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return "other";
|
|
82
|
+
};
|
|
83
|
+
|
|
68
84
|
const expressRouter = ({
|
|
69
85
|
express,
|
|
70
86
|
baseFolder,
|
|
71
|
-
fileEndings = [".js", ".ts"],
|
|
72
87
|
|
|
73
88
|
maxAnalyzeCacheSize = 1 * 1024 * 1024,
|
|
74
89
|
maxTranspileCacheSize = 64 * 1024 * 1024,
|
|
75
90
|
|
|
91
|
+
determineFileTypeByPath = defaultDetermineFileTypeByPath,
|
|
76
92
|
resolveImportPath = defaultResolveImportPath
|
|
77
93
|
}/*: {
|
|
78
94
|
express: typeof Express,
|
|
79
95
|
baseFolder: string,
|
|
80
|
-
fileEndings?: string[],
|
|
81
96
|
|
|
82
97
|
maxAnalyzeCacheSize?: number,
|
|
83
98
|
maxTranspileCacheSize?: number,
|
|
84
99
|
|
|
100
|
+
// eslint-disable-next-line no-unused-vars
|
|
101
|
+
determineFileTypeByPath?: (args: { filePath: string }) => TFileType,
|
|
85
102
|
resolveImportPath?: TResolveImportPathFunc
|
|
86
103
|
// eslint-disable-next-line complexity
|
|
87
104
|
}*/) => {
|
|
@@ -231,8 +248,13 @@ const expressRouter = ({
|
|
|
231
248
|
throw Error("HEAD not supported yet");
|
|
232
249
|
}
|
|
233
250
|
|
|
234
|
-
const
|
|
235
|
-
|
|
251
|
+
const fileType = determineFileTypeByPath({ filePath: req.url });
|
|
252
|
+
|
|
253
|
+
if (fileType === "script-resource") {
|
|
254
|
+
throw Error(`file type ${fileType} is not supported yet`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (fileType === "script") {
|
|
236
258
|
|
|
237
259
|
server.handleRequest({
|
|
238
260
|
uri: req.url,
|
|
@@ -277,5 +299,6 @@ export {
|
|
|
277
299
|
};
|
|
278
300
|
|
|
279
301
|
/*export type {
|
|
280
|
-
TResolveImportPathFunc
|
|
302
|
+
TResolveImportPathFunc,
|
|
303
|
+
TFileType
|
|
281
304
|
};*/
|
package/package.json
CHANGED