@c4a/extract-ts 0.6.18 → 0.7.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.
Files changed (4) hide show
  1. package/README.md +43 -5
  2. package/README.zh-CN.md +30 -6
  3. package/index.js +1813 -123
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [简体中文](./README.zh-CN.md)
4
4
 
5
- `@c4a/extract-ts` turns TypeScript and TSX structure into deterministic code
5
+ `@c4a/extract-ts` turns TypeScript, JavaScript, TSX, and JSX structure into deterministic code
6
6
  evidence for Context knowledge production. It implements the
7
7
  `ExtractionPlugin` protocol from `@c4a/extract` and is the default plugin used
8
8
  by the SDK `extractTs({ source, collection: "codegraph" })` phase for npm-style
@@ -15,12 +15,12 @@ APIs below are for reusable structural analysis and project-owned adapters.
15
15
 
16
16
  ## Package Role
17
17
 
18
- `@c4a/extract-ts` handles TypeScript package entry detection and AST extraction. It does not write `.context` files directly; `@c4a/extract` runs the plugin and `@c4a/context-cli` persists the resulting raw code snapshot.
18
+ `@c4a/extract-ts` handles npm package entry detection and ECMAScript-family AST extraction. It does not write `.context` files directly; `@c4a/extract` runs the plugin and `@c4a/context-cli` persists the resulting raw code snapshot.
19
19
 
20
- **Depends on:** `@c4a/extract`, `web-tree-sitter`
20
+ **Depends on:** `@c4a/extract`, `typescript`, `web-tree-sitter`
21
21
 
22
22
  ```text
23
- confirmed TypeScript boundary
23
+ confirmed TypeScript/JavaScript boundary
24
24
 
25
25
  entry detection + export tracing + AST facts
26
26
 
@@ -55,6 +55,19 @@ import { extractTypeScriptModuleExports } from "@c4a/extract-ts";
55
55
  const exports = extractTypeScriptModuleExports(source, "src/index.ts");
56
56
  ```
57
57
 
