@lionden/leo-compiler 0.1.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.
- package/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/abi-hash.d.ts +15 -0
- package/dist/abi-hash.d.ts.map +1 -0
- package/dist/abi-hash.js +75 -0
- package/dist/abi-hash.js.map +1 -0
- package/dist/abi-parser.d.ts +38 -0
- package/dist/abi-parser.d.ts.map +1 -0
- package/dist/abi-parser.js +513 -0
- package/dist/abi-parser.js.map +1 -0
- package/dist/abi-types.d.ts +111 -0
- package/dist/abi-types.d.ts.map +1 -0
- package/dist/abi-types.js +5 -0
- package/dist/abi-types.js.map +1 -0
- package/dist/cache.d.ts +27 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +74 -0
- package/dist/cache.js.map +1 -0
- package/dist/codegen/codegen-error.d.ts +10 -0
- package/dist/codegen/codegen-error.d.ts.map +1 -0
- package/dist/codegen/codegen-error.js +14 -0
- package/dist/codegen/codegen-error.js.map +1 -0
- package/dist/codegen/contract-wrapper.d.ts +6 -0
- package/dist/codegen/contract-wrapper.d.ts.map +1 -0
- package/dist/codegen/contract-wrapper.js +2482 -0
- package/dist/codegen/contract-wrapper.js.map +1 -0
- package/dist/codegen/type-mapper.d.ts +46 -0
- package/dist/codegen/type-mapper.d.ts.map +1 -0
- package/dist/codegen/type-mapper.js +132 -0
- package/dist/codegen/type-mapper.js.map +1 -0
- package/dist/codegen/typescript-generator.d.ts +65 -0
- package/dist/codegen/typescript-generator.d.ts.map +1 -0
- package/dist/codegen/typescript-generator.js +2076 -0
- package/dist/codegen/typescript-generator.js.map +1 -0
- package/dist/compiler.d.ts +43 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +532 -0
- package/dist/compiler.js.map +1 -0
- package/dist/dependency-resolver.d.ts +33 -0
- package/dist/dependency-resolver.d.ts.map +1 -0
- package/dist/dependency-resolver.js +142 -0
- package/dist/dependency-resolver.js.map +1 -0
- package/dist/import-parser.d.ts +17 -0
- package/dist/import-parser.d.ts.map +1 -0
- package/dist/import-parser.js +46 -0
- package/dist/import-parser.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/package-materializer.d.ts +29 -0
- package/dist/package-materializer.d.ts.map +1 -0
- package/dist/package-materializer.js +160 -0
- package/dist/package-materializer.js.map +1 -0
- package/dist/source-discovery.d.ts +24 -0
- package/dist/source-discovery.d.ts.map +1 -0
- package/dist/source-discovery.js +131 -0
- package/dist/source-discovery.js.map +1 -0
- package/dist/source-scrubber.d.ts +22 -0
- package/dist/source-scrubber.d.ts.map +1 -0
- package/dist/source-scrubber.js +71 -0
- package/dist/source-scrubber.js.map +1 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +34 -0
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DiscoveredUnit } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compute a hash of all inputs that affect compilation of a unit:
|
|
4
|
+
* - All .leo source file contents
|
|
5
|
+
* - Generated program.json content
|
|
6
|
+
* - Hashes of this unit's direct local dependencies (transitivity is automatic
|
|
7
|
+
* since each dep's hash includes its own deps)
|
|
8
|
+
* - Contents of linked network dependency .aleo files. This invalidates the
|
|
9
|
+
* compile cache only after a fresh source is linked, such as when switching
|
|
10
|
+
* network/endpoint scope or running `lionden compile --force`; same-scope
|
|
11
|
+
* on-chain updates are otherwise served from the network-dep cache.
|
|
12
|
+
*
|
|
13
|
+
* @param localDepIds - the canonical IDs of this unit's direct local dependencies
|
|
14
|
+
* @param depHashes - map of already-computed hashes (populated as units compile in topo order)
|
|
15
|
+
* @param networkDepIds - the names of this unit's direct network dependencies
|
|
16
|
+
* (e.g. "credits.aleo"). Their linked source in imports/ is hashed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function computeUnitHash(unit: DiscoveredUnit, packageDir: string, localDepIds: string[], depHashes: Map<string, string>, networkDepIds?: string[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a unit's compilation is cached (hash matches).
|
|
21
|
+
*/
|
|
22
|
+
export declare function isCached(cacheDir: string, id: string, currentHash: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Write the compilation hash to the cache.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeCache(cacheDir: string, id: string, hash: string): void;
|
|
27
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,EACpB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EAAE,EACrB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,aAAa,CAAC,EAAE,MAAM,EAAE,GACvB,MAAM,CAyCR;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAKnF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAG3E"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Compute a hash of all inputs that affect compilation of a unit:
|
|
6
|
+
* - All .leo source file contents
|
|
7
|
+
* - Generated program.json content
|
|
8
|
+
* - Hashes of this unit's direct local dependencies (transitivity is automatic
|
|
9
|
+
* since each dep's hash includes its own deps)
|
|
10
|
+
* - Contents of linked network dependency .aleo files. This invalidates the
|
|
11
|
+
* compile cache only after a fresh source is linked, such as when switching
|
|
12
|
+
* network/endpoint scope or running `lionden compile --force`; same-scope
|
|
13
|
+
* on-chain updates are otherwise served from the network-dep cache.
|
|
14
|
+
*
|
|
15
|
+
* @param localDepIds - the canonical IDs of this unit's direct local dependencies
|
|
16
|
+
* @param depHashes - map of already-computed hashes (populated as units compile in topo order)
|
|
17
|
+
* @param networkDepIds - the names of this unit's direct network dependencies
|
|
18
|
+
* (e.g. "credits.aleo"). Their linked source in imports/ is hashed.
|
|
19
|
+
*/
|
|
20
|
+
export function computeUnitHash(unit, packageDir, localDepIds, depHashes, networkDepIds) {
|
|
21
|
+
const hasher = crypto.createHash("sha256");
|
|
22
|
+
// Hash all source files (sorted for determinism)
|
|
23
|
+
for (const relPath of [...unit.allSources].sort()) {
|
|
24
|
+
const absPath = path.join(unit.sourceDir, relPath);
|
|
25
|
+
if (fs.existsSync(absPath)) {
|
|
26
|
+
hasher.update(`file:${relPath}\n`);
|
|
27
|
+
hasher.update(fs.readFileSync(absPath));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Hash program.json
|
|
31
|
+
const programJsonPath = path.join(packageDir, "program.json");
|
|
32
|
+
if (fs.existsSync(programJsonPath)) {
|
|
33
|
+
hasher.update("program.json\n");
|
|
34
|
+
hasher.update(fs.readFileSync(programJsonPath));
|
|
35
|
+
}
|
|
36
|
+
// Include only this unit's direct local dependency hashes
|
|
37
|
+
// (each dep hash already includes its own transitive deps)
|
|
38
|
+
for (const depId of [...localDepIds].sort()) {
|
|
39
|
+
const depHash = depHashes.get(depId);
|
|
40
|
+
if (depHash) {
|
|
41
|
+
hasher.update(`dep:${depId}:${depHash}\n`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Include linked network dependency source contents.
|
|
45
|
+
// These live in imports/<depName> after linkNetworkDependency().
|
|
46
|
+
if (networkDepIds) {
|
|
47
|
+
for (const depName of [...networkDepIds].sort()) {
|
|
48
|
+
const importPath = path.join(packageDir, "imports", depName);
|
|
49
|
+
if (fs.existsSync(importPath)) {
|
|
50
|
+
hasher.update(`network-dep:${depName}\n`);
|
|
51
|
+
hasher.update(fs.readFileSync(importPath));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return hasher.digest("hex");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if a unit's compilation is cached (hash matches).
|
|
59
|
+
*/
|
|
60
|
+
export function isCached(cacheDir, id, currentHash) {
|
|
61
|
+
const hashFile = path.join(cacheDir, `${id}.hash`);
|
|
62
|
+
if (!fs.existsSync(hashFile))
|
|
63
|
+
return false;
|
|
64
|
+
const storedHash = fs.readFileSync(hashFile, "utf-8").trim();
|
|
65
|
+
return storedHash === currentHash;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Write the compilation hash to the cache.
|
|
69
|
+
*/
|
|
70
|
+
export function writeCache(cacheDir, id, hash) {
|
|
71
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
72
|
+
fs.writeFileSync(path.join(cacheDir, `${id}.hash`), hash + "\n");
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAoB,EACpB,UAAkB,EAClB,WAAqB,EACrB,SAA8B,EAC9B,aAAwB;I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AAC;YAChD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAC7D,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC9B,MAAM,CAAC,MAAM,CAAC,eAAe,OAAO,IAAI,CAAC,CAAC;gBAC1C,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,EAAU,EAAE,WAAmB;IACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7D,OAAO,UAAU,KAAK,WAAW,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,EAAU,EAAE,IAAY;IACnE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen-stage error. Thrown by typechain emit and helper routing when the
|
|
3
|
+
* resolved config or ABI shape rules out a clean emission. Distinct from
|
|
4
|
+
* `CompilationError` (which represents Leo CLI failures).
|
|
5
|
+
*/
|
|
6
|
+
export declare class CodegenError extends Error {
|
|
7
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
8
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=codegen-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen-error.d.ts","sourceRoot":"","sources":["../../src/codegen/codegen-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;gBAExC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAKnE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codegen-stage error. Thrown by typechain emit and helper routing when the
|
|
3
|
+
* resolved config or ABI shape rules out a clean emission. Distinct from
|
|
4
|
+
* `CompilationError` (which represents Leo CLI failures).
|
|
5
|
+
*/
|
|
6
|
+
export class CodegenError extends Error {
|
|
7
|
+
context;
|
|
8
|
+
constructor(message, context = {}) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "CodegenError";
|
|
11
|
+
this.context = context;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=codegen-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen-error.js","sourceRoot":"","sources":["../../src/codegen/codegen-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,OAAO,CAAoC;IAEpD,YAAY,OAAe,EAAE,UAAmC,EAAE;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-wrapper.d.ts","sourceRoot":"","sources":["../../src/codegen/contract-wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QA46E4C,CAAC"}
|