vibedgames 0.0.5 → 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.
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
- import { existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "node:fs";
3
- import { join, relative, sep } from "node:path";
2
+ import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
3
+ import { dirname, join, relative, sep } from "node:path";
4
4
  import ignore from "ignore";
5
5
  import { create as tarCreate, extract as tarExtract } from "tar";
6
6
  /**
@@ -92,8 +92,31 @@ export async function packSource(root, tmpDir) {
92
92
  throw new Error("No source files to archive (everything was ignored?).");
93
93
  }
94
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
+ }
95
112
  const path = join(tmpDir, `vg-source-${process.pid}-${files.length}.tgz`);
96
- await tarCreate({ gzip: true, file: path, cwd: root, portable: true }, files);
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
+ }
97
120
  const buf = readFileSync(path);
98
121
  return {
99
122
  path,
@@ -102,6 +125,80 @@ export async function packSource(root, tmpDir) {
102
125
  files,
103
126
  };
104
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
+ }
105
202
  /** Extract a gzipped tar into `destDir` (created if needed). tar strips
106
203
  * leading slashes and rejects `..` paths, so extraction stays inside dest. */
107
204
  export async function extractSource(archivePath, destDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibedgames",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "vg": "./dist/index.js"