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/app/+admin/plugins | |
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/app/+admin/plugins')
7 files changed, 23 insertions, 22 deletions
diff --git a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts index 3fa1c56dc..1b78a00cd 100644 --- a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts | |||
@@ -4,8 +4,8 @@ import { ActivatedRoute, Router } from '@angular/router' | |||
4 | import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service' | 4 | import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service' |
5 | import { ComponentPagination, ConfirmService, hasMoreItems, Notifier } from '@app/core' | 5 | import { ComponentPagination, ConfirmService, hasMoreItems, Notifier } from '@app/core' |
6 | import { PluginService } from '@app/core/plugins/plugin.service' | 6 | import { PluginService } from '@app/core/plugins/plugin.service' |
7 | import { compareSemVer } from '@shared/core-utils' | 7 | import { compareSemVer } from '@peertube/peertube-core-utils' |
8 | import { PeerTubePlugin, PluginType } from '@shared/models' | 8 | import { PeerTubePlugin, PluginType, PluginType_Type } from '@peertube/peertube-models' |
9 | 9 | ||
10 | @Component({ | 10 | @Component({ |
11 | selector: 'my-plugin-list-installed', | 11 | selector: 'my-plugin-list-installed', |
@@ -13,7 +13,7 @@ import { PeerTubePlugin, PluginType } from '@shared/models' | |||
13 | styleUrls: [ './plugin-list-installed.component.scss' ] | 13 | styleUrls: [ './plugin-list-installed.component.scss' ] |
14 | }) | 14 | }) |
15 | export class PluginListInstalledComponent implements OnInit { | 15 | export class PluginListInstalledComponent implements OnInit { |
16 | pluginType: PluginType | 16 | pluginType: PluginType_Type |
17 | 17 | ||
18 | pagination: ComponentPagination = { | 18 | pagination: ComponentPagination = { |
19 | currentPage: 1, | 19 | currentPage: 1, |
@@ -48,7 +48,7 @@ export class PluginListInstalledComponent implements OnInit { | |||
48 | this.route.queryParams.subscribe(query => { | 48 | this.route.queryParams.subscribe(query => { |
49 | if (!query['pluginType']) return | 49 | if (!query['pluginType']) return |
50 | 50 | ||
51 | this.pluginType = parseInt(query['pluginType'], 10) | 51 | this.pluginType = parseInt(query['pluginType'], 10) as PluginType_Type |
52 | 52 | ||
53 | this.reloadPlugins() | 53 | this.reloadPlugins() |
54 | }) | 54 | }) |
diff --git a/client/src/app/+admin/plugins/plugin-search/plugin-search.component.ts b/client/src/app/+admin/plugins/plugin-search/plugin-search.component.ts index c03e37aa5..5539d1c13 100644 --- a/client/src/app/+admin/plugins/plugin-search/plugin-search.component.ts +++ b/client/src/app/+admin/plugins/plugin-search/plugin-search.component.ts | |||
@@ -4,8 +4,8 @@ import { Component, OnInit } from '@angular/core' | |||
4 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service' | 5 | import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service' |
6 | import { ComponentPagination, ConfirmService, hasMoreItems, Notifier, PluginService } from '@app/core' | 6 | import { ComponentPagination, ConfirmService, hasMoreItems, Notifier, PluginService } from '@app/core' |
7 | import { PeerTubePluginIndex, PluginType, PluginType_Type } from '@peertube/peertube-models' | ||
7 | import { logger } from '@root-helpers/logger' | 8 | import { logger } from '@root-helpers/logger' |
8 | import { PeerTubePluginIndex, PluginType } from '@shared/models' | ||
9 | 9 | ||
10 | @Component({ | 10 | @Component({ |
11 | selector: 'my-plugin-search', | 11 | selector: 'my-plugin-search', |
@@ -13,7 +13,7 @@ import { PeerTubePluginIndex, PluginType } from '@shared/models' | |||
13 | styleUrls: [ './plugin-search.component.scss' ] | 13 | styleUrls: [ './plugin-search.component.scss' ] |
14 | }) | 14 | }) |
15 | export class PluginSearchComponent implements OnInit { | 15 | export class PluginSearchComponent implements OnInit { |
16 | pluginType: PluginType | 16 | pluginType: PluginType_Type |
17 | 17 | ||
18 | pagination: ComponentPagination = { | 18 | pagination: ComponentPagination = { |
19 | currentPage: 1, | 19 | currentPage: 1, |
@@ -53,7 +53,7 @@ export class PluginSearchComponent implements OnInit { | |||
53 | this.route.queryParams.subscribe(query => { | 53 | this.route.queryParams.subscribe(query => { |
54 | if (!query['pluginType']) return | 54 | if (!query['pluginType']) return |
55 | 55 | ||
56 | this.pluginType = parseInt(query['pluginType'], 10) | 56 | this.pluginType = parseInt(query['pluginType'], 10) as PluginType_Type |
57 | this.search = query['search'] || '' | 57 | this.search = query['search'] || '' |
58 | 58 | ||
59 | this.reloadPlugins() | 59 | this.reloadPlugins() |
diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts index b1a41567e..9eee1a901 100644 --- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts | |||
@@ -5,7 +5,7 @@ import { ActivatedRoute } from '@angular/router' | |||
5 | import { HooksService, Notifier, PluginService } from '@app/core' | 5 | import { HooksService, Notifier, PluginService } from '@app/core' |
6 | import { BuildFormArgument } from '@app/shared/form-validators' | 6 | import { BuildFormArgument } from '@app/shared/form-validators' |
7 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' | 7 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' |
8 | import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models' | 8 | import { PeerTubePlugin, RegisterServerSettingOptions } from '@peertube/peertube-models' |
9 | import { PluginApiService } from '../shared/plugin-api.service' | 9 | import { PluginApiService } from '../shared/plugin-api.service' |
10 | 10 | ||
11 | @Component({ | 11 | @Component({ |
diff --git a/client/src/app/+admin/plugins/plugins.routes.ts b/client/src/app/+admin/plugins/plugins.routes.ts index f735a490b..40660f1f4 100644 --- a/client/src/app/+admin/plugins/plugins.routes.ts +++ b/client/src/app/+admin/plugins/plugins.routes.ts | |||
@@ -3,7 +3,7 @@ import { PluginListInstalledComponent } from '@app/+admin/plugins/plugin-list-in | |||
3 | import { PluginSearchComponent } from '@app/+admin/plugins/plugin-search/plugin-search.component' | 3 | import { PluginSearchComponent } from '@app/+admin/plugins/plugin-search/plugin-search.component' |
4 | import { PluginShowInstalledComponent } from '@app/+admin/plugins/plugin-show-installed/plugin-show-installed.component' | 4 | import { PluginShowInstalledComponent } from '@app/+admin/plugins/plugin-show-installed/plugin-show-installed.component' |
5 | import { UserRightGuard } from '@app/core' | 5 | import { UserRightGuard } from '@app/core' |
6 | import { UserRight } from '@shared/models' | 6 | import { UserRight } from '@peertube/peertube-models' |
7 | 7 | ||
8 | export const PluginsRoutes: Routes = [ | 8 | export const PluginsRoutes: Routes = [ |
9 | { | 9 | { |
diff --git a/client/src/app/+admin/plugins/shared/plugin-api.service.ts b/client/src/app/+admin/plugins/shared/plugin-api.service.ts index fbfdaea18..e1bd2f125 100644 --- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts +++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts | |||
@@ -9,9 +9,10 @@ import { | |||
9 | PeerTubePlugin, | 9 | PeerTubePlugin, |
10 | PeerTubePluginIndex, | 10 | PeerTubePluginIndex, |
11 | PluginType, | 11 | PluginType, |
12 | PluginType_Type, | ||
12 | RegisteredServerSettings, | 13 | RegisteredServerSettings, |
13 | ResultList | 14 | ResultList |
14 | } from '@shared/models' | 15 | } from '@peertube/peertube-models' |
15 | import { environment } from '../../../../environments/environment' | 16 | import { environment } from '../../../../environments/environment' |
16 | 17 | ||
17 | @Injectable() | 18 | @Injectable() |
@@ -25,7 +26,7 @@ export class PluginApiService { | |||
25 | private pluginService: PluginService | 26 | private pluginService: PluginService |
26 | ) { } | 27 | ) { } |
27 | 28 | ||
28 | getPluginTypeLabel (type: PluginType) { | 29 | getPluginTypeLabel (type: PluginType_Type) { |
29 | if (type === PluginType.PLUGIN) { | 30 | if (type === PluginType.PLUGIN) { |
30 | return $localize`plugin` | 31 | return $localize`plugin` |
31 | } | 32 | } |
@@ -34,7 +35,7 @@ export class PluginApiService { | |||
34 | } | 35 | } |
35 | 36 | ||
36 | getPlugins ( | 37 | getPlugins ( |
37 | pluginType: PluginType, | 38 | pluginType: PluginType_Type, |
38 | componentPagination: ComponentPagination, | 39 | componentPagination: ComponentPagination, |
39 | sort: string | 40 | sort: string |
40 | ) { | 41 | ) { |
@@ -49,7 +50,7 @@ export class PluginApiService { | |||
49 | } | 50 | } |
50 | 51 | ||
51 | searchAvailablePlugins ( | 52 | searchAvailablePlugins ( |
52 | pluginType: PluginType, | 53 | pluginType: PluginType_Type, |
53 | componentPagination: ComponentPagination, | 54 | componentPagination: ComponentPagination, |
54 | sort: string, | 55 | sort: string, |
55 | search?: string | 56 | search?: string |
@@ -73,7 +74,7 @@ export class PluginApiService { | |||
73 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 74 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
74 | } | 75 | } |
75 | 76 | ||
76 | getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { | 77 | getPluginRegisteredSettings (pluginName: string, pluginType: PluginType_Type) { |
77 | const npmName = this.pluginService.nameToNpmName(pluginName, pluginType) | 78 | const npmName = this.pluginService.nameToNpmName(pluginName, pluginType) |
78 | const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings' | 79 | const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings' |
79 | 80 | ||
@@ -83,7 +84,7 @@ export class PluginApiService { | |||
83 | ) | 84 | ) |
84 | } | 85 | } |
85 | 86 | ||
86 | updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) { | 87 | updatePluginSettings (pluginName: string, pluginType: PluginType_Type, settings: any) { |
87 | const npmName = this.pluginService.nameToNpmName(pluginName, pluginType) | 88 | const npmName = this.pluginService.nameToNpmName(pluginName, pluginType) |
88 | const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/settings' | 89 | const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/settings' |
89 | 90 | ||
@@ -91,7 +92,7 @@ export class PluginApiService { | |||
91 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 92 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
92 | } | 93 | } |
93 | 94 | ||
94 | uninstall (pluginName: string, pluginType: PluginType) { | 95 | uninstall (pluginName: string, pluginType: PluginType_Type) { |
95 | const body: ManagePlugin = { | 96 | const body: ManagePlugin = { |
96 | npmName: this.pluginService.nameToNpmName(pluginName, pluginType) | 97 | npmName: this.pluginService.nameToNpmName(pluginName, pluginType) |
97 | } | 98 | } |
@@ -100,7 +101,7 @@ export class PluginApiService { | |||
100 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 101 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
101 | } | 102 | } |
102 | 103 | ||
103 | update (pluginName: string, pluginType: PluginType) { | 104 | update (pluginName: string, pluginType: PluginType_Type) { |
104 | const body: ManagePlugin = { | 105 | const body: ManagePlugin = { |
105 | npmName: this.pluginService.nameToNpmName(pluginName, pluginType) | 106 | npmName: this.pluginService.nameToNpmName(pluginName, pluginType) |
106 | } | 107 | } |
@@ -118,7 +119,7 @@ export class PluginApiService { | |||
118 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 119 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
119 | } | 120 | } |
120 | 121 | ||
121 | getPluginOrThemeHref (type: PluginType, name: string) { | 122 | getPluginOrThemeHref (type: PluginType_Type, name: string) { |
122 | const typeString = type === PluginType.PLUGIN | 123 | const typeString = type === PluginType.PLUGIN |
123 | ? 'plugin' | 124 | ? 'plugin' |
124 | : 'theme' | 125 | : 'theme' |
diff --git a/client/src/app/+admin/plugins/shared/plugin-card.component.ts b/client/src/app/+admin/plugins/shared/plugin-card.component.ts index 462a6c213..ae91f6887 100644 --- a/client/src/app/+admin/plugins/shared/plugin-card.component.ts +++ b/client/src/app/+admin/plugins/shared/plugin-card.component.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Component, Input } from '@angular/core' | 1 | import { Component, Input } from '@angular/core' |
2 | import { PeerTubePlugin, PeerTubePluginIndex, PluginType } from '@shared/models' | 2 | import { PeerTubePlugin, PeerTubePluginIndex, PluginType_Type } from '@peertube/peertube-models' |
3 | import { PluginApiService } from './plugin-api.service' | 3 | import { PluginApiService } from './plugin-api.service' |
4 | 4 | ||
5 | @Component({ | 5 | @Component({ |
@@ -11,7 +11,7 @@ import { PluginApiService } from './plugin-api.service' | |||
11 | export class PluginCardComponent { | 11 | export class PluginCardComponent { |
12 | @Input() plugin: PeerTubePluginIndex | PeerTubePlugin | 12 | @Input() plugin: PeerTubePluginIndex | PeerTubePlugin |
13 | @Input() version: string | 13 | @Input() version: string |
14 | @Input() pluginType: PluginType | 14 | @Input() pluginType: PluginType_Type |
15 | 15 | ||
16 | constructor ( | 16 | constructor ( |
17 | private pluginApiService: PluginApiService | 17 | private pluginApiService: PluginApiService |
diff --git a/client/src/app/+admin/plugins/shared/plugin-navigation.component.ts b/client/src/app/+admin/plugins/shared/plugin-navigation.component.ts index 1c963f521..c829bc975 100644 --- a/client/src/app/+admin/plugins/shared/plugin-navigation.component.ts +++ b/client/src/app/+admin/plugins/shared/plugin-navigation.component.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Component, Input } from '@angular/core' | 1 | import { Component, Input } from '@angular/core' |
2 | import { PluginType } from '@shared/models/plugins' | 2 | import { PluginType_Type } from '@peertube/peertube-models' |
3 | 3 | ||
4 | @Component({ | 4 | @Component({ |
5 | selector: 'my-plugin-navigation', | 5 | selector: 'my-plugin-navigation', |
@@ -7,5 +7,5 @@ import { PluginType } from '@shared/models/plugins' | |||
7 | styleUrls: [ './plugin-navigation.component.scss' ] | 7 | styleUrls: [ './plugin-navigation.component.scss' ] |
8 | }) | 8 | }) |
9 | export class PluginNavigationComponent { | 9 | export class PluginNavigationComponent { |
10 | @Input() pluginType: PluginType | 10 | @Input() pluginType: PluginType_Type |
11 | } | 11 | } |