From f8360396ffabd2f95e9ece9c5755173bae0114b6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 Jan 2022 17:13:11 +0100 Subject: Stop using tsconfig register Prefer to replace paths at compile time --- scripts/benchmark.ts | 5 +---- scripts/build/server.sh | 6 ++---- scripts/ci.sh | 2 +- scripts/client-build-stats.ts | 3 --- scripts/create-import-video-file-job.ts | 7 ++----- scripts/create-move-video-storage-job.ts | 11 ++++------- scripts/create-transcoding-job.ts | 13 +++++-------- scripts/dev/cli.sh | 3 ++- scripts/dev/server.sh | 11 ++++------- scripts/generate-code-contributors.ts | 3 --- scripts/i18n/create-custom-files.ts | 8 +++----- scripts/migrations/peertube-2.1.ts | 15 ++++++--------- scripts/migrations/peertube-4.0.ts | 11 ++++------- scripts/nightly.sh | 2 +- scripts/parse-log.ts | 7 ++----- scripts/plugin/install.ts | 7 ++----- scripts/plugin/uninstall.ts | 5 +---- scripts/print-transcode-command.ts | 5 +---- scripts/prune-storage.ts | 27 ++++++++++++--------------- scripts/regenerate-thumbnails.ts | 5 +---- scripts/release.sh | 2 +- scripts/reset-password.ts | 5 +---- scripts/setup/cli.sh | 6 ++++-- scripts/update-host.ts | 19 ++++++++----------- 24 files changed, 68 insertions(+), 120 deletions(-) (limited to 'scripts') diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts index 011519fe3..3c3c666a1 100644 --- a/scripts/benchmark.ts +++ b/scripts/benchmark.ts @@ -1,10 +1,7 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import autocannon, { printResult } from 'autocannon' import { writeJson } from 'fs-extra' -import { createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' import { Video, VideoPrivacy } from '@shared/models' +import { createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' let server: PeerTubeServer let video: Video diff --git a/scripts/build/server.sh b/scripts/build/server.sh index 865bdd095..a2dfc3dd9 100755 --- a/scripts/build/server.sh +++ b/scripts/build/server.sh @@ -5,9 +5,7 @@ set -eu rm -rf ./dist npm run tsc -- -b --verbose -cp "./tsconfig.base.json" "./tsconfig.json" "./dist/" -cp "./scripts/tsconfig.json" "./dist/scripts/" -cp "./server/tsconfig.json" "./dist/server/" -cp "./shared/tsconfig.json" "./dist/shared/" +npm run resolve-tspaths:server + cp -r "./server/static" "./server/assets" "./dist/server" cp -r "./server/lib/emails" "./dist/server/lib" diff --git a/scripts/ci.sh b/scripts/ci.sh index b0b76ca99..2bacf2a2e 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -23,7 +23,7 @@ runTest () { joblog="$jobname-ci.log" parallel -j $jobs --retries $retries \ - "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --require ./dist/server/tests/register.js --bail {}" \ + "echo Trying {} >> $joblog; npm run mocha -- -c --timeout 30000 --exit --bail {}" \ ::: $files cat "$joblog" | uniq -c diff --git a/scripts/client-build-stats.ts b/scripts/client-build-stats.ts index 91844dfcd..d5ecd5fea 100644 --- a/scripts/client-build-stats.ts +++ b/scripts/client-build-stats.ts @@ -1,6 +1,3 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { readdir, stat } from 'fs-extra' import { join } from 'path' import { root } from '@shared/core-utils' diff --git a/scripts/create-import-video-file-job.ts b/scripts/create-import-video-file-job.ts index 071d36df4..97e9c7933 100644 --- a/scripts/create-import-video-file-job.ts +++ b/scripts/create-import-video-file-job.ts @@ -1,12 +1,9 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' import { resolve } from 'path' -import { VideoModel } from '../server/models/video/video' +import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' import { initDatabaseModels } from '../server/initializers/database' import { JobQueue } from '../server/lib/job-queue' -import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' +import { VideoModel } from '../server/models/video/video' program .option('-v, --video [videoUUID]', 'Video UUID') diff --git a/scripts/create-move-video-storage-job.ts b/scripts/create-move-video-storage-job.ts index 90c84b1d7..7465c1ce0 100644 --- a/scripts/create-move-video-storage-job.ts +++ b/scripts/create-move-video-storage-job.ts @@ -1,13 +1,10 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' -import { VideoModel } from '@server/models/video/video' +import { CONFIG } from '@server/initializers/config' import { initDatabaseModels } from '@server/initializers/database' -import { VideoState, VideoStorage } from '@shared/models' -import { moveToExternalStorageState } from '@server/lib/video-state' import { JobQueue } from '@server/lib/job-queue' -import { CONFIG } from '@server/initializers/config' +import { moveToExternalStorageState } from '@server/lib/video-state' +import { VideoModel } from '@server/models/video/video' +import { VideoState, VideoStorage } from '@shared/models' program .description('Move videos to another storage.') diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts index 244c38fcd..d462fbf33 100755 --- a/scripts/create-transcoding-job.ts +++ b/scripts/create-transcoding-job.ts @@ -1,15 +1,12 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' -import { VideoModel } from '../server/models/video/video' -import { initDatabaseModels } from '../server/initializers/database' -import { JobQueue } from '../server/lib/job-queue' +import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils' -import { VideoState, VideoTranscodingPayload } from '@shared/models' import { CONFIG } from '@server/initializers/config' -import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' import { addTranscodingJob } from '@server/lib/video' +import { VideoState, VideoTranscodingPayload } from '@shared/models' +import { initDatabaseModels } from '../server/initializers/database' +import { JobQueue } from '../server/lib/job-queue' +import { VideoModel } from '../server/models/video/video' program .option('-v, --video [videoUUID]', 'Video UUID') diff --git a/scripts/dev/cli.sh b/scripts/dev/cli.sh index 4bf4808b8..327792a19 100755 --- a/scripts/dev/cli.sh +++ b/scripts/dev/cli.sh @@ -12,4 +12,5 @@ rm -rf ./dist/server/tools/ mkdir -p "./dist/server/tools" cp -r "./server/tools/node_modules" "./dist/server/tools" -npm run tsc -- --watch --sourceMap --project ./server/tools/tsconfig.json +cd ./server/tools +../../node_modules/.bin/tsc-watch --build --verbose --onSuccess 'sh -c "cd ../../ && npm run resolve-tspaths:all"' diff --git a/scripts/dev/server.sh b/scripts/dev/server.sh index 468af0a56..9dae43a63 100755 --- a/scripts/dev/server.sh +++ b/scripts/dev/server.sh @@ -14,15 +14,12 @@ mkdir -p "./client/dist" rm -rf "./client/dist/locale" cp -r "./client/src/locale" "./client/dist/locale" -rm -rf "./dist" - -mkdir "./dist" -cp "./tsconfig.json" "./dist" +mkdir -p "./dist/server/lib" npm run tsc -- -b -v --incremental +npm run resolve-tspaths:server + cp -r ./server/static ./server/assets ./dist/server cp -r "./server/lib/emails" "./dist/server/lib" -NODE_ENV=test node node_modules/.bin/concurrently -k \ - "node_modules/.bin/nodemon --enable-source-maps --delay 1 --watch ./dist dist/server" \ - "node_modules/.bin/tsc -b -w --preserveWatchOutput" +./node_modules/.bin/tsc-watch --build --preserveWatchOutput --verbose --onSuccess 'sh -c "npm run resolve-tspaths:server && NODE_ENV=test node dist/server"' diff --git a/scripts/generate-code-contributors.ts b/scripts/generate-code-contributors.ts index 449407c44..5357daf04 100755 --- a/scripts/generate-code-contributors.ts +++ b/scripts/generate-code-contributors.ts @@ -1,6 +1,3 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { CLICommand } from '@shared/server-commands' run() diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts index d9328b125..7556866e6 100755 --- a/scripts/i18n/create-custom-files.ts +++ b/scripts/i18n/create-custom-files.ts @@ -1,9 +1,7 @@ -import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - import { writeJSON } from 'fs-extra' import { values } from 'lodash' import { join } from 'path' +import { root } from '@shared/core-utils' import { buildLanguages, VIDEO_CATEGORIES, @@ -16,7 +14,7 @@ import { } from '../../server/initializers/constants' import { I18N_LOCALES } from '../../shared/core-utils/i18n' -const videojs = require(join(__dirname, '../../../client/src/locale/videojs.en-US.json')) +const videojs = require(join(root(), 'client', 'src', 'locale', 'videojs.en-US.json')) const playerKeys = { 'Quality': 'Quality', 'Auto': 'Auto', @@ -100,7 +98,7 @@ writeAll().catch(err => { }) async function writeAll () { - const localePath = join(__dirname, '../../../client/src/locale') + const localePath = join(root(), 'client', 'src', 'locale') await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 }) await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 }) diff --git a/scripts/migrations/peertube-2.1.ts b/scripts/migrations/peertube-2.1.ts index 4bbc203c1..2e316d996 100644 --- a/scripts/migrations/peertube-2.1.ts +++ b/scripts/migrations/peertube-2.1.ts @@ -1,15 +1,12 @@ -import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - -import { initDatabaseModels, sequelizeTypescript } from '../../server/initializers/database' -import * as Sequelize from 'sequelize' -import { join } from 'path' -import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' import { pathExists, stat, writeFile } from 'fs-extra' -import { createTorrentPromise } from '@server/helpers/webtorrent' -import { CONFIG } from '@server/initializers/config' import parseTorrent from 'parse-torrent' +import { join } from 'path' +import * as Sequelize from 'sequelize' import { logger } from '@server/helpers/logger' +import { createTorrentPromise } from '@server/helpers/webtorrent' +import { CONFIG } from '@server/initializers/config' +import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' +import { initDatabaseModels, sequelizeTypescript } from '../../server/initializers/database' run() .then(() => process.exit(0)) diff --git a/scripts/migrations/peertube-4.0.ts b/scripts/migrations/peertube-4.0.ts index abf431888..64cf45474 100644 --- a/scripts/migrations/peertube-4.0.ts +++ b/scripts/migrations/peertube-4.0.ts @@ -1,16 +1,13 @@ -import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - +import Bluebird from 'bluebird' +import { move, readFile, writeFile } from 'fs-extra' import { join } from 'path' +import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' import { JobQueue } from '@server/lib/job-queue' -import { initDatabaseModels } from '../../server/initializers/database' import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getHlsResolutionPlaylistFilename } from '@server/lib/paths' import { VideoPathManager } from '@server/lib/video-path-manager' import { VideoModel } from '@server/models/video/video' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' -import { move, readFile, writeFile } from 'fs-extra' -import Bluebird from 'bluebird' -import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' +import { initDatabaseModels } from '../../server/initializers/database' run() .then(() => process.exit(0)) diff --git a/scripts/nightly.sh b/scripts/nightly.sh index 5ad603929..572277f9d 100755 --- a/scripts/nightly.sh +++ b/scripts/nightly.sh @@ -32,7 +32,7 @@ sed -i 's/"version": "\([^"]\+\)"/"version": "\1-'"$nightly_version"'"/' ./packa "$directory_name/client/package.json" "$directory_name/config" \ "$directory_name/dist" "$directory_name/package.json" \ "$directory_name/scripts" "$directory_name/support" \ - "$directory_name/tsconfig.json" "$directory_name/yarn.lock") + "$directory_name/yarn.lock") # temporary setup cd .. diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts index 6cd3a1860..d3c93cee5 100755 --- a/scripts/parse-log.ts +++ b/scripts/parse-log.ts @@ -1,15 +1,12 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' import { createReadStream, readdir } from 'fs-extra' import { join } from 'path' import { createInterface } from 'readline' +import { format as sqlFormat } from 'sql-formatter' +import { inspect } from 'util' import * as winston from 'winston' import { labelFormatter, mtimeSortFilesDesc } from '../server/helpers/logger' import { CONFIG } from '../server/initializers/config' -import { inspect } from 'util' -import { format as sqlFormat } from 'sql-formatter' program .option('-l, --level [level]', 'Level log (debug/info/warn/error)') diff --git a/scripts/plugin/install.ts b/scripts/plugin/install.ts index de045c2d2..0795d7c93 100755 --- a/scripts/plugin/install.ts +++ b/scripts/plugin/install.ts @@ -1,10 +1,7 @@ -import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - -import { initDatabaseModels } from '../../server/initializers/database' import { program } from 'commander' -import { PluginManager } from '../../server/lib/plugins/plugin-manager' import { isAbsolute } from 'path' +import { initDatabaseModels } from '../../server/initializers/database' +import { PluginManager } from '../../server/lib/plugins/plugin-manager' program .option('-n, --npm-name [npmName]', 'Plugin to install') diff --git a/scripts/plugin/uninstall.ts b/scripts/plugin/uninstall.ts index 1e14cc18f..152b651dd 100755 --- a/scripts/plugin/uninstall.ts +++ b/scripts/plugin/uninstall.ts @@ -1,8 +1,5 @@ -import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - -import { initDatabaseModels } from '../../server/initializers/database' import { program } from 'commander' +import { initDatabaseModels } from '../../server/initializers/database' import { PluginManager } from '../../server/lib/plugins/plugin-manager' program diff --git a/scripts/print-transcode-command.ts b/scripts/print-transcode-command.ts index 352145252..21667f544 100644 --- a/scripts/print-transcode-command.ts +++ b/scripts/print-transcode-command.ts @@ -1,10 +1,7 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' import ffmpeg from 'fluent-ffmpeg' -import { buildx264VODCommand, runCommand, TranscodeOptions } from '@server/helpers/ffmpeg-utils' import { exit } from 'process' +import { buildx264VODCommand, runCommand, TranscodeOptions } from '@server/helpers/ffmpeg-utils' import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/video-transcoding-profiles' program diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index 12d78fdc6..bb1e8e024 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -1,22 +1,19 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - -import { start, get } from 'prompt' -import { join, basename } from 'path' -import { CONFIG } from '../server/initializers/config' -import { VideoModel } from '../server/models/video/video' -import { initDatabaseModels } from '../server/initializers/database' -import { readdir, remove, stat } from 'fs-extra' -import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' import { map } from 'bluebird' -import { getUUIDFromFilename } from '../server/helpers/utils' -import { ThumbnailModel } from '../server/models/video/thumbnail' -import { ActorImageModel } from '../server/models/actor/actor-image' +import { readdir, remove, stat } from 'fs-extra' import { uniq, values } from 'lodash' -import { ThumbnailType } from '@shared/models' -import { VideoFileModel } from '@server/models/video/video-file' +import { basename, join } from 'path' +import { get, start } from 'prompt' import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' +import { VideoFileModel } from '@server/models/video/video-file' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' +import { ThumbnailType } from '@shared/models' +import { getUUIDFromFilename } from '../server/helpers/utils' +import { CONFIG } from '../server/initializers/config' +import { initDatabaseModels } from '../server/initializers/database' +import { ActorImageModel } from '../server/models/actor/actor-image' +import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' +import { ThumbnailModel } from '../server/models/video/thumbnail' +import { VideoModel } from '../server/models/video/video' run() .then(() => process.exit(0)) diff --git a/scripts/regenerate-thumbnails.ts b/scripts/regenerate-thumbnails.ts index 50d06f6fd..a377baa61 100644 --- a/scripts/regenerate-thumbnails.ts +++ b/scripts/regenerate-thumbnails.ts @@ -1,13 +1,10 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { map } from 'bluebird' import { program } from 'commander' import { pathExists, remove } from 'fs-extra' import { generateImageFilename, processImage } from '@server/helpers/image-utils' import { THUMBNAILS_SIZE } from '@server/initializers/constants' -import { VideoModel } from '@server/models/video/video' import { initDatabaseModels } from '@server/initializers/database' +import { VideoModel } from '@server/models/video/video' program .description('Regenerate local thumbnails using preview files') diff --git a/scripts/release.sh b/scripts/release.sh index 409a52977..313087a29 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -76,7 +76,7 @@ rm -f "./client/dist/embed-stats.json" "$directory_name/client/package.json" "$directory_name/config" \ "$directory_name/dist" "$directory_name/package.json" \ "$directory_name/scripts" "$directory_name/support" \ - "$directory_name/tsconfig.json" "$directory_name/yarn.lock") + "$directory_name/yarn.lock") # temporary setup cd .. diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts index 4c45396d4..b2e5639fb 100755 --- a/scripts/reset-password.ts +++ b/scripts/reset-password.ts @@ -1,10 +1,7 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' +import { isUserPasswordValid } from '../server/helpers/custom-validators/users' import { initDatabaseModels } from '../server/initializers/database' import { UserModel } from '../server/models/user/user' -import { isUserPasswordValid } from '../server/helpers/custom-validators/users' program .option('-u, --user [user]', 'User') diff --git a/scripts/setup/cli.sh b/scripts/setup/cli.sh index d0ad2ec5f..f84260f23 100755 --- a/scripts/setup/cli.sh +++ b/scripts/setup/cli.sh @@ -9,8 +9,10 @@ rm -rf ./dist/server/tools/ ( cd ./server/tools yarn install --pure-lockfile + ../../node_modules/.bin/tsc --build --verbose ) -npm run tsc -- --build --verbose ./server/tools/tsconfig.json cp -r "./server/tools/node_modules" "./dist/server/tools" -cp "./tsconfig.json" "./dist" + +npm run resolve-tspaths:cli +npm run resolve-tspaths:server diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 66c0137d9..bb54290a4 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -1,10 +1,7 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - +import { updateTorrentMetadata } from '@server/helpers/webtorrent' +import { getServerActor } from '@server/models/application/application' import { WEBSERVER } from '../server/initializers/constants' -import { ActorFollowModel } from '../server/models/actor/actor-follow' -import { VideoModel } from '../server/models/video/video' -import { ActorModel } from '../server/models/actor/actor' +import { initDatabaseModels } from '../server/initializers/database' import { getLocalAccountActivityPubUrl, getLocalVideoActivityPubUrl, @@ -12,13 +9,13 @@ import { getLocalVideoChannelActivityPubUrl, getLocalVideoCommentActivityPubUrl } from '../server/lib/activitypub/url' -import { VideoShareModel } from '../server/models/video/video-share' -import { VideoCommentModel } from '../server/models/video/video-comment' import { AccountModel } from '../server/models/account/account' +import { ActorModel } from '../server/models/actor/actor' +import { ActorFollowModel } from '../server/models/actor/actor-follow' +import { VideoModel } from '../server/models/video/video' import { VideoChannelModel } from '../server/models/video/video-channel' -import { initDatabaseModels } from '../server/initializers/database' -import { updateTorrentMetadata } from '@server/helpers/webtorrent' -import { getServerActor } from '@server/models/application/application' +import { VideoCommentModel } from '../server/models/video/video-comment' +import { VideoShareModel } from '../server/models/video/video-share' run() .then(() => process.exit(0)) -- cgit v1.2.3