aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/dev
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /scripts/dev
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'scripts/dev')
-rwxr-xr-xscripts/dev/cli.sh16
-rwxr-xr-xscripts/dev/peertube-cli.sh11
-rwxr-xr-xscripts/dev/peertube-runner.sh6
-rwxr-xr-xscripts/dev/server.sh8
4 files changed, 18 insertions, 23 deletions
diff --git a/scripts/dev/cli.sh b/scripts/dev/cli.sh
deleted file mode 100755
index 39ecaad94..000000000
--- a/scripts/dev/cli.sh
+++ /dev/null
@@ -1,16 +0,0 @@
1#!/bin/bash
2
3set -eu
4
5rm -rf ./dist/server/tools/
6
7(
8 cd ./server/tools
9 yarn install --pure-lockfile
10)
11
12mkdir -p "./dist/server/tools"
13cp -r "./server/tools/node_modules" "./dist/server/tools"
14
15cd ./server/tools
16../../node_modules/.bin/tsc-watch --build --verbose --onSuccess 'sh -c "cd ../../ && npm run resolve-tspaths:server"'
diff --git a/scripts/dev/peertube-cli.sh b/scripts/dev/peertube-cli.sh
new file mode 100755
index 000000000..172bf038e
--- /dev/null
+++ b/scripts/dev/peertube-cli.sh
@@ -0,0 +1,11 @@
1#!/bin/bash
2
3set -eu
4
5rm -rf ./apps/peertube-cli/dist
6
7cd ./apps/peertube-cli
8
9../../node_modules/.bin/concurrently -k \
10 "../../node_modules/.bin/tsc -w --noEmit" \
11 "node ./scripts/watch.js"
diff --git a/scripts/dev/peertube-runner.sh b/scripts/dev/peertube-runner.sh
index e39259372..7bd756123 100755
--- a/scripts/dev/peertube-runner.sh
+++ b/scripts/dev/peertube-runner.sh
@@ -2,10 +2,10 @@
2 2
3set -eu 3set -eu
4 4
5rm -rf ./packages/peertube-runner/dist 5rm -rf ./apps/peertube-runner/dist
6 6
7cd ./packages/peertube-runner 7cd ./apps/peertube-runner
8 8
9../../node_modules/.bin/concurrently -k \ 9../../node_modules/.bin/concurrently -k \
10 "../../node_modules/.bin/tsc -w --noEmit" \ 10 "../../node_modules/.bin/tsc -w --noEmit" \
11 "./node_modules/.bin/esbuild ./peertube-runner.ts --bundle --sourcemap --platform=node --external:"./lib-cov/fluent-ffmpeg" --external:pg-hstore --watch --outfile=dist/peertube-runner.js" 11 "node ./scripts/watch.js"
diff --git a/scripts/dev/server.sh b/scripts/dev/server.sh
index c52c5124c..4112cb2f8 100755
--- a/scripts/dev/server.sh
+++ b/scripts/dev/server.sh
@@ -16,10 +16,10 @@ cp -r "./client/src/locale" "./client/dist/locale"
16 16
17mkdir -p "./dist/server/lib" 17mkdir -p "./dist/server/lib"
18 18
19npm run tsc -- -b -v --incremental 19npm run tsc -- -b -v --incremental server/tsconfig.json
20npm run resolve-tspaths:server 20npm run resolve-tspaths:server
21 21
22cp -r ./server/static ./server/assets ./dist/server 22cp -r ./server/server/static ./server/server/assets ./dist/server
23cp -r "./server/lib/emails" "./dist/server/lib" 23cp -r "./server/server/lib/emails" "./dist/server/lib"
24 24
25./node_modules/.bin/tsc-watch --build --preserveWatchOutput --verbose --onSuccess 'sh -c "npm run resolve-tspaths:server && NODE_ENV=dev node dist/server"' 25./node_modules/.bin/tsc-watch --build --preserveWatchOutput --verbose --onSuccess 'sh -c "npm run resolve-tspaths:server && NODE_ENV=dev node dist/server"' server/tsconfig.json