LINE 推出的 ts-remove-unused,移除掉沒有用到的程式碼

出國前看到的東西,LINEGitHub 上發表了整理 TypeScript 程式碼的套件:「Show HN: ts-remove-unused – Remove unused code from your TypeScript project (github.com/line)」,專案在「line/ts-remove-unused」這邊:

Remove unused code from your TypeScript project

不過 Hacker News 上的反應其實頗差,其中一個原因是預設值不太友善,沒有好的 ignore path 設定,test case 這種從 entry point 不會接觸到的就會被誤判了:

It deleted 100s of files, most of which were Jest test files, and potentially all of which were a mistake. I restored them all with `git restore $(git ls-files -d)`.

另外改出來的東西是爛的:

I then ran `tsc` on the remaining _modified_ files and `Found 3920 errors in 511 files.`

另外有不少人抱怨預設不是 dry run mode,被砍了一堆東西:

You should switch the default to not delete any files and modify/remove the files only with some flag (--dry-run=false, --rm, --delete, etc). I just deleted all files accidentally in a monorepo :D Luckily I didn't had any uncommitted changes and could recover using git

反倒是有人提了另外一個已經在停止發展,但運作的很好的 project:

I've been using ts-prune[1] for years at this point. The project is in maintenance mode but works fine so I've kept using it. I've been looking into Knip[2] which is recommended by the authors of ts-prune though it's been slow mostly because there's little incentive with the current tool working fine.

[1]: https://github.com/nadeesha/ts-prune

[2]: https://github.com/webpro-nl/knip

這邊反而值得看看...

幫你打理伺服器環境的 piku

但文件寫的很糟:「The tiniest PaaS you've ever seen. Piku allows you to do git push deployments to your own servers.」。

名字來自於 Dokku,另外應該是用到了 pico 這個數量級詞:

piku, inspired by dokku, allows you do git push deployments to your own servers, no matter how small they are.

這個工具是在「Piku: Allows git push deployments to your own servers (github.com/piku)」這邊看到的,就如同說明提到的,希望透過 git push 就可以發佈軟體。

不過在討論裡面也有人抱怨文件的問題,像是在 id=40625339 這邊就有人提到。

實際到 AWS 上開了一台 EC2 instance 測,看起來就是提供一包 script 把伺服器端設定好,包括了 Let's Encrypt + nginx 以及 SSHGit 相關的設定,接著你可以直接將這台 server 設為 git remote,然後就可以用 git push 推軟體上去了。

對於只是想要跑軟體,而且容易接 CI/CD 的方案來說還算 OK,但如果想要自己客製化 nginx 或是一些工具的情境就不是那麼適用了。

去電視廣告的服務又來了...

看到「Plex’s DVR now lets you skip the commercials… by removing them for you」這篇文章,介紹 Plex 要推出去電視廣告的服務...

維基百科上的介紹比較清楚:「Plex (software)」,主要有兩個元件組成,media server 與 player:

  • The Plex Media Server desktop application runs on Windows, macOS and Linux-compatibles including some types of NAS devices. The 'server' desktop application organizes video, audio and photos from your collections and from online services, enabling the players to access and stream the contents.
  • The media players. There are official clients available for mobile devices, smart TVs, and streaming boxes, a web app and Plex Home Theater (no longer maintained), as well as many third-party alternatives.

然後這次要推出的功能是直接在錄影的時候把廣告拿掉:

Plex confirmed it’s rolling out a new feature that will allow cord cutters to skip the commercials in the TV programs recorded using its software, making the company’s lower-cost solution to streaming live TV more compelling. Unlike other commercial-skip options, Plex’s option will remove commercials from recordings automatically.

這讓我有些印像... 當年 TiVo 也有類似的功能,不過文章裡有提到 TiVo 是提供 skip 而非直接拿掉:

The new feature works by locating the commercials in your recorded media. It then actually removes them before the media is stored in your library. That sounds like it could be even better than TiVo’s commercial skipping option, for example, because you don’t have to press a button to skip the ads — they’re being pulled out for you, proactively.

不過主要是認識了 Plex 這個軟體... 如果是電視兒童的話應該用的到 XD 台灣目前的電視節目好像看的比較少...

移除 Remove Facebook Redirections...

Google Chrome 裝上 Remove Facebook Redirections 可以避免 Facebook 重導,加減提高些隱私性...

不過最近發現當 Facebook 捲頁捲很長時會變得爆慢,但網路上好像沒有人提到這個問題?看起來應該是我的某個 extension 造成的,測了老半天發現是這個 extension 的問題 :o 然後身為工程師的直覺,這八成是每次增加元素後直接對整個 document 全掃一次造成的...

翻 source code 後 (直接到 Default/Extensions/onhdomkbnapoacbialllfpbcckckidck/1.2_0/ 裡的 RemoveFacebookRedirections.js 翻) 可以發現 huntForLinks() 果然就是這樣做...

先移除掉再說 @_@