@nudojs/service 0.3.0 → 0.3.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 (72) hide show
  1. package/dist/index.d.ts +18 -3
  2. package/dist/index.js +80 -55
  3. package/package.json +16 -6
  4. package/CHANGELOG.md +0 -68
  5. package/src/__tests__/abs-bindings.test.ts +0 -53
  6. package/src/__tests__/abs-call-records.test.ts +0 -33
  7. package/src/__tests__/abs-calls.test.ts +0 -59
  8. package/src/__tests__/abs-module-cache.test.ts +0 -121
  9. package/src/__tests__/abs-modules-graph.test.ts +0 -100
  10. package/src/__tests__/abs-typevalue-diff.test.ts +0 -111
  11. package/src/__tests__/analyzer.test.ts +0 -880
  12. package/src/__tests__/as-replace.test.ts +0 -165
  13. package/src/__tests__/bpath-arg-provenance.test.ts +0 -104
  14. package/src/__tests__/bpath-as.test.ts +0 -54
  15. package/src/__tests__/bpath-cache-key.test.ts +0 -33
  16. package/src/__tests__/bpath-calls.test.ts +0 -55
  17. package/src/__tests__/bpath-diagnostics.test.ts +0 -78
  18. package/src/__tests__/bpath-env-modules.test.ts +0 -30
  19. package/src/__tests__/bpath-env.test.ts +0 -80
  20. package/src/__tests__/bpath-hosted-skip.test.ts +0 -71
  21. package/src/__tests__/bpath-import-default-ns.test.ts +0 -106
  22. package/src/__tests__/bpath-method-dedupe.test.ts +0 -65
  23. package/src/__tests__/bpath-method-diag.test.ts +0 -45
  24. package/src/__tests__/bpath-module-diags.test.ts +0 -101
  25. package/src/__tests__/bpath-path-env.test.ts +0 -46
  26. package/src/__tests__/bpath-reexport.test.ts +0 -131
  27. package/src/__tests__/bpath-replace.test.ts +0 -52
  28. package/src/__tests__/bpath-require.test.ts +0 -66
  29. package/src/__tests__/bpath-run.test.ts +0 -109
  30. package/src/__tests__/case-emitter.test.ts +0 -636
  31. package/src/__tests__/cjs-require.test.ts +0 -54
  32. package/src/__tests__/diagnostics.test.ts +0 -60
  33. package/src/__tests__/dts-generator.test.ts +0 -382
  34. package/src/__tests__/fn-cache-evict.test.ts +0 -56
  35. package/src/__tests__/fn-sig-impl.test.ts +0 -247
  36. package/src/__tests__/guard-generator.test.ts +0 -29
  37. package/src/__tests__/harvest-auto.test.ts +0 -43
  38. package/src/__tests__/harvest-node.test.ts +0 -24
  39. package/src/__tests__/harvest-package.test.ts +0 -38
  40. package/src/__tests__/harvest-to-abs.test.ts +0 -46
  41. package/src/__tests__/hover-intension.test.ts +0 -39
  42. package/src/__tests__/infer-json.test.ts +0 -35
  43. package/src/__tests__/integration.test.ts +0 -421
  44. package/src/__tests__/m3-intension.test.ts +0 -28
  45. package/src/__tests__/mock-seed-fingerprint.test.ts +0 -64
  46. package/src/__tests__/schema-generator.test.ts +0 -38
  47. package/src/__tests__/session-cache-evict.test.ts +0 -90
  48. package/src/__tests__/static-imports.test.ts +0 -44
  49. package/src/abs-modules-graph.ts +0 -387
  50. package/src/analysis-file-cache.ts +0 -51
  51. package/src/analyzer.ts +0 -3133
  52. package/src/bpath-diagnostics.ts +0 -283
  53. package/src/bpath-run.ts +0 -409
  54. package/src/case-emitter.ts +0 -477
  55. package/src/dts-generator.ts +0 -291
  56. package/src/env-to-abs.ts +0 -57
  57. package/src/fn-analysis-cache.ts +0 -119
  58. package/src/guard-generator.ts +0 -57
  59. package/src/harvest-auto.ts +0 -86
  60. package/src/harvest-node.ts +0 -48
  61. package/src/harvest-package.ts +0 -204
  62. package/src/harvest-to-abs.ts +0 -129
  63. package/src/index.ts +0 -150
  64. package/src/infer-json.ts +0 -137
  65. package/src/load-module.ts +0 -34
  66. package/src/mock-abs.ts +0 -275
  67. package/src/schema-generator.ts +0 -43
  68. package/src/semantic-tokens.ts +0 -216
  69. package/src/session-cache.ts +0 -50
  70. package/src/static-imports.ts +0 -241
  71. package/src/target-path.ts +0 -17
  72. package/tsconfig.json +0 -13
