@mnemonik/shared 7.144.2 → 7.145.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 (113) hide show
  1. package/dist/ast/grammars.d.ts +6 -6
  2. package/dist/ast/grammars.d.ts.map +1 -1
  3. package/dist/ast/grammars.js +51 -10
  4. package/dist/ast/grammars.js.map +1 -1
  5. package/dist/sourceRedaction.d.ts.map +1 -1
  6. package/dist/sourceRedaction.js +743 -64
  7. package/dist/sourceRedaction.js.map +1 -1
  8. package/package.json +2 -1
  9. package/queries/clojure.tags.scm +1 -0
  10. package/queries/dart.tags.scm +3 -0
  11. package/queries/erlang.tags.scm +2 -0
  12. package/queries/graphql.tags.scm +3 -0
  13. package/queries/haskell.tags.scm +3 -0
  14. package/queries/julia.tags.scm +1 -0
  15. package/queries/kotlin.tags.scm +3 -0
  16. package/queries/ocaml.tags.scm +2 -0
  17. package/queries/ocaml_interface.tags.scm +1 -0
  18. package/queries/perl.tags.scm +2 -0
  19. package/queries/protobuf.tags.scm +5 -0
  20. package/queries/r.tags.scm +2 -0
  21. package/queries/zig.tags.scm +2 -0
  22. package/scripts/vendor-grammars.ts +586 -35
  23. package/src/ast/grammars.ts +51 -10
  24. package/src/sourceRedaction.ts +765 -12
  25. package/wasm/bash.wasm.gz +0 -0
  26. package/wasm/c-sharp.wasm.gz +0 -0
  27. package/wasm/c.wasm.gz +0 -0
  28. package/wasm/clojure.LICENSE +21 -0
  29. package/wasm/clojure.tags.scm +1 -0
  30. package/wasm/clojure.wasm.gz +0 -0
  31. package/wasm/cmake.wasm.gz +0 -0
  32. package/wasm/cpp.wasm.gz +0 -0
  33. package/wasm/dart.LICENSE +20 -0
  34. package/wasm/dart.tags.scm +3 -0
  35. package/wasm/dart.wasm.gz +0 -0
  36. package/wasm/elixir.wasm.gz +0 -0
  37. package/wasm/erlang.LICENSE +201 -0
  38. package/wasm/erlang.tags.scm +2 -0
  39. package/wasm/erlang.wasm.gz +0 -0
  40. package/wasm/go.wasm.gz +0 -0
  41. package/wasm/graphql.LICENSE +21 -0
  42. package/wasm/graphql.tags.scm +3 -0
  43. package/wasm/graphql.wasm.gz +0 -0
  44. package/wasm/groovy.wasm.gz +0 -0
  45. package/wasm/haskell.LICENSE +21 -0
  46. package/wasm/haskell.tags.scm +3 -0
  47. package/wasm/haskell.wasm.gz +0 -0
  48. package/wasm/java.wasm.gz +0 -0
  49. package/wasm/javascript.wasm.gz +0 -0
  50. package/wasm/julia.LICENSE +21 -0
  51. package/wasm/julia.tags.scm +1 -0
  52. package/wasm/julia.wasm.gz +0 -0
  53. package/wasm/kotlin.LICENSE +9 -0
  54. package/wasm/kotlin.tags.scm +3 -0
  55. package/wasm/kotlin.wasm.gz +0 -0
  56. package/wasm/lua.wasm.gz +0 -0
  57. package/wasm/nix.wasm.gz +0 -0
  58. package/wasm/objcpp.wasm.gz +0 -0
  59. package/wasm/ocaml.LICENSE +21 -0
  60. package/wasm/ocaml.tags.scm +2 -0
  61. package/wasm/ocaml.wasm.gz +0 -0
  62. package/wasm/ocaml_interface.LICENSE +21 -0
  63. package/wasm/ocaml_interface.tags.scm +1 -0
  64. package/wasm/ocaml_interface.wasm.gz +0 -0
  65. package/wasm/perl.LICENSE +7 -0
  66. package/wasm/perl.tags.scm +2 -0
  67. package/wasm/perl.wasm.gz +0 -0
  68. package/wasm/php.wasm.gz +0 -0
  69. package/wasm/powershell.wasm.gz +0 -0
  70. package/wasm/protobuf.LICENSE +21 -0
  71. package/wasm/protobuf.tags.scm +5 -0
  72. package/wasm/protobuf.wasm.gz +0 -0
  73. package/wasm/python.wasm.gz +0 -0
  74. package/wasm/r.LICENSE +9 -0
  75. package/wasm/r.tags.scm +2 -0
  76. package/wasm/r.wasm.gz +0 -0
  77. package/wasm/ruby.wasm.gz +0 -0
  78. package/wasm/rust.wasm.gz +0 -0
  79. package/wasm/scala.wasm.gz +0 -0
  80. package/wasm/solidity.wasm.gz +0 -0
  81. package/wasm/sql.wasm.gz +0 -0
  82. package/wasm/swift.wasm.gz +0 -0
  83. package/wasm/terraform.wasm.gz +0 -0
  84. package/wasm/tsx.wasm.gz +0 -0
  85. package/wasm/typescript.wasm.gz +0 -0
  86. package/wasm/zig.LICENSE +29 -0
  87. package/wasm/zig.tags.scm +2 -0
  88. package/wasm/zig.wasm.gz +0 -0
  89. package/wasm/bash.wasm +0 -0
  90. package/wasm/c-sharp.wasm +0 -0
  91. package/wasm/c.wasm +0 -0
  92. package/wasm/cmake.wasm +0 -0
  93. package/wasm/cpp.wasm +0 -0
  94. package/wasm/elixir.wasm +0 -0
  95. package/wasm/go.wasm +0 -0
  96. package/wasm/groovy.wasm +0 -0
  97. package/wasm/java.wasm +0 -0
  98. package/wasm/javascript.wasm +0 -0
  99. package/wasm/lua.wasm +0 -0
  100. package/wasm/nix.wasm +0 -0
  101. package/wasm/objcpp.wasm +0 -0
  102. package/wasm/php.wasm +0 -0
  103. package/wasm/powershell.wasm +0 -0
  104. package/wasm/python.wasm +0 -0
  105. package/wasm/ruby.wasm +0 -0
  106. package/wasm/rust.wasm +0 -0
  107. package/wasm/scala.wasm +0 -0
  108. package/wasm/solidity.wasm +0 -0
  109. package/wasm/sql.wasm +0 -0
  110. package/wasm/swift.wasm +0 -0
  111. package/wasm/terraform.wasm +0 -0
  112. package/wasm/tsx.wasm +0 -0
  113. package/wasm/typescript.wasm +0 -0
