stackpatch 1.1.8 → 1.2.0
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 +49 -0
- package/bin/stackpatch.ts +1 -6
- package/package.json +5 -3
- package/bin/stackpatch.js +0 -82
package/bin/stackpatch
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
// Get the directory of this script (CommonJS)
|
|
7
|
+
// In CommonJS, __filename is available, but if not, use require.main
|
|
8
|
+
const scriptPath = typeof __filename !== 'undefined' ? __filename : (require.main && require.main.filename) || process.argv[1];
|
|
9
|
+
const __dirname = path.dirname(scriptPath);
|
|
10
|
+
|
|
11
|
+
// Path to the TypeScript file
|
|
12
|
+
const tsFile = path.join(__dirname, 'stackpatch.ts');
|
|
13
|
+
const args = process.argv.slice(2);
|
|
14
|
+
|
|
15
|
+
// Try to find tsx in node_modules
|
|
16
|
+
const tsxPaths = [
|
|
17
|
+
path.join(__dirname, '../node_modules/.bin/tsx'),
|
|
18
|
+
path.join(__dirname, '../../node_modules/.bin/tsx'),
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
let tsxCommand = null;
|
|
22
|
+
for (const tsxPath of tsxPaths) {
|
|
23
|
+
try {
|
|
24
|
+
if (fs.existsSync(tsxPath)) {
|
|
25
|
+
tsxCommand = tsxPath;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
// Continue
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Execute with tsx or npx
|
|
34
|
+
if (tsxCommand) {
|
|
35
|
+
const result = spawnSync(tsxCommand, [tsFile, ...args], {
|
|
36
|
+
stdio: 'inherit',
|
|
37
|
+
shell: true,
|
|
38
|
+
env: process.env,
|
|
39
|
+
});
|
|
40
|
+
process.exit(result.status || 0);
|
|
41
|
+
} else {
|
|
42
|
+
// Use npx as fallback
|
|
43
|
+
const result = spawnSync('npx', ['-y', 'tsx', tsFile, ...args], {
|
|
44
|
+
stdio: 'inherit',
|
|
45
|
+
shell: true,
|
|
46
|
+
env: process.env,
|
|
47
|
+
});
|
|
48
|
+
process.exit(result.status || 0);
|
|
49
|
+
}
|
package/bin/stackpatch.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
// This file is executed via bin/stackpatch wrapper
|
|
7
2
|
|
|
8
3
|
import fs from "fs";
|
|
9
4
|
import path from "path";
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stackpatch",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
9
|
+
"create-stackpatch": "bin/stackpatch"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"bin",
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"test": "vitest run",
|
|
18
18
|
"test:watch": "vitest",
|
|
19
19
|
"test:coverage": "vitest run --coverage",
|
|
20
|
+
"test:cli": "node scripts/test-cli-execution.js",
|
|
21
|
+
"prepublishOnly": "node scripts/prepare-publish.js && npm run test:cli",
|
|
20
22
|
"dev": "bun run bin/stackpatch.ts",
|
|
21
23
|
"create": "bun run bin/stackpatch.ts"
|
|
22
24
|
},
|
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
|
-
}
|