diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /client/src/assets/player/shared | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-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 'client/src/assets/player/shared')
11 files changed, 15 insertions, 15 deletions
diff --git a/client/src/assets/player/shared/common/utils.ts b/client/src/assets/player/shared/common/utils.ts index 609240626..4a7182021 100644 --- a/client/src/assets/player/shared/common/utils.ts +++ b/client/src/assets/player/shared/common/utils.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { VideoFile } from '@shared/models' | 1 | import { VideoFile } from '@peertube/peertube-models' |
2 | 2 | ||
3 | function toTitleCase (str: string) { | 3 | function toTitleCase (str: string) { |
4 | return str.charAt(0).toUpperCase() + str.slice(1) | 4 | return str.charAt(0).toUpperCase() + str.slice(1) |
diff --git a/client/src/assets/player/shared/control-bar/peertube-link-button.ts b/client/src/assets/player/shared/control-bar/peertube-link-button.ts index 8242b9cea..f93c265d6 100644 --- a/client/src/assets/player/shared/control-bar/peertube-link-button.ts +++ b/client/src/assets/player/shared/control-bar/peertube-link-button.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' | 2 | import { buildVideoLink, decorateVideoLink } from '@peertube/peertube-core-utils' |
3 | import { PeerTubeLinkButtonOptions } from '../../types' | 3 | import { PeerTubeLinkButtonOptions } from '../../types' |
4 | 4 | ||
5 | const Component = videojs.getComponent('Component') | 5 | const Component = videojs.getComponent('Component') |
diff --git a/client/src/assets/player/shared/metrics/metrics-plugin.ts b/client/src/assets/player/shared/metrics/metrics-plugin.ts index 06ca0c2f2..0ad16338c 100644 --- a/client/src/assets/player/shared/metrics/metrics-plugin.ts +++ b/client/src/assets/player/shared/metrics/metrics-plugin.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import debug from 'debug' | 1 | import debug from 'debug' |
2 | import videojs from 'video.js' | 2 | import videojs from 'video.js' |
3 | import { PlaybackMetricCreate, VideoResolutionType } from '@peertube/peertube-models' | ||
3 | import { logger } from '@root-helpers/logger' | 4 | import { logger } from '@root-helpers/logger' |
4 | import { PlaybackMetricCreate } from '../../../../../../shared/models' | ||
5 | import { MetricsPluginOptions, PlayerNetworkInfo } from '../../types' | 5 | import { MetricsPluginOptions, PlayerNetworkInfo } from '../../types' |
6 | 6 | ||
7 | const debugLogger = debug('peertube:player:metrics') | 7 | const debugLogger = debug('peertube:player:metrics') |
@@ -102,7 +102,7 @@ class MetricsPlugin extends Plugin { | |||
102 | } | 102 | } |
103 | 103 | ||
104 | const body: PlaybackMetricCreate = { | 104 | const body: PlaybackMetricCreate = { |
105 | resolution, | 105 | resolution: resolution as VideoResolutionType, |
106 | fps, | 106 | fps, |
107 | 107 | ||
108 | playerMode: this.options_.mode(), | 108 | playerMode: this.options_.mode(), |
diff --git a/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts index 8c376cd21..1e47fe486 100644 --- a/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts | |||
@@ -3,7 +3,7 @@ import videojs from 'video.js' | |||
3 | import { Events, Segment } from '@peertube/p2p-media-loader-core' | 3 | import { Events, Segment } from '@peertube/p2p-media-loader-core' |
4 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs' | 4 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs' |
5 | import { logger } from '@root-helpers/logger' | 5 | import { logger } from '@root-helpers/logger' |
6 | import { addQueryParams } from '@shared/core-utils' | 6 | import { addQueryParams } from '@peertube/peertube-core-utils' |
7 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types' | 7 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types' |
8 | import { SettingsButton } from '../settings/settings-menu-button' | 8 | import { SettingsButton } from '../settings/settings-menu-button' |
9 | 9 | ||
diff --git a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts index 9cb6344a9..75d483015 100644 --- a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts | |||
@@ -2,7 +2,7 @@ import { basename } from 'path' | |||
2 | import { Segment } from '@peertube/p2p-media-loader-core' | 2 | import { Segment } from '@peertube/p2p-media-loader-core' |
3 | import { logger } from '@root-helpers/logger' | 3 | import { logger } from '@root-helpers/logger' |
4 | import { wait } from '@root-helpers/utils' | 4 | import { wait } from '@root-helpers/utils' |
5 | import { removeQueryParams } from '@shared/core-utils' | 5 | import { removeQueryParams } from '@peertube/peertube-core-utils' |
6 | import { isSameOrigin } from '../common' | 6 | import { isSameOrigin } from '../common' |
7 | 7 | ||
8 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } | 8 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } |
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts index f93593415..cf866723c 100644 --- a/client/src/assets/player/shared/peertube/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import debug from 'debug' | 1 | import debug from 'debug' |
2 | import videojs from 'video.js' | 2 | import videojs from 'video.js' |
3 | import { timeToInt } from '@peertube/peertube-core-utils' | ||
4 | import { VideoView, VideoViewEvent } from '@peertube/peertube-models' | ||
3 | import { logger } from '@root-helpers/logger' | 5 | import { logger } from '@root-helpers/logger' |
4 | import { isIOS, isMobile, isSafari } from '@root-helpers/web-browser' | 6 | import { isIOS, isMobile, isSafari } from '@root-helpers/web-browser' |
5 | import { timeToInt } from '@shared/core-utils' | ||
6 | import { VideoView, VideoViewEvent } from '@shared/models/videos' | ||
7 | import { | 7 | import { |
8 | getStoredLastSubtitle, | 8 | getStoredLastSubtitle, |
9 | getStoredMute, | 9 | getStoredMute, |
diff --git a/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts b/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts index fd632d90d..41198afbe 100644 --- a/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts +++ b/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core' | 1 | import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core' |
2 | import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' | 2 | import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' |
3 | import { logger } from '@root-helpers/logger' | 3 | import { logger } from '@root-helpers/logger' |
4 | import { LiveVideoLatencyMode } from '@shared/models' | 4 | import { LiveVideoLatencyMode } from '@peertube/peertube-models' |
5 | import { getAverageBandwidthInStore } from '../../peertube-player-local-storage' | 5 | import { getAverageBandwidthInStore } from '../../peertube-player-local-storage' |
6 | import { P2PMediaLoader, P2PMediaLoaderPluginOptions, PeerTubePlayerContructorOptions, PeerTubePlayerLoadOptions } from '../../types' | 6 | import { P2PMediaLoader, P2PMediaLoaderPluginOptions, PeerTubePlayerContructorOptions, PeerTubePlayerLoadOptions } from '../../types' |
7 | import { getRtcConfig, isSameOrigin } from '../common' | 7 | import { getRtcConfig, isSameOrigin } from '../common' |
diff --git a/client/src/assets/player/shared/playlist/playlist-menu-item.ts b/client/src/assets/player/shared/playlist/playlist-menu-item.ts index f9366332d..66c92d9e5 100644 --- a/client/src/assets/player/shared/playlist/playlist-menu-item.ts +++ b/client/src/assets/player/shared/playlist/playlist-menu-item.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { secondsToTime } from '@shared/core-utils' | 2 | import { secondsToTime } from '@peertube/peertube-core-utils' |
3 | import { VideoPlaylistElement } from '@shared/models' | 3 | import { VideoPlaylistElement } from '@peertube/peertube-models' |
4 | import { PlaylistItemOptions } from '../../types' | 4 | import { PlaylistItemOptions } from '../../types' |
5 | 5 | ||
6 | const Component = videojs.getComponent('Component') | 6 | const Component = videojs.getComponent('Component') |
diff --git a/client/src/assets/player/shared/playlist/playlist-menu.ts b/client/src/assets/player/shared/playlist/playlist-menu.ts index 53a5a7274..f6795390c 100644 --- a/client/src/assets/player/shared/playlist/playlist-menu.ts +++ b/client/src/assets/player/shared/playlist/playlist-menu.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { VideoPlaylistElement } from '@shared/models' | 2 | import { VideoPlaylistElement } from '@peertube/peertube-models' |
3 | import { PlaylistPluginOptions } from '../../types' | 3 | import { PlaylistPluginOptions } from '../../types' |
4 | import { PlaylistMenuItem } from './playlist-menu-item' | 4 | import { PlaylistMenuItem } from './playlist-menu-item' |
5 | 5 | ||
diff --git a/client/src/assets/player/shared/stats/stats-card.ts b/client/src/assets/player/shared/stats/stats-card.ts index 13334d91a..fefe8483e 100644 --- a/client/src/assets/player/shared/stats/stats-card.ts +++ b/client/src/assets/player/shared/stats/stats-card.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { logger } from '@root-helpers/logger' | 2 | import { logger } from '@root-helpers/logger' |
3 | import { secondsToTime } from '@shared/core-utils' | 3 | import { secondsToTime } from '@peertube/peertube-core-utils' |
4 | import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../../types' | 4 | import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../../types' |
5 | import { bytes } from '../common' | 5 | import { bytes } from '../common' |
6 | 6 | ||
diff --git a/client/src/assets/player/shared/web-video/web-video-plugin.ts b/client/src/assets/player/shared/web-video/web-video-plugin.ts index b839062f2..18d911108 100644 --- a/client/src/assets/player/shared/web-video/web-video-plugin.ts +++ b/client/src/assets/player/shared/web-video/web-video-plugin.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import debug from 'debug' | 1 | import debug from 'debug' |
2 | import videojs from 'video.js' | 2 | import videojs from 'video.js' |
3 | import { logger } from '@root-helpers/logger' | 3 | import { logger } from '@root-helpers/logger' |
4 | import { addQueryParams } from '@shared/core-utils' | 4 | import { addQueryParams } from '@peertube/peertube-core-utils' |
5 | import { VideoFile } from '@shared/models' | 5 | import { VideoFile } from '@peertube/peertube-models' |
6 | import { PeerTubeResolution, PlayerNetworkInfo, WebVideoPluginOptions } from '../../types' | 6 | import { PeerTubeResolution, PlayerNetworkInfo, WebVideoPluginOptions } from '../../types' |
7 | 7 | ||
8 | const debugLogger = debug('peertube:player:web-video-plugin') | 8 | const debugLogger = debug('peertube:player:web-video-plugin') |