stackpatch 1.1.8 → 1.1.9
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/stackpatch.ts +2 -6
- package/package.json +1 -1
- package/bin/stackpatch.js +0 -82
package/bin/stackpatch.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
|
|
3
|
-
// Direct execution is not recommended - use the wrapper instead
|
|
4
|
-
// This file works with both Bun and Node.js
|
|
5
|
-
// - Bun can execute TypeScript files directly
|
|
6
|
-
// - Node.js uses tsx (installed as dependency) to execute TypeScript
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
":" //; exec /usr/bin/env node -e "const {spawnSync} = require('child_process'); const result = spawnSync('npx', ['-y', 'tsx', process.argv[1], ...process.argv.slice(2)], {stdio: 'inherit'}); process.exit(result.status || 0);" "$0" "$@"
|
|
7
3
|
|
|
8
4
|
import fs from "fs";
|
|
9
5
|
import path from "path";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stackpatch",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Composable frontend features for modern React & Next.js apps - Add authentication, UI components, and more with zero configuration",
|
|
5
5
|
"main": "bin/stackpatch.ts",
|
|
6
6
|
"type": "module",
|
package/bin/stackpatch.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* StackPatch CLI Wrapper
|
|
4
|
-
*
|
|
5
|
-
* This wrapper detects the runtime (Bun or Node.js) and executes the TypeScript file accordingly.
|
|
6
|
-
* - If Bun is available, uses Bun directly (faster)
|
|
7
|
-
* - Otherwise, uses tsx via npx for Node.js compatibility
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { spawn, spawnSync } from "child_process";
|
|
11
|
-
import { fileURLToPath } from "url";
|
|
12
|
-
import { dirname, join } from "path";
|
|
13
|
-
import { existsSync } from "fs";
|
|
14
|
-
|
|
15
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
-
const __dirname = dirname(__filename);
|
|
17
|
-
const tsFile = join(__dirname, "stackpatch.ts");
|
|
18
|
-
|
|
19
|
-
// Verify the TypeScript file exists
|
|
20
|
-
if (!existsSync(tsFile)) {
|
|
21
|
-
console.error(`Error: TypeScript file not found: ${tsFile}`);
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Check if Bun is available
|
|
26
|
-
function hasBun() {
|
|
27
|
-
try {
|
|
28
|
-
const result = spawnSync("bun", ["--version"], {
|
|
29
|
-
stdio: "ignore",
|
|
30
|
-
timeout: 1000,
|
|
31
|
-
});
|
|
32
|
-
return result.status === 0;
|
|
33
|
-
} catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Execute with appropriate runtime
|
|
39
|
-
const args = process.argv.slice(2);
|
|
40
|
-
|
|
41
|
-
if (hasBun()) {
|
|
42
|
-
// Use Bun if available - Bun can execute TypeScript directly
|
|
43
|
-
const bun = spawn("bun", [tsFile, ...args], {
|
|
44
|
-
stdio: "inherit",
|
|
45
|
-
cwd: process.cwd(),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
bun.on("exit", (code) => {
|
|
49
|
-
process.exit(code || 0);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
bun.on("error", (err) => {
|
|
53
|
-
console.error("Error running Bun:", err.message);
|
|
54
|
-
// Fallback to npx tsx
|
|
55
|
-
console.log("Falling back to Node.js with tsx...");
|
|
56
|
-
runWithTsx();
|
|
57
|
-
});
|
|
58
|
-
} else {
|
|
59
|
-
// Use tsx for Node.js
|
|
60
|
-
runWithTsx();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function runWithTsx() {
|
|
64
|
-
// Always use npx -y tsx - it's the most reliable method
|
|
65
|
-
// npx will download tsx if needed, and it works in all scenarios
|
|
66
|
-
const tsx = spawn("npx", ["-y", "tsx", tsFile, ...args], {
|
|
67
|
-
stdio: "inherit",
|
|
68
|
-
cwd: process.cwd(),
|
|
69
|
-
shell: true, // Use shell for npx to handle PATH correctly
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
tsx.on("exit", (code) => {
|
|
73
|
-
process.exit(code || 0);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
tsx.on("error", (err) => {
|
|
77
|
-
console.error("Error: Could not execute TypeScript file.");
|
|
78
|
-
console.error("Please ensure Node.js and npm are properly installed.");
|
|
79
|
-
console.error("Original error:", err.message);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
});
|
|
82
|
-
}
|