node-addon-api 4.1.0 → 5.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.
package/napi.h CHANGED
@@ -140,6 +140,18 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16
140
140
  ////////////////////////////////////////////////////////////////////////////////
141
141
  namespace Napi {
142
142
 
143
+ #ifdef NAPI_CPP_CUSTOM_NAMESPACE
144
+ // NAPI_CPP_CUSTOM_NAMESPACE can be #define'd per-addon to avoid symbol
145
+ // conflicts between different instances of node-addon-api
146
+
147
+ // First dummy definition of the namespace to make sure that Napi::(name) still
148
+ // refers to the right things inside this file.
149
+ namespace NAPI_CPP_CUSTOM_NAMESPACE {}
150
+ using namespace NAPI_CPP_CUSTOM_NAMESPACE;
151
+
152
+ namespace NAPI_CPP_CUSTOM_NAMESPACE {
153
+ #endif
154
+
143
155
  // Forward declarations
144
156
  class Env;
145
157
  class Value;
@@ -286,11 +298,11 @@ namespace Napi {
286
298
  Value Null() const;
287
299
 
288
300
  bool IsExceptionPending() const;
289
- Error GetAndClearPendingException();
301
+ Error GetAndClearPendingException() const;
290
302
 
291
- MaybeOrValue<Value> RunScript(const char* utf8script);
292
- MaybeOrValue<Value> RunScript(const std::string& utf8script);
293
- MaybeOrValue<Value> RunScript(String script);
303
+ MaybeOrValue<Value> RunScript(const char* utf8script) const;
304
+ MaybeOrValue<Value> RunScript(const std::string& utf8script) const;
305
+ MaybeOrValue<Value> RunScript(String script) const;
294
306
 
295
307
  #if NAPI_VERSION > 2
296
308
  template <typename Hook>
@@ -301,19 +313,20 @@ namespace Napi {
301
313
  #endif // NAPI_VERSION > 2
302
314
 
303
315
  #if NAPI_VERSION > 5
304
- template <typename T> T* GetInstanceData();
316
+ template <typename T>
317
+ T* GetInstanceData() const;
305
318
 
306
319
  template <typename T> using Finalizer = void (*)(Env, T*);
307
320
  template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
308
- void SetInstanceData(T* data);
321
+ void SetInstanceData(T* data) const;
309
322
 
310
323
  template <typename DataType, typename HintType>
311
324
  using FinalizerWithHint = void (*)(Env, DataType*, HintType*);
312
325
  template <typename DataType,
313
326
  typename HintType,
314
327
  FinalizerWithHint<DataType, HintType> fini =
315
- Env::DefaultFiniWithHint<DataType, HintType>>
316
- void SetInstanceData(DataType* data, HintType* hint);
328
+ Env::DefaultFiniWithHint<DataType, HintType>>
329
+ void SetInstanceData(DataType* data, HintType* hint) const;
317
330
  #endif // NAPI_VERSION > 5
318
331
 
319
332
  private:
@@ -727,20 +740,24 @@ namespace Napi {
727
740
  napi_value value); ///< Wraps a Node-API value primitive.
728
741
 
729
742
  /// Gets or sets a named property.
730
- PropertyLValue<std::string> operator [](
731
- const char* utf8name ///< UTF-8 encoded null-terminated property name
743
+ PropertyLValue<std::string> operator[](
744
+ const char* utf8name ///< UTF-8 encoded null-terminated property name
732
745
  );
733
746
 
734
747
  /// Gets or sets a named property.
735
- PropertyLValue<std::string> operator [](
736
- const std::string& utf8name ///< UTF-8 encoded property name
748
+ PropertyLValue<std::string> operator[](
749
+ const std::string& utf8name ///< UTF-8 encoded property name
737
750
  );
738
751
 
739
752
  /// Gets or sets an indexed property or array element.
740
- PropertyLValue<uint32_t> operator [](
741
- uint32_t index /// Property / element index
753
+ PropertyLValue<uint32_t> operator[](
754
+ uint32_t index /// Property / element index
742
755
  );
743
756
 
757
+ /// Gets or sets an indexed property or array element.
758
+ PropertyLValue<Value> operator[](Value index /// Property / element index
759
+ ) const;
760
+
744
761
  /// Gets a named property.
745
762
  MaybeOrValue<Value> operator[](
746
763
  const char* utf8name ///< UTF-8 encoded null-terminated property name
@@ -814,44 +831,44 @@ namespace Napi {
814
831
  template <typename ValueType>
815
832
  MaybeOrValue<bool> Set(napi_value key, ///< Property key primitive
816
833
  const ValueType& value ///< Property value primitive
817
- );
834
+ ) const;
818
835
 
819
836
  /// Sets a property.
820
837
  template <typename ValueType>
821
838
  MaybeOrValue<bool> Set(Value key, ///< Property key
822
839
  const ValueType& value ///< Property value
823
- );
840
+ ) const;
824
841
 
825
842
  /// Sets a named property.
826
843
  template <typename ValueType>
827
844
  MaybeOrValue<bool> Set(
828
845
  const char* utf8name, ///< UTF-8 encoded null-terminated property name
829
- const ValueType& value);
846
+ const ValueType& value) const;
830
847
 
831
848
  /// Sets a named property.
832
849
  template <typename ValueType>
833
850
  MaybeOrValue<bool> Set(
834
851
  const std::string& utf8name, ///< UTF-8 encoded property name
835
852
  const ValueType& value ///< Property value primitive
836
- );
853
+ ) const;
837
854
 
838
855
  /// Delete property.
839
856
  MaybeOrValue<bool> Delete(napi_value key ///< Property key primitive
840
- );
857
+ ) const;
841
858
 
842
859
  /// Delete property.
843
860
  MaybeOrValue<bool> Delete(Value key ///< Property key
844
- );
861
+ ) const;
845
862
 
846
863
  /// Delete property.
847
864
  MaybeOrValue<bool> Delete(
848
865
  const char* utf8name ///< UTF-8 encoded null-terminated property name
849
- );
866
+ ) const;
850
867
 
851
868
  /// Delete property.
852
869
  MaybeOrValue<bool> Delete(
853
870
  const std::string& utf8name ///< UTF-8 encoded property name
854
- );
871
+ ) const;
855
872
 
856
873
  /// Checks whether an indexed property is present.
857
874
  MaybeOrValue<bool> Has(uint32_t index ///< Property / element index
@@ -865,11 +882,11 @@ namespace Napi {
865
882
  template <typename ValueType>
866
883
  MaybeOrValue<bool> Set(uint32_t index, ///< Property / element index
867
884
  const ValueType& value ///< Property value primitive
868
- );
885
+ ) const;
869
886
 
870
887
  /// Deletes an indexed property or array element.
871
888
  MaybeOrValue<bool> Delete(uint32_t index ///< Property / element index
872
- );
889
+ ) const;
873
890
 
874
891
  /// This operation can fail in case of Proxy.[[OwnPropertyKeys]] and
875
892
  /// Proxy.[[GetOwnProperty]] calling into JavaScript. See:
@@ -887,7 +904,7 @@ namespace Napi {
887
904
  MaybeOrValue<bool> DefineProperty(
888
905
  const PropertyDescriptor&
889
906
  property ///< Descriptor for the property to be defined
890
- );
907
+ ) const;
891
908
 
892
909
  /// Defines properties on the object.
893
910
  ///
@@ -897,7 +914,7 @@ namespace Napi {
897
914
  MaybeOrValue<bool> DefineProperties(
898
915
  const std::initializer_list<PropertyDescriptor>& properties
899
916
  ///< List of descriptors for the properties to be defined
900
- );
917
+ ) const;
901
918
 
902
919
  /// Defines properties on the object.
903
920
  ///
@@ -907,7 +924,7 @@ namespace Napi {
907
924
  MaybeOrValue<bool> DefineProperties(
908
925
  const std::vector<PropertyDescriptor>& properties
909
926
  ///< Vector of descriptors for the properties to be defined
910
- );
927
+ ) const;
911
928
 
912
929
  /// Checks if an object is an instance created by a constructor function.
913
930
  ///
@@ -922,23 +939,38 @@ namespace Napi {
922
939
  ) const;
923
940
 
924
941
  template <typename Finalizer, typename T>
925
- inline void AddFinalizer(Finalizer finalizeCallback, T* data);
942
+ inline void AddFinalizer(Finalizer finalizeCallback, T* data) const;
926
943
 
927
944
  template <typename Finalizer, typename T, typename Hint>
928
945
  inline void AddFinalizer(Finalizer finalizeCallback,
929
946
  T* data,
930
- Hint* finalizeHint);
947
+ Hint* finalizeHint) const;
948
+
949
+ #ifdef NAPI_CPP_EXCEPTIONS
950
+ class const_iterator;
951
+
952
+ inline const_iterator begin() const;
953
+
954
+ inline const_iterator end() const;
955
+
956
+ class iterator;
957
+
958
+ inline iterator begin();
959
+
960
+ inline iterator end();
961
+ #endif // NAPI_CPP_EXCEPTIONS
962
+
931
963
  #if NAPI_VERSION >= 8
