@cparra/apex-reflection 2.24.4 → 3.0.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/dist/{index.d.ts → index.d.mts} +2 -4
- package/dist/index.mjs +34 -0
- package/dist/node.mjs +344 -0
- package/dist/node.wasm +0 -0
- package/package.json +16 -22
- package/dist/index.js +0 -145
- package/dist/out.js +0 -18271
- package/out.js +0 -18271
- package/publish-scripts/postinstall.js +0 -279
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Postinstall script.
|
|
5
|
-
* - Downloads the correct native binary for the current platform/arch from GitHub Releases
|
|
6
|
-
* - Stores it inside this package at: dist/native/<platform-arch>/<binaryName>
|
|
7
|
-
* - Ensures executable permissions on Unix-like systems
|
|
8
|
-
*
|
|
9
|
-
* Asset naming convention (GitHub Release assets):
|
|
10
|
-
* apex-reflection-<platform>-<arch>[.exe]
|
|
11
|
-
*
|
|
12
|
-
* Where:
|
|
13
|
-
* platform: darwin | linux | windows
|
|
14
|
-
* arch: x64 | arm64 (darwin supports both; linux/windows only x64 in this setup)
|
|
15
|
-
*
|
|
16
|
-
* The GitHub release tag is expected to be:
|
|
17
|
-
* v<version> (version taken from this package's package.json)
|
|
18
|
-
*
|
|
19
|
-
* Note:
|
|
20
|
-
* - To make installs resilient (especially for dev releases), we try multiple possible asset names.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
const https = require("https");
|
|
24
|
-
const fs = require("fs");
|
|
25
|
-
const path = require("path");
|
|
26
|
-
const stream = require("stream");
|
|
27
|
-
const { promisify } = require("util");
|
|
28
|
-
|
|
29
|
-
const pipeline = promisify(stream.pipeline);
|
|
30
|
-
|
|
31
|
-
const REPO_OWNER = "cesarParra";
|
|
32
|
-
const REPO_NAME = "apex-reflection";
|
|
33
|
-
|
|
34
|
-
function main() {
|
|
35
|
-
console.log("[apex-reflection] postinstall: installing native binary...");
|
|
36
|
-
|
|
37
|
-
const pkg = readPackageJson();
|
|
38
|
-
const version = pkg.version;
|
|
39
|
-
if (!version || typeof version !== "string") {
|
|
40
|
-
fail("package.json missing a valid `version` field.");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const target = resolveTarget(process.platform, process.arch);
|
|
44
|
-
const tag = `v${version}`;
|
|
45
|
-
|
|
46
|
-
const outDir = path.join(
|
|
47
|
-
__dirname,
|
|
48
|
-
"..",
|
|
49
|
-
"dist",
|
|
50
|
-
"native",
|
|
51
|
-
target.folderName,
|
|
52
|
-
);
|
|
53
|
-
const outPath = path.join(outDir, target.binaryFileName);
|
|
54
|
-
|
|
55
|
-
fs.mkdirSync(outDir, { recursive: true });
|
|
56
|
-
|
|
57
|
-
const candidateAssetNames = buildCandidateAssetNames(target);
|
|
58
|
-
|
|
59
|
-
return downloadFirstAvailableAsset(tag, candidateAssetNames, outPath)
|
|
60
|
-
.then(({ assetName }) => {
|
|
61
|
-
if (process.platform !== "win32") {
|
|
62
|
-
try {
|
|
63
|
-
fs.chmodSync(outPath, 0o755);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
console.warn(
|
|
66
|
-
`[apex-reflection] postinstall: could not chmod +x ${outPath}: ${stringifyErr(e)}`,
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
console.log(
|
|
72
|
-
`[apex-reflection] postinstall: native binary installed at: ${outPath} (asset: ${assetName})`,
|
|
73
|
-
);
|
|
74
|
-
})
|
|
75
|
-
.catch((err) => {
|
|
76
|
-
// Non-fatal: do not fail installation for downstream dependents.
|
|
77
|
-
// At runtime, the tool will surface a clear error if the binary is missing.
|
|
78
|
-
console.warn(
|
|
79
|
-
"[apex-reflection] postinstall: warning: failed to install native binary (install will continue).",
|
|
80
|
-
);
|
|
81
|
-
console.warn(`[apex-reflection] postinstall: ${stringifyErr(err)}`);
|
|
82
|
-
console.warn(
|
|
83
|
-
"[apex-reflection] postinstall: If you intend to use apex-reflection, ensure the native binary is available.",
|
|
84
|
-
);
|
|
85
|
-
console.warn(
|
|
86
|
-
"[apex-reflection] postinstall: Verify the release assets here:",
|
|
87
|
-
);
|
|
88
|
-
console.warn(
|
|
89
|
-
`https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/${tag}`,
|
|
90
|
-
);
|
|
91
|
-
// Exit successfully and defer the failure to runtime.
|
|
92
|
-
process.exit(0);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function readPackageJson() {
|
|
97
|
-
const pkgPath = path.join(__dirname, "..", "package.json");
|
|
98
|
-
const raw = fs.readFileSync(pkgPath, "utf8");
|
|
99
|
-
return JSON.parse(raw);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function resolveTarget(nodePlatform, nodeArch) {
|
|
103
|
-
const platformMap = {
|
|
104
|
-
darwin: "darwin",
|
|
105
|
-
linux: "linux",
|
|
106
|
-
win32: "windows",
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const releasePlatform = platformMap[nodePlatform];
|
|
110
|
-
if (!releasePlatform) {
|
|
111
|
-
throw new Error(`Unsupported platform: ${nodePlatform}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const supportedArch = new Set(["x64", "arm64"]);
|
|
115
|
-
if (!supportedArch.has(nodeArch)) {
|
|
116
|
-
throw new Error(`Unsupported architecture: ${nodeArch}`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (releasePlatform === "linux" && nodeArch !== "x64") {
|
|
120
|
-
throw new Error(`Unsupported architecture for linux: ${nodeArch}`);
|
|
121
|
-
}
|
|
122
|
-
if (releasePlatform === "windows" && nodeArch !== "x64" && nodeArch !== "arm64") {
|
|
123
|
-
throw new Error(`Unsupported architecture for windows: ${nodeArch}`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const folderName = `${releasePlatform}-${nodeArch}`;
|
|
127
|
-
const exeExt = releasePlatform === "windows" ? ".exe" : "";
|
|
128
|
-
const binaryFileName = `apex-reflection${exeExt}`;
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
releasePlatform,
|
|
132
|
-
releaseArch: nodeArch,
|
|
133
|
-
folderName,
|
|
134
|
-
exeExt,
|
|
135
|
-
binaryFileName,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function buildCandidateAssetNames(target) {
|
|
140
|
-
// Primary convention (expected):
|
|
141
|
-
// apex-reflection-<platform>-<arch>[.exe]
|
|
142
|
-
const primary = `apex-reflection-${target.releasePlatform}-${target.releaseArch}${target.exeExt}`;
|
|
143
|
-
|
|
144
|
-
// Fallbacks (mainly for dev flows / edge cases):
|
|
145
|
-
const fallbacks = [];
|
|
146
|
-
|
|
147
|
-
// Unsuffixed name (no arch/platform)
|
|
148
|
-
// - For windows, prefer .exe and then without extension (just in case).
|
|
149
|
-
if (target.releasePlatform === "windows") {
|
|
150
|
-
fallbacks.push("apex-reflection.exe");
|
|
151
|
-
fallbacks.push("apex-reflection");
|
|
152
|
-
} else {
|
|
153
|
-
fallbacks.push("apex-reflection");
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// De-dup while preserving order
|
|
157
|
-
const seen = new Set();
|
|
158
|
-
return [primary, ...fallbacks].filter((name) => {
|
|
159
|
-
if (seen.has(name)) return false;
|
|
160
|
-
seen.add(name);
|
|
161
|
-
return true;
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function downloadFirstAvailableAsset(tag, assetNames, destPath) {
|
|
166
|
-
const base = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/`;
|
|
167
|
-
|
|
168
|
-
let lastErr = null;
|
|
169
|
-
|
|
170
|
-
// Try sequentially until one downloads successfully
|
|
171
|
-
return assetNames
|
|
172
|
-
.reduce(
|
|
173
|
-
(p, assetName) => {
|
|
174
|
-
return p.catch((_) => {
|
|
175
|
-
const url = `${base}${assetName}`;
|
|
176
|
-
process.stdout.write(
|
|
177
|
-
`[apex-reflection] postinstall: trying ${url}\n`,
|
|
178
|
-
);
|
|
179
|
-
return downloadFile(url, destPath).then(() => ({ assetName }));
|
|
180
|
-
});
|
|
181
|
-
},
|
|
182
|
-
Promise.reject(new Error("No candidate asset attempted yet.")),
|
|
183
|
-
)
|
|
184
|
-
.catch((err) => {
|
|
185
|
-
lastErr = err;
|
|
186
|
-
const tried = assetNames.map((n) => `${base}${n}`).join("\n");
|
|
187
|
-
const msg =
|
|
188
|
-
`Unable to download any matching binary asset for ${process.platform}/${process.arch}.\n` +
|
|
189
|
-
`Tried:\n${tried}\n` +
|
|
190
|
-
`Last error: ${stringifyErr(lastErr)}`;
|
|
191
|
-
throw new Error(msg);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function downloadFile(url, destPath) {
|
|
196
|
-
return new Promise((resolve, reject) => {
|
|
197
|
-
const tmpPath = `${destPath}.tmp`;
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath);
|
|
201
|
-
} catch (_) {
|
|
202
|
-
// ignore
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const request = https.get(url, (response) => {
|
|
206
|
-
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
207
|
-
const next = response.headers.location;
|
|
208
|
-
response.resume();
|
|
209
|
-
if (!next)
|
|
210
|
-
return reject(new Error(`Redirect with no location for ${url}`));
|
|
211
|
-
return downloadFile(next, destPath).then(resolve, reject);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (response.statusCode !== 200) {
|
|
215
|
-
response.resume();
|
|
216
|
-
return reject(
|
|
217
|
-
new Error(`HTTP ${response.statusCode} while downloading ${url}`),
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const totalSize = Number(response.headers["content-length"] || 0);
|
|
222
|
-
let downloaded = 0;
|
|
223
|
-
|
|
224
|
-
response.on("data", (chunk) => {
|
|
225
|
-
downloaded += chunk.length;
|
|
226
|
-
if (totalSize > 0) {
|
|
227
|
-
const pct = Math.floor((downloaded / totalSize) * 100);
|
|
228
|
-
process.stdout.write(
|
|
229
|
-
`\r[apex-reflection] postinstall: downloading... ${pct}%`,
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
const file = fs.createWriteStream(tmpPath);
|
|
235
|
-
|
|
236
|
-
pipeline(response, file)
|
|
237
|
-
.then(() => {
|
|
238
|
-
process.stdout.write("\n");
|
|
239
|
-
fs.renameSync(tmpPath, destPath);
|
|
240
|
-
resolve();
|
|
241
|
-
})
|
|
242
|
-
.catch((err) => {
|
|
243
|
-
try {
|
|
244
|
-
if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath);
|
|
245
|
-
} catch (_) {
|
|
246
|
-
// ignore
|
|
247
|
-
}
|
|
248
|
-
reject(err);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
request.on("error", (err) => {
|
|
253
|
-
try {
|
|
254
|
-
if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath);
|
|
255
|
-
} catch (_) {
|
|
256
|
-
// ignore
|
|
257
|
-
}
|
|
258
|
-
reject(err);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function stringifyErr(e) {
|
|
264
|
-
if (!e) return "unknown error";
|
|
265
|
-
if (typeof e === "string") return e;
|
|
266
|
-
if (e && e.message) return e.message;
|
|
267
|
-
try {
|
|
268
|
-
return JSON.stringify(e);
|
|
269
|
-
} catch (_) {
|
|
270
|
-
return String(e);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function fail(msg) {
|
|
275
|
-
console.error(`[apex-reflection] postinstall: ${msg}`);
|
|
276
|
-
process.exit(1);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
Promise.resolve(main());
|