58
+ `extractEcmaScriptModuleExports()` is the format-neutral API for `.ts`, `.tsx`,
59
+ `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, and `.cjs`. In addition to ESM exports,
60
+ it recognizes static CommonJS `require`, `exports.name`, `module.exports.name`,
61
+ and object/wildcard `module.exports` forms. Its result declares the
62
+ `ast-catalog` coverage tier, parser capabilities, and an `analyzed` or
63
+ `unsupported` disposition with file-local diagnostics:
64
+
65
+ ```ts
66
+ import { extractEcmaScriptModuleExports } from "@c4a/extract-ts";
67
+
68
+ const moduleFacts = extractEcmaScriptModuleExports(source, "src/index.cjs");
69
+ ```
70
+
58
71
  ## Current Extraction Coverage
59
72
 
60
73
  ### Entry Detection
@@ -68,6 +81,7 @@ const exports = extractTypeScriptModuleExports(source, "src/index.ts");
68
81
  - `dist/` to `src/` source-path fallback through `resolveEntrySourcePath()`
69
82
  - package kind classification: `lib`, `cli`, or `service`
70
83
  - package version propagation into `ExtractionResult.package.version`
84
+ - authored `.js`, `.jsx`, `.mjs`, and `.cjs` entry files without remapping them to TypeScript
71
85
 
72
86
  The Context project may override auto-detection with source-relative
73
87
  `extractTs.entries`, or use `mode: "scan"` to make every `include`-matched file
@@ -88,7 +102,7 @@ It currently extracts:
88
102
  - type aliases
89
103
  - enums
90
104
  - variables
91
- - TSX component-like variables
105
+ - TSX/JSX component-like functions and variables
92
106
  - hook-like functions by name in downstream projection
93
107
  - class/interface/type members as nested symbols
94
108
  - JSDoc on declarations and members
@@ -107,6 +121,7 @@ It emits relations for:
107
121
  - `param_type`
108
122
  - `return_type`
109
123
  - `of_type`
124
+ - `calls`
110
125
 
111
126
  All emitted relations are code-grounded AST relations with confidence `1`.
112
127
 
@@ -120,6 +135,7 @@ All emitted relations are code-grounded AST relations with confidence `1`.
120
135
  - `export { A } from "./module"`
121
136
  - aliased export specifiers
122
137
  - circular re-export chains through an in-flight guard
138
+ - static CommonJS `require` bindings and `exports` / `module.exports` assignments
123
139
 
124
140
  Only declarations reachable through entries are marked `exported`; other declarations in traced files remain `internal`.
125
141
 
@@ -132,6 +148,18 @@ The plugin returns `ExtractionResult` v2. The `@c4a/extract` runner turns that i
132
148
  - `edges.jsonl` receives relation rows with package/module/version/hash metadata.
133
149
  - `digests.jsonl` receives versioned module digest rows.
134
150
 
151
+ The durable digest also retains `coverage.tier`, the complete capability list,
152
+ and a disposition for every reached file. Syntax errors, dynamic CommonJS
153
+ module names, and dynamic CommonJS export keys are `unsupported`; they include
154
+ a stable file/line/column diagnostic and do not publish partial symbols from
155
+ that file.
156
+
157
+ `typeScriptExtractionToEvidenceAdapterResult()` is the Indexer-facing export.
158
+ It converts only `c4a-extract-ts` output and publishes canonical file/fact
159
+ identities, per-file owner/disposition, explicit denominators, diagnostics, and
160
+ the ordered parser receipt through `context.indexer.evidence-adapter-result/v1`.
161
+ `ExtractionResult` remains available for the existing raw snapshot runner.
162
+
135
163
  The Context CLI consumes those rows during `context run extract:<source>:codegraph`
136
164
  to build review candidates for package/category/symbol knowledge Nodes. The
137
165
  important projection inputs are:
@@ -186,3 +214,13 @@ context run extract:component-lib:codegraph
186
214
 
187
215
  Agents should not hand-build runner input or raw snapshots for normal Context
188
216
  workspace operation.
217
+
218
+ ## Development
219
+
220
+ ```bash
221
+ bun run --filter @c4a/extract-ts build
222
+ bun run --filter @c4a/extract-ts typecheck
223
+ bun run --filter @c4a/extract-ts test
224
+ bun run --filter @c4a/extract-ts lint
225
+ bun run test:dist
226
+ ```
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](./README.md)
4
4
 
5
- `@c4a/extract-ts` 将 TypeScript 和 TSX 结构转化为 Context 知识生产可使用的确定性
5
+ `@c4a/extract-ts` 将 TypeScript、JavaScript、TSXJSX 结构转化为 Context 知识生产可使用的确定性
6
6
  代码证据。它实现 `@c4a/extract` 的 `ExtractionPlugin` 协议,也是 npm-style
7
7
  package 使用 `extractTs({ source, collection: "codegraph" })` 阶段时的默认插件。
8
8
 
@@ -13,17 +13,17 @@ package 使用 `extractTs({ source, collection: "codegraph" })` 阶段时的默
13
13
  ## 在知识生产链中的职责
14
14
 
15
15
  ```text
16
- 已确认的 TypeScript 边界
16
+ 已确认的 TypeScript/JavaScript 边界
17
17
 
18
18
  入口检测 + 导出追踪 + AST 事实
19
19
 
20
20
  原始代码快照 → 审核候选 → 正式知识
