code-gauge 4.6.0 → 4.7.1

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 (57) hide show
  1. package/README.md +25 -0
  2. package/THIRD-PARTY-NOTICES.txt +8911 -0
  3. package/dist/cliConfig.cjs +1 -1
  4. package/dist/cliConfig.cjs.map +1 -1
  5. package/dist/cliConfig.js +1 -1
  6. package/dist/diffCommand.cjs +3 -3
  7. package/dist/diffCommand.cjs.map +1 -1
  8. package/dist/diffCommand.js +3 -3
  9. package/dist/diffCommand.js.map +1 -1
  10. package/dist/languages.cjs +1 -1
  11. package/dist/languages.cjs.map +1 -1
  12. package/dist/languages.js +1 -1
  13. package/dist/languages.js.map +1 -1
  14. package/dist/metrics.cjs +1 -1
  15. package/dist/metrics.cjs.map +1 -1
  16. package/dist/metrics.d.ts +8 -3
  17. package/dist/metrics.js +1 -1
  18. package/dist/metrics.js.map +1 -1
  19. package/dist/nativeMetrics.cjs +3 -3
  20. package/dist/nativeMetrics.cjs.map +1 -1
  21. package/dist/nativeMetrics.d.ts +30 -0
  22. package/dist/nativeMetrics.js +3 -3
  23. package/dist/nativeMetrics.js.map +1 -1
  24. package/dist/scan.cjs +1 -1
  25. package/dist/scan.cjs.map +1 -1
  26. package/dist/scan.d.ts +2 -2
  27. package/dist/scan.js +1 -1
  28. package/dist/scan.js.map +1 -1
  29. package/dist/wasmBinding.cjs +2 -0
  30. package/dist/wasmBinding.cjs.map +1 -0
  31. package/dist/wasmBinding.d.ts +9 -0
  32. package/dist/wasmBinding.js +2 -0
  33. package/dist/wasmBinding.js.map +1 -0
  34. package/dist/worker.cjs +2 -0
  35. package/dist/worker.cjs.map +1 -0
  36. package/dist/worker.d.ts +1 -0
  37. package/dist/worker.js +2 -0
  38. package/dist/worker.js.map +1 -0
  39. package/native/Cargo.lock +1 -0
  40. package/native/Cargo.toml +6 -2
  41. package/native/build.rs +4 -1
  42. package/native/code-gauge.wasm +0 -0
  43. package/native/src/complexity.rs +134 -230
  44. package/native/src/dep_degree.rs +42 -39
  45. package/native/src/duplication.rs +65 -63
  46. package/native/src/functions.rs +169 -152
  47. package/native/src/languages.rs +20 -0
  48. package/native/src/lib.rs +41 -42
  49. package/native/src/measure.rs +109 -123
  50. package/native/src/napi.rs +104 -0
  51. package/native/src/ncss.rs +79 -84
  52. package/native/src/near_miss.rs +7 -7
  53. package/native/src/tree_index.rs +110 -0
  54. package/native/src/util.rs +17 -12
  55. package/native/src/wasm.rs +128 -0
  56. package/native/src/worker_pool.rs +53 -0
  57. package/package.json +16 -11
package/README.md CHANGED
@@ -257,3 +257,28 @@ console.log(metrics.maxCognitiveComplexity);
257
257
  `detectLanguage(filePath)` maps a file extension to a supported language (or `undefined`) with the
258
258
  same table as the CLI, so `measureCode` can be fed arbitrary source files. Unlike the CLI scan, it
259
259
  does not skip generated files (e.g. `.d.ts`, `.min.js`) or test files.
260
+
261
+ ### Cloudflare Workers
262
+
263
+ Workers cannot load native addons, so the package's `workerd` export runs the same API on a
264
+ WebAssembly build of the Rust engine (about 2.3 MB gzipped). Wrangler resolves that export
265
+ automatically, and no `nodejs_compat` flag is needed:
266
+
267
+ ```ts
268
+ import { measureCode } from 'code-gauge';
269
+
270
+ export default {
271
+ async fetch(request: Request): Promise<Response> {
272
+ const code = await request.text();
273
+ return Response.json(measureCode(code, { language: 'typescript' }));
274
+ },
275
+ };
276
+ ```
277
+
278
+ Only the programmatic API is available; the CLI needs a file system and `git`. The Workers
279
+ runtime's stack limits nesting to a few thousand syntax-tree levels (the native addon allows
280
+ 5,000); deeper sources fail with an error instead of being measured.
281
+
282
+ In this repository, build the WebAssembly module with `bun run build-wasm`. It downloads a
283
+ [wasi-sdk](https://github.com/WebAssembly/wasi-sdk) release for the grammars' C sources unless
284
+ `WASI_SDK_PATH` points to an installation of the same release.