@tsonic/tsbindgen 0.1.0 → 0.1.2
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 +57 -0
- package/index.js +35 -17
- package/package.json +3 -5
- package/scripts/postinstall.js +0 -80
package/bin.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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": "tsbindgen-darwin-arm64",
|
|
12
|
+
"darwin-x64": "tsbindgen-darwin-x64",
|
|
13
|
+
"linux-arm64": "tsbindgen-linux-arm64",
|
|
14
|
+
"linux-x64": "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
|
+
|
|
31
|
+
// Search paths for the platform-specific binary
|
|
32
|
+
const paths = [
|
|
33
|
+
// Nested in this package's node_modules
|
|
34
|
+
join(__dirname, "node_modules", "@tsonic", packageName, binaryName),
|
|
35
|
+
// Sibling in @tsonic scope (hoisted)
|
|
36
|
+
join(__dirname, "..", packageName, binaryName),
|
|
37
|
+
// At root node_modules level
|
|
38
|
+
join(__dirname, "..", "..", "@tsonic", packageName, binaryName),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
for (const p of paths) {
|
|
42
|
+
if (existsSync(p)) {
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.error(`Could not find tsbindgen binary for ${key}`);
|
|
48
|
+
console.error(`Package @tsonic/${packageName} may not be installed.`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const binaryPath = findBinary();
|
|
53
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
54
|
+
stdio: "inherit",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
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,51 @@ import { fileURLToPath } from "node:url";
|
|
|
11
9
|
|
|
12
10
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
11
|
|
|
12
|
+
const PLATFORMS = {
|
|
13
|
+
"darwin-arm64": "tsbindgen-darwin-arm64",
|
|
14
|
+
"darwin-x64": "tsbindgen-darwin-x64",
|
|
15
|
+
"linux-arm64": "tsbindgen-linux-arm64",
|
|
16
|
+
"linux-x64": "tsbindgen-linux-x64",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getPlatformKey = () => `${process.platform}-${process.arch}`;
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
|
-
* Get the path to the tsbindgen binary
|
|
22
|
+
* Get the path to the tsbindgen binary
|
|
16
23
|
*/
|
|
17
|
-
const getBinaryPath = () => {
|
|
18
|
-
const
|
|
24
|
+
export const getBinaryPath = () => {
|
|
25
|
+
const key = getPlatformKey();
|
|
26
|
+
const packageName = PLATFORMS[key];
|
|
19
27
|
|
|
20
|
-
if (!
|
|
28
|
+
if (!packageName) {
|
|
21
29
|
throw new Error(
|
|
22
|
-
|
|
23
|
-
"
|
|
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
|
-
|
|
35
|
+
const binaryName = "tsbindgen";
|
|
36
|
+
const paths = [
|
|
37
|
+
join(__dirname, "node_modules", "@tsonic", packageName, binaryName),
|
|
38
|
+
join(__dirname, "..", packageName, binaryName),
|
|
39
|
+
join(__dirname, "..", "..", "@tsonic", packageName, binaryName),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
for (const p of paths) {
|
|
43
|
+
if (existsSync(p)) {
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Could not find tsbindgen binary for ${key}. ` +
|
|
50
|
+
`Package @tsonic/${packageName} may not be installed.`
|
|
51
|
+
);
|
|
29
52
|
};
|
|
30
53
|
|
|
31
54
|
/**
|
|
32
55
|
* Run tsbindgen with the given arguments
|
|
33
|
-
* @param {string[]} args
|
|
56
|
+
* @param {string[]} args
|
|
34
57
|
* @returns {Promise<{ code: number; stdout: string; stderr: string }>}
|
|
35
58
|
*/
|
|
36
59
|
export const run = (args) => {
|
|
@@ -49,9 +72,7 @@ export const run = (args) => {
|
|
|
49
72
|
stderr += data.toString();
|
|
50
73
|
});
|
|
51
74
|
|
|
52
|
-
proc.on("error",
|
|
53
|
-
reject(err);
|
|
54
|
-
});
|
|
75
|
+
proc.on("error", reject);
|
|
55
76
|
|
|
56
77
|
proc.on("close", (code) => {
|
|
57
78
|
resolve({ code: code ?? 0, stdout, stderr });
|
|
@@ -61,7 +82,6 @@ export const run = (args) => {
|
|
|
61
82
|
|
|
62
83
|
/**
|
|
63
84
|
* Check if tsbindgen is available
|
|
64
|
-
* @returns {boolean}
|
|
65
85
|
*/
|
|
66
86
|
export const isAvailable = () => {
|
|
67
87
|
try {
|
|
@@ -71,5 +91,3 @@ export const isAvailable = () => {
|
|
|
71
91
|
return false;
|
|
72
92
|
}
|
|
73
93
|
};
|
|
74
|
-
|
|
75
|
-
export { getBinaryPath };
|
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsonic/tsbindgen",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Generate TypeScript declarations from .NET assemblies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"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
|
-
"
|
|
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": {
|
package/scripts/postinstall.js
DELETED
|
@@ -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();
|