vibedgames 0.0.4 → 0.0.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/dist/.tsbuildinfo +1 -1
- package/dist/commands/deploy.d.ts +5 -0
- package/dist/commands/deploy.js +57 -3
- package/dist/commands/fork.d.ts +26 -0
- package/dist/commands/fork.js +118 -0
- package/dist/index.js +2 -0
- package/dist/lib/archive.d.ts +17 -0
- package/dist/lib/archive.js +207 -0
- package/dist/lib/config-file.d.ts +3 -0
- package/dist/lib/config-file.js +6 -0
- package/package.json +3 -1
|
@@ -10,4 +10,9 @@ export declare const deployCommand: import("citty").CommandDef<{
|
|
|
10
10
|
readonly description: "Override the slug (bypasses vibedgames.json)";
|
|
11
11
|
readonly required: false;
|
|
12
12
|
};
|
|
13
|
+
readonly source: {
|
|
14
|
+
readonly type: "boolean";
|
|
15
|
+
readonly description: "Upload a forkable source archive alongside the build (use --no-source to skip).";
|
|
16
|
+
readonly default: true;
|
|
17
|
+
};
|
|
13
18
|
}>;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
3
4
|
import { defineCommand } from "citty";
|
|
4
5
|
import consola from "consola";
|
|
5
6
|
import { createClient } from "../lib/api.js";
|
|
6
|
-
import {
|
|
7
|
+
import { packSource } from "../lib/archive.js";
|
|
8
|
+
import { findProjectRoot, projectConfigPath, readProjectConfig, writeProjectConfig, } from "../lib/config-file.js";
|
|
7
9
|
import { buildManifest } from "../lib/manifest.js";
|
|
8
10
|
import { uploadAll } from "../lib/upload.js";
|
|
9
11
|
const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
|
|
@@ -24,6 +26,11 @@ export const deployCommand = defineCommand({
|
|
|
24
26
|
description: "Override the slug (bypasses vibedgames.json)",
|
|
25
27
|
required: false,
|
|
26
28
|
},
|
|
29
|
+
source: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
description: "Upload a forkable source archive alongside the build (use --no-source to skip).",
|
|
32
|
+
default: true,
|
|
33
|
+
},
|
|
27
34
|
},
|
|
28
35
|
run: async ({ args }) => {
|
|
29
36
|
const dir = resolve(args.dir);
|
|
@@ -80,6 +87,24 @@ export const deployCommand = defineCommand({
|
|
|
80
87
|
}
|
|
81
88
|
const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
|
|
82
89
|
consola.info(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
|
|
90
|
+
// ---- Pack forkable source (default on; --no-source to skip) -------------
|
|
91
|
+
let sourceArchive = null;
|
|
92
|
+
if (args.source) {
|
|
93
|
+
const root = findProjectRoot(dir);
|
|
94
|
+
if (!root) {
|
|
95
|
+
consola.warn("No vibedgames.json found above the deploy dir — skipping source upload.");
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
try {
|
|
99
|
+
sourceArchive = await packSource(root, join(tmpdir(), "vibedgames"));
|
|
100
|
+
consola.info(`Source: ${sourceArchive.files.length} files, ${formatBytes(sourceArchive.bytes)} — forkable via \`vg fork ${config.slug}\``);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
consola.error(`Source archive failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
83
108
|
// ---- Create deployment --------------------------------------------------
|
|
84
109
|
const client = createClient();
|
|
85
110
|
const started = Date.now();
|
|
@@ -94,9 +119,14 @@ export const deployCommand = defineCommand({
|
|
|
94
119
|
sha256: f.sha256,
|
|
95
120
|
contentType: f.contentType,
|
|
96
121
|
})),
|
|
122
|
+
source: sourceArchive
|
|
123
|
+
? { sha256: sourceArchive.sha256, bytes: sourceArchive.bytes }
|
|
124
|
+
: undefined,
|
|
97
125
|
});
|
|
98
126
|
}
|
|
99
127
|
catch (err) {
|
|
128
|
+
if (sourceArchive)
|
|
129
|
+
rmSync(sourceArchive.path, { force: true });
|
|
100
130
|
consola.error(err instanceof Error ? err.message : String(err));
|
|
101
131
|
process.exit(1);
|
|
102
132
|
}
|
|
@@ -114,9 +144,33 @@ export const deployCommand = defineCommand({
|
|
|
114
144
|
});
|
|
115
145
|
}
|
|
116
146
|
catch (err) {
|
|
147
|
+
if (sourceArchive)
|
|
148
|
+
rmSync(sourceArchive.path, { force: true });
|
|
117
149
|
consola.error(err instanceof Error ? err.message : String(err));
|
|
118
150
|
process.exit(1);
|
|
119
151
|
}
|
|
152
|
+
// ---- Upload source archive (best-effort companion to the bundle) -------
|
|
153
|
+
if (sourceArchive && created.sourceUpload) {
|
|
154
|
+
try {
|
|
155
|
+
const res = await fetch(created.sourceUpload.url, {
|
|
156
|
+
method: "PUT",
|
|
157
|
+
headers: created.sourceUpload.headers,
|
|
158
|
+
body: readFileSync(sourceArchive.path),
|
|
159
|
+
});
|
|
160
|
+
if (!res.ok) {
|
|
161
|
+
throw new Error(`source upload failed: ${res.status} ${res.statusText}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
rmSync(sourceArchive.path, { force: true });
|
|
166
|
+
consola.error(err instanceof Error ? err.message : String(err));
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
rmSync(sourceArchive.path, { force: true });
|
|
170
|
+
}
|
|
171
|
+
else if (sourceArchive) {
|
|
172
|
+
rmSync(sourceArchive.path, { force: true });
|
|
173
|
+
}
|
|
120
174
|
// ---- Finalize -----------------------------------------------------------
|
|
121
175
|
let finalized;
|
|
122
176
|
try {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const forkCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly slug: {
|
|
3
|
+
readonly type: "positional";
|
|
4
|
+
readonly description: "Slug of the project to fork (e.g. bomberman).";
|
|
5
|
+
readonly required: true;
|
|
6
|
+
};
|
|
7
|
+
readonly target: {
|
|
8
|
+
readonly type: "positional";
|
|
9
|
+
readonly description: "New slug + directory for the fork. Defaults to <slug>-fork.";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly name: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "Display name for the fork (defaults to the target slug).";
|
|
15
|
+
};
|
|
16
|
+
readonly force: {
|
|
17
|
+
readonly type: "boolean";
|
|
18
|
+
readonly description: "Overwrite the target directory if it exists.";
|
|
19
|
+
readonly default: false;
|
|
20
|
+
};
|
|
21
|
+
readonly json: {
|
|
22
|
+
readonly type: "boolean";
|
|
23
|
+
readonly description: "Emit machine-readable JSON (for agents).";
|
|
24
|
+
readonly default: false;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
import { createClient } from "../lib/api.js";
|
|
7
|
+
import { extractSource } from "../lib/archive.js";
|
|
8
|
+
const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
|
|
9
|
+
export const forkCommand = defineCommand({
|
|
10
|
+
meta: {
|
|
11
|
+
name: "fork",
|
|
12
|
+
description: "Fork another project's source so you can build on it. Downloads the source a project shipped with `vg deploy`, extracts it locally, and rewrites it to a new slug.",
|
|
13
|
+
},
|
|
14
|
+
args: {
|
|
15
|
+
slug: {
|
|
16
|
+
type: "positional",
|
|
17
|
+
description: "Slug of the project to fork (e.g. bomberman).",
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
target: {
|
|
21
|
+
type: "positional",
|
|
22
|
+
description: "New slug + directory for the fork. Defaults to <slug>-fork.",
|
|
23
|
+
required: false,
|
|
24
|
+
},
|
|
25
|
+
name: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Display name for the fork (defaults to the target slug).",
|
|
28
|
+
},
|
|
29
|
+
force: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
description: "Overwrite the target directory if it exists.",
|
|
32
|
+
default: false,
|
|
33
|
+
},
|
|
34
|
+
json: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
description: "Emit machine-readable JSON (for agents).",
|
|
37
|
+
default: false,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
run: async ({ args }) => {
|
|
41
|
+
const source = args.slug.trim().toLowerCase();
|
|
42
|
+
const target = (args.target ?? `${source}-fork`).trim().toLowerCase();
|
|
43
|
+
if (!SLUG_RE.test(target)) {
|
|
44
|
+
consola.error(`Invalid target slug "${target}". Use lowercase letters, digits, and hyphens.`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
const dir = resolve(process.cwd(), target);
|
|
48
|
+
if (existsSync(dir)) {
|
|
49
|
+
if (!args.force) {
|
|
50
|
+
consola.error(`Directory ${dir} already exists. Pass --force to overwrite, or pick another target.`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
// --force means replace, not merge — clear stale files first so the fork
|
|
54
|
+
// isn't a dirty mix of the archive and whatever was already there.
|
|
55
|
+
rmSync(dir, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
const client = createClient();
|
|
58
|
+
// ---- Resolve + download source -----------------------------------------
|
|
59
|
+
if (!args.json)
|
|
60
|
+
consola.start(`Forking ${source}`);
|
|
61
|
+
let src;
|
|
62
|
+
try {
|
|
63
|
+
src = await client.deploy.getSource.query({ slug: source });
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
consola.error(err instanceof Error ? err.message : String(err));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const tmp = join(tmpdir(), "vibedgames", `fork-${process.pid}.tgz`);
|
|
70
|
+
mkdirSync(join(tmpdir(), "vibedgames"), { recursive: true });
|
|
71
|
+
try {
|
|
72
|
+
const res = await fetch(src.url);
|
|
73
|
+
if (!res.ok)
|
|
74
|
+
throw new Error(`download failed: ${res.status} ${res.statusText}`);
|
|
75
|
+
writeFileSync(tmp, Buffer.from(await res.arrayBuffer()));
|
|
76
|
+
await extractSource(tmp, dir);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
consola.error(err instanceof Error ? err.message : String(err));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
rmSync(tmp, { force: true });
|
|
84
|
+
}
|
|
85
|
+
// ---- Re-slug the fork (clean slate — no provenance recorded) ------------
|
|
86
|
+
const name = args.name ?? target.replace(/-/g, " ");
|
|
87
|
+
writeFileSync(resolve(dir, "vibedgames.json"), `${JSON.stringify({ slug: target, name }, null, 2)}\n`);
|
|
88
|
+
rewritePackageName(dir, target);
|
|
89
|
+
if (args.json) {
|
|
90
|
+
consola.log(JSON.stringify({ slug: target, dir, forkedFrom: source }));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
consola.success(`Forked ${source} → ${target}`);
|
|
94
|
+
consola.log(` ${dir}`);
|
|
95
|
+
consola.log("");
|
|
96
|
+
consola.info("Next steps:");
|
|
97
|
+
consola.log(` cd ${target}`);
|
|
98
|
+
consola.log(" npm install");
|
|
99
|
+
consola.log(" npm run dev");
|
|
100
|
+
consola.log(` # then: npm run build && vg deploy ./dist → ${target}.vibedgames.com`);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
function rewritePackageName(dir, slug) {
|
|
104
|
+
const pkgPath = resolve(dir, "package.json");
|
|
105
|
+
if (!existsSync(pkgPath))
|
|
106
|
+
return;
|
|
107
|
+
try {
|
|
108
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
109
|
+
pkg.name = slug;
|
|
110
|
+
delete pkg.repository;
|
|
111
|
+
delete pkg.bugs;
|
|
112
|
+
delete pkg.homepage;
|
|
113
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
consola.warn(`Could not rewrite package.json name: ${err instanceof Error ? err.message : String(err)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
import { completionsCommand } from "./commands/completions.js";
|
|
5
5
|
import { deployCommand } from "./commands/deploy.js";
|
|
6
|
+
import { forkCommand } from "./commands/fork.js";
|
|
6
7
|
import { initCommand } from "./commands/init.js";
|
|
7
8
|
import { loginCommand } from "./commands/login.js";
|
|
8
9
|
import { logoutCommand } from "./commands/logout.js";
|
|
@@ -22,6 +23,7 @@ const main = defineCommand({
|
|
|
22
23
|
login: loginCommand,
|
|
23
24
|
logout: logoutCommand,
|
|
24
25
|
deploy: deployCommand,
|
|
26
|
+
fork: forkCommand,
|
|
25
27
|
media: mediaCommand,
|
|
26
28
|
completions: completionsCommand,
|
|
27
29
|
whoami: whoamiCommand,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type SourceArchive = {
|
|
2
|
+
/** absolute path to the temp .tgz */
|
|
3
|
+
path: string;
|
|
4
|
+
sha256: string;
|
|
5
|
+
bytes: number;
|
|
6
|
+
/** posix relative paths included, for display */
|
|
7
|
+
files: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Create a gzipped tar of `root`'s source (respecting .gitignore +
|
|
11
|
+
* HARD_EXCLUDES) at a temp path. Returns the archive path, its sha256, byte
|
|
12
|
+
* size, and the list of included files.
|
|
13
|
+
*/
|
|
14
|
+
export declare function packSource(root: string, tmpDir: string): Promise<SourceArchive>;
|
|
15
|
+
/** Extract a gzipped tar into `destDir` (created if needed). tar strips
|
|
16
|
+
* leading slashes and rejects `..` paths, so extraction stays inside dest. */
|
|
17
|
+
export declare function extractSource(archivePath: string, destDir: string): Promise<void>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
4
|
+
import ignore from "ignore";
|
|
5
|
+
import { create as tarCreate, extract as tarExtract } from "tar";
|
|
6
|
+
/**
|
|
7
|
+
* Patterns ALWAYS excluded from a source archive, regardless of .gitignore —
|
|
8
|
+
* build output, VCS internals, and (critically) secrets. Source upload is a
|
|
9
|
+
* publish: anything left in the folder becomes forkable by anyone.
|
|
10
|
+
*/
|
|
11
|
+
const HARD_EXCLUDES = [
|
|
12
|
+
"node_modules",
|
|
13
|
+
".git",
|
|
14
|
+
"dist",
|
|
15
|
+
"build",
|
|
16
|
+
".next",
|
|
17
|
+
".turbo",
|
|
18
|
+
".cache",
|
|
19
|
+
".vercel",
|
|
20
|
+
".wrangler",
|
|
21
|
+
"coverage",
|
|
22
|
+
".DS_Store",
|
|
23
|
+
"*.log",
|
|
24
|
+
// secrets — never ship these
|
|
25
|
+
".env",
|
|
26
|
+
".env.*",
|
|
27
|
+
"*.pem",
|
|
28
|
+
"*.key",
|
|
29
|
+
"*.p12",
|
|
30
|
+
"*.pfx",
|
|
31
|
+
"id_rsa",
|
|
32
|
+
"id_dsa",
|
|
33
|
+
"id_ecdsa",
|
|
34
|
+
"id_ed25519",
|
|
35
|
+
".npmrc",
|
|
36
|
+
".git-credentials",
|
|
37
|
+
// archives (avoid bundling our own output)
|
|
38
|
+
"*.tgz",
|
|
39
|
+
"*.tar.gz",
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Build the exclusion predicate. HARD_EXCLUDES live in their OWN matcher,
|
|
43
|
+
* checked independently of the user's .gitignore/.vibedgamesignore — so a
|
|
44
|
+
* negation like `!.env` in a user ignore file can NOT un-exclude a secret.
|
|
45
|
+
* A path is excluded if EITHER matcher says so.
|
|
46
|
+
*/
|
|
47
|
+
function buildIgnorer(root) {
|
|
48
|
+
const hard = ignore().add(HARD_EXCLUDES);
|
|
49
|
+
const user = ignore();
|
|
50
|
+
for (const name of [".gitignore", ".vibedgamesignore"]) {
|
|
51
|
+
const p = join(root, name);
|
|
52
|
+
if (existsSync(p))
|
|
53
|
+
user.add(readFileSync(p, "utf8"));
|
|
54
|
+
}
|
|
55
|
+
return (rel) => hard.ignores(rel) || user.ignores(rel);
|
|
56
|
+
}
|
|
57
|
+
/** Walk `root`, returning posix relative paths of files not ignored. Ignored
|
|
58
|
+
* directories are pruned (not descended into) for speed. */
|
|
59
|
+
function collectFiles(root, ignored) {
|
|
60
|
+
const out = [];
|
|
61
|
+
const walk = (dir) => {
|
|
62
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
63
|
+
const abs = join(dir, entry.name);
|
|
64
|
+
const rel = relative(root, abs).split(sep).join("/");
|
|
65
|
+
if (!rel)
|
|
66
|
+
continue;
|
|
67
|
+
// `ignore` matches dirs via a trailing slash; test both forms.
|
|
68
|
+
if (entry.isDirectory()) {
|
|
69
|
+
if (ignored(`${rel}/`) || ignored(rel))
|
|
70
|
+
continue;
|
|
71
|
+
walk(abs);
|
|
72
|
+
}
|
|
73
|
+
else if (entry.isFile()) {
|
|
74
|
+
if (ignored(rel))
|
|
75
|
+
continue;
|
|
76
|
+
out.push(rel);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
walk(root);
|
|
81
|
+
return out.sort();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a gzipped tar of `root`'s source (respecting .gitignore +
|
|
85
|
+
* HARD_EXCLUDES) at a temp path. Returns the archive path, its sha256, byte
|
|
86
|
+
* size, and the list of included files.
|
|
87
|
+
*/
|
|
88
|
+
export async function packSource(root, tmpDir) {
|
|
89
|
+
const ignored = buildIgnorer(root);
|
|
90
|
+
const files = collectFiles(root, ignored);
|
|
91
|
+
if (files.length === 0) {
|
|
92
|
+
throw new Error("No source files to archive (everything was ignored?).");
|
|
93
|
+
}
|
|
94
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
95
|
+
// If package.json uses pnpm-only protocols (workspace:/catalog:), a forked
|
|
96
|
+
// copy wouldn't `npm install` standalone. Rewrite them to concrete installed
|
|
97
|
+
// versions in the ARCHIVED package.json only (disk untouched) by staging the
|
|
98
|
+
// file list into a temp dir. No protocols → no staging (fast path).
|
|
99
|
+
const rewritten = files.includes("package.json") ? rewriteWorkspaceProtocols(root) : null;
|
|
100
|
+
let cwd = root;
|
|
101
|
+
let stage = null;
|
|
102
|
+
if (rewritten) {
|
|
103
|
+
stage = mkdtempSync(join(tmpDir, "stage-"));
|
|
104
|
+
for (const f of files) {
|
|
105
|
+
const dest = join(stage, f);
|
|
106
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
107
|
+
copyFileSync(join(root, f), dest);
|
|
108
|
+
}
|
|
109
|
+
writeFileSync(join(stage, "package.json"), rewritten);
|
|
110
|
+
cwd = stage;
|
|
111
|
+
}
|
|
112
|
+
const path = join(tmpDir, `vg-source-${process.pid}-${files.length}.tgz`);
|
|
113
|
+
try {
|
|
114
|
+
await tarCreate({ gzip: true, file: path, cwd, portable: true }, files);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
if (stage)
|
|
118
|
+
rmSync(stage, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
const buf = readFileSync(path);
|
|
121
|
+
return {
|
|
122
|
+
path,
|
|
123
|
+
sha256: createHash("sha256").update(buf).digest("hex"),
|
|
124
|
+
bytes: statSync(path).size,
|
|
125
|
+
files,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
|
|
129
|
+
/**
|
|
130
|
+
* Rewrite `workspace:` / `catalog:` dep specs in package.json to the concrete
|
|
131
|
+
* versions currently installed in node_modules — mirroring what `pnpm publish`
|
|
132
|
+
* does — so the forked project installs from npm. Returns the rewritten JSON
|
|
133
|
+
* string, or null if there's nothing to change (the common standalone case).
|
|
134
|
+
*/
|
|
135
|
+
function rewriteWorkspaceProtocols(root) {
|
|
136
|
+
let pkg;
|
|
137
|
+
try {
|
|
138
|
+
pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
let changed = false;
|
|
144
|
+
for (const field of DEP_FIELDS) {
|
|
145
|
+
const deps = pkg[field];
|
|
146
|
+
if (!deps || typeof deps !== "object")
|
|
147
|
+
continue;
|
|
148
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
149
|
+
if (typeof spec !== "string")
|
|
150
|
+
continue;
|
|
151
|
+
if (!spec.startsWith("workspace:") && !spec.startsWith("catalog:"))
|
|
152
|
+
continue;
|
|
153
|
+
const resolved = resolveSpec(root, name, spec);
|
|
154
|
+
if (resolved && resolved !== spec) {
|
|
155
|
+
deps[name] = resolved;
|
|
156
|
+
changed = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return changed ? `${JSON.stringify(pkg, null, 2)}\n` : null;
|
|
161
|
+
}
|
|
162
|
+
function resolveSpec(root, name, spec) {
|
|
163
|
+
if (spec.startsWith("workspace:")) {
|
|
164
|
+
const range = spec.slice("workspace:".length);
|
|
165
|
+
// Explicit range (e.g. workspace:^1.2.3) — keep the literal range.
|
|
166
|
+
if (/\d/.test(range))
|
|
167
|
+
return range;
|
|
168
|
+
const v = installedVersion(root, name);
|
|
169
|
+
if (!v)
|
|
170
|
+
return null;
|
|
171
|
+
if (range === "~")
|
|
172
|
+
return `~${v}`;
|
|
173
|
+
if (range === "*")
|
|
174
|
+
return v; // exact pin
|
|
175
|
+
return `^${v}`; // "" or "^"
|
|
176
|
+
}
|
|
177
|
+
// catalog: / catalog:<name> — resolve to the installed version, caret-pinned.
|
|
178
|
+
const v = installedVersion(root, name);
|
|
179
|
+
return v ? `^${v}` : null;
|
|
180
|
+
}
|
|
181
|
+
/** Version of an installed dependency, searching node_modules up the tree. */
|
|
182
|
+
function installedVersion(root, name) {
|
|
183
|
+
let dir = root;
|
|
184
|
+
while (true) {
|
|
185
|
+
const p = join(dir, "node_modules", name, "package.json");
|
|
186
|
+
if (existsSync(p)) {
|
|
187
|
+
try {
|
|
188
|
+
const v = JSON.parse(readFileSync(p, "utf8")).version;
|
|
189
|
+
if (typeof v === "string")
|
|
190
|
+
return v;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
/* fall through to parent */
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const parent = dirname(dir);
|
|
197
|
+
if (parent === dir)
|
|
198
|
+
return null;
|
|
199
|
+
dir = parent;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** Extract a gzipped tar into `destDir` (created if needed). tar strips
|
|
203
|
+
* leading slashes and rejects `..` paths, so extraction stays inside dest. */
|
|
204
|
+
export async function extractSource(archivePath, destDir) {
|
|
205
|
+
mkdirSync(destDir, { recursive: true });
|
|
206
|
+
await tarExtract({ file: archivePath, cwd: destDir });
|
|
207
|
+
}
|
|
@@ -2,6 +2,9 @@ export type ProjectConfig = {
|
|
|
2
2
|
slug: string;
|
|
3
3
|
name?: string;
|
|
4
4
|
};
|
|
5
|
+
/** The directory containing the nearest vibedgames.json at or above `dir`,
|
|
6
|
+
* or null if none — i.e. the project root to archive as forkable source. */
|
|
7
|
+
export declare function findProjectRoot(dir: string): string | null;
|
|
5
8
|
export declare function readProjectConfig(dir: string): ProjectConfig | null;
|
|
6
9
|
export declare function writeProjectConfig(dir: string, config: ProjectConfig): void;
|
|
7
10
|
export declare function projectConfigPath(dir: string): string;
|
package/dist/lib/config-file.js
CHANGED
|
@@ -16,6 +16,12 @@ function findConfigPath(dir) {
|
|
|
16
16
|
current = parent;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
/** The directory containing the nearest vibedgames.json at or above `dir`,
|
|
20
|
+
* or null if none — i.e. the project root to archive as forkable source. */
|
|
21
|
+
export function findProjectRoot(dir) {
|
|
22
|
+
const path = findConfigPath(dir);
|
|
23
|
+
return path ? dirname(path) : null;
|
|
24
|
+
}
|
|
19
25
|
export function readProjectConfig(dir) {
|
|
20
26
|
const path = findConfigPath(dir);
|
|
21
27
|
if (!path)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibedgames",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"bin": {
|
|
6
6
|
"vg": "./dist/index.js"
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"citty": "^0.2.2",
|
|
15
15
|
"consola": "^3.4.2",
|
|
16
16
|
"cross-spawn": "^7.0.6",
|
|
17
|
+
"ignore": "^7.0.5",
|
|
17
18
|
"superjson": "^2.2.6",
|
|
19
|
+
"tar": "^7.4.3",
|
|
18
20
|
"tiged": "^2.12.8"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|