rhysd / electron-about-window

'About This App' mini-window for Electron apps
https://www.npmjs.com/package/about-window
MIT License
413 stars 45 forks source link

Generate declaration files from .ts, and use it as typings #70

Closed h3poteto closed 2 years ago

h3poteto commented 2 years ago

At the moment, there is a declaration file, but it is not the latest. AboutWindowInfo is defined in here, but it is not the same as index.d.ts.

For example, I want to specify app for the openAboutWindow function, but there is no definition of app in index.d.ts. https://github.com/rhysd/electron-about-window/blob/537d0855da73c8fbaf34bb652b54b3bd9f57be45/index.d.ts#L3-L21

So I change tsconfig to generate declaration files from .ts, and use it as typings in package.json. After this change, src/index.d.ts is generated automatically using npm run build.

rhysd commented 2 years ago

Thanks.

rhysd commented 2 years ago

@h3poteto すみません,https://github.com/rhysd/electron-about-window/blob/master/src/lib.d.ts にまだ手書きの .d.ts が残っていて npm run build で生成される .d.ts は src/lib.d.ts を見ているので,どう改善されたのかよく分からなかったのですが,説明いただけませんでしょうか

For example, I want to specify app for the openAboutWindow function, but there is no definition of app in index.d.ts.

いえ,app の定義は https://github.com/rhysd/electron-about-window/blob/185c4323055591e0ea3844653e3cb8a0ee3d5507/src/lib.d.ts#L36 にこの PR をマージする前からあるようですよ.

h3poteto commented 2 years ago

前提

もともとpackage.jsonにtypingsの指定がなかったので,1.15.0までは,こちらのindex.d.tsが参照されていました. https://github.com/rhysd/electron-about-window/blob/v1.15.0/index.d.ts ここにはappの定義が存在しないため,ユーザはappを指定することができませんでした(typescriptの場合). また,npmignoreに/src/*.tsの記載があったため,src/lib.d.tsはそもそもnpmにpublishされていません.そのため,たとえappの定義がsrc/lib.d.tsに書いてあったとしても,npm installしたユーザがそれを参照することは不可能でした.

今回の変更

  1. tsconfigを変更しnpm run buildにより.d.tsファイルを生成するように変更しています.
    • 確かにsrc/lib.d.tsはあるのですが,openAboutWindow 関数の定義はsrc/index.tsに存在しており,この関数を定義するd.tsが存在しませんでした.この変更により,src/index.ts内のopenAboutWindow関数の型定義ファイルsrc/index.d.tsが生成されるようになります
    • 今後.tsファイル内に関数定義等を増やした場合も同様にd.tsファイルが自動生成されるようになります
    • AboutWindowInfoを定義している.tsファイルが,src/lib.d.tsしかないので,このファイルは引き続き必要です
  2. 上記で生成されるsrc/index.d.tsをpackage.jsonのtypingsに指定することで,ユーザがこのライブラリを参照したときに使われるd.tsファイルがsrc/index.d.tsになります.
    • このためトップディレクトリのindex.d.tsが不要になるため,これを削除しています
  3. src/index.d.tsが生成されても,npmignoreにより無視されてしまうので,src/*.d.tsファイルは無視せずにnpm publishに含めるように変更しています.
rhysd commented 2 years ago

ご説明いただきありがとうございます.

なるほど,どうやらどこかの時点で /index.d.ts/src/index.d.ts が重複して存在してしまい,/src/index.d.ts のほうだけがメンテされてしまっている状態になっていたようですね(これは意図していませんでした).理由までは追ってませんが,おそらく他のプロジェクトと混同してしまっていたものと思います.

新しいバージョンをリリースしてこの変更を使えるようにします.

rhysd commented 2 years ago

v1.15.1 をリリースしました