@grekt/cli 6.40.1 → 6.40.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.
Files changed (2) hide show
  1. package/dist/index.js +93 -54
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -102293,14 +102293,40 @@ async function publishArtifact(publisher, ctx) {
102293
102293
 
102294
102294
  // src/workspace/workspace.ts
102295
102295
  var import_fast_glob2 = __toESM(require_out4(), 1);
102296
- import { join as join29 } from "path";
102296
+ import { join as join30 } from "path";
102297
+
102298
+ // src/workspace/file-backup/file-backup.ts
102299
+ import { join as join29, basename as basename12 } from "path";
102300
+ import { randomUUID as randomUUID3 } from "crypto";
102301
+ import { tmpdir as tmpdir4 } from "os";
102302
+ function backupFiles(paths) {
102303
+ const manifest = new Map;
102304
+ for (const filePath of paths) {
102305
+ if (!fs.exists(filePath))
102306
+ continue;
102307
+ const fileId = randomUUID3().slice(0, 8);
102308
+ const backupName = `grekt-bkp-${fileId}-${basename12(filePath)}`;
102309
+ const backupPath = join29(tmpdir4(), backupName);
102310
+ fs.copyFile(filePath, backupPath);
102311
+ manifest.set(filePath, backupPath);
102312
+ }
102313
+ return manifest;
102314
+ }
102315
+ function restoreFiles(manifest) {
102316
+ for (const [originalPath, backupPath] of manifest) {
102317
+ fs.copyFile(backupPath, originalPath);
102318
+ fs.unlink(backupPath);
102319
+ }
102320
+ }
102321
+
102322
+ // src/workspace/workspace.ts
102297
102323
  var WORKSPACE_CONFIG_FILE2 = "grekt-workspace.yaml";
102298
102324
  var ARTIFACT_MANIFEST_FILE2 = "grekt.yaml";
102299
102325
  async function loadWorkspace(cwd) {
102300
102326
  if (!isWorkspaceRoot(fs, cwd)) {
102301
102327
  return null;
102302
102328
  }
102303
- const configPath = join29(cwd, WORKSPACE_CONFIG_FILE2);
102329
+ const configPath = join30(cwd, WORKSPACE_CONFIG_FILE2);
102304
102330
  const configContent = fs.readFile(configPath);
102305
102331
  const result = parseWorkspaceConfig(configContent, configPath);
102306
102332
  if (!result.success) {
@@ -102317,7 +102343,7 @@ async function loadWorkspace(cwd) {
102317
102343
  absolute: true
102318
102344
  });
102319
102345
  for (const fullPath of matches) {
102320
- const manifestPath = join29(fullPath, ARTIFACT_MANIFEST_FILE2);
102346
+ const manifestPath = join30(fullPath, ARTIFACT_MANIFEST_FILE2);
102321
102347
  if (fs.exists(manifestPath)) {
102322
102348
  artifactPaths.push(fullPath);
102323
102349
  }
@@ -102330,26 +102356,27 @@ async function loadWorkspace(cwd) {
102330
102356
  };
102331
102357
  }
102332
102358
  function generateWorkspaceFile(root, artifacts) {
102333
- const workspacePath = join29(root, "pnpm-workspace.yaml");
102334
- const rootPackageJsonPath = join29(root, "package.json");
102359
+ const workspacePath = join30(root, "pnpm-workspace.yaml");
102360
+ const rootPackageJsonPath = join30(root, "package.json");
102335
102361
  const relativePaths = artifacts.map((artifact) => artifact.relativePath);
102336
102362
  fs.writeFile(workspacePath, $stringify2({ packages: relativePaths }));
102337
102363
  fs.writeFile(rootPackageJsonPath, JSON.stringify({ name: "workspace-root", private: true }, null, 2) + `
102338
102364
  `);
102339
102365
  }
102340
- function cleanWorkspaceFile(root) {
102341
- const workspacePath = join29(root, "pnpm-workspace.yaml");
102342
- const rootPackageJsonPath = join29(root, "package.json");
102343
- if (fs.exists(workspacePath)) {
102344
- fs.unlink(workspacePath);
102345
- }
102346
- if (fs.exists(rootPackageJsonPath)) {
102347
- fs.unlink(rootPackageJsonPath);
102366
+ function cleanWorkspaceFile(root, manifest) {
102367
+ const workspacePath = join30(root, "pnpm-workspace.yaml");
102368
+ const rootPackageJsonPath = join30(root, "package.json");
102369
+ for (const filePath of [workspacePath, rootPackageJsonPath]) {
102370
+ if (manifest?.has(filePath)) {
102371
+ restoreFiles(new Map([[filePath, manifest.get(filePath)]]));
102372
+ } else if (fs.exists(filePath)) {
102373
+ fs.unlink(filePath);
102374
+ }
102348
102375
  }
102349
102376
  }
102350
102377
  function generatePackageJsonFiles(artifacts) {
102351
102378
  for (const artifact of artifacts) {
102352
- const packageJsonPath = join29(artifact.path, "package.json");
102379
+ const packageJsonPath = join30(artifact.path, "package.json");
102353
102380
  const packageJson = {
102354
102381
  name: artifact.manifest.name,
102355
102382
  version: artifact.manifest.version,
@@ -102362,8 +102389,8 @@ function generatePackageJsonFiles(artifacts) {
102362
102389
  function syncVersionsToManifest(artifacts) {
102363
102390
  let updated = 0;
102364
102391
  for (const artifact of artifacts) {
102365
- const packageJsonPath = join29(artifact.path, "package.json");
102366
- const manifestPath = join29(artifact.path, ARTIFACT_MANIFEST_FILE2);
102392
+ const packageJsonPath = join30(artifact.path, "package.json");
102393
+ const manifestPath = join30(artifact.path, ARTIFACT_MANIFEST_FILE2);
102367
102394
  if (!fs.exists(packageJsonPath))
102368
102395
  continue;
102369
102396
  const packageJson = JSON.parse(fs.readFile(packageJsonPath));
@@ -102378,10 +102405,12 @@ function syncVersionsToManifest(artifacts) {
102378
102405
  }
102379
102406
  return updated;
102380
102407
  }
102381
- function cleanPackageJsonFiles(artifacts) {
102408
+ function cleanPackageJsonFiles(artifacts, manifest) {
102382
102409
  for (const artifact of artifacts) {
102383
- const packageJsonPath = join29(artifact.path, "package.json");
102384
- if (fs.exists(packageJsonPath)) {
102410
+ const packageJsonPath = join30(artifact.path, "package.json");
102411
+ if (manifest?.has(packageJsonPath)) {
102412
+ restoreFiles(new Map([[packageJsonPath, manifest.get(packageJsonPath)]]));
102413
+ } else if (fs.exists(packageJsonPath)) {
102385
102414
  fs.unlink(packageJsonPath);
102386
102415
  }
102387
102416
  }
@@ -103180,7 +103209,7 @@ function displayUpgradeSummary(results) {
103180
103209
  }
103181
103210
 
103182
103211
  // src/commands/version.ts
103183
- import { join as join30, resolve as resolve7 } from "path";
103212
+ import { join as join31, resolve as resolve7 } from "path";
103184
103213
  import { spawnSync } from "child_process";
103185
103214
  var MANIFEST_FILE = "grekt.yaml";
103186
103215
  var BUMP_TYPES = ["patch", "minor", "major", "prerelease"];
@@ -103233,7 +103262,7 @@ var versionCommand = new Command("version").description("Bump artifact versions
103233
103262
  log("");
103234
103263
  let updated = 0;
103235
103264
  for (const artifactPath of artifactPaths) {
103236
- const manifestPath = join30(artifactPath, MANIFEST_FILE);
103265
+ const manifestPath = join31(artifactPath, MANIFEST_FILE);
103237
103266
  const manifestContent = fs.readFile(manifestPath);
103238
103267
  const result = safeParseYaml(manifestContent, ProjectConfigSchema, manifestPath);
103239
103268
  if (!result.success) {
@@ -103289,6 +103318,12 @@ async function handleExecMode(options2) {
103289
103318
  info(`Would run: ${command}`);
103290
103319
  return;
103291
103320
  }
103321
+ const filesToTouch = [
103322
+ join31(cwd, "pnpm-workspace.yaml"),
103323
+ join31(cwd, "package.json"),
103324
+ ...workspace.artifacts.map((a) => join31(a.path, "package.json"))
103325
+ ];
103326
+ const manifest = backupFiles(filesToTouch);
103292
103327
  const genSpin = spinner("Generating workspace config files...");
103293
103328
  genSpin.start();
103294
103329
  generateWorkspaceFile(cwd, workspace.artifacts);
@@ -103304,8 +103339,8 @@ async function handleExecMode(options2) {
103304
103339
  stdio: "inherit"
103305
103340
  });
103306
103341
  if (result.status !== 0) {
103307
- cleanWorkspaceFile(cwd);
103308
- cleanPackageJsonFiles(workspace.artifacts);
103342
+ cleanWorkspaceFile(cwd, manifest);
103343
+ cleanPackageJsonFiles(workspace.artifacts, manifest);
103309
103344
  error(`Command failed with exit code ${result.status}`);
103310
103345
  process.exit(result.status ?? 1);
103311
103346
  }
@@ -103315,8 +103350,8 @@ async function handleExecMode(options2) {
103315
103350
  const updatedWorkspace = await loadWorkspace(cwd);
103316
103351
  if (!updatedWorkspace) {
103317
103352
  syncSpin.stop();
103318
- cleanWorkspaceFile(cwd);
103319
- cleanPackageJsonFiles(workspace.artifacts);
103353
+ cleanWorkspaceFile(cwd, manifest);
103354
+ cleanPackageJsonFiles(workspace.artifacts, manifest);
103320
103355
  error("Failed to reload workspace");
103321
103356
  process.exit(1);
103322
103357
  }
@@ -103329,8 +103364,8 @@ async function handleExecMode(options2) {
103329
103364
  }
103330
103365
  const cleanSpin = spinner("Cleaning up...");
103331
103366
  cleanSpin.start();
103332
- cleanWorkspaceFile(cwd);
103333
- cleanPackageJsonFiles(workspace.artifacts);
103367
+ cleanWorkspaceFile(cwd, manifest);
103368
+ cleanPackageJsonFiles(workspace.artifacts, manifest);
103334
103369
  cleanSpin.stop();
103335
103370
  success("Removed temporary config files");
103336
103371
  log("");
@@ -103338,7 +103373,7 @@ async function handleExecMode(options2) {
103338
103373
  }
103339
103374
  function findArtifacts(basePath) {
103340
103375
  const artifacts = [];
103341
- if (fs.exists(join30(basePath, MANIFEST_FILE))) {
103376
+ if (fs.exists(join31(basePath, MANIFEST_FILE))) {
103342
103377
  artifacts.push(basePath);
103343
103378
  return artifacts;
103344
103379
  }
@@ -103347,9 +103382,9 @@ function findArtifacts(basePath) {
103347
103382
  for (const entry of entries) {
103348
103383
  if (entry.startsWith("."))
103349
103384
  continue;
103350
- const subPath = join30(basePath, entry);
103385
+ const subPath = join31(basePath, entry);
103351
103386
  const stat = fs.stat(subPath);
103352
- if (stat.isDirectory && fs.exists(join30(subPath, MANIFEST_FILE))) {
103387
+ if (stat.isDirectory && fs.exists(join31(subPath, MANIFEST_FILE))) {
103353
103388
  artifacts.push(subPath);
103354
103389
  }
103355
103390
  }
@@ -103492,19 +103527,23 @@ function mapFilesToArtifacts(changedFiles, artifacts) {
103492
103527
  }
103493
103528
 
103494
103529
  // src/commands/changelog/changeset-output.ts
103495
- import { join as join31 } from "path";
103530
+ import { join as join32 } from "path";
103496
103531
  import { randomBytes as randomBytes3 } from "crypto";
103497
103532
  var CHANGESET_DIR = ".changeset";
103498
- function generateChangesetFile(artifacts, workspaceRoot) {
103499
- const changesetDir = join31(workspaceRoot, CHANGESET_DIR);
103533
+ function generateChangesetFiles(artifacts, workspaceRoot) {
103534
+ const changesetDir = join32(workspaceRoot, CHANGESET_DIR);
103500
103535
  if (!fs.exists(changesetDir)) {
103501
103536
  fs.mkdir(changesetDir, { recursive: true });
103502
103537
  }
103503
- const filename = `${randomBytes3(4).toString("hex")}.md`;
103504
- const filepath = join31(changesetDir, filename);
103505
- const content = buildChangesetContent(artifacts);
103506
- fs.writeFile(filepath, content);
103507
- return filepath;
103538
+ const paths = [];
103539
+ for (const artifact of artifacts) {
103540
+ const filename = `${randomBytes3(4).toString("hex")}.md`;
103541
+ const filepath = join32(changesetDir, filename);
103542
+ const content = buildChangesetContent([artifact]);
103543
+ fs.writeFile(filepath, content);
103544
+ paths.push(filepath);
103545
+ }
103546
+ return paths;
103508
103547
  }
103509
103548
  function buildChangesetContent(artifacts) {
103510
103549
  const frontmatterLines = [];
@@ -103690,9 +103729,9 @@ function outputResult(artifactChangelogs, baseRef, cwd, options2) {
103690
103729
  log(previewChangesetContent(artifactChangelogs));
103691
103730
  return;
103692
103731
  }
103693
- const filepath = generateChangesetFile(artifactChangelogs, cwd);
103732
+ const paths = generateChangesetFiles(artifactChangelogs, cwd);
103694
103733
  newline();
103695
- success(`Changeset written to ${filepath}`);
103734
+ success(`Generated ${paths.length} changeset file(s)`);
103696
103735
  }
103697
103736
  // src/commands/workspace/workspace.ts
103698
103737
  var listSubcommand = new Command("list").description("List all artifacts in the workspace").action(async () => {
@@ -103717,7 +103756,7 @@ var listSubcommand = new Command("list").description("List all artifacts in the
103717
103756
  });
103718
103757
  var workspaceCommand = new Command("workspace").description("Manage monorepo workspaces").addCommand(listSubcommand);
103719
103758
  // src/commands/worktree/worktree.ts
103720
- import { join as join32, dirname as dirname11, isAbsolute as isAbsolute4 } from "path";
103759
+ import { join as join33, dirname as dirname11, isAbsolute as isAbsolute4 } from "path";
103721
103760
  var GREKT_DIR2 = ".grekt";
103722
103761
  function getGitCommonDir() {
103723
103762
  try {
@@ -103734,7 +103773,7 @@ function getWorktreeRoot() {
103734
103773
  }
103735
103774
  }
103736
103775
  function resolveOriginalRepoRoot(commonDir, worktreeRoot) {
103737
- const absoluteCommonDir = isAbsolute4(commonDir) ? commonDir : join32(worktreeRoot, commonDir);
103776
+ const absoluteCommonDir = isAbsolute4(commonDir) ? commonDir : join33(worktreeRoot, commonDir);
103738
103777
  return dirname11(absoluteCommonDir);
103739
103778
  }
103740
103779
  function isInsideWorktree(commonDir) {
@@ -103757,8 +103796,8 @@ var syncSubcommand = new Command("sync").description("Copy .grekt/ from the orig
103757
103796
  process.exit(1);
103758
103797
  }
103759
103798
  const originalRepoRoot = resolveOriginalRepoRoot(commonDir, worktreeRoot);
103760
- const sourcePath = join32(originalRepoRoot, GREKT_DIR2);
103761
- const destPath = join32(worktreeRoot, GREKT_DIR2);
103799
+ const sourcePath = join33(originalRepoRoot, GREKT_DIR2);
103800
+ const destPath = join33(worktreeRoot, GREKT_DIR2);
103762
103801
  if (!fs.exists(sourcePath)) {
103763
103802
  info("No .grekt/ directory found in the original repository");
103764
103803
  process.exit(0);
@@ -103781,7 +103820,7 @@ var syncSubcommand = new Command("sync").description("Copy .grekt/ from the orig
103781
103820
  });
103782
103821
  var worktreeCommand = new Command("worktree").description("Manage git worktree integration").addCommand(syncSubcommand);
103783
103822
  // src/commands/scan.ts
103784
- import { join as join33, resolve as resolve8 } from "path";
103823
+ import { join as join34, resolve as resolve8 } from "path";
103785
103824
  var VALID_BADGES = ["certified", "conditional", "suspicious", "rejected"];
103786
103825
  var BADGE_COLORS = {
103787
103826
  certified: colors5.success,
@@ -103877,7 +103916,7 @@ var scanCommand = new Command("scan").description("Scan artifacts for security i
103877
103916
  });
103878
103917
  async function scanRemoteArtifact(source, projectRoot, jsonOutput, failOnThreshold) {
103879
103918
  const displayName = getSourceDisplayName(source);
103880
- const tempDir = join33(projectRoot, ARTIFACTS_DIR, `.tmp-scan-${cryptoProvider.randomUUID()}`);
103919
+ const tempDir = join34(projectRoot, ARTIFACTS_DIR, `.tmp-scan-${cryptoProvider.randomUUID()}`);
103881
103920
  try {
103882
103921
  if (!jsonOutput) {
103883
103922
  const spin = spinner(`Downloading ${colors5.highlight(displayName)}...`);
@@ -104003,14 +104042,14 @@ async function scanAllInstalled(projectRoot, jsonOutput, failOnThreshold) {
104003
104042
  }
104004
104043
  const config = getConfig(projectRoot);
104005
104044
  const trustKey = process.env.GREKT_TRUST_KEY;
104006
- const artifactsDir = join33(projectRoot, ARTIFACTS_DIR);
104045
+ const artifactsDir = join34(projectRoot, ARTIFACTS_DIR);
104007
104046
  const results = [];
104008
104047
  const errors4 = [];
104009
104048
  if (!jsonOutput) {
104010
104049
  log(`Scanning ${colors5.bold(String(artifactIds.length))} artifact${artifactIds.length === 1 ? "" : "s"}...`);
104011
104050
  }
104012
104051
  for (const artifactId of artifactIds) {
104013
- const artifactDir = join33(artifactsDir, artifactId);
104052
+ const artifactDir = join34(artifactsDir, artifactId);
104014
104053
  if (!fs.exists(artifactDir)) {
104015
104054
  errors4.push({ artifactId, message: "Not installed (directory missing)" });
104016
104055
  continue;
@@ -104135,7 +104174,7 @@ var untrustCommand = new Command("untrust").description("Remove trusted status f
104135
104174
 
104136
104175
  // src/auth/oauth/oauth.ts
104137
104176
  import { spawn } from "child_process";
104138
- import { randomUUID as randomUUID3 } from "crypto";
104177
+ import { randomUUID as randomUUID4 } from "crypto";
104139
104178
  var LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
104140
104179
  var POLL_INTERVAL_MS = 2000;
104141
104180
  function openBrowser(url) {
@@ -104190,7 +104229,7 @@ function sleep(ms) {
104190
104229
  async function browserLogin(provider, callbacks) {
104191
104230
  const supabase = getSupabaseClient();
104192
104231
  const supabaseUrl = getSupabaseUrl();
104193
- const sessionId = randomUUID3();
104232
+ const sessionId = randomUUID4();
104194
104233
  const redirectTo = `${supabaseUrl}/functions/v1/cli-auth-callback?session_id=${sessionId}`;
104195
104234
  const { data, error: oauthError } = await supabase.auth.signInWithOAuth({
104196
104235
  provider,
@@ -104358,7 +104397,7 @@ var whoamiCommand = new Command("whoami").description("Show current user").actio
104358
104397
  // package.json
104359
104398
  var package_default = {
104360
104399
  name: "@grekt/cli",
104361
- version: "6.40.1",
104400
+ version: "6.40.3",
104362
104401
  description: "AI tools versioned, synced, and shared across tools and teams",
104363
104402
  type: "module",
104364
104403
  bin: {
@@ -104427,13 +104466,13 @@ var package_default = {
104427
104466
  // src/update-check/update-check.ts
104428
104467
  import { existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
104429
104468
  import { homedir as homedir3 } from "os";
104430
- import { join as join34 } from "path";
104469
+ import { join as join35 } from "path";
104431
104470
  var CACHE_FILENAME = ".update-check";
104432
104471
  var STALENESS_MS = 24 * 60 * 60 * 1000;
104433
104472
  var FETCH_TIMEOUT_MS = 1500;
104434
104473
  var GITHUB_RELEASES_URL = "https://api.github.com/repos/grekt-labs/cli/releases/latest";
104435
104474
  function getCachePath() {
104436
- return join34(homedir3(), ".grekt", CACHE_FILENAME);
104475
+ return join35(homedir3(), ".grekt", CACHE_FILENAME);
104437
104476
  }
104438
104477
  function isOptedOut() {
104439
104478
  return process.env.GREKT_NO_UPDATE_CHECK === "1";
@@ -104452,7 +104491,7 @@ function readCache() {
104452
104491
  }
104453
104492
  function writeCache(cache2) {
104454
104493
  try {
104455
- const dir = join34(homedir3(), ".grekt");
104494
+ const dir = join35(homedir3(), ".grekt");
104456
104495
  if (!existsSync2(dir)) {
104457
104496
  mkdirSync3(dir, { recursive: true });
104458
104497
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grekt/cli",
3
- "version": "6.40.1",
3
+ "version": "6.40.3",
4
4
  "description": "AI tools versioned, synced, and shared across tools and teams",
5
5
  "type": "module",
6
6
  "bin": {