Fix bug with tsconfig paths
authorChocobozzz <me@florianbigard.com>
Mon, 21 Oct 2019 14:02:15 +0000 (16:02 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 21 Oct 2019 14:02:15 +0000 (16:02 +0200)
package.json
scripts/build/server.sh
server.ts
server/tests/helpers/core-utils.ts
yarn.lock

index f17da34d0bdad8fcd281fbf64c1301c668937d84..17cb6677d2da5be93e6b6a5eebbb5597dfd1ed38 100644 (file)
     "lru-cache": "^5.1.1",
     "magnet-uri": "^5.1.4",
     "memoizee": "^0.4.14",
-    "module-alias": "^2.2.1",
     "morgan": "^1.5.3",
     "multer": "^1.1.0",
     "nodemailer": "^6.0.0",
     "sitemap": "^5.0.0",
     "socket.io": "^2.2.0",
     "srt-to-vtt": "^1.1.2",
+    "tsconfig-paths": "^3.9.0",
     "useragent": "^2.3.0",
     "uuid": "^3.1.0",
     "validator": "^11.0.0",
index 3880ac5fa0d9f38dd2468c349fc6ab7594132297..d66a524757399146e621d63db64699a07001f219 100755 (executable)
@@ -5,4 +5,5 @@ set -eu
 rm -rf ./dist
 
 npm run tsc
+cp "./tsconfig.json" "./dist"
 cp -r "./server/static" "./server/assets" "./dist/server"
index 5cfa09445537215fd3f9c772955d45a02ddd1b9a..b49d10344bb5a38b83739afe30fe7b350a85322d 100644 (file)
--- a/server.ts
+++ b/server.ts
@@ -1,12 +1,18 @@
-require('module-alias/register')
+import { resolve } from 'path'
 
-// FIXME: https://github.com/nodejs/node/pull/16853
-import { PluginManager } from './server/lib/plugins/plugin-manager'
+const tsConfig = require('./tsconfig.json')
+const tsConfigPaths = require('tsconfig-paths')
+
+// Thanks: https://github.com/dividab/tsconfig-paths/issues/75#issuecomment-458936883
+tsConfigPaths.register({
+  baseUrl: resolve(tsConfig.compilerOptions.baseUrl || '', tsConfig.compilerOptions.outDir || ''),
+  paths: tsConfig.compilerOptions.paths
+})
 
+// FIXME: https://github.com/nodejs/node/pull/16853
 require('tls').DEFAULT_ECDH_CURVE = 'auto'
 
 import { isTestInstance } from './server/helpers/core-utils'
-
 if (isTestInstance()) {
   require('source-map-support').install()
 }
@@ -121,6 +127,7 @@ import { PeerTubeSocket } from './server/lib/peertube-socket'
 import { updateStreamingPlaylistsInfohashesIfNeeded } from './server/lib/hls'
 import { PluginsCheckScheduler } from './server/lib/schedulers/plugins-check-scheduler'
 import { Hooks } from './server/lib/plugins/hooks'
+import { PluginManager } from './server/lib/plugins/plugin-manager'
 
 // ----------- Command line -----------
 
index e604cf7e325b1581cdef4bcc94d439d9be468709..2dbe8d63510fca5b49590b2753980622b2636221 100644 (file)
@@ -2,10 +2,8 @@
 
 import * as chai from 'chai'
 import 'mocha'
-import { snakeCase, isNumber } from 'lodash'
-import {
-  parseBytes, objectConverter
-} from '../../helpers/core-utils'
+import { snakeCase } from 'lodash'
+import { objectConverter, parseBytes } from '../../helpers/core-utils'
 import { isNumeric } from 'validator'
 
 const expect = chai.expect
index eafeffad30cecc4b13e58e69650818435059ddc0..b6a59b855013e7c04116d479444a847f4ee864dd 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
   dependencies:
     "@types/node" "*"
 
+"@types/json5@^0.0.29":
+  version "0.0.29"
+  resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
+  integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
+
 "@types/libxmljs@^0.18.0":
   version "0.18.3"
   resolved "https://registry.yarnpkg.com/@types/libxmljs/-/libxmljs-0.18.3.tgz#5aaed8fc4ec5ea99e005ee5dfb47cf9924166a4d"
@@ -4551,11 +4556,6 @@ mocha@^6.0.0:
     yargs-parser "13.1.1"
     yargs-unparser "1.6.0"
 
-module-alias@^2.2.1:
-  version "2.2.2"
-  resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.2.tgz#151cdcecc24e25739ff0aa6e51e1c5716974c0e0"
-  integrity sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==
-
 moment-timezone@^0.5.21, moment-timezone@^0.5.25:
   version "0.5.27"
   resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.27.tgz#73adec8139b6fe30452e78f210f27b1f346b8877"
@@ -6752,6 +6752,11 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
   dependencies:
     ansi-regex "^4.1.0"
 
+strip-bom@^3.0.0:
+  version "3.0.0"
+  resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
+  integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=
+
 strip-eof@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
@@ -7097,6 +7102,16 @@ ts-node@8.4.1:
     source-map-support "^0.5.6"
     yn "^3.0.0"
 
+tsconfig-paths@^3.9.0:
+  version "3.9.0"
+  resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b"
+  integrity sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==
+  dependencies:
+    "@types/json5" "^0.0.29"
+    json5 "^1.0.1"
+    minimist "^1.2.0"
+    strip-bom "^3.0.0"
+
 tslib@1.9.0:
   version "1.9.0"
   resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"