@@ -8,7 +8,7 @@
8
8
  * - it is quietly worse chunks, forever, with nothing in the logs. A caller that
9
9
  * gets `unavailable` can fall back to the heuristic chunker AND say why.
10
10
  *
11
- * Artifacts are vendored, not installed: `packages/shared/wasm/<id>.wasm` plus
11
+ * Artifacts are vendored, not installed: `packages/shared/wasm/<id>.wasm.gz` plus
12
12
  * the `<id>.tags.scm` tag queries, committed and published inside
13
13
  * `@mnemonik/shared` (see `scripts/vendor-grammars.ts` for how they get there
14
14
  * and why `npm pack` rather than devDependencies). A user's install therefore
@@ -17,9 +17,9 @@
17
17
  *
18
18
  * Two reports answer "what can this install do" and they are NOT
19
19
  * interchangeable. `astArtifactReport` stats the vendored files and costs
20
- * nothing; `astCapabilityReport` instantiates all 18 grammars, which costs ~690
21
- * ms and ~75 MB of RSS that is never returned because web-tree-sitter exposes no
22
- * `Language.delete`. Startup and per-file paths use the first; the second is for
20
+ * nothing; `astCapabilityReport` instantiates every grammar. The original
21
+ * 18-grammar set cost ~690 ms and ~75 MB of RSS that was never returned because
22
+ * web-tree-sitter exposes no `Language.delete`. Startup uses the first; the second is for
23
23
  * a diagnostic a human asked for. Grammars themselves load lazily, one per
24
24
  * language, on the first file that needs one.
25
25
  *
@@ -33,6 +33,7 @@
33
33
  import { existsSync, readFileSync, statSync } from 'node:fs';
34
34
  import { dirname, extname, join } from 'node:path';
35
35
  import { fileURLToPath } from 'node:url';
36
+ import { gunzipSync } from 'node:zlib';
36
37
  import { Language, Parser, Query, type Node } from 'web-tree-sitter';
37
38
  import { warn } from '../logger.js';
38
39
 
@@ -62,6 +63,19 @@ const AST_LANGUAGE_ID_LIST = [
62
63
  'terraform',
63
64
  'nix',
64
65
  'cmake',
66
+ 'kotlin',
67
+ 'dart',
68
+ 'erlang',
69
+ 'haskell',
70
+ 'ocaml',
71
+ 'ocaml_interface',
72
+ 'clojure',
73
+ 'julia',
74
+ 'perl',
75
+ 'r',
76
+ 'zig',
77
+ 'protobuf',
78
+ 'graphql',
65
79
  ] as const;
66
80
 
67
81
  /** A language this build can AST-parse. Exactly the vendored set, no aspirations. */
