stackpatch 1.1.5 → 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 +10 -8
- package/bin/stackpatch.js +143 -0
- package/bin/stackpatch.ts +9 -4
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -72,19 +72,21 @@ The CLI will guide you through an interactive setup:
|
|
|
72
72
|
### Create New Project
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
|
-
# Using
|
|
76
|
-
npm create stackpatch@latest my-app
|
|
77
|
-
|
|
78
|
-
# Using npx
|
|
79
|
-
npx create-stackpatch@latest my-app
|
|
80
|
-
# or
|
|
75
|
+
# Using npx (recommended - works immediately)
|
|
81
76
|
npx stackpatch create my-app
|
|
82
77
|
|
|
83
|
-
#
|
|
78
|
+
# Or without project name (will prompt)
|
|
79
|
+
npx stackpatch create
|
|
80
|
+
|
|
81
|
+
# Using bunx (Bun's npx equivalent - if you have Bun installed)
|
|
84
82
|
bunx create-stackpatch@latest my-app
|
|
85
83
|
```
|
|
86
84
|
|
|
87
|
-
> **Note:**
|
|
85
|
+
> **Note:**
|
|
86
|
+
> - `npx stackpatch create` works immediately and doesn't require the package to be published
|
|
87
|
+
> - `npm create stackpatch@latest` will work after the package is published to npm
|
|
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
|
|
88
90
|
|
|
89
91
|
### Revert an Installation
|
|
90
92
|
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
}
|
package/bin/stackpatch.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
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
|
|
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
|
|
2
7
|
|
|
3
8
|
import fs from "fs";
|
|
4
9
|
import path from "path";
|
|
@@ -9,9 +14,9 @@ import { spawnSync } from "child_process";
|
|
|
9
14
|
import Jimp from "jimp";
|
|
10
15
|
|
|
11
16
|
// ---------------- CONFIG ----------------
|
|
12
|
-
// Get directory path - Bun
|
|
13
|
-
//
|
|
14
|
-
const CLI_DIR = import.meta.dir || path.dirname(new URL(import.meta.url).pathname);
|
|
17
|
+
// Get directory path - Works with both Bun and Node.js
|
|
18
|
+
// Bun has import.meta.dir, Node.js doesn't - use fallback
|
|
19
|
+
const CLI_DIR = (import.meta as any).dir || path.dirname(new URL(import.meta.url).pathname);
|
|
15
20
|
// Resolve boilerplate path - use local boilerplate inside CLI package
|
|
16
21
|
const BOILERPLATE_ROOT = path.resolve(CLI_DIR, "../boilerplate");
|
|
17
22
|
const PATCHES: Record<
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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",
|
|
7
7
|
"bin": {
|
|
8
|
-
"stackpatch": "bin/stackpatch.
|
|
9
|
-
"create-stackpatch": "bin/stackpatch.
|
|
8
|
+
"stackpatch": "bin/stackpatch.js",
|
|
9
|
+
"create-stackpatch": "bin/stackpatch.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"bin",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/Darshh09/StackPatch#readme",
|
|
49
49
|
"engines": {
|
|
50
|
+
"node": ">=18.0.0",
|
|
50
51
|
"bun": ">=1.0.0"
|
|
51
52
|
},
|
|
52
53
|
"packageManager": "pnpm@10.28.0",
|