@zktx.io/sui-move-builder 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/dist/full/index.cjs +15 -17
- package/dist/full/index.js +15 -17
- package/dist/full/sui_move_wasm.d.ts +1 -1
- package/dist/full/sui_move_wasm_bg.wasm +0 -0
- package/dist/full/sui_move_wasm_bg.wasm.d.ts +1 -1
- package/dist/lite/index.cjs +15 -17
- package/dist/lite/index.js +15 -17
- package/dist/lite/sui_move_wasm_bg.wasm +0 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,8 +7,10 @@ Build Move packages in web or Node.js with Sui CLI-compatible dependency resolut
|
|
|
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)
|
|
11
|
-
- ✅ **
|
|
10
|
+
- ✅ **Verified Parity**: Audited against `sui-04dd` source code (Jan 2026), byte-level module comparison
|
|
11
|
+
- ✅ **Address Resolution**: Supports `original_id` for compilation, `published_at` for metadata (CLI-identical)
|
|
12
|
+
- ✅ **Lockfile Support**: Reads `Move.lock` v0/v3/v4 for faster, deterministic builds
|
|
13
|
+
- ✅ **Published.toml Support**: Reads deployment records per environment
|
|
12
14
|
- ✅ **Per-Package Editions**: Each package can use its own Move edition (legacy, 2024.alpha, 2024.beta)
|
|
13
15
|
- ✅ **Monorepo Support**: Handles local dependencies in monorepo structures
|
|
14
16
|
- ✅ **Version Conflict Detection**: Matches Sui CLI behavior for conflicting dependency versions
|
|
@@ -16,6 +18,8 @@ Build Move packages in web or Node.js with Sui CLI-compatible dependency resolut
|
|
|
16
18
|
- ✅ **GitHub Integration**: Fetches dependencies directly from git repositories
|
|
17
19
|
- ✅ **GitHub Token Support**: Optional token to raise rate limits (API calls only; raw fetch remains CORS-safe)
|
|
18
20
|
|
|
21
|
+
> 📖 For detailed CLI behavior documentation, see [CLI_PIPELINE.md](./CLI_PIPELINE.md)
|
|
22
|
+
|
|
19
23
|
## Install
|
|
20
24
|
|
|
21
25
|
```bash
|
|
@@ -244,6 +248,27 @@ npm run serve:test # serves ./test via python -m http.server
|
|
|
244
248
|
# open http://localhost:8000/test/index.html
|
|
245
249
|
```
|
|
246
250
|
|
|
251
|
+
## Fidelity Tests
|
|
252
|
+
|
|
253
|
+
This package includes byte-level comparison tests against the official Sui CLI output:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
npm run test:lite # Run fidelity tests (lite version)
|
|
257
|
+
npm test # Run full integration tests
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Test Cases (verified against Sui CLI):**
|
|
261
|
+
|
|
262
|
+
- `nautilus.enclave` - Simple package with framework dependencies
|
|
263
|
+
- `apps.kiosk` - Mysten Labs kiosk package
|
|
264
|
+
- `deeptrade-core` - Complex package with Pyth/Deepbook dependencies
|
|
265
|
+
|
|
266
|
+
All tests verify:
|
|
267
|
+
|
|
268
|
+
- ✅ Module bytecode (identical to CLI `.mv` output)
|
|
269
|
+
- ✅ Dependency IDs (exact match with CLI)
|
|
270
|
+
- ✅ Dependency order (lexicographical, CLI-consistent)
|
|
271
|
+
|
|
247
272
|
## Roadmap
|
|
248
273
|
|
|
249
274
|
- **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,26 +1,24 @@
|
|
|
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
|
-
`),
|
|
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
|
+
`),r=[],o="none";for(let c of n){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",r.push(c));continue}if(o==="package")(l.startsWith("name")||l.startsWith("version")||l.startsWith("edition")||l.startsWith("published-at")||l.startsWith("original-published-id"))&&(l.startsWith("published-at")||l.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
|
|
3
3
|
`;a+=`name = "${e}"
|
|
4
4
|
`,a+=`version = "0.0.0"
|
|
5
|
-
`,a+=`edition = "${
|
|
5
|
+
`,a+=`edition = "${i}"
|
|
6
6
|
`,a+=`
|
|
7
|
-
`,a+=
|
|
7
|
+
`,a+=r.join(`
|
|
8
8
|
`),a+=`
|
|
9
9
|
[addresses]
|
|
10
|
-
|
|
11
|
-
[addresses]
|
|
12
|
-
|
|
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]
|
|
10
|
+
`;let p=Object.entries(s);for(let[c,l]of p)a+=`${c} = "${l}"
|
|
11
|
+
`;return a}};var W=class{constructor(e,t="mainnet",i=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=i}async resolve(e,t){let i=S(e),s=i.package?.name||"RootPackage",n=i.package?.edition,r=new O(s),o=await this.buildPackage(s,this.rootSource,e,t);n&&(o.manifest.edition=n);let a=o.manifest.addresses[s];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[s]=this.normalizeAddress(o.manifest.originalId)),r.addPackage(o),this.packageFiles.set(s,t);let c=await this.loadFromLockfile(r,o,t),l=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||l.length>0)&&await this.buildDependencyGraph(r,o);let u=r.detectCycle();if(u)throw new Error(`Dependency cycle detected: ${u.join(" \u2192 ")}`);let g=new $(r,{});await g.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new T(g);await f.compute(this.packageFiles);let h=g.getUnifiedAddressTable();for(let k of r.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(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[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]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(i,o.manifest.dependencies,h,!0,n),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,i,s){let n=S(i),r=s["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(i,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=s["Published.toml"],l,u;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(l=this.normalizeAddress(I["published-at"])),I["original-id"]&&(u=this.normalizeAddress(I["original-id"])))}catch{}a.error;let g={name:n.package?.name||e,version:n.package?.version||"0.0.0",edition:n.package?.edition,publishedAt:l||a.publishedAt,originalId:u||a.originalId,latestPublishedId:p,addresses:n.addresses||{},dependencies:this.injectImplicitDependencies(n.dependencies||{},n.package?.name),devDependencies:n["dev-dependencies"]},m=Object.keys(g.addresses).find(w=>w.toLowerCase()===g.name.toLowerCase());if(m&&g.addresses[m]){let w=this.normalizeAddress(g.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(g.originalId=w)}let f=g.originalId||g.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=g.addresses[g.name]||(m?g.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(g.addresses[g.name]=h):v?g.addresses[g.name]=v:g.addresses[g.name]="0x0";let b=new Map;if(g.dependencies)for(let[w,I]of Object.entries(g.dependencies)){let M=this.parseDependencyInfo(I);M&&b.set(w,M)}return{id:{name:g.name,version:g.version,source:t||{type:"local"}},manifest:g,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 i=e["addr-subst"]||e.addr_subst,s={};for(let[n,r]of Object.entries(i))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?s[n]={type:"assign",address:r}:s[n]={type:"renameFrom",name:r});Object.keys(s).length>0&&(t.subst=s)}return t}async buildDependencyGraph(e,t){let i=Array.from(t.dependencies.entries()).sort(([,s],[,n])=>{let r=s.source.isImplicit?1:0;return(n.source.isImplicit?1:0)-r});for(let[s,n]of i){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let u=t.id.source.subdir||"",g=n.source.local,m=this.resolveRelativePath(u,g);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}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 u=this.findPackageBySource(e,n.source);u&&e.addDependency(t.id.name,u.id.name,n);continue}this.visited.add(r);let o=n.source.subdir;!o&&n.source.git&&this.isSuiRepo(n.source.git)&&(o=this.inferSuiFrameworkSubdir(s),o&&(n.source.subdir=o));let a=await this.fetcher.fetch(n.source.git,n.source.rev,o),p=null,c=`Move.${this.network}.toml`;for(let[u,g]of Object.entries(a))if(u.endsWith(c)){p=g;break}if(!p){for(let[u,g]of Object.entries(a))if(u.endsWith("Move.toml")){p=g;break}}if(!p)continue;let l=await this.buildPackage(s,n.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let u=this.packageNameCache.get(l.manifest.name);if(u){let g=u.isImplicit,m=n.source.isImplicit;if(g&&!m)continue;if(!(!g&&m)){if(JSON.stringify(u)!==JSON.stringify(n.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${l.manifest.name}' found`,`Existing: ${f(u)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
12
|
+
`))}}}this.packageNameCache.set(l.manifest.name,n.source)}l.manifest.edition||(l.manifest.edition="legacy"),e.addPackage(l),e.addDependency(t.id.name,l.id.name,n),this.packageFiles.set(l.id.name,a),await this.buildDependencyGraph(e,l)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,i,s){let n=S(e),r=n.package?.published_at||n.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=n.package?.["original-id"],c,l;if(t)try{let f=S(t),h=i&&f.env?.[i]||f.env?.[s];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(l=this.normalizeAddress(h["latest-published-id"])))}catch{}let u=a||l||c;return{publishedAt:u,originalId:p||c,latestId:u}}findPackageBySource(e,t){for(let i of e.getAllPackages()){let s=i.id.source;if(s.type===t.type&&s.git===t.git&&s.rev===t.rev&&s.subdir===t.subdir)return i}}resolveRelativePath(e,t){let i=e?e.split("/").filter(Boolean):[],s=t.split("/").filter(Boolean),n=[...i];for(let r of s)r===".."?n.length>0&&n.pop():r!=="."&&n.push(r);return n.join("/")}async computeManifestDigest(e){let i=new TextEncoder().encode(e),s=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(s)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,i){let s=i["Move.lock"];if(!s)return!1;let n=S(s);this.lockfileVersion=n.move?.version;let r=n.move?.version;return r===3?await this.loadFromLockfileV3(e,n,t):r&&r>=4?n.pinned?await this.loadFromLockfileV4(e,n,i,t):!1:await this.loadFromLockfileV0(e,n,t)}async loadFromLockfileV0(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=s.map(c=>c.name||c.id).filter(Boolean),o=[...n,...r.filter(c=>!n.includes(c))],a=new Map,p=new Map;for(let c of s){let l=c.id||c.name,u=c.source;if(!l||!u)continue;let g=null;if(u.git&&u.rev)g={type:"git",git:u.git,rev:u.rev,subdir:u.subdir};else if(u.local&&this.rootSource?.type==="git"){let y=this.resolveRelativePath(this.rootSource.subdir||"",u.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(l,g,f,m);a.set(l,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of s){let l=c.id||c.name,u=a.get(l);if(!u)continue;let g=c.dependencies;if(g&&Array.isArray(g))for(let m of g){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(u.id.name,h.id.name,y)}}}for(let c of i.dependencies.keys()){let l=p.get(c);if(l){let u=i.dependencies.get(c);e.addDependency(i.id.name,l.id.name,u)}}return a.size>0}async loadFromLockfileV3(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=new Map,r=new Map,o=[];for(let a of s)a.id&&r.set(a.id,a);for(let a of s){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 u=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(u).length===0)continue;let g=u["Move.toml"];if(!g)continue;let m=await this.buildPackage(p,l,g,u);n.set(p,m),this.packageFiles.set(m.manifest.name,u),e.addPackage(m)}e.setLockfileOrder(o);for(let a of s){let p=a.id,c=n.get(p);if(!c)continue;let l=a.dependencies;if(!(!l||!Array.isArray(l)))for(let u of l){let g=u.id,m=n.get(g);if(!m){let f=r.get(g);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(g,y,b,v);n.set(g,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 i.dependencies.keys()){let p=n.get(a);if(p){let c=i.dependencies.get(a);e.addDependency(i.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,i,s){let n=t.pinned?.[this.network];if(!n)return!1;let r=i["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,l]of Object.entries(n)){p.push(c);let u=this.lockfileSourceToDependencySource(l.source);if(!u)continue;let g=await this.fetchFromSource(u);if(!g)return!1;let m=g["Move.toml"];if(!m||l["manifest-digest"]&&await this.computeManifestDigest(m)!==l["manifest-digest"])return!1;let f=await this.buildPackage(c,u,m,g);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,g),(u.type!=="local"||!("root"in l.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,l]of Object.entries(n)){let u=o.get(c);if(u&&l.deps)for(let[g,m]of Object.entries(l.deps)){let f=o.get(m);if(f){let h=u.dependencies.get(g);h&&e.addDependency(u.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let l=c.id,u=o.get(l);if(u){let g={source:u.id.source};e.addDependency(s.id.name,u.id.name,g)}}else for(let c of s.dependencies.keys()){let l=a.get(c)||o.get(c);if(l){let u=s.dependencies.get(c);e.addDependency(s.id.name,l.id.name,u)}}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,i,s,n){let o=`[package]
|
|
15
13
|
name = "${e.package.name}"
|
|
16
14
|
version = "${e.package.version}"
|
|
17
|
-
`,
|
|
18
|
-
`),
|
|
15
|
+
`,a=n||e.package.edition;if(a&&(o+=`edition = "${a}"
|
|
16
|
+
`),o+=`
|
|
19
17
|
[dependencies]
|
|
20
|
-
`,
|
|
21
|
-
`:g.git&&g.rev&&(g.subdir?
|
|
22
|
-
`:
|
|
23
|
-
`)}}
|
|
18
|
+
`,t){let c=Object.entries(t);for(let[l,u]of c){let g=u;g.local?o+=`${l} = { local = "${g.local}" }
|
|
19
|
+
`:g.git&&g.rev&&(g.subdir?o+=`${l} = { git = "${g.git}", subdir = "${g.subdir}", rev = "${g.rev}" }
|
|
20
|
+
`:o+=`${l} = { git = "${g.git}", rev = "${g.rev}" }
|
|
21
|
+
`)}}o+=`
|
|
24
22
|
[addresses]
|
|
25
|
-
`;let
|
|
26
|
-
`;return
|
|
23
|
+
`;let p=Object.entries(i);for(let[c,l]of p)o+=`${c} = "${l}"
|
|
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 E(d,e,t,i="mainnet",s){return new W(t,i,s||null).resolve(d,e)}function se(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 i=t[0],s=t[1],n="main",r;return t.length>=4&&t[2]==="tree"&&(n=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:i,repo:s,ref:n,subdir:r}}catch{return null}}async function z(d,e){let t=se(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let i=e?.fetcher||new A(e?.githubToken),s=e?.includeLock!==!1,n=`https://github.com/${t.owner}/${t.repo}.git`,r=await i.fetch(n,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:n,rev:t.ref,subdir:t.subdir},enumerable:!1}),!s&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var B;async function R(d){return B||(B=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),B}function L(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function V(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 ne(d,e){let t=i=>{let s=i.startsWith("0x")?i.slice(2):i,n=s.length%2===0?s:`0${s}`,r=[];for(let o=0;o<n.length;o+=2){let a=parseInt(n.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let i=JSON.parse(d);if(!i.modules||!i.dependencies||!i.digest)throw new Error("missing fields in compiler output");let s=typeof i.digest=="string"?t(i.digest):Array.from(i.digest),n=i.dependencies;return e&&(n=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),n.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:i.modules,dependencies:n,digest:s}}catch(i){return L(i)}}function H(d){try{let e=JSON.parse(d);for(let t of e){let i=t.addressMapping?.[t.name]??(()=>{let s=Object.entries(t.files).find(([r])=>r.endsWith("Move.toml"));if(!s)return;let n=S(s[1]);return n.addresses&&n.addresses[t.name]||n.package?.published_at||n.package?.["published-at"]})()}}catch{}}async function ie(d){await R(d?.wasm)}async function G(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,i=await E(e,{...d.files,"Move.toml":e},new A(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:i.files,dependencies:i.dependencies}}async function re(d){try{let e={};for(let[p,c]of Object.entries(d.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await G(d),i=await R(d.wasm);H(t.dependencies);let s=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||s.set(c.publishedIdForOutput,c.name)}catch{}let n=i.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=V(n),o=r.success(),a=r.output();return o?ne(a,s):L(a)}catch(e){return L(e)}}async function oe(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await G(d),t=await R(d.wasm);H(e.dependencies);let i=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 i.passed=="boolean"&&typeof i.output=="string")return{passed:i.passed,output:i.output};let s=typeof i.passed=="function"?i.passed():i.passed,n=typeof i.output=="function"?i.output():i.output;return{passed:s,output:n}}catch(e){return L(e)}}async function ae(d){return(await R(d?.wasm)).sui_move_version()}async function ce(d){return(await R(d?.wasm)).sui_version()}async function de(d){return R(d?.wasm)}async function le(d,e,t){let i=await R(t?.wasm),s=t?.ansiColor&&typeof i.compile_with_color=="function"?i.compile_with_color(d,e,!0):i.compile(d,e,JSON.stringify({silenceWarnings:!1})),n=V(s);return{success:n.success(),output:n.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
|
package/dist/full/index.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
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
|
-
`),
|
|
1
|
+
var L=class{async fetch(e,t,i){throw new Error("Not implemented")}async fetchFile(e,t,i){throw new Error("Not implemented")}},A=class extends L{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"),n=t.headers.get("x-ratelimit-reset");i&&(this.rateLimitRemaining=parseInt(i,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,i,n,s){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 d=new Map,g={},l=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(n){let v=n.endsWith("/")?n:n+"/";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&&d.set("Move.toml",m.mode);let h=`https://raw.githubusercontent.com/${r}/${o}/${i}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(g[f]=v)});l.push(y)}if(await Promise.all(l),g["Move.toml"]&&d.get("Move.toml")==="120000"){let f=g["Move.toml"].trim(),h=n?`${n}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${i}/${h}`,v=await this.fetchContent(y);v&&(g["Move.toml"]=v)}return g}async fetchFile(t,i,n){let{owner:s,repo:r}=this.parseGitUrl(t);if(!s||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${s}/${r}/${i}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let i={},n=typeof window<"u",s=t.startsWith("https://api.github.com/");this.token&&(!n||s)&&(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 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(u){let e=!1,t="";for(let i=0;i<u.length;i++){let n=u[i];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return u.slice(0,i)}return u}function N(u){let e=u.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(u){let e={},t=u.trim().replace(/^\{/,"").replace(/\}$/,""),i="",n=!1,s="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===s)&&(n=!n,s=a),!n&&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]=N(c)}return e}function z(u){let e=[],t=u.trim().replace(/^\[/,"").replace(/\]$/,""),i="",n=!1,s="",r=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==="{"&&r++,a==="}"&&r--,a===","&&r===0)){i.trim()&&e.push(B(i.trim())),i="";continue}i+=a}return i.trim()&&e.push(B(i.trim())),e}function B(u){return u.startsWith("{")?G(u):N(u)}function S(u){let e={},t=null,i=!1,n=u.split(/\r?\n/),s=[],r=0;for(;r<n.length;){let a=x(n[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<n.length&&!p.includes("]");)p+=" "+x(n[r]).trim(),r++;r<n.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+x(n[r]).trim(),r++),s.push(p)}else s.push(a),r++}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 s){let p=x(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 d=p.match(/^\[([^\]]+)\]$/);if(d){t=d[1].trim(),i=!1;continue}let g=p.indexOf("=");if(g===-1||!t)continue;let l=p.slice(0,g).trim(),m=p.slice(g+1).trim(),f;if(m.startsWith("{")?f=G(m):m.startsWith("[")?f=z(m):f=N(m),i){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[l]=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"?l.replace(/-/g,"_"):l;y[v]=f}}return e}var F=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,n=s=>{if(i.has(s))return;i.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],i=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let r=Array.from(s).sort();for(let o of r)i(o)}t.push(n)};return i(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],i=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let r=Array.from(s).sort();for(let o of r)i(o)}t.push(n)};return i(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],i=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s)for(let r of Array.from(s))i(r);t.push(n)};i(this.root);for(let n of this.packageTable.keys())i(n);return t}detectCycle(){let e=new Set,t=new Set,i=new Map,n=s=>{e.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=s;for(;p!==o;)a.unshift(p),p=i.get(p);return a.unshift(o),a}}else{i.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 r=n(s);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 O=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 n=this.graph.getPackage(i);if(n)for(let[s,r]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==o||this.unifiedAddressTable.set(s,o)}}for(let i of this.graph.getAllPackages()){let n={};for(let[s,r]of this.unifiedAddressTable.entries())n[s]=r;this.packageResolvedTables.set(i.id.name,n),i.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,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 $=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),n=this.resolvedGraph.compilerInputOrder(),s=new Map;for(let r of n){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",d=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],g=o.manifest.originalId;!g&&o.manifest.publishedAt&&(g=o.manifest.publishedAt),g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",d||(d=g)),s.set(r,g),s.set(r.toLowerCase(),g);let l={...o.resolvedTable||{}};for(let[f,h]of Object.entries(l)){let y=s.get(f)||s.get(f.toLowerCase());y&&(l[f]=y)}g&&r!=="Sui"&&r!=="MoveStdlib"&&(l[r]=g,l[r.toLowerCase()]=g);let m={name:r,isImmediate:i.has(r),sourcePaths:p,addressMapping:l,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){return Object.keys(t).filter(n=>n.endsWith("Move.toml")||n.endsWith("Move.lock")?!1:n.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let i of this.dependencies){let n=e.get(i.name)||{},s={};for(let[r,o]of Object.entries(n)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${i.name}/${r}`;r.endsWith("Move.toml")?s[a]=this.reconstructDependencyMoveToml(i.name,o,i.edition,i.addressMapping):s[a]=o}t.push({name:i.name,files:s,edition:i.edition,addressMapping:i.addressMapping,publishedIdForOutput:i.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,i,n){let s=(t||"").split(`
|
|
2
|
+
`),r=[],o="none";for(let c of s){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",r.push(c));continue}if(o==="package")(d.startsWith("name")||d.startsWith("version")||d.startsWith("edition")||d.startsWith("published-at")||d.startsWith("original-published-id"))&&(d.startsWith("published-at")||d.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
|
|
3
3
|
`;a+=`name = "${e}"
|
|
4
4
|
`,a+=`version = "0.0.0"
|
|
5
|
-
`,a+=`edition = "${
|
|
5
|
+
`,a+=`edition = "${i}"
|
|
6
6
|
`,a+=`
|
|
7
|
-
`,a+=
|
|
7
|
+
`,a+=r.join(`
|
|
8
8
|
`),a+=`
|
|
9
9
|
[addresses]
|
|
10
|
-
|
|
11
|
-
[addresses]
|
|
12
|
-
|
|
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]
|
|
10
|
+
`;let p=Object.entries(n);for(let[c,d]of p)a+=`${c} = "${d}"
|
|
11
|
+
`;return a}};var C=class{constructor(e,t="mainnet",i=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=i}async resolve(e,t){let i=S(e),n=i.package?.name||"RootPackage",s=i.package?.edition,r=new F(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)),r.addPackage(o),this.packageFiles.set(n,t);let c=await this.loadFromLockfile(r,o,t),d=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||d.length>0)&&await this.buildDependencyGraph(r,o);let g=r.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let l=new O(r,{});await l.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new $(l);await f.compute(this.packageFiles);let h=l.getUnifiedAddressTable();for(let k of r.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(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[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]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(i,o.manifest.dependencies,h,!0,s),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,i,n){let s=S(i),r=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(i,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=n["Published.toml"],d,g;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(d=this.normalizeAddress(I["published-at"])),I["original-id"]&&(g=this.normalizeAddress(I["original-id"])))}catch{}a.error;let l={name:s.package?.name||e,version:s.package?.version||"0.0.0",edition:s.package?.edition,publishedAt:d||a.publishedAt,originalId:g||a.originalId,latestPublishedId:p,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 f=l.originalId||l.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=l.addresses[l.name]||(m?l.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(l.addresses[l.name]=h):v?l.addresses[l.name]=v:l.addresses[l.name]="0x0";let b=new Map;if(l.dependencies)for(let[w,I]of Object.entries(l.dependencies)){let M=this.parseDependencyInfo(I);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 i=e["addr-subst"]||e.addr_subst,n={};for(let[s,r]of Object.entries(i))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?n[s]={type:"assign",address:r}:n[s]={type:"renameFrom",name:r});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){let i=Array.from(t.dependencies.entries()).sort(([,n],[,s])=>{let r=n.source.isImplicit?1:0;return(s.source.isImplicit?1:0)-r});for(let[n,s]of i){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let g=t.id.source.subdir||"",l=s.source.local,m=this.resolveRelativePath(g,l);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}else continue;if(s.source.type!=="git")continue;let r=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,s.source);g&&e.addDependency(t.id.name,g.id.name,s);continue}this.visited.add(r);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),p=null,c=`Move.${this.network}.toml`;for(let[g,l]of Object.entries(a))if(g.endsWith(c)){p=l;break}if(!p){for(let[g,l]of Object.entries(a))if(g.endsWith("Move.toml")){p=l;break}}if(!p)continue;let d=await this.buildPackage(n,s.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(d.manifest.name);if(g){let l=g.isImplicit,m=s.source.isImplicit;if(l&&!m)continue;if(!(!l&&m)){if(JSON.stringify(g)!==JSON.stringify(s.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${d.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(s.source)}`,`When resolving dependencies for '${t.id.name}' -> '${n}'`].join(`
|
|
12
|
+
`))}}}this.packageNameCache.set(d.manifest.name,s.source)}d.manifest.edition||(d.manifest.edition="legacy"),e.addPackage(d),e.addDependency(t.id.name,d.id.name,s),this.packageFiles.set(d.id.name,a),await this.buildDependencyGraph(e,d)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,i,n){let s=S(e),r=s.package?.published_at||s.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=s.package?.["original-id"],c,d;if(t)try{let f=S(t),h=i&&f.env?.[i]||f.env?.[n];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(d=this.normalizeAddress(h["latest-published-id"])))}catch{}let g=a||d||c;return{publishedAt:g,originalId:p||c,latestId:g}}findPackageBySource(e,t){for(let i of e.getAllPackages()){let n=i.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return i}}resolveRelativePath(e,t){let i=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),s=[...i];for(let r of n)r===".."?s.length>0&&s.pop():r!=="."&&s.push(r);return s.join("/")}async computeManifestDigest(e){let i=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,i){let n=i["Move.lock"];if(!n)return!1;let s=S(n);this.lockfileVersion=s.move?.version;let r=s.move?.version;return r===3?await this.loadFromLockfileV3(e,s,t):r&&r>=4?s.pinned?await this.loadFromLockfileV4(e,s,i,t):!1:await this.loadFromLockfileV0(e,s,t)}async loadFromLockfileV0(e,t,i){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=n.map(c=>c.name||c.id).filter(Boolean),o=[...s,...r.filter(c=>!s.includes(c))],a=new Map,p=new Map;for(let c of n){let d=c.id||c.name,g=c.source;if(!d||!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 y=this.resolveRelativePath(this.rootSource.subdir||"",g.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(d,l,f,m);a.set(d,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of n){let d=c.id||c.name,g=a.get(d);if(!g)continue;let l=c.dependencies;if(l&&Array.isArray(l))for(let m of l){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(g.id.name,h.id.name,y)}}}for(let c of i.dependencies.keys()){let d=p.get(c);if(d){let g=i.dependencies.get(c);e.addDependency(i.id.name,d.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,i){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=new Map,r=new Map,o=[];for(let a of n)a.id&&r.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 g=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(g).length===0)continue;let l=g["Move.toml"];if(!l)continue;let m=await this.buildPackage(p,d,l,g);s.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=s.get(p);if(!c)continue;let d=a.dependencies;if(!(!d||!Array.isArray(d)))for(let g of d){let l=g.id,m=s.get(l);if(!m){let f=r.get(l);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(l,y,b,v);s.set(l,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 i.dependencies.keys()){let p=s.get(a);if(p){let c=i.dependencies.get(a);e.addDependency(i.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,i,n){let s=t.pinned?.[this.network];if(!s)return!1;let r=i["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,d]of Object.entries(s)){p.push(c);let g=this.lockfileSourceToDependencySource(d.source);if(!g)continue;let l=await this.fetchFromSource(g);if(!l)return!1;let m=l["Move.toml"];if(!m||d["manifest-digest"]&&await this.computeManifestDigest(m)!==d["manifest-digest"])return!1;let f=await this.buildPackage(c,g,m,l);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,l),(g.type!=="local"||!("root"in d.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,d]of Object.entries(s)){let g=o.get(c);if(g&&d.deps)for(let[l,m]of Object.entries(d.deps)){let f=o.get(m);if(f){let h=g.dependencies.get(l);h&&e.addDependency(g.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let d=c.id,g=o.get(d);if(g){let l={source:g.id.source};e.addDependency(n.id.name,g.id.name,l)}}else for(let c of n.dependencies.keys()){let d=a.get(c)||o.get(c);if(d){let g=n.dependencies.get(c);e.addDependency(n.id.name,d.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,i,n,s){let o=`[package]
|
|
15
13
|
name = "${e.package.name}"
|
|
16
14
|
version = "${e.package.version}"
|
|
17
|
-
`,
|
|
18
|
-
`),
|
|
15
|
+
`,a=s||e.package.edition;if(a&&(o+=`edition = "${a}"
|
|
16
|
+
`),o+=`
|
|
19
17
|
[dependencies]
|
|
20
|
-
`,
|
|
21
|
-
`:l.git&&l.rev&&(l.subdir?
|
|
22
|
-
`:
|
|
23
|
-
`)}}
|
|
18
|
+
`,t){let c=Object.entries(t);for(let[d,g]of c){let l=g;l.local?o+=`${d} = { local = "${l.local}" }
|
|
19
|
+
`:l.git&&l.rev&&(l.subdir?o+=`${d} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
|
|
20
|
+
`:o+=`${d} = { git = "${l.git}", rev = "${l.rev}" }
|
|
21
|
+
`)}}o+=`
|
|
24
22
|
[addresses]
|
|
25
|
-
`;let
|
|
26
|
-
`;return
|
|
23
|
+
`;let p=Object.entries(i);for(let[c,d]of p)o+=`${c} = "${d}"
|
|
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 j(u,e,t,i="mainnet",n){return new C(t,i,n||null).resolve(u,e)}function V(u){try{let e=new URL(u);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let i=t[0],n=t[1],s="main",r;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:i,repo:n,ref:s,subdir:r}}catch{return null}}async function H(u,e){let t=V(u);if(!t)throw new Error(`Invalid GitHub URL: ${u}`);let i=e?.fetcher||new A(e?.githubToken),n=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,r=await i.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var W;async function R(u){return W||(W=import("./sui_move_wasm.js").then(async e=>(u?await e.default(u):await e.default(),e))),W}function T(u){return{error:u instanceof Error?u.message:typeof u=="string"?u:"Unknown error"}}function _(u){if(typeof u!="object"||u===null)throw new Error("Unexpected compile result shape from wasm");let e=u;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 J(u,e){let t=i=>{let n=i.startsWith("0x")?i.slice(2):i,s=n.length%2===0?n:`0${n}`,r=[];for(let o=0;o<s.length;o+=2){let a=parseInt(s.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let i=JSON.parse(u);if(!i.modules||!i.dependencies||!i.digest)throw new Error("missing fields in compiler output");let n=typeof i.digest=="string"?t(i.digest):Array.from(i.digest),s=i.dependencies;return e&&(s=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),s.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:i.modules,dependencies:s,digest:n}}catch(i){return T(i)}}function U(u){try{let e=JSON.parse(u);for(let t of e){let i=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([r])=>r.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 me(u){await R(u?.wasm)}async function E(u){let e=u.files["Move.toml"]||"",t=u.rootGit||u.files.__rootGit,i=await j(e,{...u.files,"Move.toml":e},new A(u.githubToken),u.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:i.files,dependencies:i.dependencies}}async function he(u){try{let e={};for(let[p,c]of Object.entries(u.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);u.files=e;let t=u.resolvedDependencies?u.resolvedDependencies:await E(u),i=await R(u.wasm);U(t.dependencies);let n=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||n.set(c.publishedIdForOutput,c.name)}catch{}let s=i.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:u.silenceWarnings,testMode:u.testMode,lintFlag:u.lintFlag,stripMetadata:u.stripMetadata})),r=_(s),o=r.success(),a=r.output();return o?J(a,n):T(a)}catch(e){return T(e)}}async function ye(u){try{let e=u.resolvedDependencies?u.resolvedDependencies:await E(u),t=await R(u.wasm);U(e.dependencies);let i=u.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof i.passed=="boolean"&&typeof i.output=="string")return{passed:i.passed,output:i.output};let n=typeof i.passed=="function"?i.passed():i.passed,s=typeof i.output=="function"?i.output():i.output;return{passed:n,output:s}}catch(e){return T(e)}}async function ve(u){return(await R(u?.wasm)).sui_move_version()}async function ke(u){return(await R(u?.wasm)).sui_version()}async function be(u){return R(u?.wasm)}async function we(u,e,t){let i=await R(t?.wasm),n=t?.ansiColor&&typeof i.compile_with_color=="function"?i.compile_with_color(u,e,!0):i.compile(u,e,JSON.stringify({silenceWarnings:!1})),s=_(n);return{success:s.success(),output:s.output()}}export{he as buildMovePackage,we as compileRaw,H as fetchPackageFromGitHub,ve as getSuiMoveVersion,ke as getSuiVersion,be as getWasmBindings,me as initMoveCompiler,E as resolveDependencies,ye as testMovePackage};
|
|
@@ -37,8 +37,8 @@ export interface InitOutput {
|
|
|
37
37
|
readonly test: (a: number, b: number, c: number, d: number) => number;
|
|
38
38
|
readonly sui_version: () => [number, number];
|
|
39
39
|
readonly __wbg_movetestresult_free: (a: number, b: number) => void;
|
|
40
|
-
readonly movetestresult_output: (a: number) => [number, number];
|
|
41
40
|
readonly movetestresult_passed: (a: number) => number;
|
|
41
|
+
readonly movetestresult_output: (a: number) => [number, number];
|
|
42
42
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
43
43
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
44
44
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
Binary file
|
|
@@ -9,8 +9,8 @@ export const sui_move_version: () => [number, number];
|
|
|
9
9
|
export const test: (a: number, b: number, c: number, d: number) => number;
|
|
10
10
|
export const sui_version: () => [number, number];
|
|
11
11
|
export const __wbg_movetestresult_free: (a: number, b: number) => void;
|
|
12
|
-
export const movetestresult_output: (a: number) => [number, number];
|
|
13
12
|
export const movetestresult_passed: (a: number) => number;
|
|
13
|
+
export const movetestresult_output: (a: number) => [number, number];
|
|
14
14
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
15
15
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
16
16
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
package/dist/lite/index.cjs
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
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
|
-
`),
|
|
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
|
+
`),r=[],o="none";for(let c of n){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",r.push(c));continue}if(o==="package")(l.startsWith("name")||l.startsWith("version")||l.startsWith("edition")||l.startsWith("published-at")||l.startsWith("original-published-id"))&&(l.startsWith("published-at")||l.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
|
|
3
3
|
`;a+=`name = "${e}"
|
|
4
4
|
`,a+=`version = "0.0.0"
|
|
5
|
-
`,a+=`edition = "${
|
|
5
|
+
`,a+=`edition = "${i}"
|
|
6
6
|
`,a+=`
|
|
7
|
-
`,a+=
|
|
7
|
+
`,a+=r.join(`
|
|
8
8
|
`),a+=`
|
|
9
9
|
[addresses]
|
|
10
|
-
|
|
11
|
-
[addresses]
|
|
12
|
-
|
|
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]
|
|
10
|
+
`;let p=Object.entries(s);for(let[c,l]of p)a+=`${c} = "${l}"
|
|
11
|
+
`;return a}};var W=class{constructor(e,t="mainnet",i=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=i}async resolve(e,t){let i=S(e),s=i.package?.name||"RootPackage",n=i.package?.edition,r=new O(s),o=await this.buildPackage(s,this.rootSource,e,t);n&&(o.manifest.edition=n);let a=o.manifest.addresses[s];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[s]=this.normalizeAddress(o.manifest.originalId)),r.addPackage(o),this.packageFiles.set(s,t);let c=await this.loadFromLockfile(r,o,t),l=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||l.length>0)&&await this.buildDependencyGraph(r,o);let u=r.detectCycle();if(u)throw new Error(`Dependency cycle detected: ${u.join(" \u2192 ")}`);let g=new $(r,{});await g.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new T(g);await f.compute(this.packageFiles);let h=g.getUnifiedAddressTable();for(let k of r.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(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[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]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(i,o.manifest.dependencies,h,!0,n),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,i,s){let n=S(i),r=s["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(i,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=s["Published.toml"],l,u;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(l=this.normalizeAddress(I["published-at"])),I["original-id"]&&(u=this.normalizeAddress(I["original-id"])))}catch{}a.error;let g={name:n.package?.name||e,version:n.package?.version||"0.0.0",edition:n.package?.edition,publishedAt:l||a.publishedAt,originalId:u||a.originalId,latestPublishedId:p,addresses:n.addresses||{},dependencies:this.injectImplicitDependencies(n.dependencies||{},n.package?.name),devDependencies:n["dev-dependencies"]},m=Object.keys(g.addresses).find(w=>w.toLowerCase()===g.name.toLowerCase());if(m&&g.addresses[m]){let w=this.normalizeAddress(g.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(g.originalId=w)}let f=g.originalId||g.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=g.addresses[g.name]||(m?g.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(g.addresses[g.name]=h):v?g.addresses[g.name]=v:g.addresses[g.name]="0x0";let b=new Map;if(g.dependencies)for(let[w,I]of Object.entries(g.dependencies)){let M=this.parseDependencyInfo(I);M&&b.set(w,M)}return{id:{name:g.name,version:g.version,source:t||{type:"local"}},manifest:g,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 i=e["addr-subst"]||e.addr_subst,s={};for(let[n,r]of Object.entries(i))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?s[n]={type:"assign",address:r}:s[n]={type:"renameFrom",name:r});Object.keys(s).length>0&&(t.subst=s)}return t}async buildDependencyGraph(e,t){let i=Array.from(t.dependencies.entries()).sort(([,s],[,n])=>{let r=s.source.isImplicit?1:0;return(n.source.isImplicit?1:0)-r});for(let[s,n]of i){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let u=t.id.source.subdir||"",g=n.source.local,m=this.resolveRelativePath(u,g);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}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 u=this.findPackageBySource(e,n.source);u&&e.addDependency(t.id.name,u.id.name,n);continue}this.visited.add(r);let o=n.source.subdir;!o&&n.source.git&&this.isSuiRepo(n.source.git)&&(o=this.inferSuiFrameworkSubdir(s),o&&(n.source.subdir=o));let a=await this.fetcher.fetch(n.source.git,n.source.rev,o),p=null,c=`Move.${this.network}.toml`;for(let[u,g]of Object.entries(a))if(u.endsWith(c)){p=g;break}if(!p){for(let[u,g]of Object.entries(a))if(u.endsWith("Move.toml")){p=g;break}}if(!p)continue;let l=await this.buildPackage(s,n.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let u=this.packageNameCache.get(l.manifest.name);if(u){let g=u.isImplicit,m=n.source.isImplicit;if(g&&!m)continue;if(!(!g&&m)){if(JSON.stringify(u)!==JSON.stringify(n.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${l.manifest.name}' found`,`Existing: ${f(u)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
|
|
12
|
+
`))}}}this.packageNameCache.set(l.manifest.name,n.source)}l.manifest.edition||(l.manifest.edition="legacy"),e.addPackage(l),e.addDependency(t.id.name,l.id.name,n),this.packageFiles.set(l.id.name,a),await this.buildDependencyGraph(e,l)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,i,s){let n=S(e),r=n.package?.published_at||n.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=n.package?.["original-id"],c,l;if(t)try{let f=S(t),h=i&&f.env?.[i]||f.env?.[s];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(l=this.normalizeAddress(h["latest-published-id"])))}catch{}let u=a||l||c;return{publishedAt:u,originalId:p||c,latestId:u}}findPackageBySource(e,t){for(let i of e.getAllPackages()){let s=i.id.source;if(s.type===t.type&&s.git===t.git&&s.rev===t.rev&&s.subdir===t.subdir)return i}}resolveRelativePath(e,t){let i=e?e.split("/").filter(Boolean):[],s=t.split("/").filter(Boolean),n=[...i];for(let r of s)r===".."?n.length>0&&n.pop():r!=="."&&n.push(r);return n.join("/")}async computeManifestDigest(e){let i=new TextEncoder().encode(e),s=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(s)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,i){let s=i["Move.lock"];if(!s)return!1;let n=S(s);this.lockfileVersion=n.move?.version;let r=n.move?.version;return r===3?await this.loadFromLockfileV3(e,n,t):r&&r>=4?n.pinned?await this.loadFromLockfileV4(e,n,i,t):!1:await this.loadFromLockfileV0(e,n,t)}async loadFromLockfileV0(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=s.map(c=>c.name||c.id).filter(Boolean),o=[...n,...r.filter(c=>!n.includes(c))],a=new Map,p=new Map;for(let c of s){let l=c.id||c.name,u=c.source;if(!l||!u)continue;let g=null;if(u.git&&u.rev)g={type:"git",git:u.git,rev:u.rev,subdir:u.subdir};else if(u.local&&this.rootSource?.type==="git"){let y=this.resolveRelativePath(this.rootSource.subdir||"",u.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(l,g,f,m);a.set(l,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of s){let l=c.id||c.name,u=a.get(l);if(!u)continue;let g=c.dependencies;if(g&&Array.isArray(g))for(let m of g){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(u.id.name,h.id.name,y)}}}for(let c of i.dependencies.keys()){let l=p.get(c);if(l){let u=i.dependencies.get(c);e.addDependency(i.id.name,l.id.name,u)}}return a.size>0}async loadFromLockfileV3(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=new Map,r=new Map,o=[];for(let a of s)a.id&&r.set(a.id,a);for(let a of s){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 u=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(u).length===0)continue;let g=u["Move.toml"];if(!g)continue;let m=await this.buildPackage(p,l,g,u);n.set(p,m),this.packageFiles.set(m.manifest.name,u),e.addPackage(m)}e.setLockfileOrder(o);for(let a of s){let p=a.id,c=n.get(p);if(!c)continue;let l=a.dependencies;if(!(!l||!Array.isArray(l)))for(let u of l){let g=u.id,m=n.get(g);if(!m){let f=r.get(g);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(g,y,b,v);n.set(g,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 i.dependencies.keys()){let p=n.get(a);if(p){let c=i.dependencies.get(a);e.addDependency(i.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,i,s){let n=t.pinned?.[this.network];if(!n)return!1;let r=i["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,l]of Object.entries(n)){p.push(c);let u=this.lockfileSourceToDependencySource(l.source);if(!u)continue;let g=await this.fetchFromSource(u);if(!g)return!1;let m=g["Move.toml"];if(!m||l["manifest-digest"]&&await this.computeManifestDigest(m)!==l["manifest-digest"])return!1;let f=await this.buildPackage(c,u,m,g);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,g),(u.type!=="local"||!("root"in l.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,l]of Object.entries(n)){let u=o.get(c);if(u&&l.deps)for(let[g,m]of Object.entries(l.deps)){let f=o.get(m);if(f){let h=u.dependencies.get(g);h&&e.addDependency(u.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let l=c.id,u=o.get(l);if(u){let g={source:u.id.source};e.addDependency(s.id.name,u.id.name,g)}}else for(let c of s.dependencies.keys()){let l=a.get(c)||o.get(c);if(l){let u=s.dependencies.get(c);e.addDependency(s.id.name,l.id.name,u)}}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,i,s,n){let o=`[package]
|
|
15
13
|
name = "${e.package.name}"
|
|
16
14
|
version = "${e.package.version}"
|
|
17
|
-
`,
|
|
18
|
-
`),
|
|
15
|
+
`,a=n||e.package.edition;if(a&&(o+=`edition = "${a}"
|
|
16
|
+
`),o+=`
|
|
19
17
|
[dependencies]
|
|
20
|
-
`,
|
|
21
|
-
`:g.git&&g.rev&&(g.subdir?
|
|
22
|
-
`:
|
|
23
|
-
`)}}
|
|
18
|
+
`,t){let c=Object.entries(t);for(let[l,u]of c){let g=u;g.local?o+=`${l} = { local = "${g.local}" }
|
|
19
|
+
`:g.git&&g.rev&&(g.subdir?o+=`${l} = { git = "${g.git}", subdir = "${g.subdir}", rev = "${g.rev}" }
|
|
20
|
+
`:o+=`${l} = { git = "${g.git}", rev = "${g.rev}" }
|
|
21
|
+
`)}}o+=`
|
|
24
22
|
[addresses]
|
|
25
|
-
`;let
|
|
26
|
-
`;return
|
|
23
|
+
`;let p=Object.entries(i);for(let[c,l]of p)o+=`${c} = "${l}"
|
|
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 E(d,e,t,i="mainnet",s){return new W(t,i,s||null).resolve(d,e)}function se(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 i=t[0],s=t[1],n="main",r;return t.length>=4&&t[2]==="tree"&&(n=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:i,repo:s,ref:n,subdir:r}}catch{return null}}async function z(d,e){let t=se(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let i=e?.fetcher||new A(e?.githubToken),s=e?.includeLock!==!1,n=`https://github.com/${t.owner}/${t.repo}.git`,r=await i.fetch(n,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:n,rev:t.ref,subdir:t.subdir},enumerable:!1}),!s&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var B;async function R(d){return B||(B=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),B}function L(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function V(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 ne(d,e){let t=i=>{let s=i.startsWith("0x")?i.slice(2):i,n=s.length%2===0?s:`0${s}`,r=[];for(let o=0;o<n.length;o+=2){let a=parseInt(n.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let i=JSON.parse(d);if(!i.modules||!i.dependencies||!i.digest)throw new Error("missing fields in compiler output");let s=typeof i.digest=="string"?t(i.digest):Array.from(i.digest),n=i.dependencies;return e&&(n=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),n.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:i.modules,dependencies:n,digest:s}}catch(i){return L(i)}}function H(d){try{let e=JSON.parse(d);for(let t of e){let i=t.addressMapping?.[t.name]??(()=>{let s=Object.entries(t.files).find(([r])=>r.endsWith("Move.toml"));if(!s)return;let n=S(s[1]);return n.addresses&&n.addresses[t.name]||n.package?.published_at||n.package?.["published-at"]})()}}catch{}}async function ie(d){await R(d?.wasm)}async function G(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,i=await E(e,{...d.files,"Move.toml":e},new A(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:i.files,dependencies:i.dependencies}}async function re(d){try{let e={};for(let[p,c]of Object.entries(d.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await G(d),i=await R(d.wasm);H(t.dependencies);let s=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||s.set(c.publishedIdForOutput,c.name)}catch{}let n=i.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=V(n),o=r.success(),a=r.output();return o?ne(a,s):L(a)}catch(e){return L(e)}}async function oe(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await G(d),t=await R(d.wasm);H(e.dependencies);let i=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 i.passed=="boolean"&&typeof i.output=="string")return{passed:i.passed,output:i.output};let s=typeof i.passed=="function"?i.passed():i.passed,n=typeof i.output=="function"?i.output():i.output;return{passed:s,output:n}}catch(e){return L(e)}}async function ae(d){return(await R(d?.wasm)).sui_move_version()}async function ce(d){return(await R(d?.wasm)).sui_version()}async function de(d){return R(d?.wasm)}async function le(d,e,t){let i=await R(t?.wasm),s=t?.ansiColor&&typeof i.compile_with_color=="function"?i.compile_with_color(d,e,!0):i.compile(d,e,JSON.stringify({silenceWarnings:!1})),n=V(s);return{success:n.success(),output:n.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
|
package/dist/lite/index.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
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
|
-
`),
|
|
1
|
+
var L=class{async fetch(e,t,i){throw new Error("Not implemented")}async fetchFile(e,t,i){throw new Error("Not implemented")}},A=class extends L{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"),n=t.headers.get("x-ratelimit-reset");i&&(this.rateLimitRemaining=parseInt(i,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,i,n,s){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 d=new Map,g={},l=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(n){let v=n.endsWith("/")?n:n+"/";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&&d.set("Move.toml",m.mode);let h=`https://raw.githubusercontent.com/${r}/${o}/${i}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(g[f]=v)});l.push(y)}if(await Promise.all(l),g["Move.toml"]&&d.get("Move.toml")==="120000"){let f=g["Move.toml"].trim(),h=n?`${n}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${i}/${h}`,v=await this.fetchContent(y);v&&(g["Move.toml"]=v)}return g}async fetchFile(t,i,n){let{owner:s,repo:r}=this.parseGitUrl(t);if(!s||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${s}/${r}/${i}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let i={},n=typeof window<"u",s=t.startsWith("https://api.github.com/");this.token&&(!n||s)&&(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 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(u){let e=!1,t="";for(let i=0;i<u.length;i++){let n=u[i];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return u.slice(0,i)}return u}function N(u){let e=u.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(u){let e={},t=u.trim().replace(/^\{/,"").replace(/\}$/,""),i="",n=!1,s="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===s)&&(n=!n,s=a),!n&&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]=N(c)}return e}function z(u){let e=[],t=u.trim().replace(/^\[/,"").replace(/\]$/,""),i="",n=!1,s="",r=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==="{"&&r++,a==="}"&&r--,a===","&&r===0)){i.trim()&&e.push(B(i.trim())),i="";continue}i+=a}return i.trim()&&e.push(B(i.trim())),e}function B(u){return u.startsWith("{")?G(u):N(u)}function S(u){let e={},t=null,i=!1,n=u.split(/\r?\n/),s=[],r=0;for(;r<n.length;){let a=x(n[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<n.length&&!p.includes("]");)p+=" "+x(n[r]).trim(),r++;r<n.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+x(n[r]).trim(),r++),s.push(p)}else s.push(a),r++}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 s){let p=x(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 d=p.match(/^\[([^\]]+)\]$/);if(d){t=d[1].trim(),i=!1;continue}let g=p.indexOf("=");if(g===-1||!t)continue;let l=p.slice(0,g).trim(),m=p.slice(g+1).trim(),f;if(m.startsWith("{")?f=G(m):m.startsWith("[")?f=z(m):f=N(m),i){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[l]=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"?l.replace(/-/g,"_"):l;y[v]=f}}return e}var F=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,n=s=>{if(i.has(s))return;i.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],i=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let r=Array.from(s).sort();for(let o of r)i(o)}t.push(n)};return i(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],i=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let r=Array.from(s).sort();for(let o of r)i(o)}t.push(n)};return i(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],i=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s)for(let r of Array.from(s))i(r);t.push(n)};i(this.root);for(let n of this.packageTable.keys())i(n);return t}detectCycle(){let e=new Set,t=new Set,i=new Map,n=s=>{e.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=s;for(;p!==o;)a.unshift(p),p=i.get(p);return a.unshift(o),a}}else{i.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 r=n(s);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 O=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 n=this.graph.getPackage(i);if(n)for(let[s,r]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==o||this.unifiedAddressTable.set(s,o)}}for(let i of this.graph.getAllPackages()){let n={};for(let[s,r]of this.unifiedAddressTable.entries())n[s]=r;this.packageResolvedTables.set(i.id.name,n),i.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,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 $=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),n=this.resolvedGraph.compilerInputOrder(),s=new Map;for(let r of n){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",d=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],g=o.manifest.originalId;!g&&o.manifest.publishedAt&&(g=o.manifest.publishedAt),g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",d||(d=g)),s.set(r,g),s.set(r.toLowerCase(),g);let l={...o.resolvedTable||{}};for(let[f,h]of Object.entries(l)){let y=s.get(f)||s.get(f.toLowerCase());y&&(l[f]=y)}g&&r!=="Sui"&&r!=="MoveStdlib"&&(l[r]=g,l[r.toLowerCase()]=g);let m={name:r,isImmediate:i.has(r),sourcePaths:p,addressMapping:l,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){return Object.keys(t).filter(n=>n.endsWith("Move.toml")||n.endsWith("Move.lock")?!1:n.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let i of this.dependencies){let n=e.get(i.name)||{},s={};for(let[r,o]of Object.entries(n)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${i.name}/${r}`;r.endsWith("Move.toml")?s[a]=this.reconstructDependencyMoveToml(i.name,o,i.edition,i.addressMapping):s[a]=o}t.push({name:i.name,files:s,edition:i.edition,addressMapping:i.addressMapping,publishedIdForOutput:i.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,i,n){let s=(t||"").split(`
|
|
2
|
+
`),r=[],o="none";for(let c of s){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",r.push(c));continue}if(o==="package")(d.startsWith("name")||d.startsWith("version")||d.startsWith("edition")||d.startsWith("published-at")||d.startsWith("original-published-id"))&&(d.startsWith("published-at")||d.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
|
|
3
3
|
`;a+=`name = "${e}"
|
|
4
4
|
`,a+=`version = "0.0.0"
|
|
5
|
-
`,a+=`edition = "${
|
|
5
|
+
`,a+=`edition = "${i}"
|
|
6
6
|
`,a+=`
|
|
7
|
-
`,a+=
|
|
7
|
+
`,a+=r.join(`
|
|
8
8
|
`),a+=`
|
|
9
9
|
[addresses]
|
|
10
|
-
|
|
11
|
-
[addresses]
|
|
12
|
-
|
|
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]
|
|
10
|
+
`;let p=Object.entries(n);for(let[c,d]of p)a+=`${c} = "${d}"
|
|
11
|
+
`;return a}};var C=class{constructor(e,t="mainnet",i=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=i}async resolve(e,t){let i=S(e),n=i.package?.name||"RootPackage",s=i.package?.edition,r=new F(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)),r.addPackage(o),this.packageFiles.set(n,t);let c=await this.loadFromLockfile(r,o,t),d=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||d.length>0)&&await this.buildDependencyGraph(r,o);let g=r.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let l=new O(r,{});await l.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new $(l);await f.compute(this.packageFiles);let h=l.getUnifiedAddressTable();for(let k of r.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(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[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]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(i,o.manifest.dependencies,h,!0,s),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,i,n){let s=S(i),r=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(i,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=n["Published.toml"],d,g;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(d=this.normalizeAddress(I["published-at"])),I["original-id"]&&(g=this.normalizeAddress(I["original-id"])))}catch{}a.error;let l={name:s.package?.name||e,version:s.package?.version||"0.0.0",edition:s.package?.edition,publishedAt:d||a.publishedAt,originalId:g||a.originalId,latestPublishedId:p,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 f=l.originalId||l.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=l.addresses[l.name]||(m?l.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(l.addresses[l.name]=h):v?l.addresses[l.name]=v:l.addresses[l.name]="0x0";let b=new Map;if(l.dependencies)for(let[w,I]of Object.entries(l.dependencies)){let M=this.parseDependencyInfo(I);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 i=e["addr-subst"]||e.addr_subst,n={};for(let[s,r]of Object.entries(i))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?n[s]={type:"assign",address:r}:n[s]={type:"renameFrom",name:r});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){let i=Array.from(t.dependencies.entries()).sort(([,n],[,s])=>{let r=n.source.isImplicit?1:0;return(s.source.isImplicit?1:0)-r});for(let[n,s]of i){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let g=t.id.source.subdir||"",l=s.source.local,m=this.resolveRelativePath(g,l);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}else continue;if(s.source.type!=="git")continue;let r=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,s.source);g&&e.addDependency(t.id.name,g.id.name,s);continue}this.visited.add(r);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),p=null,c=`Move.${this.network}.toml`;for(let[g,l]of Object.entries(a))if(g.endsWith(c)){p=l;break}if(!p){for(let[g,l]of Object.entries(a))if(g.endsWith("Move.toml")){p=l;break}}if(!p)continue;let d=await this.buildPackage(n,s.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(d.manifest.name);if(g){let l=g.isImplicit,m=s.source.isImplicit;if(l&&!m)continue;if(!(!l&&m)){if(JSON.stringify(g)!==JSON.stringify(s.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${d.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(s.source)}`,`When resolving dependencies for '${t.id.name}' -> '${n}'`].join(`
|
|
12
|
+
`))}}}this.packageNameCache.set(d.manifest.name,s.source)}d.manifest.edition||(d.manifest.edition="legacy"),e.addPackage(d),e.addDependency(t.id.name,d.id.name,s),this.packageFiles.set(d.id.name,a),await this.buildDependencyGraph(e,d)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,i,n){let s=S(e),r=s.package?.published_at||s.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=s.package?.["original-id"],c,d;if(t)try{let f=S(t),h=i&&f.env?.[i]||f.env?.[n];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(d=this.normalizeAddress(h["latest-published-id"])))}catch{}let g=a||d||c;return{publishedAt:g,originalId:p||c,latestId:g}}findPackageBySource(e,t){for(let i of e.getAllPackages()){let n=i.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return i}}resolveRelativePath(e,t){let i=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),s=[...i];for(let r of n)r===".."?s.length>0&&s.pop():r!=="."&&s.push(r);return s.join("/")}async computeManifestDigest(e){let i=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,i){let n=i["Move.lock"];if(!n)return!1;let s=S(n);this.lockfileVersion=s.move?.version;let r=s.move?.version;return r===3?await this.loadFromLockfileV3(e,s,t):r&&r>=4?s.pinned?await this.loadFromLockfileV4(e,s,i,t):!1:await this.loadFromLockfileV0(e,s,t)}async loadFromLockfileV0(e,t,i){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=n.map(c=>c.name||c.id).filter(Boolean),o=[...s,...r.filter(c=>!s.includes(c))],a=new Map,p=new Map;for(let c of n){let d=c.id||c.name,g=c.source;if(!d||!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 y=this.resolveRelativePath(this.rootSource.subdir||"",g.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(d,l,f,m);a.set(d,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of n){let d=c.id||c.name,g=a.get(d);if(!g)continue;let l=c.dependencies;if(l&&Array.isArray(l))for(let m of l){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(g.id.name,h.id.name,y)}}}for(let c of i.dependencies.keys()){let d=p.get(c);if(d){let g=i.dependencies.get(c);e.addDependency(i.id.name,d.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,i){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=new Map,r=new Map,o=[];for(let a of n)a.id&&r.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 g=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(g).length===0)continue;let l=g["Move.toml"];if(!l)continue;let m=await this.buildPackage(p,d,l,g);s.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=s.get(p);if(!c)continue;let d=a.dependencies;if(!(!d||!Array.isArray(d)))for(let g of d){let l=g.id,m=s.get(l);if(!m){let f=r.get(l);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(l,y,b,v);s.set(l,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 i.dependencies.keys()){let p=s.get(a);if(p){let c=i.dependencies.get(a);e.addDependency(i.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,i,n){let s=t.pinned?.[this.network];if(!s)return!1;let r=i["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,d]of Object.entries(s)){p.push(c);let g=this.lockfileSourceToDependencySource(d.source);if(!g)continue;let l=await this.fetchFromSource(g);if(!l)return!1;let m=l["Move.toml"];if(!m||d["manifest-digest"]&&await this.computeManifestDigest(m)!==d["manifest-digest"])return!1;let f=await this.buildPackage(c,g,m,l);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,l),(g.type!=="local"||!("root"in d.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,d]of Object.entries(s)){let g=o.get(c);if(g&&d.deps)for(let[l,m]of Object.entries(d.deps)){let f=o.get(m);if(f){let h=g.dependencies.get(l);h&&e.addDependency(g.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let d=c.id,g=o.get(d);if(g){let l={source:g.id.source};e.addDependency(n.id.name,g.id.name,l)}}else for(let c of n.dependencies.keys()){let d=a.get(c)||o.get(c);if(d){let g=n.dependencies.get(c);e.addDependency(n.id.name,d.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,i,n,s){let o=`[package]
|
|
15
13
|
name = "${e.package.name}"
|
|
16
14
|
version = "${e.package.version}"
|
|
17
|
-
`,
|
|
18
|
-
`),
|
|
15
|
+
`,a=s||e.package.edition;if(a&&(o+=`edition = "${a}"
|
|
16
|
+
`),o+=`
|
|
19
17
|
[dependencies]
|
|
20
|
-
`,
|
|
21
|
-
`:l.git&&l.rev&&(l.subdir?
|
|
22
|
-
`:
|
|
23
|
-
`)}}
|
|
18
|
+
`,t){let c=Object.entries(t);for(let[d,g]of c){let l=g;l.local?o+=`${d} = { local = "${l.local}" }
|
|
19
|
+
`:l.git&&l.rev&&(l.subdir?o+=`${d} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
|
|
20
|
+
`:o+=`${d} = { git = "${l.git}", rev = "${l.rev}" }
|
|
21
|
+
`)}}o+=`
|
|
24
22
|
[addresses]
|
|
25
|
-
`;let
|
|
26
|
-
`;return
|
|
23
|
+
`;let p=Object.entries(i);for(let[c,d]of p)o+=`${c} = "${d}"
|
|
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 j(u,e,t,i="mainnet",n){return new C(t,i,n||null).resolve(u,e)}function V(u){try{let e=new URL(u);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let i=t[0],n=t[1],s="main",r;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:i,repo:n,ref:s,subdir:r}}catch{return null}}async function H(u,e){let t=V(u);if(!t)throw new Error(`Invalid GitHub URL: ${u}`);let i=e?.fetcher||new A(e?.githubToken),n=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,r=await i.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var W;async function R(u){return W||(W=import("./sui_move_wasm.js").then(async e=>(u?await e.default(u):await e.default(),e))),W}function T(u){return{error:u instanceof Error?u.message:typeof u=="string"?u:"Unknown error"}}function _(u){if(typeof u!="object"||u===null)throw new Error("Unexpected compile result shape from wasm");let e=u;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 J(u,e){let t=i=>{let n=i.startsWith("0x")?i.slice(2):i,s=n.length%2===0?n:`0${n}`,r=[];for(let o=0;o<s.length;o+=2){let a=parseInt(s.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let i=JSON.parse(u);if(!i.modules||!i.dependencies||!i.digest)throw new Error("missing fields in compiler output");let n=typeof i.digest=="string"?t(i.digest):Array.from(i.digest),s=i.dependencies;return e&&(s=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),s.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:i.modules,dependencies:s,digest:n}}catch(i){return T(i)}}function U(u){try{let e=JSON.parse(u);for(let t of e){let i=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([r])=>r.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 me(u){await R(u?.wasm)}async function E(u){let e=u.files["Move.toml"]||"",t=u.rootGit||u.files.__rootGit,i=await j(e,{...u.files,"Move.toml":e},new A(u.githubToken),u.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:i.files,dependencies:i.dependencies}}async function he(u){try{let e={};for(let[p,c]of Object.entries(u.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);u.files=e;let t=u.resolvedDependencies?u.resolvedDependencies:await E(u),i=await R(u.wasm);U(t.dependencies);let n=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||n.set(c.publishedIdForOutput,c.name)}catch{}let s=i.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:u.silenceWarnings,testMode:u.testMode,lintFlag:u.lintFlag,stripMetadata:u.stripMetadata})),r=_(s),o=r.success(),a=r.output();return o?J(a,n):T(a)}catch(e){return T(e)}}async function ye(u){try{let e=u.resolvedDependencies?u.resolvedDependencies:await E(u),t=await R(u.wasm);U(e.dependencies);let i=u.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof i.passed=="boolean"&&typeof i.output=="string")return{passed:i.passed,output:i.output};let n=typeof i.passed=="function"?i.passed():i.passed,s=typeof i.output=="function"?i.output():i.output;return{passed:n,output:s}}catch(e){return T(e)}}async function ve(u){return(await R(u?.wasm)).sui_move_version()}async function ke(u){return(await R(u?.wasm)).sui_version()}async function be(u){return R(u?.wasm)}async function we(u,e,t){let i=await R(t?.wasm),n=t?.ansiColor&&typeof i.compile_with_color=="function"?i.compile_with_color(u,e,!0):i.compile(u,e,JSON.stringify({silenceWarnings:!1})),s=_(n);return{success:s.success(),output:s.output()}}export{he as buildMovePackage,we as compileRaw,H as fetchPackageFromGitHub,ve as getSuiMoveVersion,ke as getSuiVersion,be as getWasmBindings,me as initMoveCompiler,E as resolveDependencies,ye as testMovePackage};
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zktx.io/sui-move-builder",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Build Move packages in web or Node.js with dependency fetching and dump outputs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"build:js": "tsup --out-dir dist/full && tsup --out-dir dist/lite",
|
|
53
53
|
"build": "npm run build:wasm && npm run build:js",
|
|
54
54
|
"serve:test": "python3 -m http.server 8000 --directory .",
|
|
55
|
-
"test:integration": "node test/integration/fidelity_test.mjs",
|
|
56
|
-
"test:lite": "node test/integration/
|
|
55
|
+
"test:integration": "node test/integration/fidelity_test.mjs full",
|
|
56
|
+
"test:lite": "node test/integration/fidelity_test.mjs lite",
|
|
57
57
|
"test": "npm run test:integration",
|
|
58
58
|
"prepublishOnly": "npm run build"
|
|
59
59
|
},
|