stackpatch 1.1.6 → 1.1.7
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/README.md +3 -5
- package/bin/stackpatch.js +95 -31
- package/bin/stackpatch.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,17 +78,15 @@ npx stackpatch create my-app
|
|
|
78
78
|
# Or without project name (will prompt)
|
|
79
79
|
npx stackpatch create
|
|
80
80
|
|
|
81
|
-
# Using
|
|
82
|
-
npm create stackpatch@latest my-app
|
|
83
|
-
|
|
84
|
-
# Using bunx (Bun's npx equivalent)
|
|
81
|
+
# Using bunx (Bun's npx equivalent - if you have Bun installed)
|
|
85
82
|
bunx create-stackpatch@latest my-app
|
|
86
83
|
```
|
|
87
84
|
|
|
88
85
|
> **Note:**
|
|
89
86
|
> - `npx stackpatch create` works immediately and doesn't require the package to be published
|
|
90
|
-
> - `npm create
|
|
87
|
+
> - `npm create stackpatch@latest` will work after the package is published to npm
|
|
91
88
|
> - All commands will prompt you for a project name if not provided
|
|
89
|
+
> - The CLI automatically detects and uses Bun if available, otherwise falls back to Node.js with tsx
|
|
92
90
|
|
|
93
91
|
### Revert an Installation
|
|
94
92
|
|
package/bin/stackpatch.js
CHANGED
|
@@ -11,6 +11,7 @@ import { spawn, spawnSync } from "child_process";
|
|
|
11
11
|
import { fileURLToPath } from "url";
|
|
12
12
|
import { dirname, join } from "path";
|
|
13
13
|
import { existsSync } from "fs";
|
|
14
|
+
import { createRequire } from "module";
|
|
14
15
|
|
|
15
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
17
|
const __dirname = dirname(__filename);
|
|
@@ -29,6 +30,57 @@ function hasBun() {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
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
|
+
|
|
32
84
|
// Execute with appropriate runtime
|
|
33
85
|
const args = process.argv.slice(2);
|
|
34
86
|
|
|
@@ -39,41 +91,53 @@ if (hasBun()) {
|
|
|
39
91
|
cwd: process.cwd(),
|
|
40
92
|
});
|
|
41
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
|
+
});
|
|
42
98
|
} else {
|
|
43
99
|
// Use tsx for Node.js
|
|
44
|
-
// Try
|
|
45
|
-
const
|
|
46
|
-
join(__dirname, "../node_modules/.bin/tsx"), // Local installation
|
|
47
|
-
join(__dirname, "../../node_modules/.bin/tsx"), // Monorepo structure
|
|
48
|
-
join(process.cwd(), "node_modules/.bin/tsx"), // Project's node_modules
|
|
49
|
-
];
|
|
100
|
+
// Try to find tsx locally first, then fall back to npx
|
|
101
|
+
const tsxCommand = findTsx();
|
|
50
102
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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);
|
|
56
114
|
}
|
|
57
|
-
|
|
115
|
+
process.exit(0);
|
|
116
|
+
});
|
|
58
117
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.error("Error: Could not execute TypeScript file.
|
|
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");
|
|
74
134
|
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
});
|
|
79
143
|
}
|
package/bin/stackpatch.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// This file should be executed via bin/stackpatch.js wrapper
|
|
3
|
+
// Direct execution is not recommended - use the wrapper instead
|
|
2
4
|
// This file works with both Bun and Node.js
|
|
3
5
|
// - Bun can execute TypeScript files directly
|
|
4
6
|
// - Node.js uses tsx (installed as dependency) to execute TypeScript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stackpatch",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
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",
|