21
21
  ```
22
22
 
23
- `@c4a/extract-ts` 负责 TypeScript package 入口检测和 AST 提取。它不直接写工作区;
23
+ `@c4a/extract-ts` 负责 npm package 入口检测和 ECMAScript-family AST 提取。它不直接写工作区;
24
24
  `@c4a/extract` 运行插件,Context runtime 保存并校验原始代码快照。
25
25
 
26
- **依赖:** `@c4a/extract`、`web-tree-sitter`
26
+ **依赖:** `@c4a/extract`、`typescript`、`web-tree-sitter`
27
27
 
28
28
  ## 可复用结构 API
29
29
 
@@ -57,6 +57,18 @@ const exports = extractTypeScriptModuleExports(source, "src/index.ts");
57
57
 
58
58
  它不解析文件依赖,也不判断业务含义,适合由项目自有提取器继续映射为领域事实。
59
59
 
60
+ `extractEcmaScriptModuleExports()` 是 `.ts`、`.tsx`、`.mts`、`.cts`、`.js`、
61
+ `.jsx`、`.mjs` 和 `.cjs` 共用的接口。除 ESM 外,它还识别静态 CommonJS
62
+ `require`、`exports.name`、`module.exports.name` 及 object/wildcard
63
+ `module.exports`。结果显式返回 `ast-catalog` coverage tier、capability、逐文件
64
+ `analyzed | unsupported` 状态和定位诊断:
65
+
66
+ ```ts
67
+ import { extractEcmaScriptModuleExports } from "@c4a/extract-ts";
68
+
69
+ const moduleFacts = extractEcmaScriptModuleExports(source, "src/index.cjs");
70
+ ```
71
+
60
72
  ## 当前提取范围
61
73
 
62
74
  ### 入口检测
@@ -69,6 +81,7 @@ const exports = extractTypeScriptModuleExports(source, "src/index.ts");
69
81
  - 通过 `resolveEntrySourcePath()` 将 `dist/` 入口回退到 `src/`;
70
82
  - `lib`、`cli`、`service` package 类型识别;
71
83
  - 将 package version 写入 `ExtractionResult.package.version`。
84
+ - 直接识别源码目录中的 `.js`、`.jsx`、`.mjs` 和 `.cjs`,不会误映射为 TypeScript。
72
85
 
73
86
  Context 项目可以使用 source-relative `extractTs.entries` 覆盖自动检测,或用
74
87
  `mode: "scan"` 把所有 `include` 命中的文件作为提取根。这些设置属于知识工作区,
@@ -83,7 +96,7 @@ repo-relative 前缀。
83
96
  当前支持:
84
97
 
85
98
  - function、class、interface、type alias、enum 和 variable;
86
- - TSX component-like variable;
99
+ - TSX/JSX component-like function 和 variable;
87
100
  - 下游投影按名称识别的 hook-like function;
88
101
  - class/interface/type 的嵌套成员;
89
102
  - 声明和成员 JSDoc;
@@ -94,7 +107,7 @@ repo-relative 前缀。
94
107
  - 通过 `FC<Props>` 或 `{ComponentName}Props` 约定识别的 `propsType`。
95
108
 
96
109
  输出关系包括 `imports`、`imports_type`、`extends`、`implements`、
97
- `param_type`、`return_type` 和 `of_type`。这些关系均由 AST 直接支撑,confidence
110
+ `param_type`、`return_type`、`of_type` 和 `calls`。这些关系均由 AST 直接支撑,confidence
98
111
  为 `1`。
99
112
 
100
113
  ### 导出追踪
@@ -107,6 +120,7 @@ repo-relative 前缀。
107
120
  - `export { A } from "./module"`;
108
121
  - 别名 export specifier;
109
122
  - 通过 in-flight guard 处理循环 re-export。
123
+ - 静态 CommonJS `require` binding 和 `exports` / `module.exports` assignment。
110
124
 
111
125
  只有从入口导出面可达的声明会标记为 `exported`,同一已追踪文件中的其他声明保持
112
126
  `internal`。
@@ -120,6 +134,15 @@ repo-relative 前缀。
120
134
  - `edges.jsonl`:带 package、module、version 和 hash 元数据的关系;
121
135
  - `digests.jsonl`:版本化模块 digest。
122
136
 
137
+ 模块 digest 同时保留 `coverage.tier`、完整 capability 列表和每个已到达文件的
138
+ disposition。语法错误、动态 CommonJS module name 或动态 export key 会标为
139
+ `unsupported`,返回稳定的文件/行/列诊断,并且不会发布该文件的部分符号。
140
+
141
+ Indexer 使用 `typeScriptExtractionToEvidenceAdapterResult()` 作为正式导出。它只接受
142
+ `c4a-extract-ts` 的输出,并通过 `context.indexer.evidence-adapter-result/v1` 发布 canonical
143
+ file/fact identity、逐文件 owner/disposition、显式 denominator、诊断和有序 parser receipt。
144
+ 既有原始快照 Runner 继续使用 `ExtractionResult`。
145
+
123
146
  Context runtime 使用这些行生成 package/category/symbol 知识候选。重要输入是稳定
124
147
  package 名和版本、稳定导出符号、准确 kind/visibility、文件与行范围、关系端点、
125
148
  JSDoc 和类型成员信息。
@@ -166,4 +189,5 @@ bun run --filter @c4a/extract-ts build
166
189
  bun run --filter @c4a/extract-ts typecheck
167
190
  bun run --filter @c4a/extract-ts test
168
191
  bun run --filter @c4a/extract-ts lint
192
+ bun run test:dist
169
193
  ```