workon 3.5.0 → 3.5.2

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
@@ -269,10 +269,11 @@ var init_project = __esm({
269
269
  return this._events;
270
270
  }
271
271
  set path(path8) {
272
- if (this._base) {
272
+ const pathFile = File.from(path8);
273
+ if (this._base && !pathFile.isAbsolute()) {
273
274
  this._path = this._base.join(path8);
274
275
  } else {
275
- this._path = File.from(path8);
276
+ this._path = pathFile;
276
277
  }
277
278
  this._path = this._path.absolutify();
278
279
  }
@@ -365,17 +366,17 @@ var init_environment = __esm({
365
366
  return this.projects;
366
367
  }
367
368
  const defaults = this.config.getDefaults();
368
- if (!defaults?.base) {
369
- this.projects = [];
370
- return this.projects;
371
- }
372
- const baseDir = File2.from(defaults.base);
369
+ const baseDir = defaults?.base ? File2.from(defaults.base).absolutify() : null;
373
370
  const projectsMap = this.config.getProjects();
374
- this.projects = Object.entries(projectsMap).map(([name, project]) => ({
375
- ...project,
376
- name,
377
- path: baseDir.join(project.path)
378
- }));
371
+ this.projects = Object.entries(projectsMap).map(([name, project]) => {
372
+ const projectPath = File2.from(project.path);
373
+ const resolvedPath = baseDir && !projectPath.isAbsolute() ? baseDir.join(project.path) : projectPath;
374
+ return {
375
+ ...project,
376
+ name,
377
+ path: resolvedPath
378
+ };
379
+ });
379
380
  return this.projects;
380
381
  }
381
382
  static getProjectEnvironment(base, _matching) {
@@ -1568,11 +1569,12 @@ var init_worktree = __esm({
1568
1569
  if (worktree.isMain) {
1569
1570
  throw new Error("Cannot remove the main worktree");
1570
1571
  }
1571
- if (!force && await this.hasUncommittedChanges(name)) {
1572
+ const pathMissing = !existsSync2(worktree.path);
1573
+ if (!pathMissing && !force && await this.hasUncommittedChanges(name)) {
1572
1574
  throw new Error(`Worktree '${name}' has uncommitted changes. Use --force to remove anyway.`);
1573
1575
  }
1574
1576
  const args = ["worktree", "remove"];
1575
- if (force) {
1577
+ if (force || pathMissing) {
1576
1578
  args.push("--force");
1577
1579
  }
1578
1580
  args.push(worktree.path);
@@ -1591,6 +1593,9 @@ var init_worktree = __esm({
1591
1593
  if (!worktree) {
1592
1594
  throw new Error(`Worktree '${nameOrPath}' not found`);
1593
1595
  }
1596
+ if (!existsSync2(worktree.path)) {
1597
+ return false;
1598
+ }
1594
1599
  const worktreeGit = simpleGit2(worktree.path);
1595
1600
  const status = await worktreeGit.status();
1596
1601
  return !status.isClean();
@@ -1932,6 +1937,7 @@ var init_utils = __esm({
1932
1937
  import { Command } from "commander";
1933
1938
  import chalk from "chalk";
1934
1939
  import path2 from "path";
1940
+ import { existsSync as existsSync3 } from "fs";
1935
1941
  function createListCommand(ctx) {
1936
1942
  const { config, log } = ctx;
1937
1943
  return new Command("list").description("List worktrees for the current project").option("-a, --all", "Show all worktrees (including main)").action(async (options) => {
@@ -1965,9 +1971,10 @@ Worktrees for ${displayName}:`));
1965
1971
  for (const wt of worktrees) {
1966
1972
  const isManaged = managedPaths.has(wt.path);
1967
1973
  const mainLabel = wt.isMain ? chalk.gray(" (main)") : "";
1968
- const externalLabel = !wt.isMain && !isManaged ? chalk.yellow(" (external)") : "";
1974
+ const missingLabel = !wt.isMain && !existsSync3(wt.path) ? chalk.red(" (missing)") : "";
1975
+ const externalLabel = !wt.isMain && !isManaged && !missingLabel ? chalk.yellow(" (external)") : "";
1969
1976
  const branchDisplay = wt.branch === "(detached)" ? chalk.yellow(wt.branch) : chalk.green(wt.branch);
1970
- console.log(` ${chalk.cyan(wt.name)}${mainLabel}${externalLabel}`);
1977
+ console.log(` ${chalk.cyan(wt.name)}${mainLabel}${missingLabel}${externalLabel}`);
1971
1978
  console.log(` Branch: ${branchDisplay}`);
1972
1979
  console.log(` Path: ${chalk.gray(wt.path)}`);
1973
1980
  console.log(` HEAD: ${chalk.gray(wt.head.substring(0, 8))}`);
@@ -2104,6 +2111,7 @@ import { Command as Command3 } from "commander";
2104
2111
  import chalk3 from "chalk";
2105
2112
  import ora2 from "ora";
2106
2113
  import path3 from "path";
2114
+ import { existsSync as existsSync4 } from "fs";
2107
2115
  import { confirm as confirm5 } from "@inquirer/prompts";
2108
2116
  function createRemoveCommand(ctx) {
2109
2117
  const { config, log } = ctx;
@@ -2133,22 +2141,29 @@ function createRemoveCommand(ctx) {
2133
2141
  log.error("Cannot remove the main worktree");
2134
2142
  process.exit(1);
2135
2143
  }
2136
- const hasChanges = await manager.hasUncommittedChanges(name);
2137
- if (hasChanges && !options.force) {
2138
- log.warn(`Worktree '${name}' has uncommitted changes.`);
2139
- if (!options.yes) {
2140
- const shouldForce = await confirm5({
2141
- message: "Do you want to force removal and lose these changes?",
2142
- default: false
2143
- });
2144
- if (!shouldForce) {
2145
- log.info("Removal cancelled.");
2146
- return;
2144
+ const pathMissing = !existsSync4(worktree.path);
2145
+ if (pathMissing) {
2146
+ log.warn(`Worktree directory is missing from disk: ${worktree.path}`);
2147
+ options.force = true;
2148
+ }
2149
+ if (!pathMissing) {
2150
+ const hasChanges = await manager.hasUncommittedChanges(name);
2151
+ if (hasChanges && !options.force) {
2152
+ log.warn(`Worktree '${name}' has uncommitted changes.`);
2153
+ if (!options.yes) {
2154
+ const shouldForce = await confirm5({
2155
+ message: "Do you want to force removal and lose these changes?",
2156
+ default: false
2157
+ });
2158
+ if (!shouldForce) {
2159
+ log.info("Removal cancelled.");
2160
+ return;
2161
+ }
2162
+ options.force = true;
2163
+ } else {
2164
+ log.error("Use --force to remove worktrees with uncommitted changes.");
2165
+ process.exit(1);
2147
2166
  }
2148
- options.force = true;
2149
- } else {
2150
- log.error("Use --force to remove worktrees with uncommitted changes.");
2151
- process.exit(1);
2152
2167
  }
2153
2168
  }
2154
2169
  if (!options.yes) {
@@ -2904,7 +2919,7 @@ async function initProject(defaultName, fromUser, ctx) {
2904
2919
  default: defaults?.base ? File5.from(defaults.base).join(name).path : name
2905
2920
  });
2906
2921
  let answerFile = File5.from(pathAnswer);
2907
- const defaultBase = defaults?.base ? File5.from(defaults.base) : File5.cwd();
2922
+ const defaultBase = defaults?.base ? File5.from(defaults.base).absolutify() : File5.cwd();
2908
2923
  if (!answerFile.isAbsolute()) {
2909
2924
  answerFile = defaultBase.join(answerFile.path);
2910
2925
  }
@@ -2918,7 +2933,8 @@ async function initProject(defaultName, fromUser, ctx) {
2918
2933
  } catch {
2919
2934
  answerFile = answerFile.absolutify();
2920
2935
  }
2921
- basePath = answerFile.relativize(defaultBase.path).path;
2936
+ const relPath = answerFile.relativize(defaultBase.path);
2937
+ basePath = relPath && !relPath.path.startsWith("..") ? relPath.path : answerFile.path;
2922
2938
  }
2923
2939
  const ide = await select4({
2924
2940
  message: "What is the IDE?",
@@ -3111,18 +3127,21 @@ async function createProjectManage(ctx) {
3111
3127
  return true;
3112
3128
  }
3113
3129
  });
3114
- const defaultPath = defaults?.base ? File5.from(defaults.base).join(name).path : name;
3130
+ const defaultPath = defaults?.base ? File5.from(defaults.base).absolutify().join(name).path : name;
3115
3131
  const pathInput = await input5({
3116
3132
  message: "Project path:",
3117
3133
  default: defaultPath
3118
3134
  });
3119
3135
  let relativePath = pathInput;
3120
3136
  if (defaults?.base) {
3121
- const baseDir = File5.from(defaults.base);
3137
+ const baseDir = File5.from(defaults.base).absolutify();
3122
3138
  const pathFile = File5.from(pathInput);
3123
3139
  try {
3124
3140
  if (pathFile.isAbsolute()) {
3125
- relativePath = pathFile.relativize(baseDir.path).path;
3141
+ const relPath = pathFile.relativize(baseDir.path);
3142
+ if (relPath && !relPath.path.startsWith("..")) {
3143
+ relativePath = relPath.path;
3144
+ }
3126
3145
  }
3127
3146
  } catch {
3128
3147
  relativePath = pathInput;
@@ -3183,11 +3202,14 @@ async function editProjectManage(ctx) {
3183
3202
  });
3184
3203
  let relativePath = pathInput;
3185
3204
  if (defaults?.base) {
3186
- const baseDir = File5.from(defaults.base);
3205
+ const baseDir = File5.from(defaults.base).absolutify();
3187
3206
  const pathFile = File5.from(pathInput);
3188
3207
  try {
3189
3208
  if (pathFile.isAbsolute()) {
3190
- relativePath = pathFile.relativize(baseDir.path).path;
3209
+ const relPath = pathFile.relativize(baseDir.path);
3210
+ if (relPath && !relPath.path.startsWith("..")) {
3211
+ relativePath = relPath.path;
3212
+ }
3191
3213
  }
3192
3214
  } catch {
3193
3215
  relativePath = pathInput;
@@ -4097,7 +4119,7 @@ init_environment();
4097
4119
  init_registry();
4098
4120
  init_open2();
4099
4121
  import { Command as Command16 } from "commander";
4100
- import { readFileSync as readFileSync2, existsSync as existsSync4 } from "fs";
4122
+ import { readFileSync as readFileSync2, existsSync as existsSync6 } from "fs";
4101
4123
  import { join as join2, dirname as dirname2 } from "path";
4102
4124
  import { fileURLToPath } from "url";
4103
4125
  import loog from "loog";
@@ -4277,10 +4299,13 @@ async function createProject(ctx) {
4277
4299
  });
4278
4300
  let relativePath = pathInput;
4279
4301
  if (defaults?.base) {
4280
- const baseDir = File7.from(defaults.base);
4302
+ const baseDir = File7.from(defaults.base).absolutify();
4281
4303
  const pathFile = File7.from(pathInput);
4282
4304
  try {
4283
- relativePath = pathFile.relativize(baseDir.path).path;
4305
+ const relPath = pathFile.relativize(baseDir.path);
4306
+ if (relPath && !relPath.path.startsWith("..")) {
4307
+ relativePath = relPath.path;
4308
+ }
4284
4309
  } catch {
4285
4310
  relativePath = pathInput;
4286
4311
  }
@@ -4352,11 +4377,14 @@ async function editProject(ctx) {
4352
4377
  });
4353
4378
  let relativePath = pathInput;
4354
4379
  if (defaults?.base) {
4355
- const baseDir = File7.from(defaults.base);
4380
+ const baseDir = File7.from(defaults.base).absolutify();
4356
4381
  const pathFile = File7.from(pathInput);
4357
4382
  try {
4358
4383
  if (pathFile.isAbsolute()) {
4359
- relativePath = pathFile.relativize(baseDir.path).path;
4384
+ const relPath = pathFile.relativize(baseDir.path);
4385
+ if (relPath && !relPath.path.startsWith("..")) {
4386
+ relativePath = relPath.path;
4387
+ }
4360
4388
  }
4361
4389
  } catch {
4362
4390
  relativePath = pathInput;
@@ -4464,7 +4492,7 @@ async function listProjects(ctx) {
4464
4492
 
4465
4493
  // src/commands/add.ts
4466
4494
  import { Command as Command14 } from "commander";
4467
- import { existsSync as existsSync3, readFileSync } from "fs";
4495
+ import { existsSync as existsSync5, readFileSync } from "fs";
4468
4496
  import { basename as basename2, resolve } from "path";
4469
4497
  import File8 from "phylo";
4470
4498
  import { confirm as confirm10 } from "@inquirer/prompts";
@@ -4486,7 +4514,7 @@ async function addProject(pathArg, options, ctx) {
4486
4514
  const projects = config.getProjects();
4487
4515
  const targetPath = resolve(pathArg);
4488
4516
  log.debug(`Resolved path: ${targetPath}`);
4489
- if (!existsSync3(targetPath)) {
4517
+ if (!existsSync5(targetPath)) {
4490
4518
  log.error(`Path does not exist: ${targetPath}`);
4491
4519
  process.exit(1);
4492
4520
  }
@@ -4524,7 +4552,7 @@ async function addProject(pathArg, options, ctx) {
4524
4552
  log.debug(`IDE: ${ide}`);
4525
4553
  let relativePath = targetPath;
4526
4554
  if (defaults?.base) {
4527
- const baseDir = File8.from(defaults.base);
4555
+ const baseDir = File8.from(defaults.base).absolutify();
4528
4556
  try {
4529
4557
  const relPath = pathFile.relativize(baseDir.path);
4530
4558
  if (relPath && !relPath.path.startsWith("..")) {
@@ -4570,7 +4598,7 @@ function discoverProject(targetPath, log) {
4570
4598
  packageJson: null
4571
4599
  };
4572
4600
  const packageJsonPath = resolve(targetPath, "package.json");
4573
- if (existsSync3(packageJsonPath)) {
4601
+ if (existsSync5(packageJsonPath)) {
4574
4602
  discovery.isNode = true;
4575
4603
  log.debug("Detected Node project (package.json found)");
4576
4604
  try {
@@ -4586,25 +4614,25 @@ function discoverProject(targetPath, log) {
4586
4614
  }
4587
4615
  }
4588
4616
  const bunLockPath = resolve(targetPath, "bun.lockb");
4589
- if (existsSync3(bunLockPath)) {
4617
+ if (existsSync5(bunLockPath)) {
4590
4618
  discovery.isBun = true;
4591
4619
  log.debug("Detected Bun project (bun.lockb found)");
4592
4620
  }
4593
4621
  const vscodeDir = resolve(targetPath, ".vscode");
4594
4622
  const cursorDir = resolve(targetPath, ".cursor");
4595
4623
  const ideaDir = resolve(targetPath, ".idea");
4596
- if (existsSync3(cursorDir)) {
4624
+ if (existsSync5(cursorDir)) {
4597
4625
  discovery.detectedIde = "cursor";
4598
4626
  log.debug("Detected Cursor (.cursor directory found)");
4599
- } else if (existsSync3(vscodeDir)) {
4627
+ } else if (existsSync5(vscodeDir)) {
4600
4628
  discovery.detectedIde = "code";
4601
4629
  log.debug("Detected VS Code (.vscode directory found)");
4602
- } else if (existsSync3(ideaDir)) {
4630
+ } else if (existsSync5(ideaDir)) {
4603
4631
  discovery.detectedIde = "idea";
4604
4632
  log.debug("Detected IntelliJ IDEA (.idea directory found)");
4605
4633
  }
4606
4634
  const claudeMdPath = resolve(targetPath, "CLAUDE.md");
4607
- if (existsSync3(claudeMdPath)) {
4635
+ if (existsSync5(claudeMdPath)) {
4608
4636
  discovery.hasClaude = true;
4609
4637
  log.debug("Detected Claude Code project (CLAUDE.md found)");
4610
4638
  }
@@ -4900,7 +4928,7 @@ function findPackageJson() {
4900
4928
  join2(process.cwd(), "package.json")
4901
4929
  ];
4902
4930
  for (const p of paths) {
4903
- if (existsSync4(p)) {
4931
+ if (existsSync6(p)) {
4904
4932
  return p;
4905
4933
  }
4906
4934
  }