Fix types dist paths

This commit is contained in:
Chocobozzz 2021-12-24 13:16:55 +01:00
parent 499be42ca2
commit b969539c83
No known key found for this signature in database
GPG key ID: 583A612D890159BE
14 changed files with 78 additions and 26 deletions

View file

@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test_suite: [ client, api-1, api-2, api-3, api-4, cli-plugin, lint, external-plugins ]
test_suite: [ types, client, api-1, api-2, api-3, api-4, cli-plugin, lint, external-plugins ]
env:
PGUSER: peertube

View file

@ -63,6 +63,7 @@
"nodemon": "nodemon",
"ts-node": "ts-node",
"eslint": "eslint",
"resolve-tspaths": "resolve-tspaths",
"concurrently": "concurrently",
"mocha": "mocha",
"ci": "bash ./scripts/ci.sh",
@ -203,6 +204,7 @@
"mocha": "^9.0.0",
"nodemon": "^2.0.1",
"proxy": "^1.0.2",
"resolve-tspaths": "^0.1.2",
"socket.io-client": "^4.0.1",
"source-map-support": "^0.5.0",
"supertest": "^6.0.1",

View file

@ -40,7 +40,10 @@ findTestFiles () {
find $1 -type f -name "*.js" $exception | xargs echo
}
if [ "$1" = "client" ]; then
if [ "$1" = "types" ]; then
npm run generate-types-package
npm run tsc -- --noEmit --esModuleInterop types/tests/test.ts
elif [ "$1" = "client" ]; then
npm run build
feedsFiles=$(findTestFiles ./dist/server/tests/feeds)

View file

@ -121,5 +121,5 @@ rm -f "./client/dist/embed-stats.json"
# Release types package
npm run generate-types-package
cd types
cd types/dist
npm publish --access public

View file

@ -2,6 +2,7 @@
set -eu
npm run ci -- types
npm run ci -- client
npm run ci -- cli-plugin
npm run ci -- api-1

View file

