@yalehwang/archguard 0.1.31 → 0.1.32

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.
Files changed (298) hide show
  1. package/README.md +106 -19
  2. package/assets/grammars/benchmarks.md +101 -0
  3. package/assets/grammars/checksums.json +8 -0
  4. package/{node_modules/tree-sitter/LICENSE → assets/grammars/licenses/tree-sitter-cpp.LICENSE} +2 -2
  5. package/{node_modules/node-gyp-build/LICENSE → assets/grammars/licenses/tree-sitter-go.LICENSE} +5 -5
  6. package/assets/grammars/licenses/tree-sitter-java.LICENSE +21 -0
  7. package/assets/grammars/licenses/tree-sitter-kotlin.LICENSE +21 -0
  8. package/assets/grammars/licenses/tree-sitter-python.LICENSE +21 -0
  9. package/assets/grammars/licenses/tree-sitter.LICENSE +21 -0
  10. package/assets/grammars/provenance.json +66 -0
  11. package/assets/grammars/tree-sitter-cpp.wasm +0 -0
  12. package/assets/grammars/tree-sitter-go.wasm +0 -0
  13. package/assets/grammars/tree-sitter-java.wasm +0 -0
  14. package/assets/grammars/tree-sitter-kotlin.wasm +0 -0
  15. package/assets/grammars/tree-sitter-python.wasm +0 -0
  16. package/assets/grammars/tree-sitter.wasm +0 -0
  17. package/dist/analysis/fitness/rule-types.d.ts +1 -33
  18. package/dist/analysis/fitness/rule-types.d.ts.map +1 -1
  19. package/dist/cli/analyze/run-analysis.d.ts +4 -0
  20. package/dist/cli/analyze/run-analysis.d.ts.map +1 -1
  21. package/dist/cli/analyze/run-analysis.js +63 -43
  22. package/dist/cli/analyze/run-analysis.js.map +1 -1
  23. package/dist/cli/cache/cache-manager.js +1 -1
  24. package/dist/cli/cache/cache-manager.js.map +1 -1
  25. package/dist/cli/mcp/analyze-tool.d.ts +2 -0
  26. package/dist/cli/mcp/analyze-tool.d.ts.map +1 -1
  27. package/dist/cli/mcp/analyze-tool.js +5 -0
  28. package/dist/cli/mcp/analyze-tool.js.map +1 -1
  29. package/dist/cli/mcp/mcp-server.d.ts +7 -2
  30. package/dist/cli/mcp/mcp-server.d.ts.map +1 -1
  31. package/dist/cli/mcp/mcp-server.js +37 -3
  32. package/dist/cli/mcp/mcp-server.js.map +1 -1
  33. package/dist/cli/processors/arch-json-provider-types.d.ts +5 -0
  34. package/dist/cli/processors/arch-json-provider-types.d.ts.map +1 -1
  35. package/dist/cli/processors/arch-json-provider.d.ts +5 -0
  36. package/dist/cli/processors/arch-json-provider.d.ts.map +1 -1
  37. package/dist/cli/processors/arch-json-provider.js +104 -55
  38. package/dist/cli/processors/arch-json-provider.js.map +1 -1
  39. package/dist/cli/processors/arch-json-utils.d.ts.map +1 -1
  40. package/dist/cli/processors/arch-json-utils.js +12 -3
  41. package/dist/cli/processors/arch-json-utils.js.map +1 -1
  42. package/dist/cli/processors/diagram-processor.d.ts +4 -0
  43. package/dist/cli/processors/diagram-processor.d.ts.map +1 -1
  44. package/dist/cli/processors/diagram-processor.js +2 -0
  45. package/dist/cli/processors/diagram-processor.js.map +1 -1
  46. package/dist/cli/processors/worker-pool-factory.d.ts +3 -0
  47. package/dist/cli/processors/worker-pool-factory.d.ts.map +1 -1
  48. package/dist/cli/processors/worker-pool-factory.js +9 -0
  49. package/dist/cli/processors/worker-pool-factory.js.map +1 -1
  50. package/dist/mermaid/generator.d.ts.map +1 -1
  51. package/dist/mermaid/generator.js +19 -1
  52. package/dist/mermaid/generator.js.map +1 -1
  53. package/dist/mermaid/renderer.d.ts.map +1 -1
  54. package/dist/mermaid/renderer.js +1 -1
  55. package/dist/mermaid/renderer.js.map +1 -1
  56. package/dist/mermaid/test-coverage-renderer.d.ts.map +1 -1
  57. package/dist/mermaid/test-coverage-renderer.js +18 -12
  58. package/dist/mermaid/test-coverage-renderer.js.map +1 -1
  59. package/dist/parser/archjson-aggregator.js +1 -1
  60. package/dist/parser/archjson-aggregator.js.map +1 -1
  61. package/dist/parser/parallel-parser.d.ts +10 -0
  62. package/dist/parser/parallel-parser.d.ts.map +1 -1
  63. package/dist/parser/parallel-parser.js +76 -35
  64. package/dist/parser/parallel-parser.js.map +1 -1
  65. package/dist/parser/parse-worker-pool.d.ts +59 -0
  66. package/dist/parser/parse-worker-pool.d.ts.map +1 -0
  67. package/dist/parser/parse-worker-pool.js +170 -0
  68. package/dist/parser/parse-worker-pool.js.map +1 -0
  69. package/dist/parser/parse-worker.d.ts +2 -0
  70. package/dist/parser/parse-worker.d.ts.map +1 -0
  71. package/dist/parser/parse-worker.js +71 -0
  72. package/dist/parser/parse-worker.js.map +1 -0
  73. package/dist/parser/process-parse-worker-pools.d.ts +18 -0
  74. package/dist/parser/process-parse-worker-pools.d.ts.map +1 -0
  75. package/dist/parser/process-parse-worker-pools.js +31 -0
  76. package/dist/parser/process-parse-worker-pools.js.map +1 -0
  77. package/dist/plugins/cpp/builders/class-builder.d.ts +2 -2
  78. package/dist/plugins/cpp/builders/class-builder.d.ts.map +1 -1
  79. package/dist/plugins/cpp/builders/class-builder.js.map +1 -1
  80. package/dist/plugins/cpp/index.d.ts +4 -1
  81. package/dist/plugins/cpp/index.d.ts.map +1 -1
  82. package/dist/plugins/cpp/index.js +11 -2
  83. package/dist/plugins/cpp/index.js.map +1 -1
  84. package/dist/plugins/cpp/tree-sitter-bridge.d.ts +3 -2
  85. package/dist/plugins/cpp/tree-sitter-bridge.d.ts.map +1 -1
  86. package/dist/plugins/cpp/tree-sitter-bridge.js +17 -15
  87. package/dist/plugins/cpp/tree-sitter-bridge.js.map +1 -1
  88. package/dist/plugins/golang/builders/function-builder.d.ts +4 -4
  89. package/dist/plugins/golang/builders/function-builder.d.ts.map +1 -1
  90. package/dist/plugins/golang/builders/function-builder.js.map +1 -1
  91. package/dist/plugins/golang/builders/goroutine-builder.d.ts +2 -2
  92. package/dist/plugins/golang/builders/goroutine-builder.d.ts.map +1 -1
  93. package/dist/plugins/golang/builders/goroutine-builder.js.map +1 -1
  94. package/dist/plugins/golang/builders/interface-builder.d.ts +4 -4
  95. package/dist/plugins/golang/builders/interface-builder.d.ts.map +1 -1
  96. package/dist/plugins/golang/builders/interface-builder.js.map +1 -1
  97. package/dist/plugins/golang/builders/node-utils.d.ts +3 -3
  98. package/dist/plugins/golang/builders/node-utils.d.ts.map +1 -1
  99. package/dist/plugins/golang/builders/node-utils.js.map +1 -1
  100. package/dist/plugins/golang/builders/struct-builder.d.ts +2 -2
  101. package/dist/plugins/golang/builders/struct-builder.d.ts.map +1 -1
  102. package/dist/plugins/golang/builders/struct-builder.js.map +1 -1
  103. package/dist/plugins/golang/go-parse-coordinator.d.ts +10 -2
  104. package/dist/plugins/golang/go-parse-coordinator.d.ts.map +1 -1
  105. package/dist/plugins/golang/go-parse-coordinator.js +44 -6
  106. package/dist/plugins/golang/go-parse-coordinator.js.map +1 -1
  107. package/dist/plugins/golang/gopls-client.d.ts +31 -2
  108. package/dist/plugins/golang/gopls-client.d.ts.map +1 -1
  109. package/dist/plugins/golang/gopls-client.js +230 -32
  110. package/dist/plugins/golang/gopls-client.js.map +1 -1
  111. package/dist/plugins/golang/gopls-interface-resolver.d.ts +14 -1
  112. package/dist/plugins/golang/gopls-interface-resolver.d.ts.map +1 -1
  113. package/dist/plugins/golang/gopls-interface-resolver.js +42 -11
  114. package/dist/plugins/golang/gopls-interface-resolver.js.map +1 -1
  115. package/dist/plugins/golang/index.d.ts +3 -1
  116. package/dist/plugins/golang/index.d.ts.map +1 -1
  117. package/dist/plugins/golang/index.js +17 -3
  118. package/dist/plugins/golang/index.js.map +1 -1
  119. package/dist/plugins/golang/interface-matcher.d.ts.map +1 -1
  120. package/dist/plugins/golang/interface-matcher.js +32 -30
  121. package/dist/plugins/golang/interface-matcher.js.map +1 -1
  122. package/dist/plugins/golang/tree-sitter-bridge.d.ts +3 -2
  123. package/dist/plugins/golang/tree-sitter-bridge.d.ts.map +1 -1
  124. package/dist/plugins/golang/tree-sitter-bridge.js +25 -23
  125. package/dist/plugins/golang/tree-sitter-bridge.js.map +1 -1
  126. package/dist/plugins/java/index.d.ts +4 -0
  127. package/dist/plugins/java/index.d.ts.map +1 -1
  128. package/dist/plugins/java/index.js +12 -1
  129. package/dist/plugins/java/index.js.map +1 -1
  130. package/dist/plugins/java/tree-sitter-bridge.d.ts +3 -2
  131. package/dist/plugins/java/tree-sitter-bridge.d.ts.map +1 -1
  132. package/dist/plugins/java/tree-sitter-bridge.js +33 -31
  133. package/dist/plugins/java/tree-sitter-bridge.js.map +1 -1
  134. package/dist/plugins/kotlin/builders/class-builder.d.ts +2 -1
  135. package/dist/plugins/kotlin/builders/class-builder.d.ts.map +1 -1
  136. package/dist/plugins/kotlin/builders/class-builder.js.map +1 -1
  137. package/dist/plugins/kotlin/builders/function-builder.d.ts +2 -1
  138. package/dist/plugins/kotlin/builders/function-builder.d.ts.map +1 -1
  139. package/dist/plugins/kotlin/builders/function-builder.js.map +1 -1
  140. package/dist/plugins/kotlin/index.d.ts +4 -1
  141. package/dist/plugins/kotlin/index.d.ts.map +1 -1
  142. package/dist/plugins/kotlin/index.js +12 -4
  143. package/dist/plugins/kotlin/index.js.map +1 -1
  144. package/dist/plugins/kotlin/tree-sitter-bridge.d.ts +3 -3
  145. package/dist/plugins/kotlin/tree-sitter-bridge.d.ts.map +1 -1
  146. package/dist/plugins/kotlin/tree-sitter-bridge.js +6 -7
  147. package/dist/plugins/kotlin/tree-sitter-bridge.js.map +1 -1
  148. package/dist/plugins/python/index.d.ts +4 -0
  149. package/dist/plugins/python/index.d.ts.map +1 -1
  150. package/dist/plugins/python/index.js +12 -1
  151. package/dist/plugins/python/index.js.map +1 -1
  152. package/dist/plugins/python/tree-sitter-bridge.d.ts +3 -2
  153. package/dist/plugins/python/tree-sitter-bridge.d.ts.map +1 -1
  154. package/dist/plugins/python/tree-sitter-bridge.js +50 -48
  155. package/dist/plugins/python/tree-sitter-bridge.js.map +1 -1
  156. package/dist/plugins/shared/native-parser-backend.d.ts +33 -0
  157. package/dist/plugins/shared/native-parser-backend.d.ts.map +1 -0
  158. package/dist/plugins/shared/native-parser-backend.js +84 -0
  159. package/dist/plugins/shared/native-parser-backend.js.map +1 -0
  160. package/dist/plugins/shared/parser-backend.d.ts +13 -0
  161. package/dist/plugins/shared/parser-backend.d.ts.map +1 -0
  162. package/dist/plugins/shared/parser-backend.js +38 -0
  163. package/dist/plugins/shared/parser-backend.js.map +1 -0
  164. package/dist/plugins/shared/parser-runtime.d.ts +32 -0
  165. package/dist/plugins/shared/parser-runtime.d.ts.map +1 -0
  166. package/dist/plugins/shared/parser-runtime.js +152 -0
  167. package/dist/plugins/shared/parser-runtime.js.map +1 -0
  168. package/dist/plugins/shared/plugin-factory.d.ts +5 -0
  169. package/dist/plugins/shared/plugin-factory.d.ts.map +1 -0
  170. package/dist/plugins/shared/plugin-factory.js +27 -0
  171. package/dist/plugins/shared/plugin-factory.js.map +1 -0
  172. package/dist/plugins/shared/syntax-tree.d.ts +32 -0
  173. package/dist/plugins/shared/syntax-tree.d.ts.map +1 -0
  174. package/dist/plugins/shared/syntax-tree.js +2 -0
  175. package/dist/plugins/shared/syntax-tree.js.map +1 -0
  176. package/dist/plugins/shared/wasm-parser-backend.d.ts +18 -0
  177. package/dist/plugins/shared/wasm-parser-backend.d.ts.map +1 -0
  178. package/dist/plugins/shared/wasm-parser-backend.js +118 -0
  179. package/dist/plugins/shared/wasm-parser-backend.js.map +1 -0
  180. package/dist/plugins/typescript/builders/module-graph-builder.d.ts.map +1 -1
  181. package/dist/plugins/typescript/builders/module-graph-builder.js +2 -1
  182. package/dist/plugins/typescript/builders/module-graph-builder.js.map +1 -1
  183. package/dist/types/config-global.d.ts +7 -1
  184. package/dist/types/config-global.d.ts.map +1 -1
  185. package/dist/types/config.d.ts +1 -0
  186. package/dist/types/config.d.ts.map +1 -1
  187. package/dist/types/config.js +1 -0
  188. package/dist/types/config.js.map +1 -1
  189. package/dist/types/fitness-rules.d.ts +34 -0
  190. package/dist/types/fitness-rules.d.ts.map +1 -0
  191. package/dist/types/fitness-rules.js +2 -0
  192. package/dist/types/fitness-rules.js.map +1 -0
  193. package/dist/types/parser-runtime.d.ts +4 -0
  194. package/dist/types/parser-runtime.d.ts.map +1 -0
  195. package/dist/types/parser-runtime.js +5 -0
  196. package/dist/types/parser-runtime.js.map +1 -0
  197. package/package.json +29 -16
  198. package/node_modules/node-addon-api/LICENSE.md +0 -9
  199. package/node_modules/node-addon-api/README.md +0 -95
  200. package/node_modules/node-addon-api/common.gypi +0 -21
  201. package/node_modules/node-addon-api/except.gypi +0 -25
  202. package/node_modules/node-addon-api/index.js +0 -14
  203. package/node_modules/node-addon-api/napi-inl.deprecated.h +0 -186
  204. package/node_modules/node-addon-api/napi-inl.h +0 -7033
  205. package/node_modules/node-addon-api/napi.h +0 -3309
  206. package/node_modules/node-addon-api/node_addon_api.gyp +0 -42
  207. package/node_modules/node-addon-api/node_api.gyp +0 -9
  208. package/node_modules/node-addon-api/noexcept.gypi +0 -26
  209. package/node_modules/node-addon-api/nothing.c +0 -0
  210. package/node_modules/node-addon-api/package-support.json +0 -21
  211. package/node_modules/node-addon-api/package.json +0 -480
  212. package/node_modules/node-addon-api/tools/README.md +0 -73
  213. package/node_modules/node-addon-api/tools/check-napi.js +0 -99
  214. package/node_modules/node-addon-api/tools/clang-format.js +0 -71
  215. package/node_modules/node-addon-api/tools/conversion.js +0 -301
  216. package/node_modules/node-gyp-build/README.md +0 -58
  217. package/node_modules/node-gyp-build/SECURITY.md +0 -5
  218. package/node_modules/node-gyp-build/bin.js +0 -84
  219. package/node_modules/node-gyp-build/build-test.js +0 -19
  220. package/node_modules/node-gyp-build/index.js +0 -6
  221. package/node_modules/node-gyp-build/node-gyp-build.js +0 -207
  222. package/node_modules/node-gyp-build/optional.js +0 -7
  223. package/node_modules/node-gyp-build/package.json +0 -43
  224. package/node_modules/tree-sitter/README.md +0 -128
  225. package/node_modules/tree-sitter/binding.gyp +0 -80
  226. package/node_modules/tree-sitter/index.js +0 -916
  227. package/node_modules/tree-sitter/package.json +0 -76
  228. package/node_modules/tree-sitter/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  229. package/node_modules/tree-sitter/src/addon_data.h +0 -47
  230. package/node_modules/tree-sitter/src/binding.cc +0 -35
  231. package/node_modules/tree-sitter/src/conversions.cc +0 -140
  232. package/node_modules/tree-sitter/src/conversions.h +0 -22
  233. package/node_modules/tree-sitter/src/language.cc +0 -106
  234. package/node_modules/tree-sitter/src/language.h +0 -17
  235. package/node_modules/tree-sitter/src/logger.cc +0 -70
  236. package/node_modules/tree-sitter/src/logger.h +0 -19
  237. package/node_modules/tree-sitter/src/lookaheaditerator.cc +0 -122
  238. package/node_modules/tree-sitter/src/lookaheaditerator.h +0 -33
  239. package/node_modules/tree-sitter/src/node.cc +0 -1088
  240. package/node_modules/tree-sitter/src/node.h +0 -30
  241. package/node_modules/tree-sitter/src/parser.cc +0 -306
  242. package/node_modules/tree-sitter/src/parser.h +0 -35
  243. package/node_modules/tree-sitter/src/query.cc +0 -397
  244. package/node_modules/tree-sitter/src/query.h +0 -40
  245. package/node_modules/tree-sitter/src/tree.cc +0 -316
  246. package/node_modules/tree-sitter/src/tree.h +0 -45
  247. package/node_modules/tree-sitter/src/tree_cursor.cc +0 -213
  248. package/node_modules/tree-sitter/src/tree_cursor.h +0 -52
  249. package/node_modules/tree-sitter/tree-sitter.d.ts +0 -1042
  250. package/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +0 -1478
  251. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +0 -48
  252. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +0 -41
  253. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +0 -291
  254. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +0 -68
  255. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +0 -146
  256. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +0 -11
  257. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +0 -523
  258. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +0 -36
  259. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +0 -21
  260. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +0 -293
  261. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +0 -293
  262. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +0 -52
  263. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +0 -483
  264. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +0 -54
  265. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +0 -12
  266. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +0 -875
  267. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +0 -2293
  268. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +0 -286
  269. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +0 -48
  270. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +0 -239
  271. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +0 -4350
  272. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +0 -34
  273. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +0 -95
  274. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +0 -911
  275. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +0 -133
  276. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +0 -1034
  277. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +0 -399
  278. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +0 -170
  279. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +0 -31
  280. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +0 -717
  281. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +0 -48
  282. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +0 -11
  283. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +0 -1
  284. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +0 -414
  285. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +0 -29
  286. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +0 -1
  287. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +0 -448
  288. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +0 -1
  289. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +0 -1
  290. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +0 -733
  291. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +0 -881
  292. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +0 -75
  293. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +0 -24
  294. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +0 -113
  295. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +0 -1314
  296. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +0 -1935
  297. package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +0 -31
  298. package/scripts/postinstall-tree-sitter.mjs +0 -28
