zonepm 0.1.0 → 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/bin/zpm +42 -12
- package/package.json +7 -3
- package/scripts/postinstall.js +30 -0
package/bin/zpm
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
const { execFileSync, spawnSync } = require("child_process");
|
|
3
4
|
const path = require("path");
|
|
4
5
|
const fs = require("fs");
|
|
5
6
|
|
|
@@ -16,23 +17,52 @@ if (!pkgName) {
|
|
|
16
17
|
process.exit(1);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
21
|
+
const binName = `zpm${ext}`;
|
|
22
|
+
|
|
23
|
+
// Platform package name without scope (e.g., "darwin-arm64")
|
|
24
|
+
const platformDir = pkgName.split("/").pop();
|
|
25
|
+
|
|
26
|
+
function findBinary() {
|
|
27
|
+
// 1. Try require.resolve (works for local node_modules installs)
|
|
28
|
+
try {
|
|
29
|
+
const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
|
|
30
|
+
const p = path.join(pkgDir, binName);
|
|
31
|
+
if (fs.existsSync(p)) return p;
|
|
32
|
+
} catch {}
|
|
33
|
+
|
|
34
|
+
// 2. Try sibling directory (works for pnpm link / monorepo layout)
|
|
35
|
+
{
|
|
36
|
+
const p = path.join(__dirname, "..", "..", platformDir, binName);
|
|
37
|
+
if (fs.existsSync(p)) return p;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 3. Try resolving from global node_modules paths
|
|
41
|
+
const globalDirs = [];
|
|
42
|
+
try {
|
|
43
|
+
globalDirs.push(execFileSync("npm", ["root", "-g"], { encoding: "utf8" }).trim());
|
|
44
|
+
} catch {}
|
|
45
|
+
try {
|
|
46
|
+
globalDirs.push(execFileSync("pnpm", ["root", "-g"], { encoding: "utf8" }).trim());
|
|
47
|
+
} catch {}
|
|
48
|
+
|
|
49
|
+
for (const dir of globalDirs) {
|
|
50
|
+
const p = path.join(dir, pkgName, binName);
|
|
51
|
+
if (fs.existsSync(p)) return p;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return null;
|
|
28
55
|
}
|
|
29
56
|
|
|
30
|
-
|
|
31
|
-
|
|
57
|
+
const binPath = findBinary();
|
|
58
|
+
|
|
59
|
+
if (!binPath) {
|
|
60
|
+
console.error(`Could not find package ${pkgName}.`);
|
|
61
|
+
console.error(`Try: npm install -g ${pkgName}`);
|
|
32
62
|
process.exit(1);
|
|
33
63
|
}
|
|
34
64
|
|
|
35
|
-
const result =
|
|
65
|
+
const result = spawnSync(binPath, process.argv.slice(2), {
|
|
36
66
|
stdio: "inherit",
|
|
37
67
|
});
|
|
38
68
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zonepm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A minimal npm package manager written in Rust",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
"bin": {
|
|
11
11
|
"zpm": "bin/zpm"
|
|
12
12
|
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"postinstall": "node scripts/postinstall.js"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
|
-
"bin"
|
|
17
|
+
"bin",
|
|
18
|
+
"scripts"
|
|
15
19
|
],
|
|
16
20
|
"optionalDependencies": {
|
|
17
|
-
"@zonepm/darwin-arm64": "0.
|
|
21
|
+
"@zonepm/darwin-arm64": "0.2.0"
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
|
|
3
|
+
const PLATFORMS = {
|
|
4
|
+
"darwin-arm64": "@zonepm/darwin-arm64",
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
8
|
+
const pkgName = PLATFORMS[platformKey];
|
|
9
|
+
|
|
10
|
+
if (!pkgName) {
|
|
11
|
+
console.warn(`zonepm: no prebuilt binary for ${platformKey}`);
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Check if the platform package is already installed
|
|
16
|
+
try {
|
|
17
|
+
require.resolve(`${pkgName}/package.json`);
|
|
18
|
+
// Already installed, nothing to do
|
|
19
|
+
} catch {
|
|
20
|
+
console.log(`zonepm: installing ${pkgName}...`);
|
|
21
|
+
try {
|
|
22
|
+
execSync(`npm install ${pkgName}@${require("../package.json").version}`, {
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
env: { ...process.env, npm_config_global: "" },
|
|
25
|
+
});
|
|
26
|
+
} catch {
|
|
27
|
+
console.warn(`zonepm: failed to install ${pkgName}. You may need to install it manually:`);
|
|
28
|
+
console.warn(` npm install ${pkgName}`);
|
|
29
|
+
}
|
|
30
|
+
}
|