Skip to content

Commit 9fa7a90

Browse files
committed
refactor(win32-def): update dependencies
1 parent 2fe7310 commit 9fa7a90

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

packages/win32-def/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@
5656
},
5757
"license": "MIT",
5858
"dependencies": {
59-
"@waiting/shared-core": "^23.25.3",
6059
"koffi": "^2.9.2"
6160
},
61+
"devDependencies": {
62+
"@waiting/shared-core": "^23.25.5"
63+
},
6264
"engines": {
6365
"node": ">=18.11.0"
6466
},

packages/win32-def/src/lib/ffi.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
export type FnCallParam = string | string[] | readonly string[]
3+
export type FnCallParams = FnCallParam[] | readonly FnCallParam[] | never[]
4+
export type FnParamsExpand = string[][]
5+
6+
export function expandFFIParamArray(input: FnCallParams): FnParamsExpand {
7+
const res: FnParamsExpand = []
8+
const tmp: string[] = []
9+
permute(input, 0, tmp, res)
10+
return res
11+
}
12+
13+
function permute(input: FnCallParams, index: number, current: string[], result: FnParamsExpand): void {
14+
if (index === input.length) {
15+
result.push(current)
16+
return
17+
}
18+
19+
const item = input[index]
20+
21+
if (Array.isArray(item)) {
22+
const len = item.length
23+
24+
for (let i = 0; i < len; i += 1) {
25+
const tmp = item[i] ?? []
26+
permute(input, index + 1, current.concat(tmp), result)
27+
}
28+
}
29+
else if (typeof item === 'string') {
30+
permute(input, index + 1, current.concat([item]), result)
31+
}
32+
else {
33+
throw new TypeError('invalid input')
34+
}
35+
}
36+

packages/win32-def/src/lib/loader/loader.helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'node:assert'
22

3-
import { expandFFIParamArray } from '@waiting/shared-core'
43
import koffi from 'koffi'
54

65
import { loadOptionsDefault } from '##/lib/config.js'
@@ -18,6 +17,8 @@ import type {
1817
UpdateMultipleChoiceMapperOptions,
1918
} from '##/lib/types.js'
2019

20+
import { expandFFIParamArray } from '../ffi.js'
21+
2122
import { LoaderCache } from './loader.cache.js'
2223
import type {
2324
BindOptions,

0 commit comments

Comments
 (0)