dreamer-b2b-flux- 0.2.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # dreamer-b2b-flux-
2
+
3
+ Platform-aware npm wrapper package for `dreamer-b2b-flux-`.
4
+
5
+ The package installs a platform-specific binary from this release:
6
+
7
+ `https://github.com/yehezkieldio/dreamer-b2b-yinlin-e2e-/releases/tag/v0.2.0`
@@ -0,0 +1,166 @@
1
+ const fs = require("node:fs");
2
+ const http = require("node:http");
3
+ const https = require("node:https");
4
+ const path = require("node:path");
5
+ const { spawnSync } = require("node:child_process");
6
+ const { URL } = require("node:url");
7
+
8
+ const MAX_REDIRECTS = 5;
9
+ const DOWNLOAD_TIMEOUT_MS = 30000;
10
+
11
+ function fail(message) {
12
+ console.error(message);
13
+ process.exit(1);
14
+ }
15
+
16
+ function downloadToFile(url, destination, redirects = 0) {
17
+ return new Promise((resolve, reject) => {
18
+ let parsed;
19
+ try {
20
+ parsed = new URL(url);
21
+ } catch (error) {
22
+ reject(new Error(`Invalid download URL ${url}: ${error.message}`));
23
+ return;
24
+ }
25
+
26
+ const client = parsed.protocol === "https:" ? https : parsed.protocol === "http:" ? http : null;
27
+ if (!client) {
28
+ reject(new Error(`Unsupported download URL protocol: ${parsed.protocol}`));
29
+ return;
30
+ }
31
+
32
+ const request = client.get(parsed, (response) => {
33
+ if (
34
+ response.statusCode &&
35
+ response.statusCode >= 300 &&
36
+ response.statusCode < 400 &&
37
+ response.headers.location
38
+ ) {
39
+ if (redirects >= MAX_REDIRECTS) {
40
+ response.resume();
41
+ reject(new Error(`Too many redirects while downloading ${url}`));
42
+ return;
43
+ }
44
+ const redirectUrl = new URL(response.headers.location, parsed).toString();
45
+ response.resume();
46
+ downloadToFile(redirectUrl, destination, redirects + 1).then(resolve, reject);
47
+ return;
48
+ }
49
+
50
+ if (response.statusCode !== 200) {
51
+ response.resume();
52
+ reject(new Error(`HTTP ${response.statusCode} while downloading ${url}`));
53
+ return;
54
+ }
55
+
56
+ const out = fs.createWriteStream(destination, { mode: 0o755 });
57
+ out.on("error", reject);
58
+ out.on("finish", () => out.close(resolve));
59
+ response.pipe(out);
60
+ });
61
+
62
+ request.setTimeout(DOWNLOAD_TIMEOUT_MS, () => {
63
+ request.destroy(new Error(`Timed out downloading ${url}`));
64
+ });
65
+ request.on("error", reject);
66
+ });
67
+ }
68
+
69
+ class Package {
70
+ constructor(platform, name, artifactDownloadUrl) {
71
+ this.platform = platform;
72
+ this.name = name;
73
+ this.artifactDownloadUrl = artifactDownloadUrl;
74
+ this.installDirectory = path.join(__dirname, "node_modules", ".bin_real");
75
+ }
76
+
77
+ uniqueBinaryPaths() {
78
+ return [...new Set(Object.values(this.platform.bins || {}))];
79
+ }
80
+
81
+ exists() {
82
+ const binaryPaths = this.uniqueBinaryPaths();
83
+ if (binaryPaths.length === 0) {
84
+ return false;
85
+ }
86
+ return binaryPaths.every((relativePath) =>
87
+ fs.existsSync(path.join(this.installDirectory, relativePath))
88
+ );
89
+ }
90
+
91
+ install(suppressLogs = false) {
92
+ const binaryPaths = this.uniqueBinaryPaths();
93
+ if (binaryPaths.length !== 1) {
94
+ fail(
95
+ `${this.name} expected exactly one binary for ${this.platform.artifactName}, got ${binaryPaths.length}`
96
+ );
97
+ }
98
+
99
+ if (this.exists()) {
100
+ if (!suppressLogs) {
101
+ console.error(`${this.name} is already installed.`);
102
+ }
103
+ return Promise.resolve();
104
+ }
105
+
106
+ fs.rmSync(this.installDirectory, { recursive: true, force: true });
107
+
108
+ const relativePath = binaryPaths[0];
109
+ const destination = path.join(this.installDirectory, relativePath);
110
+ const temporary = `${destination}.tmp-${process.pid}`;
111
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
112
+
113
+ const url = `${this.artifactDownloadUrl}/${this.platform.artifactName}`;
114
+ if (!suppressLogs) {
115
+ console.error(`Downloading ${url}`);
116
+ }
117
+
118
+ fs.rmSync(temporary, { force: true });
119
+ return downloadToFile(url, temporary)
120
+ .then(() => {
121
+ fs.renameSync(temporary, destination);
122
+ if (process.platform !== "win32") {
123
+ fs.chmodSync(destination, 0o755);
124
+ }
125
+ if (!suppressLogs) {
126
+ console.error(`${this.name} installed.`);
127
+ }
128
+ })
129
+ .catch((error) => {
130
+ fs.rmSync(temporary, { force: true });
131
+ fail(`Failed to install ${this.name}: ${error.message}`);
132
+ });
133
+ }
134
+
135
+ run(binaryName) {
136
+ const execute = () => {
137
+ const relativePath = this.platform.bins[binaryName];
138
+ if (!relativePath) {
139
+ fail(`${binaryName} is not published in ${this.name}`);
140
+ }
141
+
142
+ const binaryPath = path.join(this.installDirectory, relativePath);
143
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
144
+ cwd: process.cwd(),
145
+ stdio: "inherit",
146
+ });
147
+
148
+ if (result.error) {
149
+ fail(result.error.message);
150
+ }
151
+
152
+ process.exit(result.status ?? 1);
153
+ };
154
+
155
+ if (!this.exists()) {
156
+ this.install(true).then(execute, (error) => fail(error.message));
157
+ return;
158
+ }
159
+
160
+ execute();
161
+ }
162
+ }
163
+
164
+ module.exports = {
165
+ Package,
166
+ };
package/binary.js ADDED
@@ -0,0 +1,168 @@
1
+ const { Package } = require("./binary-install");
2
+
3
+ const {
4
+ name,
5
+ artifactDownloadUrl,
6
+ supportedPlatforms,
7
+ glibcMinimum,
8
+ } = require("./package.json");
9
+
10
+ function fail(message) {
11
+ console.error(message);
12
+ process.exit(1);
13
+ }
14
+
15
+ function parseVersion(version) {
16
+ if (!version || typeof version !== "string") {
17
+ return null;
18
+ }
19
+ const match = version.match(/^(\d+)\.(\d+)/);
20
+ if (!match) {
21
+ return null;
22
+ }
23
+ return {
24
+ major: Number(match[1]),
25
+ series: Number(match[2]),
26
+ };
27
+ }
28
+
29
+ function runtimeGlibcVersion() {
30
+ const report = process.report;
31
+ if (!report || typeof report.getReport !== "function") {
32
+ return null;
33
+ }
34
+ return parseVersion(report.getReport()?.header?.glibcVersionRuntime || null);
35
+ }
36
+
37
+ function glibcCompatible() {
38
+ const runtime = runtimeGlibcVersion();
39
+ if (!runtime) {
40
+ return false;
41
+ }
42
+ if (runtime.major > glibcMinimum.major) {
43
+ return true;
44
+ }
45
+ if (runtime.major < glibcMinimum.major) {
46
+ return false;
47
+ }
48
+ return runtime.series >= glibcMinimum.series;
49
+ }
50
+
51
+ function platformCandidates() {
52
+ const os = process.platform;
53
+ const arch = process.arch;
54
+
55
+ if (os === "darwin" && arch === "x64") {
56
+ return ["x86_64-apple-darwin"];
57
+ }
58
+ if (os === "darwin" && arch === "arm64") {
59
+ return ["aarch64-apple-darwin"];
60
+ }
61
+ if (os === "win32" && arch === "x64") {
62
+ return ["x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu"];
63
+ }
64
+ if (os === "win32" && arch === "arm64") {
65
+ return ["aarch64-pc-windows-msvc", "aarch64-pc-windows-gnu"];
66
+ }
67
+ if (os === "win32" && arch === "ia32") {
68
+ return ["i686-pc-windows-msvc", "i686-pc-windows-gnu"];
69
+ }
70
+ if (os === "linux" && arch === "x64") {
71
+ if (glibcCompatible()) {
72
+ return [
73
+ "x86_64-unknown-linux-gnu",
74
+ "x86_64-unknown-linux-musl",
75
+ "x86_64-unknown-linux-musl-static",
76
+ "x86_64-unknown-linux-musl-dynamic",
77
+ ];
78
+ }
79
+ return [
80
+ "x86_64-unknown-linux-musl",
81
+ "x86_64-unknown-linux-musl-static",
82
+ "x86_64-unknown-linux-musl-dynamic",
83
+ "x86_64-unknown-linux-gnu",
84
+ ];
85
+ }
86
+ if (os === "linux" && arch === "arm64") {
87
+ if (glibcCompatible()) {
88
+ return [
89
+ "aarch64-unknown-linux-gnu",
90
+ "aarch64-unknown-linux-musl",
91
+ "aarch64-unknown-linux-musl-static",
92
+ "aarch64-unknown-linux-musl-dynamic",
93
+ ];
94
+ }
95
+ return [
96
+ "aarch64-unknown-linux-musl",
97
+ "aarch64-unknown-linux-musl-static",
98
+ "aarch64-unknown-linux-musl-dynamic",
99
+ "aarch64-unknown-linux-gnu",
100
+ ];
101
+ }
102
+ if (os === "linux" && arch === "arm") {
103
+ if (glibcCompatible()) {
104
+ return [
105
+ "armv7-unknown-linux-gnueabihf",
106
+ "arm-unknown-linux-gnueabihf",
107
+ "armv7-unknown-linux-musleabihf",
108
+ "arm-unknown-linux-musleabihf",
109
+ ];
110
+ }
111
+ return [
112
+ "armv7-unknown-linux-musleabihf",
113
+ "arm-unknown-linux-musleabihf",
114
+ "armv7-unknown-linux-gnueabihf",
115
+ "arm-unknown-linux-gnueabihf",
116
+ ];
117
+ }
118
+ if (os === "linux" && arch === "ia32") {
119
+ if (glibcCompatible()) {
120
+ return ["i686-unknown-linux-gnu", "i686-unknown-linux-musl"];
121
+ }
122
+ return ["i686-unknown-linux-musl", "i686-unknown-linux-gnu"];
123
+ }
124
+ if (os === "linux" && arch === "riscv64") {
125
+ if (glibcCompatible()) {
126
+ return ["riscv64gc-unknown-linux-gnu", "riscv64gc-unknown-linux-musl"];
127
+ }
128
+ return ["riscv64gc-unknown-linux-musl", "riscv64gc-unknown-linux-gnu"];
129
+ }
130
+
131
+ return [];
132
+ }
133
+
134
+ function getPlatform() {
135
+ for (const triple of platformCandidates()) {
136
+ const entry = supportedPlatforms[triple];
137
+ if (entry) {
138
+ return entry;
139
+ }
140
+ }
141
+
142
+ fail(
143
+ `Unsupported platform ${process.platform}/${process.arch} for ${name}. ` +
144
+ `Supported targets: ${Object.keys(supportedPlatforms).join(", ")}`
145
+ );
146
+ }
147
+
148
+ function getPackage() {
149
+ const platform = getPlatform();
150
+ return new Package(platform, name, artifactDownloadUrl);
151
+ }
152
+
153
+ function install(suppressLogs) {
154
+ if (!artifactDownloadUrl || typeof artifactDownloadUrl !== "string") {
155
+ fail(`Invalid artifactDownloadUrl for ${name}`);
156
+ }
157
+ return getPackage().install(suppressLogs);
158
+ }
159
+
160
+ function run(binaryName) {
161
+ return getPackage().run(binaryName);
162
+ }
163
+
164
+ module.exports = {
165
+ getPackage,
166
+ install,
167
+ run,
168
+ };
package/install.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { install } = require("./binary");
4
+
5
+ install(false);
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "dreamer-b2b-flux-",
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "description": "Platform-aware binary installer for dreamer-b2b-flux-",
6
+ "license": "MIT",
7
+ "artifactDownloadUrl": "https://github.com/yehezkieldio/dreamer-b2b-yinlin-e2e-/releases/download/v0.2.0",
8
+ "supportedPlatforms": {"x86_64-unknown-linux-gnu":{"artifactName":"dreamer-b2b-flux--x86_64-unknown-linux-gnu","bins":{"dreamer-b2b-flux-":"dreamer-b2b-flux-"},"zipExt":""}},
9
+ "glibcMinimum": {"major":2,"series":31},
10
+ "bin": {
11
+ "dreamer-b2b-flux-": "run-dreamer-b2b-flux-.js"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node ./install.js"
15
+ },
16
+ "files": [
17
+ "README.md",
18
+ "install.js",
19
+ "binary.js",
20
+ "binary-install.js",
21
+ "run-dreamer-b2b-flux-.js"
22
+ ]
23
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { run } = require("./binary");
4
+
5
+ run("dreamer-b2b-flux-");