@rebasepro/cli 0.29.2 → 0.29.3

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.
@@ -7453,55 +7453,62 @@ function isWithin(dir, candidate) {
7453
7453
  const relative = path.relative(dir, candidate);
7454
7454
  return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
7455
7455
  }
7456
- /** The deepest directory containing every path given. */
7457
- function commonAncestor(paths) {
7458
- let ancestor = paths[0];
7459
- for (const p of paths.slice(1)) while (!isWithin(ancestor, p)) ancestor = path.dirname(ancestor);
7460
- return ancestor;
7461
- }
7462
7456
  var DEPENDENCY_FIELDS = [
7463
7457
  "dependencies",
7464
7458
  "devDependencies",
7465
7459
  "optionalDependencies"
7466
7460
  ];
7461
+ /** The directory, inside the project, that carries the repositories its links reach outside it. */
7462
+ var LINKED_DIR = ".rebase-linked";
7467
7463
  /**
7468
- * Directories outside every unit that a unit's `package.json` files link to
7469
- * with `link:` or `file:`.
7464
+ * The local links of one manifest — `link:`/`file:` dependencies on a directory
7465
+ * that exists — or `null` when it is not a manifest that parses.
7470
7466
  *
7471
7467
  * `@rebasepro/*` links are not followed. They point at a local framework
7472
7468
  * checkout, which is not the project's source and would drag a whole monorepo
7473
7469
  * into the archive; a rebuild moves those packages to a published release
7474
7470
  * anyway.
7475
7471
  */
7472
+ function localLinks(manifestPath) {
7473
+ let manifest;
7474
+ try {
7475
+ manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
7476
+ } catch {
7477
+ return null;
7478
+ }
7479
+ if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) return null;
7480
+ const record = manifest;
7481
+ const links = [];
7482
+ for (const field of DEPENDENCY_FIELDS) {
7483
+ const deps = record[field];
7484
+ if (typeof deps !== "object" || deps === null) continue;
7485
+ for (const [name, spec] of Object.entries(deps)) {
7486
+ if (name.startsWith("@rebasepro/") || typeof spec !== "string") continue;
7487
+ const match = /^(link|file):(.+)$/.exec(spec);
7488
+ if (!match) continue;
7489
+ try {
7490
+ const target = fs.realpathSync(path.resolve(path.dirname(manifestPath), match[2]));
7491
+ if (!fs.statSync(target).isDirectory()) continue;
7492
+ links.push({
7493
+ field,
7494
+ name,
7495
+ protocol: match[1],
7496
+ target
7497
+ });
7498
+ } catch {}
7499
+ }
7500
+ }
7501
+ return {
7502
+ manifest: record,
7503
+ links
7504
+ };
7505
+ }
7506
+ /** Directories outside every unit that a unit's `package.json` files link to with `link:` or `file:`. */
7476
7507
  function externalLinkTargets(units) {
7477
7508
  const targets = /* @__PURE__ */ new Set();
7478
7509
  for (const unit of units) for (const relative of unit.files) {
7479
7510
  if (path.posix.basename(relative) !== "package.json") continue;
7480
- let manifest;
7481
- try {
7482
- manifest = JSON.parse(fs.readFileSync(path.join(unit.root, relative), "utf8"));
7483
- } catch {
7484
- continue;
7485
- }
7486
- if (typeof manifest !== "object" || manifest === null) continue;
7487
- for (const field of DEPENDENCY_FIELDS) {
7488
- const deps = manifest[field];
7489
- if (typeof deps !== "object" || deps === null) continue;
7490
- for (const [name, spec] of Object.entries(deps)) {
7491
- if (name.startsWith("@rebasepro/") || typeof spec !== "string") continue;
7492
- const match = /^(?:link|file):(.+)$/.exec(spec);
7493
- if (!match) continue;
7494
- const target = path.resolve(unit.root, path.posix.dirname(relative), match[1]);
7495
- let real;
7496
- try {
7497
- real = fs.realpathSync(target);
7498
- if (!fs.statSync(real).isDirectory()) continue;
7499
- } catch {
7500
- continue;
7501
- }
7502
- if (!units.some((u) => isWithin(u.root, real))) targets.add(real);
7503
- }
7504
- }
7511
+ for (const link of localLinks(path.join(unit.root, relative))?.links ?? []) if (!units.some((u) => isWithin(u.root, link.target))) targets.add(link.target);
7505
7512
  }
7506
7513
  return [...targets];
7507
7514
  }
