@tsed/platform-express 8.13.1 → 8.13.2

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.
@@ -1,11 +1,12 @@
1
1
  import "@tsed/platform-multer/express";
2
+ import { readFileSync } from "node:fs";
3
+ import { dirname } from "node:path";
2
4
  import { catchAsyncError, Env, isFunction } from "@tsed/core";
3
5
  import { constant, inject, logger, runInContext } from "@tsed/di";
4
6
  import { PlatformExceptions } from "@tsed/platform-exceptions";
5
7
  import { adapter, application, createContext, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformResponse } from "@tsed/platform-http";
6
8
  import { PlatformHandlerType } from "@tsed/platform-router";
7
9
  import Express from "express";
8
- import { version } from "express/package.json" with { type: "json" };
9
10
  import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
10
11
  import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
11
12
  import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
@@ -15,6 +16,15 @@ function callNext(next, metadata, $ctx) {
15
16
  return next && $ctx.error && !$ctx.isDone() ? next($ctx.error) : next();
16
17
  }
17
18
  }
19
+ function getVersion() {
20
+ try {
21
+ const { version } = JSON.parse(readFileSync(dirname(import.meta.resolve("express")) + "package.json", "utf8"));
22
+ return `v${version.split(".")[0]}`;
23
+ }
24
+ catch (er) {
25
+ return "v4";
26
+ }
27
+ }
18
28
  /**
19
29
  * @platform
20
30
  * @express
@@ -69,10 +79,10 @@ export class PlatformExpress extends PlatformAdapter {
69
79
  }
70
80
  mapLayers(layers) {
71
81
  const rawApp = this.app.getApp();
72
- const v = `v${version.split(".")[0]}`;
82
+ const version = getVersion();
73
83
  layers.forEach((layer) => {
74
84
  const handlers = layer.getArgs(false);
75
- const { path, wildcard } = convertPath(layer.path, v);
85
+ const { path, wildcard } = convertPath(layer.path, version);
76
86
  layer.path = path;
77
87
  if (layer.method === "statics") {
78
88
  rawApp.use(path, this.statics(path, layer.opts));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/platform-express",
3
3
  "description": "A TypeScript Framework on top of Express",
4
4
  "type": "module",
5
- "version": "8.13.1",
5
+ "version": "8.13.2",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -58,13 +58,13 @@
58
58
  "tslib": "2.7.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@tsed/barrels": "8.13.1",
62
- "@tsed/core": "8.13.1",
63
- "@tsed/di": "8.13.1",
64
- "@tsed/platform-http": "8.13.1",
65
- "@tsed/platform-test-sdk": "8.13.1",
66
- "@tsed/platform-views": "8.13.1",
67
- "@tsed/typescript": "8.13.1",
61
+ "@tsed/barrels": "8.13.2",
62
+ "@tsed/core": "8.13.2",
63
+ "@tsed/di": "8.13.2",
64
+ "@tsed/platform-http": "8.13.2",
65
+ "@tsed/platform-test-sdk": "8.13.2",
66
+ "@tsed/platform-views": "8.13.2",
67
+ "@tsed/typescript": "8.13.2",
68
68
  "@types/body-parser": "1.19.5",
69
69
  "@types/compression": "1.7.5",
70
70
  "@types/cookie-parser": "1.4.7",