@grekt/cli 6.40.2 → 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.
- package/dist/index.js +82 -47
- 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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
102334
|
-
const rootPackageJsonPath =
|
|
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 =
|
|
102342
|
-
const rootPackageJsonPath =
|
|
102343
|
-
|
|
102344
|
-
|
|
102345
|
-
|
|
102346
|
-
|
|
102347
|
-
|
|
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 =
|
|
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 =
|
|
102366
|
-
const manifestPath =
|
|
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 =
|
|
102384
|
-
if (
|
|
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
|
|
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 =
|
|
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(
|
|
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 =
|
|
103385
|
+
const subPath = join31(basePath, entry);
|
|
103351
103386
|
const stat = fs.stat(subPath);
|
|
103352
|
-
if (stat.isDirectory && fs.exists(
|
|
103387
|
+
if (stat.isDirectory && fs.exists(join31(subPath, MANIFEST_FILE))) {
|
|
103353
103388
|
artifacts.push(subPath);
|
|
103354
103389
|
}
|
|
103355
103390
|
}
|
|
@@ -103492,18 +103527,18 @@ function mapFilesToArtifacts(changedFiles, artifacts) {
|
|
|
103492
103527
|
}
|
|
103493
103528
|
|
|
103494
103529
|
// src/commands/changelog/changeset-output.ts
|
|
103495
|
-
import { join as
|
|
103530
|
+
import { join as join32 } from "path";
|
|
103496
103531
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
103497
103532
|
var CHANGESET_DIR = ".changeset";
|
|
103498
103533
|
function generateChangesetFiles(artifacts, workspaceRoot) {
|
|
103499
|
-
const changesetDir =
|
|
103534
|
+
const changesetDir = join32(workspaceRoot, CHANGESET_DIR);
|
|
103500
103535
|
if (!fs.exists(changesetDir)) {
|
|
103501
103536
|
fs.mkdir(changesetDir, { recursive: true });
|
|
103502
103537
|
}
|
|
103503
103538
|
const paths = [];
|
|
103504
103539
|
for (const artifact of artifacts) {
|
|
103505
103540
|
const filename = `${randomBytes3(4).toString("hex")}.md`;
|
|
103506
|
-
const filepath =
|
|
103541
|
+
const filepath = join32(changesetDir, filename);
|
|
103507
103542
|
const content = buildChangesetContent([artifact]);
|
|
103508
103543
|
fs.writeFile(filepath, content);
|
|
103509
103544
|
paths.push(filepath);
|
|
@@ -103721,7 +103756,7 @@ var listSubcommand = new Command("list").description("List all artifacts in the
|
|
|
103721
103756
|
});
|
|
103722
103757
|
var workspaceCommand = new Command("workspace").description("Manage monorepo workspaces").addCommand(listSubcommand);
|
|
103723
103758
|
// src/commands/worktree/worktree.ts
|
|
103724
|
-
import { join as
|
|
103759
|
+
import { join as join33, dirname as dirname11, isAbsolute as isAbsolute4 } from "path";
|
|
103725
103760
|
var GREKT_DIR2 = ".grekt";
|
|
103726
103761
|
function getGitCommonDir() {
|
|
103727
103762
|
try {
|
|
@@ -103738,7 +103773,7 @@ function getWorktreeRoot() {
|
|
|
103738
103773
|
}
|
|
103739
103774
|
}
|
|
103740
103775
|
function resolveOriginalRepoRoot(commonDir, worktreeRoot) {
|
|
103741
|
-
const absoluteCommonDir = isAbsolute4(commonDir) ? commonDir :
|
|
103776
|
+
const absoluteCommonDir = isAbsolute4(commonDir) ? commonDir : join33(worktreeRoot, commonDir);
|
|
103742
103777
|
return dirname11(absoluteCommonDir);
|
|
103743
103778
|
}
|
|
103744
103779
|
function isInsideWorktree(commonDir) {
|
|
@@ -103761,8 +103796,8 @@ var syncSubcommand = new Command("sync").description("Copy .grekt/ from the orig
|
|
|
103761
103796
|
process.exit(1);
|
|
103762
103797
|
}
|
|
103763
103798
|
const originalRepoRoot = resolveOriginalRepoRoot(commonDir, worktreeRoot);
|
|
103764
|
-
const sourcePath =
|
|
103765
|
-
const destPath =
|
|
103799
|
+
const sourcePath = join33(originalRepoRoot, GREKT_DIR2);
|
|
103800
|
+
const destPath = join33(worktreeRoot, GREKT_DIR2);
|
|
103766
103801
|
if (!fs.exists(sourcePath)) {
|
|
103767
103802
|
info("No .grekt/ directory found in the original repository");
|
|
103768
103803
|
process.exit(0);
|
|
@@ -103785,7 +103820,7 @@ var syncSubcommand = new Command("sync").description("Copy .grekt/ from the orig
|
|
|
103785
103820
|
});
|
|
103786
103821
|
var worktreeCommand = new Command("worktree").description("Manage git worktree integration").addCommand(syncSubcommand);
|
|
103787
103822
|
// src/commands/scan.ts
|
|
103788
|
-
import { join as
|
|
103823
|
+
import { join as join34, resolve as resolve8 } from "path";
|
|
103789
103824
|
var VALID_BADGES = ["certified", "conditional", "suspicious", "rejected"];
|
|
103790
103825
|
var BADGE_COLORS = {
|
|
103791
103826
|
certified: colors5.success,
|
|
@@ -103881,7 +103916,7 @@ var scanCommand = new Command("scan").description("Scan artifacts for security i
|
|
|
103881
103916
|
});
|
|
103882
103917
|
async function scanRemoteArtifact(source, projectRoot, jsonOutput, failOnThreshold) {
|
|
103883
103918
|
const displayName = getSourceDisplayName(source);
|
|
103884
|
-
const tempDir =
|
|
103919
|
+
const tempDir = join34(projectRoot, ARTIFACTS_DIR, `.tmp-scan-${cryptoProvider.randomUUID()}`);
|
|
103885
103920
|
try {
|
|
103886
103921
|
if (!jsonOutput) {
|
|
103887
103922
|
const spin = spinner(`Downloading ${colors5.highlight(displayName)}...`);
|
|
@@ -104007,14 +104042,14 @@ async function scanAllInstalled(projectRoot, jsonOutput, failOnThreshold) {
|
|
|
104007
104042
|
}
|
|
104008
104043
|
const config = getConfig(projectRoot);
|
|
104009
104044
|
const trustKey = process.env.GREKT_TRUST_KEY;
|
|
104010
|
-
const artifactsDir =
|
|
104045
|
+
const artifactsDir = join34(projectRoot, ARTIFACTS_DIR);
|
|
104011
104046
|
const results = [];
|
|
104012
104047
|
const errors4 = [];
|
|
104013
104048
|
if (!jsonOutput) {
|
|
104014
104049
|
log(`Scanning ${colors5.bold(String(artifactIds.length))} artifact${artifactIds.length === 1 ? "" : "s"}...`);
|
|
104015
104050
|
}
|
|
104016
104051
|
for (const artifactId of artifactIds) {
|
|
104017
|
-
const artifactDir =
|
|
104052
|
+
const artifactDir = join34(artifactsDir, artifactId);
|
|
104018
104053
|
if (!fs.exists(artifactDir)) {
|
|
104019
104054
|
errors4.push({ artifactId, message: "Not installed (directory missing)" });
|
|
104020
104055
|
continue;
|
|
@@ -104139,7 +104174,7 @@ var untrustCommand = new Command("untrust").description("Remove trusted status f
|
|
|
104139
104174
|
|
|
104140
104175
|
// src/auth/oauth/oauth.ts
|
|
104141
104176
|
import { spawn } from "child_process";
|
|
104142
|
-
import { randomUUID as
|
|
104177
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
104143
104178
|
var LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
|
|
104144
104179
|
var POLL_INTERVAL_MS = 2000;
|
|
104145
104180
|
function openBrowser(url) {
|
|
@@ -104194,7 +104229,7 @@ function sleep(ms) {
|
|
|
104194
104229
|
async function browserLogin(provider, callbacks) {
|
|
104195
104230
|
const supabase = getSupabaseClient();
|
|
104196
104231
|
const supabaseUrl = getSupabaseUrl();
|
|
104197
|
-
const sessionId =
|
|
104232
|
+
const sessionId = randomUUID4();
|
|
104198
104233
|
const redirectTo = `${supabaseUrl}/functions/v1/cli-auth-callback?session_id=${sessionId}`;
|
|
104199
104234
|
const { data, error: oauthError } = await supabase.auth.signInWithOAuth({
|
|
104200
104235
|
provider,
|
|
@@ -104362,7 +104397,7 @@ var whoamiCommand = new Command("whoami").description("Show current user").actio
|
|
|
104362
104397
|
// package.json
|
|
104363
104398
|
var package_default = {
|
|
104364
104399
|
name: "@grekt/cli",
|
|
104365
|
-
version: "6.40.
|
|
104400
|
+
version: "6.40.3",
|
|
104366
104401
|
description: "AI tools versioned, synced, and shared across tools and teams",
|
|
104367
104402
|
type: "module",
|
|
104368
104403
|
bin: {
|
|
@@ -104431,13 +104466,13 @@ var package_default = {
|
|
|
104431
104466
|
// src/update-check/update-check.ts
|
|
104432
104467
|
import { existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
104433
104468
|
import { homedir as homedir3 } from "os";
|
|
104434
|
-
import { join as
|
|
104469
|
+
import { join as join35 } from "path";
|
|
104435
104470
|
var CACHE_FILENAME = ".update-check";
|
|
104436
104471
|
var STALENESS_MS = 24 * 60 * 60 * 1000;
|
|
104437
104472
|
var FETCH_TIMEOUT_MS = 1500;
|
|
104438
104473
|
var GITHUB_RELEASES_URL = "https://api.github.com/repos/grekt-labs/cli/releases/latest";
|
|
104439
104474
|
function getCachePath() {
|
|
104440
|
-
return
|
|
104475
|
+
return join35(homedir3(), ".grekt", CACHE_FILENAME);
|
|
104441
104476
|
}
|
|
104442
104477
|
function isOptedOut() {
|
|
104443
104478
|
return process.env.GREKT_NO_UPDATE_CHECK === "1";
|
|
@@ -104456,7 +104491,7 @@ function readCache() {
|
|
|
104456
104491
|
}
|
|
104457
104492
|
function writeCache(cache2) {
|
|
104458
104493
|
try {
|
|
104459
|
-
const dir =
|
|
104494
|
+
const dir = join35(homedir3(), ".grekt");
|
|
104460
104495
|
if (!existsSync2(dir)) {
|
|
104461
104496
|
mkdirSync3(dir, { recursive: true });
|
|
104462
104497
|
}
|