@theholocron/cli 5.8.0 → 5.8.1

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
@@ -34366,6 +34366,20 @@ function scopeVariants(input) {
34366
34366
  return [full, `@${input.scope}/${renamed}`];
34367
34367
  }).sort((a, b) => b[0].length - a[0].length);
34368
34368
  }
34369
+ // src/commands/replace-variants/replace-variants.ts
34370
+ /**
34371
+ * Replace every search string of `variants` in `content` in ONE pass, longest
34372
+ * search string first, so text a replacement wrote is never searched again
34373
+ * (a new name that contains the template's slug is not grown by the next
34374
+ * variant's pass). A search string listed twice keeps its first replacement.
34375
+ */
34376
+ function replaceVariants(content, variants) {
34377
+ const lookup = /* @__PURE__ */ new Map();
34378
+ for (const [search, replacement] of variants) if (search !== "" && !lookup.has(search)) lookup.set(search, replacement);
34379
+ if (lookup.size === 0) return content;
34380
+ const pattern = [...lookup.keys()].sort((a, b) => b.length - a.length).map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
34381
+ return content.replace(new RegExp(pattern, "g"), (match) => lookup.get(match));
34382
+ }
34369
34383
  // src/commands/new/without-tokens/without-tokens.ts
34370
34384
  /** The names of variables that hold a credential for GitHub, this CLI or 1Password. */
34371
34385
  const CREDENTIAL_NAME = /^(HOLOCRON|GITHUB|GH|OP)_.*(TOKEN|SECRET|KEY)$/;
@@ -34672,7 +34686,7 @@ function patchFiles(dir, variants, description, homepage, runtimeEnvironment, pr
34672
34686
  }
34673
34687
  if (isBinary(content)) continue;
34674
34688
  const original = content;
34675
- for (const [search, replacement] of variants) content = content.split(search).join(replacement);
34689
+ content = replaceVariants(content, variants);
34676
34690
  if (description !== void 0) {
34677
34691
  content = content.split("<description>").join(description);
34678
34692
  content = content.replace(/(<!-- holocron:description -->)[\s\S]*?(<!-- \/holocron:description -->)/g, `$1\n${description}\n$2`);