diff --git a/packages/playground/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uniplugin/utssdk/app-ios/index.swift.map b/packages/playground/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uniplugin/utssdk/app-ios/index.swift.map index c55fa49033900a40274dd88e0f1552e60bc5eef7..a1fb4972ccb66cfaa1e93f34676a1987340d7b1d 100644 --- a/packages/playground/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uniplugin/utssdk/app-ios/index.swift.map +++ b/packages/playground/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uniplugin/utssdk/app-ios/index.swift.map @@ -1 +1 @@ -{"version":3,"sources":["uni_modules/test-uniplugin/utssdk/app-ios/index.uts","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["import { UIDevice } from 'UIKit'\nimport { CLLocationManager, CLAuthorizationStatus } from 'CoreLocation'\nimport { ShowToast } from '../interface.uts'\n\ntype GetBatteryInfoOptions = {\n name: string\n pwd: number\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\n\nexport default function getBatteryInfo(options: GetBatteryInfoOptions) {\n new UIAlertController(\n (title = title),\n (message = message),\n (preferredStyle = UIAlertController.Style.alert)\n )\n const res = {\n errMsg: 'getBatteryInfo:ok',\n level: UIDevice.current.batteryLevel * 100,\n isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,\n }\n if (options.success != null) {\n options.success!(res)\n }\n if (options.complete != null) {\n options.complete!(res)\n }\n}\n\nexport function test1(callback: () => void): string {\n console.log({ \"a\": \"b\" })\n console.log('test1')\n\n\n\n\n console.log('def ios')\n\n\n console.log('ndef android')\n\n\n\n\n\n console.log('def android || def ios')\n\n\n\n\n console.log(CLLocationManager, CLAuthorizationStatus)\n const a = -3\n console.log(~a)\n return 'test1'\n}\n\nclass Test1 { }\nexport class Test {\n constructor() {\n new Test1()\n }\n test(): string | null {\n if (UTSiOS.macros(\"swift(>=1)\")) {\n console.log(\"swift(>=1)\")\n }\n if (UTSiOS.macros(\"arch(i386) || arch(arm)\")) {\n console.log(\"arch(i386) || arch(arm)\")\n }\n if (UTSiOS.available(\"iOS 14, macOS 11.0, *\")) {\n console.log(\"iOS 14, macOS 11.0, *\")\n } else if (UTSiOS.available(\"iOS 13,*\")) {\n console.log(\"iOS 13,*\")\n } else if (UTSiOS.unavailable(\"tvOS 12\")) {\n console.log(\"tvOS 12\")\n }\n return null\n }\n}\n\nexport async function testAsync() {\n uni.showToast()\n uni.showToast()\n uni.showModel()\n return { a: 1 }\n}\n\nexport const showToast1: ShowToast = (msg) => { }\nexport const showToast2: ShowToast = function (msg) { }\nexport const showToast3: ShowToast = function showToast(msg) { }\n","export type ShowToast = (msg: string) => void\n"],"names":[],"mappings":";;AAAA,aAAgC;AAChC,oBAAuE;;;iBCD3D,eAAa,KAAK,MAAM,KAAK,IAAI;ADIhB;;aAAxB;IACH,WAAA,MAAM,MAAM,EAAA;IACZ,WAAA,KAAK,QAAM,EAAA;IACX,WAAA,aAAW,KAAK,kBAAkB,IAAI,GAAA;IACtC,WAAA,UAAQ,KAAK,kBAAkB,IAAI,GAAA;IACnC,WAAA,cAAY,KAAK,kBAAkB,IAAI,GAAA;;;;;QAJvC,uBAAM,MAAM;QACZ,qBAAK,QAAM;QACX,iCAAW,KAAK,kBAAkB,IAAI;QACtC,2BAAQ,KAAK,kBAAkB,IAAI;QACnC,mCAAY,KAAK,kBAAkB,IAAI;;AACzC;AAEe,YAAS,eAAe,EAAA,SAAS,qBAAqB,EAAE;IACjE,kBACD,OAAQ,OACR,SAAU,SACV,gBAAiB,kBAAkB,KAAK,CAAC,KAAK;IAEjD,IAAM,MAAM;QACV,CAAA,SAAQ;QACR,CAAA,QAAO,SAAS,OAAO,CAAC,YAAY,GAAG,GAAG;QAC1C,CAAA,aAAY,SAAS,OAAO,CAAC,YAAY,IAAI,SAAS,YAAY,CAAC,QAAQ;MAC5E;IACD,IAAI,QAAQ,OAAO,IAAI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KAAK,IAAI;sBAApB;;6BAAA,KAAK,MAAM,KAAK,IAAI;sBAApB;;6BAAA,KAAK,MAAM,KAAK,IAAI;sBAApB;;;;;4CDYc,EAAA,SAAS,+BAAqB;kCAA9B;;qCAmBjB,0BAAuB,MAAM;yBAA7B;;;;;;0CC/BG,KAAK,MAAM,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB"} \ No newline at end of file +{"version":3,"sources":["uni_modules/test-uniplugin/utssdk/app-ios/index.uts","uni_modules/test-uniplugin/utssdk/interface.uts"],"sourcesContent":["import { UIDevice } from 'UIKit'\nimport { CLLocationManager, CLAuthorizationStatus } from 'CoreLocation'\nimport { ShowToast } from '../interface.uts'\n\ntype GetBatteryInfoOptions = {\n name: string\n pwd: number\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\n\nexport default function getBatteryInfo(options: GetBatteryInfoOptions) {\n new UIAlertController(\n (title = title),\n (message = message),\n (preferredStyle = UIAlertController.Style.alert)\n )\n const res = {\n errMsg: 'getBatteryInfo:ok',\n level: UIDevice.current.batteryLevel * 100,\n isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,\n }\n if (options.success != null) {\n options.success!(res)\n }\n if (options.complete != null) {\n options.complete!(res)\n }\n}\n\nexport function test1(callback: () => void): string {\n console.log({ \"a\": \"b\" })\n console.log('test1')\n\n\n\n\n console.log('def ios')\n\n\n console.log('ndef android')\n\n\n\n\n\n console.log('def android || def ios')\n\n\n\n\n console.log(CLLocationManager, CLAuthorizationStatus)\n const a = -3\n console.log(~a)\n return 'test1'\n}\n\nclass Test1 { }\nexport class Test {\n constructor() {\n new Test1()\n }\n test(): string | null {\n if (UTSiOS.macros(\"swift(>=1)\")) {\n console.log(\"swift(>=1)\")\n }\n if (UTSiOS.macros(\"arch(i386) || arch(arm)\")) {\n console.log(\"arch(i386) || arch(arm)\")\n }\n if (UTSiOS.available(\"iOS 14, macOS 11.0, *\")) {\n console.log(\"iOS 14, macOS 11.0, *\")\n } else if (UTSiOS.available(\"iOS 13,*\")) {\n console.log(\"iOS 13,*\")\n } else if (UTSiOS.unavailable(\"tvOS 12\")) {\n console.log(\"tvOS 12\")\n }\n return null\n }\n}\n\nexport async function testAsync() {\n uni.showToast()\n uni.showToast()\n uni.showModel()\n return { a: 1 }\n}\n\nexport const showToast1: ShowToast = (msg) => { }\nexport const showToast2: ShowToast = function (msg) { }\nexport const showToast3: ShowToast = function showToast(msg) { }\n","export type ShowToast = (msg: string) => void\n"],"names":[],"mappings":";;AAAA,aAAgC;AAChC,oBAAuE;;;iBCD3D,eAAa,KAAK,MAAM,KAAK,IAAI;ADIhB;;aAAxB;IACH,WAAA,MAAM,MAAM,EAAA;IACZ,WAAA,KAAK,QAAM,EAAA;IACX,WAAA,aAAW,KAAK,kBAAkB,IAAI,GAAA;IACtC,WAAA,UAAQ,KAAK,kBAAkB,IAAI,GAAA;IACnC,WAAA,cAAY,KAAK,kBAAkB,IAAI,GAAA;;;;;QAJvC,uBAAM,MAAM;QACZ,qBAAK,QAAM;QACX,iCAAW,KAAK,kBAAkB,IAAI;QACtC,2BAAQ,KAAK,kBAAkB,IAAI;QACnC,mCAAY,KAAK,kBAAkB,IAAI;;AACzC;AAEe,YAAS,eAAe,EAAA,SAAS,qBAAqB,EAAE;IACjE,kBACD,OAAQ,OACR,SAAU,SACV,gBAAiB,kBAAkB,KAAK,CAAC,KAAK;IAEjD,IAAM,MAAM;QACV,CAAA,SAAQ;QACR,CAAA,QAAO,SAAS,OAAO,CAAC,YAAY,GAAG,GAAG;QAC1C,CAAA,aAAY,SAAS,OAAO,CAAC,YAAY,IAAI,SAAS,YAAY,CAAC,QAAQ;MAC5E;IACD,IAAI,QAAQ,OAAO,IAAI,GAAI;QACzB,QAAQ,OAAO,EAAE;;IAEnB,IAAI,QAAQ,QAAQ,IAAI,GAAI;QAC1B,Q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IAAI;sBAApB;;;;;4CDYc,EAAA,SAAS,+BAAqB;kCAA9B;;qCAmBjB,0BAAuB,MAAM;yBAA7B;;;;;;0CC/BG,KAAK,MAAM,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB;;0CAAA,KAAK,MAAM,KAAK,IAAI;8BAApB"} \ No newline at end of file diff --git a/packages/playground/uts/unpackage/dist/dev/app-plus/uni_modules/test-uniplugin/utssdk/app-ios/index.swift b/packages/playground/uts/unpackage/dist/dev/app-plus/uni_modules/test-uniplugin/utssdk/app-ios/index.swift index 81f22f86eb5c965c1d4aa85588f642cc07890f1e..69e0b0193735ebe0222c307188ffcbffb095f84e 100644 --- a/packages/playground/uts/unpackage/dist/dev/app-plus/uni_modules/test-uniplugin/utssdk/app-ios/index.swift +++ b/packages/playground/uts/unpackage/dist/dev/app-plus/uni_modules/test-uniplugin/utssdk/app-ios/index.swift @@ -136,9 +136,6 @@ public func test1ByJs(_ callback: UTSCallback) -> String { @objc(UTSSDKModulesTestUniPluginTestByJs) @objcMembers public class TestByJs : Test { - override public init(){ - super.init(); - } public func testByJs() -> String? { return test(); } diff --git a/packages/uni-app-plus/dist/uni.runtime.esm.js b/packages/uni-app-plus/dist/uni.runtime.esm.js index 1dea23277d5c2bb7280640c5a03535bd8423239e..5198904f883043143af929073dbff8e1c7cef66c 100644 --- a/packages/uni-app-plus/dist/uni.runtime.esm.js +++ b/packages/uni-app-plus/dist/uni.runtime.esm.js @@ -17302,6 +17302,9 @@ function getProxy() { return proxy; } function resolveSyncResult(res) { + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeSync.result', res); + } if (res.errMsg) { throw new Error(res.errMsg); } @@ -17312,6 +17315,9 @@ function invokePropGetter(args) { throw new Error(args.errMsg); } delete args.errMsg; + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokePropGetter.args', args); + } return resolveSyncResult(getProxy().invokeSync(args, () => { })); } function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: cls, name: propOrMethod, method, companion, params: methodParams, errMsg, }, instanceId) { @@ -17353,7 +17359,13 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: }); if (async) { return new Promise((resolve, reject) => { + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeAsync.args', invokeArgs); + } getProxy().invokeAsync(invokeArgs, (res) => { + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeAsync.result', res); + } if (res.type !== 'return') { invokeCallback(res); } @@ -17368,6 +17380,9 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: }); }); } + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeSync.args', invokeArgs); + } return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback)); }; } @@ -17380,6 +17395,12 @@ function initUTSStaticMethod(async, opts) { return initProxyFunction(async, opts, 0); } const initUTSProxyFunction = initUTSStaticMethod; +function parseClassMethodName(name, methods) { + if (hasOwn$1(methods, name + 'ByJs')) { + return name + 'ByJs'; + } + return name; +} function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, errMsg, }) { const baseOptions = { moduleName, @@ -17388,6 +17409,12 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c class: cls, errMsg, }; + // iOS 需要为 ByJs 的 class 构造函数(如果包含JSONObject或UTSCallback类型)补充最后一个参数 + if (typeof plus !== 'undefined' && plus.os.name === 'iOS') { + if (constructorParams.find((p) => p.type === 'UTSCallback' || p.type.indexOf('JSONObject') > 0)) { + constructorParams.push({ name: '_byJs', type: 'boolean' }); + } + } const ProxyClass = class UTSClass { constructor(...params) { if (errMsg) { @@ -17403,6 +17430,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c get(_, name) { if (!target[name]) { //实例方法 + name = parseClassMethodName(name, methods); if (hasOwn$1(methods, name)) { const { async, params } = methods[name]; target[name] = initUTSInstanceMethod(!!async, extend({ @@ -17429,6 +17457,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c const staticMethodCache = {}; return new Proxy(ProxyClass, { get(target, name, receiver) { + name = parseClassMethodName(name, staticMethods); if (hasOwn$1(staticMethods, name)) { if (!staticMethodCache[name]) { const { async, params } = staticMethods[name]; diff --git a/packages/uni-app-plus/src/service/api/plugin/uts.js b/packages/uni-app-plus/src/service/api/plugin/uts.js index 719c081f763d03959290cf3559e77479751ad1ec..681c0217c375e00e25f0a8cd55ed88fec6b85d2e 100644 --- a/packages/uni-app-plus/src/service/api/plugin/uts.js +++ b/packages/uni-app-plus/src/service/api/plugin/uts.js @@ -28,6 +28,9 @@ function getProxy() { return proxy; } function resolveSyncResult(res) { + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeSync.result', res); + } if (res.errMsg) { throw new Error(res.errMsg); } @@ -38,6 +41,9 @@ function invokePropGetter(args) { throw new Error(args.errMsg); } delete args.errMsg; + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokePropGetter.args', args); + } return resolveSyncResult(getProxy().invokeSync(args, () => { })); } function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: cls, name: propOrMethod, method, companion, params: methodParams, errMsg, }, instanceId) { @@ -79,7 +85,13 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: }); if (async) { return new Promise((resolve, reject) => { + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeAsync.args', invokeArgs); + } getProxy().invokeAsync(invokeArgs, (res) => { + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeAsync.result', res); + } if (res.type !== 'return') { invokeCallback(res); } @@ -94,6 +106,9 @@ function initProxyFunction(async, { moduleName, moduleType, package: pkg, class: }); }); } + if ((process.env.NODE_ENV !== 'production')) { + console.log('uts.invokeSync.args', invokeArgs); + } return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback)); }; } @@ -106,6 +121,12 @@ function initUTSStaticMethod(async, opts) { return initProxyFunction(async, opts, 0); } const initUTSProxyFunction = initUTSStaticMethod; +function parseClassMethodName(name, methods) { + if (hasOwn(methods, name + 'ByJs')) { + return name + 'ByJs'; + } + return name; +} function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, constructor: { params: constructorParams }, methods, props, staticProps, staticMethods, errMsg, }) { const baseOptions = { moduleName, @@ -114,6 +135,12 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c class: cls, errMsg, }; + // iOS 需要为 ByJs 的 class 构造函数(如果包含JSONObject或UTSCallback类型)补充最后一个参数 + if (typeof plus !== 'undefined' && plus.os.name === 'iOS') { + if (constructorParams.find((p) => p.type === 'UTSCallback' || p.type.indexOf('JSONObject') > 0)) { + constructorParams.push({ name: '_byJs', type: 'boolean' }); + } + } const ProxyClass = class UTSClass { constructor(...params) { if (errMsg) { @@ -129,6 +156,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c get(_, name) { if (!target[name]) { //实例方法 + name = parseClassMethodName(name, methods); if (hasOwn(methods, name)) { const { async, params } = methods[name]; target[name] = initUTSInstanceMethod(!!async, extend({ @@ -155,6 +183,7 @@ function initUTSProxyClass({ moduleName, moduleType, package: pkg, class: cls, c const staticMethodCache = {}; return new Proxy(ProxyClass, { get(target, name, receiver) { + name = parseClassMethodName(name, staticMethods); if (hasOwn(staticMethods, name)) { if (!staticMethodCache[name]) { const { async, params } = staticMethods[name]; diff --git a/packages/uni-app-plus/src/service/api/plugin/uts.ts b/packages/uni-app-plus/src/service/api/plugin/uts.ts index 89bf4b5ae10517672e96c6cb00d76c23ea72c5ce..0cbaee09a848185f12ab6965c3c2d77304af2d18 100644 --- a/packages/uni-app-plus/src/service/api/plugin/uts.ts +++ b/packages/uni-app-plus/src/service/api/plugin/uts.ts @@ -176,6 +176,9 @@ function getProxy(): { } function resolveSyncResult(res: InvokeSyncRes) { + if (__DEV__) { + console.log('uts.invokeSync.result', res) + } if (res.errMsg) { throw new Error(res.errMsg) } @@ -187,6 +190,9 @@ function invokePropGetter(args: InvokeArgs) { throw new Error(args.errMsg) } delete args.errMsg + if (__DEV__) { + console.log('uts.invokePropGetter.args', args) + } return resolveSyncResult(getProxy().invokeSync(args, () => {})) } @@ -247,7 +253,13 @@ function initProxyFunction( }) if (async) { return new Promise((resolve, reject) => { + if (__DEV__) { + console.log('uts.invokeAsync.args', invokeArgs) + } getProxy().invokeAsync(invokeArgs, (res) => { + if (__DEV__) { + console.log('uts.invokeAsync.result', res) + } if (res.type !== 'return') { invokeCallback(res) } else { @@ -260,6 +272,9 @@ function initProxyFunction( }) }) } + if (__DEV__) { + console.log('uts.invokeSync.args', invokeArgs) + } return resolveSyncResult(getProxy().invokeSync(invokeArgs, invokeCallback)) } } @@ -275,6 +290,13 @@ function initUTSStaticMethod(async: boolean, opts: ProxyFunctionOptions) { export const initUTSProxyFunction = initUTSStaticMethod +function parseClassMethodName(name: string, methods: Record) { + if (hasOwn(methods, name + 'ByJs')) { + return name + 'ByJs' + } + return name +} + export function initUTSProxyClass({ moduleName, moduleType, @@ -294,6 +316,16 @@ export function initUTSProxyClass({ class: cls, errMsg, } + // iOS 需要为 ByJs 的 class 构造函数(如果包含JSONObject或UTSCallback类型)补充最后一个参数 + if (typeof plus !== 'undefined' && plus.os.name === 'iOS') { + if ( + constructorParams.find( + (p) => p.type === 'UTSCallback' || p.type.indexOf('JSONObject') > 0 + ) + ) { + constructorParams.push({ name: '_byJs', type: 'boolean' }) + } + } const ProxyClass = class UTSClass { constructor(...params: unknown[]) { if (errMsg) { @@ -313,6 +345,7 @@ export function initUTSProxyClass({ get(_, name) { if (!target[name as string]) { //实例方法 + name = parseClassMethodName(name as string, methods) if (hasOwn(methods, name)) { const { async, params } = methods[name] target[name] = initUTSInstanceMethod( @@ -345,6 +378,7 @@ export function initUTSProxyClass({ const staticMethodCache: Record = {} return new Proxy(ProxyClass, { get(target, name, receiver) { + name = parseClassMethodName(name as string, staticMethods) if (hasOwn(staticMethods, name)) { if (!staticMethodCache[name as string]) { const { async, params } = staticMethods[name] diff --git a/packages/uts-darwin-arm64/uts.darwin-arm64.node b/packages/uts-darwin-arm64/uts.darwin-arm64.node index 39c039420b847980935e6d06f55c052b7ab1c05a..4e2cf61130628a83acdbe3454a703f22c939e316 100755 Binary files a/packages/uts-darwin-arm64/uts.darwin-arm64.node and b/packages/uts-darwin-arm64/uts.darwin-arm64.node differ diff --git a/packages/uts-darwin-x64/uts.darwin-x64.node b/packages/uts-darwin-x64/uts.darwin-x64.node index a9f6d6f21e67b820eae87c226db3b51b7161a029..059b6919509ca879372625ee1562faa5d48a6754 100755 Binary files a/packages/uts-darwin-x64/uts.darwin-x64.node and b/packages/uts-darwin-x64/uts.darwin-x64.node differ diff --git a/packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node b/packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node index 886fb55f6c73f6a0b3b4b0a208a6ba2af1f83e1d..14f1a38fed042e09c92dd3c868bdf0d891bc6c2a 100755 Binary files a/packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node and b/packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node differ diff --git a/packages/uts-linux-x64-musl/uts.linux-x64-musl.node b/packages/uts-linux-x64-musl/uts.linux-x64-musl.node index 02df4a8dac054d2b3d92113912a5b060cee77d5a..d3ce85e0d6b2716f2c27776cdc2c5b57203a15da 100755 Binary files a/packages/uts-linux-x64-musl/uts.linux-x64-musl.node and b/packages/uts-linux-x64-musl/uts.linux-x64-musl.node differ diff --git a/packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node b/packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node index e7bcbde117121c11b83491d4f30e153c3137cb2b..9b15c1a75e6c229b1794633b87336d48dcbaf2a9 100644 Binary files a/packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node and b/packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node differ diff --git a/packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node b/packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node index 3100d382d09fe6d3ac39408edc42e2b8b3b880c4..0815538895cece0f86c105da5effd6245ab6fe89 100755 Binary files a/packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node and b/packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node differ