Skip to content

Commit

Permalink
refactor(win32-def): update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Dec 26, 2024
1 parent 2fe7310 commit 9fa7a90
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/win32-def/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
},
"license": "MIT",
"dependencies": {
"@waiting/shared-core": "^23.25.3",
"koffi": "^2.9.2"
},
"devDependencies": {
"@waiting/shared-core": "^23.25.5"
},
"engines": {
"node": ">=18.11.0"
},
Expand Down
36 changes: 36 additions & 0 deletions packages/win32-def/src/lib/ffi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

export type FnCallParam = string | string[] | readonly string[]
export type FnCallParams = FnCallParam[] | readonly FnCallParam[] | never[]
export type FnParamsExpand = string[][]

export function expandFFIParamArray(input: FnCallParams): FnParamsExpand {
const res: FnParamsExpand = []
const tmp: string[] = []
permute(input, 0, tmp, res)
return res
}

function permute(input: FnCallParams, index: number, current: string[], result: FnParamsExpand): void {
if (index === input.length) {
result.push(current)
return
}

const item = input[index]

if (Array.isArray(item)) {
const len = item.length

for (let i = 0; i < len; i += 1) {
const tmp = item[i] ?? []
permute(input, index + 1, current.concat(tmp), result)
}
}
else if (typeof item === 'string') {
permute(input, index + 1, current.concat([item]), result)
}
else {
throw new TypeError('invalid input')
}
}

3 changes: 2 additions & 1 deletion packages/win32-def/src/lib/loader/loader.helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'node:assert'

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

import { loadOptionsDefault } from '##/lib/config.js'
Expand All @@ -18,6 +17,8 @@ import type {
UpdateMultipleChoiceMapperOptions,
} from '##/lib/types.js'

import { expandFFIParamArray } from '../ffi.js'

import { LoaderCache } from './loader.cache.js'
import type {
BindOptions,
Expand Down

0 comments on commit 9fa7a90

Please sign in to comment.