@@ -1,99 +0,0 @@
1
- 'use strict';
2
- // Descend into a directory structure and, for each file matching *.node, output
3
- // based on the imports found in the file whether it's an N-API module or not.
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
-
8
- // Read the output of the command, break it into lines, and use the reducer to
9
- // decide whether the file is an N-API module or not.
10
- function checkFile (file, command, argv, reducer) {
11
- const child = require('child_process').spawn(command, argv, {
12
- stdio: ['inherit', 'pipe', 'inherit']
13
- });
14
- let leftover = '';
15
- let isNapi;
16
- child.stdout.on('data', (chunk) => {
17
- if (isNapi === undefined) {
18
- chunk = (leftover + chunk.toString()).split(/[\r\n]+/);
19
- leftover = chunk.pop();
20
- isNapi = chunk.reduce(reducer, isNapi);
21
- if (isNapi !== undefined) {
22
- child.kill();
23
- }
24
- }
25
- });
26
- child.on('close', (code, signal) => {
27
- if ((code === null && signal !== null) || (code !== 0)) {
28
- console.log(
29
- command + ' exited with code: ' + code + ' and signal: ' + signal);
30
- } else {
31
- // Green if it's a N-API module, red otherwise.
32
- console.log(
33
- '\x1b[' + (isNapi ? '42' : '41') + 'm' +
34
- (isNapi ? ' N-API' : 'Not N-API') +
35
- '\x1b[0m: ' + file);
36
- }
37
- });
38
- }
39
-
40
- // Use nm -a to list symbols.
41
- function checkFileUNIX (file) {
42
- checkFile(file, 'nm', ['-a', file], (soFar, line) => {
43
- if (soFar === undefined) {
44
- line = line.match(/([0-9a-f]*)? ([a-zA-Z]) (.*$)/);
45
- if (line[2] === 'U') {
46
- if (/^napi/.test(line[3])) {
47
- soFar = true;
48
- }
49
- }
50
- }
51
- return soFar;
52
- });
53
- }
54
-
55
- // Use dumpbin /imports to list symbols.
56
- function checkFileWin32 (file) {
57
- checkFile(file, 'dumpbin', ['/imports', file], (soFar, line) => {
58
- if (soFar === undefined) {
59
- line = line.match(/([0-9a-f]*)? +([a-zA-Z0-9]) (.*$)/);
60
- if (line && /^napi/.test(line[line.length - 1])) {
61
- soFar = true;
62
- }
63
- }
64
- return soFar;
65
- });
66
- }
67
-
68
- // Descend into a directory structure and pass each file ending in '.node' to
69
- // one of the above checks, depending on the OS.
70
- function recurse (top) {
71
- fs.readdir(top, (error, items) => {
72
- if (error) {
73
- throw new Error('error reading directory ' + top + ': ' + error);
74
- }
75
- items.forEach((item) => {
76
- item = path.join(top, item);
77
- fs.stat(item, ((item) => (error, stats) => {
78
- if (error) {
79
- throw new Error('error about ' + item + ': ' + error);
80
- }
81
- if (stats.isDirectory()) {
82
- recurse(item);
83
- } else if (/[.]node$/.test(item) &&
84
- // Explicitly ignore files called 'nothing.node' because they are
85
- // artefacts of node-addon-api having identified a version of
86
- // Node.js that ships with a correct implementation of N-API.
87
- path.basename(item) !== 'nothing.node') {
88
- process.platform === 'win32'
89
- ? checkFileWin32(item)
90
- : checkFileUNIX(item);
91
- }
92
- })(item));
93
- });
94
- });
95
- }
96
-
97
- // Start with the directory given on the command line or the current directory
98
- // if nothing was given.
99
- recurse(process.argv.length > 3 ? process.argv[2] : '.');
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const spawn = require('child_process').spawnSync;
4
- const path = require('path');
5
-
6
- const filesToCheck = ['*.h', '*.cc'];
7
- const FORMAT_START = process.env.FORMAT_START || 'main';
8
-
9
- function main (args) {
10
- let fix = false;
11
- while (args.length > 0) {
12
- switch (args[0]) {
13
- case '-f':
14
- case '--fix':
15
- fix = true;
16
- break;
17
- default:
18
- }
19
- args.shift();
20
- }
21
-
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'];
27
- if (fix) {
28
- options.push(FORMAT_START);
29
- } else {
30
- options.push('--diff', FORMAT_START);
31
- }
32
-
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
- );
39
-
40
- if (result.stderr) {
41
- console.error('Error running git-clang-format:', result.stderr);
42
- return 2;
43
- }
44
-
45
- const clangFormatOutput = result.stdout.trim();
46
- // Bail fast if in fix mode.
47
- if (fix) {
48
- console.log(clangFormatOutput);
49
- return 0;
50
- }
51
- // Detect if there is any complains from clang-format
52
- if (
53
- clangFormatOutput !== '' &&
54
- clangFormatOutput !== 'no modified files to format' &&
55
- clangFormatOutput !== 'clang-format did not modify any files'
56
- ) {
57
- console.error(clangFormatOutput);
58
- const fixCmd = 'npm run lint:fix';
59
- console.error(`
60
- ERROR: please run "${fixCmd}" to format changes in your commit
61
- Note that when running the command locally, please keep your local
62
- main branch and working branch up to date with nodejs/node-addon-api
63
- to exclude un-related complains.
64
- Or you can run "env FORMAT_START=upstream/main ${fixCmd}".`);
65
- return 1;
66
- }
67
- }
68
-
69
- if (require.main === module) {
70
- process.exitCode = main(process.argv.slice(2));
71
- }
@@ -1,301 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
-
8
- const args = process.argv.slice(2);
9
- const dir = args[0];
10
- if (!dir) {
11
- console.log('Usage: node ' + path.basename(__filename) + ' <target-dir>');
12
- process.exit(1);
13
- }
14
-
15
- const NodeApiVersion = require('../').version;
16
-
17
- const disable = args[1];
18
- let ConfigFileOperations;
19
- if (disable !== '--disable' && dir !== '--disable') {
20
- ConfigFileOperations = {
21
- 'package.json': [
22
- [/([ ]*)"dependencies": {/g, '$1"dependencies": {\n$1 "node-addon-api": "' + NodeApiVersion + '",'],
23
- [/[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '']
24
- ],
25
- 'binding.gyp': [
26
- [/([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\','],
27
- [/([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \\"require(\'node-addon-api\').include_dir\\")",'],
28
- [/[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, ''],
29
- [/([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2xcode_settings$2: { $2GCC_ENABLE_CPP_EXCEPTIONS$2: $2YES$2,\n $2CLANG_CXX_LIBRARY$2: $2libc++$2,\n $2MACOSX_DEPLOYMENT_TARGET$2: $210.7$2,\n },\n $2msvs_settings$2: {\n $2VCCLCompilerTool$2: { $2ExceptionHandling$2: 1 },\n },']
30
- ]
31
- };
32
- } else {
33
- ConfigFileOperations = {
34
- 'package.json': [
35
- [/([ ]*)"dependencies": {/g, '$1"dependencies": {\n$1 "node-addon-api": "' + NodeApiVersion + '",'],
36
- [/[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '']
37
- ],
38
- 'binding.gyp': [
39
- [/([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\','],
40
- [/([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \'require(\\"node-addon-api\\").include_dir\')",'],
41
- [/[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, ''],
42
- [/([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2defines$2: [ $2NAPI_DISABLE_CPP_EXCEPTIONS$2 ],\n $2conditions$2: [\n [\'OS=="win"\', { $2defines$2: [ $2_HAS_EXCEPTIONS=1$2 ] }]\n ]']
43
- ]
44
- };
45
- }
46
-
47
- const SourceFileOperations = [
48
- [/Nan::SetMethod\(target,[\s]*"(.*)"[\s]*,[\s]*([^)]+)\)/g, 'exports.Set(Napi::String::New(env, "$1"), Napi::Function::New(env, $2))'],
49
-
50
- [/v8::Local<v8::FunctionTemplate>\s+(\w+)\s*=\s*Nan::New<FunctionTemplate>\([\w\d:]+\);(?:\w+->Reset\(\1\))?\s+\1->SetClassName\(Nan::String::New\("(\w+)"\)\);/g, 'Napi::Function $1 = DefineClass(env, "$2", {'],
51
- [/Local<FunctionTemplate>\s+(\w+)\s*=\s*Nan::New<FunctionTemplate>\([\w\d:]+\);\s+(\w+)\.Reset\((\1)\);\s+\1->SetClassName\((Nan::String::New|Nan::New<(v8::)*String>)\("(.+?)"\)\);/g, 'Napi::Function $1 = DefineClass(env, "$6", {'],
52
- [/Local<FunctionTemplate>\s+(\w+)\s*=\s*Nan::New<FunctionTemplate>\([\w\d:]+\);(?:\w+->Reset\(\1\))?\s+\1->SetClassName\(Nan::String::New\("(\w+)"\)\);/g, 'Napi::Function $1 = DefineClass(env, "$2", {'],
53
- [/Nan::New<v8::FunctionTemplate>\(([\w\d:]+)\)->GetFunction\(\)/g, 'Napi::Function::New(env, $1)'],
54
- [/Nan::New<FunctionTemplate>\(([\w\d:]+)\)->GetFunction()/g, 'Napi::Function::New(env, $1);'],
55
- [/Nan::New<v8::FunctionTemplate>\(([\w\d:]+)\)/g, 'Napi::Function::New(env, $1)'],
56
- [/Nan::New<FunctionTemplate>\(([\w\d:]+)\)/g, 'Napi::Function::New(env, $1)'],
57
-
58
- // FunctionTemplate to FunctionReference
59
- [/Nan::Persistent<(v8::)*FunctionTemplate>/g, 'Napi::FunctionReference'],
60
- [/Nan::Persistent<(v8::)*Function>/g, 'Napi::FunctionReference'],
61
- [/v8::Local<v8::FunctionTemplate>/g, 'Napi::FunctionReference'],
62
- [/Local<FunctionTemplate>/g, 'Napi::FunctionReference'],
63
- [/v8::FunctionTemplate/g, 'Napi::FunctionReference'],
64
- [/FunctionTemplate/g, 'Napi::FunctionReference'],
65
-
66
- [/([ ]*)Nan::SetPrototypeMethod\(\w+, "(\w+)", (\w+)\);/g, '$1InstanceMethod("$2", &$3),'],
67
- [/([ ]*)(?:\w+\.Reset\(\w+\);\s+)?\(target\)\.Set\("(\w+)",\s*Nan::GetFunction\((\w+)\)\);/gm,
68
- '});\n\n' +
69
- '$1constructor = Napi::Persistent($3);\n' +
70
- '$1constructor.SuppressDestruct();\n' +
71
- '$1target.Set("$2", $3);'],
72
-
73
- // TODO: Other attribute combinations
74
- [/static_cast<PropertyAttribute>\(ReadOnly\s*\|\s*DontDelete\)/gm,
75
- 'static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)'],
76
-
77
- [/([\w\d:<>]+?)::Cast\((.+?)\)/g, '$2.As<$1>()'],
78
-
79
- [/\*Nan::Utf8String\(([^)]+)\)/g, '$1->As<Napi::String>().Utf8Value().c_str()'],
80
- [/Nan::Utf8String +(\w+)\(([^)]+)\)/g, 'std::string $1 = $2.As<Napi::String>()'],
81
- [/Nan::Utf8String/g, 'std::string'],
82
-
83
- [/v8::String::Utf8Value (.+?)\((.+?)\)/g, 'Napi::String $1(env, $2)'],
84
- [/String::Utf8Value (.+?)\((.+?)\)/g, 'Napi::String $1(env, $2)'],
85
- [/\.length\(\)/g, '.Length()'],
86
-
87
- [/Nan::MakeCallback\(([^,]+),[\s\\]+([^,]+),/gm, '$2.MakeCallback($1,'],
88
-
89
- [/class\s+(\w+)\s*:\s*public\s+Nan::ObjectWrap/g, 'class $1 : public Napi::ObjectWrap<$1>'],
90
- [/(\w+)\(([^)]*)\)\s*:\s*Nan::ObjectWrap\(\)\s*(,)?/gm, '$1($2) : Napi::ObjectWrap<$1>()$3'],
91
-
92
- // HandleOKCallback to OnOK
93
- [/HandleOKCallback/g, 'OnOK'],
94
- // HandleErrorCallback to OnError
95
- [/HandleErrorCallback/g, 'OnError'],
96
-
97
- // ex. .As<Function>() to .As<Napi::Object>()
98
- [/\.As<v8::(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>\(\)/g, '.As<Napi::$1>()'],
99
- [/\.As<(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>\(\)/g, '.As<Napi::$1>()'],
100
-
101
- // ex. Nan::New<Number>(info[0]) to Napi::Number::New(info[0])
102
- [/Nan::New<(v8::)*Integer>\((.+?)\)/g, 'Napi::Number::New(env, $2)'],
103
- [/Nan::New\(([0-9.]+)\)/g, 'Napi::Number::New(env, $1)'],
104
- [/Nan::New<(v8::)*String>\("(.+?)"\)/g, 'Napi::String::New(env, "$2")'],
105
- [/Nan::New\("(.+?)"\)/g, 'Napi::String::New(env, "$1")'],
106
- [/Nan::New<(v8::)*(.+?)>\(\)/g, 'Napi::$2::New(env)'],
107
- [/Nan::New<(.+?)>\(\)/g, 'Napi::$1::New(env)'],
108
- [/Nan::New<(v8::)*(.+?)>\(/g, 'Napi::$2::New(env, '],
109
- [/Nan::New<(.+?)>\(/g, 'Napi::$1::New(env, '],
110
- [/Nan::NewBuffer\(/g, 'Napi::Buffer<char>::New(env, '],
111
- // TODO: Properly handle this
112
- [/Nan::New\(/g, 'Napi::New(env, '],
113
-
114
- [/\.IsInt32\(\)/g, '.IsNumber()'],
115
- [/->IsInt32\(\)/g, '.IsNumber()'],
116
-
117
- [/(.+?)->BooleanValue\(\)/g, '$1.As<Napi::Boolean>().Value()'],
118
- [/(.+?)->Int32Value\(\)/g, '$1.As<Napi::Number>().Int32Value()'],
119
- [/(.+?)->Uint32Value\(\)/g, '$1.As<Napi::Number>().Uint32Value()'],
120
- [/(.+?)->IntegerValue\(\)/g, '$1.As<Napi::Number>().Int64Value()'],
121
- [/(.+?)->NumberValue\(\)/g, '$1.As<Napi::Number>().DoubleValue()'],
122
-
123
- // ex. Nan::To<bool>(info[0]) to info[0].Value()
124
- [/Nan::To<v8::(Boolean|String|Number|Object|Array|Symbol|Function)>\((.+?)\)/g, '$2.To<Napi::$1>()'],
125
- [/Nan::To<(Boolean|String|Number|Object|Array|Symbol|Function)>\((.+?)\)/g, '$2.To<Napi::$1>()'],
126
- // ex. Nan::To<bool>(info[0]) to info[0].As<Napi::Boolean>().Value()
127
- [/Nan::To<bool>\((.+?)\)/g, '$1.As<Napi::Boolean>().Value()'],
128
- // ex. Nan::To<int>(info[0]) to info[0].As<Napi::Number>().Int32Value()
129
- [/Nan::To<int>\((.+?)\)/g, '$1.As<Napi::Number>().Int32Value()'],
130
- // ex. Nan::To<int32_t>(info[0]) to info[0].As<Napi::Number>().Int32Value()
131
- [/Nan::To<int32_t>\((.+?)\)/g, '$1.As<Napi::Number>().Int32Value()'],
132
- // ex. Nan::To<uint32_t>(info[0]) to info[0].As<Napi::Number>().Uint32Value()
133
- [/Nan::To<uint32_t>\((.+?)\)/g, '$1.As<Napi::Number>().Uint32Value()'],
134
- // ex. Nan::To<int64_t>(info[0]) to info[0].As<Napi::Number>().Int64Value()
135
- [/Nan::To<int64_t>\((.+?)\)/g, '$1.As<Napi::Number>().Int64Value()'],
136
- // ex. Nan::To<float>(info[0]) to info[0].As<Napi::Number>().FloatValue()
137
- [/Nan::To<float>\((.+?)\)/g, '$1.As<Napi::Number>().FloatValue()'],
138
- // ex. Nan::To<double>(info[0]) to info[0].As<Napi::Number>().DoubleValue()
139
- [/Nan::To<double>\((.+?)\)/g, '$1.As<Napi::Number>().DoubleValue()'],
140
-
141
- [/Nan::New\((\w+)\)->HasInstance\((\w+)\)/g, '$2.InstanceOf($1.Value())'],
142
-
143
- [/Nan::Has\(([^,]+),\s*/gm, '($1).Has('],
144
- [/\.Has\([\s|\\]*Nan::New<(v8::)*String>\(([^)]+)\)\)/gm, '.Has($1)'],
145
- [/\.Has\([\s|\\]*Nan::New\(([^)]+)\)\)/gm, '.Has($1)'],
146
-
147
- [/Nan::Get\(([^,]+),\s*/gm, '($1).Get('],
148
- [/\.Get\([\s|\\]*Nan::New<(v8::)*String>\(([^)]+)\)\)/gm, '.Get($1)'],
149
- [/\.Get\([\s|\\]*Nan::New\(([^)]+)\)\)/gm, '.Get($1)'],
150
-
151
- [/Nan::Set\(([^,]+),\s*/gm, '($1).Set('],
152
- [/\.Set\([\s|\\]*Nan::New<(v8::)*String>\(([^)]+)\)\s*,/gm, '.Set($1,'],
153
- [/\.Set\([\s|\\]*Nan::New\(([^)]+)\)\s*,/gm, '.Set($1,'],
154
-
155
- // ex. node::Buffer::HasInstance(info[0]) to info[0].IsBuffer()
156
- [/node::Buffer::HasInstance\((.+?)\)/g, '$1.IsBuffer()'],
157
- // ex. node::Buffer::Length(info[0]) to info[0].Length()
158
- [/node::Buffer::Length\((.+?)\)/g, '$1.As<Napi::Buffer<char>>().Length()'],
159
- // ex. node::Buffer::Data(info[0]) to info[0].Data()
160
- [/node::Buffer::Data\((.+?)\)/g, '$1.As<Napi::Buffer<char>>().Data()'],
161
- [/Nan::CopyBuffer\(/g, 'Napi::Buffer::Copy(env, '],
162
-
163
- // Nan::AsyncQueueWorker(worker)
164
- [/Nan::AsyncQueueWorker\((.+)\);/g, '$1.Queue();'],
165
- [/Nan::(Undefined|Null|True|False)\(\)/g, 'env.$1()'],
166
-
167
- // Nan::ThrowError(error) to Napi::Error::New(env, error).ThrowAsJavaScriptException()
168
- [/([ ]*)return Nan::Throw(\w*?)Error\((.+?)\);/g, '$1Napi::$2Error::New(env, $3).ThrowAsJavaScriptException();\n$1return env.Null();'],
169
- [/Nan::Throw(\w*?)Error\((.+?)\);\n(\s*)return;/g, 'Napi::$1Error::New(env, $2).ThrowAsJavaScriptException();\n$3return env.Null();'],
170
- [/Nan::Throw(\w*?)Error\((.+?)\);/g, 'Napi::$1Error::New(env, $2).ThrowAsJavaScriptException();\n'],
171
- // Nan::RangeError(error) to Napi::RangeError::New(env, error)
172
- [/Nan::(\w*?)Error\((.+)\)/g, 'Napi::$1Error::New(env, $2)'],
173
-
174
- [/Nan::Set\((.+?),\n* *(.+?),\n* *(.+?),\n* *(.+?)\)/g, '$1.Set($2, $3, $4)'],
175
-
176
- [/Nan::(Escapable)?HandleScope\s+(\w+)\s*;/g, 'Napi::$1HandleScope $2(env);'],
177
- [/Nan::(Escapable)?HandleScope/g, 'Napi::$1HandleScope'],
178
- [/Nan::ForceSet\(([^,]+), ?/g, '$1->DefineProperty('],
179
- [/\.ForceSet\(Napi::String::New\(env, "(\w+)"\),\s*?/g, '.DefineProperty("$1", '],
180
- // [ /Nan::GetPropertyNames\(([^,]+)\)/, '$1->GetPropertyNames()' ],
181
- [/Nan::Equals\(([^,]+),/g, '$1.StrictEquals('],
182
-
183
- [/(.+)->Set\(/g, '$1.Set('],
184
-
185
- [/Nan::Callback/g, 'Napi::FunctionReference'],
186
-
187
- [/Nan::Persistent<Object>/g, 'Napi::ObjectReference'],
188
- [/Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target/g, 'Napi::Env& env, Napi::Object& target'],
189
-
190
- [/(\w+)\*\s+(\w+)\s*=\s*Nan::ObjectWrap::Unwrap<\w+>\(info\.This\(\)\);/g, '$1* $2 = this;'],
191
- [/Nan::ObjectWrap::Unwrap<(\w+)>\((.*)\);/g, '$2.Unwrap<$1>();'],
192
-
193
- [/Nan::NAN_METHOD_RETURN_TYPE/g, 'void'],
194
- [/NAN_INLINE/g, 'inline'],
195
-
196
- [/Nan::NAN_METHOD_ARGS_TYPE/g, 'const Napi::CallbackInfo&'],
197
- [/NAN_METHOD\(([\w\d:]+?)\)/g, 'Napi::Value $1(const Napi::CallbackInfo& info)'],
198
- [/static\s*NAN_GETTER\(([\w\d:]+?)\)/g, 'Napi::Value $1(const Napi::CallbackInfo& info)'],
199
- [/NAN_GETTER\(([\w\d:]+?)\)/g, 'Napi::Value $1(const Napi::CallbackInfo& info)'],
200
- [/static\s*NAN_SETTER\(([\w\d:]+?)\)/g, 'void $1(const Napi::CallbackInfo& info, const Napi::Value& value)'],
201
- [/NAN_SETTER\(([\w\d:]+?)\)/g, 'void $1(const Napi::CallbackInfo& info, const Napi::Value& value)'],
202
- [/void Init\((v8::)*Local<(v8::)*Object> exports\)/g, 'Napi::Object Init(Napi::Env env, Napi::Object exports)'],
203
- [/NAN_MODULE_INIT\(([\w\d:]+?)\);/g, 'Napi::Object $1(Napi::Env env, Napi::Object exports);'],
204
- [/NAN_MODULE_INIT\(([\w\d:]+?)\)/g, 'Napi::Object $1(Napi::Env env, Napi::Object exports)'],
205
-
206
- [/::(Init(?:ialize)?)\(target\)/g, '::$1(env, target, module)'],
207
- [/constructor_template/g, 'constructor'],
208
-
209
- [/Nan::FunctionCallbackInfo<(v8::)?Value>[ ]*& [ ]*info\)[ ]*{\n*([ ]*)/gm, 'Napi::CallbackInfo& info) {\n$2Napi::Env env = info.Env();\n$2'],
210
- [/Nan::FunctionCallbackInfo<(v8::)*Value>\s*&\s*info\);/g, 'Napi::CallbackInfo& info);'],
211
- [/Nan::FunctionCallbackInfo<(v8::)*Value>\s*&/g, 'Napi::CallbackInfo&'],
212
-
213
- [/Buffer::HasInstance\(([^)]+)\)/g, '$1.IsBuffer()'],
214
-
215
- [/info\[(\d+)\]->/g, 'info[$1].'],
216
- [/info\[([\w\d]+)\]->/g, 'info[$1].'],
217
- [/info\.This\(\)->/g, 'info.This().'],
218
- [/->Is(Object|String|Int32|Number)\(\)/g, '.Is$1()'],
219
- [/info.GetReturnValue\(\).SetUndefined\(\)/g, 'return env.Undefined()'],
220
- [/info\.GetReturnValue\(\)\.Set\(((\n|.)+?)\);/g, 'return $1;'],
221
-
222
- // ex. Local<Value> to Napi::Value
223
- [/v8::Local<v8::(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>/g, 'Napi::$1'],
224
- [/Local<(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>/g, 'Napi::$1'],
225
-
226
- // Declare an env in helper functions that take a Napi::Value
227
- [/(\w+)\(Napi::Value (\w+)(,\s*[^()]+)?\)\s*{\n*([ ]*)/gm, '$1(Napi::Value $2$3) {\n$4Napi::Env env = $2.Env();\n$4'],
228
-
229
- // delete #include <node.h> and/or <v8.h>
230
- [/#include +(<|")(?:node|nan).h("|>)/g, '#include $1napi.h$2\n#include $1uv.h$2'],
231
- // NODE_MODULE to NODE_API_MODULE
232
- [/NODE_MODULE/g, 'NODE_API_MODULE'],
233
- [/Nan::/g, 'Napi::'],
234
- [/nan.h/g, 'napi.h'],
235
-
236
- // delete .FromJust()
237
- [/\.FromJust\(\)/g, ''],
238
- // delete .ToLocalCheck()
239
- [/\.ToLocalChecked\(\)/g, ''],
240
- [/^.*->SetInternalFieldCount\(.*$/gm, ''],
241
-
242
- // replace using node; and/or using v8; to using Napi;
243
- [/using (node|v8);/g, 'using Napi;'],
244
- [/using namespace (node|Nan|v8);/g, 'using namespace Napi;'],
245
- // delete using v8::Local;
246
- [/using v8::Local;\n/g, ''],
247
- // replace using v8::XXX; with using Napi::XXX
248
- [/using v8::([A-Za-z]+);/g, 'using Napi::$1;']
249
-
250
- ];
251
-
252
- const paths = listFiles(dir);
253
- paths.forEach(function (dirEntry) {
254
- const filename = dirEntry.split('\\').pop().split('/').pop();
255
-
256
- // Check whether the file is a source file or a config file
257
- // then execute function accordingly
258
- const sourcePattern = /.+\.h|.+\.cc|.+\.cpp/;
259
- if (sourcePattern.test(filename)) {
260
- convertFile(dirEntry, SourceFileOperations);
261
- } else if (ConfigFileOperations[filename] != null) {
262
- convertFile(dirEntry, ConfigFileOperations[filename]);
263
- }
264
- });
265
-
266
- function listFiles (dir, filelist) {
267
- const files = fs.readdirSync(dir);
268
- filelist = filelist || [];
269
- files.forEach(function (file) {
270
- if (file === 'node_modules') {
271
- return;
272
- }
273
-
274
- if (fs.statSync(path.join(dir, file)).isDirectory()) {
275
- filelist = listFiles(path.join(dir, file), filelist);
276
- } else {
277
- filelist.push(path.join(dir, file));
278
- }
279
- });
280
- return filelist;
281
- }
282
-
283
- function convert (content, operations) {
284
- for (let i = 0; i < operations.length; i++) {
285
- const operation = operations[i];
286
- content = content.replace(operation[0], operation[1]);
287
- }
288
- return content;
289
- }
290
-
291
- function convertFile (fileName, operations) {
292
- fs.readFile(fileName, 'utf-8', function (err, file) {
293
- if (err) throw err;
294
-
295
- file = convert(file, operations);
296
-
297
- fs.writeFile(fileName, file, function (err) {
298
- if (err) throw err;
299
- });
300
- });
301
- }
@@ -1,58 +0,0 @@
1
- # node-gyp-build
2
-
3
- > Build tool and bindings loader for [`node-gyp`][node-gyp] that supports prebuilds.
4
-
5
- ```
6
- npm install node-gyp-build
7
- ```
8
-
9
- [![Test](https://github.com/prebuild/node-gyp-build/actions/workflows/test.yml/badge.svg)](https://github.com/prebuild/node-gyp-build/actions/workflows/test.yml)
10
-
11
- Use together with [`prebuildify`][prebuildify] to easily support prebuilds for your native modules.
12
-
13
- ## Usage
14
-
15
- > **Note.** Prebuild names have changed in [`prebuildify@3`][prebuildify] and `node-gyp-build@4`. Please see the documentation below.
16
-
17
- `node-gyp-build` works similar to [`node-gyp build`][node-gyp] except that it will check if a build or prebuild is present before rebuilding your project.
18
-
19
- It's main intended use is as an npm install script and bindings loader for native modules that bundle prebuilds using [`prebuildify`][prebuildify].
20
-
21
- First add `node-gyp-build` as an install script to your native project
22
-
23
- ``` js
24
- {
25
- ...
26
- "scripts": {
27
- "install": "node-gyp-build"
28
- }
29
- }
30
- ```
31
-
32
- Then in your `index.js`, instead of using the [`bindings`](https://www.npmjs.com/package/bindings) module use `node-gyp-build` to load your binding.
33
-
34
- ``` js
35
- var binding = require('node-gyp-build')(__dirname)
36
- ```
37
-
38
- If you do these two things and bundle prebuilds with [`prebuildify`][prebuildify] your native module will work for most platforms
39
- without having to compile on install time AND will work in both node and electron without the need to recompile between usage.
40
-
41
- Users can override `node-gyp-build` and force compiling by doing `npm install --build-from-source`.
42
-
43
- Prebuilds will be attempted loaded from `MODULE_PATH/prebuilds/...` and then next `EXEC_PATH/prebuilds/...` (the latter allowing use with `zeit/pkg`)
44
-
45
- ## Supported prebuild names
46
-
47
- If so desired you can bundle more specific flavors, for example `musl` builds to support Alpine, or targeting a numbered ARM architecture version.
48
-
49
- These prebuilds can be bundled in addition to generic prebuilds; `node-gyp-build` will try to find the most specific flavor first. Prebuild filenames are composed of _tags_. The runtime tag takes precedence, as does an `abi` tag over `napi`. For more details on tags, please see [`prebuildify`][prebuildify].
50
-
51
- Values for the `libc` and `armv` tags are auto-detected but can be overridden through the `LIBC` and `ARM_VERSION` environment variables, respectively.
52
-
53
- ## License
54
-
55
- MIT
56
-
57
- [prebuildify]: https://github.com/prebuild/prebuildify
58
- [node-gyp]: https://www.npmjs.com/package/node-gyp
@@ -1,5 +0,0 @@
1
- ## Security contact information
2
-
3
- To report a security vulnerability, please use the
4
- [Tidelift security contact](https://tidelift.com/security).
5
- Tidelift will coordinate the fix and disclosure.
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var proc = require('child_process')
4
- var os = require('os')
5
- var path = require('path')
6
-
7
- if (!buildFromSource()) {
8
- proc.exec('node-gyp-build-test', function (err, stdout, stderr) {
9
- if (err) {
10
- if (verbose()) console.error(stderr)
11
- preinstall()
12
- }
13
- })
14
- } else {
15
- preinstall()
16
- }
17
-
18
- function build () {
19
- var win32 = os.platform() === 'win32'
20
- var shell = win32
21
- var args = [win32 ? 'node-gyp.cmd' : 'node-gyp', 'rebuild']
22
-
23
- try {
24
- var pkg = require('node-gyp/package.json')
25
- args = [
26
- process.execPath,
27
- path.join(require.resolve('node-gyp/package.json'), '..', typeof pkg.bin === 'string' ? pkg.bin : pkg.bin['node-gyp']),
28
- 'rebuild'
29
- ]
30
- shell = false
31
- } catch (_) {}
32
-
33
- proc.spawn(args[0], args.slice(1), { stdio: 'inherit', shell, windowsHide: true }).on('exit', function (code) {
34
- if (code || !process.argv[3]) process.exit(code)
35
- exec(process.argv[3]).on('exit', function (code) {
36
- process.exit(code)
37
- })
38
- })
39
- }
40
-
41
- function preinstall () {
42
- if (!process.argv[2]) return build()
43
- exec(process.argv[2]).on('exit', function (code) {
44
- if (code) process.exit(code)
45
- build()
46
- })
47
- }
48
-
49
- function exec (cmd) {
50
- if (process.platform !== 'win32') {
51
- var shell = os.platform() === 'android' ? 'sh' : true
52
- return proc.spawn(cmd, [], {
53
- shell,
54
- stdio: 'inherit'
55
- })
56
- }
57
-
58
- return proc.spawn(cmd, [], {
59
- windowsVerbatimArguments: true,
60
- stdio: 'inherit',
61
- shell: true,
62
- windowsHide: true
63
- })
64
- }
65
-
66
- function buildFromSource () {
67
- return hasFlag('--build-from-source') || process.env.npm_config_build_from_source === 'true'
68
- }
69
-
70
- function verbose () {
71
- return hasFlag('--verbose') || process.env.npm_config_loglevel === 'verbose'
72
- }
73
-
74
- // TODO (next major): remove in favor of env.npm_config_* which works since npm
75
- // 0.1.8 while npm_config_argv will stop working in npm 7. See npm/rfcs#90
76
- function hasFlag (flag) {
77
- if (!process.env.npm_config_argv) return false
78
-
79
- try {
80
- return JSON.parse(process.env.npm_config_argv).original.indexOf(flag) !== -1
81
- } catch (_) {
82
- return false
83
- }
84
- }
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- process.env.NODE_ENV = 'test'
4
-
5
- var path = require('path')
6
- var test = null
7
-
8
- try {
9
- var pkg = require(path.join(process.cwd(), 'package.json'))
10
- if (pkg.name && process.env[pkg.name.toUpperCase().replace(/-/g, '_')]) {
11
- process.exit(0)
12
- }
13
- test = pkg.prebuild.test
14
- } catch (err) {
15
- // do nothing
16
- }
17
-
18
- if (test) require(path.join(process.cwd(), test))
19
- else require('./')()
@@ -1,6 +0,0 @@
1
- const runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require // eslint-disable-line
2
- if (typeof runtimeRequire.addon === 'function') { // if the platform supports native resolving prefer that
3
- module.exports = runtimeRequire.addon.bind(runtimeRequire)
4
- } else { // else use the runtime version here
5
- module.exports = require('./node-gyp-build.js')
6
- }