Verified Commit 5e898d88 authored by Chocobozzz's avatar Chocobozzz
Browse files

Compile server using webpack

It's more flexible
Tsconfig paths are compiled so we don't need register ts config paths at runtime, which can be slow
Easier for dev (using nodemon plugin etc)
Bundle server in one file, for faster startup
parent cea093bc
......@@ -60,10 +60,9 @@
"commander": "commander",
"lint": "npm run ci -- lint",
"ng": "ng",
"nodemon": "nodemon",
"resolve-tspaths": "resolve-tspaths",
"ts-node": "ts-node",
"eslint": "eslint",
"resolve-tspaths": "resolve-tspaths",
"concurrently": "concurrently",
"mocha": "mocha",
"ci": "bash ./scripts/ci.sh",
......@@ -185,6 +184,7 @@
"@types/request": "^2.0.3",
"@types/supertest": "^2.0.3",
"@types/validator": "^13.0.0",
"@types/webpack-env": "^1.16.3",
"@types/webtorrent": "^0.109.0",
"@types/ws": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
......@@ -201,14 +201,19 @@
"eslint-plugin-promise": "^6.0.0",
"fast-xml-parser": "^4.0.0-beta.8",
"mocha": "^9.0.0",
"nodemon": "^2.0.1",
"nodemon-webpack-plugin": "^4.7.0",
"proxy": "^1.0.2",
"resolve-tspaths": "^0.2.1",
"socket.io-client": "^4.0.1",
"supertest": "^6.0.1",
"swagger-cli": "^4.0.2",
"ts-loader": "^9.2.6",
"ts-node": "10.4.0",
"typescript": "^4.0.5"
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript": "^4.0.5",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-node-externals": "^3.0.0"
},
"resolutions": {
"depcheck/@babel/parser": "7.16.4"
......
......@@ -3,7 +3,8 @@
"compilerOptions": {
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true,
"emitDeclarationOnly": false,
"declaration": true,
"outDir": "../../dist/client/",
"rootDir": "./",
"tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo"
......
......@@ -3,7 +3,8 @@
"compilerOptions": {
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true,
"emitDeclarationOnly": false,
"declaration": true,
"outDir": "./dist/",
"baseUrl": "./src/",
"rootDir": "./src/",
......
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
......
......@@ -4,10 +4,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/"
./node_modules/.bin/webpack -c ./webpack/webpack.server.js --env target production --stats-error-details
cp -r "./server/static" "./server/assets" "./dist/server"
cp -r "./server/lib/emails" "./dist/server/lib"
......@@ -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; TS_NODE_PROJECT=./tsconfig.json TS_NODE_BASEURL="./dist" npm run mocha -- -c --timeout 30000 --exit -r tsconfig-paths/register --bail {}" \
::: $files
cat "$joblog" | uniq -c
......
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'
......
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')
......
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.')
......
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')
......
......@@ -12,4 +12,4 @@ 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
./node_modules/.bin/webpack -c ./webpack/webpack.cli.js --env target development --stats-error-details --watch
......@@ -16,13 +16,9 @@ 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
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/webpack -c ./webpack/webpack.server.js --watch --env target development
import { registerTSPaths } from '../server/helpers/register-ts-paths'
registerTSPaths()
import { CLICommand } from '@shared/server-commands'
run()
......
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 = __non_webpack_require__(join(root(), 'client', 'src', 'locale', 'videojs.en-US.json'))
const playerKeys = {
'Quality': 'Quality',
'Auto': 'Auto',
......@@ -100,20 +98,20 @@ 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 })
for (const key of Object.keys(I18N_LOCALES)) {
const playerJsonPath = join(localePath, `player.${key}.json`)
const translatedPlayer = require(playerJsonPath)
const translatedPlayer = __non_webpack_require__(playerJsonPath)
const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
const serverJsonPath = join(localePath, `server.${key}.json`)
const translatedServer = require(serverJsonPath)
const translatedServer = __non_webpack_require__(serverJsonPath)
const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
......
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))
......
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))
......
......@@ -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 ..
......
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)')
......@@ -133,6 +130,8 @@ async function getFiles () {
const logFiles = await readdir(CONFIG.STORAGE.LOG_DIR)
const filename = await getNewestFile(logFiles, CONFIG.STORAGE.LOG_DIR)
if (!filename) return []
return [ join(CONFIG.STORAGE.LOG_DIR, filename) ]
}
......
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')
......
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment