toolcrib 0.7.0 → 0.9.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcrib",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Bootstrap the toolcrib UI toolkit into your project",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@ import * as p from '@clack/prompts';
3
3
  import { fetchRelease, fetchTestsRelease } from '../lib/release.js';
4
4
  import { resolveVersion } from '../lib/github.js';
5
5
  import { PendingChanges, normalize, joinPatchPath } from '../lib/patches.js';
6
- import { mergeImportsField } from '../lib/deps.js';
6
+ import { resolveDependencyDecisions, buildProposedPackageJson, mergeImportsField } from '../lib/deps.js';
7
7
  import { fileExists, readJsonIfExists, readLock, readTextIfExists, proposeLockUpdate } from '../lib/project.js';
8
8
  import { MANAGED_DOCS, KNOWN_TARGET_FILES, listManagedBlocks, upsertManagedBlock } from '../lib/managedDocs.js';
9
9
 
@@ -86,8 +86,8 @@ function diffReleaseFiles(projectRoot, oldRelease, newRelease, changes, conflict
86
86
  }
87
87
 
88
88
  // A file present in oldRelease but absent from newRelease was removed
89
- // upstream — e.g. useAnimatedMount.ts when Drawer moved to Radix
90
- // Presence in v0.10.0. Without this pass, a vendored copy of a file
89
+ // upstream — e.g. useAnimatedMount.ts when Drawer moved to a Presence
90
+ // primitive in v0.10.0. Without this pass, a vendored copy of a file
91
91
  // upstream no longer ships just sits there forever, unreferenced but
92
92
  // never cleaned up, since the loop above only ever visits paths that
93
93
  // still exist in the *new* release. classify(original, local, '')
