refactor(release-cleanup): 將清理邏輯由 bash 改寫為 Node.js #6
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
// 進入點:載入設定、建立 Gitea 客戶端,依序清理舊成品與孤立 tag。
|
// 進入點:載入設定、建立 Gitea 客戶端,依序清理舊成品與孤立 tag。
|
||||||
|
|
||||||
|
import { pathToFileURL } from 'node:url'
|
||||||
import { loadConfig } from './config.js'
|
import { loadConfig } from './config.js'
|
||||||
import { GiteaClient } from './gitea-client.js'
|
import { GiteaClient } from './gitea-client.js'
|
||||||
import { cleanupReleases } from './releases.js'
|
import { cleanupReleases } from './releases.js'
|
||||||
@@ -25,7 +26,8 @@ export async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 僅在直接以 `node index.js` 執行時啟動主流程;被測試 import 時不自動執行,方便撰寫整合測試。
|
// 僅在直接以 `node index.js` 執行時啟動主流程;被測試 import 時不自動執行,方便撰寫整合測試。
|
||||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
// 以 pathToFileURL 正確處理含空白/特殊字元的路徑與跨平台差異,避免手動拼接 file:// 的脆弱性。
|
||||||
|
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||||
|
Ghost marked this conversation as resolved
Outdated
|
|||||||
main().catch((error) => {
|
main().catch((error) => {
|
||||||
failError(error)
|
failError(error)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user
嚴重等級:🔵 建議
審查員:Bard
問題:手動拼接 import.meta.url 字串來判斷執行入口,寫法原始且脆弱。
建議:引用 node:url 中的 pathToFileURL,使用 import.meta.url === pathToFileURL(process.argv[1]).href 進行比較。