@ -37,7 +37,6 @@
- [Update README](#update-readme)
- [Update package.json](#update-packagejson)
- [Write code](#write-code)
- [Typescript](#typescript)
- [Add translations](#add-translations)
- [Build your plugin](#build-your-plugin)
- [Test your plugin/theme](#test-your-plugintheme)
@ -880,22 +879,23 @@ And if you don't need CSS or client script files, use an empty `array`:
### Write code
Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :)
It's up to you to check the code you write will be compatible with the PeerTube NodeJS version, and will be supported by web browsers.
**JavaScript**
**Caution:** It's up to you to check the code you write will be compatible with the PeerTube NodeJS version,
and will be supported by web browsers.
If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/).
If you want to use __Typescript__ see section below.
### Typescript
**Typescript**
If you want to use __Typescript__, you can add __PeerTube__ types as dev dependencies:
You can add __PeerTube__ types as dev dependencies:
```
npm install --save-dev @peertube/peertube-types
```
This package exposes *server* definition files by default:
```ts
import { RegisterServerOptions } from '@peertube/peertube-types/server/types'
import { RegisterServerOptions } from '@peertube/peertube-types'
export async function register ({ registerHook }: RegisterServerOptions) {
registerHook({
@ -907,8 +907,8 @@ export async function register ({ registerHook }: RegisterServerOptions) {
But it also exposes client types and various models used in __PeerTube__:
```ts
import { RegisterClientOptions } from '@larriereguichet/peertube-types/client/types';
import { Video } from '@larriereguichet/peertube-types/shared';
import { Video } from '@peertube/peertube-types';
import { RegisterClientOptions } from '@peertube/peertube-types/client';
function register({ registerHook, peertubeHelpers }: RegisterClientOptions) {
registerHook({
@ -926,16 +926,14 @@ function register({ registerHook, peertubeHelpers }: RegisterClientOptions) {
fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, {
method: 'PUT',
headers: peertubeHelpers.getAuthHeader(),
})
.then((res) => res.json())
.then((data) => console.log('Hi %s.', data));
}).then((res) => res.json())
.then((data) => console.log('Hi %s.', data));
},
});
}
export { register };
```
> Other types are accessible from the shared path `@peertube/peertube-types/shared`.
### Add translations

View file

@ -27,7 +27,7 @@
"paths": {
"@server/*": [ "server/*" ],
"@shared/*": [ "shared/*" ],
"@client/*": [ "client/src/*" ],
"@client/*": [ "client/src/*" ]
},
"resolveJsonModule": true,
"strict": false,

View file

@ -23,6 +23,7 @@ async function run () {
await remove(typesDistPath)
execSync('npm run tsc -- -b --verbose types', { stdio: 'inherit' })
execSync(`npm run resolve-tspaths -- --project ${distTsConfigPath} --src ${typesDistPath} --out ${typesDistPath}`, { stdio: 'inherit' })
const allDependencies = Object.assign(
mainPackageJson.dependencies,
@ -69,9 +70,5 @@ async function run () {
console.log(`Writing git ignore to ${typesDistGitIgnorePath}`)
await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo')
console.log('Copying tsconfig files')
await copyFile(distTsConfigPath, resolve(typesDistPath, './tsconfig.json'))
await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesDistPath, './tsconfig.base.json'))
await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md'))
}

View file

@ -1,6 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"stripInternal": true,
"removeComments": false,
"emitDeclarationOnly": true,
"outDir": "../../dist/client/",
"rootDir": "./",
"tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo"

View file

@ -1 +1,3 @@
export * from '@server/types'
export * from '@server/types/models'
export * from '@shared/models'

32
types/tests/test.ts Normal file
View file

@ -0,0 +1,32 @@
import { RegisterServerOptions, Video } from '../dist'
import { RegisterClientOptions } from '../dist/client'
function register1 ({ registerHook }: RegisterServerOptions) {
registerHook({
target: 'action:application.listening',
handler: () => console.log('hello')
})
}
function register2 ({ registerHook, peertubeHelpers }: RegisterClientOptions) {
registerHook({
target: 'action:admin-plugin-settings.init',
handler: ({ npmName }: { npmName: string }) => {
if ('peertube-plugin-transcription' !== npmName) {
return
}
},
})
registerHook({
target: 'action:video-watch.video.loaded',
handler: ({ video }: { video: Video }) => {
fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, {
method: 'PUT',
headers: peertubeHelpers.getAuthHeader(),
})
.then((res) => res.json())
.then((data) => console.log('Hi %s.', data))
},
})
}

View file

@ -5,7 +5,7 @@
"node_modules/@types",
"client/node_modules/@types"
],
"baseUrl": "./",
"baseUrl": "./dist",
"paths": {
"@server/*": [ "server/*" ],
"@shared/*": [ "shared/*" ],

View file

@ -7,10 +7,11 @@
"outDir": "./dist/",
"baseUrl": "./src/",
"rootDir": "./src/",
"tsBuildInfoFile": "./dist/tsconfig.server.types.tsbuildinfo",
"paths": {
"@server/*": [ "../../server/*" ],
"@shared/*": [ "../../shared/*" ],
"@client/*": [ "../../client/src/*" ],
"@client/*": [ "../../client/src/*" ]
}
},
"references": [
@ -18,6 +19,5 @@
{ "path": "../server/tsconfig.types.json" },
{ "path": "./src/client/tsconfig.json" }
],
"files": ["./src/index.ts"],
"files": ["./src/index.ts"]
}

View file

@ -3070,6 +3070,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8:
dependencies:
delayed-stream "~1.0.0"
commander@8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.2.0.tgz#37fe2bde301d87d47a53adeff8b5915db1381ca8"
integrity sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA==
commander@^2.19.0, commander@^2.7.1:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
@ -4207,7 +4212,7 @@ fast-fifo@^1.0.0:
resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.0.0.tgz#9bc72e6860347bb045a876d1c5c0af11e9b984e7"
integrity sha512-4VEXmjxLj7sbs8J//cn2qhRap50dGzF5n8fjay8mau+Jn4hxSeR3xPFwxMaQq/pDaq7+KQk0PAbC2+nWDkJrmQ==
fast-glob@^3.1.1:
fast-glob@3.2.7, fast-glob@^3.1.1:
version "3.2.7"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1"
integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==
@ -7472,6 +7477,15 @@ resolve-from@^4.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
resolve-tspaths@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/resolve-tspaths/-/resolve-tspaths-0.1.2.tgz#621c78f2372dea919f7cecf4f228e7fd6dbd8d45"
integrity sha512-HBU+9gBL/CWzCXudGVJAOGph9xspBShW2Ay8cngXMB8fLBkv8Oz/yoe/LC9cCAzuZouul9YNRyKQKdr/GEFR3w==
dependencies:
ansi-colors "4.1.1"
commander "8.2.0"
fast-glob "3.2.7"
resolve@^1.10.1, resolve@^1.15.1, resolve@^1.18.1, resolve@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"