stackpatch 1.1.7 → 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 +3 -3
- package/bin/stackpatch.js +0 -143
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,12 +1,12 @@
|
|
|
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",
|
|
7
7
|
"bin": {
|
|
8
|
-
"stackpatch": "bin/stackpatch.
|
|
9
|
-
"create-stackpatch": "bin/stackpatch.
|
|
8
|
+
"stackpatch": "bin/stackpatch.ts",
|
|
9
|
+
"create-stackpatch": "bin/stackpatch.ts"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"bin",
|
package/bin/stackpatch.js
DELETED
|
@@ -1,143 +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 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
|
-
import { createRequire } from "module";
|
|
15
|
-
|
|
16
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
-
const __dirname = dirname(__filename);
|
|
18
|
-
const tsFile = join(__dirname, "stackpatch.ts");
|
|
19
|
-
|
|
20
|
-
// Check if Bun is available
|
|
21
|
-
function hasBun() {
|
|
22
|
-
try {
|
|
23
|
-
const result = spawnSync("bun", ["--version"], {
|
|
24
|
-
stdio: "ignore",
|
|
25
|
-
timeout: 1000,
|
|
26
|
-
});
|
|
27
|
-
return result.status === 0;
|
|
28
|
-
} catch {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Find tsx executable
|
|
34
|
-
function findTsx() {
|
|
35
|
-
// First, try to resolve tsx from the package's node_modules using require.resolve
|
|
36
|
-
// This works when the package is installed locally or via npx
|
|
37
|
-
try {
|
|
38
|
-
const require = createRequire(import.meta.url);
|
|
39
|
-
|
|
40
|
-
// Try to resolve tsx/cli.mjs directly
|
|
41
|
-
try {
|
|
42
|
-
const tsxBinPath = require.resolve("tsx/cli.mjs");
|
|
43
|
-
if (existsSync(tsxBinPath)) {
|
|
44
|
-
return ["node", tsxBinPath];
|
|
45
|
-
}
|
|
46
|
-
} catch {
|
|
47
|
-
// tsx/cli.mjs not found
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Try to find tsx package and locate cli.mjs
|
|
51
|
-
try {
|
|
52
|
-
const tsxPackagePath = require.resolve("tsx/package.json");
|
|
53
|
-
const tsxDir = dirname(tsxPackagePath);
|
|
54
|
-
const tsxBin = join(tsxDir, "cli.mjs");
|
|
55
|
-
|
|
56
|
-
if (existsSync(tsxBin)) {
|
|
57
|
-
return ["node", tsxBin];
|
|
58
|
-
}
|
|
59
|
-
} catch {
|
|
60
|
-
// tsx package not found
|
|
61
|
-
}
|
|
62
|
-
} catch {
|
|
63
|
-
// require.resolve failed - package might not be installed yet
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Try node_modules/.bin/tsx in various locations
|
|
67
|
-
const possibleTsxPaths = [
|
|
68
|
-
join(__dirname, "../node_modules/.bin/tsx"),
|
|
69
|
-
join(__dirname, "../../node_modules/.bin/tsx"),
|
|
70
|
-
join(process.cwd(), "node_modules/.bin/tsx"),
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
for (const tsxPath of possibleTsxPaths) {
|
|
74
|
-
if (existsSync(tsxPath)) {
|
|
75
|
-
return [tsxPath];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Final fallback: use npx to download and run tsx
|
|
80
|
-
// This is the most reliable method when package is downloaded via npx
|
|
81
|
-
return ["npx", "-y", "tsx"];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Execute with appropriate runtime
|
|
85
|
-
const args = process.argv.slice(2);
|
|
86
|
-
|
|
87
|
-
if (hasBun()) {
|
|
88
|
-
// Use Bun if available
|
|
89
|
-
const bun = spawn("bun", [tsFile, ...args], {
|
|
90
|
-
stdio: "inherit",
|
|
91
|
-
cwd: process.cwd(),
|
|
92
|
-
});
|
|
93
|
-
bun.on("exit", (code) => process.exit(code || 0));
|
|
94
|
-
bun.on("error", (err) => {
|
|
95
|
-
console.error("Error running Bun:", err.message);
|
|
96
|
-
process.exit(1);
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
// Use tsx for Node.js
|
|
100
|
-
// Try to find tsx locally first, then fall back to npx
|
|
101
|
-
const tsxCommand = findTsx();
|
|
102
|
-
|
|
103
|
-
// If we're using npx, it will handle downloading tsx if needed
|
|
104
|
-
// This is the most reliable method when package is downloaded via npx
|
|
105
|
-
const tsx = spawn(tsxCommand[0], [...tsxCommand.slice(1), tsFile, ...args], {
|
|
106
|
-
stdio: "inherit",
|
|
107
|
-
cwd: process.cwd(),
|
|
108
|
-
shell: tsxCommand[0] === "npx", // Use shell for npx to handle PATH correctly
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
tsx.on("exit", (code) => {
|
|
112
|
-
if (code !== 0 && code !== null) {
|
|
113
|
-
process.exit(code);
|
|
114
|
-
}
|
|
115
|
-
process.exit(0);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
tsx.on("error", (err) => {
|
|
119
|
-
// If npx fails, try one more time with explicit node
|
|
120
|
-
if (tsxCommand[0] !== "npx") {
|
|
121
|
-
console.error("Error: Could not execute TypeScript file.");
|
|
122
|
-
console.error("Trying with npx...");
|
|
123
|
-
|
|
124
|
-
const npxTsx = spawn("npx", ["-y", "tsx", tsFile, ...args], {
|
|
125
|
-
stdio: "inherit",
|
|
126
|
-
cwd: process.cwd(),
|
|
127
|
-
shell: true,
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
npxTsx.on("exit", (code) => process.exit(code || 0));
|
|
131
|
-
npxTsx.on("error", () => {
|
|
132
|
-
console.error("Error: Could not execute TypeScript file.");
|
|
133
|
-
console.error("Please ensure tsx is available: npm install -g tsx");
|
|
134
|
-
process.exit(1);
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
console.error("Error: Could not execute TypeScript file.");
|
|
138
|
-
console.error("Please ensure tsx is available: npm install -g tsx");
|
|
139
|
-
console.error("Original error:", err.message);
|
|
140
|
-
process.exit(1);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|