wurzel 0.0.9 → 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,15 +33,18 @@ 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);
40
+ // eslint-disable-next-line no-useless-assignment
38
41
  let resolvedUrl/*: string | undefined*/ = undefined;
39
42
 
40
43
  try {
41
44
  resolvedUrl = resolveImport(specifier, parentUrl.toString());
42
45
  } catch (error) {
43
46
  return {
44
- error: error/* as Error*/
47
+ error: error /*as Error*/
45
48
  };
46
49
  }
47
50
 
@@ -64,24 +67,40 @@ const defaultResolveImportPath/*: TResolveImportPathFunc*/ = async ({ importer,
64
67
  };
65
68
  };
66
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
+
67
84
  const expressRouter = ({
68
85
  express,
69
86
  baseFolder,
70
- fileEndings = [".js", ".ts"],
71
87
 
72
88
  maxAnalyzeCacheSize = 1 * 1024 * 1024,
73
89
  maxTranspileCacheSize = 64 * 1024 * 1024,
74
90
 
91
+ determineFileTypeByPath = defaultDetermineFileTypeByPath,
75
92
  resolveImportPath = defaultResolveImportPath
76
93
  }/*: {
77
94
  express: typeof Express,
78
95
  baseFolder: string,
79
- fileEndings?: string[],
80
96
 
81
97
  maxAnalyzeCacheSize?: number,
82
98
  maxTranspileCacheSize?: number,
83
99
 
100
+ // eslint-disable-next-line no-unused-vars
101
+ determineFileTypeByPath?: (args: { filePath: string }) => TFileType,
84
102
  resolveImportPath?: TResolveImportPathFunc
103
+ // eslint-disable-next-line complexity
85
104
  }*/) => {
86
105
 
87
106
  const router = express.Router();
@@ -119,6 +138,7 @@ const expressRouter = ({
119
138
  };
120
139
  }
121
140
 
141
+ // eslint-disable-next-line no-useless-assignment
122
142
  let transpiled/*: string | undefined*/ = undefined;
123
143
 
124
144
  try {
@@ -126,7 +146,7 @@ const expressRouter = ({
126
146
  transpiled = result.transpiledCode;
127
147
  } catch (ex) {
128
148
  return {
129
- error: ex/* as Error*/,
149
+ error: ex /*as Error*/,
130
150
  };
131
151
  }
132
152
 
@@ -228,8 +248,13 @@ const expressRouter = ({
228
248
  throw Error("HEAD not supported yet");
229
249
  }
230
250
 
231
- const isScript = fileEndings.some((ending) => req.url.endsWith(ending));
232
- 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") {
233
258
 
234
259
  server.handleRequest({
235
260
  uri: req.url,
@@ -274,5 +299,6 @@ export {
274
299
  };
275
300
 
276
301
  /*export type {
277
- TResolveImportPathFunc
302
+ TResolveImportPathFunc,
303
+ TFileType
278
304
  };*/
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Hello World</title>
7
+ <script src="index.ts" type="module"></script>
8
+ </head>
9
+ <body>
10
+ <h1>Hello World!</h1>
11
+ </body>
12
+ </html>
@@ -0,0 +1,5 @@
1
+ type TMyType = "a" | "b" | "c";
2
+
3
+ const x: TMyType = "a";
4
+
5
+ console.log("Hello from TypeScript!", { x });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import {
2
+ expressRouter as wurzelExpressRouter,
3
+ defaultResolveImportPath,
4
+ /*type TResolveImportPathFunc
5
+ */} from "../../lib/index.js";
6
+ import nodePath from "node:path";
7
+ import { resolve } from "esm-resource";
8
+ import express from "express";
9
+
10
+ const relativePath = ({ filepath }/*: { filepath: string }*/) => {
11
+ return nodePath.resolve(resolve({ importMeta: import.meta, filepath }));
12
+ };
13
+
14
+ const baseFolder = relativePath({ filepath: "./frontend" });
15
+
16
+ const resolveImportPath/*: TResolveImportPathFunc*/ = async ({ importer, specifier }) => {
17
+ if (specifier === "vue") {
18
+ return {
19
+ error: undefined,
20
+ // this is only an example, it is neither installed nor used in this sample
21
+ filePath: relativePath({ filepath: "../node_modules/vue/dist/vue.esm-browser.js" })
22
+ };
23
+ }
24
+
25
+ return defaultResolveImportPath({ importer, specifier });
26
+ };
27
+
28
+ const app = express();
29
+
30
+ app.use("/", wurzelExpressRouter({
31
+ express,
32
+ baseFolder,
33
+ resolveImportPath
34
+ }));
35
+
36
+ const port = 8080;
37
+
38
+ app.listen(port, () => {
39
+ console.log(`listening on :${port}`);
40
+ });
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
+ "version": "0.0.11",
2
3
  "name": "wurzel",
3
- "version": "0.0.9",
4
4
  "type": "module",
5
+ "description": "A tool to serve script files from different directories",
5
6
  "files": [
6
7
  "dist"
7
8
  ],
@@ -9,34 +10,41 @@
9
10
  "dependencies": {
10
11
  "commentscript": "^0.0.10",
11
12
  "es6-debug-server": "^0.0.9",
12
- "esm-resource": "^0.0.1",
13
- "express": "^4.19.2",
13
+ "esm-resource": "^0.0.3",
14
14
  "import-meta-resolve": "^4.0.0",
15
15
  "lru-cache": "^10.2.1"
16
16
  },
17
17
  "devDependencies": {
18
- "@eslint/js": "^9.7.0",
18
+ "@eslint/js": "^10.0.1",
19
+ "@k13engineering/releasetool": "^0.0.5",
19
20
  "@types/express": "^4.17.21",
20
21
  "@types/node": "^20.12.7",
21
- "deno-node": "^0.0.5",
22
- "typescript-eslint": "^7.16.1"
22
+ "deno-node": "^0.0.12",
23
+ "express": "^5.2.1",
24
+ "npm-check-updates": "^20.0.2",
25
+ "typescript-eslint": "^8.58.2"
23
26
  },
24
27
  "bin": {
25
28
  "wurzel": "dist/bin/wurzel.js"
26
29
  },
27
30
  "scripts": {
28
- "build": "rm -rf dist/ && deno-node-build --root . --out dist/ --entry lib/index.ts --entry bin/wurzel.ts",
31
+ "build": "rm -rf dist/ && deno-node-build --root . --out dist/ --entry lib/index.ts --entry bin/wurzel.ts --entry samples/express/main.ts && cp -r samples/express/frontend dist/samples/express/",
29
32
  "lint": "eslint .",
30
- "test": "true"
33
+ "test": "true",
34
+ "type-check": "tsc --noEmit",
35
+ "update-deps": "npm-check-updates -u"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
31
39
  },
32
40
  "author": "Simon Kadisch",
33
- "license": "LGPL-2.1",
34
- "repository": {
35
- "type": "git",
36
- "url": "git+https://github.com/k13-engineering/wurzel.git"
37
- },
38
- "bugs": {
39
- "url": "https://github.com/k13-engineering/wurzel/issues"
40
- },
41
- "homepage": "https://github.com/k13-engineering/wurzel#readme"
41
+ "license": "LGPL-2.1",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/k13-engineering/wurzel.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/k13-engineering/wurzel/issues"
48
+ },
49
+ "homepage": "https://github.com/k13-engineering/wurzel#readme"
42
50
  }