diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-24 13:16:55 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-24 13:28:33 +0100 |
commit | b969539c838ae3012d7a7040c5e310bb9c834e95 (patch) | |
tree | 821495c8457b19f5595c73e5778e30f6bc6a6cc7 | |
parent | 499be42ca2e03d73fef2f9501d121d830137bd6b (diff) | |
download | PeerTube-b969539c838ae3012d7a7040c5e310bb9c834e95.tar.gz PeerTube-b969539c838ae3012d7a7040c5e310bb9c834e95.tar.zst PeerTube-b969539c838ae3012d7a7040c5e310bb9c834e95.zip |
Fix types dist paths
-rw-r--r-- | .github/workflows/test.yml | 2 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | scripts/ci.sh | 5 | ||||
-rwxr-xr-x | scripts/release.sh | 2 | ||||
-rwxr-xr-x | scripts/test.sh | 1 | ||||
-rw-r--r-- | support/doc/plugins/guide.md | 24 | ||||
-rw-r--r-- | tsconfig.base.json | 2 | ||||
-rw-r--r-- | types/generate-package.ts | 5 | ||||
-rw-r--r-- | types/src/client/tsconfig.json | 3 | ||||
-rw-r--r-- | types/src/index.ts | 2 | ||||
-rw-r--r-- | types/tests/test.ts | 32 | ||||
-rw-r--r-- | types/tsconfig.dist.json | 2 | ||||
-rw-r--r-- | types/tsconfig.json | 6 | ||||
-rw-r--r-- | yarn.lock | 16 |
14 files changed, 78 insertions, 26 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 030ec3790..6bd759c06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml | |||
@@ -39,7 +39,7 @@ jobs: | |||
39 | strategy: | 39 | strategy: |
40 | fail-fast: false | 40 | fail-fast: false |
41 | matrix: | 41 | matrix: |
42 | test_suite: [ client, api-1, api-2, api-3, api-4, cli-plugin, lint, external-plugins ] | 42 | test_suite: [ types, client, api-1, api-2, api-3, api-4, cli-plugin, lint, external-plugins ] |
43 | 43 | ||
44 | env: | 44 | env: |
45 | PGUSER: peertube | 45 | PGUSER: peertube |
diff --git a/package.json b/package.json index c9717b5e9..5c133e186 100644 --- a/package.json +++ b/package.json | |||
@@ -63,6 +63,7 @@ | |||
63 | "nodemon": "nodemon", | 63 | "nodemon": "nodemon", |
64 | "ts-node": "ts-node", | 64 | "ts-node": "ts-node", |
65 | "eslint": "eslint", | 65 | "eslint": "eslint", |
66 | "resolve-tspaths": "resolve-tspaths", | ||
66 | "concurrently": "concurrently", | 67 | "concurrently": "concurrently", |
67 | "mocha": "mocha", | 68 | "mocha": "mocha", |
68 | "ci": "bash ./scripts/ci.sh", | 69 | "ci": "bash ./scripts/ci.sh", |
@@ -203,6 +204,7 @@ | |||
203 | "mocha": "^9.0.0", | 204 | "mocha": "^9.0.0", |
204 | "nodemon": "^2.0.1", | 205 | "nodemon": "^2.0.1", |
205 | "proxy": "^1.0.2", | 206 | "proxy": "^1.0.2", |
207 | "resolve-tspaths": "^0.1.2", | ||
206 | "socket.io-client": "^4.0.1", | 208 | "socket.io-client": "^4.0.1", |
207 | "source-map-support": "^0.5.0", | 209 | "source-map-support": "^0.5.0", |
208 | "supertest": "^6.0.1", | 210 | "supertest": "^6.0.1", |
diff --git a/scripts/ci.sh b/scripts/ci.sh index a628cbced..070a104cc 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh | |||
@@ -40,7 +40,10 @@ findTestFiles () { | |||
40 | find $1 -type f -name "*.js" $exception | xargs echo | 40 | find $1 -type f -name "*.js" $exception | xargs echo |
41 | } | 41 | } |
42 | 42 | ||
43 | if [ "$1" = "client" ]; then | 43 | if [ "$1" = "types" ]; then |
44 | npm run generate-types-package | ||
45 | npm run tsc -- --noEmit --esModuleInterop types/tests/test.ts | ||
46 | elif [ "$1" = "client" ]; then | ||
44 | npm run build | 47 | npm run build |
45 | 48 | ||
46 | feedsFiles=$(findTestFiles ./dist/server/tests/feeds) | 49 | feedsFiles=$(findTestFiles ./dist/server/tests/feeds) |
diff --git a/scripts/release.sh b/scripts/release.sh index 7681de90d..409a52977 100755 --- a/scripts/release.sh +++ b/scripts/release.sh | |||
@@ -121,5 +121,5 @@ rm -f "./client/dist/embed-stats.json" | |||
121 | 121 | ||
122 | # Release types package | 122 | # Release types package |
123 | npm run generate-types-package | 123 | npm run generate-types-package |
124 | cd types | 124 | cd types/dist |
125 | npm publish --access public | 125 | npm publish --access public |
diff --git a/scripts/test.sh b/scripts/test.sh index 2dc79c6ce..4d1d8720a 100755 --- a/scripts/test.sh +++ b/scripts/test.sh | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | set -eu | 3 | set -eu |
4 | 4 | ||
5 | npm run ci -- types | ||
5 | npm run ci -- client | 6 | npm run ci -- client |
6 | npm run ci -- cli-plugin | 7 | npm run ci -- cli-plugin |
7 | npm run ci -- api-1 | 8 | npm run ci -- api-1 |
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index 0a91460f5..26fcb8987 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md | |||
@@ -37,7 +37,6 @@ | |||
37 | - [Update README](#update-readme) | 37 | - [Update README](#update-readme) |
38 | - [Update package.json](#update-packagejson) | 38 | - [Update package.json](#update-packagejson) |
39 | - [Write code](#write-code) | 39 | - [Write code](#write-code) |
40 | - [Typescript](#typescript) | ||
41 | - [Add translations](#add-translations) | 40 | - [Add translations](#add-translations) |
42 | - [Build your plugin](#build-your-plugin) | 41 | - [Build your plugin](#build-your-plugin) |
43 | - [Test your plugin/theme](#test-your-plugintheme) | 42 | - [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`: | |||
880 | ### Write code | 879 | ### Write code |
881 | 880 | ||
882 | Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :) | 881 | Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :) |
882 | 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. | ||
883 | |||
884 | **JavaScript** | ||
883 | 885 | ||
884 | **Caution:** It's up to you to check the code you write will be compatible with the PeerTube NodeJS version, | ||
885 | and will be supported by web browsers. | ||
886 | If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/). | 886 | If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/). |
887 | If you want to use __Typescript__ see section below. | ||
888 | 887 | ||
889 | ### Typescript | 888 | **Typescript** |
889 | |||
890 | If you want to use __Typescript__, you can add __PeerTube__ types as dev dependencies: | ||
890 | 891 | ||
891 | You can add __PeerTube__ types as dev dependencies: | ||
892 | ``` | 892 | ``` |
893 | npm install --save-dev @peertube/peertube-types | 893 | npm install --save-dev @peertube/peertube-types |
894 | ``` | 894 | ``` |
895 | 895 | ||
896 | This package exposes *server* definition files by default: | 896 | This package exposes *server* definition files by default: |
897 | ```ts | 897 | ```ts |
898 | import { RegisterServerOptions } from '@peertube/peertube-types/server/types' | 898 | import { RegisterServerOptions } from '@peertube/peertube-types' |
899 | 899 | ||
900 | export async function register ({ registerHook }: RegisterServerOptions) { | 900 | export async function register ({ registerHook }: RegisterServerOptions) { |
901 | registerHook({ | 901 | registerHook({ |
@@ -907,8 +907,8 @@ export async function register ({ registerHook }: RegisterServerOptions) { | |||
907 | 907 | ||
908 | But it also exposes client types and various models used in __PeerTube__: | 908 | But it also exposes client types and various models used in __PeerTube__: |
909 | ```ts | 909 | ```ts |
910 | import { RegisterClientOptions } from '@larriereguichet/peertube-types/client/types'; | 910 | import { Video } from '@peertube/peertube-types'; |
911 | import { Video } from '@larriereguichet/peertube-types/shared'; | 911 | import { RegisterClientOptions } from '@peertube/peertube-types/client'; |
912 | 912 | ||
913 | function register({ registerHook, peertubeHelpers }: RegisterClientOptions) { | 913 | function register({ registerHook, peertubeHelpers }: RegisterClientOptions) { |
914 | registerHook({ | 914 | registerHook({ |
@@ -926,16 +926,14 @@ function register({ registerHook, peertubeHelpers }: RegisterClientOptions) { | |||
926 | fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, { | 926 | fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, { |
927 | method: 'PUT', | 927 | method: 'PUT', |
928 | headers: peertubeHelpers.getAuthHeader(), | 928 | headers: peertubeHelpers.getAuthHeader(), |
929 | }) | 929 | }).then((res) => res.json()) |
930 | .then((res) => res.json()) | 930 | .then((data) => console.log('Hi %s.', data)); |
931 | .then((data) => console.log('Hi %s.', data)); | ||
932 | }, | 931 | }, |
933 | }); | 932 | }); |
934 | } | 933 | } |
935 | 934 | ||
936 | export { register }; | 935 | export { register }; |
937 | ``` | 936 | ``` |
938 | > Other types are accessible from the shared path `@peertube/peertube-types/shared`. | ||
939 | 937 | ||
940 | ### Add translations | 938 | ### Add translations |
941 | 939 | ||
diff --git a/tsconfig.base.json b/tsconfig.base.json index a323b0d05..85e3ac213 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json | |||
@@ -27,7 +27,7 @@ | |||
27 | "paths": { | 27 | "paths": { |
28 | "@server/*": [ "server/*" ], | 28 | "@server/*": [ "server/*" ], |
29 | "@shared/*": [ "shared/*" ], | 29 | "@shared/*": [ "shared/*" ], |
30 | "@client/*": [ "client/src/*" ], | 30 | "@client/*": [ "client/src/*" ] |
31 | }, | 31 | }, |
32 | "resolveJsonModule": true, | 32 | "resolveJsonModule": true, |
33 | "strict": false, | 33 | "strict": false, |
diff --git a/types/generate-package.ts b/types/generate-package.ts index a4f049a31..ae061f9b0 100644 --- a/types/generate-package.ts +++ b/types/generate-package.ts | |||
@@ -23,6 +23,7 @@ async function run () { | |||
23 | 23 | ||
24 | await remove(typesDistPath) | 24 | await remove(typesDistPath) |
25 | execSync('npm run tsc -- -b --verbose types', { stdio: 'inherit' }) | 25 | execSync('npm run tsc -- -b --verbose types', { stdio: 'inherit' }) |
26 | execSync(`npm run resolve-tspaths -- --project ${distTsConfigPath} --src ${typesDistPath} --out ${typesDistPath}`, { stdio: 'inherit' }) | ||
26 | 27 | ||
27 | const allDependencies = Object.assign( | 28 | const allDependencies = Object.assign( |
28 | mainPackageJson.dependencies, | 29 | mainPackageJson.dependencies, |
@@ -69,9 +70,5 @@ async function run () { | |||
69 | console.log(`Writing git ignore to ${typesDistGitIgnorePath}`) | 70 | console.log(`Writing git ignore to ${typesDistGitIgnorePath}`) |
70 | await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo') | 71 | await writeFile(typesDistGitIgnorePath, '*.tsbuildinfo') |
71 | 72 | ||
72 | console.log('Copying tsconfig files') | ||
73 | await copyFile(distTsConfigPath, resolve(typesDistPath, './tsconfig.json')) | ||
74 | await copyFile(resolve(cwd(), './tsconfig.base.json'), resolve(typesDistPath, './tsconfig.base.json')) | ||
75 | |||
76 | await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md')) | 73 | await copyFile(resolve(typesPath, './README.md'), resolve(typesDistPath, './README.md')) |
77 | } | 74 | } |
diff --git a/types/src/client/tsconfig.json b/types/src/client/tsconfig.json index 199273538..dea4c131c 100644 --- a/types/src/client/tsconfig.json +++ b/types/src/client/tsconfig.json | |||
@@ -1,6 +1,9 @@ | |||
1 | { | 1 | { |
2 | "extends": "../../../tsconfig.base.json", | 2 | "extends": "../../../tsconfig.base.json", |
3 | "compilerOptions": { | 3 | "compilerOptions": { |
4 | "stripInternal": true, | ||
5 | "removeComments": false, | ||
6 | "emitDeclarationOnly": true, | ||
4 | "outDir": "../../dist/client/", | 7 | "outDir": "../../dist/client/", |
5 | "rootDir": "./", | 8 | "rootDir": "./", |
6 | "tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo" | 9 | "tsBuildInfoFile": "../../dist/tsconfig.client.types.tsbuildinfo" |
diff --git a/types/src/index.ts b/types/src/index.ts index f1325777f..a8adca287 100644 --- a/types/src/index.ts +++ b/types/src/index.ts | |||
@@ -1 +1,3 @@ | |||
1 | export * from '@server/types' | 1 | export * from '@server/types' |
2 | export * from '@server/types/models' | ||
3 | export * from '@shared/models' | ||
diff --git a/types/tests/test.ts b/types/tests/test.ts new file mode 100644 index 000000000..8c53320a1 --- /dev/null +++ b/types/tests/test.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { RegisterServerOptions, Video } from '../dist' | ||
2 | import { RegisterClientOptions } from '../dist/client' | ||
3 | |||
4 | function register1 ({ registerHook }: RegisterServerOptions) { | ||
5 | registerHook({ | ||
6 | target: 'action:application.listening', | ||
7 | handler: () => console.log('hello') | ||
8 | }) | ||
9 | } | ||
10 | |||
11 | function register2 ({ registerHook, peertubeHelpers }: RegisterClientOptions) { | ||
12 | registerHook({ | ||
13 | target: 'action:admin-plugin-settings.init', | ||
14 | handler: ({ npmName }: { npmName: string }) => { | ||
15 | if ('peertube-plugin-transcription' !== npmName) { | ||
16 | return | ||
17 | } | ||
18 | }, | ||
19 | }) | ||
20 | |||
21 | registerHook({ | ||
22 | target: 'action:video-watch.video.loaded', | ||
23 | handler: ({ video }: { video: Video }) => { | ||
24 | fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, { | ||
25 | method: 'PUT', | ||
26 | headers: peertubeHelpers.getAuthHeader(), | ||
27 | }) | ||
28 | .then((res) => res.json()) | ||
29 | .then((data) => console.log('Hi %s.', data)) | ||
30 | }, | ||
31 | }) | ||
32 | } | ||
diff --git a/types/tsconfig.dist.json b/types/tsconfig.dist.json index fc2dbe45b..fbc92712b 100644 --- a/types/tsconfig.dist.json +++ b/types/tsconfig.dist.json | |||
@@ -5,7 +5,7 @@ | |||
5 | "node_modules/@types", | 5 | "node_modules/@types", |
6 | "client/node_modules/@types" | 6 | "client/node_modules/@types" |
7 | ], | 7 | ], |
8 | "baseUrl": "./", | 8 | "baseUrl": "./dist", |
9 | "paths": { | 9 | "paths": { |
10 | "@server/*": [ "server/*" ], | 10 | "@server/*": [ "server/*" ], |
11 | "@shared/*": [ "shared/*" ], | 11 | "@shared/*": [ "shared/*" ], |
diff --git a/types/tsconfig.json b/types/tsconfig.json index 8f09c4a83..514683886 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json | |||
@@ -7,10 +7,11 @@ | |||
7 | "outDir": "./dist/", | 7 | "outDir": "./dist/", |
8 | "baseUrl": "./src/", | 8 | "baseUrl": "./src/", |
9 | "rootDir": "./src/", | 9 | "rootDir": "./src/", |
10 | "tsBuildInfoFile": "./dist/tsconfig.server.types.tsbuildinfo", | ||
10 | "paths": { | 11 | "paths": { |
11 | "@server/*": [ "../../server/*" ], | 12 | "@server/*": [ "../../server/*" ], |
12 | "@shared/*": [ "../../shared/*" ], | 13 | "@shared/*": [ "../../shared/*" ], |
13 | "@client/*": [ "../../client/src/*" ], | 14 | "@client/*": [ "../../client/src/*" ] |
14 | } | 15 | } |
15 | }, | 16 | }, |
16 | "references": [ | 17 | "references": [ |
@@ -18,6 +19,5 @@ | |||
18 | { "path": "../server/tsconfig.types.json" }, | 19 | { "path": "../server/tsconfig.types.json" }, |
19 | { "path": "./src/client/tsconfig.json" } | 20 | { "path": "./src/client/tsconfig.json" } |
20 | ], | 21 | ], |
21 | "files": ["./src/index.ts"], | 22 | "files": ["./src/index.ts"] |
22 | } | 23 | } |
23 | |||
@@ -3070,6 +3070,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8: | |||
3070 | dependencies: | 3070 | dependencies: |
3071 | delayed-stream "~1.0.0" | 3071 | delayed-stream "~1.0.0" |
3072 | 3072 | ||
3073 | commander@8.2.0: | ||
3074 | version "8.2.0" | ||
3075 | resolved "https://registry.yarnpkg.com/commander/-/commander-8.2.0.tgz#37fe2bde301d87d47a53adeff8b5915db1381ca8" | ||
3076 | integrity sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA== | ||
3077 | |||
3073 | commander@^2.19.0, commander@^2.7.1: | 3078 | commander@^2.19.0, commander@^2.7.1: |
3074 | version "2.20.3" | 3079 | version "2.20.3" |
3075 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" | 3080 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" |
@@ -4207,7 +4212,7 @@ fast-fifo@^1.0.0: | |||
4207 | resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.0.0.tgz#9bc72e6860347bb045a876d1c5c0af11e9b984e7" | 4212 | resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.0.0.tgz#9bc72e6860347bb045a876d1c5c0af11e9b984e7" |
4208 | integrity sha512-4VEXmjxLj7sbs8J//cn2qhRap50dGzF5n8fjay8mau+Jn4hxSeR3xPFwxMaQq/pDaq7+KQk0PAbC2+nWDkJrmQ== | 4213 | integrity sha512-4VEXmjxLj7sbs8J//cn2qhRap50dGzF5n8fjay8mau+Jn4hxSeR3xPFwxMaQq/pDaq7+KQk0PAbC2+nWDkJrmQ== |
4209 | 4214 | ||
4210 | fast-glob@^3.1.1: | 4215 | fast-glob@3.2.7, fast-glob@^3.1.1: |
4211 | version "3.2.7" | 4216 | version "3.2.7" |
4212 | resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1" | 4217 | resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1" |
4213 | integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q== | 4218 | integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q== |
@@ -7472,6 +7477,15 @@ resolve-from@^4.0.0: | |||
7472 | resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" | 7477 | resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" |
7473 | integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== | 7478 | integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== |
7474 | 7479 | ||
7480 | resolve-tspaths@^0.1.2: | ||
7481 | version "0.1.2" | ||
7482 | resolved "https://registry.yarnpkg.com/resolve-tspaths/-/resolve-tspaths-0.1.2.tgz#621c78f2372dea919f7cecf4f228e7fd6dbd8d45" | ||
7483 | integrity sha512-HBU+9gBL/CWzCXudGVJAOGph9xspBShW2Ay8cngXMB8fLBkv8Oz/yoe/LC9cCAzuZouul9YNRyKQKdr/GEFR3w== | ||
7484 | dependencies: | ||
7485 | ansi-colors "4.1.1" | ||
7486 | commander "8.2.0" | ||
7487 | fast-glob "3.2.7" | ||
7488 | |||
7475 | resolve@^1.10.1, resolve@^1.15.1, resolve@^1.18.1, resolve@^1.20.0: | 7489 | resolve@^1.10.1, resolve@^1.15.1, resolve@^1.18.1, resolve@^1.20.0: |
7476 | version "1.20.0" | 7490 | version "1.20.0" |
7477 | resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" | 7491 | resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" |