@@ -305,13 +305,36 @@ export async function mergeCommand(options) {
305
305
 
306
306
  await cleanupAll();
307
307
 
308
- // Installs from before the "imports" subpath entry existed won't have it —
309
- // propose adding it here too, not just on a fresh `init`.
308
+ // package.json: the target release's peerDependencies the project doesn't
309
+ // have yet (a release can introduce new ones -- e.g. the Base UI switch
310
+ // added @base-ui/react), plus installs from before the "imports" subpath
311
+ // entry existed. One combined patch, same reason as init.js: two propose()
312
+ // calls for the same relPath would both diff against the original file.
310
313
  const pkgPath = path.join(projectRoot, 'package.json');
311
314
  const userPkg = readJsonIfExists(pkgPath);
315
+ let depConflicts = [];
316
+ let removedPeers = [];
312
317
  if (userPkg) {
313
- const importsResult = mergeImportsField(userPkg, TOOLKIT_IMPORTS_ENTRY);
314
- if (importsResult.changed) {
318
+ const depDecisions = resolveDependencyDecisions(userPkg, newRelease.config?.peerDependencies ?? {});
319
+ const pkgWithDeps = depDecisions.toAdd.length > 0
320
+ ? buildProposedPackageJson(userPkg, depDecisions.toAdd)
321
+ : userPkg;
322
+ // The vendored tests' own peers are dev tooling, so devDependencies, as in init.
323
+ const testsDepDecisions = newTestsRelease
324
+ ? resolveDependencyDecisions(pkgWithDeps, newTestsRelease.config?.peerDependencies ?? {})
325
+ : null;
326
+ const pkgWithAllDeps = testsDepDecisions?.toAdd.length > 0
327
+ ? buildProposedPackageJson(pkgWithDeps, testsDepDecisions.toAdd, 'devDependencies')
328
+ : pkgWithDeps;
329
+ depConflicts = [...depDecisions.conflicts, ...(testsDepDecisions?.conflicts ?? [])];
330
+ // Peers the old release needed and the new one doesn't: reported, never
331
+ // removed -- the project may use them itself.
332
+ const newPeers = newRelease.config?.peerDependencies ?? {};
333
+ removedPeers = Object.keys(oldRelease.config?.peerDependencies ?? {}).filter(
334
+ (name) => !(name in newPeers) && (userPkg.dependencies?.[name] || userPkg.devDependencies?.[name])
335
+ );
336
+ const importsResult = mergeImportsField(pkgWithAllDeps, TOOLKIT_IMPORTS_ENTRY);
337
+ if (depDecisions.toAdd.length > 0 || testsDepDecisions?.toAdd.length > 0 || importsResult.changed) {
315
338
  changes.propose(
316
339
  'package.json',
317
340
  readTextIfExists(pkgPath),
@@ -381,6 +404,21 @@ export async function mergeCommand(options) {
381
404
  );
382
405
  }
383
406
 
407
+ if (depConflicts.length > 0) {
408
+ process.exitCode = 1;
409
+ p.log.warn(
410
+ `${depConflicts.length} dependency conflict(s) — not staged, needs your decision:\n` +
411
+ depConflicts
412
+ .map((d) => ` ${d.name}: you have ${d.userRange}, toolcrib needs ${d.requiredRange} (${d.reason})`)
413
+ .join('\n')
414
+ );
415
+ }
416
+ if (removedPeers.length > 0) {
417
+ p.log.info(
418
+ `No longer required by toolcrib (left in package.json; remove them if your own code doesn't use them): ${removedPeers.join(', ')}`
419
+ );
420
+ }
421
+
384
422
  p.outro(changes.isEmpty() ? 'No changes to apply.' : 'Review ./toolcrib-patches/, then run `toolcrib apply`.');
385
423
  }
386
424
 
package/src/lib/zip.js CHANGED
@@ -32,10 +32,28 @@ export function powerShellQuote(value) {
32
32
  export async function extractZip(zipBuffer, targetDir) {
33
33
  await fsp.mkdir(targetDir, { recursive: true });
34
34
 
35
- const tmpZipPath = path.join(os.tmpdir(), `toolcrib-${Date.now()}.zip`);
36
- await fsp.writeFile(tmpZipPath, zipBuffer);
35
+ // A bare `Date.now()`-keyed filename collides under real concurrent use:
36
+ // commands/merge.js (old + new release) and `init --with-tests` (core +
37
+ // tests release) both fetch two releases via Promise.allSettled, and each
38
+ // independently calls extractZip() — two calls landing in the same
39
+ // millisecond used to share one tmpZipPath, so one call's write/unlink
40
+ // could clobber or delete the file out from under the other's still-
41
+ // running Expand-Archive/unzip, silently corrupting one extraction (both
42
+ // ending up with identical content) or crashing outright. Found for real
43
+ // running a v0.14.0->v0.15.0 `merge` simulation before the v0.15.0 release
44
+ // (see issue #488). fsp.mkdtemp gives each call its own directory, the
45
+ // same pattern lib/release.js's fetchRelease/fetchTestsRelease already
46
+ // use for their own tempDirs — no shared path between concurrent calls.
47
+ const tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'toolcrib-zip-'));
48
+ const tmpZipPath = path.join(tmpDir, 'archive.zip');
37
49
 
38
50
  try {
51
+ // Inside the try, not before it — caught in review (Gemini, PR #489):
52
+ // a write failure here (disk full, permissions) used to abort before
53
+ // the try/finally even started, leaking tmpDir the same way the
54
+ // pre-fix code leaked on every concurrent collision.
55
+ await fsp.writeFile(tmpZipPath, zipBuffer);
56
+
39
57
  if (process.platform === 'win32') {
40
58
  // PowerShell's Expand-Archive ships on all modern Windows installs.
41
59
  //
@@ -60,7 +78,7 @@ export async function extractZip(zipBuffer, targetDir) {
60
78
  await execFileAsync('unzip', ['-o', '-q', tmpZipPath, '-d', targetDir]);
61
79
  }
62
80
  } finally {
63
- await fsp.unlink(tmpZipPath).catch(() => {});
81
+ await fsp.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
64
82
  }
65
83
  }
66
84