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.
- package/README.md +25 -0
- package/THIRD-PARTY-NOTICES.txt +8911 -0
- package/dist/cliConfig.cjs +1 -1
- package/dist/cliConfig.cjs.map +1 -1
- package/dist/cliConfig.js +1 -1
- package/dist/diffCommand.cjs +3 -3
- package/dist/diffCommand.cjs.map +1 -1
- package/dist/diffCommand.js +3 -3
- package/dist/diffCommand.js.map +1 -1
- package/dist/languages.cjs +1 -1
- package/dist/languages.cjs.map +1 -1
- package/dist/languages.js +1 -1
- package/dist/languages.js.map +1 -1
- package/dist/metrics.cjs +1 -1
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.ts +8 -3
- package/dist/metrics.js +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/nativeMetrics.cjs +3 -3
- package/dist/nativeMetrics.cjs.map +1 -1
- package/dist/nativeMetrics.d.ts +30 -0
- package/dist/nativeMetrics.js +3 -3
- package/dist/nativeMetrics.js.map +1 -1
- package/dist/scan.cjs +1 -1
- package/dist/scan.cjs.map +1 -1
- package/dist/scan.d.ts +2 -2
- package/dist/scan.js +1 -1
- package/dist/scan.js.map +1 -1
- package/dist/wasmBinding.cjs +2 -0
- package/dist/wasmBinding.cjs.map +1 -0
- package/dist/wasmBinding.d.ts +9 -0
- package/dist/wasmBinding.js +2 -0
- package/dist/wasmBinding.js.map +1 -0
- package/dist/worker.cjs +2 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +2 -0
- package/dist/worker.js.map +1 -0
- package/native/Cargo.lock +1 -0
- package/native/Cargo.toml +6 -2
- package/native/build.rs +4 -1
- package/native/code-gauge.wasm +0 -0
- package/native/src/complexity.rs +134 -230
- package/native/src/dep_degree.rs +42 -39
- package/native/src/duplication.rs +65 -63
- package/native/src/functions.rs +169 -152
- package/native/src/languages.rs +20 -0
- package/native/src/lib.rs +41 -42
- package/native/src/measure.rs +109 -123
- package/native/src/napi.rs +104 -0
- package/native/src/ncss.rs +79 -84
- package/native/src/near_miss.rs +7 -7
- package/native/src/tree_index.rs +110 -0
- package/native/src/util.rs +17 -12
- package/native/src/wasm.rs +128 -0
- package/native/src/worker_pool.rs +53 -0
- 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.
|