typeslayer 0.1.4 → 0.1.6

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/typeslayer.js CHANGED
@@ -22,9 +22,6 @@ const getBinaryInfo = () => {
22
22
  if (plat === "linux" && architecture === "x64") {
23
23
  platformDir = "linux-x64";
24
24
  binaryName = "typeslayer";
25
- } else if (plat === "darwin" && architecture === "x64") {
26
- platformDir = "darwin-x64";
27
- binaryName = "typeslayer";
28
25
  } else if (plat === "darwin" && architecture === "arm64") {
29
26
  platformDir = "darwin-arm64";
30
27
  binaryName = "typeslayer";
package/package.json CHANGED
@@ -1,53 +1,55 @@
1
1
  {
2
- "name": "typeslayer",
3
- "version": "0.1.4",
4
- "description": "Slay your TypeScript types",
5
- "private": false,
6
- "type": "module",
7
- "keywords": [
8
- "typescript",
9
- "ts",
10
- "tauri",
11
- "desktop",
12
- "benchmarking",
13
- "performance"
14
- ],
15
- "author": "Dimitri Mitropoulos",
16
- "license": "MIT",
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/dimitropoulos/typeslayer.git"
20
- },
21
- "bugs": {
22
- "url": "https://github.com/dimitropoulos/typeslayer/issues"
23
- },
24
- "homepage": "https://github.com/dimitropoulos/typeslayer#readme",
25
- "bin": {
26
- "typeslayer": "bin/typeslayer.js"
27
- },
28
- "files": [
29
- "bin",
30
- "scripts"
31
- ],
32
- "os": [
33
- "linux",
34
- "darwin",
35
- "win32"
36
- ],
37
- "cpu": [
38
- "x64",
39
- "arm64"
40
- ],
41
- "engines": {
42
- "node": ">=24.0.0",
43
- "pnpm": ">=10.0.0"
44
- },
45
- "packageManager": "pnpm@10.6.5",
46
- "scripts": {
47
- "postinstall": "node scripts/postinstall.js",
48
- "dev": "vite",
49
- "build": "tsc && vite build",
50
- "preview": "vite preview",
51
- "tauri": "tauri"
52
- }
2
+ "name": "typeslayer",
3
+ "version": "0.1.6",
4
+ "description": "Slay your TypeScript types",
5
+ "private": false,
6
+ "type": "module",
7
+ "keywords": [
8
+ "typescript",
9
+ "ts",
10
+ "tauri",
11
+ "desktop",
12
+ "benchmarking",
13
+ "performance"
14
+ ],
15
+ "author": "Dimitri Mitropoulos",
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/dimitropoulos/typeslayer.git",
20
+ "directory": "packages/typeslayer"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/dimitropoulos/typeslayer/issues"
24
+ },
25
+ "homepage": "https://github.com/dimitropoulos/typeslayer#readme",
26
+ "bin": {
27
+ "typeslayer": "bin/typeslayer.js"
28
+ },
29
+ "files": [
30
+ "bin",
31
+ "scripts"
32
+ ],
33
+ "os": [
34
+ "linux",
35
+ "darwin",
36
+ "win32"
37
+ ],
38
+ "cpu": [
39
+ "x64",
40
+ "arm64"
41
+ ],
42
+ "engines": {
43
+ "node": ">=24.0.0",
44
+ "pnpm": ">=10.0.0"
45
+ },
46
+ "packageManager": "pnpm@10.6.5",
47
+ "scripts": {
48
+ "postinstall": "node scripts/postinstall.js"
49
+ },
50
+ "optionalDependencies": {
51
+ "@typeslayer/linux-x64": "0.1.6",
52
+ "@typeslayer/darwin-arm64": "0.1.6",
53
+ "@typeslayer/win32-x64": "0.1.6"
54
+ }
53
55
  }
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { chmodSync, createWriteStream, existsSync, mkdirSync } from "node:fs";
4
- import { get } from "node:https";
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
 
@@ -23,80 +25,32 @@ const getBinaryInfo = () => {
23
25
  const plat = platform();
24
26
  const architecture = arch();
25
27
 
26
- let platformDir, binaryName, releaseAssetName;
28
+ let platformDir, binaryName, npmPackage;
27
29
 
28
30
  if (plat === "linux" && architecture === "x64") {
29
31
  platformDir = "linux-x64";
30
32
  binaryName = "typeslayer";
31
- releaseAssetName = "typeslayer-linux-x64";
32
- } else if (plat === "darwin" && architecture === "x64") {
33
- platformDir = "darwin-x64";
34
- binaryName = "typeslayer";
35
- releaseAssetName = "typeslayer-darwin-x64";
33
+ npmPackage = "@typeslayer/linux-x64";
36
34
  } else if (plat === "darwin" && architecture === "arm64") {
37
35
  platformDir = "darwin-arm64";
38
36
  binaryName = "typeslayer";
39
- releaseAssetName = "typeslayer-darwin-arm64";
37
+ npmPackage = "@typeslayer/darwin-arm64";
40
38
  } else if (plat === "win32" && architecture === "x64") {
41
39
  platformDir = "win32-x64";
42
40
  binaryName = "typeslayer.exe";
43
- releaseAssetName = "typeslayer-win32-x64.exe";
41
+ npmPackage = "@typeslayer/win32-x64";
44
42
  } else {
45
43
  console.warn(`⚠️ Platform ${plat}-${architecture} is not supported`);
46
44
  process.exit(0); // Don't fail the install, just skip
47
45
  }
48
46
 
49
- return { platformDir, binaryName, releaseAssetName };
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
- });
47
+ return { platformDir, binaryName, npmPackage };
94
48
  };
95
49
 
96
50
  (async () => {
97
51
  try {
98
- const { platformDir, binaryName, releaseAssetName } = getBinaryInfo();
99
- const binariesDir = join(__dirname, "..", "binaries", platformDir);
52
+ const { platformDir, binaryName, npmPackage } = getBinaryInfo();
53
+ const binariesDir = join(__dirname, "..", "..", "builds", platformDir);
100
54
  const binaryPath = join(binariesDir, binaryName);
101
55
 
102
56
  // Skip if binary already exists
@@ -108,10 +62,63 @@ const downloadBinary = (url, destPath) => {
108
62
  // Create directory if it doesn't exist
109
63
  mkdirSync(binariesDir, { recursive: true });
110
64
 
111
- // Download from GitHub release
112
- const releaseUrl = `https://github.com/dimitropoulos/typeslayer/releases/download/typeslayer-v${PACKAGE_VERSION}/${releaseAssetName}`;
65
+ // First, try to use the optionalDependency (esbuild pattern)
66
+ // This is the primary mechanism - npm installs the right platform package automatically
67
+ let binaryFound = false;
68
+ try {
69
+ const optionalPkgPath = require.resolve(`${npmPackage}/package.json`);
70
+ const optionalBinaryPath = join(dirname(optionalPkgPath), binaryName);
71
+ if (existsSync(optionalBinaryPath)) {
72
+ console.log(`📦 Using ${npmPackage} from optionalDependencies...`);
73
+ const fs = await import("node:fs/promises");
74
+ await fs.copyFile(optionalBinaryPath, binaryPath);
75
+ if (process.platform !== "win32") {
76
+ chmodSync(binaryPath, 0o755);
77
+ }
78
+ console.log("✅ Binary copied successfully");
79
+ binaryFound = true;
80
+ }
81
+ } catch {
82
+ // optionalDependency not available - fall back to downloading
83
+ console.warn(
84
+ `⚠️ ${npmPackage} not found in optionalDependencies (may have been installed with --no-optional flag)`,
85
+ );
86
+ }
87
+
88
+ if (!binaryFound) {
89
+ // Fallback: Install the platform-specific binary package from npm
90
+ console.log(`📦 Downloading ${npmPackage}@${PACKAGE_VERSION}...`);
91
+ execSync(`npm install --no-save "${npmPackage}@${PACKAGE_VERSION}"`, {
92
+ stdio: "inherit",
93
+ });
94
+
95
+ // Copy the binary from node_modules to our builds directory
96
+ const nodeModulesBinaryPath = join(
97
+ __dirname,
98
+ "..",
99
+ "..",
100
+ "..",
101
+ "node_modules",
102
+ npmPackage.replace("@", "").replace("/", "-"),
103
+ binaryName,
104
+ );
105
+
106
+ if (!existsSync(nodeModulesBinaryPath)) {
107
+ throw new Error(
108
+ `Binary not found at ${nodeModulesBinaryPath} after npm install`,
109
+ );
110
+ }
111
+
112
+ // Copy and make executable
113
+ const fs = await import("node:fs/promises");
114
+ await fs.copyFile(nodeModulesBinaryPath, binaryPath);
113
115
 
114
- await downloadBinary(releaseUrl, binaryPath);
116
+ if (process.platform !== "win32") {
117
+ chmodSync(binaryPath, 0o755);
118
+ }
119
+
120
+ console.log("✅ Binary installed successfully");
121
+ }
115
122
  } catch (error) {
116
123
  console.error("❌ Failed to download binary:", error.message);
117
124
  console.error(