@@ -137,6 +151,19 @@ export const QUERY_CHAIN: Readonly<Record<AstLanguageId, readonly AstLanguageId[
137
151
  terraform: ['terraform'],
138
152
  nix: ['nix'],
139
153
  cmake: ['cmake'],
154
+ kotlin: ['kotlin'],
155
+ dart: ['dart'],
156
+ erlang: ['erlang'],
157
+ haskell: ['haskell'],
158
+ ocaml: ['ocaml'],
159
+ ocaml_interface: ['ocaml_interface'],
160
+ clojure: ['clojure'],
161
+ julia: ['julia'],
162
+ perl: ['perl'],
163
+ r: ['r'],
164
+ zig: ['zig'],
165
+ protobuf: ['protobuf'],
166
+ graphql: ['graphql'],
140
167
  };
141
168
 
142
169
  /**
@@ -151,6 +178,7 @@ const EXTENSION_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
151
178
  '.tsx': 'tsx',
152
179
  '.m': 'objcpp',
153
180
  '.mm': 'objcpp',
181
+ '.mli': 'ocaml_interface',
154
182
  };
155
183
 
156
184
  /** Upstream permits a bodyless else for highlighting across preprocessor boundaries. */
@@ -180,9 +208,8 @@ export function objcppSyntaxIssue(root: Node): string | null {
180
208
  *
181
209
  * Absences are deliberate answers, not gaps. `markdown` is missing because
182
210
  * headers already are a document's semantic unit and 10,483 production chunks
183
- * depend on `chunkMarkdown` keeping them; `kotlin`, `dart` and friends
184
- * are missing because no loadable grammar is vendored yet. Both resolve to
185
- * `null` and the heuristic chunker takes over.
211
+ * depend on `chunkMarkdown` keeping them; `svelte` is absent because component
212
+ * parsing belongs to its adapter. Both resolve to `null` here.
186
213
  */
187
214
  const LANGUAGE_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
188
215
  typescript: 'typescript',
@@ -208,6 +235,20 @@ const LANGUAGE_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
208
235
  terraform: 'terraform',
209
236
  nix: 'nix',
210
237
  cmake: 'cmake',
238
+ kotlin: 'kotlin',
239
+ dart: 'dart',
240
+ erlang: 'erlang',
241
+ haskell: 'haskell',
242
+ ocaml: 'ocaml',
243
+ clojure: 'clojure',
244
+ julia: 'julia',
245
+ perl: 'perl',
246
+ r: 'r',
247
+ zig: 'zig',
248
+ protobuf: 'protobuf',
249
+ graphql: 'graphql',
250
+ // Syntax reuse only: Starlark load/binding semantics belong to its own graph adapter.
251
+ starlark: 'python',
211
252
  };
212
253
 
213
254
  /** A loaded grammar plus its compiled query. Compiled once, reused per file. */
@@ -357,7 +398,7 @@ type ArtifactResolution =
357
398
  | { unavailable: 'wasm_missing' | 'tags_query_missing'; detail: string };
358
399
 
359
400
  function resolveArtifacts(id: AstLanguageId, artifactDir: string): ArtifactResolution {
360
- const wasmPath = join(artifactDir, `${grammarArtifactBasename(id)}.wasm`);
401
+ const wasmPath = join(artifactDir, `${grammarArtifactBasename(id)}.wasm.gz`);
361
402
  if (!isNonEmptyFile(wasmPath)) {
362
403
  return { unavailable: 'wasm_missing', detail: `missing or empty grammar artifact ${wasmPath}` };
363
404
  }
@@ -401,7 +442,7 @@ async function attemptLoad(id: AstLanguageId, artifactDir: string): Promise<Gram
401
442
  let language: Language;
402
443
  try {
403
444
  await initParser();
404
- language = await Language.load(wasmPath);
445
+ language = await Language.load(gunzipSync(readFileSync(wasmPath)));
405
446
  } catch (err) {
406
447
  // Presence is not loadability: tree-sitter-dart ships a 741 KB .wasm that
407
448
  // Language.load rejects because the artifact predates the current wasm ABI.
@@ -503,7 +544,7 @@ export function astArtifactReport(artifactDir: string = WASM_DIR): {
503
544
  *
504
545
  * NOT free, and the cost is memory rather than only latency: measured on this
505
546
  * checkout, ~690 ms and ~75 MB of RSS that is never given back. web-tree-sitter
506
- * 0.26.11 exposes no `Language.delete` (see `attemptLoad`), so all 18 grammars
547
+ * 0.26.11 exposes no `Language.delete` (see `attemptLoad`), so all vendored grammars
507
548
  * stay resident for the life of the process - including the fifteen a given repo
508
549
  * has no files for. Caching makes the second call free; it does not make the
509
550
  * first one cheap.