932
964
  /// This operation can fail in case of Proxy.[[GetPrototypeOf]] calling into
933
965
  /// JavaScript.
934
966
  /// See
935
967
  /// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
936
- MaybeOrValue<bool> Freeze();
968
+ MaybeOrValue<bool> Freeze() const;
937
969
  /// This operation can fail in case of Proxy.[[GetPrototypeOf]] calling into
938
970
  /// JavaScript.
939
971
  /// See
940
972
  /// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof
941
- MaybeOrValue<bool> Seal();
973
+ MaybeOrValue<bool> Seal() const;
942
974
  #endif // NAPI_VERSION >= 8
943
975
  };
944
976
 
@@ -976,6 +1008,55 @@ namespace Napi {
976
1008
  uint32_t Length() const;
977
1009
  };
978
1010
 
1011
+ #ifdef NAPI_CPP_EXCEPTIONS
1012
+ class Object::const_iterator {
1013
+ private:
1014
+ enum class Type { BEGIN, END };
1015
+
1016
+ inline const_iterator(const Object* object, const Type type);
1017
+
1018
+ public:
1019
+ inline const_iterator& operator++();
1020
+
1021
+ inline bool operator==(const const_iterator& other) const;
1022
+
1023
+ inline bool operator!=(const const_iterator& other) const;
1024
+
1025
+ inline const std::pair<Value, Object::PropertyLValue<Value>> operator*()
1026
+ const;
1027
+
1028
+ private:
1029
+ const Napi::Object* _object;
1030
+ Array _keys;
1031
+ uint32_t _index;
1032
+
1033
+ friend class Object;
1034
+ };
1035
+
1036
+ class Object::iterator {
1037
+ private:
1038
+ enum class Type { BEGIN, END };
1039
+
1040
+ inline iterator(Object* object, const Type type);
1041
+
1042
+ public:
1043
+ inline iterator& operator++();
1044
+
1045
+ inline bool operator==(const iterator& other) const;
1046
+
1047
+ inline bool operator!=(const iterator& other) const;
1048
+
1049
+ inline std::pair<Value, Object::PropertyLValue<Value>> operator*();
1050
+
1051
+ private:
1052
+ Napi::Object* _object;
1053
+ Array _keys;
1054
+ uint32_t _index;
1055
+
1056
+ friend class Object;
1057
+ };
1058
+ #endif // NAPI_CPP_EXCEPTIONS
1059
+
979
1060
  /// A JavaScript array buffer value.
