@deepseek-ai/dsh-typert-generator 0.2.0-rc.2 → 0.2.1-alpha.2
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.i18n.yaml +4 -4
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/index.js +22 -5
- package/lib/types/analyzer.js +27 -6
- package/lib/types/tsdown-plugin.js +6 -6
- package/package.json +6 -6
package/README.i18n.yaml
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
en: b8720f6ac186a8e8
|
|
22
22
|
zh: 3e04a4c1bebc2cf4
|
|
23
23
|
/deepseek-ai-dsh-typert-generator/use-this-package/analyzing-a-workspace-statically:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: 4ea0e4977cefa39d
|
|
25
|
+
zh: 41bdb6047bc79524
|
|
26
26
|
/deepseek-ai-dsh-typert-generator/use-this-package/running-generation-inside-a-tsdown-build:
|
|
27
27
|
en: cc3f7d23739380f6
|
|
28
28
|
zh: 864d15088f581271
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
en: f3b1002133fe8736
|
|
58
58
|
zh: e8d5fecd10db5e3a
|
|
59
59
|
/deepseek-ai-dsh-typert-generator/known-limitations-and-deferred-work/dev-note:
|
|
60
|
-
en:
|
|
61
|
-
zh:
|
|
60
|
+
en: e67f633dc6fe7773
|
|
61
|
+
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ After the build, `lib/typert.host.js` and `lib/typert.host.d.ts` exist and the [
|
|
|
47
47
|
|
|
48
48
|
Static consumers call `WorkspaceAnalyzer` directly against the workspace's `tsconfig.host.json` and `tsconfig.client.json` aggregates, select a face and package subset, and read the resulting `FaceModel` and type graph without emitting or loading runtime artifacts. `analyzeInBatches()` processes a large package selection through bounded compiler programs with the same model shape, and `discoverPackages()` finds contributing packages without building a type-checker program.
|
|
49
49
|
|
|
50
|
+
JSON, YAML, SVG, PNG, JPEG, and WebP resource exports contribute no TypeScript declarations and are excluded from the API model. Missing JavaScript or TypeScript export sources remain errors.
|
|
51
|
+
|
|
50
52
|
### Running generation inside a tsdown build
|
|
51
53
|
|
|
52
54
|
The package's `./tsdown` subpath provides `typertPlugin()` for the root tsdown config: it lowers standard decorators in TypeScript dependencies before bundling and emits the model-driven face artifacts at the package output root. In `package` mode it emits only the bundled package; in `workspace` mode it emits every explicit contributor once.
|
|
@@ -141,5 +143,3 @@ These limits define what the generator cannot model or emit; they are current pa
|
|
|
141
143
|
None.
|
|
142
144
|
|
|
143
145
|
</details>
|
|
144
|
-
|
|
145
|
-
**Runtime invariant:** No companion is published. The source-project analyzer and build-time emitter run outside any Cordis runtime; model snapshots, executable artifacts, and consuming-package typechecks enforce the output contract.
|
package/README.zh.md
CHANGED
|
@@ -47,6 +47,8 @@ files:
|
|
|
47
47
|
|
|
48
48
|
静态消费方直接针对工作区的 `tsconfig.host.json` 与 `tsconfig.client.json` 聚合配置调用 `WorkspaceAnalyzer`,选择 face 与包子集,并在不生成或加载运行时产物的前提下读取生成的 `FaceModel` 与类型图。`analyzeInBatches()` 通过有界的编译器程序处理大批量包选择,模型形态保持一致;`discoverPackages()` 无需构建类型检查程序即可找出参与贡献的包。
|
|
49
49
|
|
|
50
|
+
JSON、YAML、SVG、PNG、JPEG 和 WebP 资源导出不提供 TypeScript 声明,因此不进入 API 模型。JavaScript 或 TypeScript 导出源文件缺失时仍报错。
|
|
51
|
+
|
|
50
52
|
### 在 tsdown 构建中运行生成
|
|
51
53
|
|
|
52
54
|
包的 `./tsdown` 子路径为根 tsdown 配置提供 `typertPlugin()`:它在打包前转换 TypeScript 依赖中的标准装饰器,并在包输出根目录生成模型驱动的 face 产物。`package` 模式只生成当前打包的包;`workspace` 模式对每个显式贡献方各生成一次。
|
|
@@ -141,5 +143,3 @@ Host 与 Client 是两个独立的 TypeScript 程序。直接项目引用确定
|
|
|
141
143
|
无。
|
|
142
144
|
|
|
143
145
|
</details>
|
|
144
|
-
|
|
145
|
-
**运行时不变式:** 不发布伴生入口。源码项目分析器与构建时 emitter 均不在任何 Cordis 运行时中运行;模型快照、可执行产物与消费方包的类型检查会强制执行其输出约定。
|
package/lib/index.js
CHANGED
|
@@ -370,6 +370,9 @@ var FaceAnalyzer = class {
|
|
|
370
370
|
nodes = /* @__PURE__ */ new Map();
|
|
371
371
|
exportsByPackage = /* @__PURE__ */ new Map();
|
|
372
372
|
nodeOrdinals = /* @__PURE__ */ new Map();
|
|
373
|
+
/** Registration and package lookups per source path; the registration set is fixed per analyzer. */
|
|
374
|
+
registrationByFile = /* @__PURE__ */ new Map();
|
|
375
|
+
packageNameByFile = /* @__PURE__ */ new Map();
|
|
373
376
|
staticLookups;
|
|
374
377
|
staticContexts;
|
|
375
378
|
constructor(options) {
|
|
@@ -455,7 +458,7 @@ var FaceAnalyzer = class {
|
|
|
455
458
|
const targets = packageExportTargets(registration.manifest).filter(([subpath]) => registration.exportSubpaths === void 0 || registration.exportSubpaths.includes(subpath));
|
|
456
459
|
const records = [];
|
|
457
460
|
for (const [subpath, target] of targets) {
|
|
458
|
-
if (target.includes("*") || subpath === "./package.json" || subpath === "./typert" || subpath === "./client/typert" || subpath === "./remote" ||
|
|
461
|
+
if (target.includes("*") || subpath === "./package.json" || subpath === "./typert" || subpath === "./client/typert" || subpath === "./remote" || /\.(?:json|ya?ml|svg|png|jpe?g|webp)$/iu.test(target)) continue;
|
|
459
462
|
const sourcePath = sourcePathForExport(registration.root, target);
|
|
460
463
|
const sourceFile = this.sourceFiles.get(realPath(sourcePath));
|
|
461
464
|
if (sourceFile === void 0) throw new TypertAnalysisError(`typert(${this.face}): ${registration.name} export ${subpath} resolves to missing source ${sourcePath}`);
|
|
@@ -1954,12 +1957,19 @@ var FaceAnalyzer = class {
|
|
|
1954
1957
|
return `${this.packageNameForFile(declaration.getSourceFile().fileName)}:${location.file}#${symbol.name}`;
|
|
1955
1958
|
}
|
|
1956
1959
|
registrationForFile(file) {
|
|
1960
|
+
if (this.registrationByFile.has(file)) return this.registrationByFile.get(file);
|
|
1957
1961
|
const path = realPath(file);
|
|
1958
|
-
|
|
1962
|
+
const registration = this.allRegistrations.find((registration) => registration.face === this.face && isWithin(path, registration.root));
|
|
1963
|
+
this.registrationByFile.set(file, registration);
|
|
1964
|
+
return registration;
|
|
1959
1965
|
}
|
|
1960
1966
|
packageNameForFile(file) {
|
|
1967
|
+
const cached = this.packageNameByFile.get(file);
|
|
1968
|
+
if (cached !== void 0) return cached;
|
|
1961
1969
|
const path = realPath(file);
|
|
1962
|
-
|
|
1970
|
+
const name = this.allRegistrations.find((registration) => isWithin(path, registration.root))?.name ?? "<external>";
|
|
1971
|
+
this.packageNameByFile.set(file, name);
|
|
1972
|
+
return name;
|
|
1963
1973
|
}
|
|
1964
1974
|
allocateNodeId(site) {
|
|
1965
1975
|
const location = this.locationKey(site);
|
|
@@ -2140,7 +2150,8 @@ function declarationText(declaration) {
|
|
|
2140
2150
|
function classShape(node) {
|
|
2141
2151
|
const nonPublic = (member) => (ts.canHaveModifiers(member) ? ts.getModifiers(member) : void 0)?.some((modifier) => modifier.kind === ts.SyntaxKind.PrivateKeyword || modifier.kind === ts.SyntaxKind.ProtectedKeyword) ?? false;
|
|
2142
2152
|
const members = node.members.flatMap((member) => {
|
|
2143
|
-
|
|
2153
|
+
const name = ts.getNameOfDeclaration(member);
|
|
2154
|
+
if (ts.isClassStaticBlockDeclaration(member) || nonPublic(member) || name !== void 0 && ts.isPrivateIdentifier(name)) return [];
|
|
2144
2155
|
if (ts.isMethodDeclaration(member)) return [ts.factory.updateMethodDeclaration(member, member.modifiers, member.asteriskToken, member.name, member.questionToken, member.typeParameters, member.parameters, member.type, void 0)];
|
|
2145
2156
|
if (ts.isConstructorDeclaration(member)) return [ts.factory.updateConstructorDeclaration(member, member.modifiers, member.parameters, void 0)];
|
|
2146
2157
|
if (ts.isGetAccessorDeclaration(member)) return [ts.factory.updateGetAccessorDeclaration(member, member.modifiers, member.name, member.parameters, member.type, void 0)];
|
|
@@ -2383,8 +2394,14 @@ function formatProgramDiagnostic(root, face, diagnostic) {
|
|
|
2383
2394
|
return `typert(${face}): ${slash(relative(root, diagnostic.file.fileName))}:${String(position.line + 1)}:${String(position.character + 1)}: TypeScript TS${String(diagnostic.code)}: ${message}`;
|
|
2384
2395
|
}
|
|
2385
2396
|
const realPathCache = /* @__PURE__ */ new Map();
|
|
2397
|
+
/** Normalized form per requested path; `resolve` reads only the process working directory. */
|
|
2398
|
+
const absolutePathCache = /* @__PURE__ */ new Map();
|
|
2386
2399
|
function realPath(path) {
|
|
2387
|
-
|
|
2400
|
+
let absolute = absolutePathCache.get(path);
|
|
2401
|
+
if (absolute === void 0) {
|
|
2402
|
+
absolute = resolve(path);
|
|
2403
|
+
absolutePathCache.set(path, absolute);
|
|
2404
|
+
}
|
|
2388
2405
|
const cached = realPathCache.get(absolute);
|
|
2389
2406
|
if (cached !== void 0) return cached;
|
|
2390
2407
|
if (!existsSync(absolute)) return absolute;
|
package/lib/types/analyzer.js
CHANGED
|
@@ -437,6 +437,9 @@ class FaceAnalyzer {
|
|
|
437
437
|
nodes = new Map();
|
|
438
438
|
exportsByPackage = new Map();
|
|
439
439
|
nodeOrdinals = new Map();
|
|
440
|
+
/** Registration and package lookups per source path; the registration set is fixed per analyzer. */
|
|
441
|
+
registrationByFile = new Map();
|
|
442
|
+
packageNameByFile = new Map();
|
|
440
443
|
staticLookups;
|
|
441
444
|
staticContexts;
|
|
442
445
|
constructor(options) {
|
|
@@ -556,8 +559,8 @@ class FaceAnalyzer {
|
|
|
556
559
|
for (const [subpath, target] of targets) {
|
|
557
560
|
if (target.includes('*') || subpath === './package.json'
|
|
558
561
|
|| subpath === './typert' || subpath === './client/typert' || subpath === './remote'
|
|
559
|
-
// Data exports
|
|
560
|
-
||
|
|
562
|
+
// Data exports carry no TypeScript API; their owning readers validate the resources.
|
|
563
|
+
|| /\.(?:json|ya?ml|svg|png|jpe?g|webp)$/iu.test(target))
|
|
561
564
|
continue;
|
|
562
565
|
const sourcePath = sourcePathForExport(registration.root, target);
|
|
563
566
|
const sourceFile = this.sourceFiles.get(realPath(sourcePath));
|
|
@@ -2337,13 +2340,23 @@ class FaceAnalyzer {
|
|
|
2337
2340
|
return `${this.packageNameForFile(declaration.getSourceFile().fileName)}:${location.file}#${symbol.name}`;
|
|
2338
2341
|
}
|
|
2339
2342
|
registrationForFile(file) {
|
|
2343
|
+
if (this.registrationByFile.has(file))
|
|
2344
|
+
return this.registrationByFile.get(file);
|
|
2340
2345
|
const path = realPath(file);
|
|
2341
|
-
|
|
2346
|
+
const registration = this.allRegistrations
|
|
2342
2347
|
.find(registration => registration.face === this.face && isWithin(path, registration.root));
|
|
2348
|
+
this.registrationByFile.set(file, registration);
|
|
2349
|
+
return registration;
|
|
2343
2350
|
}
|
|
2344
2351
|
packageNameForFile(file) {
|
|
2352
|
+
const cached = this.packageNameByFile.get(file);
|
|
2353
|
+
if (cached !== undefined)
|
|
2354
|
+
return cached;
|
|
2345
2355
|
const path = realPath(file);
|
|
2346
|
-
|
|
2356
|
+
const name = this.allRegistrations
|
|
2357
|
+
.find(registration => isWithin(path, registration.root))?.name ?? '<external>';
|
|
2358
|
+
this.packageNameByFile.set(file, name);
|
|
2359
|
+
return name;
|
|
2347
2360
|
}
|
|
2348
2361
|
allocateNodeId(site) {
|
|
2349
2362
|
const location = this.locationKey(site);
|
|
@@ -2587,7 +2600,9 @@ function declarationText(declaration) {
|
|
|
2587
2600
|
function classShape(node) {
|
|
2588
2601
|
const nonPublic = (member) => (ts.canHaveModifiers(member) ? ts.getModifiers(member) : undefined)?.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword || modifier.kind === ts.SyntaxKind.ProtectedKeyword) ?? false;
|
|
2589
2602
|
const members = node.members.flatMap((member) => {
|
|
2590
|
-
|
|
2603
|
+
const name = ts.getNameOfDeclaration(member);
|
|
2604
|
+
if (ts.isClassStaticBlockDeclaration(member) || nonPublic(member)
|
|
2605
|
+
|| (name !== undefined && ts.isPrivateIdentifier(name)))
|
|
2591
2606
|
return [];
|
|
2592
2607
|
if (ts.isMethodDeclaration(member)) {
|
|
2593
2608
|
return [ts.factory.updateMethodDeclaration(member, member.modifiers, member.asteriskToken, member.name, member.questionToken, member.typeParameters, member.parameters, member.type, undefined)];
|
|
@@ -2865,8 +2880,14 @@ function formatProgramDiagnostic(root, face, diagnostic) {
|
|
|
2865
2880
|
return `typert(${face}): ${file}:${String(position.line + 1)}:${String(position.character + 1)}: TypeScript TS${String(diagnostic.code)}: ${message}`;
|
|
2866
2881
|
}
|
|
2867
2882
|
const realPathCache = new Map();
|
|
2883
|
+
/** Normalized form per requested path; `resolve` reads only the process working directory. */
|
|
2884
|
+
const absolutePathCache = new Map();
|
|
2868
2885
|
function realPath(path) {
|
|
2869
|
-
|
|
2886
|
+
let absolute = absolutePathCache.get(path);
|
|
2887
|
+
if (absolute === undefined) {
|
|
2888
|
+
absolute = resolve(path);
|
|
2889
|
+
absolutePathCache.set(path, absolute);
|
|
2890
|
+
}
|
|
2870
2891
|
const cached = realPathCache.get(absolute);
|
|
2871
2892
|
if (cached !== undefined)
|
|
2872
2893
|
return cached;
|
|
@@ -10,10 +10,10 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
10
10
|
import ts from 'typescript';
|
|
11
11
|
import { WorkspaceTypertGenerator } from "./workspace.js";
|
|
12
12
|
const DECORATOR_SYNTAX = /^\s*@[A-Za-z_$][\w$]*/m;
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
const
|
|
13
|
+
// Full builds and typecheck own TypeScript diagnostics. Benchmark-only emission
|
|
14
|
+
// defers them to the required full-build CI jobs; Typert generates reflection
|
|
15
|
+
// without repeating those diagnostics.
|
|
16
|
+
const TSC_OWNED_DIAGNOSTICS = { checkDiagnostics: false };
|
|
17
17
|
/**
|
|
18
18
|
* Create the decorator-lowering and typert-generation plugin for the root tsdown config.
|
|
19
19
|
* @param pluginOptions - package/workspace emission mode and independent program faces.
|
|
@@ -64,7 +64,7 @@ export function typertPlugin(pluginOptions = {}) {
|
|
|
64
64
|
return;
|
|
65
65
|
let artifacts = artifactsByRoot.get(root);
|
|
66
66
|
if (artifacts === undefined) {
|
|
67
|
-
const generator = new WorkspaceTypertGenerator(root,
|
|
67
|
+
const generator = new WorkspaceTypertGenerator(root, TSC_OWNED_DIAGNOSTICS);
|
|
68
68
|
artifacts = pluginOptions.faces === undefined
|
|
69
69
|
? generator.generate()
|
|
70
70
|
: generator.generate(undefined, pluginOptions.faces);
|
|
@@ -74,7 +74,7 @@ export function typertPlugin(pluginOptions = {}) {
|
|
|
74
74
|
},
|
|
75
75
|
};
|
|
76
76
|
function emitWorkspace(root, faces) {
|
|
77
|
-
const generator = new WorkspaceTypertGenerator(root,
|
|
77
|
+
const generator = new WorkspaceTypertGenerator(root, TSC_OWNED_DIAGNOSTICS);
|
|
78
78
|
const packages = generator.discover(faces)
|
|
79
79
|
.filter(candidate => hasTypertExport(readManifest(join(root, candidate.root)).exports))
|
|
80
80
|
.map(candidate => candidate.package);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-typert-generator",
|
|
3
3
|
"description": "TypeScript project analyzer and model-driven Typert artifact generator",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1-alpha.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"typescript": "^6.0.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@deepseek-ai/cordis": "~4.0.
|
|
39
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"
|
|
43
|
-
"@deepseek-ai/dsh-
|
|
44
|
-
"@deepseek-ai/
|
|
45
|
-
"
|
|
42
|
+
"@deepseek-ai/dsh-tool-cordis": "0.2.1-alpha.2",
|
|
43
|
+
"@deepseek-ai/dsh-typert-registry": "0.2.1-alpha.2",
|
|
44
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1",
|
|
45
|
+
"zod": "^4.4.3"
|
|
46
46
|
}
|
|
47
47
|
}
|