@@ -7510,11 +7517,22 @@ function externalLinkTargets(units) {
7510
7517
  *
7511
7518
  * The project's repository first — or the project walked, outside git. Then
7512
7519
  * every repository a local `link:`/`file:` dependency reaches outside it, until
7513
- * nothing new is reached, rooted together at their deepest common directory.
7514
- * That is dadaki's shape: its Rebase project is a repository of its own, nested
7515
- * inside the editor's repository (which ignores it), and its frontend links
7516
- * `../../packages/editor` from there. A listing of the project's repository
7517
- * alone rebuilt into "Rollup failed to resolve import @dadaki/editor".
7520
+ * nothing new is reached. That is dadaki's shape: its Rebase project is a
7521
+ * repository of its own, and its frontend links `../../packages/editor`, a
7522
+ * package of another repository on the same machine. A listing of the
7523
+ * project's repository alone rebuilt into "Rollup failed to resolve import
7524
+ * @dadaki/editor".
7525
+ *
7526
+ * Where those repositories sit on this machine says nothing about where they
7527
+ * sit in the archive. They used to keep their places, under the deepest
7528
+ * directory every one shares — which was `/` for the deploy that ran from a
7529
+ * scratch checkout in `/private/tmp` and reached the editor through a symlink:
7530
+ * the archive carried two absolute trees, and the link, read in the archive,
7531
+ * named nothing, so every platform rebuild failed. So each such repository is
7532
+ * carried inside the project, at `.rebase-linked/<name>/` — below it, where the
7533
+ * rebuild installs every lockfile it finds, the repository's own included — and
7534
+ * every manifest that links into it is pointed there, in the archive's copy
7535
+ * only. Nothing on disk changes.
7518
7536
  *
7519
7537
  * Paths are resolved through `realpath` first: git reports its top level with
7520
7538
  * symlinks resolved (`/private/var/…` for a macOS temp directory), and a
@@ -7528,17 +7546,71 @@ function listSourceFiles(projectRoot, git = runGit) {
7528
7546
  if (units.some((u) => isWithin(u.root, target))) continue;
7529
7547
  units.push(listUnit(target, git));
7530
7548
  }
7531
- const root = commonAncestor(units.map((u) => u.root));
7549
+ const [project, ...linked] = units;
7550
+ const root = project.root;
7551
+ const projectPath = toPosix(path.relative(root, realRoot));
7552
+ if (linked.length === 0) return {
7553
+ root,
7554
+ files: [...project.files].sort(),
7555
+ projectPath,
7556
+ fromGit: project.fromGit
7557
+ };
7558
+ const taken = /* @__PURE__ */ new Set();
7559
+ const placed = units.map((unit, index) => {
7560
+ if (index === 0) return {
7561
+ unit,
7562
+ prefix: ""
7563
+ };
7564
+ const base = path.basename(unit.root) || "linked";
7565
+ let name = base;
7566
+ for (let n = 2; taken.has(name); n++) name = `${base}-${n}`;
7567
+ taken.add(name);
7568
+ return {
7569
+ unit,
7570
+ prefix: [
7571
+ projectPath,
7572
+ LINKED_DIR,
7573
+ name
7574
+ ].filter(Boolean).join("/")
7575
+ };
7576
+ });
7577
+ const archivePathOf = (absolute) => {
7578
+ for (const { unit, prefix } of placed) {
7579
+ if (!isWithin(unit.root, absolute)) continue;
7580
+ return [prefix, toPosix(path.relative(unit.root, absolute))].filter(Boolean).join("/");
7581
+ }
7582
+ };
7532
7583
  const files = /* @__PURE__ */ new Set();
7533
- for (const unit of units) {
7534
- const prefix = toPosix(path.relative(root, unit.root));
7535
- for (const file of unit.files) files.add(prefix ? `${prefix}/${file}` : file);
7584
+ const sources = {};
7585
+ const contents = {};
7586
+ for (const { unit, prefix } of placed) for (const file of unit.files) {
7587
+ const archivePath = prefix ? `${prefix}/${file}` : file;
7588
+ files.add(archivePath);
7589
+ if (prefix) sources[archivePath] = path.join(unit.root, file);
7590
+ if (path.posix.basename(file) !== "package.json") continue;
7591
+ const parsed = localLinks(path.join(unit.root, file));
7592
+ if (!parsed) continue;
7593
+ let changed = false;
7594
+ for (const link of parsed.links) {
7595
+ const targetPath = archivePathOf(link.target);
7596
+ if (targetPath === void 0) continue;
7597
+ const relative = path.posix.relative(path.posix.dirname(archivePath), targetPath) || ".";
7598
+ const spec = `${link.protocol}:${relative.startsWith(".") ? relative : `./${relative}`}`;
7599
+ const deps = parsed.manifest[link.field];
7600
+ if (deps[link.name] !== spec) {
7601
+ deps[link.name] = spec;
7602
+ changed = true;
7603
+ }
7604
+ }
7605
+ if (changed) contents[archivePath] = `${JSON.stringify(parsed.manifest, null, 2)}\n`;
7536
7606
  }
7537
7607
  return {
7538
7608
  root,
7539
7609
  files: [...files].sort(),
7540
- projectPath: toPosix(path.relative(root, realRoot)),
7541
- fromGit: units.every((u) => u.fromGit)
7610
+ projectPath,
7611
+ fromGit: units.every((u) => u.fromGit),
7612
+ sources,
7613
+ contents
7542
7614
  };
7543
7615
  }
7544
7616
  /** The per-directory file of patterns a `--source` build context leaves out, beside `.gitignore`. */
@@ -7589,14 +7661,22 @@ function listContextFiles(dir, git = runGit) {
7589
7661
  function packSource(listing, outPath) {
7590
7662
  const listPath = `${outPath}.files`;
7591
7663
  fs.writeFileSync(listPath, listing.files.map((file) => `${file}\0`).join(""));
7664
+ const stage = listing.sources !== void 0 || listing.contents !== void 0 ? fs.mkdtempSync(`${outPath}.stage-`) : void 0;
7665
+ if (stage) for (const file of listing.files) {
7666
+ const at = path.join(stage, ...file.split("/"));
7667
+ fs.mkdirSync(path.dirname(at), { recursive: true });
7668
+ const content = listing.contents?.[file];
7669
+ if (content !== void 0) fs.writeFileSync(at, content);
7670
+ else fs.symlinkSync(listing.sources?.[file] ?? path.join(listing.root, file), at);
7671
+ }
7592
7672
  return new Promise((resolve, reject) => {
7593
7673
  const child = spawn("tar", [
7594
- "-czf",
7674
+ stage ? "-czhf" : "-czf",
7595
7675
  path.resolve(outPath),
7596
7676
  "--no-xattrs",
7597
7677
  "--null",
7598
7678
  "-C",
7599
- listing.root,
7679
+ stage ?? listing.root,
7600
7680
  "-T",
7601
7681
  path.resolve(listPath)
7602
7682
  ], {
@@ -7614,7 +7694,13 @@ function packSource(listing, outPath) {
7614
7694
  child.stderr.on("data", (chunk) => stderr += String(chunk));
7615
7695
  child.on("error", reject);
7616
7696
  child.on("close", (code) => code === 0 ? resolve() : reject(new Error(stderr.trim() || `tar exited ${code}`)));
7617
- }).finally(() => fs.rmSync(listPath, { force: true }));
7697
+ }).finally(() => {
7698
+ fs.rmSync(listPath, { force: true });
7699
+ if (stage) fs.rmSync(stage, {
7700
+ recursive: true,
7701
+ force: true
7702
+ });
7703
+ });
7618
7704
  }
7619
7705
  /** Upload a source archive; returns the control plane's id for it. */
7620
7706
  async function uploadRebuildSource(url, token, projectId, tarPath) {
@@ -15093,4 +15179,4 @@ function printCloudHelp() {
15093
15179
  //#endregion
15094
15180
  export { CLOUD_GROUP_NAMES, GROUP_ALIASES, cloudCommand };
15095
15181
 
15096
- //# sourceMappingURL=cloud-DWL-lxU_.js.map
15182
+ //# sourceMappingURL=cloud-Cj5ey3l_.js.map