mafit 2.3.0 → 2.4.1
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/bin/mafit.js +36 -21
- package/lib/platform.js +26 -0
- package/package.json +9 -8
- package/scripts/postinstall.js +61 -0
package/bin/mafit.js
CHANGED
|
@@ -4,44 +4,59 @@ import { spawn } from "node:child_process";
|
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
PLATFORM_PACKAGE_BY_PLATFORM_ARCH,
|
|
9
|
+
platformBinaryName,
|
|
10
|
+
platformKey,
|
|
11
|
+
} from "../lib/platform.js";
|
|
8
12
|
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
13
|
const require = createRequire(import.meta.url);
|
|
12
14
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"linux-x64": "mafit-linux-x64",
|
|
17
|
-
"linux-arm64": "mafit-linux-arm64",
|
|
18
|
-
"win32-x64": "mafit-windows-x64",
|
|
19
|
-
"win32-arm64": "mafit-windows-arm64",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const platformKey = `${process.platform}-${process.arch}`;
|
|
23
|
-
const packageName = PLATFORM_PACKAGE_BY_PLATFORM_ARCH[platformKey];
|
|
15
|
+
const { version } = require("../package.json");
|
|
16
|
+
const key = platformKey();
|
|
17
|
+
const packageName = PLATFORM_PACKAGE_BY_PLATFORM_ARCH[key];
|
|
24
18
|
|
|
25
19
|
if (!packageName) {
|
|
26
20
|
console.error(`Unsupported platform: ${process.platform} (${process.arch})`);
|
|
21
|
+
console.error(`mafit@${version} ships binaries for: ${Object.keys(PLATFORM_PACKAGE_BY_PLATFORM_ARCH).join(", ")}`);
|
|
27
22
|
process.exit(1);
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
const binaryName =
|
|
25
|
+
const binaryName = platformBinaryName();
|
|
31
26
|
|
|
32
|
-
let
|
|
27
|
+
let packageDir;
|
|
33
28
|
try {
|
|
34
|
-
|
|
35
|
-
binaryPath = path.join(path.dirname(packageJsonPath), binaryName);
|
|
29
|
+
packageDir = path.dirname(require.resolve(`${packageName}/package.json`));
|
|
36
30
|
} catch {
|
|
31
|
+
// npm treats a 404 on an optional dependency as non-fatal, so a global
|
|
32
|
+
// install that raced the registry can silently end up without the binary.
|
|
37
33
|
console.error(`Missing optional platform package: ${packageName}`);
|
|
38
|
-
console.error("
|
|
34
|
+
console.error("");
|
|
35
|
+
console.error(`mafit@${version} needs ${packageName}@${version} on ${key}.`);
|
|
36
|
+
console.error("npm silently skips optional dependencies it cannot fetch, so this");
|
|
37
|
+
console.error("usually means the install ran before that package was published.");
|
|
38
|
+
console.error("");
|
|
39
|
+
console.error("Fix with one of:");
|
|
40
|
+
console.error(` npm uninstall -g mafit && npm install -g mafit@${version}`);
|
|
41
|
+
console.error(` npm install -g ${packageName}@${version}`);
|
|
42
|
+
console.error(" npm cache clean --force # if it keeps failing");
|
|
39
43
|
process.exit(1);
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
const platformVersion = require(`${packageName}/package.json`).version;
|
|
47
|
+
if (platformVersion !== version) {
|
|
48
|
+
console.error(
|
|
49
|
+
`warning: ${packageName}@${platformVersion} does not match mafit@${version}`
|
|
50
|
+
);
|
|
51
|
+
console.error(" Reinstall both together: npm uninstall -g mafit && npm install -g mafit@" + version);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const binaryPath = path.join(packageDir, binaryName);
|
|
55
|
+
|
|
42
56
|
if (!existsSync(binaryPath)) {
|
|
43
|
-
console.error(`Missing mafit binary for ${
|
|
44
|
-
console.error(`Expected
|
|
57
|
+
console.error(`Missing mafit binary for ${key}: ${binaryPath}`);
|
|
58
|
+
console.error(`Expected ${packageName}@${version} to contain ${binaryName}.`);
|
|
59
|
+
console.error(` npm uninstall -g mafit && npm install -g mafit@${version}`);
|
|
45
60
|
process.exit(1);
|
|
46
61
|
}
|
|
47
62
|
|
package/lib/platform.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the shipped package: which optional platform
|
|
3
|
+
* package this process needs, and what the binary inside it is called.
|
|
4
|
+
* Shared by bin/mafit.js (runtime dispatch) and scripts/postinstall.js
|
|
5
|
+
* (install-time verification) so the two can never disagree.
|
|
6
|
+
*/
|
|
7
|
+
export const PLATFORM_PACKAGE_BY_PLATFORM_ARCH = {
|
|
8
|
+
"darwin-x64": "mafit-darwin-x64",
|
|
9
|
+
"darwin-arm64": "mafit-darwin-arm64",
|
|
10
|
+
"linux-x64": "mafit-linux-x64",
|
|
11
|
+
"linux-arm64": "mafit-linux-arm64",
|
|
12
|
+
"win32-x64": "mafit-windows-x64",
|
|
13
|
+
"win32-arm64": "mafit-windows-arm64",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function platformKey() {
|
|
17
|
+
return `${process.platform}-${process.arch}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function platformPackageName() {
|
|
21
|
+
return PLATFORM_PACKAGE_BY_PLATFORM_ARCH[platformKey()];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function platformBinaryName() {
|
|
25
|
+
return process.platform === "win32" ? "mafit.exe" : "mafit";
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mafit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Mafit local agent CLI",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"bin",
|
|
15
15
|
"scripts",
|
|
16
|
-
"README.md"
|
|
16
|
+
"README.md",
|
|
17
|
+
"lib"
|
|
17
18
|
],
|
|
18
19
|
"optionalDependencies": {
|
|
19
|
-
"mafit-linux-x64": "2.
|
|
20
|
-
"mafit-linux-arm64": "2.
|
|
21
|
-
"mafit-darwin-x64": "2.
|
|
22
|
-
"mafit-darwin-arm64": "2.
|
|
23
|
-
"mafit-windows-x64": "2.
|
|
24
|
-
"mafit-windows-arm64": "2.
|
|
20
|
+
"mafit-linux-x64": "2.4.1",
|
|
21
|
+
"mafit-linux-arm64": "2.4.1",
|
|
22
|
+
"mafit-darwin-x64": "2.4.1",
|
|
23
|
+
"mafit-darwin-arm64": "2.4.1",
|
|
24
|
+
"mafit-windows-x64": "2.4.1",
|
|
25
|
+
"mafit-windows-arm64": "2.4.1"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build:binaries": "../scripts/build-npm-binaries.sh",
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import {
|
|
5
|
+
PLATFORM_PACKAGE_BY_PLATFORM_ARCH,
|
|
6
|
+
platformKey,
|
|
7
|
+
} from "../lib/platform.js";
|
|
8
|
+
|
|
3
9
|
if (process.env.CI === "true") {
|
|
4
10
|
process.exit(0);
|
|
5
11
|
}
|
|
6
12
|
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const { version } = require("../package.json");
|
|
15
|
+
|
|
16
|
+
// Fail loudly instead of printing a success banner for an install that cannot
|
|
17
|
+
// run: npm skips optional dependencies it cannot fetch, which happens when the
|
|
18
|
+
// install races the registry right after a release.
|
|
19
|
+
function missingPlatformPackage() {
|
|
20
|
+
const key = platformKey();
|
|
21
|
+
const packageName = PLATFORM_PACKAGE_BY_PLATFORM_ARCH[key];
|
|
22
|
+
if (!packageName) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
require.resolve(`${packageName}/package.json`);
|
|
27
|
+
return null;
|
|
28
|
+
} catch {
|
|
29
|
+
return packageName;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
function isChineseLocale() {
|
|
8
34
|
let systemLocale = "";
|
|
9
35
|
try {
|
|
@@ -73,4 +99,39 @@ const chineseLines = [
|
|
|
73
99
|
"",
|
|
74
100
|
];
|
|
75
101
|
|
|
102
|
+
function reportMissingPlatformPackage(packageName) {
|
|
103
|
+
const chinese = isChineseLocale();
|
|
104
|
+
const lines = chinese
|
|
105
|
+
? [
|
|
106
|
+
"",
|
|
107
|
+
` ✗ 安装不完整:缺少 ${packageName}`,
|
|
108
|
+
"",
|
|
109
|
+
` mafit@${version} 需要 ${packageName}@${version}。`,
|
|
110
|
+
" npm 会静默跳过拉取失败的可选依赖,通常发生在刚发布后立刻安装。",
|
|
111
|
+
"",
|
|
112
|
+
" 修复:",
|
|
113
|
+
` npm uninstall -g mafit && npm install -g mafit@${version}`,
|
|
114
|
+
` npm install -g ${packageName}@${version}`,
|
|
115
|
+
]
|
|
116
|
+
: [
|
|
117
|
+
"",
|
|
118
|
+
` ✗ Incomplete install: ${packageName} is missing`,
|
|
119
|
+
"",
|
|
120
|
+
` mafit@${version} needs ${packageName}@${version}.`,
|
|
121
|
+
" npm silently skips optional dependencies it cannot fetch; this usually",
|
|
122
|
+
" happens when installing right after a release.",
|
|
123
|
+
"",
|
|
124
|
+
" Fix:",
|
|
125
|
+
` npm uninstall -g mafit && npm install -g mafit@${version}`,
|
|
126
|
+
` npm install -g ${packageName}@${version}`,
|
|
127
|
+
];
|
|
128
|
+
console.error([...heading, ...lines, ""].join("\n"));
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const missing = missingPlatformPackage();
|
|
133
|
+
if (missing) {
|
|
134
|
+
reportMissingPlatformPackage(missing);
|
|
135
|
+
}
|
|
136
|
+
|
|
76
137
|
console.log([...heading, ...(isChineseLocale() ? chineseLines : englishLines)].join("\n"));
|