@theholocron/cli 5.0.0-alpha.168 → 5.0.0-alpha.169

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/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSyn
4
4
  import { homedir, hostname, tmpdir, userInfo } from "node:os";
5
5
  import path, { basename, dirname, join, relative, resolve, sep } from "node:path";
6
6
  import { checkbox, confirm, input, select } from "@inquirer/prompts";
7
- import { KNOWN_WORKFLOWS, createAlexignore, createAlexrc, createAstromech, createCommitMsg, createDependabot, createDevmoji, createEditorconfig, createEditorconfigChecker, createHeader, createLabeler, createPreCommit, createPrePush, createPrepareCommitMsg, createYamlignore, createYamllint, deployOnRelease, extractPreviewConfig, readWorkspacePackages, reusableTemplates } from "@theholocron/astromech";
7
+ import { KNOWN_WORKFLOWS, createAlexignore, createAlexrc, createAstromech, createCommitMsg, createDependabot, createDevmoji, createEditorconfig, createEditorconfigChecker, createHeader, createLabeler, createPreCommit, createPrePush, createPrepareCommitMsg, createYamlignore, createYamllint, defaultListDirs, defaultPaths, defaultReadJson, deployOnRelease, extractPreviewConfig, readWorkspacePackages, reusableTemplates, workspacePackages } from "@theholocron/astromech";
8
8
  import { loadTasksConfig } from "@theholocron/astromech/config";
9
9
  import { lintCommitMsgFile } from "@theholocron/astromech/lint";
10
10
  import { LOG_LEVELS, NoopAnalyticsSink, NoopErrorSink, redactObject } from "@theholocron/observability/core";
