create-puzzmo 1.0.10 → 1.0.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +22 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-puzzmo",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Create a Puzzmo game project",
5
5
  "type": "module",
6
6
  "bin": "./src/index.js",
package/src/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawnSync } from "node:child_process"
4
-
4
+ import { get } from "node:https"
5
5
  // Forward all args to `puzzmo game create`
6
6
  const args = process.argv.slice(2)
7
7
 
8
8
  // Detect the package manager that invoked this script
9
9
  const pm = detectPackageManager()
10
10
 
11
- // Always ensure the latest puzzmo CLI is installed
12
- console.log("Installing @puzzmo/cli@latest...")
13
- spawnSync("npm", ["install", "-g", "@puzzmo/cli@latest"], { stdio: "inherit" })
11
+ // Fetch the actual latest version from the registry to avoid npm cache staleness
12
+ const version = await fetchLatestVersion("@puzzmo/cli")
13
+ console.log(`Installing @puzzmo/cli@${version}...`)
14
+ spawnSync("npm", ["install", "-g", `@puzzmo/cli@${version}`], { stdio: "inherit" })
14
15
 
15
16
  // Pass --pm so the CLI knows which package manager to use in generated files
16
17
  const extraArgs = args.includes("--pm") ? [] : ["--pm", pm]
@@ -28,3 +29,20 @@ function detectPackageManager() {
28
29
  if (ua.startsWith("pnpm")) return "pnpm"
29
30
  return "npm"
30
31
  }
32
+
33
+ /** Fetches the latest version from the npm registry, falls back to "latest" tag */
34
+ function fetchLatestVersion(pkg) {
35
+ return new Promise((resolve) => {
36
+ get(`https://registry.npmjs.org/${pkg}/latest`, (res) => {
37
+ let data = ""
38
+ res.on("data", (chunk) => (data += chunk))
39
+ res.on("end", () => {
40
+ try {
41
+ resolve(JSON.parse(data).version)
42
+ } catch {
43
+ resolve("latest")
44
+ }
45
+ })
46
+ }).on("error", () => resolve("latest"))
47
+ })
48
+ }