dev: updated node 18.19.1 for binaries

Massimo Melina committed Jul 3, 2024 at 21:40 UTC f706c4bd183f63be23568faabd0b24d66cdbb47f
4 files changed +19 -25
package.json
+2 -2
@@ -28,7 +28,7 @@
28 "dist-modules": "cp package*.json central.json dist && cd dist && npm ci --omit=dev && cd .. && node prune_modules",
29 "dist-pre": "cd dist && rm -rf node_modules/@node-rs/crc32-*",
30 "dist-bin-win": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-win32-x64-msvc && pkg . --public -C gzip -t node18-win-x64 && zip hfs-windows-x64-$(jq -r .version ../package.json).zip hfs.exe -r plugins && cd ..",
31 - "dist-bin-mac-arm": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-darwin-arm64 && pkg . --public -C gzip -t node18-macos-arm64 && zip hfs-mac-arm64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
31 + "dist-bin-mac-arm": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-darwin-arm64 && pkg . --public -C gzip -t node20-macos-arm64 && zip hfs-mac-arm64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
32 "dist-bin-mac": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-darwin-x64 && pkg . --public -C gzip -t node18-macos-x64 && zip hfs-mac-x64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
33 "dist-bin-linux": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-linux-x64-gnu && pkg . --public -C gzip -t node18-linux-x64 && zip hfs-linux-x64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
34 "dist-win": "npm run dist-modules && npm run dist-bin-win",
@@ -118,7 +118,7 @@
118 "mocha": "^9.1.3",
119 "nm-prune": "^5.0.0",
120 "nodemon": "^2.0.15",
121 - "pkg": "^5.7.0",
121 + "@yao-pkg/pkg": "^5.12.0",
122 "tough-cookie": "^4.0.0",
123 "ts-node": "^10.4.0"
124 }
src/cross.ts
+1
@@ -117,6 +117,7 @@ export function wait<T=undefined>(ms: number, val?: T): Promise<T | undefined> {
117 return new Promise(res=> setTimeout(res,ms,val))
118 }
119
120 +// throws after ms
121 export function haveTimeout<T>(ms: number, job: Promise<T>, error?: any) {
122 return Promise.race([job, wait(ms).then(() => { throw error || Error('timeout') })])
123 }
src/upload.ts
+5 -4
@@ -60,12 +60,13 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
60 }
61 else
62 try {
63 - if (!Object.hasOwn(cache, dir)) {
64 - const c = cache[dir] = getDiskSpaceSync(dir)
63 + const statDir = base.source!
64 + if (!Object.hasOwn(cache, statDir)) {
65 + const c = cache[statDir] = getDiskSpaceSync(statDir)
66 if (!c) throw 'miss'
66 - setTimeout(() => delete cache[dir], 3_000) // invalidate shortly
67 + setTimeout(() => delete cache[statDir], 3_000) // invalidate shortly
68 }
68 - const { free } = cache[dir]
69 + const { free } = cache[statDir]
70 if (typeof free !== 'number' || isNaN(free))
71 throw ''
72 if (reqSize > free - (min || 0))
src/util-os.ts
+11 -19
@@ -1,23 +1,18 @@
1 -import { dirname, resolve } from 'path'
2 -import { existsSync } from 'fs'
3 -import { exec, ExecOptions, execSync, spawnSync } from 'child_process'
4 -import { exists, onlyTruthy, prefix, splitAt } from './misc'
1 +import { resolve } from 'path'
2 +import { statfsSync } from 'fs'
3 +import { statfs } from 'node:fs/promises'
4 +import { exec, ExecOptions } from 'child_process'
5 +import { haveTimeout, onlyTruthy, prefix, splitAt } from './misc'
6 import _ from 'lodash'
7 import { pid } from 'node:process'
8 import { promisify } from 'util'
9 import { IS_WINDOWS } from './const'
10
11 const DF_TIMEOUT = 2000
11 -const LOGICALDISK_TIMEOUT = DF_TIMEOUT
12
13 -// not using statfsSync because it's not available in node 18.5.0 (latest version with pkg)
13 export function getDiskSpaceSync(path: string) {
15 - if (IS_WINDOWS)
16 - return parseLogicaldisk(execSync(makeLogicaldisk(path), { timeout: LOGICALDISK_TIMEOUT }).toString())[0]
17 - while (path && !existsSync(path))
18 - path = dirname(path)
19 - try { return parseDfResult(spawnSync('df', ['-k', path], { timeout: DF_TIMEOUT }).stdout.toString())[0] }
20 - catch(e: any) { throw parseDfResult(e) }
14 + const s = statfsSync(path)
15 + return { free: s.bavail * s.bsize, total: s.blocks * s.bsize }
16 }
17
18 export function bashEscape(par: string) {
@@ -29,17 +24,14 @@ export function cmdEscape(par: string) {
24 }
25
26 export async function getDiskSpace(path: string) {
32 - if (IS_WINDOWS)
33 - return parseLogicaldisk(await runCmd(makeLogicaldisk(path), [], { timeout: LOGICALDISK_TIMEOUT }))[0]
34 - while (path && !await exists(path))
35 - path = dirname(path)
36 - return parseDfResult(await promisify(exec)(`df -k`, { timeout: DF_TIMEOUT }).then(x => x.stdout, e => e))[0]
27 + const s = await haveTimeout(DF_TIMEOUT, statfs(path))
28 + return { name: path, free: s.bavail * s.bsize, total: s.blocks * s.bsize }
29 }
30
31 export async function getDiskSpaces(): Promise<{ name: string, free: number, total: number, description?: string }[]> {
32 if (IS_WINDOWS) {
41 - const drives = await getDrives() // since network-drives can hang 'wmic' for many seconds checking disk space (issue#648), and a single timeout would make whole operation fail, so we fork the job on each drive
42 - return onlyTruthy(await Promise.all(drives.map(getDiskSpace)))
33 + const drives = await getDrives()
34 + return onlyTruthy(await Promise.all(drives.map(x => getDiskSpace(x).catch(() => {}))))
35 }
36 return parseDfResult(await promisify(exec)(`df -k`, { timeout: DF_TIMEOUT }).then(x => x.stdout, e => e))
37 }