typeslayer 0.1.4 → 0.1.5
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/package.json +2 -6
- package/scripts/postinstall.js +77 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeslayer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Slay your TypeScript types",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -44,10 +44,6 @@
|
|
|
44
44
|
},
|
|
45
45
|
"packageManager": "pnpm@10.6.5",
|
|
46
46
|
"scripts": {
|
|
47
|
-
"postinstall": "node scripts/postinstall.js"
|
|
48
|
-
"dev": "vite",
|
|
49
|
-
"build": "tsc && vite build",
|
|
50
|
-
"preview": "vite preview",
|
|
51
|
-
"tauri": "tauri"
|
|
47
|
+
"postinstall": "node scripts/postinstall.js"
|
|
52
48
|
}
|
|
53
49
|
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
5
6
|
import { arch, platform } from "node:os";
|
|
6
7
|
import { dirname, join } from "node:path";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
8
9
|
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
11
|
const __dirname = dirname(__filename);
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
11
13
|
|
|
12
14
|
const PACKAGE_VERSION = process.env.npm_package_version;
|
|
13
15
|
|
|
@@ -19,84 +21,49 @@ if (process.env.TYPESLAYER_SKIP_POSTINSTALL) {
|
|
|
19
21
|
process.exit(0);
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
// Also skip if we're in a pnpm workspace (local development)
|
|
25
|
+
if (
|
|
26
|
+
process.env.PNPM_HOME ||
|
|
27
|
+
process.env.npm_config_user_agent?.includes("pnpm")
|
|
28
|
+
) {
|
|
29
|
+
console.log("⏭️ Skipping typeslayer binary download (in pnpm workspace).");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
const getBinaryInfo = () => {
|
|
23
34
|
const plat = platform();
|
|
24
35
|
const architecture = arch();
|
|
25
36
|
|
|
26
|
-
let platformDir, binaryName,
|
|
37
|
+
let platformDir, binaryName, npmPackage;
|
|
27
38
|
|
|
28
39
|
if (plat === "linux" && architecture === "x64") {
|
|
29
40
|
platformDir = "linux-x64";
|
|
30
41
|
binaryName = "typeslayer";
|
|
31
|
-
|
|
42
|
+
npmPackage = "@typeslayer/linux-x64";
|
|
32
43
|
} else if (plat === "darwin" && architecture === "x64") {
|
|
33
44
|
platformDir = "darwin-x64";
|
|
34
45
|
binaryName = "typeslayer";
|
|
35
|
-
|
|
46
|
+
npmPackage = "@typeslayer/darwin-x64";
|
|
36
47
|
} else if (plat === "darwin" && architecture === "arm64") {
|
|
37
48
|
platformDir = "darwin-arm64";
|
|
38
49
|
binaryName = "typeslayer";
|
|
39
|
-
|
|
50
|
+
npmPackage = "@typeslayer/darwin-arm64";
|
|
40
51
|
} else if (plat === "win32" && architecture === "x64") {
|
|
41
52
|
platformDir = "win32-x64";
|
|
42
53
|
binaryName = "typeslayer.exe";
|
|
43
|
-
|
|
54
|
+
npmPackage = "@typeslayer/win32-x64";
|
|
44
55
|
} else {
|
|
45
56
|
console.warn(`⚠️ Platform ${plat}-${architecture} is not supported`);
|
|
46
57
|
process.exit(0); // Don't fail the install, just skip
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
return { platformDir, binaryName,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const downloadBinary = (url, destPath) => {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
console.log(`📦 Downloading binary from ${url}...`);
|
|
55
|
-
|
|
56
|
-
get(url, (response) => {
|
|
57
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
58
|
-
// Follow redirect
|
|
59
|
-
return downloadBinary(response.headers.location, destPath).then(
|
|
60
|
-
resolve,
|
|
61
|
-
reject,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (response.statusCode !== 200) {
|
|
66
|
-
reject(
|
|
67
|
-
new Error(
|
|
68
|
-
`Failed to download: ${response.statusCode} ${response.statusMessage}`,
|
|
69
|
-
),
|
|
70
|
-
);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const fileStream = createWriteStream(destPath);
|
|
75
|
-
response.pipe(fileStream);
|
|
76
|
-
|
|
77
|
-
fileStream.on("finish", () => {
|
|
78
|
-
fileStream.close();
|
|
79
|
-
// Make executable on Unix-like systems
|
|
80
|
-
if (process.platform !== "win32") {
|
|
81
|
-
chmodSync(destPath, 0o755);
|
|
82
|
-
}
|
|
83
|
-
console.log("✅ Binary downloaded successfully");
|
|
84
|
-
resolve();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
fileStream.on("error", (err) => {
|
|
88
|
-
reject(err);
|
|
89
|
-
});
|
|
90
|
-
}).on("error", (err) => {
|
|
91
|
-
reject(err);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
60
|
+
return { platformDir, binaryName, npmPackage };
|
|
94
61
|
};
|
|
95
62
|
|
|
96
63
|
(async () => {
|
|
97
64
|
try {
|
|
98
|
-
const { platformDir, binaryName,
|
|
99
|
-
const binariesDir = join(__dirname, "..", "
|
|
65
|
+
const { platformDir, binaryName, npmPackage } = getBinaryInfo();
|
|
66
|
+
const binariesDir = join(__dirname, "..", "..", "builds", platformDir);
|
|
100
67
|
const binaryPath = join(binariesDir, binaryName);
|
|
101
68
|
|
|
102
69
|
// Skip if binary already exists
|
|
@@ -108,10 +75,63 @@ const downloadBinary = (url, destPath) => {
|
|
|
108
75
|
// Create directory if it doesn't exist
|
|
109
76
|
mkdirSync(binariesDir, { recursive: true });
|
|
110
77
|
|
|
111
|
-
//
|
|
112
|
-
|
|
78
|
+
// First, try to use the optionalDependency (esbuild pattern)
|
|
79
|
+
// This is the primary mechanism - npm installs the right platform package automatically
|
|
80
|
+
let binaryFound = false;
|
|
81
|
+
try {
|
|
82
|
+
const optionalPkgPath = require.resolve(`${npmPackage}/package.json`);
|
|
83
|
+
const optionalBinaryPath = join(dirname(optionalPkgPath), binaryName);
|
|
84
|
+
if (existsSync(optionalBinaryPath)) {
|
|
85
|
+
console.log(`📦 Using ${npmPackage} from optionalDependencies...`);
|
|
86
|
+
const fs = await import("node:fs/promises");
|
|
87
|
+
await fs.copyFile(optionalBinaryPath, binaryPath);
|
|
88
|
+
if (process.platform !== "win32") {
|
|
89
|
+
chmodSync(binaryPath, 0o755);
|
|
90
|
+
}
|
|
91
|
+
console.log("✅ Binary copied successfully");
|
|
92
|
+
binaryFound = true;
|
|
93
|
+
}
|
|
94
|
+
} catch {
|
|
95
|
+
// optionalDependency not available - fall back to downloading
|
|
96
|
+
console.warn(
|
|
97
|
+
`⚠️ ${npmPackage} not found in optionalDependencies (may have been installed with --no-optional flag)`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!binaryFound) {
|
|
102
|
+
// Fallback: Install the platform-specific binary package from npm
|
|
103
|
+
console.log(`📦 Downloading ${npmPackage}@${PACKAGE_VERSION}...`);
|
|
104
|
+
execSync(`npm install --no-save "${npmPackage}@${PACKAGE_VERSION}"`, {
|
|
105
|
+
stdio: "inherit",
|
|
106
|
+
});
|
|
113
107
|
|
|
114
|
-
|
|
108
|
+
// Copy the binary from node_modules to our builds directory
|
|
109
|
+
const nodeModulesBinaryPath = join(
|
|
110
|
+
__dirname,
|
|
111
|
+
"..",
|
|
112
|
+
"..",
|
|
113
|
+
"..",
|
|
114
|
+
"node_modules",
|
|
115
|
+
npmPackage.replace("@", "").replace("/", "-"),
|
|
116
|
+
binaryName,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (!existsSync(nodeModulesBinaryPath)) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`Binary not found at ${nodeModulesBinaryPath} after npm install`,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Copy and make executable
|
|
126
|
+
const fs = await import("node:fs/promises");
|
|
127
|
+
await fs.copyFile(nodeModulesBinaryPath, binaryPath);
|
|
128
|
+
|
|
129
|
+
if (process.platform !== "win32") {
|
|
130
|
+
chmodSync(binaryPath, 0o755);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
console.log("✅ Binary installed successfully");
|
|
134
|
+
}
|
|
115
135
|
} catch (error) {
|
|
116
136
|
console.error("❌ Failed to download binary:", error.message);
|
|
117
137
|
console.error(
|