create-flow-os 0.0.52 → 0.0.54

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "create-flow-os",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "license": "PolyForm-Shield-1.0.0",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@flow-os/client": "^0.0.52"
7
+ "@flow-os/client": "^0.0.54"
8
8
  },
9
9
  "bin": {
10
10
  "create-flow-os": "./src/index.ts"
package/src/init/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import * as readline from "readline";
4
4
  import { join, dirname } from "path";
5
5
  import { fileURLToPath } from "url";
6
- import { libsWithConfig, toShortName, toPkgName } from "./lib";
6
+ import { libsWithConfig, fetchFlowOsPackagesFromNpm, toShortName, toPkgName } from "./lib";
7
7
  import { initLib, fetchFlowPackageVersions, shouldUseWorkspace, findFlowOsRepoRoot } from "./scaffold";
8
8
  import { bannerBox, withLoading, colors } from "./ui";
9
9
 
@@ -15,7 +15,9 @@ const { V, V_LIGHT, Y, E, R, B } = colors;
15
15
  const cwd = process.cwd();
16
16
  const cliRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
17
17
  const flowOsRepoRoot = findFlowOsRepoRoot(cwd);
18
- const available = libsWithConfig(cliRoot, flowOsRepoRoot).map(toShortName);
18
+ const available = flowOsRepoRoot
19
+ ? libsWithConfig(cliRoot, flowOsRepoRoot).map(toShortName)
20
+ : (await fetchFlowOsPackagesFromNpm()).map(toShortName);
19
21
 
20
22
  let libs = [...new Set(process.argv.slice(3))];
21
23
 
package/src/init/lib.ts CHANGED
@@ -3,6 +3,7 @@ import { join, dirname } from "path";
3
3
  import { fileURLToPath } from "url";
4
4
 
5
5
  const FLOW_PREFIX = "@flow-os/";
6
+ const NPM_ORG_API = "https://registry.npmjs.org/-/org/flow-os/package";
6
7
 
7
8
  export function pkgRoot(pkgName: string): string {
8
9
  const url = import.meta.resolve(pkgName);
@@ -47,6 +48,18 @@ export function libsWithConfig(cliRoot: string, flowOsRepoRoot?: string | null):
47
48
  return deps.filter((name) => existsSync(join(pkgRoot(name), "config")));
48
49
  }
49
50
 
51
+ /** In prod (fuori repo): scarica lista pacchetti @flow-os/* da npm. Mappa automaticamente anche i nuovi. */
52
+ export async function fetchFlowOsPackagesFromNpm(): Promise<string[]> {
53
+ try {
54
+ const res = await fetch(NPM_ORG_API, { headers: { Accept: "application/json" } });
55
+ if (!res.ok) return [];
56
+ const data = (await res.json()) as Record<string, unknown>;
57
+ return Object.keys(data).filter((k) => k.startsWith(FLOW_PREFIX));
58
+ } catch {
59
+ return [];
60
+ }
61
+ }
62
+
50
63
  export function toShortName(name: string): string {
51
64
  return name.replace(FLOW_PREFIX, "");
52
65
  }
@@ -105,7 +105,8 @@ export function shouldUseWorkspace(cwd: string): boolean {
105
105
  return !!findFlowOsRepoRoot(cwd);
106
106
  }
107
107
 
108
- /** Recupera versione di un pacchetto @flow-os/* dal registry npm (con cache 5 min) */
108
+ /** Recupera versione di un pacchetto @flow-os/* dal registry npm (con cache 5 min).
109
+ * In prod usa la penultima stabile da versions/ per evitare ritardi di propagazione della più recente. */
109
110
  async function fetchFlowPackageVersion(pkgName: string): Promise<string | undefined> {
110
111
  const tag = isCreateFlowOsDev() ? "dev" : "latest";
111
112
  const key = `${pkgName}@${tag}`;
@@ -117,8 +118,18 @@ async function fetchFlowPackageVersion(pkgName: string): Promise<string | undefi
117
118
  headers: { "Cache-Control": "max-age=300", Accept: "application/json" },
118
119
  });
119
120
  if (!res.ok) return undefined;
120
- const data = (await res.json()) as { "dist-tags"?: Record<string, string> };
121
- const v = data["dist-tags"]?.[tag] ?? data["dist-tags"]?.["latest"];
121
+ const data = (await res.json()) as {
122
+ "dist-tags"?: Record<string, string>;
123
+ versions?: Record<string, unknown>;
124
+ };
125
+ if (isCreateFlowOsDev()) {
126
+ const v = data["dist-tags"]?.["dev"] ?? data["dist-tags"]?.["latest"];
127
+ if (v) versionCache.set(key, { v, ts: Date.now() });
128
+ return v;
129
+ }
130
+ const versions = data.versions ? Object.keys(data.versions) : [];
131
+ const stable = versions.filter((v) => /^\d+\.\d+\.\d+$/.test(v)).sort(semverCompare);
132
+ const v = stable[stable.length - 2] ?? stable[stable.length - 1] ?? data["dist-tags"]?.["latest"];
122
133
  if (v) versionCache.set(key, { v, ts: Date.now() });
123
134
  return v;
124
135
  } catch {
@@ -126,6 +137,16 @@ async function fetchFlowPackageVersion(pkgName: string): Promise<string | undefi
126
137
  }
127
138
  }
128
139
 
140
+ function semverCompare(a: string, b: string): number {
141
+ const pa = a.split(".").map(Number);
142
+ const pb = b.split(".").map(Number);
143
+ for (let i = 0; i < 3; i++) {
144
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
145
+ if (d !== 0) return d;
146
+ }
147
+ return 0;
148
+ }
149
+
129
150
  /** Recupera versioni di tutti i pacchetti @flow-os/* richiesti dal registry npm */
130
151
  export async function fetchFlowPackageVersions(pkgNames: string[]): Promise<Map<string, string>> {
131
152
  const out = new Map<string, string>();
@@ -511,8 +532,11 @@ export async function initLib(
511
532
  const installCwd = useWorkspace && flowOsRepoRoot ? flowOsRepoRoot : cwd;
512
533
  const proc = Bun.spawn(["bun", "install"], { cwd: installCwd, stdout: "pipe", stderr: "pipe" });
513
534
  const exitCode = await proc.exited;
535
+ const stdout = await new Response(proc.stdout).text();
536
+ const stderr = await new Response(proc.stderr).text();
514
537
  if (exitCode !== 0) {
515
- throw new Error(`bun install exited with code ${exitCode}`);
538
+ const errMsg = stderr.trim() || stdout.trim() || `exit code ${exitCode}`;
539
+ throw new Error(`bun install failed:\n${errMsg}`);
516
540
  }
517
541
 
518
542
  const { rmSync } = await import("fs");