@acidify/yogurt 0.1.0-dev.108 → 0.1.0-dev.111

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.
Files changed (3) hide show
  1. package/index.mjs +102 -0
  2. package/package.json +7 -7
  3. package/index.js +0 -54
package/index.mjs ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'child_process';
4
+ import { fileURLToPath } from 'url';
5
+ import path from 'path';
6
+ import fs from 'fs';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ const { platform, arch } = process;
12
+
13
+ const yogurtBinaryName = process.platform === 'win32' ? 'yogurt.exe' : 'yogurt.kexe';
14
+
15
+ // Installed globally with npm, and executed with `yogurt`
16
+ const globalInstallRoot = path.resolve(
17
+ __dirname,
18
+ 'node_modules', // nested node_modules folder
19
+ '@acidify',
20
+ `yogurt-${platform}-${arch}`,
21
+ );
22
+
23
+ // Installed locally, and executed with `npx yogurt`
24
+ const localInstallRoot = path.resolve(
25
+ process.cwd(),
26
+ 'node_modules', // project's node_modules folder
27
+ '@acidify',
28
+ `yogurt-${platform}-${arch}`,
29
+ );
30
+
31
+ const localInstallRootNonCwd = path.resolve(
32
+ __dirname, // yogurt
33
+ '..', // @acidify
34
+ '..', // project's node_modules folder
35
+ '@acidify',
36
+ `yogurt-${platform}-${arch}`,
37
+ );
38
+
39
+ const globalBinaryPath = path.join(globalInstallRoot, yogurtBinaryName);
40
+ const localBinaryPath = path.join(localInstallRoot, yogurtBinaryName);
41
+ const localBinaryPathNonCwd = path.join(localInstallRootNonCwd, yogurtBinaryName);
42
+
43
+ const getBinaryPath = () => {
44
+ if (fs.existsSync(globalBinaryPath)) {
45
+ return globalBinaryPath;
46
+ }
47
+ if (fs.existsSync(localBinaryPath)) {
48
+ return localBinaryPath;
49
+ }
50
+ if (fs.existsSync(localBinaryPathNonCwd)) {
51
+ return localBinaryPathNonCwd;
52
+ }
53
+
54
+ console.error(`Yogurt binary not found for ${platform}-${arch}, please ensure it is installed correctly.`);
55
+ console.error('The script has looked for the binary in the following locations:');
56
+ console.error(` - ${globalBinaryPath}`);
57
+ console.error(` - ${localBinaryPath}`);
58
+ console.error(` - ${localBinaryPathNonCwd}`);
59
+ process.exit(1);
60
+ };
61
+
62
+ const binaryPath = getBinaryPath();
63
+
64
+ const child = spawn(binaryPath, [], {
65
+ stdio: 'inherit',
66
+ });
67
+
68
+ child.on('error', (err) => {
69
+ console.error(err);
70
+ process.exit(1);
71
+ });
72
+
73
+ const forwardSignal = (signal) => {
74
+ if (child.killed) {
75
+ return;
76
+ }
77
+ try {
78
+ child.kill(signal);
79
+ } catch {
80
+ /* ignore */
81
+ }
82
+ };
83
+
84
+ ['SIGINT', 'SIGTERM', 'SIGHUP'].forEach((sig) => {
85
+ process.on(sig, () => forwardSignal(sig));
86
+ });
87
+
88
+ const childResult = await new Promise((resolve) => {
89
+ child.on('exit', (code, signal) => {
90
+ if (signal) {
91
+ resolve({ type: 'signal', signal });
92
+ } else {
93
+ resolve({ type: 'code', exitCode: code ?? 1 });
94
+ }
95
+ });
96
+ });
97
+
98
+ if (childResult.type === 'signal') {
99
+ process.kill(process.pid, childResult.signal);
100
+ } else {
101
+ process.exit(childResult.exitCode);
102
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@acidify/yogurt",
3
- "version": "0.1.0-dev.108",
3
+ "version": "0.1.0-dev.111",
4
4
  "description": "Milky implementation based on Acidify",
5
5
  "bin": {
6
- "yogurt": "./index.js"
6
+ "yogurt": "index.mjs"
7
7
  },
8
8
  "keywords": [
9
9
  "qq",
@@ -18,10 +18,10 @@
18
18
  "license": "GPL-3.0-only",
19
19
  "packageManager": "pnpm@10.26.0",
20
20
  "optionalDependencies": {
21
- "@acidify/yogurt-win32-x64": "0.1.0-dev.108",
22
- "@acidify/yogurt-linux-x64": "0.1.0-dev.108",
23
- "@acidify/yogurt-linux-arm64": "0.1.0-dev.108",
24
- "@acidify/yogurt-darwin-x64": "0.1.0-dev.108",
25
- "@acidify/yogurt-darwin-arm64": "0.1.0-dev.108"
21
+ "@acidify/yogurt-win32-x64": "0.1.0-dev.111",
22
+ "@acidify/yogurt-linux-x64": "0.1.0-dev.111",
23
+ "@acidify/yogurt-linux-arm64": "0.1.0-dev.111",
24
+ "@acidify/yogurt-darwin-x64": "0.1.0-dev.111",
25
+ "@acidify/yogurt-darwin-arm64": "0.1.0-dev.111"
26
26
  }
27
27
  }
package/index.js DELETED
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { spawn } from "child_process";
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- const { platform, arch } = process;
11
-
12
- const vendorRoot = path.join(__dirname, "node_modules", "@acidify", `yogurt-${platform}-${arch}`);
13
- const yogurtBinaryName = process.platform === "win32" ? "yogurt.exe" : "yogurt.kexe";
14
- const binaryPath = path.join(vendorRoot, yogurtBinaryName);
15
-
16
- const child = spawn(binaryPath, [], {
17
- stdio: "inherit",
18
- });
19
-
20
- child.on("error", (err) => {
21
- console.error(err);
22
- process.exit(1);
23
- });
24
-
25
- const forwardSignal = (signal) => {
26
- if (child.killed) {
27
- return;
28
- }
29
- try {
30
- child.kill(signal);
31
- } catch {
32
- /* ignore */
33
- }
34
- };
35
-
36
- ["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
37
- process.on(sig, () => forwardSignal(sig));
38
- });
39
-
40
- const childResult = await new Promise((resolve) => {
41
- child.on("exit", (code, signal) => {
42
- if (signal) {
43
- resolve({ type: "signal", signal });
44
- } else {
45
- resolve({ type: "code", exitCode: code ?? 1 });
46
- }
47
- });
48
- });
49
-
50
- if (childResult.type === "signal") {
51
- process.kill(process.pid, childResult.signal);
52
- } else {
53
- process.exit(childResult.exitCode);
54
- }