@zktx.io/sui-move-builder 0.2.2 → 0.2.3
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 +7 -2
- package/dist/full/index.cjs +19 -21
- package/dist/full/index.d.cts +1 -1
- package/dist/full/index.d.ts +1 -1
- package/dist/full/index.js +19 -21
- package/dist/full/sui_move_wasm.js +3 -3
- package/dist/full/sui_move_wasm_bg.wasm +0 -0
- package/dist/lite/index.cjs +19 -21
- package/dist/lite/index.d.cts +1 -1
- package/dist/lite/index.d.ts +1 -1
- package/dist/lite/index.js +19 -21
- package/dist/lite/sui_move_wasm.js +2 -2
- package/dist/lite/sui_move_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @zktx.io/sui-move-builder
|
|
2
2
|
|
|
3
|
-
> **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (tag: `
|
|
3
|
+
> **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (tag: `v1.63.3`)
|
|
4
4
|
|
|
5
5
|
Build Move packages in web or Node.js with Sui CLI-compatible dependency resolution and compilation.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- ✅ **Sui CLI Compatible**: Identical dependency resolution algorithm as Sui CLI
|
|
10
|
+
- ✅ **Verified Parity**: Audited against `sui-04dd` source code (Jan 2026)
|
|
10
11
|
- ✅ **Lockfile Support**: Reads `Move.lock` for faster, deterministic builds
|
|
11
12
|
- ✅ **Per-Package Editions**: Each package can use its own Move edition (legacy, 2024.alpha, 2024.beta)
|
|
12
13
|
- ✅ **Monorepo Support**: Handles local dependencies in monorepo structures
|
|
@@ -141,7 +142,7 @@ name = "my_package"
|
|
|
141
142
|
edition = "2024.beta"
|
|
142
143
|
|
|
143
144
|
[dependencies]
|
|
144
|
-
|
|
145
|
+
dep_name = { git = "https://github.com/org/repo.git", subdir = "packages/dep_name", rev = "main" }
|
|
145
146
|
`,
|
|
146
147
|
"sources/main.move": "...",
|
|
147
148
|
};
|
|
@@ -242,3 +243,7 @@ if (entry.name === "build" || entry.name === ".git") continue;
|
|
|
242
243
|
npm run serve:test # serves ./test via python -m http.server
|
|
243
244
|
# open http://localhost:8000/test/index.html
|
|
244
245
|
```
|
|
246
|
+
|
|
247
|
+
## Roadmap
|
|
248
|
+
|
|
249
|
+
- **Return Build Artifacts**: Future updates will include generating and returning `Move.lock` and `Published.toml` files to the caller, facilitating deployment tracking and deterministic rebuilds.
|
package/dist/full/index.cjs
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
"use strict";var E=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(d,e)=>{for(var t in e)R(d,t,{get:e[t],enumerable:!0})},G=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of V(e))!q.call(d,n)&&n!==t&&R(d,n,{get:()=>e[n],enumerable:!(s=z(e,n))||s.enumerable});return d};var K=(d,e,t)=>(t=d!=null?E(H(d)):{},G(e||!d||!d.__esModule?R(t,"default",{value:d,enumerable:!0}):t,d)),Q=d=>G(R({},"__esModule",{value:!0}),d);var ae={};J(ae,{buildMovePackage:()=>te,compileRaw:()=>oe,fetchPackageFromGitHub:()=>_,getSuiMoveVersion:()=>se,getSuiVersion:()=>ie,getWasmBindings:()=>re,initMoveCompiler:()=>ee,resolveDependencies:()=>L,testMovePackage:()=>ne});module.exports=Q(ae);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,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let l of a.tree){if(l.type!=="blob")continue;let p=l.path;if(n){if(!l.path.startsWith(n))continue;p=l.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${l.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let l=g["Move.toml"].trim();if(l.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!l.includes("[")&&!l.includes("=")){let p=l,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${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",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(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(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}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 C(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=F(a)}return e}function X(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(B(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(B(s.trim())),e}function B(d){return d.startsWith("{")?C(d):F(d)}function w(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=M(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+M(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+M(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=M(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let l=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=C(p):p.startsWith("[")?m=X(p):m=F(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[l]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?l.replace(/-/g,"_"):l;h[v]=m}}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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);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=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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 A=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[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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 I=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(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}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,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
-
`),i=[],
|
|
3
|
-
|
|
4
|
-
`,
|
|
5
|
-
`,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`),a+=`
|
|
1
|
+
"use strict";var V=Object.create;var D=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var Q=(d,e)=>{for(var t in e)D(d,t,{get:e[t],enumerable:!0})},B=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of q(e))!K.call(d,n)&&n!==t&&D(d,n,{get:()=>e[n],enumerable:!(s=H(e,n))||s.enumerable});return d};var X=(d,e,t)=>(t=d!=null?V(J(d)):{},B(e||!d||!d.__esModule?D(t,"default",{value:d,enumerable:!0}):t,d)),Y=d=>B(D({},"__esModule",{value:!0}),d);var de={};Q(de,{buildMovePackage:()=>se,compileRaw:()=>ce,fetchPackageFromGitHub:()=>U,getSuiMoveVersion:()=>re,getSuiVersion:()=>oe,getWasmBindings:()=>ae,initMoveCompiler:()=>ne,resolveDependencies:()=>N,testMovePackage:()=>ie});module.exports=Y(de);var T=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},R=class extends T{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,r){let{owner:i,repo:o}=this.parseGitUrl(t);if(!i||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${o}@${s}`,p=`https://api.github.com/repos/${i}/${o}/git/trees/${s}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let y=1;y<=3;y++)try{if(y>1){let b=Math.pow(2,y-1)*1e3;await new Promise(k=>setTimeout(k,b))}let h={};this.token&&(h.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:h});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&y<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(h){if(f=h instanceof Error?h:new Error(String(h)),y===3)return{}}if(f)return{}}let l=new Map,g={},u=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(n){if(!m.path.startsWith(n))continue;f=m.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;f==="Move.toml"&&m.mode&&l.set("Move.toml",m.mode);let y=`https://raw.githubusercontent.com/${i}/${o}/${s}/${m.path}`,h=this.fetchContent(y).then(v=>{v&&(g[f]=v)});u.push(h)}if(await Promise.all(u),g["Move.toml"]&&l.get("Move.toml")==="120000"){let f=g["Move.toml"].trim(),y=n?`${n}/${f}`.replace(/\/+/g,"/"):f,h=`https://raw.githubusercontent.com/${i}/${o}/${s}/${y}`,v=await this.fetchContent(h);v&&(g["Move.toml"]=v)}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let o=await i.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function A(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 O(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 j(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=a),!n&&a===","){i.push(s),s="";continue}s+=a}s.trim()&&i.push(s);for(let o of i){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=O(c)}return e}function Z(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){s.trim()&&e.push(W(s.trim())),s="";continue}s+=a}return s.trim()&&e.push(W(s.trim())),e}function W(d){return d.startsWith("{")?j(d):O(d)}function S(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let a=A(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(i++;i<n.length&&!p.includes("]");)p+=" "+A(n[i]).trim(),i++;i<n.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+A(n[i]).trim(),i++),r.push(p)}else r.push(a),i++}function o(a,p){let c=a;for(let l of p){if(!(l in c))return;c=c[l]}return c}for(let a of r){let p=A(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),s=!0;let y=t.split("."),h=e;for(let b=0;b<y.length-1;b++){let k=y[b];k in h||(h[k]={}),h=h[k]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let l=p.match(/^\[([^\]]+)\]$/);if(l){t=l[1].trim(),s=!1;continue}let g=p.indexOf("=");if(g===-1||!t)continue;let u=p.slice(0,g).trim(),m=p.slice(g+1).trim(),f;if(m.startsWith("{")?f=j(m):m.startsWith("[")?f=Z(m):f=O(m),s){let y=t.split("."),h=o(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[u]=f}}else{let y=t.split("."),h=e;for(let b of y)b in h||(h[b]={}),h=h[b];let v=t==="package"?u.replace(/-/g,"_"):u;h[v]=f}}return e}var I=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)if(e.has(o)){if(t.has(o)){let a=[o],p=r;for(;p!==o;)a.unshift(p),p=s.get(p);return a.unshift(o),a}}else{s.set(o,r);let a=n(o);if(a)return a}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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 x=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[r,i]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==o||this.unifiedAddressTable.set(r,o)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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()}compilerInputOrder(){return this.graph.compilerInputOrder()}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.compilerInputOrder(),r=new Map;for(let i of n){if(i===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(i);if(!o)continue;let a=e.get(i)||{},p=this.extractSourcePaths(i,a),c=o.manifest.edition||"legacy",l=o.manifest.latestPublishedId||o.manifest.originalId||o.manifest.publishedAt||o.resolvedTable?.[i],g=o.manifest.originalId||o.manifest.publishedAt||o.manifest.latestPublishedId||l;g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",l=g),r.set(i,g),r.set(i.toLowerCase(),g);let u={...o.resolvedTable||{}};for(let[f,y]of Object.entries(u)){let h=r.get(f)||r.get(f.toLowerCase());h&&(u[f]=h)}g&&i!=="Sui"&&i!=="MoveStdlib"&&(u[i]=g,u[i.toLowerCase()]=g);let m={name:i,isImmediate:s.has(i),sourcePaths:p,addressMapping:u,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:l};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}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,r=(i,o)=>{let a=n.encode(`/vfs/deps/${e}/${i}`),p=n.encode(`/vfs/deps/${e}/${o}`),c=Math.min(a.length,p.length);for(let l=0;l<c;l++)if(a[l]!==p[l])return a[l]-p[l];return a.length-p.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,o]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[a]=this.reconstructDependencyMoveToml(s.name,o,s.edition,s.addressMapping):r[a]=o}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
+
`),i=[],o="none";for(let c of r){let l=c.trim();if(l.startsWith("[")){l.startsWith("[package]")?o="package":l.startsWith("[addresses]")?o="addresses":l.startsWith("[dependencies")||l.startsWith("[dev-dependencies")?o="dependencies":(o="other",i.push(c));continue}if(o==="package")l.includes("name =")||l.includes("version =");else{if(o==="addresses")continue;o!=="none"&&i.push(c)}}let a=`[package]
|
|
3
|
+
`;a+=`name = "${e}"
|
|
4
|
+
`,a+=`version = "0.0.0"
|
|
5
|
+
`,a+=`edition = "${s}"
|
|
6
|
+
`,a+=`
|
|
7
|
+
`,a+=i.join(`
|
|
8
|
+
`),a+=`
|
|
9
|
+
[addresses]
|
|
9
10
|
`,a+=`
|
|
10
|
-
[dependencies]
|
|
11
|
-
`;for(let l of c)a+=l+`
|
|
12
|
-
`;a+=`
|
|
13
11
|
[addresses]
|
|
14
|
-
`;for(let[l
|
|
15
|
-
`;return a}};var
|
|
16
|
-
`))}this.packageNameCache.set(
|
|
12
|
+
`;let p=Object.entries(n).sort(([c],[l])=>c<l?-1:c>l?1:0);for(let[c,l]of p)a+=`${c} = "${l}"
|
|
13
|
+
`;return a}};var L=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=S(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new I(n),o=await this.buildPackage(n,this.rootSource,e,t);r&&(o.manifest.edition=r);let a=o.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[n]=this.normalizeAddress(o.manifest.originalId)),i.addPackage(o),this.packageFiles.set(n,t);let c=await this.loadFromLockfile(i,o,t),l=Array.from(o.dependencies.keys()).filter(k=>!i.getPackage(k));(!c||l.length>0)&&await this.buildDependencyGraph(i,o);let g=i.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let u=new x(i,{});await u.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new $(u);await f.compute(this.packageFiles);let y=u.getUnifiedAddressTable();for(let k of i.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name==="Sui"||k.manifest.name,w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);y[k.manifest.name]=P,y[k.manifest.name.toLowerCase()]=P}}let h=this.reconstructMoveToml(s,y,!0,r),v={...t};delete v["Move.lock"],v["Move.toml"]=h;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,s,n){let r=S(s),i=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(s,i,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=n["Published.toml"],l,g;if(c)try{let P=S(c).published?.[this.network];P&&(P["published-at"]&&(l=this.normalizeAddress(P["published-at"])),P["original-id"]&&(g=this.normalizeAddress(P["original-id"])))}catch{}a.error;let u={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:l||a.publishedAt,originalId:g||a.originalId,latestPublishedId:p,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},m=Object.keys(u.addresses).find(w=>w.toLowerCase()===u.name.toLowerCase());if(m&&u.addresses[m]){let w=this.normalizeAddress(u.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(u.originalId=w)}let f=u.originalId||u.publishedAt,y=f&&f!=="0x0"?this.normalizeAddress(f):void 0,h=u.addresses[u.name],v=h?this.normalizeAddress(h):void 0;y?h||(u.addresses[u.name]=y):v?u.addresses[u.name]=v:u.addresses[u.name]="0x0";let b=new Map;if(u.dependencies)for(let[w,P]of Object.entries(u.dependencies)){let G=this.parseDependencyInfo(P);G&&b.set(w,G)}return{id:{name:u.name,version:u.version,source:t||{type:"local"}},manifest:u,dependencies:b,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[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={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 l=t.id.source.subdir||"",g=n.source.local,u=this.resolveRelativePath(l,g);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 r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let l=this.findPackageBySource(e,n.source);l&&e.addDependency(t.id.name,l.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let o=await this.fetcher.fetch(n.source.git,n.source.rev,i),a=null,p=`Move.${this.network}.toml`;for(let[l,g]of Object.entries(o))if(l.endsWith(p)){a=g;break}if(!a){for(let[l,g]of Object.entries(o))if(l.endsWith("Move.toml")){a=g;break}}if(!a)continue;let c=await this.buildPackage(s,n.source,a,o);if(!this.lockfileVersion||this.lockfileVersion<4){let l=this.packageNameCache.get(c.manifest.name);if(l){let g=u=>JSON.stringify(u);throw new Error([`Conflicting versions of package '${c.manifest.name}' found`,`Existing: ${g(l)}`,`New: ${g(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
14
|
+
`))}this.packageNameCache.set(c.manifest.name,n.source)}c.manifest.edition||(c.manifest.edition="legacy"),e.addPackage(c),e.addDependency(t.id.name,c.id.name,n),this.packageFiles.set(c.id.name,o),await this.buildDependencyGraph(e,c)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s,n){let r=S(e),i=r.package?.published_at||r.package?.["published-at"],o=i&&i!=="0x0"?i:void 0,a=o?this.normalizeAddress(o):void 0,p=r.package?.["original-id"],c,l;if(t)try{let m=S(t),f=s&&m.env?.[s]||m.env?.[n];f&&(f["original-published-id"]&&(c=this.normalizeAddress(f["original-published-id"])),f["latest-published-id"]&&(l=this.normalizeAddress(f["latest-published-id"])))}catch{}return{publishedAt:c||a||l,originalId:p||c,latestId:l}}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),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.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(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=S(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],i=n.map(c=>c.name||c.id).filter(Boolean),o=[...r,...i.filter(c=>!r.includes(c))],a=new Map,p=new Map;for(let c of n){let l=c.id||c.name,g=c.source;if(!l||!g)continue;let u=null;if(g.git&&g.rev)u={type:"git",git:g.git,rev:g.rev,subdir:g.subdir};else if(g.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",g.local);u={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let m=await this.fetcher.fetch(u.git,u.rev,u.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let y=await this.buildPackage(l,u,f,m);a.set(l,y),p.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,m),e.addPackage(y)}o.length&&e.setLockfileOrder(o);for(let c of n){let l=c.id||c.name,g=a.get(l);if(!g)continue;let u=c.dependencies;if(u&&Array.isArray(u))for(let m of u){let f=m.id||m.name,y=a.get(f)||p.get(f);if(y){let h={source:y.id.source};e.addDependency(g.id.name,y.id.name,h)}}}for(let c of s.dependencies.keys()){let l=p.get(c);if(l){let g=s.dependencies.get(c);e.addDependency(s.id.name,l.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,o=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let p=a.id,c=a.source;o.push(p);let l=null;if(c?.git&&c.rev)l={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!l.git||!l.rev)continue;let g=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(g).length===0)continue;let u=g["Move.toml"];if(!u)continue;let m=await this.buildPackage(p,l,u,g);r.set(p,m),this.packageFiles.set(m.manifest.name,g),e.addPackage(m)}e.setLockfileOrder(o);for(let a of n){let p=a.id,c=r.get(p);if(!c)continue;let l=a.dependencies;if(!(!l||!Array.isArray(l)))for(let g of l){let u=g.id,m=r.get(u);if(!m){let f=i.get(u);if(f?.source?.local&&c.id.source.type==="git"){let y=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),h={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(u,h,b,v);r.set(u,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of s.dependencies.keys()){let p=r.get(a);if(p){let c=s.dependencies.get(a);e.addDependency(s.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,l]of Object.entries(r)){p.push(c);let g=this.lockfileSourceToDependencySource(l.source);if(!g)continue;let u=await this.fetchFromSource(g);if(!u)return!1;let m=u["Move.toml"];if(!m||l["manifest-digest"]&&await this.computeManifestDigest(m)!==l["manifest-digest"])return!1;let f=await this.buildPackage(c,g,m,u);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,u),(g.type!=="local"||!("root"in l.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,l]of Object.entries(r)){let g=o.get(c);if(g&&l.deps)for(let[u,m]of Object.entries(l.deps)){let f=o.get(m);if(f){let y=g.dependencies.get(u);y&&e.addDependency(g.id.name,f.id.name,y)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let l=c.id,g=o.get(l);if(g){let u={source:g.id.source};e.addDependency(n.id.name,g.id.name,u)}}else for(let c of n.dependencies.keys()){let l=a.get(c)||o.get(c);if(l){let g=n.dependencies.get(c);e.addDependency(n.id.name,l.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)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
|
|
17
15
|
name = "${e.package.name}"
|
|
18
16
|
version = "${e.package.version}"
|
|
19
|
-
`,
|
|
17
|
+
`,o=n||e.package.edition;if(o&&(i+=`edition = "${o}"
|
|
20
18
|
`),i+=`
|
|
21
19
|
[dependencies]
|
|
22
|
-
`,e.dependencies)
|
|
23
|
-
`:
|
|
24
|
-
`:i+=`${
|
|
25
|
-
`)}i+=`
|
|
20
|
+
`,e.dependencies){let p=Object.entries(e.dependencies).sort(([c],[l])=>c.localeCompare(l));for(let[c,l]of p){let g=l;g.local?i+=`${c} = { local = "${g.local}" }
|
|
21
|
+
`:g.git&&g.rev&&(g.subdir?i+=`${c} = { git = "${g.git}", subdir = "${g.subdir}", rev = "${g.rev}" }
|
|
22
|
+
`:i+=`${c} = { git = "${g.git}", rev = "${g.rev}" }
|
|
23
|
+
`)}}i+=`
|
|
26
24
|
[addresses]
|
|
27
|
-
`;for(let[
|
|
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",
|
|
25
|
+
`;let a=Object.entries(t).sort(([p],[c])=>p.localeCompare(c));for(let[p,c]of a)i+=`${p} = "${c}"
|
|
26
|
+
`;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",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function _(d,e,t,s="mainnet",n){return new L(t,s,n||null).resolve(d,e)}function ee(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],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function U(d,e){let t=ee(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let s=e?.fetcher||new R(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":o,...a}=i;return a}return i}var C;async function M(d){return C||(C=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),C}function F(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function E(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 te(d){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let o=parseInt(n.slice(i,i+2),16);if(Number.isNaN(o))throw new Error("invalid hex digest");r.push(o)}return r};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 F(t)}}function z(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 r=S(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function ne(d){await M(d?.wasm)}async function N(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,s=await _(e,{...d.files,"Move.toml":e},new R(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 se(d){try{let e={};for(let[a,p]of Object.entries(d.files))(a.endsWith(".move")||a.endsWith("Move.toml")||a.endsWith("Move.lock")||a.endsWith("Published.toml"))&&(e[a]=p);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await N(d),s=await M(d.wasm);z(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=E(n),i=r.success(),o=r.output();return i?te(o):F(o)}catch(e){return F(e)}}async function ie(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await N(d),t=await M(d.wasm);z(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,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return F(e)}}async function re(d){return(await M(d?.wasm)).sui_move_version()}async function oe(d){return(await M(d?.wasm)).sui_version()}async function ae(d){return M(d?.wasm)}async function ce(d,e,t){let s=await M(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})),r=E(n);return{success:r.success(),output:r.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
|
package/dist/full/index.d.cts
CHANGED
|
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
|
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
41
|
* const files = await fetchPackageFromGitHub(
|
|
42
|
-
* 'https://github.com/
|
|
42
|
+
* 'https://github.com/org/repo/tree/main/packages/example_package'
|
|
43
43
|
* );
|
|
44
44
|
*
|
|
45
45
|
* // files = {
|
package/dist/full/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
|
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
41
|
* const files = await fetchPackageFromGitHub(
|
|
42
|
-
* 'https://github.com/
|
|
42
|
+
* 'https://github.com/org/repo/tree/main/packages/example_package'
|
|
43
43
|
* );
|
|
44
44
|
*
|
|
45
45
|
* // files = {
|
package/dist/full/index.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
var $=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends ${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,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let d of a.tree){if(d.type!=="blob")continue;let p=d.path;if(n){if(!d.path.startsWith(n))continue;p=d.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${d.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let d=g["Move.toml"].trim();if(d.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!d.includes("[")&&!d.includes("=")){let p=d,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${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",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(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(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function R(l){let e=!1,t="";for(let s=0;s<l.length;s++){let n=l[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return l.slice(0,s)}return l}function x(l){let e=l.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 N(l){let e={},t=l.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=x(a)}return e}function _(l){let e=[],t=l.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(L(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(L(s.trim())),e}function L(l){return l.startsWith("{")?N(l):x(l)}function w(l){let e={},t=null,s=!1,n=l.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=R(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+R(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+R(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=R(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let d=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=N(p):p.startsWith("[")?m=_(p):m=x(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[d]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?d.replace(/-/g,"_"):d;h[v]=m}}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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);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=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}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,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
-
`),i=[],
|
|
3
|
-
|
|
4
|
-
`,
|
|
5
|
-
`,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`),a+=`
|
|
1
|
+
var F=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},R=class extends F{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,r){let{owner:i,repo:o}=this.parseGitUrl(t);if(!i||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${o}@${s}`,p=`https://api.github.com/repos/${i}/${o}/git/trees/${s}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let y=1;y<=3;y++)try{if(y>1){let b=Math.pow(2,y-1)*1e3;await new Promise(k=>setTimeout(k,b))}let h={};this.token&&(h.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:h});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&y<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(h){if(f=h instanceof Error?h:new Error(String(h)),y===3)return{}}if(f)return{}}let d=new Map,l={},u=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(n){if(!m.path.startsWith(n))continue;f=m.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;f==="Move.toml"&&m.mode&&d.set("Move.toml",m.mode);let y=`https://raw.githubusercontent.com/${i}/${o}/${s}/${m.path}`,h=this.fetchContent(y).then(v=>{v&&(l[f]=v)});u.push(h)}if(await Promise.all(u),l["Move.toml"]&&d.get("Move.toml")==="120000"){let f=l["Move.toml"].trim(),y=n?`${n}/${f}`.replace(/\/+/g,"/"):f,h=`https://raw.githubusercontent.com/${i}/${o}/${s}/${y}`,v=await this.fetchContent(h);v&&(l["Move.toml"]=v)}return l}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let o=await i.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function D(g){let e=!1,t="";for(let s=0;s<g.length;s++){let n=g[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return g.slice(0,s)}return g}function T(g){let e=g.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 G(g){let e={},t=g.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=a),!n&&a===","){i.push(s),s="";continue}s+=a}s.trim()&&i.push(s);for(let o of i){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=T(c)}return e}function U(g){let e=[],t=g.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){s.trim()&&e.push(N(s.trim())),s="";continue}s+=a}return s.trim()&&e.push(N(s.trim())),e}function N(g){return g.startsWith("{")?G(g):T(g)}function S(g){let e={},t=null,s=!1,n=g.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let a=D(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(i++;i<n.length&&!p.includes("]");)p+=" "+D(n[i]).trim(),i++;i<n.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+D(n[i]).trim(),i++),r.push(p)}else r.push(a),i++}function o(a,p){let c=a;for(let d of p){if(!(d in c))return;c=c[d]}return c}for(let a of r){let p=D(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),s=!0;let y=t.split("."),h=e;for(let b=0;b<y.length-1;b++){let k=y[b];k in h||(h[k]={}),h=h[k]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let d=p.match(/^\[([^\]]+)\]$/);if(d){t=d[1].trim(),s=!1;continue}let l=p.indexOf("=");if(l===-1||!t)continue;let u=p.slice(0,l).trim(),m=p.slice(l+1).trim(),f;if(m.startsWith("{")?f=G(m):m.startsWith("[")?f=U(m):f=T(m),s){let y=t.split("."),h=o(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[u]=f}}else{let y=t.split("."),h=e;for(let b of y)b in h||(h[b]={}),h=h[b];let v=t==="package"?u.replace(/-/g,"_"):u;h[v]=f}}return e}var A=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)if(e.has(o)){if(t.has(o)){let a=[o],p=r;for(;p!==o;)a.unshift(p),p=s.get(p);return a.unshift(o),a}}else{s.set(o,r);let a=n(o);if(a)return a}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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 I=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[r,i]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==o||this.unifiedAddressTable.set(r,o)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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()}compilerInputOrder(){return this.graph.compilerInputOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var x=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.compilerInputOrder(),r=new Map;for(let i of n){if(i===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(i);if(!o)continue;let a=e.get(i)||{},p=this.extractSourcePaths(i,a),c=o.manifest.edition||"legacy",d=o.manifest.latestPublishedId||o.manifest.originalId||o.manifest.publishedAt||o.resolvedTable?.[i],l=o.manifest.originalId||o.manifest.publishedAt||o.manifest.latestPublishedId||d;l||(l="0x0000000000000000000000000000000000000000000000000000000000000000",d=l),r.set(i,l),r.set(i.toLowerCase(),l);let u={...o.resolvedTable||{}};for(let[f,y]of Object.entries(u)){let h=r.get(f)||r.get(f.toLowerCase());h&&(u[f]=h)}l&&i!=="Sui"&&i!=="MoveStdlib"&&(u[i]=l,u[i.toLowerCase()]=l);let m={name:i,isImmediate:s.has(i),sourcePaths:p,addressMapping:u,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:d};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}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,r=(i,o)=>{let a=n.encode(`/vfs/deps/${e}/${i}`),p=n.encode(`/vfs/deps/${e}/${o}`),c=Math.min(a.length,p.length);for(let d=0;d<c;d++)if(a[d]!==p[d])return a[d]-p[d];return a.length-p.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,o]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[a]=this.reconstructDependencyMoveToml(s.name,o,s.edition,s.addressMapping):r[a]=o}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
+
`),i=[],o="none";for(let c of r){let d=c.trim();if(d.startsWith("[")){d.startsWith("[package]")?o="package":d.startsWith("[addresses]")?o="addresses":d.startsWith("[dependencies")||d.startsWith("[dev-dependencies")?o="dependencies":(o="other",i.push(c));continue}if(o==="package")d.includes("name =")||d.includes("version =");else{if(o==="addresses")continue;o!=="none"&&i.push(c)}}let a=`[package]
|
|
3
|
+
`;a+=`name = "${e}"
|
|
4
|
+
`,a+=`version = "0.0.0"
|
|
5
|
+
`,a+=`edition = "${s}"
|
|
6
|
+
`,a+=`
|
|
7
|
+
`,a+=i.join(`
|
|
8
|
+
`),a+=`
|
|
9
|
+
[addresses]
|
|
9
10
|
`,a+=`
|
|
10
|
-
[dependencies]
|
|
11
|
-
`;for(let d of c)a+=d+`
|
|
12
|
-
`;a+=`
|
|
13
11
|
[addresses]
|
|
14
|
-
`;for(let[d
|
|
15
|
-
`;return a}};var
|
|
16
|
-
`))}this.packageNameCache.set(
|
|
12
|
+
`;let p=Object.entries(n).sort(([c],[d])=>c<d?-1:c>d?1:0);for(let[c,d]of p)a+=`${c} = "${d}"
|
|
13
|
+
`;return a}};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=S(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new A(n),o=await this.buildPackage(n,this.rootSource,e,t);r&&(o.manifest.edition=r);let a=o.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[n]=this.normalizeAddress(o.manifest.originalId)),i.addPackage(o),this.packageFiles.set(n,t);let c=await this.loadFromLockfile(i,o,t),d=Array.from(o.dependencies.keys()).filter(k=>!i.getPackage(k));(!c||d.length>0)&&await this.buildDependencyGraph(i,o);let l=i.detectCycle();if(l)throw new Error(`Dependency cycle detected: ${l.join(" \u2192 ")}`);let u=new I(i,{});await u.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new x(u);await f.compute(this.packageFiles);let y=u.getUnifiedAddressTable();for(let k of i.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name==="Sui"||k.manifest.name,w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);y[k.manifest.name]=P,y[k.manifest.name.toLowerCase()]=P}}let h=this.reconstructMoveToml(s,y,!0,r),v={...t};delete v["Move.lock"],v["Move.toml"]=h;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,s,n){let r=S(s),i=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(s,i,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=n["Published.toml"],d,l;if(c)try{let P=S(c).published?.[this.network];P&&(P["published-at"]&&(d=this.normalizeAddress(P["published-at"])),P["original-id"]&&(l=this.normalizeAddress(P["original-id"])))}catch{}a.error;let u={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:d||a.publishedAt,originalId:l||a.originalId,latestPublishedId:p,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},m=Object.keys(u.addresses).find(w=>w.toLowerCase()===u.name.toLowerCase());if(m&&u.addresses[m]){let w=this.normalizeAddress(u.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(u.originalId=w)}let f=u.originalId||u.publishedAt,y=f&&f!=="0x0"?this.normalizeAddress(f):void 0,h=u.addresses[u.name],v=h?this.normalizeAddress(h):void 0;y?h||(u.addresses[u.name]=y):v?u.addresses[u.name]=v:u.addresses[u.name]="0x0";let b=new Map;if(u.dependencies)for(let[w,P]of Object.entries(u.dependencies)){let C=this.parseDependencyInfo(P);C&&b.set(w,C)}return{id:{name:u.name,version:u.version,source:t||{type:"local"}},manifest:u,dependencies:b,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[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={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 d=t.id.source.subdir||"",l=n.source.local,u=this.resolveRelativePath(d,l);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 r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let d=this.findPackageBySource(e,n.source);d&&e.addDependency(t.id.name,d.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let o=await this.fetcher.fetch(n.source.git,n.source.rev,i),a=null,p=`Move.${this.network}.toml`;for(let[d,l]of Object.entries(o))if(d.endsWith(p)){a=l;break}if(!a){for(let[d,l]of Object.entries(o))if(d.endsWith("Move.toml")){a=l;break}}if(!a)continue;let c=await this.buildPackage(s,n.source,a,o);if(!this.lockfileVersion||this.lockfileVersion<4){let d=this.packageNameCache.get(c.manifest.name);if(d){let l=u=>JSON.stringify(u);throw new Error([`Conflicting versions of package '${c.manifest.name}' found`,`Existing: ${l(d)}`,`New: ${l(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
14
|
+
`))}this.packageNameCache.set(c.manifest.name,n.source)}c.manifest.edition||(c.manifest.edition="legacy"),e.addPackage(c),e.addDependency(t.id.name,c.id.name,n),this.packageFiles.set(c.id.name,o),await this.buildDependencyGraph(e,c)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s,n){let r=S(e),i=r.package?.published_at||r.package?.["published-at"],o=i&&i!=="0x0"?i:void 0,a=o?this.normalizeAddress(o):void 0,p=r.package?.["original-id"],c,d;if(t)try{let m=S(t),f=s&&m.env?.[s]||m.env?.[n];f&&(f["original-published-id"]&&(c=this.normalizeAddress(f["original-published-id"])),f["latest-published-id"]&&(d=this.normalizeAddress(f["latest-published-id"])))}catch{}return{publishedAt:c||a||d,originalId:p||c,latestId:d}}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),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.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(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=S(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],i=n.map(c=>c.name||c.id).filter(Boolean),o=[...r,...i.filter(c=>!r.includes(c))],a=new Map,p=new Map;for(let c of n){let d=c.id||c.name,l=c.source;if(!d||!l)continue;let u=null;if(l.git&&l.rev)u={type:"git",git:l.git,rev:l.rev,subdir:l.subdir};else if(l.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",l.local);u={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let m=await this.fetcher.fetch(u.git,u.rev,u.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let y=await this.buildPackage(d,u,f,m);a.set(d,y),p.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,m),e.addPackage(y)}o.length&&e.setLockfileOrder(o);for(let c of n){let d=c.id||c.name,l=a.get(d);if(!l)continue;let u=c.dependencies;if(u&&Array.isArray(u))for(let m of u){let f=m.id||m.name,y=a.get(f)||p.get(f);if(y){let h={source:y.id.source};e.addDependency(l.id.name,y.id.name,h)}}}for(let c of s.dependencies.keys()){let d=p.get(c);if(d){let l=s.dependencies.get(c);e.addDependency(s.id.name,d.id.name,l)}}return a.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,o=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let p=a.id,c=a.source;o.push(p);let d=null;if(c?.git&&c.rev)d={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);d={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!d.git||!d.rev)continue;let l=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(l).length===0)continue;let u=l["Move.toml"];if(!u)continue;let m=await this.buildPackage(p,d,u,l);r.set(p,m),this.packageFiles.set(m.manifest.name,l),e.addPackage(m)}e.setLockfileOrder(o);for(let a of n){let p=a.id,c=r.get(p);if(!c)continue;let d=a.dependencies;if(!(!d||!Array.isArray(d)))for(let l of d){let u=l.id,m=r.get(u);if(!m){let f=i.get(u);if(f?.source?.local&&c.id.source.type==="git"){let y=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),h={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(u,h,b,v);r.set(u,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of s.dependencies.keys()){let p=r.get(a);if(p){let c=s.dependencies.get(a);e.addDependency(s.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,d]of Object.entries(r)){p.push(c);let l=this.lockfileSourceToDependencySource(d.source);if(!l)continue;let u=await this.fetchFromSource(l);if(!u)return!1;let m=u["Move.toml"];if(!m||d["manifest-digest"]&&await this.computeManifestDigest(m)!==d["manifest-digest"])return!1;let f=await this.buildPackage(c,l,m,u);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,u),(l.type!=="local"||!("root"in d.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,d]of Object.entries(r)){let l=o.get(c);if(l&&d.deps)for(let[u,m]of Object.entries(d.deps)){let f=o.get(m);if(f){let y=l.dependencies.get(u);y&&e.addDependency(l.id.name,f.id.name,y)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let d=c.id,l=o.get(d);if(l){let u={source:l.id.source};e.addDependency(n.id.name,l.id.name,u)}}else for(let c of n.dependencies.keys()){let d=a.get(c)||o.get(c);if(d){let l=n.dependencies.get(c);e.addDependency(n.id.name,d.id.name,l)}}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)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
|
|
17
15
|
name = "${e.package.name}"
|
|
18
16
|
version = "${e.package.version}"
|
|
19
|
-
`,
|
|
17
|
+
`,o=n||e.package.edition;if(o&&(i+=`edition = "${o}"
|
|
20
18
|
`),i+=`
|
|
21
19
|
[dependencies]
|
|
22
|
-
`,e.dependencies)
|
|
23
|
-
`:
|
|
24
|
-
`:i+=`${
|
|
25
|
-
`)}i+=`
|
|
20
|
+
`,e.dependencies){let p=Object.entries(e.dependencies).sort(([c],[d])=>c.localeCompare(d));for(let[c,d]of p){let l=d;l.local?i+=`${c} = { local = "${l.local}" }
|
|
21
|
+
`:l.git&&l.rev&&(l.subdir?i+=`${c} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
|
|
22
|
+
`:i+=`${c} = { git = "${l.git}", rev = "${l.rev}" }
|
|
23
|
+
`)}}i+=`
|
|
26
24
|
[addresses]
|
|
27
|
-
`;for(let[
|
|
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",
|
|
25
|
+
`;let a=Object.entries(t).sort(([p],[c])=>p.localeCompare(c));for(let[p,c]of a)i+=`${p} = "${c}"
|
|
26
|
+
`;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",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function B(g,e,t,s="mainnet",n){return new O(t,s,n||null).resolve(g,e)}function E(g){try{let e=new URL(g);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],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function z(g,e){let t=E(g);if(!t)throw new Error(`Invalid GitHub URL: ${g}`);let s=e?.fetcher||new R(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":o,...a}=i;return a}return i}var L;async function M(g){return L||(L=import("./sui_move_wasm.js").then(async e=>(g?await e.default(g):await e.default(),e))),L}function $(g){return{error:g instanceof Error?g.message:typeof g=="string"?g:"Unknown error"}}function W(g){if(typeof g!="object"||g===null)throw new Error("Unexpected compile result shape from wasm");let e=g;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 V(g){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let o=parseInt(n.slice(i,i+2),16);if(Number.isNaN(o))throw new Error("invalid hex digest");r.push(o)}return r};try{let t=JSON.parse(g);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 $(t)}}function j(g){try{let e=JSON.parse(g);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 r=S(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function pe(g){await M(g?.wasm)}async function _(g){let e=g.files["Move.toml"]||"",t=g.rootGit||g.files.__rootGit,s=await B(e,{...g.files,"Move.toml":e},new R(g.githubToken),g.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function fe(g){try{let e={};for(let[a,p]of Object.entries(g.files))(a.endsWith(".move")||a.endsWith("Move.toml")||a.endsWith("Move.lock")||a.endsWith("Published.toml"))&&(e[a]=p);g.files=e;let t=g.resolvedDependencies?g.resolvedDependencies:await _(g),s=await M(g.wasm);j(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:g.silenceWarnings,testMode:g.testMode,lintFlag:g.lintFlag,stripMetadata:g.stripMetadata})),r=W(n),i=r.success(),o=r.output();return i?V(o):$(o)}catch(e){return $(e)}}async function me(g){try{let e=g.resolvedDependencies?g.resolvedDependencies:await _(g),t=await M(g.wasm);j(e.dependencies);let s=g.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,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return $(e)}}async function he(g){return(await M(g?.wasm)).sui_move_version()}async function ye(g){return(await M(g?.wasm)).sui_version()}async function ve(g){return M(g?.wasm)}async function ke(g,e,t){let s=await M(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(g,e,!0):s.compile(g,e,JSON.stringify({silenceWarnings:!1})),r=W(n);return{success:r.success(),output:r.output()}}export{fe as buildMovePackage,ke as compileRaw,z as fetchPackageFromGitHub,he as getSuiMoveVersion,ye as getSuiVersion,ve as getWasmBindings,pe as initMoveCompiler,_ as resolveDependencies,me as testMovePackage};
|
|
@@ -158,12 +158,12 @@ function __wbg_get_imports() {
|
|
|
158
158
|
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
159
159
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
160
160
|
},
|
|
161
|
-
__wbg_log_098460783f5a8b3c: function(arg0, arg1) {
|
|
162
|
-
console.log(getStringFromWasm0(arg0, arg1));
|
|
163
|
-
},
|
|
164
161
|
__wbg_log_0f025e1465d13170: function(arg0, arg1) {
|
|
165
162
|
console.log(getStringFromWasm0(arg0, arg1));
|
|
166
163
|
},
|
|
164
|
+
__wbg_warn_4b3c7c44b93d17a4: function(arg0, arg1) {
|
|
165
|
+
console.warn(getStringFromWasm0(arg0, arg1));
|
|
166
|
+
},
|
|
167
167
|
__wbindgen_init_externref_table: function() {
|
|
168
168
|
const table = wasm.__wbindgen_externrefs;
|
|
169
169
|
const offset = table.grow(4);
|
|
Binary file
|
package/dist/lite/index.cjs
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
"use strict";var E=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(d,e)=>{for(var t in e)R(d,t,{get:e[t],enumerable:!0})},G=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of V(e))!q.call(d,n)&&n!==t&&R(d,n,{get:()=>e[n],enumerable:!(s=z(e,n))||s.enumerable});return d};var K=(d,e,t)=>(t=d!=null?E(H(d)):{},G(e||!d||!d.__esModule?R(t,"default",{value:d,enumerable:!0}):t,d)),Q=d=>G(R({},"__esModule",{value:!0}),d);var ae={};J(ae,{buildMovePackage:()=>te,compileRaw:()=>oe,fetchPackageFromGitHub:()=>_,getSuiMoveVersion:()=>se,getSuiVersion:()=>ie,getWasmBindings:()=>re,initMoveCompiler:()=>ee,resolveDependencies:()=>L,testMovePackage:()=>ne});module.exports=Q(ae);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,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let l of a.tree){if(l.type!=="blob")continue;let p=l.path;if(n){if(!l.path.startsWith(n))continue;p=l.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${l.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let l=g["Move.toml"].trim();if(l.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!l.includes("[")&&!l.includes("=")){let p=l,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${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",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(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(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}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 C(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=F(a)}return e}function X(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(B(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(B(s.trim())),e}function B(d){return d.startsWith("{")?C(d):F(d)}function w(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=M(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+M(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+M(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=M(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let l=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=C(p):p.startsWith("[")?m=X(p):m=F(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[l]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?l.replace(/-/g,"_"):l;h[v]=m}}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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);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=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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 A=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[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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 I=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(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}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,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
-
`),i=[],
|
|
3
|
-
|
|
4
|
-
`,
|
|
5
|
-
`,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`),a+=`
|
|
1
|
+
"use strict";var V=Object.create;var D=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var Q=(d,e)=>{for(var t in e)D(d,t,{get:e[t],enumerable:!0})},B=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of q(e))!K.call(d,n)&&n!==t&&D(d,n,{get:()=>e[n],enumerable:!(s=H(e,n))||s.enumerable});return d};var X=(d,e,t)=>(t=d!=null?V(J(d)):{},B(e||!d||!d.__esModule?D(t,"default",{value:d,enumerable:!0}):t,d)),Y=d=>B(D({},"__esModule",{value:!0}),d);var de={};Q(de,{buildMovePackage:()=>se,compileRaw:()=>ce,fetchPackageFromGitHub:()=>U,getSuiMoveVersion:()=>re,getSuiVersion:()=>oe,getWasmBindings:()=>ae,initMoveCompiler:()=>ne,resolveDependencies:()=>N,testMovePackage:()=>ie});module.exports=Y(de);var T=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},R=class extends T{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,r){let{owner:i,repo:o}=this.parseGitUrl(t);if(!i||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${o}@${s}`,p=`https://api.github.com/repos/${i}/${o}/git/trees/${s}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let y=1;y<=3;y++)try{if(y>1){let b=Math.pow(2,y-1)*1e3;await new Promise(k=>setTimeout(k,b))}let h={};this.token&&(h.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:h});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&y<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(h){if(f=h instanceof Error?h:new Error(String(h)),y===3)return{}}if(f)return{}}let l=new Map,g={},u=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(n){if(!m.path.startsWith(n))continue;f=m.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;f==="Move.toml"&&m.mode&&l.set("Move.toml",m.mode);let y=`https://raw.githubusercontent.com/${i}/${o}/${s}/${m.path}`,h=this.fetchContent(y).then(v=>{v&&(g[f]=v)});u.push(h)}if(await Promise.all(u),g["Move.toml"]&&l.get("Move.toml")==="120000"){let f=g["Move.toml"].trim(),y=n?`${n}/${f}`.replace(/\/+/g,"/"):f,h=`https://raw.githubusercontent.com/${i}/${o}/${s}/${y}`,v=await this.fetchContent(h);v&&(g["Move.toml"]=v)}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let o=await i.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function A(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 O(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 j(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=a),!n&&a===","){i.push(s),s="";continue}s+=a}s.trim()&&i.push(s);for(let o of i){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=O(c)}return e}function Z(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){s.trim()&&e.push(W(s.trim())),s="";continue}s+=a}return s.trim()&&e.push(W(s.trim())),e}function W(d){return d.startsWith("{")?j(d):O(d)}function S(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let a=A(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(i++;i<n.length&&!p.includes("]");)p+=" "+A(n[i]).trim(),i++;i<n.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+A(n[i]).trim(),i++),r.push(p)}else r.push(a),i++}function o(a,p){let c=a;for(let l of p){if(!(l in c))return;c=c[l]}return c}for(let a of r){let p=A(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),s=!0;let y=t.split("."),h=e;for(let b=0;b<y.length-1;b++){let k=y[b];k in h||(h[k]={}),h=h[k]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let l=p.match(/^\[([^\]]+)\]$/);if(l){t=l[1].trim(),s=!1;continue}let g=p.indexOf("=");if(g===-1||!t)continue;let u=p.slice(0,g).trim(),m=p.slice(g+1).trim(),f;if(m.startsWith("{")?f=j(m):m.startsWith("[")?f=Z(m):f=O(m),s){let y=t.split("."),h=o(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[u]=f}}else{let y=t.split("."),h=e;for(let b of y)b in h||(h[b]={}),h=h[b];let v=t==="package"?u.replace(/-/g,"_"):u;h[v]=f}}return e}var I=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)if(e.has(o)){if(t.has(o)){let a=[o],p=r;for(;p!==o;)a.unshift(p),p=s.get(p);return a.unshift(o),a}}else{s.set(o,r);let a=n(o);if(a)return a}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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 x=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[r,i]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==o||this.unifiedAddressTable.set(r,o)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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()}compilerInputOrder(){return this.graph.compilerInputOrder()}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.compilerInputOrder(),r=new Map;for(let i of n){if(i===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(i);if(!o)continue;let a=e.get(i)||{},p=this.extractSourcePaths(i,a),c=o.manifest.edition||"legacy",l=o.manifest.latestPublishedId||o.manifest.originalId||o.manifest.publishedAt||o.resolvedTable?.[i],g=o.manifest.originalId||o.manifest.publishedAt||o.manifest.latestPublishedId||l;g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",l=g),r.set(i,g),r.set(i.toLowerCase(),g);let u={...o.resolvedTable||{}};for(let[f,y]of Object.entries(u)){let h=r.get(f)||r.get(f.toLowerCase());h&&(u[f]=h)}g&&i!=="Sui"&&i!=="MoveStdlib"&&(u[i]=g,u[i.toLowerCase()]=g);let m={name:i,isImmediate:s.has(i),sourcePaths:p,addressMapping:u,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:l};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}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,r=(i,o)=>{let a=n.encode(`/vfs/deps/${e}/${i}`),p=n.encode(`/vfs/deps/${e}/${o}`),c=Math.min(a.length,p.length);for(let l=0;l<c;l++)if(a[l]!==p[l])return a[l]-p[l];return a.length-p.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,o]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[a]=this.reconstructDependencyMoveToml(s.name,o,s.edition,s.addressMapping):r[a]=o}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
+
`),i=[],o="none";for(let c of r){let l=c.trim();if(l.startsWith("[")){l.startsWith("[package]")?o="package":l.startsWith("[addresses]")?o="addresses":l.startsWith("[dependencies")||l.startsWith("[dev-dependencies")?o="dependencies":(o="other",i.push(c));continue}if(o==="package")l.includes("name =")||l.includes("version =");else{if(o==="addresses")continue;o!=="none"&&i.push(c)}}let a=`[package]
|
|
3
|
+
`;a+=`name = "${e}"
|
|
4
|
+
`,a+=`version = "0.0.0"
|
|
5
|
+
`,a+=`edition = "${s}"
|
|
6
|
+
`,a+=`
|
|
7
|
+
`,a+=i.join(`
|
|
8
|
+
`),a+=`
|
|
9
|
+
[addresses]
|
|
9
10
|
`,a+=`
|
|
10
|
-
[dependencies]
|
|
11
|
-
`;for(let l of c)a+=l+`
|
|
12
|
-
`;a+=`
|
|
13
11
|
[addresses]
|
|
14
|
-
`;for(let[l
|
|
15
|
-
`;return a}};var
|
|
16
|
-
`))}this.packageNameCache.set(
|
|
12
|
+
`;let p=Object.entries(n).sort(([c],[l])=>c<l?-1:c>l?1:0);for(let[c,l]of p)a+=`${c} = "${l}"
|
|
13
|
+
`;return a}};var L=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=S(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new I(n),o=await this.buildPackage(n,this.rootSource,e,t);r&&(o.manifest.edition=r);let a=o.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[n]=this.normalizeAddress(o.manifest.originalId)),i.addPackage(o),this.packageFiles.set(n,t);let c=await this.loadFromLockfile(i,o,t),l=Array.from(o.dependencies.keys()).filter(k=>!i.getPackage(k));(!c||l.length>0)&&await this.buildDependencyGraph(i,o);let g=i.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let u=new x(i,{});await u.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new $(u);await f.compute(this.packageFiles);let y=u.getUnifiedAddressTable();for(let k of i.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name==="Sui"||k.manifest.name,w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);y[k.manifest.name]=P,y[k.manifest.name.toLowerCase()]=P}}let h=this.reconstructMoveToml(s,y,!0,r),v={...t};delete v["Move.lock"],v["Move.toml"]=h;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,s,n){let r=S(s),i=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(s,i,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=n["Published.toml"],l,g;if(c)try{let P=S(c).published?.[this.network];P&&(P["published-at"]&&(l=this.normalizeAddress(P["published-at"])),P["original-id"]&&(g=this.normalizeAddress(P["original-id"])))}catch{}a.error;let u={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:l||a.publishedAt,originalId:g||a.originalId,latestPublishedId:p,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},m=Object.keys(u.addresses).find(w=>w.toLowerCase()===u.name.toLowerCase());if(m&&u.addresses[m]){let w=this.normalizeAddress(u.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(u.originalId=w)}let f=u.originalId||u.publishedAt,y=f&&f!=="0x0"?this.normalizeAddress(f):void 0,h=u.addresses[u.name],v=h?this.normalizeAddress(h):void 0;y?h||(u.addresses[u.name]=y):v?u.addresses[u.name]=v:u.addresses[u.name]="0x0";let b=new Map;if(u.dependencies)for(let[w,P]of Object.entries(u.dependencies)){let G=this.parseDependencyInfo(P);G&&b.set(w,G)}return{id:{name:u.name,version:u.version,source:t||{type:"local"}},manifest:u,dependencies:b,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[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={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 l=t.id.source.subdir||"",g=n.source.local,u=this.resolveRelativePath(l,g);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 r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let l=this.findPackageBySource(e,n.source);l&&e.addDependency(t.id.name,l.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let o=await this.fetcher.fetch(n.source.git,n.source.rev,i),a=null,p=`Move.${this.network}.toml`;for(let[l,g]of Object.entries(o))if(l.endsWith(p)){a=g;break}if(!a){for(let[l,g]of Object.entries(o))if(l.endsWith("Move.toml")){a=g;break}}if(!a)continue;let c=await this.buildPackage(s,n.source,a,o);if(!this.lockfileVersion||this.lockfileVersion<4){let l=this.packageNameCache.get(c.manifest.name);if(l){let g=u=>JSON.stringify(u);throw new Error([`Conflicting versions of package '${c.manifest.name}' found`,`Existing: ${g(l)}`,`New: ${g(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
14
|
+
`))}this.packageNameCache.set(c.manifest.name,n.source)}c.manifest.edition||(c.manifest.edition="legacy"),e.addPackage(c),e.addDependency(t.id.name,c.id.name,n),this.packageFiles.set(c.id.name,o),await this.buildDependencyGraph(e,c)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s,n){let r=S(e),i=r.package?.published_at||r.package?.["published-at"],o=i&&i!=="0x0"?i:void 0,a=o?this.normalizeAddress(o):void 0,p=r.package?.["original-id"],c,l;if(t)try{let m=S(t),f=s&&m.env?.[s]||m.env?.[n];f&&(f["original-published-id"]&&(c=this.normalizeAddress(f["original-published-id"])),f["latest-published-id"]&&(l=this.normalizeAddress(f["latest-published-id"])))}catch{}return{publishedAt:c||a||l,originalId:p||c,latestId:l}}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),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.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(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=S(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],i=n.map(c=>c.name||c.id).filter(Boolean),o=[...r,...i.filter(c=>!r.includes(c))],a=new Map,p=new Map;for(let c of n){let l=c.id||c.name,g=c.source;if(!l||!g)continue;let u=null;if(g.git&&g.rev)u={type:"git",git:g.git,rev:g.rev,subdir:g.subdir};else if(g.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",g.local);u={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let m=await this.fetcher.fetch(u.git,u.rev,u.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let y=await this.buildPackage(l,u,f,m);a.set(l,y),p.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,m),e.addPackage(y)}o.length&&e.setLockfileOrder(o);for(let c of n){let l=c.id||c.name,g=a.get(l);if(!g)continue;let u=c.dependencies;if(u&&Array.isArray(u))for(let m of u){let f=m.id||m.name,y=a.get(f)||p.get(f);if(y){let h={source:y.id.source};e.addDependency(g.id.name,y.id.name,h)}}}for(let c of s.dependencies.keys()){let l=p.get(c);if(l){let g=s.dependencies.get(c);e.addDependency(s.id.name,l.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,o=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let p=a.id,c=a.source;o.push(p);let l=null;if(c?.git&&c.rev)l={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!l.git||!l.rev)continue;let g=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(g).length===0)continue;let u=g["Move.toml"];if(!u)continue;let m=await this.buildPackage(p,l,u,g);r.set(p,m),this.packageFiles.set(m.manifest.name,g),e.addPackage(m)}e.setLockfileOrder(o);for(let a of n){let p=a.id,c=r.get(p);if(!c)continue;let l=a.dependencies;if(!(!l||!Array.isArray(l)))for(let g of l){let u=g.id,m=r.get(u);if(!m){let f=i.get(u);if(f?.source?.local&&c.id.source.type==="git"){let y=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),h={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(u,h,b,v);r.set(u,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of s.dependencies.keys()){let p=r.get(a);if(p){let c=s.dependencies.get(a);e.addDependency(s.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,l]of Object.entries(r)){p.push(c);let g=this.lockfileSourceToDependencySource(l.source);if(!g)continue;let u=await this.fetchFromSource(g);if(!u)return!1;let m=u["Move.toml"];if(!m||l["manifest-digest"]&&await this.computeManifestDigest(m)!==l["manifest-digest"])return!1;let f=await this.buildPackage(c,g,m,u);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,u),(g.type!=="local"||!("root"in l.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,l]of Object.entries(r)){let g=o.get(c);if(g&&l.deps)for(let[u,m]of Object.entries(l.deps)){let f=o.get(m);if(f){let y=g.dependencies.get(u);y&&e.addDependency(g.id.name,f.id.name,y)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let l=c.id,g=o.get(l);if(g){let u={source:g.id.source};e.addDependency(n.id.name,g.id.name,u)}}else for(let c of n.dependencies.keys()){let l=a.get(c)||o.get(c);if(l){let g=n.dependencies.get(c);e.addDependency(n.id.name,l.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)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
|
|
17
15
|
name = "${e.package.name}"
|
|
18
16
|
version = "${e.package.version}"
|
|
19
|
-
`,
|
|
17
|
+
`,o=n||e.package.edition;if(o&&(i+=`edition = "${o}"
|
|
20
18
|
`),i+=`
|
|
21
19
|
[dependencies]
|
|
22
|
-
`,e.dependencies)
|
|
23
|
-
`:
|
|
24
|
-
`:i+=`${
|
|
25
|
-
`)}i+=`
|
|
20
|
+
`,e.dependencies){let p=Object.entries(e.dependencies).sort(([c],[l])=>c.localeCompare(l));for(let[c,l]of p){let g=l;g.local?i+=`${c} = { local = "${g.local}" }
|
|
21
|
+
`:g.git&&g.rev&&(g.subdir?i+=`${c} = { git = "${g.git}", subdir = "${g.subdir}", rev = "${g.rev}" }
|
|
22
|
+
`:i+=`${c} = { git = "${g.git}", rev = "${g.rev}" }
|
|
23
|
+
`)}}i+=`
|
|
26
24
|
[addresses]
|
|
27
|
-
`;for(let[
|
|
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",
|
|
25
|
+
`;let a=Object.entries(t).sort(([p],[c])=>p.localeCompare(c));for(let[p,c]of a)i+=`${p} = "${c}"
|
|
26
|
+
`;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",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function _(d,e,t,s="mainnet",n){return new L(t,s,n||null).resolve(d,e)}function ee(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],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function U(d,e){let t=ee(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let s=e?.fetcher||new R(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":o,...a}=i;return a}return i}var C;async function M(d){return C||(C=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),C}function F(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function E(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 te(d){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let o=parseInt(n.slice(i,i+2),16);if(Number.isNaN(o))throw new Error("invalid hex digest");r.push(o)}return r};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 F(t)}}function z(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 r=S(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function ne(d){await M(d?.wasm)}async function N(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,s=await _(e,{...d.files,"Move.toml":e},new R(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 se(d){try{let e={};for(let[a,p]of Object.entries(d.files))(a.endsWith(".move")||a.endsWith("Move.toml")||a.endsWith("Move.lock")||a.endsWith("Published.toml"))&&(e[a]=p);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await N(d),s=await M(d.wasm);z(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=E(n),i=r.success(),o=r.output();return i?te(o):F(o)}catch(e){return F(e)}}async function ie(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await N(d),t=await M(d.wasm);z(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,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return F(e)}}async function re(d){return(await M(d?.wasm)).sui_move_version()}async function oe(d){return(await M(d?.wasm)).sui_version()}async function ae(d){return M(d?.wasm)}async function ce(d,e,t){let s=await M(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})),r=E(n);return{success:r.success(),output:r.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
|
package/dist/lite/index.d.cts
CHANGED
|
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
|
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
41
|
* const files = await fetchPackageFromGitHub(
|
|
42
|
-
* 'https://github.com/
|
|
42
|
+
* 'https://github.com/org/repo/tree/main/packages/example_package'
|
|
43
43
|
* );
|
|
44
44
|
*
|
|
45
45
|
* // files = {
|
package/dist/lite/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
|
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
41
|
* const files = await fetchPackageFromGitHub(
|
|
42
|
-
* 'https://github.com/
|
|
42
|
+
* 'https://github.com/org/repo/tree/main/packages/example_package'
|
|
43
43
|
* );
|
|
44
44
|
*
|
|
45
45
|
* // files = {
|
package/dist/lite/index.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
var $=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends ${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,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let d of a.tree){if(d.type!=="blob")continue;let p=d.path;if(n){if(!d.path.startsWith(n))continue;p=d.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${d.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let d=g["Move.toml"].trim();if(d.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!d.includes("[")&&!d.includes("=")){let p=d,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${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",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(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(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function R(l){let e=!1,t="";for(let s=0;s<l.length;s++){let n=l[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return l.slice(0,s)}return l}function x(l){let e=l.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 N(l){let e={},t=l.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=x(a)}return e}function _(l){let e=[],t=l.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(L(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(L(s.trim())),e}function L(l){return l.startsWith("{")?N(l):x(l)}function w(l){let e={},t=null,s=!1,n=l.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=R(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+R(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+R(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=R(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let d=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=N(p):p.startsWith("[")?m=_(p):m=x(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[d]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?d.replace(/-/g,"_"):d;h[v]=m}}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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);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=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}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,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
-
`),i=[],
|
|
3
|
-
|
|
4
|
-
`,
|
|
5
|
-
`,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`),a+=`
|
|
1
|
+
var F=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},R=class extends F{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,r){let{owner:i,repo:o}=this.parseGitUrl(t);if(!i||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${o}@${s}`,p=`https://api.github.com/repos/${i}/${o}/git/trees/${s}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let y=1;y<=3;y++)try{if(y>1){let b=Math.pow(2,y-1)*1e3;await new Promise(k=>setTimeout(k,b))}let h={};this.token&&(h.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:h});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&y<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(h){if(f=h instanceof Error?h:new Error(String(h)),y===3)return{}}if(f)return{}}let d=new Map,l={},u=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(n){if(!m.path.startsWith(n))continue;f=m.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;f==="Move.toml"&&m.mode&&d.set("Move.toml",m.mode);let y=`https://raw.githubusercontent.com/${i}/${o}/${s}/${m.path}`,h=this.fetchContent(y).then(v=>{v&&(l[f]=v)});u.push(h)}if(await Promise.all(u),l["Move.toml"]&&d.get("Move.toml")==="120000"){let f=l["Move.toml"].trim(),y=n?`${n}/${f}`.replace(/\/+/g,"/"):f,h=`https://raw.githubusercontent.com/${i}/${o}/${s}/${y}`,v=await this.fetchContent(h);v&&(l["Move.toml"]=v)}return l}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let o=await i.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function D(g){let e=!1,t="";for(let s=0;s<g.length;s++){let n=g[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return g.slice(0,s)}return g}function T(g){let e=g.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 G(g){let e={},t=g.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=a),!n&&a===","){i.push(s),s="";continue}s+=a}s.trim()&&i.push(s);for(let o of i){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=T(c)}return e}function U(g){let e=[],t=g.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===r)&&(n=!n,r=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){s.trim()&&e.push(N(s.trim())),s="";continue}s+=a}return s.trim()&&e.push(N(s.trim())),e}function N(g){return g.startsWith("{")?G(g):T(g)}function S(g){let e={},t=null,s=!1,n=g.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let a=D(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(i++;i<n.length&&!p.includes("]");)p+=" "+D(n[i]).trim(),i++;i<n.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+D(n[i]).trim(),i++),r.push(p)}else r.push(a),i++}function o(a,p){let c=a;for(let d of p){if(!(d in c))return;c=c[d]}return c}for(let a of r){let p=D(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),s=!0;let y=t.split("."),h=e;for(let b=0;b<y.length-1;b++){let k=y[b];k in h||(h[k]={}),h=h[k]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let d=p.match(/^\[([^\]]+)\]$/);if(d){t=d[1].trim(),s=!1;continue}let l=p.indexOf("=");if(l===-1||!t)continue;let u=p.slice(0,l).trim(),m=p.slice(l+1).trim(),f;if(m.startsWith("{")?f=G(m):m.startsWith("[")?f=U(m):f=T(m),s){let y=t.split("."),h=o(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[u]=f}}else{let y=t.split("."),h=e;for(let b of y)b in h||(h[b]={}),h=h[b];let v=t==="package"?u.replace(/-/g,"_"):u;h[v]=f}}return e}var A=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);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=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r){let i=Array.from(r).sort();for(let o of i)s(o)}t.push(n)};return s(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))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=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let o of i)if(e.has(o)){if(t.has(o)){let a=[o],p=r;for(;p!==o;)a.unshift(p),p=s.get(p);return a.unshift(o),a}}else{s.set(o,r);let a=n(o);if(a)return a}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);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 I=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[r,i]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==o||this.unifiedAddressTable.set(r,o)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=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()}compilerInputOrder(){return this.graph.compilerInputOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var x=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.compilerInputOrder(),r=new Map;for(let i of n){if(i===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(i);if(!o)continue;let a=e.get(i)||{},p=this.extractSourcePaths(i,a),c=o.manifest.edition||"legacy",d=o.manifest.latestPublishedId||o.manifest.originalId||o.manifest.publishedAt||o.resolvedTable?.[i],l=o.manifest.originalId||o.manifest.publishedAt||o.manifest.latestPublishedId||d;l||(l="0x0000000000000000000000000000000000000000000000000000000000000000",d=l),r.set(i,l),r.set(i.toLowerCase(),l);let u={...o.resolvedTable||{}};for(let[f,y]of Object.entries(u)){let h=r.get(f)||r.get(f.toLowerCase());h&&(u[f]=h)}l&&i!=="Sui"&&i!=="MoveStdlib"&&(u[i]=l,u[i.toLowerCase()]=l);let m={name:i,isImmediate:s.has(i),sourcePaths:p,addressMapping:u,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:d};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}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,r=(i,o)=>{let a=n.encode(`/vfs/deps/${e}/${i}`),p=n.encode(`/vfs/deps/${e}/${o}`),c=Math.min(a.length,p.length);for(let d=0;d<c;d++)if(a[d]!==p[d])return a[d]-p[d];return a.length-p.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,o]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[a]=this.reconstructDependencyMoveToml(s.name,o,s.edition,s.addressMapping):r[a]=o}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
|
|
2
|
+
`),i=[],o="none";for(let c of r){let d=c.trim();if(d.startsWith("[")){d.startsWith("[package]")?o="package":d.startsWith("[addresses]")?o="addresses":d.startsWith("[dependencies")||d.startsWith("[dev-dependencies")?o="dependencies":(o="other",i.push(c));continue}if(o==="package")d.includes("name =")||d.includes("version =");else{if(o==="addresses")continue;o!=="none"&&i.push(c)}}let a=`[package]
|
|
3
|
+
`;a+=`name = "${e}"
|
|
4
|
+
`,a+=`version = "0.0.0"
|
|
5
|
+
`,a+=`edition = "${s}"
|
|
6
|
+
`,a+=`
|
|
7
|
+
`,a+=i.join(`
|
|
8
|
+
`),a+=`
|
|
9
|
+
[addresses]
|
|
9
10
|
`,a+=`
|
|
10
|
-
[dependencies]
|
|
11
|
-
`;for(let d of c)a+=d+`
|
|
12
|
-
`;a+=`
|
|
13
11
|
[addresses]
|
|
14
|
-
`;for(let[d
|
|
15
|
-
`;return a}};var
|
|
16
|
-
`))}this.packageNameCache.set(
|
|
12
|
+
`;let p=Object.entries(n).sort(([c],[d])=>c<d?-1:c>d?1:0);for(let[c,d]of p)a+=`${c} = "${d}"
|
|
13
|
+
`;return a}};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=S(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new A(n),o=await this.buildPackage(n,this.rootSource,e,t);r&&(o.manifest.edition=r);let a=o.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[n]=this.normalizeAddress(o.manifest.originalId)),i.addPackage(o),this.packageFiles.set(n,t);let c=await this.loadFromLockfile(i,o,t),d=Array.from(o.dependencies.keys()).filter(k=>!i.getPackage(k));(!c||d.length>0)&&await this.buildDependencyGraph(i,o);let l=i.detectCycle();if(l)throw new Error(`Dependency cycle detected: ${l.join(" \u2192 ")}`);let u=new I(i,{});await u.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new x(u);await f.compute(this.packageFiles);let y=u.getUnifiedAddressTable();for(let k of i.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name==="Sui"||k.manifest.name,w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);y[k.manifest.name]=P,y[k.manifest.name.toLowerCase()]=P}}let h=this.reconstructMoveToml(s,y,!0,r),v={...t};delete v["Move.lock"],v["Move.toml"]=h;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,s,n){let r=S(s),i=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(s,i,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=n["Published.toml"],d,l;if(c)try{let P=S(c).published?.[this.network];P&&(P["published-at"]&&(d=this.normalizeAddress(P["published-at"])),P["original-id"]&&(l=this.normalizeAddress(P["original-id"])))}catch{}a.error;let u={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:d||a.publishedAt,originalId:l||a.originalId,latestPublishedId:p,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},m=Object.keys(u.addresses).find(w=>w.toLowerCase()===u.name.toLowerCase());if(m&&u.addresses[m]){let w=this.normalizeAddress(u.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(u.originalId=w)}let f=u.originalId||u.publishedAt,y=f&&f!=="0x0"?this.normalizeAddress(f):void 0,h=u.addresses[u.name],v=h?this.normalizeAddress(h):void 0;y?h||(u.addresses[u.name]=y):v?u.addresses[u.name]=v:u.addresses[u.name]="0x0";let b=new Map;if(u.dependencies)for(let[w,P]of Object.entries(u.dependencies)){let C=this.parseDependencyInfo(P);C&&b.set(w,C)}return{id:{name:u.name,version:u.version,source:t||{type:"local"}},manifest:u,dependencies:b,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[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={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 d=t.id.source.subdir||"",l=n.source.local,u=this.resolveRelativePath(d,l);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 r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let d=this.findPackageBySource(e,n.source);d&&e.addDependency(t.id.name,d.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let o=await this.fetcher.fetch(n.source.git,n.source.rev,i),a=null,p=`Move.${this.network}.toml`;for(let[d,l]of Object.entries(o))if(d.endsWith(p)){a=l;break}if(!a){for(let[d,l]of Object.entries(o))if(d.endsWith("Move.toml")){a=l;break}}if(!a)continue;let c=await this.buildPackage(s,n.source,a,o);if(!this.lockfileVersion||this.lockfileVersion<4){let d=this.packageNameCache.get(c.manifest.name);if(d){let l=u=>JSON.stringify(u);throw new Error([`Conflicting versions of package '${c.manifest.name}' found`,`Existing: ${l(d)}`,`New: ${l(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
14
|
+
`))}this.packageNameCache.set(c.manifest.name,n.source)}c.manifest.edition||(c.manifest.edition="legacy"),e.addPackage(c),e.addDependency(t.id.name,c.id.name,n),this.packageFiles.set(c.id.name,o),await this.buildDependencyGraph(e,c)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s,n){let r=S(e),i=r.package?.published_at||r.package?.["published-at"],o=i&&i!=="0x0"?i:void 0,a=o?this.normalizeAddress(o):void 0,p=r.package?.["original-id"],c,d;if(t)try{let m=S(t),f=s&&m.env?.[s]||m.env?.[n];f&&(f["original-published-id"]&&(c=this.normalizeAddress(f["original-published-id"])),f["latest-published-id"]&&(d=this.normalizeAddress(f["latest-published-id"])))}catch{}return{publishedAt:c||a||d,originalId:p||c,latestId:d}}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),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.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(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=S(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],i=n.map(c=>c.name||c.id).filter(Boolean),o=[...r,...i.filter(c=>!r.includes(c))],a=new Map,p=new Map;for(let c of n){let d=c.id||c.name,l=c.source;if(!d||!l)continue;let u=null;if(l.git&&l.rev)u={type:"git",git:l.git,rev:l.rev,subdir:l.subdir};else if(l.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",l.local);u={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let m=await this.fetcher.fetch(u.git,u.rev,u.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let y=await this.buildPackage(d,u,f,m);a.set(d,y),p.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,m),e.addPackage(y)}o.length&&e.setLockfileOrder(o);for(let c of n){let d=c.id||c.name,l=a.get(d);if(!l)continue;let u=c.dependencies;if(u&&Array.isArray(u))for(let m of u){let f=m.id||m.name,y=a.get(f)||p.get(f);if(y){let h={source:y.id.source};e.addDependency(l.id.name,y.id.name,h)}}}for(let c of s.dependencies.keys()){let d=p.get(c);if(d){let l=s.dependencies.get(c);e.addDependency(s.id.name,d.id.name,l)}}return a.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,o=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let p=a.id,c=a.source;o.push(p);let d=null;if(c?.git&&c.rev)d={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);d={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!d.git||!d.rev)continue;let l=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(l).length===0)continue;let u=l["Move.toml"];if(!u)continue;let m=await this.buildPackage(p,d,u,l);r.set(p,m),this.packageFiles.set(m.manifest.name,l),e.addPackage(m)}e.setLockfileOrder(o);for(let a of n){let p=a.id,c=r.get(p);if(!c)continue;let d=a.dependencies;if(!(!d||!Array.isArray(d)))for(let l of d){let u=l.id,m=r.get(u);if(!m){let f=i.get(u);if(f?.source?.local&&c.id.source.type==="git"){let y=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),h={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(u,h,b,v);r.set(u,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of s.dependencies.keys()){let p=r.get(a);if(p){let c=s.dependencies.get(a);e.addDependency(s.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,d]of Object.entries(r)){p.push(c);let l=this.lockfileSourceToDependencySource(d.source);if(!l)continue;let u=await this.fetchFromSource(l);if(!u)return!1;let m=u["Move.toml"];if(!m||d["manifest-digest"]&&await this.computeManifestDigest(m)!==d["manifest-digest"])return!1;let f=await this.buildPackage(c,l,m,u);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,u),(l.type!=="local"||!("root"in d.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,d]of Object.entries(r)){let l=o.get(c);if(l&&d.deps)for(let[u,m]of Object.entries(d.deps)){let f=o.get(m);if(f){let y=l.dependencies.get(u);y&&e.addDependency(l.id.name,f.id.name,y)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let d=c.id,l=o.get(d);if(l){let u={source:l.id.source};e.addDependency(n.id.name,l.id.name,u)}}else for(let c of n.dependencies.keys()){let d=a.get(c)||o.get(c);if(d){let l=n.dependencies.get(c);e.addDependency(n.id.name,d.id.name,l)}}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)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
|
|
17
15
|
name = "${e.package.name}"
|
|
18
16
|
version = "${e.package.version}"
|
|
19
|
-
`,
|
|
17
|
+
`,o=n||e.package.edition;if(o&&(i+=`edition = "${o}"
|
|
20
18
|
`),i+=`
|
|
21
19
|
[dependencies]
|
|
22
|
-
`,e.dependencies)
|
|
23
|
-
`:
|
|
24
|
-
`:i+=`${
|
|
25
|
-
`)}i+=`
|
|
20
|
+
`,e.dependencies){let p=Object.entries(e.dependencies).sort(([c],[d])=>c.localeCompare(d));for(let[c,d]of p){let l=d;l.local?i+=`${c} = { local = "${l.local}" }
|
|
21
|
+
`:l.git&&l.rev&&(l.subdir?i+=`${c} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
|
|
22
|
+
`:i+=`${c} = { git = "${l.git}", rev = "${l.rev}" }
|
|
23
|
+
`)}}i+=`
|
|
26
24
|
[addresses]
|
|
27
|
-
`;for(let[
|
|
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",
|
|
25
|
+
`;let a=Object.entries(t).sort(([p],[c])=>p.localeCompare(c));for(let[p,c]of a)i+=`${p} = "${c}"
|
|
26
|
+
`;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",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function B(g,e,t,s="mainnet",n){return new O(t,s,n||null).resolve(g,e)}function E(g){try{let e=new URL(g);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],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function z(g,e){let t=E(g);if(!t)throw new Error(`Invalid GitHub URL: ${g}`);let s=e?.fetcher||new R(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":o,...a}=i;return a}return i}var L;async function M(g){return L||(L=import("./sui_move_wasm.js").then(async e=>(g?await e.default(g):await e.default(),e))),L}function $(g){return{error:g instanceof Error?g.message:typeof g=="string"?g:"Unknown error"}}function W(g){if(typeof g!="object"||g===null)throw new Error("Unexpected compile result shape from wasm");let e=g;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 V(g){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let o=parseInt(n.slice(i,i+2),16);if(Number.isNaN(o))throw new Error("invalid hex digest");r.push(o)}return r};try{let t=JSON.parse(g);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 $(t)}}function j(g){try{let e=JSON.parse(g);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 r=S(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function pe(g){await M(g?.wasm)}async function _(g){let e=g.files["Move.toml"]||"",t=g.rootGit||g.files.__rootGit,s=await B(e,{...g.files,"Move.toml":e},new R(g.githubToken),g.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function fe(g){try{let e={};for(let[a,p]of Object.entries(g.files))(a.endsWith(".move")||a.endsWith("Move.toml")||a.endsWith("Move.lock")||a.endsWith("Published.toml"))&&(e[a]=p);g.files=e;let t=g.resolvedDependencies?g.resolvedDependencies:await _(g),s=await M(g.wasm);j(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:g.silenceWarnings,testMode:g.testMode,lintFlag:g.lintFlag,stripMetadata:g.stripMetadata})),r=W(n),i=r.success(),o=r.output();return i?V(o):$(o)}catch(e){return $(e)}}async function me(g){try{let e=g.resolvedDependencies?g.resolvedDependencies:await _(g),t=await M(g.wasm);j(e.dependencies);let s=g.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,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return $(e)}}async function he(g){return(await M(g?.wasm)).sui_move_version()}async function ye(g){return(await M(g?.wasm)).sui_version()}async function ve(g){return M(g?.wasm)}async function ke(g,e,t){let s=await M(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(g,e,!0):s.compile(g,e,JSON.stringify({silenceWarnings:!1})),r=W(n);return{success:r.success(),output:r.output()}}export{fe as buildMovePackage,ke as compileRaw,z as fetchPackageFromGitHub,he as getSuiMoveVersion,ye as getSuiVersion,ve as getWasmBindings,pe as initMoveCompiler,_ as resolveDependencies,me as testMovePackage};
|
|
@@ -110,8 +110,8 @@ function __wbg_get_imports() {
|
|
|
110
110
|
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
111
111
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
112
112
|
},
|
|
113
|
-
|
|
114
|
-
console.
|
|
113
|
+
__wbg_warn_4b3c7c44b93d17a4: function(arg0, arg1) {
|
|
114
|
+
console.warn(getStringFromWasm0(arg0, arg1));
|
|
115
115
|
},
|
|
116
116
|
};
|
|
117
117
|
return {
|
|
Binary file
|