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.
@@ -12,6 +12,12 @@ app.use("/", wurzel({ express, baseFolder: rootFolder }));
12
12
 
13
13
  const port = 8080;
14
14
 
15
- app.listen(port, () => {
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
  });
@@ -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, fileEndings, maxAnalyzeCacheSize, maxTranspileCacheSize, resolveImportPath }: {
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 isScript = fileEndings.some((ending) => req.url.endsWith(ending));
235
- if (isScript) {
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
  };*/
@@ -4,6 +4,7 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Hello World</title>
7
+ <script src="index.ts" type="module"></script>
7
8
  </head>
8
9
  <body>
9
10
  <h1>Hello World!</h1>
@@ -0,0 +1,5 @@
1
+ type TMyType = "a" | "b" | "c";
2
+
3
+ const x: TMyType = "a";
4
+
5
+ console.log("Hello from TypeScript!", { x });
@@ -30,7 +30,6 @@ const app = express();
30
30
  app.use("/", wurzelExpressRouter({
31
31
  express,
32
32
  baseFolder,
33
- fileEndings: [".ts", ".js", ".mjs"],
34
33
  resolveImportPath
35
34
  }));
36
35
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.10",
2
+ "version": "0.0.11",
3
3
  "name": "wurzel",
4
4
  "type": "module",
5
5
  "description": "A tool to serve script files from different directories",