create-flow-os 0.0.53 → 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 +2 -2
- package/src/init/lib.ts +1 -1
- package/src/init/scaffold.ts +10 -44
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-flow-os",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
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));
|
package/src/init/scaffold.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync,
|
|
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,22 +98,16 @@ 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 (
|
|
101
|
+
/** Recupera versione di un pacchetto @flow-os/* dal registry npm (sempre fresh) */
|
|
109
102
|
async function fetchFlowPackageVersion(pkgName: string): Promise<string | undefined> {
|
|
110
103
|
const tag = isCreateFlowOsDev() ? "dev" : "latest";
|
|
111
|
-
const key = `${pkgName}@${tag}`;
|
|
112
|
-
const cached = versionCache.get(key);
|
|
113
|
-
if (cached && Date.now() - cached.ts < VERSION_TTL_MS) return cached.v;
|
|
114
|
-
|
|
115
104
|
try {
|
|
116
105
|
const res = await fetch(`${NPM_REGISTRY}/${pkgName}`, {
|
|
117
|
-
headers: { "Cache-Control": "
|
|
106
|
+
headers: { "Cache-Control": "no-cache", Accept: "application/json" },
|
|
118
107
|
});
|
|
119
108
|
if (!res.ok) return undefined;
|
|
120
109
|
const data = (await res.json()) as { "dist-tags"?: Record<string, string> };
|
|
121
|
-
|
|
122
|
-
if (v) versionCache.set(key, { v, ts: Date.now() });
|
|
123
|
-
return v;
|
|
110
|
+
return data["dist-tags"]?.[tag] ?? data["dist-tags"]?.["latest"];
|
|
124
111
|
} catch {
|
|
125
112
|
return undefined;
|
|
126
113
|
}
|
|
@@ -143,7 +130,7 @@ export async function fetchFlowClientVersion(): Promise<string | undefined> {
|
|
|
143
130
|
return fetchFlowPackageVersion("@flow-os/client");
|
|
144
131
|
}
|
|
145
132
|
|
|
146
|
-
/** Scarica config da npm
|
|
133
|
+
/** Scarica config da npm (sempre fresh, no cache) */
|
|
147
134
|
async function fetchConfigFromNpm(
|
|
148
135
|
pkgName: string,
|
|
149
136
|
version: string,
|
|
@@ -151,23 +138,9 @@ async function fetchConfigFromNpm(
|
|
|
151
138
|
): Promise<{ files: Map<string, string>; configDir: string; tmpDir: string } | null> {
|
|
152
139
|
const shortName = pkgName.replace(/^@flow-os\//, "");
|
|
153
140
|
const { tmpdir } = await import("os");
|
|
154
|
-
const cacheDir = join(tmpdir(), "flow-os-cache", `${shortName}-${version}`);
|
|
155
|
-
const configDir = join(cacheDir, "package", "config");
|
|
156
|
-
|
|
157
|
-
if (existsSync(configDir)) {
|
|
158
|
-
try {
|
|
159
|
-
const { statSync } = await import("fs");
|
|
160
|
-
const st = statSync(configDir);
|
|
161
|
-
if (Date.now() - st.mtimeMs < TARBALL_CACHE_MAX_AGE_MS) {
|
|
162
|
-
const files = collectConfigFiles(configDir);
|
|
163
|
-
return { files, configDir, tmpDir: cacheDir };
|
|
164
|
-
}
|
|
165
|
-
} catch {}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
141
|
const url = `${NPM_REGISTRY}/${pkgName}/-/${shortName}-${version}.tgz`;
|
|
169
142
|
try {
|
|
170
|
-
const res = await fetch(url, { headers: { "Cache-Control": "
|
|
143
|
+
const res = await fetch(url, { headers: { "Cache-Control": "no-cache" } });
|
|
171
144
|
if (!res.ok) return null;
|
|
172
145
|
const archive = new Bun.Archive(await res.blob());
|
|
173
146
|
const tmpDir = join(tmpdir(), `flow-os-${shortName}-${version}-${Date.now()}`);
|
|
@@ -175,16 +148,6 @@ async function fetchConfigFromNpm(
|
|
|
175
148
|
const extractedConfigDir = join(tmpDir, "package", "config");
|
|
176
149
|
if (!existsSync(extractedConfigDir)) return null;
|
|
177
150
|
const files = collectConfigFiles(extractedConfigDir);
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
const { mkdirSync } = await import("fs");
|
|
181
|
-
mkdirSync(join(cacheDir, "package"), { recursive: true });
|
|
182
|
-
const { cpSync } = await import("fs");
|
|
183
|
-
cpSync(join(tmpDir, "package", "config"), join(cacheDir, "package", "config"), {
|
|
184
|
-
recursive: true,
|
|
185
|
-
});
|
|
186
|
-
} catch {}
|
|
187
|
-
|
|
188
151
|
tmpDirs.push(tmpDir);
|
|
189
152
|
return { files, configDir: extractedConfigDir, tmpDir };
|
|
190
153
|
} catch {
|
|
@@ -511,8 +474,11 @@ export async function initLib(
|
|
|
511
474
|
const installCwd = useWorkspace && flowOsRepoRoot ? flowOsRepoRoot : cwd;
|
|
512
475
|
const proc = Bun.spawn(["bun", "install"], { cwd: installCwd, stdout: "pipe", stderr: "pipe" });
|
|
513
476
|
const exitCode = await proc.exited;
|
|
477
|
+
const stdout = await new Response(proc.stdout).text();
|
|
478
|
+
const stderr = await new Response(proc.stderr).text();
|
|
514
479
|
if (exitCode !== 0) {
|
|
515
|
-
|
|
480
|
+
const errMsg = stderr.trim() || stdout.trim() || `exit code ${exitCode}`;
|
|
481
|
+
throw new Error(`bun install failed:\n${errMsg}`);
|
|
516
482
|
}
|
|
517
483
|
|
|
518
484
|
const { rmSync } = await import("fs");
|