mick-templates 1.1.5 → 1.1.6

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/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { spawn } from "child_process";
3
3
  import { dirname, join } from "path";
4
4
  import { fileURLToPath } from "url";
5
+ import { createRequire } from "module";
5
6
  import { getUserAgent } from "package-manager-detector";
6
7
 
7
8
  // Get the directory where this script is located
@@ -20,11 +21,18 @@ if (agent === "bun") {
20
21
  command = "bun";
21
22
  args = [cliPath, ...process.argv.slice(2)];
22
23
  } else {
23
- // Use the local tsx from the package's node_modules
24
- const isWin = process.platform === "win32";
25
- const tsxBin = join(projectRoot, "node_modules", ".bin", "tsx");
26
- command = isWin ? `${tsxBin}.cmd` : tsxBin;
27
- args = [cliPath, ...process.argv.slice(2)];
24
+ const require = createRequire(import.meta.url);
25
+ try {
26
+ // Try to resolve tsx from the package's dependencies
27
+ const tsxPath = require.resolve("tsx/cli");
28
+ command = process.execPath || "node";
29
+ args = [tsxPath, cliPath, ...process.argv.slice(2)];
30
+ } catch (_err) {
31
+ // Fallback to npx if tsx is not resolvable
32
+ const isWin = process.platform === "win32";
33
+ command = isWin ? "npx.cmd" : "npx";
34
+ args = ["tsx", cliPath, ...process.argv.slice(2)];
35
+ }
28
36
  }
29
37
 
30
38
  // Spawn the command
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mick-templates",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "CLI tool for creating projects from templates",
5
5
  "bin": {
6
6
  "mick-templates": "bin/cli.js"
package/src/lib/pm.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { getUserAgent, resolveCommand } from "package-manager-detector";
2
2
  import type { AgentName } from "package-manager-detector";
3
3
  import { spawn } from "child_process";
4
+ import { createRequire } from "module";
5
+ import { join, dirname } from "path";
6
+ import { readFile } from "fs/promises";
4
7
 
5
8
  /**
6
9
  * Get the current package manager agent.
@@ -42,6 +45,36 @@ export async function execute(
42
45
  args: string[]
43
46
  ): Promise<void> {
44
47
  const agent = getAgent();
48
+
49
+ if (agent === "bun") {
50
+ await run("bunx", [pkg, ...args], cwd);
51
+ return;
52
+ }
53
+
54
+ // Try to resolve the package binary from our own dependencies
55
+ try {
56
+ const require = createRequire(import.meta.url);
57
+ const pkgJsonPath = require.resolve(`${pkg}/package.json`);
58
+ const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf-8")) as Record<
59
+ string,
60
+ any
61
+ >;
62
+
63
+ let binPath: string | undefined;
64
+ if (typeof pkgJson.bin === "string") {
65
+ binPath = join(dirname(pkgJsonPath), pkgJson.bin);
66
+ } else if (pkgJson.bin && pkgJson.bin[pkg]) {
67
+ binPath = join(dirname(pkgJsonPath), pkgJson.bin[pkg]);
68
+ }
69
+
70
+ if (binPath) {
71
+ await run("node", [binPath, ...args], cwd);
72
+ return;
73
+ }
74
+ } catch (_err) {
75
+ // Fallback to global execute
76
+ }
77
+
45
78
  const resolved = resolveCommand(agent, "execute", [pkg, ...args]);
46
79
  if (!resolved) throw new Error(`Cannot resolve execute command for ${agent}`);
47
80