winusb-driver-generator 1.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,17 @@
1
+ - commits:
2
+ - subject: "patch: fix linting long lines"
3
+ hash: 1c449945e94871e64d477284c2ec0d3f0cc8adf1
4
+ body: ""
5
+ footer: {}
6
+ author: mcraa
7
+ - subject: "major: migrate to NAPI"
8
+ hash: de012670ef0b6abe303cb345774cab9d6412962e
9
+ body: ""
10
+ footer: {}
11
+ author: mcraa
12
+ version: 2.0.0
13
+ title: ""
14
+ date: 2023-02-13T14:55:46.389Z
1
15
  - commits:
2
16
  - subject: Add support for Node 18
3
17
  hash: f366578887174f2dea005735f92f16ff5cd2f5f8
@@ -8,7 +22,7 @@
8
22
  author: Akis Kesoglou
9
23
  version: 1.5.0
10
24
  title: ""
11
- date: 2023-01-20T10:00:09.261Z
25
+ date: 2023-01-20T10:11:05.406Z
12
26
  - commits:
13
27
  - subject: "chore(deps): update deps/libwdi digest to 6722681"
14
28
  hash: cf7f1a17a93adff95ebed2809f9bfd5c71cdc9e0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## 1.2.3 - 2019-01-11
7
7
 
8
+ # v2.0.0
9
+ ## (2023-02-13)
10
+
11
+ * patch: fix linting long lines [mcraa]
12
+ * major: migrate to NAPI [mcraa]
13
+
8
14
  # v1.5.0
9
15
  ## (2023-01-20)
10
16
 