@@ -5217,6 +5217,62 @@ const STALE_LABELS = [
5217
5217
  //#region src/templates/dco.yml
5218
5218
  var dco_default = "allowRemediationCommits:\n individual: true\n";
5219
5219
  //#endregion
5220
+ //#region src/commands/preview-deploy-paths/preview-deploy-paths.ts
5221
+ /** `realpathSync`, falling back to the unresolved input on a path that doesn't exist (e.g. a test fixture). */
5222
+ function tryRealpath(path) {
5223
+ try {
5224
+ return realpathSync(path);
5225
+ } catch {
5226
+ return path;
5227
+ }
5228
+ }
5229
+ /**
5230
+ * `delivery.previewDeploy`'s package directory plus its `workspace:*`
5231
+ * dependencies' directories (holocron#1023) — the reusable workflow's
5232
+ * `paths` input, so a PR touching only an unrelated package in the
5233
+ * monorepo skips the actual deploy work instead of spinning up a Vercel
5234
+ * preview for every PR regardless of relevance. `undefined` for a
5235
+ * root-level consumer (`cwd: "."` or omitted) -- every PR already IS a PR
5236
+ * to that package, no filter needed -- or when `cwd` doesn't resolve to
5237
+ * any known workspace package (soft-skip; the caller leaves `paths`
5238
+ * unset rather than guessing).
5239
+ */
5240
+ function resolvePreviewDeployPaths(gitRoot, cwdValue) {
5241
+ if (!cwdValue || cwdValue === ".") return void 0;
5242
+ const all = workspacePackages(gitRoot, {
5243
+ readJson: defaultReadJson,
5244
+ listDirs: defaultListDirs
5245
+ });
5246
+ const target = tryRealpath(resolve(gitRoot, cwdValue));
5247
+ const pkg = all.find((candidate) => tryRealpath(candidate.dir) === target);
5248
+ if (!pkg) return void 0;
5249
+ return defaultPaths(gitRoot, pkg, all);
5250
+ }
5251
+ /**
5252
+ * Returns `tasks` unchanged unless it has a `delivery.previewDeploy` entry
5253
+ * with a non-root `with.cwd` and no `with.paths` of its own -- in which
5254
+ * case that one entry gets an auto-computed `paths` (see
5255
+ * {@link resolvePreviewDeployPaths}), added without mutating the input.
5256
+ * An explicit `with.paths` from the repo's own config always wins; this
5257
+ * only fills in what the repo didn't already specify.
5258
+ */
5259
+ function withAutoPreviewDeployPaths(tasks, gitRoot) {
5260
+ return tasks.map((entry) => {
5261
+ if (typeof entry === "string" || entry.name !== "delivery.previewDeploy") return entry;
5262
+ const cwdValue = entry.with?.["cwd"];
5263
+ if (typeof cwdValue !== "string" || entry.with?.["paths"] !== void 0) return entry;
5264
+ const paths = resolvePreviewDeployPaths(gitRoot, cwdValue);
5265
+ if (!paths) return entry;
5266
+ return {
5267
+ ...entry,
5268
+ with: {
5269
+ ...entry.with,
5270
+ paths
5271
+ }
5272
+ };
5273
+ });
5274
+ }
5275
+ //#endregion
5220
5276
  //#region src/commands/workflow-source-marker/workflow-source-marker.ts
5221
5277
  /** `# Source package: <path>` line at the head of a generated thin-caller workflow — see {@link resolvePkgRelPath}. */
5222
5278
  const SOURCE_PACKAGE_MARKER = /^# Source package: (.+)$/m;
@@ -6105,10 +6161,11 @@ async function runSetup(input) {
6105
6161
  const steps = [];
6106
6162
  const repo = config.repo;
6107
6163
  const effectivePreset = repo?.protection;
6108
- const setupPkgRelPath = resolvePkgRelPath(findRootSync(input.context.repoRoot, ".git", {
6164
+ const setupGitRoot = findRootSync(input.context.repoRoot, ".git", {
6109
6165
  fallback: "start",
6110
6166
  realpath: true
6111
- }), input.loaded.filepath);
6167
+ });
6168
+ const setupPkgRelPath = resolvePkgRelPath(setupGitRoot, input.loaded.filepath);
6112
6169
  const hooksEnabled = input.hooks ?? (typeof config.hooks === "boolean" ? config.hooks : typeof config.hooks === "object" ? config.hooks.prePush !== false : effectivePreset === "strict");
6113
6170
  print(style.header(`Holocron setup — ${config.name}${dryRun ? " (dry-run)" : ""}`));
6114
6171
  print(style.dim(` config: ${input.loaded.filepath}`));
@@ -6157,7 +6214,7 @@ async function runSetup(input) {
6157
6214
  print(formatStep(steps[steps.length - 1]));
6158
6215
  }
6159
6216
  }
6160
- const tasks = config.tasks;
6217
+ const tasks = config.tasks && config.tasks.length > 0 ? withAutoPreviewDeployPaths(config.tasks, setupGitRoot) : config.tasks;
6161
6218
  if (loader.has("source") && tasks && tasks.length > 0) {
6162
6219
  const source = loader.get("source");
6163
6220
  print(style.step("workflows"));
@@ -7532,7 +7589,8 @@ async function runSync(input) {
7532
7589
  print(formatSyncStep(steps[steps.length - 1]));
7533
7590
  }
7534
7591
  if (stepName === "workflows") {
7535
- const taskEntries = config.tasks ?? [];
7592
+ const rawTaskEntries = config.tasks ?? [];
7593
+ const taskEntries = rawTaskEntries.length === 0 ? rawTaskEntries : withAutoPreviewDeployPaths(rawTaskEntries, gitRoot);
7536
7594
  if (taskEntries.length === 0) {
7537
7595
  steps.push({
7538
7596
  capability: "local",
@@ -7544,7 +7602,7 @@ async function runSync(input) {
7544
7602
  } else {
7545
7603
  const files = createAstromech({
7546
7604
  cwd: input.context.repoRoot,
7547
- config: { tasks: config.tasks },
7605
+ config: { tasks: taskEntries },
7548
7606
  orgContext: {
7549
7607
  org: config.org,
7550
7608
  domain: config.domain