@zktx.io/sui-move-builder 0.1.7 → 0.2.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/README.md +27 -3
- package/dist/full/index.cjs +28 -0
- package/dist/{index.d.cts → full/index.d.cts} +17 -3
- package/dist/{index.d.ts → full/index.d.ts} +17 -3
- package/dist/full/index.js +28 -0
- package/dist/full/sui_move_wasm.d.ts +69 -0
- package/dist/full/sui_move_wasm.js +361 -0
- package/dist/full/sui_move_wasm_bg.wasm +0 -0
- package/dist/full/sui_move_wasm_bg.wasm.d.ts +18 -0
- package/dist/lite/index.cjs +28 -0
- package/dist/lite/index.d.cts +147 -0
- package/dist/lite/index.d.ts +147 -0
- package/dist/lite/index.js +28 -0
- package/dist/lite/sui_move_wasm.d.ts +54 -0
- package/dist/{sui_move_wasm.js → lite/sui_move_wasm.js} +146 -151
- package/dist/lite/sui_move_wasm_bg.wasm +0 -0
- package/dist/{sui_move_wasm_bg.wasm.d.ts → lite/sui_move_wasm_bg.wasm.d.ts} +5 -6
- package/package.json +15 -7
- package/dist/index.cjs +0 -28
- package/dist/index.js +0 -28
- package/dist/sui_move_wasm.d.ts +0 -57
- package/dist/sui_move_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @zktx.io/sui-move-builder
|
|
2
2
|
|
|
3
|
+
> **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (tag: `testnet-v1.63.1`)
|
|
4
|
+
|
|
3
5
|
Build Move packages in web or Node.js with Sui CLI-compatible dependency resolution and compilation.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
@@ -19,6 +21,25 @@ Build Move packages in web or Node.js with Sui CLI-compatible dependency resolut
|
|
|
19
21
|
npm install @zktx.io/sui-move-builder
|
|
20
22
|
```
|
|
21
23
|
|
|
24
|
+
## Lite vs Full Version
|
|
25
|
+
|
|
26
|
+
The package comes in two variants:
|
|
27
|
+
|
|
28
|
+
1. **Full Version (Default)**: ~12MB. Includes `move-unit-test`, `sui-move-natives`, and testing capabilities.
|
|
29
|
+
2. **Lite Version**: ~5.1MB. Build-only. **Recommended for frontend applications** where testing infrastructure is not needed.
|
|
30
|
+
|
|
31
|
+
### Using the Full Version (Default)
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { initMoveCompiler, buildMovePackage, testMovePackage } from "@zktx.io/sui-move-builder";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Using the Lite Version
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { initMoveCompiler, buildMovePackage } from "@zktx.io/sui-move-builder/lite";
|
|
41
|
+
```
|
|
42
|
+
|
|
22
43
|
## Quick start (Node.js or browser)
|
|
23
44
|
|
|
24
45
|
```ts
|
|
@@ -49,6 +70,12 @@ const result = await buildMovePackage({
|
|
|
49
70
|
files,
|
|
50
71
|
// optional: bump GitHub API limits during dependency resolution
|
|
51
72
|
githubToken: process.env.GITHUB_TOKEN,
|
|
73
|
+
// optional: silence warnings from Move compiler
|
|
74
|
+
silenceWarnings: true,
|
|
75
|
+
// optional: enable test mode (include #[test_only] modules)
|
|
76
|
+
testMode: false,
|
|
77
|
+
// optional: set linting level (default: "all")
|
|
78
|
+
lintFlag: "all",
|
|
52
79
|
});
|
|
53
80
|
|
|
54
81
|
if (result.success) {
|
|
@@ -181,6 +208,3 @@ npm run serve:test # serves ./test via python -m http.server
|
|
|
181
208
|
# open http://localhost:8000/test/index.html
|
|
182
209
|
```
|
|
183
210
|
|
|
184
|
-
## Source
|
|
185
|
-
|
|
186
|
-
> **Upstream source (Sui repository):** https://github.com/MystenLabs/sui
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";var U=Object.create;var R=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var q=(d,e)=>{for(var t in e)R(d,t,{get:e[t],enumerable:!0})},N=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of z(e))!H.call(d,n)&&n!==t&&R(d,n,{get:()=>e[n],enumerable:!(s=E(e,n))||s.enumerable});return d};var J=(d,e,t)=>(t=d!=null?U(V(d)):{},N(e||!d||!d.__esModule?R(t,"default",{value:d,enumerable:!0}):t,d)),K=d=>N(R({},"__esModule",{value:!0}),d);var oe={};q(oe,{buildMovePackage:()=>ee,compileRaw:()=>re,fetchPackageFromGitHub:()=>W,getSuiMoveVersion:()=>ne,getSuiVersion:()=>se,getWasmBindings:()=>ie,initMoveCompiler:()=>Z,resolveDependencies:()=>L,testMovePackage:()=>te});module.exports=K(oe);var x=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends x{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let s=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");s&&(this.rateLimitRemaining=parseInt(s,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,s,n,o){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${c}@${s}`,l=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,r;if(this.treeCache.has(a))r=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let k=Math.pow(2,h-1)*1e3;await new Promise(v=>setTimeout(v,k))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let m=await fetch(l,{headers:y});if(this.updateRateLimit(m),!m.ok){if(m.status===403||m.status===429){let k=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${k.toLocaleTimeString()}`)}if(m.status>=500&&m.status<600&&h<3){f=new Error(`Failed to fetch tree: ${m.statusText}`);continue}throw new Error(`Failed to fetch tree: ${m.statusText}`)}r=await m.json(),this.treeCache.set(a,r);break}catch(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let g={},p=[];for(let u of r.tree){if(u.type!=="blob")continue;let f=u.path;if(n){if(!u.path.startsWith(n))continue;f=u.path.slice(n.length),f.startsWith("/")&&(f=f.slice(1))}if(!f.endsWith(".move")&&f!=="Move.toml"&&f!=="Move.lock"&&!f.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let h=`https://raw.githubusercontent.com/${i}/${c}/${s}/${u.path}`,y=this.fetchContent(h).then(m=>{m&&(g[f]=m)});p.push(y)}if(await Promise.all(p),g["Move.toml"]){let u=g["Move.toml"].trim();if(u.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!u.includes("[")&&!u.includes("=")){let f=u,h=n?`${n}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${h}`,m=await this.fetchContent(y);m&&(g["Move.toml"]=m,g[f]=m)}}return g}async fetchFile(t,s,n){let{owner:o,repo:i}=this.parseGitUrl(t);if(!o||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${o}/${i}/${s}/${n}`;return this.fetchContent(c)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",o=t.startsWith("https://api.github.com/");this.token&&(!n||o)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let c=await i.text();return this.cache.set(t,c),c}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(o=>o);if(n.length>=2){let o=n[1];return o.endsWith(".git")&&(o=o.slice(0,-4)),{owner:n[0],repo:o}}}catch{}return{owner:null,repo:null}}};function M(d){let e=!1,t="";for(let s=0;s<d.length;s++){let n=d[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return d.slice(0,s)}return d}function F(d){let e=d.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function B(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,o="",i=[];for(let c=0;c<t.length;c++){let a=t[c];if((a==='"'||a==="'")&&(!n||a===o)&&(n=!n,o=a),!n&&a===","){i.push(s),s="";continue}s+=a}s.trim()&&i.push(s);for(let c of i){let a=c.indexOf("=");if(a===-1)continue;let l=c.slice(0,a).trim(),r=c.slice(a+1).trim();e[l]=F(r)}return e}function Q(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,o="",i=0;for(let c=0;c<t.length;c++){let a=t[c];if((a==='"'||a==="'")&&(!n||a===o)&&(n=!n,o=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){s.trim()&&e.push(G(s.trim())),s="";continue}s+=a}return s.trim()&&e.push(G(s.trim())),e}function G(d){return d.startsWith("{")?B(d):F(d)}function b(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),o=[],i=0;for(;i<n.length;){let a=M(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let l=a;for(i++;i<n.length&&!l.includes("]");)l+=" "+M(n[i]).trim(),i++;i<n.length&&l.includes("[")&&!l.includes("]")&&(l+=" "+M(n[i]).trim(),i++),o.push(l)}else o.push(a),i++}function c(a,l){let r=a;for(let g of l){if(!(g in r))return;r=r[g]}return r}for(let a of o){let l=M(a).trim();if(!l)continue;let r=l.match(/^\[\[([^\]]+)\]\]$/);if(r){t=r[1].trim(),s=!0;let y=t.split("."),m=e;for(let v=0;v<y.length-1;v++){let w=y[v];w in m||(m[w]={}),m=m[w]}let k=y[y.length-1];Array.isArray(m[k])||(m[k]=[]),m[k].push({});continue}let g=l.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let p=l.indexOf("=");if(p===-1||!t)continue;let u=l.slice(0,p).trim(),f=l.slice(p+1).trim(),h;if(f.startsWith("{")?h=B(f):f.startsWith("[")?h=Q(f):h=F(f),s){let y=t.split("."),m=c(e,y);if(Array.isArray(m)&&m.length>0){let k=m[m.length-1];k[u]=h}}else{let y=t.split("."),m=e;for(let v of y)v in m||(m[v]={}),m=m[v];let k=t==="package"?u.replace(/-/g,"_"):u;m[k]=h}}return e}var D=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib","SuiSystem","Bridge"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,s){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,s=new Set,n=o=>{if(s.has(o))return;s.add(o),t.add(o);let i=this.graph.get(o);if(i)for(let c of i)n(c)};return n(e),t.delete(e),t}topologicalOrder(){if(!this.lockfileOrder.length)return this.topologicalOrderDFS().filter(i=>i!==this.root);let e=new Set,t=new Set,s=o=>{if(t.has(o))return;t.add(o),e.add(o);let i=this.graph.get(o);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let o of this.lockfileOrder)o!==this.root&&e.has(o)&&n.push(o);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let o=this.graph.get(n);if(o)for(let i of Array.from(o))s(i);t.push(n)};s(this.root);for(let n of this.packageTable.keys())s(n);return t}detectCycle(){let e=new Set,t=new Set,s=new Map,n=o=>{e.add(o),t.add(o);let i=this.graph.get(o);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let a=[c],l=o;for(;l!==c;)a.unshift(l),l=s.get(l);return a.unshift(c),a}}else{s.set(c,o);let a=n(c);if(a)return a}return t.delete(o),null};for(let o of this.packageTable.keys())if(!e.has(o)){let i=n(o);if(i)return i}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var $=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let s of t){let n=this.graph.getPackage(s);if(n)for(let[o,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(o)&&this.unifiedAddressTable.get(o)!==c||this.unifiedAddressTable.set(o,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[o,i]of this.unifiedAddressTable.entries())n[o]=i;this.packageResolvedTables.set(s.id.name,n),s.resolvedTable=n}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,s]of this.unifiedAddressTable.entries())e[t]=s;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var A=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let s=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.topologicalOrder(),o=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||o.has(i))continue;let a=e.get(i)||{},l=this.extractSourcePaths(i,a),r=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],p={name:i,isImmediate:s.has(i),sourcePaths:l,addressMapping:c.resolvedTable||{},compilerConfig:{edition:r,flavor:"sui"},moduleFormat:l.length>0?"Source":"Bytecode",edition:r,publishedIdForOutput:g};this.dependencies.push(p)}}extractSourcePaths(e,t){let s=Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move")),n=new TextEncoder,o=(i,c)=>{let a=n.encode(`/vfs/deps/${e}/${i}`),l=n.encode(`/vfs/deps/${e}/${c}`),r=Math.min(a.length,l.length);for(let g=0;g<r;g++)if(a[g]!==l[g])return a[g]-l[g];return a.length-l.length};return s.sort(o),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},o={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?o[a]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):o[a]=c}t.push({name:s.name,files:o,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let o=(t||"").split(`
|
|
2
|
+
`),i=[],c=[],a=!1,l=!1;for(let u of o){let f=u.trim();if(f.startsWith("[package]")){a=!0,l=!1;continue}if(f.startsWith("[dependencies]")){a=!1,l=!0;continue}if(f.startsWith("[")){a=!1,l=!1;continue}a&&f&&i.push(u),l&&f&&c.push(u)}let r=`[package]
|
|
3
|
+
`,g=!1,p=!1;for(let u of i)if(u.includes("name ="))r+=u+`
|
|
4
|
+
`,g=!0;else if(u.includes("version ="))r+=u+`
|
|
5
|
+
`,p=!0;else{if(u.includes("edition ="))continue;r+=u+`
|
|
6
|
+
`}g||(r+=`name = "${e}"
|
|
7
|
+
`),p||(r+=`version = "0.0.0"
|
|
8
|
+
`),r+=`edition = "${s}"
|
|
9
|
+
`,r+=`
|
|
10
|
+
[dependencies]
|
|
11
|
+
`;for(let u of c)r+=u+`
|
|
12
|
+
`;r+=`
|
|
13
|
+
[addresses]
|
|
14
|
+
`;for(let[u,f]of Object.entries(n))r+=`${u} = "${f}"
|
|
15
|
+
`;return r}};var O=class{constructor(e,t="mainnet",s=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=s}async resolve(e,t){let s=b(e),n=s.package?.name||"RootPackage",o=s.package?.edition,i=new D(n),c=await this.buildPackage(n,this.rootSource,e,t);o&&(c.manifest.edition=o);let a=c.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&c.manifest.originalId&&(c.manifest.addresses[n]=this.normalizeAddress(c.manifest.originalId)),i.addPackage(c),this.packageFiles.set(n,t);let r=await this.loadFromLockfile(i,c,t),g=Array.from(c.dependencies.keys()).filter(k=>!i.getPackage(k));(!r||g.length>0)&&await this.buildDependencyGraph(i,c);let p=i.detectCycle();if(p)throw new Error(`Dependency cycle detected: ${p.join(" \u2192 ")}`);let u=new $(i,{});await u.resolve();let f=new A(u);await f.compute(this.packageFiles);let h=this.reconstructMoveToml(s,u.getUnifiedAddressTable(),!0,o),y={...t};delete y["Move.lock"],y["Move.toml"]=h;let m=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(m)}}async buildPackage(e,t,s,n){let o=b(s),i=n["Move.lock"],c=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(s,i,c),l=a.latestId?this.normalizeAddress(a.latestId):void 0;a.error;let r={name:o.package?.name||e,version:o.package?.version||"0.0.0",edition:o.package?.edition,publishedAt:a.publishedAt,originalId:a.originalId,latestPublishedId:l,addresses:o.addresses||{},dependencies:o.dependencies||{},devDependencies:o["dev-dependencies"]},g=r.publishedAt&&r.publishedAt!=="0x0"?this.normalizeAddress(r.publishedAt):void 0,p=r.addresses[r.name],u=p?this.normalizeAddress(p):void 0;g?r.addresses[r.name]=g:u?r.addresses[r.name]=u:r.addresses[r.name]="0x0";let f=new Map;if(r.dependencies)for(let[y,m]of Object.entries(r.dependencies)){let k=this.parseDependencyInfo(m);k&&f.set(y,k)}return{id:{name:r.name,version:r.version,source:t||{type:"local"}},manifest:r,dependencies:f,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir};else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let s=e["addr-subst"]||e.addr_subst,n={};for(let[o,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[o]={type:"assign",address:i}:n[o]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){for(let[s,n]of t.dependencies.entries()){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let g=t.id.source.subdir||"",p=n.source.local,u=this.resolveRelativePath(g,p);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:u}}else continue;if(n.source.type!=="git")continue;let o=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(o)){let g=this.findPackageBySource(e,n.source);g&&e.addDependency(t.id.name,g.id.name,n);continue}this.visited.add(o);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let c=await this.fetcher.fetch(n.source.git,n.source.rev,i,`${t.id.name} -> ${s}`),a=null,l=`Move.${this.network}.toml`;for(let[g,p]of Object.entries(c))if(g.endsWith(l)){a=p;break}if(!a){for(let[g,p]of Object.entries(c))if(g.endsWith("Move.toml")){a=p;break}}if(!a)continue;let r=await this.buildPackage(s,n.source,a,c);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(r.manifest.name);if(g){let p=u=>JSON.stringify(u);throw new Error([`Conflicting versions of package '${r.manifest.name}' found`,`Existing: ${p(g)}`,`New: ${p(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
16
|
+
`))}this.packageNameCache.set(r.manifest.name,n.source)}r.manifest.publishedAt&&(r.manifest.addresses[r.manifest.name]=this.normalizeAddress(r.manifest.publishedAt)),r.manifest.edition||(r.manifest.edition="legacy"),e.addPackage(r),e.addDependency(t.id.name,r.id.name,n),this.packageFiles.set(r.id.name,c),await this.buildDependencyGraph(e,r)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s){let n=b(e),o=n.package?.published_at||n.package?.["published-at"],i=o&&o!=="0x0"?o:void 0,c=i?this.normalizeAddress(i):void 0,a=n.package?.["original-id"];if(!t||!s)return{publishedAt:c,originalId:a};let l=b(t),r,g,p;if(l.env)for(let[,u]of Object.entries(l.env)){let f=u["latest-published-id"],h=u["original-published-id"],y=u["chain-id"];if(y===s||!y){let m=f&&f!=="0x0"?this.normalizeAddress(f):void 0,k=h&&h!=="0x0"?this.normalizeAddress(h):void 0;g=m,p=k,r=m||k;break}}return!p&&r&&(p=r),r&&c&&r!==c?{error:`Conflicting 'published-at' addresses between Move.toml (${c}) and Move.lock (${r})`}:{publishedAt:p||c||r,originalId:p||a,latestId:g||r||c}}findPackageBySource(e,t){for(let s of e.getAllPackages()){let n=s.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return s}}resolveRelativePath(e,t){let s=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),o=[...s];for(let i of n)i===".."?o.length>0&&o.pop():i!=="."&&o.push(i);return o.join("/")}async computeManifestDigest(e){let s=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let o=b(n);this.lockfileVersion=o.move?.version;let i=o.move?.version;return i===3?await this.loadFromLockfileV3(e,o,t):i&&i>=4?await this.loadFromLockfileV4(e,o,s):await this.loadFromLockfileV0(e,o,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let o=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(r=>r.name||r.id||r).filter(Boolean):[],i=n.map(r=>r.name||r.id).filter(Boolean),c=[...o,...i.filter(r=>!o.includes(r))],a=new Map,l=new Map;for(let r of n){let g=r.id||r.name,p=r.source;if(!g||!p)continue;let u=null;if(p.git&&p.rev)u={type:"git",git:p.git,rev:p.rev,subdir:p.subdir};else if(p.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",p.local);u={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;let f=await this.fetcher.fetch(u.git,u.rev,u.subdir,`lockfile:${g}`);if(Object.keys(f).length===0)continue;let h=f["Move.toml"];if(!h)continue;let y=await this.buildPackage(g,u,h,f);a.set(g,y),l.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,f),e.addPackage(y)}c.length&&e.setLockfileOrder(c);for(let r of n){let g=r.id||r.name,p=a.get(g);if(!p)continue;let u=r.dependencies;if(u&&Array.isArray(u))for(let f of u){let h=f.id||f.name,y=a.get(h)||l.get(h);if(y){let m={source:y.id.source};e.addDependency(p.id.name,y.id.name,m)}}}for(let r of s.dependencies.keys()){let g=l.get(r);if(g){let p=s.dependencies.get(r);e.addDependency(s.id.name,g.id.name,p)}}return a.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let o=new Map,i=new Map,c=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let l=a.id,r=a.source;c.push(l);let g=null;if(r?.git&&r.rev)g={type:"git",git:r.git,rev:r.rev,subdir:r.subdir};else if(r?.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",r.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let p=await this.fetcher.fetch(r.git,r.rev,r.subdir,`lockfile:${l}`);if(Object.keys(p).length===0)continue;let u=p["Move.toml"];if(!u)continue;let f=await this.buildPackage(l,g,u,p);o.set(l,f),this.packageFiles.set(f.manifest.name,p),e.addPackage(f)}e.setLockfileOrder(c);for(let a of n){let l=a.id,r=o.get(l);if(!r)continue;let g=a.dependencies;if(!(!g||!Array.isArray(g)))for(let p of g){let u=p.id,f=o.get(u);if(!f){let h=i.get(u);if(h?.source?.local&&r.id.source.type==="git"){let y=this.resolveRelativePath(r.id.source.subdir||"",h.source.local),m={type:"git",git:r.id.source.git,rev:r.id.source.rev,subdir:y},k=await this.fetcher.fetch(m.git,m.rev,m.subdir,`lockfile:${u}`),v=k["Move.toml"];if(v){let w=await this.buildPackage(u,m,v,k);o.set(u,w),this.packageFiles.set(w.manifest.name,k),e.addPackage(w),f=w}}}if(f){let h={source:f.id.source};e.addDependency(r.id.name,f.id.name,h)}}}for(let a of s.dependencies.keys()){let l=o.get(a);if(l){let r=s.dependencies.get(a);e.addDependency(s.id.name,l.id.name,r)}}return!0}async loadFromLockfileV4(e,t,s){let n=t.pinned?.[this.network];if(!n)return!1;let o=rootFiles["Move.toml"];if(o&&t.move?.manifest_digest&&await this.computeManifestDigest(o)!==t.move.manifest_digest)return!1;let i=new Map,c=new Map,a=[];for(let[l,r]of Object.entries(n)){a.push(l);let g=this.lockfileSourceToDependencySource(r.source);if(!g)continue;let p=await this.fetchFromSource(g);if(!p)return!1;let u=p["Move.toml"];if(!u||r["manifest-digest"]&&await this.computeManifestDigest(u)!==r["manifest-digest"])return!1;let f=await this.buildPackage(l,g,u,p);i.set(l,f),c.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,p),(g.type!=="local"||!("root"in r.source))&&e.addPackage(f)}a.length>0&&e.setLockfileOrder(a);for(let[l,r]of Object.entries(n)){let g=i.get(l);if(g&&r.deps)for(let[p,u]of Object.entries(r.deps)){let f=i.get(u);if(f){let h=g.dependencies.get(p);h&&e.addDependency(g.id.name,f.id.name,h)}}}for(let l of rootPackage.dependencies.keys()){let r=c.get(l)||i.get(l);if(r){let g=rootPackage.dependencies.get(l);e.addDependency(rootPackage.id.name,r.id.name,g)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir,"lockfile:dependency")}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
|
|
17
|
+
name = "${e.package.name}"
|
|
18
|
+
version = "${e.package.version}"
|
|
19
|
+
`,c=n||e.package.edition;if(c&&(i+=`edition = "${c}"
|
|
20
|
+
`),i+=`
|
|
21
|
+
[dependencies]
|
|
22
|
+
`,e.dependencies)for(let[a,l]of Object.entries(e.dependencies)){let r=l;r.local?i+=`${a} = { local = "${r.local}" }
|
|
23
|
+
`:r.git&&r.rev&&(r.subdir?i+=`${a} = { git = "${r.git}", subdir = "${r.subdir}", rev = "${r.rev}" }
|
|
24
|
+
`:i+=`${a} = { git = "${r.git}", rev = "${r.rev}" }
|
|
25
|
+
`)}i+=`
|
|
26
|
+
[addresses]
|
|
27
|
+
`;for(let[a,l]of Object.entries(t))i+=`${a} = "${l}"
|
|
28
|
+
`;return i}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",DeepBook:"crates/sui-framework/packages/deepbook",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function C(d,e,t,s="mainnet",n){return new O(t,s,n||null).resolve(d,e)}function X(d){try{let e=new URL(d);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let s=t[0],n=t[1],o="main",i;return t.length>=4&&t[2]==="tree"&&(o=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:o,subdir:i}}catch{return null}}async function W(d,e){let t=X(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let s=e?.fetcher||new S(e?.githubToken),n=e?.includeLock!==!1,o=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(o,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:o,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":c,...a}=i;return a}return i}var T;async function P(d){return T||(T=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),T}function I(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function _(d){if(typeof d!="object"||d===null)throw new Error("Unexpected compile result shape from wasm");let e=d;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function Y(d){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,o=[];for(let i=0;i<n.length;i+=2){let c=parseInt(n.slice(i,i+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");o.push(c)}return o};try{let t=JSON.parse(d);if(!t.modules||!t.dependencies||!t.digest)throw new Error("missing fields in compiler output");let s=typeof t.digest=="string"?e(t.digest):Array.from(t.digest);return{modules:t.modules,dependencies:t.dependencies,digest:s}}catch(t){return I(t)}}function j(d){try{let e=JSON.parse(d);for(let t of e){let s=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let o=b(n[1]);return o.addresses&&o.addresses[t.name]||o.package?.published_at||o.package?.["published-at"]})()}}catch{}}async function Z(d){await P(d?.wasm)}async function L(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,s=await C(e,{...d.files,"Move.toml":e},new S(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function ee(d){try{if(d.files["Move.lock"]&&d.files["Move.toml"])try{let c=b(d.files["Move.lock"]),a=d.network||"mainnet",l=c.env?.[a]?.["original-published-id"];if(l){let g=b(d.files["Move.toml"]).package?.name;if(g){let p=new Set([g,g.toLowerCase()]),u=d.files["Move.toml"];for(let f of p){let h=new RegExp(`(^|[\\s])(${f}\\s*=\\s*)"0x0"`,"m");if(h.test(u)){u=u.replace(h,`$1$2"${l}"`);break}}d.files["Move.toml"]=u}}}catch{}let e=d.resolvedDependencies?d.resolvedDependencies:await L(d),t=await P(d.wasm);j(e.dependencies);let s=t.compile(e.files,e.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag})),n=_(s),o=n.success(),i=n.output();return o?Y(i):I(i)}catch(e){return I(e)}}async function te(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await L(d),t=await P(d.wasm);j(e.dependencies);let s=d.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof s.passed=="boolean"&&typeof s.output=="string")return{passed:s.passed,output:s.output};let n=typeof s.passed=="function"?s.passed():s.passed,o=typeof s.output=="function"?s.output():s.output;return{passed:n,output:o}}catch(e){return I(e)}}async function ne(d){return(await P(d?.wasm)).sui_move_version()}async function se(d){return(await P(d?.wasm)).sui_version()}async function ie(d){return P(d?.wasm)}async function re(d,e,t){let s=await P(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(d,e,!0):s.compile(d,e,JSON.stringify({silenceWarnings:!1})),o=_(n);return{success:o.success(),output:o.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
|
|
@@ -69,7 +69,7 @@ interface BuildInput {
|
|
|
69
69
|
/** Virtual file system contents. Keys are paths (e.g. "Move.toml", "sources/Module.move"). */
|
|
70
70
|
files: Record<string, string>;
|
|
71
71
|
/** Optional custom URL for the wasm binary. Defaults to bundled wasm next to this module. */
|
|
72
|
-
wasm?: string | URL;
|
|
72
|
+
wasm?: string | URL | BufferSource;
|
|
73
73
|
/** Optional hint for the root package git source (enables resolving local deps from Move.lock). */
|
|
74
74
|
rootGit?: {
|
|
75
75
|
git: string;
|
|
@@ -84,6 +84,12 @@ interface BuildInput {
|
|
|
84
84
|
network?: "mainnet" | "testnet" | "devnet";
|
|
85
85
|
/** Optional pre-resolved dependencies. If provided, dependency resolution will be skipped. */
|
|
86
86
|
resolvedDependencies?: ResolvedDependencies;
|
|
87
|
+
/** Use this option to silence warnings. */
|
|
88
|
+
silenceWarnings?: boolean;
|
|
89
|
+
/** Use this option to enable test mode (includes #[test_only] modules). */
|
|
90
|
+
testMode?: boolean;
|
|
91
|
+
/** Use this option to specify lint level (e.g. "all", "none"). */
|
|
92
|
+
lintFlag?: string;
|
|
87
93
|
}
|
|
88
94
|
interface BuildSuccess {
|
|
89
95
|
/** Base64-encoded bytecode modules. */
|
|
@@ -99,7 +105,7 @@ interface BuildFailure {
|
|
|
99
105
|
type WasmModule = typeof __sui_move_wasm_js;
|
|
100
106
|
/** Initialize the wasm module (idempotent). Provide a custom wasm URL if hosting separately. */
|
|
101
107
|
declare function initMoveCompiler(options?: {
|
|
102
|
-
wasm?: string | URL;
|
|
108
|
+
wasm?: string | URL | BufferSource;
|
|
103
109
|
}): Promise<void>;
|
|
104
110
|
/**
|
|
105
111
|
* Resolve dependencies for a Move package without compiling.
|
|
@@ -108,6 +114,14 @@ declare function initMoveCompiler(options?: {
|
|
|
108
114
|
declare function resolveDependencies(input: Omit<BuildInput, "resolvedDependencies">): Promise<ResolvedDependencies>;
|
|
109
115
|
/** Compile a Move package in memory using the bundled Move compiler wasm. */
|
|
110
116
|
declare function buildMovePackage(input: BuildInput): Promise<BuildSuccess | BuildFailure>;
|
|
117
|
+
interface TestSuccess {
|
|
118
|
+
/** Whether all tests passed. */
|
|
119
|
+
passed: boolean;
|
|
120
|
+
/** Output from the test runner (stdout). */
|
|
121
|
+
output: string;
|
|
122
|
+
}
|
|
123
|
+
/** Compile and run tests for a Move package in memory. */
|
|
124
|
+
declare function testMovePackage(input: BuildInput): Promise<TestSuccess | BuildFailure>;
|
|
111
125
|
/** Sui Move version baked into the wasm (e.g. from Cargo.lock). */
|
|
112
126
|
declare function getSuiMoveVersion(options?: {
|
|
113
127
|
wasm?: string | URL;
|
|
@@ -130,4 +144,4 @@ declare function compileRaw(filesJson: string, depsJson: string, options?: {
|
|
|
130
144
|
}>;
|
|
131
145
|
type BuildResult = BuildSuccess | BuildFailure;
|
|
132
146
|
|
|
133
|
-
export { type BuildFailure, type BuildInput, type BuildResult, type BuildSuccess, type ResolvedDependencies, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies };
|
|
147
|
+
export { type BuildFailure, type BuildInput, type BuildResult, type BuildSuccess, type ResolvedDependencies, type TestSuccess, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies, testMovePackage };
|
|
@@ -69,7 +69,7 @@ interface BuildInput {
|
|
|
69
69
|
/** Virtual file system contents. Keys are paths (e.g. "Move.toml", "sources/Module.move"). */
|
|
70
70
|
files: Record<string, string>;
|
|
71
71
|
/** Optional custom URL for the wasm binary. Defaults to bundled wasm next to this module. */
|
|
72
|
-
wasm?: string | URL;
|
|
72
|
+
wasm?: string | URL | BufferSource;
|
|
73
73
|
/** Optional hint for the root package git source (enables resolving local deps from Move.lock). */
|
|
74
74
|
rootGit?: {
|
|
75
75
|
git: string;
|
|
@@ -84,6 +84,12 @@ interface BuildInput {
|
|
|
84
84
|
network?: "mainnet" | "testnet" | "devnet";
|
|
85
85
|
/** Optional pre-resolved dependencies. If provided, dependency resolution will be skipped. */
|
|
86
86
|
resolvedDependencies?: ResolvedDependencies;
|
|
87
|
+
/** Use this option to silence warnings. */
|
|
88
|
+
silenceWarnings?: boolean;
|
|
89
|
+
/** Use this option to enable test mode (includes #[test_only] modules). */
|
|
90
|
+
testMode?: boolean;
|
|
91
|
+
/** Use this option to specify lint level (e.g. "all", "none"). */
|
|
92
|
+
lintFlag?: string;
|
|
87
93
|
}
|
|
88
94
|
interface BuildSuccess {
|
|
89
95
|
/** Base64-encoded bytecode modules. */
|
|
@@ -99,7 +105,7 @@ interface BuildFailure {
|
|
|
99
105
|
type WasmModule = typeof __sui_move_wasm_js;
|
|
100
106
|
/** Initialize the wasm module (idempotent). Provide a custom wasm URL if hosting separately. */
|
|
101
107
|
declare function initMoveCompiler(options?: {
|
|
102
|
-
wasm?: string | URL;
|
|
108
|
+
wasm?: string | URL | BufferSource;
|
|
103
109
|
}): Promise<void>;
|
|
104
110
|
/**
|
|
105
111
|
* Resolve dependencies for a Move package without compiling.
|
|
@@ -108,6 +114,14 @@ declare function initMoveCompiler(options?: {
|
|
|
108
114
|
declare function resolveDependencies(input: Omit<BuildInput, "resolvedDependencies">): Promise<ResolvedDependencies>;
|
|
109
115
|
/** Compile a Move package in memory using the bundled Move compiler wasm. */
|
|
110
116
|
declare function buildMovePackage(input: BuildInput): Promise<BuildSuccess | BuildFailure>;
|
|
117
|
+
interface TestSuccess {
|
|
118
|
+
/** Whether all tests passed. */
|
|
119
|
+
passed: boolean;
|
|
120
|
+
/** Output from the test runner (stdout). */
|
|
121
|
+
output: string;
|
|
122
|
+
}
|
|
123
|
+
/** Compile and run tests for a Move package in memory. */
|
|
124
|
+
declare function testMovePackage(input: BuildInput): Promise<TestSuccess | BuildFailure>;
|
|
111
125
|
/** Sui Move version baked into the wasm (e.g. from Cargo.lock). */
|
|
112
126
|
declare function getSuiMoveVersion(options?: {
|
|
113
127
|
wasm?: string | URL;
|
|
@@ -130,4 +144,4 @@ declare function compileRaw(filesJson: string, depsJson: string, options?: {
|
|
|
130
144
|
}>;
|
|
131
145
|
type BuildResult = BuildSuccess | BuildFailure;
|
|
132
146
|
|
|
133
|
-
export { type BuildFailure, type BuildInput, type BuildResult, type BuildSuccess, type ResolvedDependencies, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies };
|
|
147
|
+
export { type BuildFailure, type BuildInput, type BuildResult, type BuildSuccess, type ResolvedDependencies, type TestSuccess, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies, testMovePackage };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var I=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends I{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let s=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");s&&(this.rateLimitRemaining=parseInt(s,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,s,n,o){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${c}@${s}`,l=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,r;if(this.treeCache.has(a))r=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let k=Math.pow(2,h-1)*1e3;await new Promise(v=>setTimeout(v,k))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let m=await fetch(l,{headers:y});if(this.updateRateLimit(m),!m.ok){if(m.status===403||m.status===429){let k=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${k.toLocaleTimeString()}`)}if(m.status>=500&&m.status<600&&h<3){f=new Error(`Failed to fetch tree: ${m.statusText}`);continue}throw new Error(`Failed to fetch tree: ${m.statusText}`)}r=await m.json(),this.treeCache.set(a,r);break}catch(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let g={},p=[];for(let u of r.tree){if(u.type!=="blob")continue;let f=u.path;if(n){if(!u.path.startsWith(n))continue;f=u.path.slice(n.length),f.startsWith("/")&&(f=f.slice(1))}if(!f.endsWith(".move")&&f!=="Move.toml"&&f!=="Move.lock"&&!f.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let h=`https://raw.githubusercontent.com/${i}/${c}/${s}/${u.path}`,y=this.fetchContent(h).then(m=>{m&&(g[f]=m)});p.push(y)}if(await Promise.all(p),g["Move.toml"]){let u=g["Move.toml"].trim();if(u.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!u.includes("[")&&!u.includes("=")){let f=u,h=n?`${n}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${h}`,m=await this.fetchContent(y);m&&(g["Move.toml"]=m,g[f]=m)}}return g}async fetchFile(t,s,n){let{owner:o,repo:i}=this.parseGitUrl(t);if(!o||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${o}/${i}/${s}/${n}`;return this.fetchContent(c)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",o=t.startsWith("https://api.github.com/");this.token&&(!n||o)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let c=await i.text();return this.cache.set(t,c),c}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(o=>o);if(n.length>=2){let o=n[1];return o.endsWith(".git")&&(o=o.slice(0,-4)),{owner:n[0],repo:o}}}catch{}return{owner:null,repo:null}}};function R(d){let e=!1,t="";for(let s=0;s<d.length;s++){let n=d[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return d.slice(0,s)}return d}function x(d){let e=d.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function L(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,o="",i=[];for(let c=0;c<t.length;c++){let a=t[c];if((a==='"'||a==="'")&&(!n||a===o)&&(n=!n,o=a),!n&&a===","){i.push(s),s="";continue}s+=a}s.trim()&&i.push(s);for(let c of i){let a=c.indexOf("=");if(a===-1)continue;let l=c.slice(0,a).trim(),r=c.slice(a+1).trim();e[l]=x(r)}return e}function W(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,o="",i=0;for(let c=0;c<t.length;c++){let a=t[c];if((a==='"'||a==="'")&&(!n||a===o)&&(n=!n,o=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){s.trim()&&e.push(T(s.trim())),s="";continue}s+=a}return s.trim()&&e.push(T(s.trim())),e}function T(d){return d.startsWith("{")?L(d):x(d)}function b(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),o=[],i=0;for(;i<n.length;){let a=R(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let l=a;for(i++;i<n.length&&!l.includes("]");)l+=" "+R(n[i]).trim(),i++;i<n.length&&l.includes("[")&&!l.includes("]")&&(l+=" "+R(n[i]).trim(),i++),o.push(l)}else o.push(a),i++}function c(a,l){let r=a;for(let g of l){if(!(g in r))return;r=r[g]}return r}for(let a of o){let l=R(a).trim();if(!l)continue;let r=l.match(/^\[\[([^\]]+)\]\]$/);if(r){t=r[1].trim(),s=!0;let y=t.split("."),m=e;for(let v=0;v<y.length-1;v++){let w=y[v];w in m||(m[w]={}),m=m[w]}let k=y[y.length-1];Array.isArray(m[k])||(m[k]=[]),m[k].push({});continue}let g=l.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let p=l.indexOf("=");if(p===-1||!t)continue;let u=l.slice(0,p).trim(),f=l.slice(p+1).trim(),h;if(f.startsWith("{")?h=L(f):f.startsWith("[")?h=W(f):h=x(f),s){let y=t.split("."),m=c(e,y);if(Array.isArray(m)&&m.length>0){let k=m[m.length-1];k[u]=h}}else{let y=t.split("."),m=e;for(let v of y)v in m||(m[v]={}),m=m[v];let k=t==="package"?u.replace(/-/g,"_"):u;m[k]=h}}return e}var M=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib","SuiSystem","Bridge"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,s){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,s=new Set,n=o=>{if(s.has(o))return;s.add(o),t.add(o);let i=this.graph.get(o);if(i)for(let c of i)n(c)};return n(e),t.delete(e),t}topologicalOrder(){if(!this.lockfileOrder.length)return this.topologicalOrderDFS().filter(i=>i!==this.root);let e=new Set,t=new Set,s=o=>{if(t.has(o))return;t.add(o),e.add(o);let i=this.graph.get(o);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let o of this.lockfileOrder)o!==this.root&&e.has(o)&&n.push(o);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let o=this.graph.get(n);if(o)for(let i of Array.from(o))s(i);t.push(n)};s(this.root);for(let n of this.packageTable.keys())s(n);return t}detectCycle(){let e=new Set,t=new Set,s=new Map,n=o=>{e.add(o),t.add(o);let i=this.graph.get(o);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let a=[c],l=o;for(;l!==c;)a.unshift(l),l=s.get(l);return a.unshift(c),a}}else{s.set(c,o);let a=n(c);if(a)return a}return t.delete(o),null};for(let o of this.packageTable.keys())if(!e.has(o)){let i=n(o);if(i)return i}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var D=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let s of t){let n=this.graph.getPackage(s);if(n)for(let[o,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(o)&&this.unifiedAddressTable.get(o)!==c||this.unifiedAddressTable.set(o,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[o,i]of this.unifiedAddressTable.entries())n[o]=i;this.packageResolvedTables.set(s.id.name,n),s.resolvedTable=n}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,s]of this.unifiedAddressTable.entries())e[t]=s;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var $=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let s=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.topologicalOrder(),o=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||o.has(i))continue;let a=e.get(i)||{},l=this.extractSourcePaths(i,a),r=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],p={name:i,isImmediate:s.has(i),sourcePaths:l,addressMapping:c.resolvedTable||{},compilerConfig:{edition:r,flavor:"sui"},moduleFormat:l.length>0?"Source":"Bytecode",edition:r,publishedIdForOutput:g};this.dependencies.push(p)}}extractSourcePaths(e,t){let s=Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move")),n=new TextEncoder,o=(i,c)=>{let a=n.encode(`/vfs/deps/${e}/${i}`),l=n.encode(`/vfs/deps/${e}/${c}`),r=Math.min(a.length,l.length);for(let g=0;g<r;g++)if(a[g]!==l[g])return a[g]-l[g];return a.length-l.length};return s.sort(o),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},o={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?o[a]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):o[a]=c}t.push({name:s.name,files:o,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let o=(t||"").split(`
|
|
2
|
+
`),i=[],c=[],a=!1,l=!1;for(let u of o){let f=u.trim();if(f.startsWith("[package]")){a=!0,l=!1;continue}if(f.startsWith("[dependencies]")){a=!1,l=!0;continue}if(f.startsWith("[")){a=!1,l=!1;continue}a&&f&&i.push(u),l&&f&&c.push(u)}let r=`[package]
|
|
3
|
+
`,g=!1,p=!1;for(let u of i)if(u.includes("name ="))r+=u+`
|
|
4
|
+
`,g=!0;else if(u.includes("version ="))r+=u+`
|
|
5
|
+
`,p=!0;else{if(u.includes("edition ="))continue;r+=u+`
|
|
6
|
+
`}g||(r+=`name = "${e}"
|
|
7
|
+
`),p||(r+=`version = "0.0.0"
|
|
8
|
+
`),r+=`edition = "${s}"
|
|
9
|
+
`,r+=`
|
|
10
|
+
[dependencies]
|
|
11
|
+
`;for(let u of c)r+=u+`
|
|
12
|
+
`;r+=`
|
|
13
|
+
[addresses]
|
|
14
|
+
`;for(let[u,f]of Object.entries(n))r+=`${u} = "${f}"
|
|
15
|
+
`;return r}};var F=class{constructor(e,t="mainnet",s=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=s}async resolve(e,t){let s=b(e),n=s.package?.name||"RootPackage",o=s.package?.edition,i=new M(n),c=await this.buildPackage(n,this.rootSource,e,t);o&&(c.manifest.edition=o);let a=c.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&c.manifest.originalId&&(c.manifest.addresses[n]=this.normalizeAddress(c.manifest.originalId)),i.addPackage(c),this.packageFiles.set(n,t);let r=await this.loadFromLockfile(i,c,t),g=Array.from(c.dependencies.keys()).filter(k=>!i.getPackage(k));(!r||g.length>0)&&await this.buildDependencyGraph(i,c);let p=i.detectCycle();if(p)throw new Error(`Dependency cycle detected: ${p.join(" \u2192 ")}`);let u=new D(i,{});await u.resolve();let f=new $(u);await f.compute(this.packageFiles);let h=this.reconstructMoveToml(s,u.getUnifiedAddressTable(),!0,o),y={...t};delete y["Move.lock"],y["Move.toml"]=h;let m=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(m)}}async buildPackage(e,t,s,n){let o=b(s),i=n["Move.lock"],c=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(s,i,c),l=a.latestId?this.normalizeAddress(a.latestId):void 0;a.error;let r={name:o.package?.name||e,version:o.package?.version||"0.0.0",edition:o.package?.edition,publishedAt:a.publishedAt,originalId:a.originalId,latestPublishedId:l,addresses:o.addresses||{},dependencies:o.dependencies||{},devDependencies:o["dev-dependencies"]},g=r.publishedAt&&r.publishedAt!=="0x0"?this.normalizeAddress(r.publishedAt):void 0,p=r.addresses[r.name],u=p?this.normalizeAddress(p):void 0;g?r.addresses[r.name]=g:u?r.addresses[r.name]=u:r.addresses[r.name]="0x0";let f=new Map;if(r.dependencies)for(let[y,m]of Object.entries(r.dependencies)){let k=this.parseDependencyInfo(m);k&&f.set(y,k)}return{id:{name:r.name,version:r.version,source:t||{type:"local"}},manifest:r,dependencies:f,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir};else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let s=e["addr-subst"]||e.addr_subst,n={};for(let[o,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[o]={type:"assign",address:i}:n[o]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){for(let[s,n]of t.dependencies.entries()){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let g=t.id.source.subdir||"",p=n.source.local,u=this.resolveRelativePath(g,p);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:u}}else continue;if(n.source.type!=="git")continue;let o=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(o)){let g=this.findPackageBySource(e,n.source);g&&e.addDependency(t.id.name,g.id.name,n);continue}this.visited.add(o);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let c=await this.fetcher.fetch(n.source.git,n.source.rev,i,`${t.id.name} -> ${s}`),a=null,l=`Move.${this.network}.toml`;for(let[g,p]of Object.entries(c))if(g.endsWith(l)){a=p;break}if(!a){for(let[g,p]of Object.entries(c))if(g.endsWith("Move.toml")){a=p;break}}if(!a)continue;let r=await this.buildPackage(s,n.source,a,c);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(r.manifest.name);if(g){let p=u=>JSON.stringify(u);throw new Error([`Conflicting versions of package '${r.manifest.name}' found`,`Existing: ${p(g)}`,`New: ${p(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
16
|
+
`))}this.packageNameCache.set(r.manifest.name,n.source)}r.manifest.publishedAt&&(r.manifest.addresses[r.manifest.name]=this.normalizeAddress(r.manifest.publishedAt)),r.manifest.edition||(r.manifest.edition="legacy"),e.addPackage(r),e.addDependency(t.id.name,r.id.name,n),this.packageFiles.set(r.id.name,c),await this.buildDependencyGraph(e,r)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s){let n=b(e),o=n.package?.published_at||n.package?.["published-at"],i=o&&o!=="0x0"?o:void 0,c=i?this.normalizeAddress(i):void 0,a=n.package?.["original-id"];if(!t||!s)return{publishedAt:c,originalId:a};let l=b(t),r,g,p;if(l.env)for(let[,u]of Object.entries(l.env)){let f=u["latest-published-id"],h=u["original-published-id"],y=u["chain-id"];if(y===s||!y){let m=f&&f!=="0x0"?this.normalizeAddress(f):void 0,k=h&&h!=="0x0"?this.normalizeAddress(h):void 0;g=m,p=k,r=m||k;break}}return!p&&r&&(p=r),r&&c&&r!==c?{error:`Conflicting 'published-at' addresses between Move.toml (${c}) and Move.lock (${r})`}:{publishedAt:p||c||r,originalId:p||a,latestId:g||r||c}}findPackageBySource(e,t){for(let s of e.getAllPackages()){let n=s.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return s}}resolveRelativePath(e,t){let s=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),o=[...s];for(let i of n)i===".."?o.length>0&&o.pop():i!=="."&&o.push(i);return o.join("/")}async computeManifestDigest(e){let s=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let o=b(n);this.lockfileVersion=o.move?.version;let i=o.move?.version;return i===3?await this.loadFromLockfileV3(e,o,t):i&&i>=4?await this.loadFromLockfileV4(e,o,s):await this.loadFromLockfileV0(e,o,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let o=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(r=>r.name||r.id||r).filter(Boolean):[],i=n.map(r=>r.name||r.id).filter(Boolean),c=[...o,...i.filter(r=>!o.includes(r))],a=new Map,l=new Map;for(let r of n){let g=r.id||r.name,p=r.source;if(!g||!p)continue;let u=null;if(p.git&&p.rev)u={type:"git",git:p.git,rev:p.rev,subdir:p.subdir};else if(p.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",p.local);u={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;let f=await this.fetcher.fetch(u.git,u.rev,u.subdir,`lockfile:${g}`);if(Object.keys(f).length===0)continue;let h=f["Move.toml"];if(!h)continue;let y=await this.buildPackage(g,u,h,f);a.set(g,y),l.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,f),e.addPackage(y)}c.length&&e.setLockfileOrder(c);for(let r of n){let g=r.id||r.name,p=a.get(g);if(!p)continue;let u=r.dependencies;if(u&&Array.isArray(u))for(let f of u){let h=f.id||f.name,y=a.get(h)||l.get(h);if(y){let m={source:y.id.source};e.addDependency(p.id.name,y.id.name,m)}}}for(let r of s.dependencies.keys()){let g=l.get(r);if(g){let p=s.dependencies.get(r);e.addDependency(s.id.name,g.id.name,p)}}return a.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let o=new Map,i=new Map,c=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let l=a.id,r=a.source;c.push(l);let g=null;if(r?.git&&r.rev)g={type:"git",git:r.git,rev:r.rev,subdir:r.subdir};else if(r?.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",r.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let p=await this.fetcher.fetch(r.git,r.rev,r.subdir,`lockfile:${l}`);if(Object.keys(p).length===0)continue;let u=p["Move.toml"];if(!u)continue;let f=await this.buildPackage(l,g,u,p);o.set(l,f),this.packageFiles.set(f.manifest.name,p),e.addPackage(f)}e.setLockfileOrder(c);for(let a of n){let l=a.id,r=o.get(l);if(!r)continue;let g=a.dependencies;if(!(!g||!Array.isArray(g)))for(let p of g){let u=p.id,f=o.get(u);if(!f){let h=i.get(u);if(h?.source?.local&&r.id.source.type==="git"){let y=this.resolveRelativePath(r.id.source.subdir||"",h.source.local),m={type:"git",git:r.id.source.git,rev:r.id.source.rev,subdir:y},k=await this.fetcher.fetch(m.git,m.rev,m.subdir,`lockfile:${u}`),v=k["Move.toml"];if(v){let w=await this.buildPackage(u,m,v,k);o.set(u,w),this.packageFiles.set(w.manifest.name,k),e.addPackage(w),f=w}}}if(f){let h={source:f.id.source};e.addDependency(r.id.name,f.id.name,h)}}}for(let a of s.dependencies.keys()){let l=o.get(a);if(l){let r=s.dependencies.get(a);e.addDependency(s.id.name,l.id.name,r)}}return!0}async loadFromLockfileV4(e,t,s){let n=t.pinned?.[this.network];if(!n)return!1;let o=rootFiles["Move.toml"];if(o&&t.move?.manifest_digest&&await this.computeManifestDigest(o)!==t.move.manifest_digest)return!1;let i=new Map,c=new Map,a=[];for(let[l,r]of Object.entries(n)){a.push(l);let g=this.lockfileSourceToDependencySource(r.source);if(!g)continue;let p=await this.fetchFromSource(g);if(!p)return!1;let u=p["Move.toml"];if(!u||r["manifest-digest"]&&await this.computeManifestDigest(u)!==r["manifest-digest"])return!1;let f=await this.buildPackage(l,g,u,p);i.set(l,f),c.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,p),(g.type!=="local"||!("root"in r.source))&&e.addPackage(f)}a.length>0&&e.setLockfileOrder(a);for(let[l,r]of Object.entries(n)){let g=i.get(l);if(g&&r.deps)for(let[p,u]of Object.entries(r.deps)){let f=i.get(u);if(f){let h=g.dependencies.get(p);h&&e.addDependency(g.id.name,f.id.name,h)}}}for(let l of rootPackage.dependencies.keys()){let r=c.get(l)||i.get(l);if(r){let g=rootPackage.dependencies.get(l);e.addDependency(rootPackage.id.name,r.id.name,g)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir,"lockfile:dependency")}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
|
|
17
|
+
name = "${e.package.name}"
|
|
18
|
+
version = "${e.package.version}"
|
|
19
|
+
`,c=n||e.package.edition;if(c&&(i+=`edition = "${c}"
|
|
20
|
+
`),i+=`
|
|
21
|
+
[dependencies]
|
|
22
|
+
`,e.dependencies)for(let[a,l]of Object.entries(e.dependencies)){let r=l;r.local?i+=`${a} = { local = "${r.local}" }
|
|
23
|
+
`:r.git&&r.rev&&(r.subdir?i+=`${a} = { git = "${r.git}", subdir = "${r.subdir}", rev = "${r.rev}" }
|
|
24
|
+
`:i+=`${a} = { git = "${r.git}", rev = "${r.rev}" }
|
|
25
|
+
`)}i+=`
|
|
26
|
+
[addresses]
|
|
27
|
+
`;for(let[a,l]of Object.entries(t))i+=`${a} = "${l}"
|
|
28
|
+
`;return i}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",DeepBook:"crates/sui-framework/packages/deepbook",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function N(d,e,t,s="mainnet",n){return new F(t,s,n||null).resolve(d,e)}function _(d){try{let e=new URL(d);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let s=t[0],n=t[1],o="main",i;return t.length>=4&&t[2]==="tree"&&(o=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:o,subdir:i}}catch{return null}}async function j(d,e){let t=_(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let s=e?.fetcher||new S(e?.githubToken),n=e?.includeLock!==!1,o=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(o,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:o,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":c,...a}=i;return a}return i}var O;async function P(d){return O||(O=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),O}function A(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function G(d){if(typeof d!="object"||d===null)throw new Error("Unexpected compile result shape from wasm");let e=d;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function U(d){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,o=[];for(let i=0;i<n.length;i+=2){let c=parseInt(n.slice(i,i+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");o.push(c)}return o};try{let t=JSON.parse(d);if(!t.modules||!t.dependencies||!t.digest)throw new Error("missing fields in compiler output");let s=typeof t.digest=="string"?e(t.digest):Array.from(t.digest);return{modules:t.modules,dependencies:t.dependencies,digest:s}}catch(t){return A(t)}}function B(d){try{let e=JSON.parse(d);for(let t of e){let s=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let o=b(n[1]);return o.addresses&&o.addresses[t.name]||o.package?.published_at||o.package?.["published-at"]})()}}catch{}}async function le(d){await P(d?.wasm)}async function C(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,s=await N(e,{...d.files,"Move.toml":e},new S(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function ge(d){try{if(d.files["Move.lock"]&&d.files["Move.toml"])try{let c=b(d.files["Move.lock"]),a=d.network||"mainnet",l=c.env?.[a]?.["original-published-id"];if(l){let g=b(d.files["Move.toml"]).package?.name;if(g){let p=new Set([g,g.toLowerCase()]),u=d.files["Move.toml"];for(let f of p){let h=new RegExp(`(^|[\\s])(${f}\\s*=\\s*)"0x0"`,"m");if(h.test(u)){u=u.replace(h,`$1$2"${l}"`);break}}d.files["Move.toml"]=u}}}catch{}let e=d.resolvedDependencies?d.resolvedDependencies:await C(d),t=await P(d.wasm);B(e.dependencies);let s=t.compile(e.files,e.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag})),n=G(s),o=n.success(),i=n.output();return o?U(i):A(i)}catch(e){return A(e)}}async function ue(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await C(d),t=await P(d.wasm);B(e.dependencies);let s=d.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof s.passed=="boolean"&&typeof s.output=="string")return{passed:s.passed,output:s.output};let n=typeof s.passed=="function"?s.passed():s.passed,o=typeof s.output=="function"?s.output():s.output;return{passed:n,output:o}}catch(e){return A(e)}}async function fe(d){return(await P(d?.wasm)).sui_move_version()}async function pe(d){return(await P(d?.wasm)).sui_version()}async function me(d){return P(d?.wasm)}async function he(d,e,t){let s=await P(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(d,e,!0):s.compile(d,e,JSON.stringify({silenceWarnings:!1})),o=G(n);return{success:o.success(),output:o.output()}}export{ge as buildMovePackage,he as compileRaw,j as fetchPackageFromGitHub,fe as getSuiMoveVersion,pe as getSuiVersion,me as getWasmBindings,le as initMoveCompiler,C as resolveDependencies,ue as testMovePackage};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class MoveCompilerResult {
|
|
5
|
+
private constructor();
|
|
6
|
+
free(): void;
|
|
7
|
+
[Symbol.dispose](): void;
|
|
8
|
+
readonly output: string;
|
|
9
|
+
readonly success: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class MoveTestResult {
|
|
13
|
+
private constructor();
|
|
14
|
+
free(): void;
|
|
15
|
+
[Symbol.dispose](): void;
|
|
16
|
+
readonly output: string;
|
|
17
|
+
readonly passed: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function compile(files_json: string, dependencies_json: string, options_json?: string | null): MoveCompilerResult;
|
|
21
|
+
|
|
22
|
+
export function sui_move_version(): string;
|
|
23
|
+
|
|
24
|
+
export function sui_version(): string;
|
|
25
|
+
|
|
26
|
+
export function test(files_json: string, dependencies_json: string): MoveTestResult;
|
|
27
|
+
|
|
28
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
29
|
+
|
|
30
|
+
export interface InitOutput {
|
|
31
|
+
readonly memory: WebAssembly.Memory;
|
|
32
|
+
readonly __wbg_movecompilerresult_free: (a: number, b: number) => void;
|
|
33
|
+
readonly compile: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
34
|
+
readonly movecompilerresult_output: (a: number) => [number, number];
|
|
35
|
+
readonly movecompilerresult_success: (a: number) => number;
|
|
36
|
+
readonly sui_move_version: () => [number, number];
|
|
37
|
+
readonly test: (a: number, b: number, c: number, d: number) => number;
|
|
38
|
+
readonly sui_version: () => [number, number];
|
|
39
|
+
readonly __wbg_movetestresult_free: (a: number, b: number) => void;
|
|
40
|
+
readonly movetestresult_output: (a: number) => [number, number];
|
|
41
|
+
readonly movetestresult_passed: (a: number) => number;
|
|
42
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
43
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
44
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
45
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
46
|
+
readonly __wbindgen_start: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
53
|
+
* a precompiled `WebAssembly.Module`.
|
|
54
|
+
*
|
|
55
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
56
|
+
*
|
|
57
|
+
* @returns {InitOutput}
|
|
58
|
+
*/
|
|
59
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
63
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
64
|
+
*
|
|
65
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
66
|
+
*
|
|
67
|
+
* @returns {Promise<InitOutput>}
|
|
68
|
+
*/
|
|
69
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|