@mytegroupinc/myte-core 0.0.41 → 0.0.42
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/mytecody-cli.js +75 -7
- package/package.json +1 -1
package/mytecody-cli.js
CHANGED
|
@@ -747,6 +747,63 @@ function installArtifactBytes(bytes, manifest, artifact) {
|
|
|
747
747
|
return installedManifest;
|
|
748
748
|
}
|
|
749
749
|
|
|
750
|
+
function reusableInstalledArtifact(artifact) {
|
|
751
|
+
const enginePath = currentEnginePath();
|
|
752
|
+
const current = readCurrentClientManifest();
|
|
753
|
+
if (!current || !fs.existsSync(enginePath)) return null;
|
|
754
|
+
|
|
755
|
+
const currentArtifact = current.artifact || {};
|
|
756
|
+
if (artifact && artifact.sha256) {
|
|
757
|
+
if (String(currentArtifact.sha256 || "").toLowerCase() !== String(artifact.sha256 || "").toLowerCase()) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const engineBytes = fs.readFileSync(enginePath);
|
|
763
|
+
const installedSha = sha256Hex(engineBytes);
|
|
764
|
+
const expectedInstalledSha =
|
|
765
|
+
artifact && (artifact.installed_sha256 || artifact.executable_sha256 || artifact.uncompressed_sha256);
|
|
766
|
+
if (expectedInstalledSha && installedSha.toLowerCase() !== String(expectedInstalledSha).toLowerCase()) {
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
if (
|
|
770
|
+
currentArtifact.installed_sha256 &&
|
|
771
|
+
installedSha.toLowerCase() !== String(currentArtifact.installed_sha256).toLowerCase()
|
|
772
|
+
) {
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
return {
|
|
777
|
+
enginePath,
|
|
778
|
+
engineBytes,
|
|
779
|
+
artifactSizeBytes: Number(currentArtifact.size_bytes || artifact?.size_bytes || 0),
|
|
780
|
+
installedSha,
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function installManifestForReusableArtifact(reusable, manifest, artifact) {
|
|
785
|
+
const installedManifest = {
|
|
786
|
+
schema_version: manifest.schema_version || 1,
|
|
787
|
+
channel: manifest.channel || DEFAULT_CHANNEL,
|
|
788
|
+
version: manifest.version || "unknown",
|
|
789
|
+
installed_at: new Date().toISOString(),
|
|
790
|
+
launcher_version: PACKAGE_VERSION,
|
|
791
|
+
platform: platformKey(),
|
|
792
|
+
executable: reusable.enginePath,
|
|
793
|
+
artifact: {
|
|
794
|
+
url: artifact.url,
|
|
795
|
+
sha256: artifact.sha256,
|
|
796
|
+
format: artifactFormat(artifact),
|
|
797
|
+
size_bytes: reusable.artifactSizeBytes,
|
|
798
|
+
installed_sha256: reusable.installedSha,
|
|
799
|
+
installed_size_bytes: reusable.engineBytes.length,
|
|
800
|
+
},
|
|
801
|
+
};
|
|
802
|
+
fs.mkdirSync(path.dirname(currentClientManifestPath()), { recursive: true });
|
|
803
|
+
fs.writeFileSync(currentClientManifestPath(), JSON.stringify(installedManifest, null, 2), "utf8");
|
|
804
|
+
return installedManifest;
|
|
805
|
+
}
|
|
806
|
+
|
|
750
807
|
async function installReleaseAssets(manifest, artifact, { progress } = {}) {
|
|
751
808
|
const assets = releaseAssetsForPlatform(manifest, artifact);
|
|
752
809
|
const installed = [];
|
|
@@ -1400,12 +1457,23 @@ async function buildUpdatePayload(args, envPath, { dryRun = false, progress = nu
|
|
|
1400
1457
|
if (!artifactMetadata.ok) {
|
|
1401
1458
|
throw new Error(`MyteCody release artifact metadata is ${artifactMetadata.status}.`);
|
|
1402
1459
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1460
|
+
let installed;
|
|
1461
|
+
let artifactDigest = String(artifact.sha256 || "");
|
|
1462
|
+
let artifactSizeBytes = Number(artifact.size_bytes || 0);
|
|
1463
|
+
const reusable = reusableInstalledArtifact(artifact);
|
|
1464
|
+
if (reusable) {
|
|
1465
|
+
if (progress) progress("reusing installed MyteCody engine");
|
|
1466
|
+
installed = installManifestForReusableArtifact(reusable, manifest, artifact);
|
|
1467
|
+
artifactSizeBytes = reusable.artifactSizeBytes;
|
|
1468
|
+
} else {
|
|
1469
|
+
const bytes = await readArtifactBytes(artifact, { progress });
|
|
1470
|
+
artifactDigest = sha256Hex(bytes);
|
|
1471
|
+
artifactSizeBytes = bytes.length;
|
|
1472
|
+
if (artifactDigest.toLowerCase() !== String(artifact.sha256 || "").toLowerCase()) {
|
|
1473
|
+
throw new Error(`Artifact SHA-256 mismatch: expected ${artifact.sha256}, got ${artifactDigest}`);
|
|
1474
|
+
}
|
|
1475
|
+
installed = installArtifactBytes(bytes, manifest, artifact);
|
|
1407
1476
|
}
|
|
1408
|
-
const installed = installArtifactBytes(bytes, manifest, artifact);
|
|
1409
1477
|
const installedAssets = await installReleaseAssets(manifest, artifact, { progress });
|
|
1410
1478
|
if (installedAssets.length) {
|
|
1411
1479
|
installed.assets = installedAssets;
|
|
@@ -1415,8 +1483,8 @@ async function buildUpdatePayload(args, envPath, { dryRun = false, progress = nu
|
|
|
1415
1483
|
ok: true,
|
|
1416
1484
|
version: installed.version,
|
|
1417
1485
|
executable: installed.executable,
|
|
1418
|
-
sha256:
|
|
1419
|
-
size_bytes:
|
|
1486
|
+
sha256: artifactDigest,
|
|
1487
|
+
size_bytes: artifactSizeBytes,
|
|
1420
1488
|
installed_sha256: installed.artifact.installed_sha256,
|
|
1421
1489
|
installed_size_bytes: installed.artifact.installed_size_bytes,
|
|
1422
1490
|
format: installed.artifact.format,
|