supabase 1.89.1 → 1.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/postinstall.js +62 -4
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
7
|
import binLinks from "bin-links";
|
|
8
|
+
import { createHash } from "crypto";
|
|
8
9
|
import fs from "fs";
|
|
9
10
|
import fetch from "node-fetch";
|
|
10
11
|
import path from "path";
|
|
@@ -24,6 +25,10 @@ const PLATFORM_MAPPING = {
|
|
|
24
25
|
win32: "windows",
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
const arch = ARCH_MAPPING[process.arch];
|
|
29
|
+
|
|
30
|
+
const platform = PLATFORM_MAPPING[process.platform];
|
|
31
|
+
|
|
27
32
|
// TODO: import pkg from "../package.json" assert { type: "json" };
|
|
28
33
|
const readPackageJson = async () => {
|
|
29
34
|
const packageJsonPath = path.join(".", "package.json");
|
|
@@ -32,14 +37,12 @@ const readPackageJson = async () => {
|
|
|
32
37
|
};
|
|
33
38
|
|
|
34
39
|
const parsePackageJson = (packageJson) => {
|
|
35
|
-
const arch = ARCH_MAPPING[process.arch];
|
|
36
40
|
if (!arch) {
|
|
37
41
|
throw Error(
|
|
38
42
|
"Installation is not supported for this architecture: " + process.arch
|
|
39
43
|
);
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
const platform = PLATFORM_MAPPING[process.platform];
|
|
43
46
|
if (!platform) {
|
|
44
47
|
throw Error(
|
|
45
48
|
"Installation is not supported for this platform: " + process.platform
|
|
@@ -60,9 +63,39 @@ const parsePackageJson = (packageJson) => {
|
|
|
60
63
|
return { binPath, url };
|
|
61
64
|
};
|
|
62
65
|
|
|
66
|
+
const fetchAndParseCheckSumFile = async (packageJson) => {
|
|
67
|
+
const version = packageJson.version;
|
|
68
|
+
const pkgName = packageJson.name;
|
|
69
|
+
const repo = packageJson.repository;
|
|
70
|
+
const checksumFileUrl = `https://github.com/${repo}/releases/download/v${version}/${pkgName}_${version}_checksums.txt`;
|
|
71
|
+
|
|
72
|
+
// Fetch the checksum file
|
|
73
|
+
console.info("Downloading", checksumFileUrl);
|
|
74
|
+
const response = await fetch(checksumFileUrl);
|
|
75
|
+
if (response.ok) {
|
|
76
|
+
const checkSumContent = await response.text();
|
|
77
|
+
const lines = checkSumContent.split("\n");
|
|
78
|
+
|
|
79
|
+
const checksums = {};
|
|
80
|
+
for (const line of lines) {
|
|
81
|
+
const [checksum, packageName] = line.split(/\s+/);
|
|
82
|
+
checksums[packageName] = checksum;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return checksums;
|
|
86
|
+
} else {
|
|
87
|
+
console.error(
|
|
88
|
+
"Could not fetch checksum file",
|
|
89
|
+
response.status,
|
|
90
|
+
response.statusText
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
63
95
|
const errGlobal = `Installing Supabase CLI as a global module is not supported.
|
|
64
96
|
Please use one of the supported package managers: https://github.com/supabase/cli#install-the-cli
|
|
65
97
|
`;
|
|
98
|
+
const errChecksum = "Checksum mismatch. Downloaded data might be corrupted.";
|
|
66
99
|
|
|
67
100
|
/**
|
|
68
101
|
* Reads the configuration from application's package.json,
|
|
@@ -91,7 +124,33 @@ async function main() {
|
|
|
91
124
|
|
|
92
125
|
console.info("Downloading", url);
|
|
93
126
|
const resp = await fetch(url);
|
|
94
|
-
|
|
127
|
+
|
|
128
|
+
const hash = createHash("sha256");
|
|
129
|
+
const pkgNameWithPlatform = `${pkg.name}_${platform}_${arch}.tar.gz`;
|
|
130
|
+
const checksumMap = await fetchAndParseCheckSumFile(pkg);
|
|
131
|
+
|
|
132
|
+
resp.body
|
|
133
|
+
.on("data", (chunk) => {
|
|
134
|
+
hash.update(chunk);
|
|
135
|
+
})
|
|
136
|
+
.pipe(ungz);
|
|
137
|
+
|
|
138
|
+
ungz
|
|
139
|
+
.on("end", () => {
|
|
140
|
+
const expectedChecksum = checksumMap?.[pkgNameWithPlatform];
|
|
141
|
+
// Skip verification if we can't find the file checksum
|
|
142
|
+
if (!expectedChecksum) {
|
|
143
|
+
console.warn("Skipping checksum verification");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const calculatedChecksum = hash.digest("hex");
|
|
147
|
+
if (calculatedChecksum !== expectedChecksum) {
|
|
148
|
+
throw errChecksum;
|
|
149
|
+
}
|
|
150
|
+
console.info("Checksum verified.");
|
|
151
|
+
})
|
|
152
|
+
.pipe(untar);
|
|
153
|
+
|
|
95
154
|
await new Promise((resolve, reject) => {
|
|
96
155
|
untar.on("error", reject);
|
|
97
156
|
untar.on("end", () => resolve());
|
|
@@ -103,7 +162,6 @@ async function main() {
|
|
|
103
162
|
pkg: { ...pkg, bin: { [pkg.name]: binPath } },
|
|
104
163
|
});
|
|
105
164
|
|
|
106
|
-
// TODO: verify checksums
|
|
107
165
|
console.info("Installed Supabase CLI successfully");
|
|
108
166
|
}
|
|
109
167
|
|