package/binding.gyp CHANGED
@@ -193,9 +193,13 @@
193
193
  {
194
194
  "target_name": "Generator",
195
195
  "include_dirs" : [
196
- "<!(node -e \"require('nan')\")",
196
+ "<!@(node -p \"require('node-addon-api').include\")",
197
197
  "."
198
198
  ],
199
+ 'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
200
+ "defines": [
201
+ "NAPI_VERSION=<(napi_build_version)"
202
+ ],
199
203
  "conditions": [
200
204
  [ "OS=='win'", {
201
205
  "dependencies" : [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "winusb-driver-generator",
3
- "version": "1.5.0",
3
+ "version": "2.0.0",
4
4
  "main": "index.js",
5
5
  "description": "Associate a USB vendor/product ID pair with WinUSB",
6
6
  "homepage": "https://github.com/resin-io-modules/winusb-driver-generator",
@@ -19,14 +19,14 @@
19
19
  "configure": "node-gyp configure",
20
20
  "build-windows": "node-gyp rebuild",
21
21
  "build": "echo npm run build-windows",
22
- "rebuild": "prebuild-install || node-gyp rebuild",
22
+ "rebuild": "prebuild-install --runtime napi || node-gyp rebuild",
23
23
  "lint-js": "eslint *.js",
24
24
  "lint-cpp": "cpplint --recursive src",
25
25
  "lint": "npm run lint-js && npm run lint-cpp",
26
26
  "test-windows": "npm run lint",
27
27
  "test": "echo npm run test-windows",
28
- "install": "prebuild-install || node-gyp rebuild",
29
- "prebuilds": "prebuild"
28
+ "install": "prebuild-install --runtime napi || node-gyp rebuild",
29
+ "prebuilds": "prebuild --runtime napi"
30
30
  },
31
31
  "author": "Juan Cruz Viotti <juan@resin.io>",
32
32
  "license": "Apache-2.0",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "bindings": "^1.5.0",
44
- "nan": "^2.17.0",
44
+ "node-addon-api": "^5.0.0",
45
45
  "prebuild-install": "^7.1.1"
46
46
  },
47
47
  "gypfile": true,
@@ -52,6 +52,6 @@
52
52
  "node": ">=16 < 19"
53
53
  },
54
54
  "versionist": {
55
- "publishedAt": "2023-01-20T10:00:09.411Z"
55
+ "publishedAt": "2023-02-13T14:55:46.578Z"
56
56
  }
57
57
  }
package/src/generator.cpp CHANGED
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  #include "src/generator.h"
18
+ #include <napi.h>
18
19
 
19
20
  static int
20
21
  generator_list_driverless_devices(struct wdi_device_info **result) {
@@ -46,10 +47,11 @@ generator_install_winusb_inf(struct wdi_device_info *device,
46
47
  return wdi_install_driver(device, path, name, NULL);
47
48
  }
48
49
 
49
- NAN_METHOD(listDriverlessDevices) {
50
+ Napi::Value ListDriverlessDevices(const Napi::CallbackInfo& info) {
50
51
  int code = WDI_SUCCESS;
51
52
  struct wdi_device_info *device_list_node;
52
- v8::Local<v8::Object> devices = Nan::New<v8::Array>();
53
+ Napi::Env env = info.Env();
54
+ Napi::Object devices = Napi::Array::New(env);
53
55
  wdi_set_log_level(WDI_LOG_LEVEL_WARNING);
54
56
 
55
57
  code = generator_list_driverless_devices(&device_list_node);
@@ -57,22 +59,24 @@ NAN_METHOD(listDriverlessDevices) {
57
59
  uint32_t index = 0;
58
60
  for (; device_list_node != NULL
59
61
  ; device_list_node = device_list_node->next) {
60
- v8::Local<v8::Object> device = Nan::New<v8::Object>();
61
- Nan::Set(device, Nan::New<v8::String>("vid").ToLocalChecked(),
62
- Nan::New<v8::Number>(static_cast<double>(device_list_node->vid)));
63
- Nan::Set(device, Nan::New<v8::String>("pid").ToLocalChecked(),
64
- Nan::New<v8::Number>(static_cast<double>(device_list_node->pid)));
65
- Nan::Set(device, Nan::New<v8::String>("hid").ToLocalChecked(),
66
- Nan::New<v8::String>(device_list_node->hardware_id).ToLocalChecked());
67
- Nan::Set(device, Nan::New<v8::String>("did").ToLocalChecked(),
68
- Nan::New<v8::String>(device_list_node->device_id).ToLocalChecked());
69
- Nan::Set(devices, index, device);
62
+ Napi::Object device = Napi::Object::New(env);
63
+ device.Set(Napi::String::New(env, "vid"),
64
+ Napi::Number::New(env, static_cast<double>(device_list_node->vid)));
65
+ device.Set(Napi::String::New(env, "pid"),
66
+ Napi::Number::New(env, static_cast<double>(device_list_node->pid)));
67
+ device.Set(Napi::String::New(env, "hid"),
68
+ Napi::String::New(env, device_list_node->hardware_id));
69
+ device.Set(Napi::String::New(env, "did"),
70
+ Napi::String::New(env, device_list_node->device_id));
71
+ device.Set(index, device);
70
72
  index++;
71
73
  }
72
74
 
73
75
  code = wdi_destroy_list(device_list_node);
74
76
  if (code != WDI_SUCCESS) {
75
- return Nan::ThrowError(wdi_strerror(code));
77
+ Napi::TypeError::New(env, wdi_strerror(code))
78
+ .ThrowAsJavaScriptException();
79
+ return env.Null();
76
80
  }
77
81
 
78
82
  // This means the returned list is empty.
@@ -81,37 +85,45 @@ NAN_METHOD(listDriverlessDevices) {
81
85
  // If the list of driverless devices is empty, then we
82
86
  // can assume every device has a driver.
83
87
  } else if (code != WDI_ERROR_NO_DEVICE) {
84
- return Nan::ThrowError(wdi_strerror(code));
88
+ Napi::TypeError::New(env, wdi_strerror(code))
89
+ .ThrowAsJavaScriptException();
90
+ return env.Null();
85
91
  }
86
92
 
87
- info.GetReturnValue().Set(devices);
93
+ return devices;
88
94
  }
89
95
 
90
- NAN_METHOD(associate) {
96
+ Napi::Value Associate(const Napi::CallbackInfo& info) {
97
+ Napi::Env env = info.Env();
98
+
91
99
  if (info.Length() != 3) {
92
- return Nan::ThrowError("This function expects 3 arguments");
100
+ Napi::TypeError::New(env, "This function expects 3 arguments")
101
+ .ThrowAsJavaScriptException();
102
+ return env.Null();
93
103
  }
94
104
 
95
- if (!info[0]->IsNumber()) {
96
- return Nan::ThrowError("Product id must be a number");
105
+ if (!info[0].IsNumber()) {
106
+ Napi::TypeError::New(env, "Product id must be a number")
107
+ .ThrowAsJavaScriptException();
108
+ return env.Null();
97
109
  }
98
110
 
99
- if (!info[1]->IsNumber()) {
100
- return Nan::ThrowError("Vendor id must be a number");
111
+ if (!info[1].IsNumber()) {
112
+ Napi::TypeError::New(env, "Vendor id must be a number")
113
+ .ThrowAsJavaScriptException();
114
+ return env.Null();
101
115
  }
102
116
 
103
- if (!info[2]->IsString()) {
104
- return Nan::ThrowError("Description must be a string");
117
+ if (!info[2].IsString()) {
118
+ Napi::TypeError::New(env, "Description must be a string")
119
+ .ThrowAsJavaScriptException();
120
+ return env.Null();
105
121
  }
106
122
 
107
- auto context = v8::Isolate::GetCurrent()->GetCurrentContext();
108
-
109
- const uint16_t vendor = info[0]->Uint32Value(context).ToChecked();
110
- const uint16_t product = info[1]->Uint32Value(context).ToChecked();
123
+ const uint32_t vendor = info[0].As<Napi::Number>().Uint32Value();
124
+ const uint32_t product = info[1].As<Napi::Number>().Uint32Value();
111
125
 
112
- // TODO(jviotti): Is there a better way to go from v8::String to char *?
113
- Nan::Utf8String description_v8(info[2]->ToString(context).ToLocalChecked());
114
- std::string description_string = std::string(*description_v8);
126
+ std::string description_string = info[2].As<Napi::String>().Utf8Value();
115
127
  char *description = new char[description_string.length() + 1];
116
128
  // cpplint suggests snprintf over strcpy, but the former
117
129
  // is not implemented in Visual Studio 2013.
@@ -140,7 +152,9 @@ NAN_METHOD(associate) {
140
152
  std::cout << "Extracting driver files" << std::endl;
141
153
  code = generator_generate_winusb_inf(&device, INF_NAME, INF_PATH);
142
154
  if (code != WDI_SUCCESS) {
143
- return Nan::ThrowError(wdi_strerror(code));
155
+ Napi::TypeError::New(env, wdi_strerror(code))
156
+ .ThrowAsJavaScriptException();
157
+ return env.Null();
144
158
  }
145
159
 
146
160
  std::cout << "Installing driver" << std::endl;
@@ -158,28 +172,39 @@ NAN_METHOD(associate) {
158
172
  } else if (code == WDI_ERROR_NO_DEVICE) {
159
173
  matching_device_found = false;
160
174
  } else {
161
- return Nan::ThrowError(wdi_strerror(code));
175
+ Napi::TypeError::New(env, wdi_strerror(code))
176
+ .ThrowAsJavaScriptException();
177
+ return env.Null();
162
178
  }
163
179
 
164
180
  code = generator_install_winusb_inf(&device, INF_NAME, INF_PATH);
165
181
  if (code != WDI_SUCCESS) {
166
- return Nan::ThrowError(wdi_strerror(code));
182
+ Napi::TypeError::New(env, wdi_strerror(code))
183
+ .ThrowAsJavaScriptException();
184
+ return env.Null();
167
185
  }
168
186
 
169
187
  if (matching_device_found) {
170
188
  code = wdi_destroy_list(device_list_node);
171
189
  if (code != WDI_SUCCESS) {
172
- return Nan::ThrowError(wdi_strerror(code));
190
+ Napi::TypeError::New(env, wdi_strerror(code))
191
+ .ThrowAsJavaScriptException();
192
+ return env.Null();
173
193
  }
174
194
  }
175
195
 
176
196
  delete [] description;
177
- info.GetReturnValue().SetUndefined();
197
+ return env.Undefined();
178
198
  }
179
199
 
180
- NAN_MODULE_INIT(GeneratorInit) {
181
- NAN_EXPORT(target, listDriverlessDevices);
182
- NAN_EXPORT(target, associate);
200
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
201
+ exports.Set(
202
+ Napi::String::New(env, "listDriverlessDevices"),
203
+ Napi::Function::New(env, ListDriverlessDevices));
204
+ exports.Set(
205
+ Napi::String::New(env, "associate"),
206
+ Napi::Function::New(env, Associate));
207
+ return exports;
183
208
  }
184
209
 
185
- NODE_MODULE(Generator, GeneratorInit)
210
+ NODE_API_MODULE(Generator, Init)
package/src/generator.h CHANGED
@@ -18,7 +18,7 @@
18
18
  */
19
19
 
20
20
  #include <stdio.h>
21
- #include <nan.h>
21
+ #include <napi.h>
22
22
  #include <libwdi.h>
23
23
  #include <string>
24
24
  #include <iostream>
@@ -32,7 +32,7 @@
32
32
  #pragma warning(disable:28159)
33
33
  #endif
34
34
 
35
- NAN_METHOD(hasDriver);
36
- NAN_METHOD(associate);
35
+ Napi::Value listDriverlessDevices(const Napi::CallbackInfo& info);
36
+ Napi::Value associate(const Napi::CallbackInfo& info);
37
37
 
38
38
  #endif // SRC_GENERATOR_H_