create-flow-os 0.0.54 → 0.0.55

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.54",
3
+ "version": "0.0.55",
4
4
  "license": "PolyForm-Shield-1.0.0",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@flow-os/client": "^0.0.54"
7
+ "@flow-os/client": "^0.0.55"
8
8
  },
9
9
  "bin": {
10
10
  "create-flow-os": "./src/index.ts"
package/src/init/lib.ts CHANGED
@@ -51,7 +51,7 @@ export function libsWithConfig(cliRoot: string, flowOsRepoRoot?: string | null):
51
51
  /** In prod (fuori repo): scarica lista pacchetti @flow-os/* da npm. Mappa automaticamente anche i nuovi. */
52
52
  export async function fetchFlowOsPackagesFromNpm(): Promise<string[]> {
53
53
  try {
54
- const res = await fetch(NPM_ORG_API, { headers: { Accept: "application/json" } });
54
+ const res = await fetch(NPM_ORG_API, { headers: { "Cache-Control": "no-cache", Accept: "application/json" } });
55
55
  if (!res.ok) return [];
56
56
  const data = (await res.json()) as Record<string, unknown>;
57
57
  return Object.keys(data).filter((k) => k.startsWith(FLOW_PREFIX));
@@ -1,4 +1,4 @@
1
- import { existsSync, cpSync, readFileSync, writeFileSync, readdirSync, mkdirSync } from "fs";
1
+ import { existsSync, readFileSync, writeFileSync, readdirSync, mkdirSync } from "fs";
2
2
  import { join, basename, dirname } from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  import { pkgRoot, flowDeps, toPkgName, toShortName } from "./lib";
@@ -7,13 +7,6 @@ import { mergeFile, resolveConflicts, mergeJsonTemplates, mergeCodeTemplates } f
7
7
  const SKIP = new Set(["node_modules", ".git", ".vite", "package.json"]);
8
8
  const NPM_REGISTRY = "https://registry.npmjs.org";
9
9
 
10
- /** Cache versioni registry: 5 min TTL */
11
- const versionCache = new Map<string, { v: string; ts: number }>();
12
- const VERSION_TTL_MS = 5 * 60 * 1000;
13
-
14
- /** Cache tarball estratti: riusa se esiste e < 1h */
15
- const TARBALL_CACHE_MAX_AGE_MS = 60 * 60 * 1000;
16
-
17
10
  /** Raccoglie file da configDir in una Map relPath -> content */
18
11
  function collectConfigFiles(configDir: string, relPath = ""): Map<string, string> {
19
12
  const out = new Map<string, string>();
@@ -105,48 +98,21 @@ export function shouldUseWorkspace(cwd: string): boolean {
105
98
  return !!findFlowOsRepoRoot(cwd);
106
99
  }
107
100
 
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. */
101
+ /** Recupera versione di un pacchetto @flow-os/* dal registry npm (sempre fresh) */
110
102
  async function fetchFlowPackageVersion(pkgName: string): Promise<string | undefined> {
111
103
  const tag = isCreateFlowOsDev() ? "dev" : "latest";
112
- const key = `${pkgName}@${tag}`;
113
- const cached = versionCache.get(key);
114
- if (cached && Date.now() - cached.ts < VERSION_TTL_MS) return cached.v;
115
-
116
104
  try {
117
105
  const res = await fetch(`${NPM_REGISTRY}/${pkgName}`, {
118
- headers: { "Cache-Control": "max-age=300", Accept: "application/json" },
106
+ headers: { "Cache-Control": "no-cache", Accept: "application/json" },
119
107
  });
120
108
  if (!res.ok) return undefined;
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"];
133
- if (v) versionCache.set(key, { v, ts: Date.now() });
134
- return v;
109
+ const data = (await res.json()) as { "dist-tags"?: Record<string, string> };
110
+ return data["dist-tags"]?.[tag] ?? data["dist-tags"]?.["latest"];
135
111
  } catch {
136
112
  return undefined;
137
113
  }
138
114
  }
139
115
 
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
-
150
116
  /** Recupera versioni di tutti i pacchetti @flow-os/* richiesti dal registry npm */
151
117
  export async function fetchFlowPackageVersions(pkgNames: string[]): Promise<Map<string, string>> {
152
118
  const out = new Map<string, string>();
@@ -164,7 +130,7 @@ export async function fetchFlowClientVersion(): Promise<string | undefined> {
164
130
  return fetchFlowPackageVersion("@flow-os/client");
165
131
  }
166
132
 
167
- /** Scarica config da npm; riusa cache se estratta di recente (< 1h) */
133
+ /** Scarica config da npm (sempre fresh, no cache) */
168
134
  async function fetchConfigFromNpm(
169
135
  pkgName: string,
170
136
  version: string,
@@ -172,23 +138,9 @@ async function fetchConfigFromNpm(
172
138
  ): Promise<{ files: Map<string, string>; configDir: string; tmpDir: string } | null> {
173
139
  const shortName = pkgName.replace(/^@flow-os\//, "");
174
140
  const { tmpdir } = await import("os");
175
- const cacheDir = join(tmpdir(), "flow-os-cache", `${shortName}-${version}`);
176
- const configDir = join(cacheDir, "package", "config");
177
-
178
- if (existsSync(configDir)) {
179
- try {
180
- const { statSync } = await import("fs");
181
- const st = statSync(configDir);
182
- if (Date.now() - st.mtimeMs < TARBALL_CACHE_MAX_AGE_MS) {
183
- const files = collectConfigFiles(configDir);
184
- return { files, configDir, tmpDir: cacheDir };
185
- }
186
- } catch {}
187
- }
188
-
189
141
  const url = `${NPM_REGISTRY}/${pkgName}/-/${shortName}-${version}.tgz`;
190
142
  try {
191
- const res = await fetch(url, { headers: { "Cache-Control": "max-age=3600" } });
143
+ const res = await fetch(url, { headers: { "Cache-Control": "no-cache" } });
192
144
  if (!res.ok) return null;
193
145
  const archive = new Bun.Archive(await res.blob());
194
146
  const tmpDir = join(tmpdir(), `flow-os-${shortName}-${version}-${Date.now()}`);
@@ -196,16 +148,6 @@ async function fetchConfigFromNpm(
196
148
  const extractedConfigDir = join(tmpDir, "package", "config");
197
149
  if (!existsSync(extractedConfigDir)) return null;
198
150
  const files = collectConfigFiles(extractedConfigDir);
199
-
200
- try {
201
- const { mkdirSync } = await import("fs");
202
- mkdirSync(join(cacheDir, "package"), { recursive: true });
203
- const { cpSync } = await import("fs");
204
- cpSync(join(tmpDir, "package", "config"), join(cacheDir, "package", "config"), {
205
- recursive: true,
206
- });
207
- } catch {}
208
-
209
151
  tmpDirs.push(tmpDir);
210
152
  return { files, configDir: extractedConfigDir, tmpDir };
211
153
  } catch {