]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix types dist paths
authorChocobozzz <me@florianbigard.com>
Fri, 24 Dec 2021 12:16:55 +0000 (13:16 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 24 Dec 2021 12:28:33 +0000 (13:28 +0100)
14 files changed:
.github/workflows/test.yml
package.json
scripts/ci.sh
scripts/release.sh
scripts/test.sh
support/doc/plugins/guide.md
tsconfig.base.json
types/generate-package.ts
types/src/client/tsconfig.json
types/src/index.ts
types/tests/test.ts [new file with mode: 0644]
types/tsconfig.dist.json
types/tsconfig.json
yarn.lock

index 030ec37908216b1c8287eb35b79e5625f402c3ee..6bd759c0674e6028ad1550c2135a5918993291ca 100644 (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
index c9717b5e96052d029fb213ed48501c14c6ec8b84..5c133e18643ec95053abbe171fbc219325dd39f4 100644 (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",
     "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",
index a628cbcedb34e4832df075fa67dc97e670a11bb5..070a104ccffd8bb8c873638f9d8792f077426f8f 100755 (executable)
@@ -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)
index 7681de90da243acb15ee14cf33fff6211b4b2149..409a52977391891a0c4107b179cb18e8a10b13f9 100755 (executable)
@@ -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
index 2dc79c6ceba3a9ac64fda224ca554548aa74173f..4d1d8720a68f5866ba9896ee9f973381dba2e57b 100755 (executable)
@@ -2,6 +2,7 @@
 
 set -eu
 
+npm run ci -- types
 npm run ci -- client
 npm run ci -- cli-plugin
 npm run ci -- api-1
index 0a91460f5d6768a900117e0d4a87776af46fbaa2..26fcb8987793c826b988901991ed0646161c534b 100644 (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
 
index a323b0d05e5293f2682f3809c8b39da8f2c66c23..85e3ac213304cd6f4dbb831c6ffc1858bc252b81 100644 (file)
@@ -27,7 +27,7 @@
     "paths": {
       "@server/*": [ "server/*" ],
       "@shared/*": [ "shared/*" ],
-      "@client/*": [ "client/src/*" ],
+      "@client/*": [ "client/src/*" ]
     },
     "resolveJsonModule": true,
     "strict": false,
index a4f049a31ae7a01c22dac1846770ede20b5596da..ae061f9b0f930536596927113d0ddaebc3aa8ad9 100644 (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'))
 }
index 199273538bb0ad2341480a58887357b826bb6649..dea4c131c4081ed004ae304876be3b90e30ecbac 100644 (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"
index f1325777f61efb00e947b50480e1689b074b697e..a8adca287810e95dd1441c5dc025660dfbe4c65e 100644 (file)
@@ -1 +1,3 @@
 export * from '@server/types'
+export * from '@server/types/models'
+export * from '@shared/models'
diff --git a/types/tests/test.ts b/types/tests/test.ts
new file mode 100644 (file)
index 0000000..8c53320
--- /dev/null
@@ -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))
+    },
+  })
+}
index fc2dbe45bdb2a44d934bc376fad5a7424180d56c..fbc92712b9eefef7fffc39acfa2da6b70878c3f6 100644 (file)
@@ -5,7 +5,7 @@
       "node_modules/@types",
       "client/node_modules/@types"
     ],
-    "baseUrl": "./",
+    "baseUrl": "./dist",
     "paths": {
       "@server/*": [ "server/*" ],
       "@shared/*": [ "shared/*" ],
index 8f09c4a831f4adb1d68e642d32a8977363701391..51468388676d38114e055c8931126bf6054c4c98 100644 (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"]
 }
-
index 8c9527cf986823aa2da5e3395a9d9649de60bc9b..c0efa220348f8cd2640269cf5c17d51d97e78f1c 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -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"