@inteeka/task-cli 0.2.2 → 0.2.4

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.js CHANGED
@@ -4050,9 +4050,13 @@ function registerConfig(program2) {
4050
4050
 
4051
4051
  // src/commands/doctor.ts
4052
4052
  import { execFileSync as execFileSync10 } from "child_process";
4053
+ import { readFile as readFile8, writeFile as writeFile10 } from "fs/promises";
4054
+ import { join as join11 } from "path";
4053
4055
  import { request as request5 } from "undici";
4056
+ var ALLOWED_TEST_EXECUTABLES = /* @__PURE__ */ new Set(["pnpm", "npm", "yarn", "bun", "node", "npx"]);
4057
+ var DEFAULT_TEST_COMMAND = "pnpm typecheck";
4054
4058
  function registerDoctor(program2) {
4055
- program2.command("doctor").description("Diagnose your CLI setup").action(async () => {
4059
+ program2.command("doctor").description("Diagnose your CLI setup").option("--fix", "attempt to auto-remediate fixable problems (e.g. add a typecheck script)").action(async (opts) => {
4056
4060
  const checks = [];
4057
4061
  const creds = await readCredentials();
4058
4062
  checks.push({
@@ -4109,16 +4113,122 @@ function registerDoctor(program2) {
4109
4113
  } catch {
4110
4114
  checks.push({ name: "working tree", ok: false, detail: "not in a git repo" });
4111
4115
  }
4116
+ const testCheck = await checkPrePushTest(
4117
+ root,
4118
+ project?.cli_test_command ?? null,
4119
+ opts.fix === true
4120
+ );
4121
+ checks.push(testCheck);
4112
4122
  let allOk = true;
4113
4123
  for (const check of checks) {
4114
4124
  const sym = check.ok ? c.ok("\u2713") : c.err("\u2717");
4115
4125
  process.stdout.write(`${sym} ${check.name.padEnd(16)} ${c.dim(check.detail)}
4116
4126
  `);
4117
- if (!check.ok) allOk = false;
4127
+ if (!check.ok) {
4128
+ allOk = false;
4129
+ if (check.remediation) {
4130
+ process.stdout.write(` ${c.dim("\u2192 " + check.remediation)}
4131
+ `);
4132
+ }
4133
+ }
4118
4134
  }
4119
4135
  if (!allOk) process.exit(1);
4120
4136
  });
4121
4137
  }
4138
+ async function checkPrePushTest(root, configuredCommand, fix) {
4139
+ const command = configuredCommand && configuredCommand.trim().length > 0 ? configuredCommand.trim() : DEFAULT_TEST_COMMAND;
4140
+ const argv = command.split(/\s+/).filter((s) => s.length > 0);
4141
+ const exe = argv[0];
4142
+ if (!exe || !ALLOWED_TEST_EXECUTABLES.has(exe)) {
4143
+ return {
4144
+ name: "pre-push test",
4145
+ ok: false,
4146
+ detail: `command "${command}" not allowlisted (allowed: ${[...ALLOWED_TEST_EXECUTABLES].join(", ")})`,
4147
+ remediation: "update projects.cli_test_command via the dashboard"
4148
+ };
4149
+ }
4150
+ const scriptName = resolveScriptName(argv);
4151
+ if (!scriptName) {
4152
+ return {
4153
+ name: "pre-push test",
4154
+ ok: true,
4155
+ detail: `${command} (non-script executable, not statically verifiable)`
4156
+ };
4157
+ }
4158
+ const pkgPath = join11(root, "package.json");
4159
+ let pkgRaw;
4160
+ try {
4161
+ pkgRaw = await readFile8(pkgPath, "utf8");
4162
+ } catch {
4163
+ return {
4164
+ name: "pre-push test",
4165
+ ok: false,
4166
+ detail: `no package.json at repo root for "${command}"`,
4167
+ remediation: `add a package.json with a "${scriptName}" script, or set projects.cli_test_command in the dashboard`
4168
+ };
4169
+ }
4170
+ let pkg;
4171
+ try {
4172
+ pkg = JSON.parse(pkgRaw);
4173
+ } catch (err) {
4174
+ return {
4175
+ name: "pre-push test",
4176
+ ok: false,
4177
+ detail: `package.json is invalid JSON: ${err.message}`
4178
+ };
4179
+ }
4180
+ const scripts = pkg.scripts ?? {};
4181
+ if (typeof scripts[scriptName] === "string" && scripts[scriptName].trim().length > 0) {
4182
+ return {
4183
+ name: "pre-push test",
4184
+ ok: true,
4185
+ detail: `${command} \u2192 "${scripts[scriptName]}"`
4186
+ };
4187
+ }
4188
+ const isDefaultTypecheck = command === DEFAULT_TEST_COMMAND && scriptName === "typecheck";
4189
+ const hasTypeScript = !!pkg.devDependencies?.typescript || !!pkg.dependencies?.typescript;
4190
+ if (fix && isDefaultTypecheck && hasTypeScript) {
4191
+ pkg.scripts = { ...scripts, typecheck: "tsc --noEmit" };
4192
+ const indent = detectIndent(pkgRaw);
4193
+ const trailingNewline = pkgRaw.endsWith("\n") ? "\n" : "";
4194
+ await writeFile10(pkgPath, JSON.stringify(pkg, null, indent) + trailingNewline);
4195
+ return {
4196
+ name: "pre-push test",
4197
+ ok: true,
4198
+ detail: `added "typecheck": "tsc --noEmit" to ${pkgPath}`
4199
+ };
4200
+ }
4201
+ const remediation = isDefaultTypecheck ? hasTypeScript ? 're-run with --fix to add "typecheck": "tsc --noEmit" to package.json' : 'add a "typecheck" script to package.json, or set a different cli_test_command in the dashboard' : `add a "${scriptName}" script to package.json, or update cli_test_command in the dashboard`;
4202
+ return {
4203
+ name: "pre-push test",
4204
+ ok: false,
4205
+ detail: `"${scriptName}" script missing \u2014 "${command}" will exit 254 (ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL)`,
4206
+ remediation
4207
+ };
4208
+ }
4209
+ function resolveScriptName(argv) {
4210
+ const [exe, ...rest] = argv;
4211
+ if (!exe || rest.length === 0) return null;
4212
+ if (exe === "pnpm" || exe === "yarn" || exe === "bun") {
4213
+ const next = rest[0];
4214
+ if (!next) return null;
4215
+ if (next === "run") return rest[1] ?? null;
4216
+ if (next.startsWith("-")) return null;
4217
+ return next;
4218
+ }
4219
+ if (exe === "npm") {
4220
+ if (rest[0] === "run" || rest[0] === "run-script") return rest[1] ?? null;
4221
+ return null;
4222
+ }
4223
+ return null;
4224
+ }
4225
+ function detectIndent(raw) {
4226
+ const match = raw.match(/^(\s+)"/m);
4227
+ if (!match) return 2;
4228
+ const ws = match[1] ?? " ";
4229
+ if (ws.startsWith(" ")) return " ";
4230
+ return ws.length;
4231
+ }
4122
4232
  function checkBinary(name, command) {
4123
4233
  try {
4124
4234
  const out = execFileSync10(command, ["--version"], { encoding: "utf8" }).trim();
@@ -4129,7 +4239,7 @@ function checkBinary(name, command) {
4129
4239
  }
4130
4240
 
4131
4241
  // src/commands/version.ts
4132
- var CLI_VERSION = true ? "0.2.2" : "0.0.0-dev";
4242
+ var CLI_VERSION = true ? "0.2.4" : "0.0.0-dev";
4133
4243
  function registerVersion(program2) {
4134
4244
  program2.command("version").description("Print the CLI version").action(() => {
4135
4245
  process.stdout.write(CLI_VERSION + "\n");