@zktx.io/sui-move-builder 0.2.5 → 0.2.6
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 +5 -1
- package/dist/full/index.cjs +14 -13
- package/dist/full/index.d.cts +37 -1
- package/dist/full/index.d.ts +37 -1
- package/dist/full/index.js +13 -12
- package/dist/full/sui_move_wasm.d.ts +14 -1
- package/dist/full/sui_move_wasm.js +27 -0
- package/dist/full/sui_move_wasm_bg.wasm +0 -0
- package/dist/full/sui_move_wasm_bg.wasm.d.ts +2 -1
- package/dist/lite/index.cjs +14 -13
- package/dist/lite/index.d.cts +37 -1
- package/dist/lite/index.d.ts +37 -1
- package/dist/lite/index.js +13 -12
- package/dist/lite/sui_move_wasm.d.ts +13 -0
- package/dist/lite/sui_move_wasm.js +31 -0
- package/dist/lite/sui_move_wasm_bg.wasm +0 -0
- package/dist/lite/sui_move_wasm_bg.wasm.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Build Move packages in web or Node.js with Sui CLI-compatible dependency resolut
|
|
|
10
10
|
- ✅ **Verified Parity**: Audited against `sui-04dd` source code (Jan 2026), byte-level module comparison
|
|
11
11
|
- ✅ **Address Resolution**: Supports `original_id` for compilation, `published_at` for metadata (CLI-identical)
|
|
12
12
|
- ✅ **Lockfile Support**: Reads `Move.lock` v0/v3/v4 for faster, deterministic builds
|
|
13
|
+
- ✅ **Move.lock V4 Output**: Generates **V4 format** (`version = 4`) with CLI-compatible `manifest_digest`
|
|
13
14
|
- ✅ **Published.toml Support**: Reads deployment records per environment
|
|
14
15
|
- ✅ **Per-Package Editions**: Each package can use its own Move edition (legacy, 2024.alpha, 2024.beta)
|
|
15
16
|
- ✅ **Monorepo Support**: Handles local dependencies in monorepo structures
|
|
@@ -93,6 +94,8 @@ const result = await buildMovePackage({
|
|
|
93
94
|
if (result.success) {
|
|
94
95
|
console.log("Digest:", result.digest);
|
|
95
96
|
console.log("Modules:", result.modules); // Base64-encoded bytecode
|
|
97
|
+
console.log("Move.lock:", result.moveLock); // V4 lockfile content
|
|
98
|
+
console.log("Environment:", result.environment); // e.g., "mainnet"
|
|
96
99
|
} else {
|
|
97
100
|
console.error("Build failed:", result.error);
|
|
98
101
|
}
|
|
@@ -271,4 +274,5 @@ All tests verify:
|
|
|
271
274
|
|
|
272
275
|
## Roadmap
|
|
273
276
|
|
|
274
|
-
- **
|
|
277
|
+
- ✅ **Move.lock V4 Generation**: Build results now include CLI-compatible `moveLock` field
|
|
278
|
+
- **Published.toml Generation**: Future updates will include generating `Published.toml` for deployment tracking
|
package/dist/full/index.cjs
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
"use strict";var J=Object.create;var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var Y=(d,e)=>{for(var t in e)x(d,t,{get:e[t],enumerable:!0})},j=(d,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of q(e))!X.call(d,s)&&s!==t&&x(d,s,{get:()=>e[s],enumerable:!(i=K(e,s))||i.enumerable});return d};var Z=(d,e,t)=>(t=d!=null?J(Q(d)):{},j(e||!d||!d.__esModule?x(t,"default",{value:d,enumerable:!0}):t,d)),ee=d=>j(x({},"__esModule",{value:!0}),d);var ge={};Y(ge,{buildMovePackage:()=>re,compileRaw:()=>le,fetchPackageFromGitHub:()=>z,getSuiMoveVersion:()=>ae,getSuiVersion:()=>ce,getWasmBindings:()=>de,initMoveCompiler:()=>ie,resolveDependencies:()=>G,testMovePackage:()=>oe});module.exports=ee(ge);var N=class{async fetch(e,t,i){throw new Error("Not implemented")}async fetchFile(e,t,i){throw new Error("Not implemented")}},A=class extends N{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let i=t.headers.get("x-ratelimit-remaining"),s=t.headers.get("x-ratelimit-reset");i&&(this.rateLimitRemaining=parseInt(i,10)),s&&(this.rateLimitReset=parseInt(s,10)*1e3)}async fetch(t,i,s,n){let{owner:r,repo:o}=this.parseGitUrl(t);if(!r||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${r}/${o}@${i}`,p=`https://api.github.com/repos/${r}/${o}/git/trees/${i}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let b=Math.pow(2,h-1)*1e3;await new Promise(k=>setTimeout(k,b))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:y});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&&h<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(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let l=new Map,u={},g=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(s){let v=s.endsWith("/")?s:s+"/";if(!m.path.startsWith(v))continue;f=m.path.slice(v.length)}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 h=`https://raw.githubusercontent.com/${r}/${o}/${i}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(u[f]=v)});g.push(y)}if(await Promise.all(g),u["Move.toml"]&&l.get("Move.toml")==="120000"){let f=u["Move.toml"].trim(),h=s?`${s}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${i}/${h}`,v=await this.fetchContent(y);v&&(u["Move.toml"]=v)}return u}async fetchFile(t,i,s){let{owner:n,repo:r}=this.parseGitUrl(t);if(!n||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${n}/${r}/${i}/${s}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let i={},s=typeof window<"u",n=t.startsWith("https://api.github.com/");this.token&&(!s||n)&&(i.Authorization=`Bearer ${this.token}`);let r=await fetch(t,{headers:i});if(!r.ok)return null;let o=await r.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let s=new URL(t).pathname.split("/").filter(n=>n);if(s.length>=2){let n=s[1];return n.endsWith(".git")&&(n=n.slice(0,-4)),{owner:s[0],repo:n}}}catch{}return{owner:null,repo:null}}};function F(d){let e=!1,t="";for(let i=0;i<d.length;i++){let s=d[i];if((s==='"'||s==="'")&&(!e||s===t)&&(e=!e,t=s),!e&&s==="#")return d.slice(0,i)}return d}function C(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 U(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),i="",s=!1,n="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!s||a===n)&&(s=!s,n=a),!s&&a===","){r.push(i),i="";continue}i+=a}i.trim()&&r.push(i);for(let o of r){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=C(c)}return e}function te(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),i="",s=!1,n="",r=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!s||a===n)&&(s=!s,n=s?a:""),!s&&(a==="{"&&r++,a==="}"&&r--,a===","&&r===0)){i.trim()&&e.push(_(i.trim())),i="";continue}i+=a}return i.trim()&&e.push(_(i.trim())),e}function _(d){return d.startsWith("{")?U(d):C(d)}function S(d){let e={},t=null,i=!1,s=d.split(/\r?\n/),n=[],r=0;for(;r<s.length;){let a=F(s[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<s.length&&!p.includes("]");)p+=" "+F(s[r]).trim(),r++;r<s.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+F(s[r]).trim(),r++),n.push(p)}else n.push(a),r++}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 n){let p=F(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),i=!0;let h=t.split("."),y=e;for(let b=0;b<h.length-1;b++){let k=h[b];k in y||(y[k]={}),y=y[k]}let v=h[h.length-1];Array.isArray(y[v])||(y[v]=[]),y[v].push({});continue}let l=p.match(/^\[([^\]]+)\]$/);if(l){t=l[1].trim(),i=!1;continue}let u=p.indexOf("=");if(u===-1||!t)continue;let g=p.slice(0,u).trim(),m=p.slice(u+1).trim(),f;if(m.startsWith("{")?f=U(m):m.startsWith("[")?f=te(m):f=C(m),i){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[g]=f}}else{let h=t.split("."),y=e;for(let b of h)b in y||(y[b]={}),y=y[b];let v=t==="package"?g.replace(/-/g,"_"):g;y[v]=f}}return e}var O=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,i){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,i=new Set,s=n=>{if(i.has(n))return;i.add(n),t.add(n);let r=this.graph.get(n);if(r)for(let o of r)s(o)};return s(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n){let r=Array.from(n).sort();for(let o of r)i(o)}t.push(s)};return i(this.root),t.filter(s=>s!==this.root)}compilerInputOrder(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n){let r=Array.from(n).sort();for(let o of r)i(o)}t.push(s)};return i(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n)for(let r of Array.from(n))i(r);t.push(s)};i(this.root);for(let s of this.packageTable.keys())i(s);return t}detectCycle(){let e=new Set,t=new Set,i=new Map,s=n=>{e.add(n),t.add(n);let r=this.graph.get(n);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=n;for(;p!==o;)a.unshift(p),p=i.get(p);return a.unshift(o),a}}else{i.set(o,n);let a=s(o);if(a)return a}return t.delete(n),null};for(let n of this.packageTable.keys())if(!e.has(n)){let r=s(n);if(r)return r}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var $=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let i of t){let s=this.graph.getPackage(i);if(s)for(let[n,r]of Object.entries(s.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(n)&&this.unifiedAddressTable.get(n)!==o||this.unifiedAddressTable.set(n,o)}}for(let i of this.graph.getAllPackages()){let s={};for(let[n,r]of this.unifiedAddressTable.entries())s[n]=r;this.packageResolvedTables.set(i.id.name,s),i.resolvedTable=s}}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,i]of this.unifiedAddressTable.entries())e[t]=i;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 T=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 i=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),s=this.resolvedGraph.compilerInputOrder(),n=new Map;for(let r of s){if(r===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(r);if(!o)continue;let a=e.get(r)||{},p=this.extractSourcePaths(r,a),c=o.manifest.edition||"legacy",l=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],u=o.manifest.originalId;!u&&o.manifest.publishedAt&&(u=o.manifest.publishedAt),u||(u="0x0000000000000000000000000000000000000000000000000000000000000000",l||(l=u)),n.set(r,u),n.set(r.toLowerCase(),u);let g={...o.resolvedTable||{}};for(let[f,h]of Object.entries(g)){let y=n.get(f)||n.get(f.toLowerCase());y&&(g[f]=y)}u&&r!=="Sui"&&r!=="MoveStdlib"&&(g[r]=u,g[r.toLowerCase()]=u);let m={name:r,isImmediate:i.has(r),sourcePaths:p,addressMapping:g,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){return Object.keys(t).filter(s=>s.endsWith("Move.toml")||s.endsWith("Move.lock")?!1:s.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let i of this.dependencies){let s=e.get(i.name)||{},n={};for(let[r,o]of Object.entries(s)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${i.name}/${r}`;r.endsWith("Move.toml")?n[a]=this.reconstructDependencyMoveToml(i.name,o,i.edition,i.addressMapping):n[a]=o}t.push({name:i.name,files:n,edition:i.edition,addressMapping:i.addressMapping,publishedIdForOutput:i.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,i,s){let n=(t||"").split(`
|
|
2
|
-
`),
|
|
1
|
+
"use strict";var q=Object.create;var $=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var ee=(c,e)=>{for(var t in e)$(c,t,{get:e[t],enumerable:!0})},j=(c,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of X(e))!Z.call(c,n)&&n!==t&&$(c,n,{get:()=>e[n],enumerable:!(r=Q(e,n))||r.enumerable});return c};var te=(c,e,t)=>(t=c!=null?q(Y(c)):{},j(e||!c||!c.__esModule?$(t,"default",{value:c,enumerable:!0}):t,c)),se=c=>j($({},"__esModule",{value:!0}),c);var fe={};ee(fe,{buildMovePackage:()=>ce,compileRaw:()=>pe,fetchPackageFromGitHub:()=>H,getSuiMoveVersion:()=>le,getSuiVersion:()=>ge,getWasmBindings:()=>ue,initMoveCompiler:()=>ae,resolveDependencies:()=>W,testMovePackage:()=>de});module.exports=se(fe);var C=class{async fetch(e,t,r){throw new Error("Not implemented")}async fetchFile(e,t,r){throw new Error("Not implemented")}getResolvedSha(e,t){}},D=class extends C{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.resolvedShaCache=new Map,this.token=t}getResolvedSha(t,r){let{owner:n,repo:s}=this.parseGitUrl(t);if(!n||!s)return;let i=`${n}/${s}@${r}`;return this.resolvedShaCache.get(i)}updateRateLimit(t){let r=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");r&&(this.rateLimitRemaining=parseInt(r,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,r,n,s){let{owner:i,repo:o}=this.parseGitUrl(t);if(!i||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${o}@${r}`,h=`https://api.github.com/repos/${i}/${o}/git/trees/${r}?recursive=1`,d;if(this.treeCache.has(a))d=this.treeCache.get(a);else{let u=null;for(let f=1;f<=3;f++)try{if(f>1){let b=Math.pow(2,f-1)*1e3;await new Promise(k=>setTimeout(k,b))}let v={};this.token&&(v.Authorization=`Bearer ${this.token}`);let y=await fetch(h,{headers:v});if(this.updateRateLimit(y),!y.ok){if(y.status===403||y.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(y.status>=500&&y.status<600&&f<3){u=new Error(`Failed to fetch tree: ${y.statusText}`);continue}throw new Error(`Failed to fetch tree: ${y.statusText}`)}d=await y.json(),this.treeCache.set(a,d),d.sha&&this.resolvedShaCache.set(a,d.sha);break}catch(v){if(u=v instanceof Error?v:new Error(String(v)),f===3)return{}}if(u)return{}}let p=new Map,g={},l=[];for(let m of d.tree){if(m.type!=="blob")continue;let u=m.path;if(n){let y=n.endsWith("/")?n:n+"/";if(!m.path.startsWith(y))continue;u=m.path.slice(y.length)}if(!u.endsWith(".move")&&u!=="Move.toml"&&u!=="Move.lock"&&!u.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;u==="Move.toml"&&m.mode&&p.set("Move.toml",m.mode);let f=`https://raw.githubusercontent.com/${i}/${o}/${r}/${m.path}`,v=this.fetchContent(f).then(y=>{y&&(g[u]=y)});l.push(v)}if(await Promise.all(l),g["Move.toml"]&&p.get("Move.toml")==="120000"){let u=g["Move.toml"].trim(),f=n?`${n}/${u}`.replace(/\/+/g,"/"):u,v=`https://raw.githubusercontent.com/${i}/${o}/${r}/${f}`,y=await this.fetchContent(v);y&&(g["Move.toml"]=y)}return g}async fetchFile(t,r,n){let{owner:s,repo:i}=this.parseGitUrl(t);if(!s||!i)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${s}/${i}/${r}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let r={},n=typeof window<"u",s=t.startsWith("https://api.github.com/");this.token&&(!n||s)&&(r.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:r});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(s=>s);if(n.length>=2){let s=n[1];return s.endsWith(".git")&&(s=s.slice(0,-4)),{owner:n[0],repo:s}}}catch{}return{owner:null,repo:null}}};function x(c){let e=!1,t="";for(let r=0;r<c.length;r++){let n=c[r];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return c.slice(0,r)}return c}function _(c){let e=c.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 E(c){let e={},t=c.trim().replace(/^\{/,"").replace(/\}$/,""),r="",n=!1,s="",i=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===s)&&(n=!n,s=a),!n&&a===","){i.push(r),r="";continue}r+=a}r.trim()&&i.push(r);for(let o of i){let a=o.indexOf("=");if(a===-1)continue;let h=o.slice(0,a).trim(),d=o.slice(a+1).trim();e[h]=_(d)}return e}function ne(c){let e=[],t=c.trim().replace(/^\[/,"").replace(/\]$/,""),r="",n=!1,s="",i=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===s)&&(n=!n,s=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){r.trim()&&e.push(U(r.trim())),r="";continue}r+=a}return r.trim()&&e.push(U(r.trim())),e}function U(c){return c.startsWith("{")?E(c):_(c)}function S(c){let e={},t=null,r=!1,n=c.split(/\r?\n/),s=[],i=0;for(;i<n.length;){let a=x(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let h=a;for(i++;i<n.length&&!h.includes("]");)h+=" "+x(n[i]).trim(),i++;i<n.length&&h.includes("[")&&!h.includes("]")&&(h+=" "+x(n[i]).trim(),i++),s.push(h)}else s.push(a),i++}function o(a,h){let d=a;for(let p of h){if(!(p in d))return;d=d[p]}return d}for(let a of s){let h=x(a).trim();if(!h)continue;let d=h.match(/^\[\[([^\]]+)\]\]$/);if(d){t=d[1].trim(),r=!0;let f=t.split("."),v=e;for(let b=0;b<f.length-1;b++){let k=f[b];k in v||(v[k]={}),v=v[k]}let y=f[f.length-1];Array.isArray(v[y])||(v[y]=[]),v[y].push({});continue}let p=h.match(/^\[([^\]]+)\]$/);if(p){t=p[1].trim(),r=!1;continue}let g=h.indexOf("=");if(g===-1||!t)continue;let l=h.slice(0,g).trim(),m=h.slice(g+1).trim(),u;if(m.startsWith("{")?u=E(m):m.startsWith("[")?u=ne(m):u=_(m),r){let f=t.split("."),v=o(e,f);if(Array.isArray(v)&&v.length>0){let y=v[v.length-1];y[l]=u}}else{let f=t.split("."),v=e;for(let b of f)b in v||(v[b]={}),v=v[b];let y=t==="package"?l.replace(/-/g,"_"):l;v[y]=u}}return e}var O=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,r){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,r=new Set,n=s=>{if(r.has(s))return;r.add(s),t.add(s);let i=this.graph.get(s);if(i)for(let o of i)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],r=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let i=Array.from(s).sort();for(let o of i)r(o)}t.push(n)};return r(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],r=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let i=Array.from(s).sort();for(let o of i)r(o)}t.push(n)};return r(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],r=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s)for(let i of Array.from(s))r(i);t.push(n)};r(this.root);for(let n of this.packageTable.keys())r(n);return t}detectCycle(){let e=new Set,t=new Set,r=new Map,n=s=>{e.add(s),t.add(s);let i=this.graph.get(s);if(i)for(let o of i)if(e.has(o)){if(t.has(o)){let a=[o],h=s;for(;h!==o;)a.unshift(h),h=r.get(h);return a.unshift(o),a}}else{r.set(o,s);let a=n(o);if(a)return a}return t.delete(s),null};for(let s of this.packageTable.keys())if(!e.has(s)){let i=n(s);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 F=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 r of t){let n=this.graph.getPackage(r);if(n)for(let[s,i]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(i);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==o||this.unifiedAddressTable.set(s,o)}}for(let r of this.graph.getAllPackages()){let n={};for(let[s,i]of this.unifiedAddressTable.entries())n[s]=i;this.packageResolvedTables.set(r.id.name,n),r.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,r]of this.unifiedAddressTable.entries())e[t]=r;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 L=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 r=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.compilerInputOrder(),s=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)||{},h=this.extractSourcePaths(i,a),d=o.manifest.edition||"legacy",p=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[i],g=o.manifest.originalId;!g&&o.manifest.publishedAt&&(g=o.manifest.publishedAt),g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",p||(p=g)),s.set(i,g),s.set(i.toLowerCase(),g);let l={...o.resolvedTable||{}};for(let[y,b]of Object.entries(l)){let k=s.get(y)||s.get(y.toLowerCase());k&&(l[y]=k)}g&&i!=="Sui"&&i!=="MoveStdlib"&&(l[i]=g,l[i.toLowerCase()]=g);let m=o.id.source,u={type:m.type,git:m.git,rev:m.rev,subdir:m.subdir,local:m.local},f=Object.keys(o.manifest.dependencies||{}),v={name:i,isImmediate:r.has(i),sourcePaths:h,addressMapping:l,compilerConfig:{edition:d,flavor:"sui"},moduleFormat:h.length>0?"Source":"Bytecode",edition:d,publishedIdForOutput:p,source:u,manifestDeps:f,manifest:{name:o.manifest.name,dependencies:o.manifest.dependencies}};this.dependencies.push(v)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}extractSourcePaths(e,t){return Object.keys(t).filter(n=>n.endsWith("Move.toml")||n.endsWith("Move.lock")?!1:n.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let r of this.dependencies){let n=e.get(r.name)||{},s={};for(let[i,o]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${r.name}/${i}`;i.endsWith("Move.toml")?s[a]=this.reconstructDependencyMoveToml(r.name,o,r.edition,r.addressMapping):s[a]=o}t.push({name:r.name,files:s,edition:r.edition,addressMapping:r.addressMapping,publishedIdForOutput:r.publishedIdForOutput,source:r.source,manifestDeps:r.manifestDeps,manifest:r.manifest})}return t}reconstructDependencyMoveToml(e,t,r,n){let s=(t||"").split(`
|
|
2
|
+
`),i=[],o="none";for(let d of s){let p=d.trim();if(p.startsWith("[")){p.startsWith("[package]")?o="package":p.startsWith("[addresses]")?o="addresses":p.startsWith("[dependencies")||p.startsWith("[dev-dependencies")?o="dependencies":(o="other",i.push(d));continue}if(o==="package")(p.startsWith("name")||p.startsWith("version")||p.startsWith("edition")||p.startsWith("published-at")||p.startsWith("original-published-id"))&&(p.startsWith("published-at")||p.startsWith("original-published-id"))&&i.push(d);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&i.push(d)}}let a=`[package]
|
|
3
3
|
`;a+=`name = "${e}"
|
|
4
4
|
`,a+=`version = "0.0.0"
|
|
5
|
-
`,a+=`edition = "${
|
|
5
|
+
`,a+=`edition = "${r}"
|
|
6
6
|
`,a+=`
|
|
7
|
-
`,a+=
|
|
7
|
+
`,a+=i.join(`
|
|
8
8
|
`),a+=`
|
|
9
9
|
[addresses]
|
|
10
|
-
`;let
|
|
11
|
-
`;return a}};var
|
|
12
|
-
`))}}}this.packageNameCache.set(
|
|
10
|
+
`;let h=Object.entries(n);for(let[d,p]of h)a+=`${d} = "${p}"
|
|
11
|
+
`;return a}};var G=class{constructor(e,t="mainnet",r=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=r}async resolve(e,t){let r=S(e),n=r.package?.name||"RootPackage",s=r.package?.edition,i=new O(n),o=await this.buildPackage(n,this.rootSource,e,t);s&&(o.manifest.edition=s);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 d=await this.loadFromLockfile(i,o,t),p=Array.from(o.dependencies.keys()).filter(k=>!i.getPackage(k));(!d||p.length>0)&&await this.buildDependencyGraph(i,o);let g=i.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let l=new F(i,{});await l.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let u=new L(l);await u.compute(this.packageFiles);let f=l.getUnifiedAddressTable();for(let k of i.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name===o.manifest.name){let P=Object.keys(k.manifest.addresses).find(A=>A.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let A=this.normalizeAddress(k.manifest.addresses[P]);f[k.manifest.name]=A,f[k.manifest.name.toLowerCase()]=A;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);f[k.manifest.name]=P,f[k.manifest.name.toLowerCase()]=P;continue}let M=Object.keys(k.manifest.addresses).find(P=>P.toLowerCase()===k.manifest.name.toLowerCase());if(M&&k.manifest.addresses[M]){let P=this.normalizeAddress(k.manifest.addresses[M]);f[k.manifest.name]=P,f[k.manifest.name.toLowerCase()]=P;continue}}let v=this.reconstructMoveToml(r,o.manifest.dependencies,f,!0,s),y={...t};delete y["Move.lock"],y["Move.toml"]=v;let b=u.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(b)}}async buildPackage(e,t,r,n){let s=S(r),i=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(r,i,o,this.network),h=a.latestId?this.normalizeAddress(a.latestId):void 0,d=n["Published.toml"],p,g;if(d)try{let R=S(d).published?.[this.network];R&&(R["published-at"]&&(p=this.normalizeAddress(R["published-at"])),R["original-id"]&&(g=this.normalizeAddress(R["original-id"])))}catch{}a.error;let l={name:s.package?.name||e,version:s.package?.version||"0.0.0",edition:s.package?.edition,publishedAt:p||a.publishedAt,originalId:g||a.originalId,latestPublishedId:h,addresses:s.addresses||{},dependencies:this.injectImplicitDependencies(s.dependencies||{},s.package?.name),devDependencies:s["dev-dependencies"]},m=Object.keys(l.addresses).find(w=>w.toLowerCase()===l.name.toLowerCase());if(m&&l.addresses[m]){let w=this.normalizeAddress(l.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(l.originalId=w)}let u=l.originalId||l.publishedAt,f=u&&u!=="0x0"?this.normalizeAddress(u):void 0,v=l.addresses[l.name]||(m?l.addresses[m]:void 0),y=v?this.normalizeAddress(v):void 0;f?v||(l.addresses[l.name]=f):y?l.addresses[l.name]=y:l.addresses[l.name]="0x0";let b=new Map;if(l.dependencies)for(let[w,R]of Object.entries(l.dependencies)){let M=this.parseDependencyInfo(R);M&&b.set(w,M)}return{id:{name:l.name,version:l.version,source:t||{type:"local"}},manifest:l,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},e.isImplicit&&(t.source.isImplicit=!0);else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let r=e["addr-subst"]||e.addr_subst,n={};for(let[s,i]of Object.entries(r))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[s]={type:"assign",address:i}:n[s]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){let r=Array.from(t.dependencies.entries()).sort(([,n],[,s])=>{let i=n.source.isImplicit?1:0;return(s.source.isImplicit?1:0)-i});for(let[n,s]of r){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let l=t.id.source.subdir||"",m=s.source.local,u=this.resolveRelativePath(l,m);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:u}}else continue;if(s.source.type!=="git")continue;let i=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(i)){let l=this.findPackageBySource(e,s.source);l&&e.addDependency(t.id.name,l.id.name,s);continue}this.visited.add(i);let o=s.source.subdir;!o&&s.source.git&&this.isSuiRepo(s.source.git)&&(o=this.inferSuiFrameworkSubdir(n),o&&(s.source.subdir=o));let a=await this.fetcher.fetch(s.source.git,s.source.rev,o),h=this.fetcher.getResolvedSha(s.source.git,s.source.rev);h&&(s.source.rev=h);let d=null,p=`Move.${this.network}.toml`;for(let[l,m]of Object.entries(a))if(l.endsWith(p)){d=m;break}if(!d){for(let[l,m]of Object.entries(a))if(l.endsWith("Move.toml")){d=m;break}}if(!d)continue;let g=await this.buildPackage(n,s.source,d,a);if(!this.lockfileVersion||this.lockfileVersion<4){let l=this.packageNameCache.get(g.manifest.name);if(l){let m=l.isImplicit,u=s.source.isImplicit;if(m&&!u)continue;if(!(!m&&u)){if(JSON.stringify(l)!==JSON.stringify(s.source)){let f=v=>JSON.stringify(v);throw new Error([`Conflicting versions of package '${g.manifest.name}' found`,`Existing: ${f(l)}`,`New: ${f(s.source)}`,`When resolving dependencies for '${t.id.name}' -> '${n}'`].join(`
|
|
12
|
+
`))}}}this.packageNameCache.set(g.manifest.name,s.source)}g.manifest.edition||(g.manifest.edition="legacy"),e.addPackage(g),e.addDependency(t.id.name,g.id.name,s),this.packageFiles.set(g.id.name,a),await this.buildDependencyGraph(e,g)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,r,n){let s=S(e),i=s.package?.published_at||s.package?.["published-at"],o=i&&i!=="0x0"?i:void 0,a=o?this.normalizeAddress(o):void 0,h=s.package?.["original-id"],d,p;if(t)try{let u=S(t),f=r&&u.env?.[r]||u.env?.[n];f&&(f["original-published-id"]&&(d=this.normalizeAddress(f["original-published-id"])),f["latest-published-id"]&&(p=this.normalizeAddress(f["latest-published-id"])))}catch{}let g=a||p||d;return{publishedAt:g,originalId:h||d,latestId:g}}findPackageBySource(e,t){for(let r of e.getAllPackages()){let n=r.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return r}}resolveRelativePath(e,t){let r=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),s=[...r];for(let i of n)i===".."?s.length>0&&s.pop():i!=="."&&s.push(i);return s.join("/")}async computeManifestDigest(e){let r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,r){let n=r["Move.lock"];if(!n)return!1;let s=S(n);this.lockfileVersion=s.move?.version;let i=s.move?.version;return i===3?await this.loadFromLockfileV3(e,s,t):i&&i>=4?s.pinned?await this.loadFromLockfileV4(e,s,r,t):!1:await this.loadFromLockfileV0(e,s,t)}async loadFromLockfileV0(e,t,r){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(d=>d.name||d.id||d).filter(Boolean):[],i=n.map(d=>d.name||d.id).filter(Boolean),o=[...s,...i.filter(d=>!s.includes(d))],a=new Map,h=new Map;for(let d of n){let p=d.id||d.name,g=d.source;if(!p||!g)continue;let l=null;if(g.git&&g.rev)l={type:"git",git:g.git,rev:g.rev,subdir:g.subdir};else if(g.local&&this.rootSource?.type==="git"){let v=this.resolveRelativePath(this.rootSource.subdir||"",g.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:v}}else continue;let m=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(m).length===0)continue;let u=m["Move.toml"];if(!u)continue;let f=await this.buildPackage(p,l,u,m);a.set(p,f),h.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,m),e.addPackage(f)}o.length&&e.setLockfileOrder(o);for(let d of n){let p=d.id||d.name,g=a.get(p);if(!g)continue;let l=d.dependencies;if(l&&Array.isArray(l))for(let m of l){let u=m.id||m.name,f=a.get(u)||h.get(u);if(f){let v={source:f.id.source};e.addDependency(g.id.name,f.id.name,v)}}}for(let d of r.dependencies.keys()){let p=h.get(d);if(p){let g=r.dependencies.get(d);e.addDependency(r.id.name,p.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,r){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=new Map,i=new Map,o=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let h=a.id,d=a.source;o.push(h);let p=null;if(d?.git&&d.rev)p={type:"git",git:d.git,rev:d.rev,subdir:d.subdir};else if(d?.local&&this.rootSource?.type==="git"){let u=this.resolveRelativePath(this.rootSource.subdir||"",d.local);p={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:u}}else continue;if(!p.git||!p.rev)continue;let g=await this.fetcher.fetch(p.git,p.rev,p.subdir);if(Object.keys(g).length===0)continue;let l=g["Move.toml"];if(!l)continue;let m=await this.buildPackage(h,p,l,g);s.set(h,m),this.packageFiles.set(m.manifest.name,g),e.addPackage(m)}e.setLockfileOrder(o);for(let a of n){let h=a.id,d=s.get(h);if(!d)continue;let p=a.dependencies;if(!(!p||!Array.isArray(p)))for(let g of p){let l=g.id,m=s.get(l);if(!m){let u=i.get(l);if(u?.source?.local&&d.id.source.type==="git"){let f=this.resolveRelativePath(d.id.source.subdir||"",u.source.local),v={type:"git",git:d.id.source.git,rev:d.id.source.rev,subdir:f},y=await this.fetcher.fetch(v.git,v.rev,v.subdir),b=y["Move.toml"];if(b){let k=await this.buildPackage(l,v,b,y);s.set(l,k),this.packageFiles.set(k.manifest.name,y),e.addPackage(k),m=k}}}if(m){let u={source:m.id.source};e.addDependency(d.id.name,m.id.name,u)}}}for(let a of r.dependencies.keys()){let h=s.get(a);if(h){let d=r.dependencies.get(a);e.addDependency(r.id.name,h.id.name,d)}}return!0}async loadFromLockfileV4(e,t,r,n){let s=t.pinned?.[this.network];if(!s)return!1;let i=r["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,h=[];for(let[d,p]of Object.entries(s)){h.push(d);let g=this.lockfileSourceToDependencySource(p.source);if(!g)continue;let l=await this.fetchFromSource(g);if(!l)return!1;let m=l["Move.toml"];if(!m||p["manifest-digest"]&&await this.computeManifestDigest(m)!==p["manifest-digest"])return!1;let u=await this.buildPackage(d,g,m,l);o.set(d,u),a.set(u.manifest.name,u),this.packageFiles.set(u.manifest.name,l),(g.type!=="local"||!("root"in p.source))&&e.addPackage(u)}h.length>0&&e.setLockfileOrder(h);for(let[d,p]of Object.entries(s)){let g=o.get(d);if(g&&p.deps)for(let[l,m]of Object.entries(p.deps)){let u=o.get(m);if(u){let f=g.dependencies.get(l);f&&e.addDependency(g.id.name,u.id.name,f)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let d of t.move.dependencies){let p=d.id,g=o.get(p);if(g){let l={source:g.id.source};e.addDependency(n.id.name,g.id.name,l)}}else for(let d of n.dependencies.keys()){let p=a.get(d)||o.get(d);if(p){let g=n.dependencies.get(d);e.addDependency(n.id.name,p.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,r,n,s){let o=`[package]
|
|
13
13
|
name = "${e.package.name}"
|
|
14
14
|
version = "${e.package.version}"
|
|
15
|
-
`,a=
|
|
15
|
+
`,a=s||e.package.edition;if(a&&(o+=`edition = "${a}"
|
|
16
16
|
`),o+=`
|
|
17
17
|
[dependencies]
|
|
18
|
-
`,t){let
|
|
19
|
-
`:
|
|
20
|
-
`:o+=`${
|
|
18
|
+
`,t){let d=Object.entries(t);for(let[p,g]of d){let l=g;l.local?o+=`${p} = { local = "${l.local}" }
|
|
19
|
+
`:l.git&&l.rev&&(l.subdir?o+=`${p} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
|
|
20
|
+
`:o+=`${p} = { git = "${l.git}", rev = "${l.rev}" }
|
|
21
21
|
`)}}o+=`
|
|
22
22
|
[addresses]
|
|
23
|
-
`;let
|
|
24
|
-
`;return o}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()]}injectImplicitDependencies(e,t){return t==="Sui"||t==="MoveStdlib"||t==="SuiSystem"||t==="sui"||!e.Sui&&!e.sui&&(e.Sui={git:"https://github.com/MystenLabs/sui.git",subdir:"crates/sui-framework/packages/sui-framework",rev:"framework/mainnet",isImplicit:!0}),e}};async function
|
|
23
|
+
`;let h=Object.entries(r);for(let[d,p]of h)o+=`${d} = "${p}"
|
|
24
|
+
`;return o}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()]}injectImplicitDependencies(e,t){return t==="Sui"||t==="MoveStdlib"||t==="SuiSystem"||t==="sui"||!e.Sui&&!e.sui&&(e.Sui={git:"https://github.com/MystenLabs/sui.git",subdir:"crates/sui-framework/packages/sui-framework",rev:"framework/mainnet",isImplicit:!0}),e}};async function z(c,e,t,r="mainnet",n){return new G(t,r,n||null).resolve(c,e)}var ie=4;function T(c){return c.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function V(c,e,t,r,n,s){let i=[];i.push("# Generated by move; do not edit"),i.push("# This file should be checked in."),i.push(""),i.push("[move]"),i.push(`version = ${ie}`),i.push("");try{let o=JSON.parse(c),a=new Map(o.map(g=>[g.name,g])),h=(g,l)=>{let m=l.map(u=>{let f=g?.[u];return f?.git?{name:u,git:f.git,subdir:f.subdir||"",rev:f.rev||"",use_environment:t}:f?.local?{name:u,local:f.local,use_environment:t}:{name:u,use_environment:t}});return JSON.stringify({deps:m})},d=r||[];i.push(`[pinned.${t}.${e}]`),i.push("source = { root = true }"),i.push(`use_environment = "${t}"`);let p=n?n(h(s,d)):"";if(i.push(`manifest_digest = "${p}"`),d.length>0){let g=d.sort().map(l=>`${l} = "${l}"`);i.push(`deps = { ${g.join(", ")} }`)}else i.push("deps = {}");i.push("");for(let g of o){let l=g.name,m=`pinned.${t}.${l}`;i.push(`[${m}]`);let u=g.source;u?.type==="git"&&u?.git&&u?.rev?i.push(`source = { git = "${T(u.git)}", subdir = "${T(u.subdir||"")}", rev = "${T(u.rev)}" }`):u?.type==="local"&&u?.local?i.push(`source = { local = "${T(u.local)}" }`):i.push("source = { root = true }");let f=g.manifestDeps||Object.keys(g.manifest?.dependencies||{});i.push(`use_environment = "${t}"`);let v=n?n(h(g.manifest?.dependencies,f)):"";if(i.push(`manifest_digest = "${v}"`),f.length>0){let y=f.sort().map(b=>`${b} = "${b}"`);i.push(`deps = { ${y.join(", ")} }`)}else i.push("deps = {}");i.push("")}}catch{i.push(`[pinned.${t}.${e}]`),i.push("source = { root = true }"),i.push(`use_environment = "${t}"`),i.push('manifest_digest = ""'),i.push("deps = {}"),i.push("")}return i.join(`
|
|
25
|
+
`)}function re(c){try{let e=new URL(c);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let r=t[0],n=t[1],s="main",i;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:r,repo:n,ref:s,subdir:i}}catch{return null}}async function H(c,e){let t=re(c);if(!t)throw new Error(`Invalid GitHub URL: ${c}`);let r=e?.fetcher||new D(e?.githubToken),n=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,i=await r.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":o,...a}=i;return a}return i}var B;async function I(c){return B||(B=import("./sui_move_wasm.js").then(async e=>(c?await e.default(c):await e.default(),e))),B}function N(c){return{error:c instanceof Error?c.message:typeof c=="string"?c:"Unknown error"}}function J(c){if(typeof c!="object"||c===null)throw new Error("Unexpected compile result shape from wasm");let e=c;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 oe(c,e,t,r){let n=s=>{let i=s.startsWith("0x")?s.slice(2):s,o=i.length%2===0?i:`0${i}`,a=[];for(let h=0;h<o.length;h+=2){let d=parseInt(o.slice(h,h+2),16);if(Number.isNaN(d))throw new Error("invalid hex digest");a.push(d)}return a};try{let s=JSON.parse(c);if(!s.modules||!s.dependencies||!s.digest)throw new Error("missing fields in compiler output");let i=typeof s.digest=="string"?n(s.digest):Array.from(s.digest),o=s.dependencies;return e&&(o=Array.from(e.keys()).filter(a=>a!=="0x0000000000000000000000000000000000000000000000000000000000000000"),o.sort((a,h)=>{let d=e.get(a)||"",p=e.get(h)||"";return d<p?-1:d>p?1:0})),{modules:s.modules,dependencies:o,digest:i,moveLock:t||"",environment:r||"mainnet"}}catch(s){return N(s)}}function K(c){try{let e=JSON.parse(c);for(let t of e){let r=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let s=S(n[1]);return s.addresses&&s.addresses[t.name]||s.package?.published_at||s.package?.["published-at"]})()}}catch{}}async function ae(c){await I(c?.wasm)}async function W(c){let e=c.files["Move.toml"]||"",t=c.rootGit||c.files.__rootGit,r=await z(e,{...c.files,"Move.toml":e},new D(c.githubToken),c.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:r.files,dependencies:r.dependencies}}async function ce(c){let e=c.network||"mainnet";try{let t={};for(let[u,f]of Object.entries(c.files))(u.endsWith(".move")||u.endsWith("Move.toml")||u.endsWith("Move.lock")||u.endsWith("Published.toml"))&&(t[u]=f);c.files=t,c.onProgress?.({type:"resolve_start"});let r=c.resolvedDependencies?c.resolvedDependencies:await W(c),n=0;try{n=JSON.parse(r.dependencies).length}catch{}c.onProgress?.({type:"resolve_complete",count:n});let s=await I(c.wasm);K(r.dependencies);let i=new Map,o="Package";try{let u=JSON.parse(r.dependencies),f=c.files["Move.toml"],v=[];if(f){let y=S(f);y.package?.name&&(o=y.package.name),y.dependencies&&(v=Object.keys(y.dependencies))}for(let y of u)!y.publishedIdForOutput||y.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(y.publishedIdForOutput)||i.set(y.publishedIdForOutput,y.name)}catch{}c.onProgress?.({type:"compile_start"});let a=s.compile(r.files,r.dependencies,JSON.stringify({silenceWarnings:c.silenceWarnings,testMode:c.testMode,lintFlag:c.lintFlag,stripMetadata:c.stripMetadata})),h=J(a),d=h.success(),p=h.output();if(c.onProgress?.({type:"compile_complete"}),!d)return N(p);c.onProgress?.({type:"lockfile_generate"});let g=[],l;try{let u=c.files["Move.toml"];if(u){let f=S(u);f.dependencies&&(g=Object.keys(f.dependencies),l=f.dependencies)}}catch{}let m=V(r.dependencies,o,e,g,s.compute_manifest_digest,l);return oe(p,i,m,e)}catch(t){return N(t)}}async function de(c){try{let e=c.resolvedDependencies?c.resolvedDependencies:await W(c),t=await I(c.wasm);K(e.dependencies);let r=c.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof r.passed=="boolean"&&typeof r.output=="string")return{passed:r.passed,output:r.output};let n=typeof r.passed=="function"?r.passed():r.passed,s=typeof r.output=="function"?r.output():r.output;return{passed:n,output:s}}catch(e){return N(e)}}async function le(c){return(await I(c?.wasm)).sui_move_version()}async function ge(c){return(await I(c?.wasm)).sui_version()}async function ue(c){return I(c?.wasm)}async function pe(c,e,t){let r=await I(t?.wasm),n=t?.ansiColor&&typeof r.compile_with_color=="function"?r.compile_with_color(c,e,!0):r.compile(c,e,JSON.stringify({silenceWarnings:!1})),s=J(n);return{success:s.success(),output:s.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
|
package/dist/full/index.d.cts
CHANGED
|
@@ -6,15 +6,24 @@ declare class Fetcher {
|
|
|
6
6
|
fetch(_gitUrl: string, _rev: string, _subdir?: string): Promise<Record<string, string>>;
|
|
7
7
|
/** Fetch a single file from a repository. */
|
|
8
8
|
fetchFile(_gitUrl: string, _rev: string, _path: string): Promise<string | null>;
|
|
9
|
+
/** Get the resolved commit SHA for a git URL and rev (after fetch). */
|
|
10
|
+
getResolvedSha(_gitUrl: string, _rev: string): string | undefined;
|
|
9
11
|
}
|
|
10
12
|
/** Fetcher that retrieves files from public GitHub repositories via fetch(). */
|
|
11
13
|
declare class GitHubFetcher extends Fetcher {
|
|
12
14
|
private cache;
|
|
13
15
|
private treeCache;
|
|
16
|
+
private resolvedShaCache;
|
|
14
17
|
private rateLimitRemaining;
|
|
15
18
|
private rateLimitReset;
|
|
16
19
|
private token;
|
|
17
20
|
constructor(token?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Get the resolved commit SHA for a git URL and rev.
|
|
23
|
+
* This returns the actual commit SHA that was fetched, resolving tags/branches.
|
|
24
|
+
* Must be called after fetch() to get the resolved SHA.
|
|
25
|
+
*/
|
|
26
|
+
getResolvedSha(gitUrl: string, rev: string): string | undefined;
|
|
18
27
|
/**
|
|
19
28
|
* Update rate limit info from response headers
|
|
20
29
|
*/
|
|
@@ -59,6 +68,27 @@ declare function fetchPackageFromGitHub(url: string, options?: {
|
|
|
59
68
|
includeLock?: boolean;
|
|
60
69
|
}): Promise<Record<string, string>>;
|
|
61
70
|
|
|
71
|
+
/** Build progress event types for tracking build status */
|
|
72
|
+
type BuildProgressEvent = {
|
|
73
|
+
type: "resolve_start";
|
|
74
|
+
} | {
|
|
75
|
+
type: "resolve_dep";
|
|
76
|
+
name: string;
|
|
77
|
+
source: string;
|
|
78
|
+
current: number;
|
|
79
|
+
total: number;
|
|
80
|
+
} | {
|
|
81
|
+
type: "resolve_complete";
|
|
82
|
+
count: number;
|
|
83
|
+
} | {
|
|
84
|
+
type: "compile_start";
|
|
85
|
+
} | {
|
|
86
|
+
type: "compile_complete";
|
|
87
|
+
} | {
|
|
88
|
+
type: "lockfile_generate";
|
|
89
|
+
};
|
|
90
|
+
/** Callback function for receiving build progress events */
|
|
91
|
+
type OnProgressCallback = (event: BuildProgressEvent) => void;
|
|
62
92
|
interface ResolvedDependencies {
|
|
63
93
|
/** JSON string of resolved files for the root package */
|
|
64
94
|
files: string;
|
|
@@ -92,6 +122,8 @@ interface BuildInput {
|
|
|
92
122
|
lintFlag?: string;
|
|
93
123
|
/** Use this option to strip metadata from the output (e.g. for mainnet dep matching). */
|
|
94
124
|
stripMetadata?: boolean;
|
|
125
|
+
/** Optional progress callback for build events */
|
|
126
|
+
onProgress?: OnProgressCallback;
|
|
95
127
|
}
|
|
96
128
|
interface BuildSuccess {
|
|
97
129
|
/** Base64-encoded bytecode modules. */
|
|
@@ -100,6 +132,10 @@ interface BuildSuccess {
|
|
|
100
132
|
dependencies: string[];
|
|
101
133
|
/** Blake2b-256 package digest as byte array (matches Sui CLI JSON). */
|
|
102
134
|
digest: number[];
|
|
135
|
+
/** Move.lock V4 content (TOML string) */
|
|
136
|
+
moveLock: string;
|
|
137
|
+
/** Build environment used */
|
|
138
|
+
environment: string;
|
|
103
139
|
}
|
|
104
140
|
interface BuildFailure {
|
|
105
141
|
error: string;
|
|
@@ -146,4 +182,4 @@ declare function compileRaw(filesJson: string, depsJson: string, options?: {
|
|
|
146
182
|
}>;
|
|
147
183
|
type BuildResult = BuildSuccess | BuildFailure;
|
|
148
184
|
|
|
149
|
-
export { type BuildFailure, type BuildInput, type BuildResult, type BuildSuccess, type ResolvedDependencies, type TestSuccess, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies, testMovePackage };
|
|
185
|
+
export { type BuildFailure, type BuildInput, type BuildProgressEvent, type BuildResult, type BuildSuccess, type OnProgressCallback, type ResolvedDependencies, type TestSuccess, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies, testMovePackage };
|
package/dist/full/index.d.ts
CHANGED
|
@@ -6,15 +6,24 @@ declare class Fetcher {
|
|
|
6
6
|
fetch(_gitUrl: string, _rev: string, _subdir?: string): Promise<Record<string, string>>;
|
|
7
7
|
/** Fetch a single file from a repository. */
|
|
8
8
|
fetchFile(_gitUrl: string, _rev: string, _path: string): Promise<string | null>;
|
|
9
|
+
/** Get the resolved commit SHA for a git URL and rev (after fetch). */
|
|
10
|
+
getResolvedSha(_gitUrl: string, _rev: string): string | undefined;
|
|
9
11
|
}
|
|
10
12
|
/** Fetcher that retrieves files from public GitHub repositories via fetch(). */
|
|
11
13
|
declare class GitHubFetcher extends Fetcher {
|
|
12
14
|
private cache;
|
|
13
15
|
private treeCache;
|
|
16
|
+
private resolvedShaCache;
|
|
14
17
|
private rateLimitRemaining;
|
|
15
18
|
private rateLimitReset;
|
|
16
19
|
private token;
|
|
17
20
|
constructor(token?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Get the resolved commit SHA for a git URL and rev.
|
|
23
|
+
* This returns the actual commit SHA that was fetched, resolving tags/branches.
|
|
24
|
+
* Must be called after fetch() to get the resolved SHA.
|
|
25
|
+
*/
|
|
26
|
+
getResolvedSha(gitUrl: string, rev: string): string | undefined;
|
|
18
27
|
/**
|
|
19
28
|
* Update rate limit info from response headers
|
|
20
29
|
*/
|
|
@@ -59,6 +68,27 @@ declare function fetchPackageFromGitHub(url: string, options?: {
|
|
|
59
68
|
includeLock?: boolean;
|
|
60
69
|
}): Promise<Record<string, string>>;
|
|
61
70
|
|
|
71
|
+
/** Build progress event types for tracking build status */
|
|
72
|
+
type BuildProgressEvent = {
|
|
73
|
+
type: "resolve_start";
|
|
74
|
+
} | {
|
|
75
|
+
type: "resolve_dep";
|
|
76
|
+
name: string;
|
|
77
|
+
source: string;
|
|
78
|
+
current: number;
|
|
79
|
+
total: number;
|
|
80
|
+
} | {
|
|
81
|
+
type: "resolve_complete";
|
|
82
|
+
count: number;
|
|
83
|
+
} | {
|
|
84
|
+
type: "compile_start";
|
|
85
|
+
} | {
|
|
86
|
+
type: "compile_complete";
|
|
87
|
+
} | {
|
|
88
|
+
type: "lockfile_generate";
|
|
89
|
+
};
|
|
90
|
+
/** Callback function for receiving build progress events */
|
|
91
|
+
type OnProgressCallback = (event: BuildProgressEvent) => void;
|
|
62
92
|
interface ResolvedDependencies {
|
|
63
93
|
/** JSON string of resolved files for the root package */
|
|
64
94
|
files: string;
|
|
@@ -92,6 +122,8 @@ interface BuildInput {
|
|
|
92
122
|
lintFlag?: string;
|
|
93
123
|
/** Use this option to strip metadata from the output (e.g. for mainnet dep matching). */
|
|
94
124
|
stripMetadata?: boolean;
|
|
125
|
+
/** Optional progress callback for build events */
|
|
126
|
+
onProgress?: OnProgressCallback;
|
|
95
127
|
}
|
|
96
128
|
interface BuildSuccess {
|
|
97
129
|
/** Base64-encoded bytecode modules. */
|
|
@@ -100,6 +132,10 @@ interface BuildSuccess {
|
|
|
100
132
|
dependencies: string[];
|
|
101
133
|
/** Blake2b-256 package digest as byte array (matches Sui CLI JSON). */
|
|
102
134
|
digest: number[];
|
|
135
|
+
/** Move.lock V4 content (TOML string) */
|
|
136
|
+
moveLock: string;
|
|
137
|
+
/** Build environment used */
|
|
138
|
+
environment: string;
|
|
103
139
|
}
|
|
104
140
|
interface BuildFailure {
|
|
105
141
|
error: string;
|
|
@@ -146,4 +182,4 @@ declare function compileRaw(filesJson: string, depsJson: string, options?: {
|
|
|
146
182
|
}>;
|
|
147
183
|
type BuildResult = BuildSuccess | BuildFailure;
|
|
148
184
|
|
|
149
|
-
export { type BuildFailure, type BuildInput, type BuildResult, type BuildSuccess, type ResolvedDependencies, type TestSuccess, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies, testMovePackage };
|
|
185
|
+
export { type BuildFailure, type BuildInput, type BuildProgressEvent, type BuildResult, type BuildSuccess, type OnProgressCallback, type ResolvedDependencies, type TestSuccess, buildMovePackage, compileRaw, fetchPackageFromGitHub, getSuiMoveVersion, getSuiVersion, getWasmBindings, initMoveCompiler, resolveDependencies, testMovePackage };
|