980
1061
  class ArrayBuffer : public Object {
981
1062
  public:
@@ -1278,11 +1359,14 @@ namespace Napi {
1278
1359
  MaybeOrValue<Value> Call(
1279
1360
  const std::initializer_list<napi_value>& args) const;
1280
1361
  MaybeOrValue<Value> Call(const std::vector<napi_value>& args) const;
1362
+ MaybeOrValue<Value> Call(const std::vector<Value>& args) const;
1281
1363
  MaybeOrValue<Value> Call(size_t argc, const napi_value* args) const;
1282
1364
  MaybeOrValue<Value> Call(
1283
1365
  napi_value recv, const std::initializer_list<napi_value>& args) const;
1284
1366
  MaybeOrValue<Value> Call(napi_value recv,
1285
1367
  const std::vector<napi_value>& args) const;
1368
+ MaybeOrValue<Value> Call(napi_value recv,
1369
+ const std::vector<Value>& args) const;
1286
1370
  MaybeOrValue<Value> Call(napi_value recv,
1287
1371
  size_t argc,
1288
1372
  const napi_value* args) const;
@@ -1390,8 +1474,8 @@ namespace Napi {
1390
1474
  // within a HandleScope so that the value handle gets cleaned up efficiently.
1391
1475
  T Value() const;
1392
1476
 
1393
- uint32_t Ref();
1394
- uint32_t Unref();
1477
+ uint32_t Ref() const;
1478
+ uint32_t Unref() const;
1395
1479
  void Reset();
1396
1480
  void Reset(const T& value, uint32_t refcount = 0);
1397
1481
 
@@ -1428,24 +1512,27 @@ namespace Napi {
1428
1512
 
1429
1513
  MaybeOrValue<Napi::Value> Get(const char* utf8name) const;
1430
1514
  MaybeOrValue<Napi::Value> Get(const std::string& utf8name) const;
1431
- MaybeOrValue<bool> Set(const char* utf8name, napi_value value);
1432
- MaybeOrValue<bool> Set(const char* utf8name, Napi::Value value);
1433
- MaybeOrValue<bool> Set(const char* utf8name, const char* utf8value);
1434
- MaybeOrValue<bool> Set(const char* utf8name, bool boolValue);
1435
- MaybeOrValue<bool> Set(const char* utf8name, double numberValue);
1436
- MaybeOrValue<bool> Set(const std::string& utf8name, napi_value value);
1437
- MaybeOrValue<bool> Set(const std::string& utf8name, Napi::Value value);
1438
- MaybeOrValue<bool> Set(const std::string& utf8name, std::string& utf8value);
1439
- MaybeOrValue<bool> Set(const std::string& utf8name, bool boolValue);
1440
- MaybeOrValue<bool> Set(const std::string& utf8name, double numberValue);
1515
+ MaybeOrValue<bool> Set(const char* utf8name, napi_value value) const;
1516
+ MaybeOrValue<bool> Set(const char* utf8name, Napi::Value value) const;
1517
+ MaybeOrValue<bool> Set(const char* utf8name, const char* utf8value) const;
1518
+ MaybeOrValue<bool> Set(const char* utf8name, bool boolValue) const;
1519
+ MaybeOrValue<bool> Set(const char* utf8name, double numberValue) const;
1520
+ MaybeOrValue<bool> Set(const std::string& utf8name, napi_value value) const;
1521
+ MaybeOrValue<bool> Set(const std::string& utf8name,
1522
+ Napi::Value value) const;
1523
+ MaybeOrValue<bool> Set(const std::string& utf8name,
1524
+ std::string& utf8value) const;
1525
+ MaybeOrValue<bool> Set(const std::string& utf8name, bool boolValue) const;
1526
+ MaybeOrValue<bool> Set(const std::string& utf8name,
1527
+ double numberValue) const;
1441
1528
 
1442
1529
  MaybeOrValue<Napi::Value> Get(uint32_t index) const;
1443
- MaybeOrValue<bool> Set(uint32_t index, const napi_value value);
1444
- MaybeOrValue<bool> Set(uint32_t index, const Napi::Value value);
1445
- MaybeOrValue<bool> Set(uint32_t index, const char* utf8value);
1446
- MaybeOrValue<bool> Set(uint32_t index, const std::string& utf8value);
1447
- MaybeOrValue<bool> Set(uint32_t index, bool boolValue);
1448
- MaybeOrValue<bool> Set(uint32_t index, double numberValue);
1530
+ MaybeOrValue<bool> Set(uint32_t index, const napi_value value) const;
1531
+ MaybeOrValue<bool> Set(uint32_t index, const Napi::Value value) const;
1532
+ MaybeOrValue<bool> Set(uint32_t index, const char* utf8value) const;
1533
+ MaybeOrValue<bool> Set(uint32_t index, const std::string& utf8value) const;
1534
+ MaybeOrValue<bool> Set(uint32_t index, bool boolValue) const;
1535
+ MaybeOrValue<bool> Set(uint32_t index, double numberValue) const;
1449
1536
 
1450
1537
  protected:
1451
1538
  ObjectReference(const ObjectReference&);
@@ -1627,6 +1714,8 @@ namespace Napi {
1627
1714
  const std::string& Message() const NAPI_NOEXCEPT;
1628
1715
  void ThrowAsJavaScriptException() const;
1629
1716
 
1717
+ Object Value() const;
1718
+
1630
1719
  #ifdef NAPI_CPP_EXCEPTIONS
1631
1720
  const char* what() const NAPI_NOEXCEPT override;
1632
1721
  #endif // NAPI_CPP_EXCEPTIONS
@@ -1646,7 +1735,8 @@ namespace Napi {
1646
1735
  /// !endcond
1647
1736
 
1648
1737
  private:
1649
- mutable std::string _message;
1738
+ static inline const char* ERROR_WRAP_VALUE() NAPI_NOEXCEPT;
1739
+ mutable std::string _message;
1650
1740
  };
1651
1741
 
1652
1742
  class TypeError : public Error {
@@ -2123,6 +2213,8 @@ namespace Napi {
2123
2213
  static PropertyDescriptor StaticValue(Symbol name,
2124
2214
  Napi::Value value,
2125
2215
  napi_property_attributes attributes = napi_default);
2216
+ static Napi::Value OnCalledAsFunction(
2217
+ const Napi::CallbackInfo& callbackInfo);
2126
2218
  virtual void Finalize(Napi::Env env);
2127
2219
 
2128
2220
  private:
@@ -2477,10 +2569,10 @@ namespace Napi {
2477
2569
  napi_status Acquire() const;
2478
2570
 
2479
2571
  // This API may be called from any thread.
2480
- napi_status Release();
2572
+ napi_status Release() const;
2481
2573
 
2482
2574
  // This API may be called from any thread.
2483
- napi_status Abort();
2575
+ napi_status Abort() const;
2484
2576
 
2485
2577
  struct ConvertibleContext
2486
2578
  {
@@ -2676,10 +2768,10 @@ namespace Napi {
2676
2768
  napi_status Acquire() const;
2677
2769
 
2678
2770
  // This API may be called from any thread.
2679
- napi_status Release();
2771
+ napi_status Release() const;
2680
2772
 
2681
2773
  // This API may be called from any thread.
2682
- napi_status Abort();
2774
+ napi_status Abort() const;
2683
2775
 
2684
2776
  // This API may be called from any thread.
2685
2777
  ContextType* GetContext() const;
@@ -2899,6 +2991,10 @@ namespace Napi {
2899
2991
  };
2900
2992
  #endif // NAPI_VERSION > 5
2901
2993
 
2994
+ #ifdef NAPI_CPP_CUSTOM_NAMESPACE
2995
+ } // namespace NAPI_CPP_CUSTOM_NAMESPACE
2996
+ #endif
2997
+
2902
2998
  } // namespace Napi
2903
2999
 
2904
3000
  // Inline implementations of all the above class methods are included here.
package/noexcept.gypi CHANGED
@@ -2,15 +2,25 @@
2
2
  'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
3
3
  'cflags': [ '-fno-exceptions' ],
4
4
  'cflags_cc': [ '-fno-exceptions' ],
5
- 'msvs_settings': {
6
- 'VCCLCompilerTool': {
7
- 'ExceptionHandling': 0,
8
- 'EnablePREfast': 'true',
9
- },
10
- },
11
- 'xcode_settings': {
12
- 'CLANG_CXX_LIBRARY': 'libc++',
13
- 'MACOSX_DEPLOYMENT_TARGET': '10.7',
14
- 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
15
- },
5
+ 'conditions': [
6
+ ["OS=='win'", {
7
+ # _HAS_EXCEPTIONS is already defined and set to 0 in common.gypi
8
+ #"defines": [
9
+ # "_HAS_EXCEPTIONS=0"
10
+ #],
11
+ "msvs_settings": {
12
+ "VCCLCompilerTool": {
13
+ 'ExceptionHandling': 0,
14
+ 'EnablePREfast': 'true',
15
+ },
16
+ },
17
+ }],
18
+ ["OS=='mac'", {
19
+ 'xcode_settings': {
20
+ 'CLANG_CXX_LIBRARY': 'libc++',
21
+ 'MACOSX_DEPLOYMENT_TARGET': '10.7',
22
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
23
+ },
24
+ }],
25
+ ],
16
26
  }
package/package.json CHANGED
@@ -11,6 +11,10 @@
11
11
  "name": "Alba Mendez",
12
12
  "url": "https://github.com/jmendeth"
13
13
  },
14
+ {
15
+ "name": "Alexander Floh",
16
+ "url": "https://github.com/alexanderfloh"
17
+ },
14
18
  {
15
19
  "name": "András Timár, Dr",
16
20
  "url": "https://github.com/timarandras"
@@ -75,6 +79,10 @@
75
79
  "name": "David Halls",
76
80
  "url": "https://github.com/davedoesdev"
77
81
  },
82
+ {
83
+ "name": "Deepak Rajamohan",
84
+ "url": "https://github.com/deepakrkris"
85
+ },
78
86
  {
79
87
  "name": "Dmitry Ashkadov",
80
88
  "url": "https://github.com/dmitryash"
@@ -84,13 +92,21 @@
84
92
  "url": "https://github.com/nadongguri"
85
93
  },
86
94
  {
87
- "name": "Ferdinand Holzer",
88
- "url": "https://github.com/fholzer"
95
+ "name": "Doni Rubiagatra",
96
+ "url": "https://github.com/rubiagatra"
89
97
  },
90
98
  {
91
99
  "name": "Eric Bickle",
92
100
  "url": "https://github.com/ebickle"
93
101
  },
102
+ {
103
+ "name": "extremeheat",
104
+ "url": "https://github.com/extremeheat"
105
+ },
106
+ {
107
+ "name": "Ferdinand Holzer",
108
+ "url": "https://github.com/fholzer"
109
+ },
94
110
  {
95
111
  "name": "Gabriel Schulhof",
96
112
  "url": "https://github.com/gabrielschulhof"
@@ -255,6 +271,10 @@
255
271
  "name": "Philipp Renoth",
256
272
  "url": "https://github.com/DaAitch"
257
273
  },
274
+ {
275
+ "name": "rgerd",
276
+ "url": "https://github.com/rgerd"
277
+ },
258
278
  {
259
279
  "name": "Rolf Timmermans",
260
280
  "url": "https://github.com/rolftimmermans"
@@ -275,6 +295,10 @@
275
295
  "name": "Sam Roberts",
276
296
  "url": "https://github.com/sam-github"
277
297
  },
298
+ {
299
+ "name": "strager",
300
+ "url": "https://github.com/strager"
301
+ },
278
302
  {
279
303
  "name": "Taylor Woll",
280
304
  "url": "https://github.com/boingoing"
@@ -291,6 +315,10 @@
291
315
  "name": "Tobias Nießen",
292
316
  "url": "https://github.com/tniessen"
293
317
  },
318
+ {
319
+ "name": "todoroff",
320
+ "url": "https://github.com/todoroff"
321
+ },
294
322
  {
295
323
  "name": "Tux3",
296
324
  "url": "https://github.com/tux3"
@@ -299,6 +327,19 @@
299
327
  "name": "Vlad Velmisov",
300
328
  "url": "https://github.com/Velmisov"
301
329
  },
330
+ {
331
+ "name": "Vladimir Morozov",
332
+ "url": "https://github.com/vmoroz"
333
+
334
+ },
335
+ {
336
+ "name": "WenheLI",
337
+ "url": "https://github.com/WenheLI"
338
+ },
339
+ {
340
+ "name": "Xuguang Mei",
341
+ "url": "https://github.com/meixg"
342
+ },
302
343
  {
303
344
  "name": "Yohei Kishimoto",
304
345
  "url": "https://github.com/morokosi"
@@ -317,7 +358,14 @@
317
358
  "benchmark": "^2.1.4",
318
359
  "bindings": "^1.5.0",
319
360
  "clang-format": "^1.4.0",
361
+ "eslint": "^7.32.0",
362
+ "eslint-config-semistandard": "^16.0.0",
363
+ "eslint-config-standard": "^16.0.3",
364
+ "eslint-plugin-import": "^2.24.2",
365
+ "eslint-plugin-node": "^11.1.0",
366
+ "eslint-plugin-promise": "^5.1.0",
320
367
  "fs-extra": "^9.0.1",
368
+ "path": "^0.12.7",
321
369
  "pre-commit": "^1.2.2",
322
370
  "safe-buffer": "^5.1.1"
323
371
  },
@@ -338,7 +386,6 @@
338
386
  "license": "MIT",
339
387
  "main": "index.js",
340
388
  "name": "node-addon-api",
341
- "optionalDependencies": {},
342
389
  "readme": "README.md",
343
390
  "repository": {
344
391
  "type": "git",
@@ -359,10 +406,10 @@
359
406
  "predev:incremental": "node-gyp configure build -C test --debug",
360
407
  "dev:incremental": "node test",
361
408
  "doc": "doxygen doc/Doxyfile",
362
- "lint": "node tools/clang-format",
363
- "lint:fix": "node tools/clang-format --fix"
409
+ "lint": "node tools/eslint-format && node tools/clang-format",
410
+ "lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix"
364
411
  },
365
412
  "pre-commit": "lint",
366
- "version": "4.1.0",
413
+ "version": "5.0.0",
367
414
  "support": true
368
415
  }
@@ -4,36 +4,38 @@ const spawn = require('child_process').spawnSync;
4
4
  const path = require('path');
5
5
 
6
6
  const filesToCheck = ['*.h', '*.cc'];
7
- const CLANG_FORMAT_START = process.env.CLANG_FORMAT_START || 'main';
7
+ const FORMAT_START = process.env.FORMAT_START || 'main';
8
8
 
9
- function main(args) {
9
+ function main (args) {
10
10
  let fix = false;
11
11
  while (args.length > 0) {
12
12
  switch (args[0]) {
13
13
  case '-f':
14
14
  case '--fix':
15
15
  fix = true;
16
+ break;
16
17
  default:
17
18
  }
18
19
  args.shift();
19
20
  }
20
21
 
21
- let clangFormatPath = path.dirname(require.resolve('clang-format'));
22
- const options = ['--binary=node_modules/.bin/clang-format', '--style=file'];
22
+ const clangFormatPath = path.dirname(require.resolve('clang-format'));
23
+ const binary = process.platform === 'win32'
24
+ ? 'node_modules\\.bin\\clang-format.cmd'
25
+ : 'node_modules/.bin/clang-format';
26
+ const options = ['--binary=' + binary, '--style=file'];
23
27
  if (fix) {
24
- options.push(CLANG_FORMAT_START);
28
+ options.push(FORMAT_START);
25
29
  } else {
26
- options.push('--diff', CLANG_FORMAT_START);
30
+ options.push('--diff', FORMAT_START);
27
31
  }
28
32
 
29
- const gitClangFormatPath = path.join(clangFormatPath,
30
- 'bin/git-clang-format');
31
- const result = spawn('python', [
32
- gitClangFormatPath,
33
- ...options,
34
- '--',
35
- ...filesToCheck
36
- ], { encoding: 'utf-8' });
33
+ const gitClangFormatPath = path.join(clangFormatPath, 'bin/git-clang-format');
34
+ const result = spawn(
35
+ 'python',
36
+ [gitClangFormatPath, ...options, '--', ...filesToCheck],
37
+ { encoding: 'utf-8' }
38
+ );
37
39
 
38
40
  if (result.stderr) {
39
41
  console.error('Error running git-clang-format:', result.stderr);
@@ -47,9 +49,11 @@ function main(args) {
47
49
  return 0;
48
50
  }
49
51
  // Detect if there is any complains from clang-format
50
- if (clangFormatOutput !== '' &&
51
- clangFormatOutput !== ('no modified files to format') &&
52
- clangFormatOutput !== ('clang-format did not modify any files')) {
52
+ if (
53
+ clangFormatOutput !== '' &&
54
+ clangFormatOutput !== 'no modified files to format' &&
55
+ clangFormatOutput !== 'clang-format did not modify any files'
56
+ ) {
53
57
  console.error(clangFormatOutput);
54
58
  const fixCmd = 'npm run lint:fix';
55
59
  console.error(`
@@ -57,7 +61,7 @@ function main(args) {
57
61
  Note that when running the command locally, please keep your local
58
62
  main branch and working branch up to date with nodejs/node-addon-api
59
63
  to exclude un-related complains.
60
- Or you can run "env CLANG_FORMAT_START=upstream/main ${fixCmd}".`);
64
+ Or you can run "env FORMAT_START=upstream/main ${fixCmd}".`);
61
65
  return 1;
62
66
  }
63
67
  }