mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
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)
This commit is contained in:
parent
04d1da5621
commit
3a4992633e
2196 changed files with 12690 additions and 11574 deletions
19
packages/typescript-utils/package.json
Normal file
19
packages/typescript-utils/package.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "@peertube/peertube-typescript-utils",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"main": "dist/index.js",
|
||||
"files": [ "dist" ],
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"peertube:tsx": "./src/index.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
1
packages/typescript-utils/src/index.ts
Normal file
1
packages/typescript-utils/src/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './types.js'
|
45
packages/typescript-utils/src/types.ts
Normal file
45
packages/typescript-utils/src/types.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* eslint-disable @typescript-eslint/array-type */
|
||||
|
||||
export type FunctionPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends Function ? K : never
|
||||
}[keyof T]
|
||||
|
||||
export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>
|
||||
|
||||
export type AttributesOnly<T> = {
|
||||
[K in keyof T]: T[K] extends Function ? never : T[K]
|
||||
}
|
||||
|
||||
export type PickWith<T, KT extends keyof T, V> = {
|
||||
[P in KT]: T[P] extends V ? V : never
|
||||
}
|
||||
|
||||
export type PickWithOpt<T, KT extends keyof T, V> = {
|
||||
[P in KT]?: T[P] extends V ? V : never
|
||||
}
|
||||
|
||||
// https://github.com/krzkaczor/ts-essentials Rocks!
|
||||
export type DeepPartial<T> = {
|
||||
[P in keyof T]?: T[P] extends Array<infer U>
|
||||
? Array<DeepPartial<U>>
|
||||
: T[P] extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<DeepPartial<U>>
|
||||
: DeepPartial<T[P]>
|
||||
}
|
||||
|
||||
type Primitive = string | Function | number | boolean | symbol | undefined | null
|
||||
export type DeepOmitHelper<T, K extends keyof T> = {
|
||||
[P in K]: // extra level of indirection needed to trigger homomorhic behavior
|
||||
T[P] extends infer TP // distribute over unions
|
||||
? TP extends Primitive
|
||||
? TP // leave primitives and functions alone
|
||||
: TP extends any[]
|
||||
? DeepOmitArray<TP, K> // Array special handling
|
||||
: DeepOmit<TP, K>
|
||||
: never
|
||||
}
|
||||
export type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>>
|
||||
|
||||
export type DeepOmitArray<T extends any[], K> = {
|
||||
[P in keyof T]: DeepOmit<T[P], K>
|
||||
}
|
8
packages/typescript-utils/tsconfig.json
Normal file
8
packages/typescript-utils/tsconfig.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "src",
|
||||
"tsBuildInfoFile": "./dist/.tsbuildinfo"
|
||||
}
|
||||
}
|
10
packages/typescript-utils/tsconfig.types.json
Normal file
10
packages/typescript-utils/tsconfig.types.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../types-generator/dist/peertube-typescript-utils",
|
||||
"tsBuildInfoFile": "../types-generator/dist/peertube-typescript-utils/.tsbuildinfo",
|
||||
"stripInternal": true,
|
||||
"removeComments": false,
|
||||
"emitDeclarationOnly": true
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue