@tsonic/tsbindgen 0.1.0 → 0.1.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.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from "node:child_process";
4
+ import { existsSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+
10
+ const PLATFORMS = {
11
+ "darwin-arm64": "@tsonic/tsbindgen-darwin-arm64",
12
+ "darwin-x64": "@tsonic/tsbindgen-darwin-x64",
13
+ "linux-arm64": "@tsonic/tsbindgen-linux-arm64",
14
+ "linux-x64": "@tsonic/tsbindgen-linux-x64",
15
+ };
16
+
17
+ const getPlatformKey = () => `${process.platform}-${process.arch}`;
18
+
19
+ const findBinary = () => {
20
+ const key = getPlatformKey();
21
+ const packageName = PLATFORMS[key];
22
+
23
+ if (!packageName) {
24
+ console.error(`Unsupported platform: ${key}`);
25
+ console.error("tsbindgen supports: darwin-arm64, darwin-x64, linux-arm64, linux-x64");
26
+ process.exit(1);
27
+ }
28
+
29
+ const binaryName = "tsbindgen";
30
+ const paths = [
31
+ join(__dirname, "node_modules", packageName, binaryName),
32
+ join(__dirname, "..", packageName, binaryName),
33
+ ];
34
+
35
+ for (const p of paths) {
36
+ if (existsSync(p)) {
37
+ return p;
38
+ }
39
+ }
40
+
41
+ console.error(`Could not find tsbindgen binary for ${key}`);
42
+ console.error(`Package ${packageName} may not be installed.`);
43
+ process.exit(1);
44
+ };
45
+
46
+ const binaryPath = findBinary();
47
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
48
+ stdio: "inherit",
49
+ });
50
+
51
+ process.exit(result.status ?? 1);
package/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  /**
2
2
  * @tsonic/tsbindgen - Programmatic API
3
- *
4
- * Provides a way to invoke tsbindgen from JavaScript code.
5
3
  */
6
4
 
7
5
  import { spawn } from "node:child_process";
@@ -11,26 +9,50 @@ import { fileURLToPath } from "node:url";
11
9
 
12
10
  const __dirname = dirname(fileURLToPath(import.meta.url));
13
11
 
12
+ const PLATFORMS = {
13
+ "darwin-arm64": "@tsonic/tsbindgen-darwin-arm64",
14
+ "darwin-x64": "@tsonic/tsbindgen-darwin-x64",
15
+ "linux-arm64": "@tsonic/tsbindgen-linux-arm64",
16
+ "linux-x64": "@tsonic/tsbindgen-linux-x64",
17
+ };
18
+
19
+ const getPlatformKey = () => `${process.platform}-${process.arch}`;
20
+
14
21
  /**
15
- * Get the path to the tsbindgen binary (symlinked by postinstall)
22
+ * Get the path to the tsbindgen binary
16
23
  */
17
- const getBinaryPath = () => {
18
- const binaryPath = join(__dirname, "tsbindgen");
24
+ export const getBinaryPath = () => {
25
+ const key = getPlatformKey();
26
+ const packageName = PLATFORMS[key];
19
27
 
20
- if (!existsSync(binaryPath)) {
28
+ if (!packageName) {
21
29
  throw new Error(
22
- "tsbindgen binary not found. " +
23
- "This may mean the package was not installed correctly or " +
24
- "your platform is not supported (darwin-arm64, darwin-x64, linux-arm64, linux-x64)."
30
+ `Unsupported platform: ${key}. ` +
31
+ "tsbindgen supports: darwin-arm64, darwin-x64, linux-arm64, linux-x64"
25
32
  );
26
33
  }
27
34
 
28
- return binaryPath;
35
+ const binaryName = "tsbindgen";
36
+ const paths = [
37
+ join(__dirname, "node_modules", packageName, binaryName),
38
+ join(__dirname, "..", packageName, binaryName),
39
+ ];
40
+
41
+ for (const p of paths) {
42
+ if (existsSync(p)) {
43
+ return p;
44
+ }
45
+ }
46
+
47
+ throw new Error(
48
+ `Could not find tsbindgen binary for ${key}. ` +
49
+ `Package ${packageName} may not be installed.`
50
+ );
29
51
  };
30
52
 
31
53
  /**
32
54
  * Run tsbindgen with the given arguments
33
- * @param {string[]} args - Command line arguments
55
+ * @param {string[]} args
34
56
  * @returns {Promise<{ code: number; stdout: string; stderr: string }>}
35
57
  */
36
58
  export const run = (args) => {
@@ -49,9 +71,7 @@ export const run = (args) => {
49
71
  stderr += data.toString();
50
72
  });
51
73
 
52
- proc.on("error", (err) => {
53
- reject(err);
54
- });
74
+ proc.on("error", reject);
55
75
 
56
76
  proc.on("close", (code) => {
57
77
  resolve({ code: code ?? 0, stdout, stderr });
@@ -61,7 +81,6 @@ export const run = (args) => {
61
81
 
62
82
  /**
63
83
  * Check if tsbindgen is available
64
- * @returns {boolean}
65
84
  */
66
85
  export const isAvailable = () => {
67
86
  try {
@@ -71,5 +90,3 @@ export const isAvailable = () => {
71
90
  return false;
72
91
  }
73
92
  };
74
-
75
- export { getBinaryPath };
package/package.json CHANGED
@@ -1,23 +1,21 @@
1
1
  {
2
2
  "name": "@tsonic/tsbindgen",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Generate TypeScript declarations from .NET assemblies",
5
5
  "type": "module",
6
6
  "bin": {
7
- "tsbindgen": "./tsbindgen"
7
+ "tsbindgen": "./bin.js"
8
8
  },
9
9
  "main": "./index.js",
10
10
  "exports": {
11
11
  ".": "./index.js"
12
12
  },
13
13
  "files": [
14
- "tsbindgen",
14
+ "bin.js",
15
15
  "index.js",
16
- "scripts/postinstall.js",
17
16
  "README.md"
18
17
  ],
19
18
  "scripts": {
20
- "postinstall": "node scripts/postinstall.js",
21
19
  "build": "./scripts/build-native.sh"
22
20
  },
23
21
  "optionalDependencies": {
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Postinstall script for @tsonic/tsbindgen
5
- * Links the correct platform-specific binary after npm install
6
- */
7
-
8
- import { existsSync, symlinkSync, unlinkSync, chmodSync } from "node:fs";
9
- import { dirname, join } from "node:path";
10
- import { fileURLToPath } from "node:url";
11
-
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
- const ROOT = join(__dirname, "..");
14
-
15
- const PLATFORMS = {
16
- "darwin-arm64": "@tsonic/tsbindgen-darwin-arm64",
17
- "darwin-x64": "@tsonic/tsbindgen-darwin-x64",
18
- "linux-arm64": "@tsonic/tsbindgen-linux-arm64",
19
- "linux-x64": "@tsonic/tsbindgen-linux-x64",
20
- };
21
-
22
- const getPlatformKey = () => `${process.platform}-${process.arch}`;
23
-
24
- const findBinary = () => {
25
- const key = getPlatformKey();
26
- const packageName = PLATFORMS[key];
27
- const platformDir = key; // e.g., "linux-x64"
28
-
29
- if (!packageName) {
30
- console.error(`Unsupported platform: ${key}`);
31
- console.error("tsbindgen supports: darwin-arm64, darwin-x64, linux-arm64, linux-x64");
32
- process.exit(1);
33
- }
34
-
35
- const binaryName = "tsbindgen";
36
-
37
- // Search paths where the platform package might be installed
38
- const searchPaths = [
39
- // Development: local npm/ directory
40
- join(ROOT, "npm", platformDir, binaryName),
41
- // Installed as dependency
42
- join(ROOT, "node_modules", packageName, binaryName),
43
- // Hoisted installations
44
- join(ROOT, "..", packageName, binaryName),
45
- join(ROOT, "..", "..", packageName, binaryName),
46
- ];
47
-
48
- for (const p of searchPaths) {
49
- if (existsSync(p)) {
50
- return p;
51
- }
52
- }
53
-
54
- // Not found - this is OK during development or if optional dep failed
55
- console.warn(`Warning: Could not find ${packageName} binary`);
56
- console.warn("tsbindgen will not be available on this platform");
57
- return null;
58
- };
59
-
60
- const main = () => {
61
- const binaryPath = findBinary();
62
- if (!binaryPath) {
63
- return;
64
- }
65
-
66
- const linkPath = join(ROOT, "tsbindgen");
67
-
68
- // Remove existing link if present
69
- if (existsSync(linkPath)) {
70
- unlinkSync(linkPath);
71
- }
72
-
73
- // Create symlink to platform binary
74
- symlinkSync(binaryPath, linkPath);
75
- chmodSync(linkPath, 0o755);
76
-
77
- console.log(`Linked tsbindgen -> ${binaryPath}`);
78
- };
79
-
80
- main();