From 3a4992633ee62d5edfbb484d9c6bcb3cf158489d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 31 Jul 2023 14:34:36 +0200 Subject: 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) --- server/tests/lib/index.ts | 1 - .../tests/lib/video-constant-registry-factory.ts | 154 --------------------- 2 files changed, 155 deletions(-) delete mode 100644 server/tests/lib/index.ts delete mode 100644 server/tests/lib/video-constant-registry-factory.ts (limited to 'server/tests/lib') diff --git a/server/tests/lib/index.ts b/server/tests/lib/index.ts deleted file mode 100644 index a40df35fd..000000000 --- a/server/tests/lib/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './video-constant-registry-factory' diff --git a/server/tests/lib/video-constant-registry-factory.ts b/server/tests/lib/video-constant-registry-factory.ts deleted file mode 100644 index c3480dc12..000000000 --- a/server/tests/lib/video-constant-registry-factory.ts +++ /dev/null @@ -1,154 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions */ -import { expect } from 'chai' -import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory' -import { - VIDEO_CATEGORIES, - VIDEO_LANGUAGES, - VIDEO_LICENCES, - VIDEO_PLAYLIST_PRIVACIES, - VIDEO_PRIVACIES -} from '@server/initializers/constants' -import { - VideoPlaylistPrivacy, - VideoPrivacy -} from '@shared/models' - -describe('VideoConstantManagerFactory', function () { - const factory = new VideoConstantManagerFactory('peertube-plugin-constants') - - afterEach(() => { - factory.resetVideoConstants('peertube-plugin-constants') - }) - - describe('VideoCategoryManager', () => { - const videoCategoryManager = factory.createVideoConstantManager('category') - - it('Should be able to list all video category constants', () => { - const constants = videoCategoryManager.getConstants() - expect(constants).to.deep.equal(VIDEO_CATEGORIES) - }) - - it('Should be able to delete a video category constant', () => { - const successfullyDeleted = videoCategoryManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(videoCategoryManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video category constant', () => { - const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life') - expect(successfullyAdded).to.be.true - expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life') - }) - - it('Should be able to reset video category constants', () => { - videoCategoryManager.deleteConstant(1) - videoCategoryManager.resetConstants() - expect(videoCategoryManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('VideoLicenceManager', () => { - const videoLicenceManager = factory.createVideoConstantManager('licence') - it('Should be able to list all video licence constants', () => { - const constants = videoLicenceManager.getConstants() - expect(constants).to.deep.equal(VIDEO_LICENCES) - }) - - it('Should be able to delete a video licence constant', () => { - const successfullyDeleted = videoLicenceManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(videoLicenceManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video licence constant', () => { - const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence') - expect(successfullyAdded).to.be.true - expect(videoLicenceManager.getConstantValue(42 as any)).to.equal('European Union Public Licence') - }) - - it('Should be able to reset video licence constants', () => { - videoLicenceManager.deleteConstant(1) - videoLicenceManager.resetConstants() - expect(videoLicenceManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('PlaylistPrivacyManager', () => { - const playlistPrivacyManager = factory.createVideoConstantManager('playlistPrivacy') - it('Should be able to list all video playlist privacy constants', () => { - const constants = playlistPrivacyManager.getConstants() - expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES) - }) - - it('Should be able to delete a video playlist privacy constant', () => { - const successfullyDeleted = playlistPrivacyManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video playlist privacy constant', () => { - const successfullyAdded = playlistPrivacyManager.addConstant(42 as any, 'Friends only') - expect(successfullyAdded).to.be.true - expect(playlistPrivacyManager.getConstantValue(42 as any)).to.equal('Friends only') - }) - - it('Should be able to reset video playlist privacy constants', () => { - playlistPrivacyManager.deleteConstant(1) - playlistPrivacyManager.resetConstants() - expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('VideoPrivacyManager', () => { - const videoPrivacyManager = factory.createVideoConstantManager('privacy') - it('Should be able to list all video privacy constants', () => { - const constants = videoPrivacyManager.getConstants() - expect(constants).to.deep.equal(VIDEO_PRIVACIES) - }) - - it('Should be able to delete a video privacy constant', () => { - const successfullyDeleted = videoPrivacyManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video privacy constant', () => { - const successfullyAdded = videoPrivacyManager.addConstant(42 as any, 'Friends only') - expect(successfullyAdded).to.be.true - expect(videoPrivacyManager.getConstantValue(42 as any)).to.equal('Friends only') - }) - - it('Should be able to reset video privacy constants', () => { - videoPrivacyManager.deleteConstant(1) - videoPrivacyManager.resetConstants() - expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('VideoLanguageManager', () => { - const videoLanguageManager = factory.createVideoConstantManager('language') - it('Should be able to list all video language constants', () => { - const constants = videoLanguageManager.getConstants() - expect(constants).to.deep.equal(VIDEO_LANGUAGES) - }) - - it('Should be able to add a video language constant', () => { - const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan') - expect(successfullyAdded).to.be.true - expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan') - }) - - it('Should be able to delete a video language constant', () => { - videoLanguageManager.addConstant('fr', 'Fr occitan') - const successfullyDeleted = videoLanguageManager.deleteConstant('fr') - expect(successfullyDeleted).to.be.true - expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined - }) - - it('Should be able to reset video language constants', () => { - videoLanguageManager.addConstant('fr', 'Fr occitan') - videoLanguageManager.resetConstants() - expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined - }) - }) -}) -- cgit v1.2.3