@@ -1,109 +0,0 @@
1
- import { describe, it, expect, afterAll } from "vitest";
2
- import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { runTranspiled, callTranspiledExport, $lit, litValue } from "@nudojs/core";
6
- import { tryBPathCall, isBPathCapable, analyzeFile } from "@nudojs/service";
7
- import { typeValueToString } from "@nudojs/core";
8
-
9
- const dirs: string[] = [];
10
- afterAll(() => {
11
- for (const d of dirs) rmSync(d, { recursive: true, force: true });
12
- });
13
-
14
- function tmpPair(math: string, main: string) {
15
- const dir = mkdtempSync(join(tmpdir(), "nudo-bpath-imp-"));
16
- dirs.push(dir);
17
- writeFileSync(join(dir, "math.js"), math, "utf-8");
18
- writeFileSync(join(dir, "main.js"), main, "utf-8");
19
- return { dir, mainPath: join(dir, "main.js"), main };
20
- }
21
-
22
- describe("B-path imported functions", () => {
23
- it("runTranspiled + injected JS exports from dep", () => {
24
- const dep = runTranspiled(`export function double(x) { return x * 2; }`);
25
- const main = runTranspiled(
26
- `import { double } from "./math.js";
27
- export function run(n) { return double(n); }`,
28
- { modules: { "./math.js": dep as never } },
29
- );
30
- const r = callTranspiledExport(main, "run", [$lit(21)]);
31
- expect(litValue(r)).toBe(42);
32
- });
33
-
34
- it("tryBPathCall via module graph (Abs absFunction dep)", () => {
35
- const { main, mainPath } = tmpPair(
36
- `export function double(x) { return x * 2; }`,
37
- `import { double } from "./math.js";
38
- export function run(n) { return double(n); }
39
- `,
40
- );
41
- const r = tryBPathCall(main, mainPath, "run", [$lit(21)]);
42
- expect(r).toBeDefined();
43
- expect(litValue(r!)).toBe(42);
44
- });
45
-
46
- it("analyzeFile case polish uses B path for relative import", () => {
47
- const { dir, main, mainPath } = tmpPair(
48
- `export function triple(x) { return x * 3; }`,
49
- `import { triple } from "./b.js";
50
- /**
51
- * @nudo:case "four" (4)
52
- */
53
- export function run(n) { return triple(n); }
54
- `.replace("./b.js", "./math.js"),
55
- );
56
- void dir;
57
- const result = analyzeFile(mainPath, main);
58
- const run = result.functions.find((f) => f.name === "run");
59
- expect(run).toBeDefined();
60
- const c = run!.cases.find((x) => x.name === "four");
61
- expect(c).toBeDefined();
62
- expect(typeValueToString(c!.result)).toBe("12");
63
- // B 路径应挂上 intension
64
- expect(c!.intension?.abs ?? c!.intension?.display).toBeTruthy();
65
- });
66
-
67
- it("isBPathCapable allows class, async, and require; rejects env", () => {
68
- expect(isBPathCapable("function f() { return 1; }")).toBe(true);
69
- expect(isBPathCapable("class A { constructor() { this.x = 1; } }")).toBe(true);
70
- expect(isBPathCapable("async function f() { return 1; }")).toBe(true);
71
- expect(isBPathCapable("const x = require('lodash');")).toBe(true);
72
- });
73
-
74
- it("object slots holding functions become first-class Abs fns (no raw JS leak)", () => {
75
- // 回归:transpile 把函数表达式编译成真实 JS 函数;流进对象槽后
76
- // 下游 absToTypeValue 读 .shape 曾裸崩(Cannot read properties of undefined (reading 'k'))
77
- const dir = mkdtempSync(join(tmpdir(), "nudo-bpath-fnslot-"));
78
- dirs.push(dir);
79
- const p = join(dir, "main.js");
80
- const src = `
81
- function helper(a, b) { return a; }
82
- export function make() {
83
- const f = (x) => x + 1;
84
- return { load: f, arrow: (y) => y, ref: helper };
85
- }
86
- `;
87
- writeFileSync(p, src, "utf-8");
88
- const r = tryBPathCall(src, p, "make", []);
89
- expect(r).toBeDefined();
90
- expect(r!.shape.k).toBe("obj");
91
- const slots = (r!.shape as { slots: Record<string, { value: { shape: { k: string; params?: string[] } } }> }).slots;
92
- expect(slots.load.value.shape.k).toBe("fn");
93
- expect(slots.arrow.value.shape.params).toEqual(["y"]);
94
- // 声明函数引用无参数名可恢复 → argN 回退(与 analyzer extractParamNames 口径一致)
95
- expect(slots.ref.value.shape.params).toEqual(["arg0", "arg1"]);
96
- });
97
- });
98
-
99
- describe("transpile import emission", () => {
100
- it("preserves relative import", async () => {
101
- const { transpile } = await import("@nudojs/core");
102
- const out = transpile(
103
- `import { double } from "./math.js";
104
- export function run(n) { return double(n); }`,
105
- );
106
- expect(out).toContain('from "./math.js"');
107
- expect(out).toContain("double");
108
- });
109
- });