uloop-cli 1.7.0 → 1.7.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.
@@ -9,6 +9,10 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __commonJS = (cb, mod) => function __require() {
10
10
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
11
  };
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
12
16
  var __copyProps = (to, from, except, desc) => {
13
17
  if (from && typeof from === "object" || typeof from === "function") {
14
18
  for (let key of __getOwnPropNames(from))
@@ -25,6 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
29
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
30
  mod
27
31
  ));
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
33
 
29
34
  // node_modules/commander/lib/error.js
30
35
  var require_error = __commonJS({
@@ -5382,6 +5387,14 @@ var require_semver2 = __commonJS({
5382
5387
  }
5383
5388
  });
5384
5389
 
5390
+ // src/cli.ts
5391
+ var cli_exports = {};
5392
+ __export(cli_exports, {
5393
+ getInstalledVersion: () => getInstalledVersion,
5394
+ updateCli: () => updateCli
5395
+ });
5396
+ module.exports = __toCommonJS(cli_exports);
5397
+
5385
5398
  // src/cli-constants.ts
5386
5399
  var PRODUCT_DISPLAY_NAME = "Unity CLI Loop";
5387
5400
  var MENU_PATH_SERVER = "Window > Unity CLI Loop > Server";
@@ -5755,6 +5768,13 @@ var UnityNotRunningError = class extends Error {
5755
5768
  }
5756
5769
  projectRoot;
5757
5770
  };
5771
+ var UnityServerNotRunningError = class extends Error {
5772
+ constructor(projectRoot) {
5773
+ super("UNITY_SERVER_NOT_RUNNING");
5774
+ this.projectRoot = projectRoot;
5775
+ }
5776
+ projectRoot;
5777
+ };
5758
5778
  function normalizePort(port) {
5759
5779
  if (typeof port !== "number") {
5760
5780
  return null;
@@ -5834,9 +5854,6 @@ async function readPortFromSettingsOrThrow(projectRoot) {
5834
5854
  continue;
5835
5855
  }
5836
5856
  const settings = parsed;
5837
- if (settings.isServerRunning === false) {
5838
- throw new UnityNotRunningError(projectRoot);
5839
- }
5840
5857
  const port = resolvePortFromUnitySettings(settings);
5841
5858
  if (port !== null) {
5842
5859
  return port;
@@ -5895,7 +5912,7 @@ var import_path4 = require("path");
5895
5912
 
5896
5913
  // src/default-tools.json
5897
5914
  var default_tools_default = {
5898
- version: "1.7.0",
5915
+ version: "1.7.3",
5899
5916
  tools: [
5900
5917
  {
5901
5918
  name: "compile",
@@ -6528,7 +6545,7 @@ function getCachedServerVersion() {
6528
6545
  }
6529
6546
 
6530
6547
  // src/version.ts
6531
- var VERSION = "1.7.0";
6548
+ var VERSION = "1.7.3";
6532
6549
 
6533
6550
  // src/spinner.ts
6534
6551
  var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
@@ -6562,6 +6579,228 @@ function createSpinner(initialMessage) {
6562
6579
  };
6563
6580
  }
6564
6581
 
6582
+ // src/unity-process.ts
6583
+ var import_node_child_process = require("node:child_process");
6584
+ var import_node_util = require("node:util");
6585
+ var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
6586
+ var WINDOWS_PROCESS_QUERY = `Get-CimInstance Win32_Process -Filter "name = 'Unity.exe'" | Select-Object ProcessId, CommandLine | ConvertTo-Json -Compress`;
6587
+ var defaultDependencies = {
6588
+ platform: process.platform,
6589
+ runCommand: runUnityProcessQuery
6590
+ };
6591
+ function buildUnityProcessCommand(platform) {
6592
+ if (platform === "darwin") {
6593
+ return {
6594
+ command: "ps",
6595
+ args: ["-Ao", "pid=,command="]
6596
+ };
6597
+ }
6598
+ if (platform === "linux") {
6599
+ return {
6600
+ command: "ps",
6601
+ args: ["-eo", "pid=,args="]
6602
+ };
6603
+ }
6604
+ if (platform === "win32") {
6605
+ return {
6606
+ command: "powershell.exe",
6607
+ args: ["-NoProfile", "-NonInteractive", "-Command", WINDOWS_PROCESS_QUERY]
6608
+ };
6609
+ }
6610
+ return null;
6611
+ }
6612
+ function parseUnityProcesses(platform, output) {
6613
+ if (platform === "win32") {
6614
+ return parseWindowsUnityProcesses(output);
6615
+ }
6616
+ return parsePsUnityProcesses(output);
6617
+ }
6618
+ function tokenizeCommandLine(commandLine) {
6619
+ const tokens = [];
6620
+ let current = "";
6621
+ let inQuotes = false;
6622
+ for (let i = 0; i < commandLine.length; i++) {
6623
+ const character = commandLine[i];
6624
+ if (character === '"') {
6625
+ inQuotes = !inQuotes;
6626
+ continue;
6627
+ }
6628
+ if (!inQuotes && /\s/.test(character)) {
6629
+ if (current.length > 0) {
6630
+ tokens.push(current);
6631
+ current = "";
6632
+ }
6633
+ continue;
6634
+ }
6635
+ current += character;
6636
+ }
6637
+ if (current.length > 0) {
6638
+ tokens.push(current);
6639
+ }
6640
+ return tokens;
6641
+ }
6642
+ function extractUnityProjectPath(commandLine) {
6643
+ const tokens = tokenizeCommandLine(commandLine);
6644
+ for (let i = 0; i < tokens.length; i++) {
6645
+ const token = tokens[i].toLowerCase();
6646
+ if (token !== "-projectpath") {
6647
+ continue;
6648
+ }
6649
+ const projectPath = tokens[i + 1];
6650
+ return projectPath ?? null;
6651
+ }
6652
+ return null;
6653
+ }
6654
+ function normalizeUnityProjectPath(projectPath, platform) {
6655
+ const normalizedSeparators = projectPath.replace(/\\/g, "/").replace(/\/+$/, "");
6656
+ if (platform === "win32") {
6657
+ return normalizedSeparators.toLowerCase();
6658
+ }
6659
+ return normalizedSeparators;
6660
+ }
6661
+ function isUnityProcessForProject(commandLine, projectRoot, platform) {
6662
+ if (platform !== "win32") {
6663
+ return commandLineContainsProjectRoot(commandLine, projectRoot, platform);
6664
+ }
6665
+ const extractedProjectPath = extractUnityProjectPath(commandLine);
6666
+ if (extractedProjectPath === null) {
6667
+ return false;
6668
+ }
6669
+ return normalizeUnityProjectPath(extractedProjectPath, platform) === normalizeUnityProjectPath(projectRoot, platform);
6670
+ }
6671
+ function commandLineContainsProjectRoot(commandLine, projectRoot, platform) {
6672
+ const projectPathFlagIndex = commandLine.toLowerCase().indexOf(" -projectpath");
6673
+ if (projectPathFlagIndex === -1) {
6674
+ return false;
6675
+ }
6676
+ const normalizedProjectRoot = normalizeUnityProjectPath(projectRoot, platform);
6677
+ let projectRootIndex = commandLine.indexOf(normalizedProjectRoot, projectPathFlagIndex);
6678
+ while (projectRootIndex !== -1) {
6679
+ const beforeProjectRoot = commandLine[projectRootIndex - 1];
6680
+ const projectPathEndIndex = skipTrailingProjectPathSeparators(
6681
+ commandLine,
6682
+ projectRootIndex + normalizedProjectRoot.length
6683
+ );
6684
+ if (isProjectPathBoundaryCharacter(beforeProjectRoot) && isProjectPathTerminator(commandLine, projectPathEndIndex)) {
6685
+ return true;
6686
+ }
6687
+ projectRootIndex = commandLine.indexOf(normalizedProjectRoot, projectRootIndex + 1);
6688
+ }
6689
+ return false;
6690
+ }
6691
+ function isProjectPathBoundaryCharacter(character) {
6692
+ return character === void 0 || /\s|["']/.test(character);
6693
+ }
6694
+ function skipTrailingProjectPathSeparators(commandLine, startIndex) {
6695
+ let index = startIndex;
6696
+ while (readCharacterAt(commandLine, index) === "/") {
6697
+ index += 1;
6698
+ }
6699
+ return index;
6700
+ }
6701
+ function isProjectPathTerminator(commandLine, projectRootEndIndex) {
6702
+ const character = readCharacterAt(commandLine, projectRootEndIndex);
6703
+ if (character === null) {
6704
+ return true;
6705
+ }
6706
+ if (character === '"' || character === "'") {
6707
+ return true;
6708
+ }
6709
+ if (!/\s/.test(character)) {
6710
+ return false;
6711
+ }
6712
+ for (let i = projectRootEndIndex; i < commandLine.length; i++) {
6713
+ const trailingCharacter = readCharacterAt(commandLine, i);
6714
+ if (trailingCharacter === null) {
6715
+ return true;
6716
+ }
6717
+ if (/\s/.test(trailingCharacter)) {
6718
+ continue;
6719
+ }
6720
+ return trailingCharacter === "-";
6721
+ }
6722
+ return true;
6723
+ }
6724
+ function readCharacterAt(value, index) {
6725
+ const character = value.slice(index, index + 1);
6726
+ if (character.length === 0) {
6727
+ return null;
6728
+ }
6729
+ return character;
6730
+ }
6731
+ function isUnityEditorProcess(commandLine, platform) {
6732
+ const lowerCommandLine = commandLine.toLowerCase();
6733
+ if (lowerCommandLine.length === 0) {
6734
+ return false;
6735
+ }
6736
+ const projectPathFlagIndex = lowerCommandLine.indexOf(" -projectpath");
6737
+ const executableSection = projectPathFlagIndex === -1 ? lowerCommandLine : lowerCommandLine.slice(0, projectPathFlagIndex);
6738
+ if (platform === "win32") {
6739
+ return executableSection.includes("unity.exe");
6740
+ }
6741
+ if (platform === "darwin") {
6742
+ return executableSection.includes("/unity.app/contents/macos/unity");
6743
+ }
6744
+ if (platform === "linux") {
6745
+ return executableSection.endsWith("/unity") || executableSection.endsWith("/unity-editor") || executableSection.includes("/editor/unity");
6746
+ }
6747
+ return false;
6748
+ }
6749
+ async function findRunningUnityProcessForProject(projectRoot, dependencies = defaultDependencies) {
6750
+ const unityProcessCommand = buildUnityProcessCommand(dependencies.platform);
6751
+ if (unityProcessCommand === null) {
6752
+ return null;
6753
+ }
6754
+ const output = await dependencies.runCommand(
6755
+ unityProcessCommand.command,
6756
+ unityProcessCommand.args
6757
+ );
6758
+ const runningProcesses = parseUnityProcesses(dependencies.platform, output);
6759
+ const matchingProcess = runningProcesses.find(
6760
+ (processInfo) => isUnityEditorProcess(processInfo.commandLine, dependencies.platform) && isUnityProcessForProject(processInfo.commandLine, projectRoot, dependencies.platform)
6761
+ );
6762
+ if (matchingProcess === void 0) {
6763
+ return null;
6764
+ }
6765
+ return {
6766
+ pid: matchingProcess.pid
6767
+ };
6768
+ }
6769
+ async function runUnityProcessQuery(command, args) {
6770
+ const { stdout } = await execFileAsync(command, args, {
6771
+ encoding: "utf8",
6772
+ maxBuffer: 1024 * 1024
6773
+ });
6774
+ return stdout;
6775
+ }
6776
+ function parsePsUnityProcesses(output) {
6777
+ return output.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0).map((line) => {
6778
+ const match = line.match(/^(\d+)\s+(.+)$/);
6779
+ if (match === null) {
6780
+ return null;
6781
+ }
6782
+ return {
6783
+ pid: Number.parseInt(match[1], 10),
6784
+ commandLine: match[2]
6785
+ };
6786
+ }).filter((processInfo) => processInfo !== null);
6787
+ }
6788
+ function parseWindowsUnityProcesses(output) {
6789
+ const trimmed = output.trim();
6790
+ if (trimmed.length === 0) {
6791
+ return [];
6792
+ }
6793
+ const parsed = JSON.parse(trimmed);
6794
+ const processArray = Array.isArray(parsed) ? parsed : [parsed];
6795
+ return processArray.filter(isWindowsUnityProcessWithCommandLine).map((processInfo) => ({
6796
+ pid: processInfo.ProcessId,
6797
+ commandLine: processInfo.CommandLine
6798
+ }));
6799
+ }
6800
+ function isWindowsUnityProcessWithCommandLine(processInfo) {
6801
+ return typeof processInfo.ProcessId === "number" && typeof processInfo.CommandLine === "string";
6802
+ }
6803
+
6565
6804
  // src/compile-helpers.ts
6566
6805
  var import_node_assert2 = __toESM(require("node:assert"), 1);
6567
6806
  var import_fs4 = require("fs");
@@ -6797,6 +7036,9 @@ var RETRY_DELAY_MS = 500;
6797
7036
  var MAX_RETRIES = 3;
6798
7037
  var COMPILE_WAIT_TIMEOUT_MS = 9e4;
6799
7038
  var COMPILE_WAIT_POLL_INTERVAL_MS = 100;
7039
+ var defaultConnectionFailureDiagnosisDependencies = {
7040
+ findRunningUnityProcessForProjectFn: findRunningUnityProcessForProject
7041
+ };
6800
7042
  function getCompileExecutionOptions(toolName, params) {
6801
7043
  if (toolName !== "compile") {
6802
7044
  return {
@@ -6813,6 +7055,34 @@ function isRetryableError(error) {
6813
7055
  const message = error.message;
6814
7056
  return message.includes("ECONNREFUSED") || message.includes("EADDRNOTAVAIL") || message === "UNITY_NO_RESPONSE";
6815
7057
  }
7058
+ async function diagnoseRetryableProjectConnectionError(error, projectRoot, shouldDiagnoseProjectState, dependencies = defaultConnectionFailureDiagnosisDependencies) {
7059
+ if (!shouldDiagnoseProjectState || projectRoot === null || !isRetryableError(error)) {
7060
+ return error;
7061
+ }
7062
+ const runningProcess = await dependencies.findRunningUnityProcessForProjectFn(projectRoot).catch(() => void 0);
7063
+ if (runningProcess === void 0) {
7064
+ return error;
7065
+ }
7066
+ if (runningProcess === null) {
7067
+ return new UnityNotRunningError(projectRoot);
7068
+ }
7069
+ return new UnityServerNotRunningError(projectRoot);
7070
+ }
7071
+ async function throwFinalToolError(error, projectRoot, shouldDiagnoseProjectState) {
7072
+ const diagnosedError = await diagnoseRetryableProjectConnectionError(
7073
+ error,
7074
+ projectRoot,
7075
+ shouldDiagnoseProjectState
7076
+ );
7077
+ if (diagnosedError instanceof Error) {
7078
+ throw diagnosedError;
7079
+ }
7080
+ if (typeof diagnosedError === "string") {
7081
+ throw new Error(diagnosedError);
7082
+ }
7083
+ const serializedError = JSON.stringify(diagnosedError);
7084
+ throw new Error(serializedError ?? "Unknown error");
7085
+ }
6816
7086
  function isTransportDisconnectError(error) {
6817
7087
  if (!(error instanceof Error)) {
6818
7088
  return false;
@@ -6864,6 +7134,12 @@ function checkUnityBusyState(projectPath) {
6864
7134
  throw new Error("UNITY_SERVER_STARTING");
6865
7135
  }
6866
7136
  }
7137
+ function checkUnityBusyStateBeforeProjectResolution(globalOptions) {
7138
+ if (globalOptions.port !== void 0) {
7139
+ return;
7140
+ }
7141
+ checkUnityBusyState(globalOptions.projectPath);
7142
+ }
6867
7143
  async function executeToolCommand(toolName, params, globalOptions) {
6868
7144
  let portNumber;
6869
7145
  if (globalOptions.port) {
@@ -6873,6 +7149,7 @@ async function executeToolCommand(toolName, params, globalOptions) {
6873
7149
  }
6874
7150
  portNumber = parsed;
6875
7151
  }
7152
+ checkUnityBusyStateBeforeProjectResolution(globalOptions);
6876
7153
  const port = await resolveUnityPort(portNumber, globalOptions.projectPath);
6877
7154
  const compileOptions = getCompileExecutionOptions(toolName, params);
6878
7155
  const shouldWaitForDomainReload = compileOptions.waitForDomainReload;
@@ -6885,7 +7162,7 @@ async function executeToolCommand(toolName, params, globalOptions) {
6885
7162
  const shouldValidateProject = portNumber === void 0 && projectRoot !== null;
6886
7163
  let requestDispatched = false;
6887
7164
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
6888
- checkUnityBusyState(globalOptions.projectPath);
7165
+ checkUnityBusyStateBeforeProjectResolution(globalOptions);
6889
7166
  const client = new DirectUnityClient(port);
6890
7167
  try {
6891
7168
  await client.connect();
@@ -6932,8 +7209,8 @@ async function executeToolCommand(toolName, params, globalOptions) {
6932
7209
  if (immediateResult === void 0 && !requestDispatched) {
6933
7210
  spinner.stop();
6934
7211
  restoreStdin();
6935
- if (lastError instanceof Error) {
6936
- throw lastError;
7212
+ if (lastError !== void 0) {
7213
+ await throwFinalToolError(lastError, projectRoot, shouldValidateProject);
6937
7214
  }
6938
7215
  throw new Error(
6939
7216
  "Compile request never reached Unity. Check that Unity is running and retry."
@@ -6984,14 +7261,7 @@ async function executeToolCommand(toolName, params, globalOptions) {
6984
7261
  if (lastError === void 0) {
6985
7262
  throw new Error("Tool execution failed without error details.");
6986
7263
  }
6987
- if (lastError instanceof Error) {
6988
- throw lastError;
6989
- }
6990
- if (typeof lastError === "string") {
6991
- throw new Error(lastError);
6992
- }
6993
- const serializedError = JSON.stringify(lastError);
6994
- throw new Error(serializedError ?? "Unknown error");
7264
+ await throwFinalToolError(lastError, projectRoot, shouldValidateProject);
6995
7265
  }
6996
7266
  async function listAvailableTools(globalOptions) {
6997
7267
  let portNumber;
@@ -7002,6 +7272,7 @@ async function listAvailableTools(globalOptions) {
7002
7272
  }
7003
7273
  portNumber = parsed;
7004
7274
  }
7275
+ checkUnityBusyStateBeforeProjectResolution(globalOptions);
7005
7276
  const port = await resolveUnityPort(portNumber, globalOptions.projectPath);
7006
7277
  const projectRoot = globalOptions.projectPath !== void 0 ? validateProjectPath(globalOptions.projectPath) : findUnityProjectRoot();
7007
7278
  const shouldValidateProject = portNumber === void 0 && projectRoot !== null;
@@ -7009,7 +7280,7 @@ async function listAvailableTools(globalOptions) {
7009
7280
  const spinner = createSpinner("Connecting to Unity...");
7010
7281
  let lastError;
7011
7282
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
7012
- checkUnityBusyState(globalOptions.projectPath);
7283
+ checkUnityBusyStateBeforeProjectResolution(globalOptions);
7013
7284
  const client = new DirectUnityClient(port);
7014
7285
  try {
7015
7286
  await client.connect();
@@ -7041,7 +7312,7 @@ async function listAvailableTools(globalOptions) {
7041
7312
  }
7042
7313
  spinner.stop();
7043
7314
  restoreStdin();
7044
- throw lastError;
7315
+ await throwFinalToolError(lastError, projectRoot, shouldValidateProject);
7045
7316
  }
7046
7317
  function convertProperties(unityProps) {
7047
7318
  const result = {};
@@ -7064,6 +7335,7 @@ async function syncTools(globalOptions) {
7064
7335
  }
7065
7336
  portNumber = parsed;
7066
7337
  }
7338
+ checkUnityBusyStateBeforeProjectResolution(globalOptions);
7067
7339
  const port = await resolveUnityPort(portNumber, globalOptions.projectPath);
7068
7340
  const projectRoot = globalOptions.projectPath !== void 0 ? validateProjectPath(globalOptions.projectPath) : findUnityProjectRoot();
7069
7341
  const shouldValidateProject = portNumber === void 0 && projectRoot !== null;
@@ -7071,7 +7343,7 @@ async function syncTools(globalOptions) {
7071
7343
  const spinner = createSpinner("Connecting to Unity...");
7072
7344
  let lastError;
7073
7345
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
7074
- checkUnityBusyState(globalOptions.projectPath);
7346
+ checkUnityBusyStateBeforeProjectResolution(globalOptions);
7075
7347
  const client = new DirectUnityClient(port);
7076
7348
  try {
7077
7349
  await client.connect();
@@ -7121,7 +7393,7 @@ async function syncTools(globalOptions) {
7121
7393
  }
7122
7394
  spinner.stop();
7123
7395
  restoreStdin();
7124
- throw lastError;
7396
+ await throwFinalToolError(lastError, projectRoot, shouldValidateProject);
7125
7397
  }
7126
7398
 
7127
7399
  // src/arg-parser.ts
@@ -8001,11 +8273,11 @@ Uninstalling uloop skills (${location})...`);
8001
8273
  var import_path9 = require("path");
8002
8274
 
8003
8275
  // node_modules/launch-unity/dist/lib.js
8004
- var import_node_child_process = require("node:child_process");
8276
+ var import_node_child_process2 = require("node:child_process");
8005
8277
  var import_node_fs2 = require("node:fs");
8006
8278
  var import_promises4 = require("node:fs/promises");
8007
8279
  var import_node_path2 = require("node:path");
8008
- var import_node_util = require("node:util");
8280
+ var import_node_util2 = require("node:util");
8009
8281
 
8010
8282
  // node_modules/launch-unity/dist/unityHub.js
8011
8283
  var import_promises3 = require("node:fs/promises");
@@ -8277,7 +8549,7 @@ var getProjectCliArgs = async (projectPath) => {
8277
8549
  };
8278
8550
 
8279
8551
  // node_modules/launch-unity/dist/lib.js
8280
- var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
8552
+ var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
8281
8553
  var UNITY_EXECUTABLE_PATTERN_MAC = /Unity\.app\/Contents\/MacOS\/Unity/i;
8282
8554
  var UNITY_EXECUTABLE_PATTERN_WINDOWS = /Unity\.exe/i;
8283
8555
  var PROJECT_PATH_PATTERN = /-(?:projectPath|projectpath)(?:=|\s+)("[^"]+"|'[^']+'|.+?)(?=\s+-[a-zA-Z]|$)/i;
@@ -8377,7 +8649,7 @@ var isUnityAuxiliaryProcess = (command) => {
8377
8649
  async function listUnityProcessesMac() {
8378
8650
  let stdout = "";
8379
8651
  try {
8380
- const result = await execFileAsync(PROCESS_LIST_COMMAND_MAC, PROCESS_LIST_ARGS_MAC);
8652
+ const result = await execFileAsync2(PROCESS_LIST_COMMAND_MAC, PROCESS_LIST_ARGS_MAC);
8381
8653
  stdout = result.stdout;
8382
8654
  } catch (error) {
8383
8655
  const message = error instanceof Error ? error.message : String(error);
@@ -8424,7 +8696,7 @@ async function listUnityProcessesWindows() {
8424
8696
  ];
8425
8697
  let stdout = "";
8426
8698
  try {
8427
- const result = await execFileAsync(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8699
+ const result = await execFileAsync2(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8428
8700
  stdout = result.stdout ?? "";
8429
8701
  } catch (error) {
8430
8702
  const message = error instanceof Error ? error.message : String(error);
@@ -8487,7 +8759,7 @@ async function focusUnityProcess(pid) {
8487
8759
  async function focusUnityProcessMac(pid) {
8488
8760
  const script = `tell application "System Events" to set frontmost of (first process whose unix id is ${pid}) to true`;
8489
8761
  try {
8490
- await execFileAsync("osascript", ["-e", script]);
8762
+ await execFileAsync2("osascript", ["-e", script]);
8491
8763
  console.log("Brought existing Unity to the front.");
8492
8764
  } catch (error) {
8493
8765
  const message = error instanceof Error ? error.message : String(error);
@@ -8515,7 +8787,7 @@ async function focusUnityProcessWindows(pid) {
8515
8787
  "[Win32Interop]::SetForegroundWindow($handle) | Out-Null"
8516
8788
  ];
8517
8789
  try {
8518
- await execFileAsync(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8790
+ await execFileAsync2(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8519
8791
  console.log("Brought existing Unity to the front.");
8520
8792
  } catch (error) {
8521
8793
  const message = error instanceof Error ? error.message : String(error);
@@ -8524,7 +8796,7 @@ async function focusUnityProcessWindows(pid) {
8524
8796
  }
8525
8797
  async function isLockfileHeldMac(lockfilePath) {
8526
8798
  try {
8527
- const result = await execFileAsync("lsof", [lockfilePath]);
8799
+ const result = await execFileAsync2("lsof", [lockfilePath]);
8528
8800
  const lines = result.stdout.split("\n").filter((line) => line.length > 0);
8529
8801
  return lines.length > 1;
8530
8802
  } catch {
@@ -8545,7 +8817,7 @@ async function isLockfileHeldWindows(lockfilePath) {
8545
8817
  "}"
8546
8818
  ];
8547
8819
  try {
8548
- const result = await execFileAsync(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8820
+ const result = await execFileAsync2(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8549
8821
  return result.stdout.trim() === "LOCKED";
8550
8822
  } catch {
8551
8823
  return false;
@@ -8655,7 +8927,7 @@ async function sendGracefulQuitMac(pid) {
8655
8927
  "end tell"
8656
8928
  ].join("\n");
8657
8929
  try {
8658
- await execFileAsync("osascript", ["-e", script]);
8930
+ await execFileAsync2("osascript", ["-e", script]);
8659
8931
  } catch {
8660
8932
  }
8661
8933
  }
@@ -8665,7 +8937,7 @@ async function sendGracefulQuitWindows(pid) {
8665
8937
  `try { $proc = Get-Process -Id ${pid} -ErrorAction Stop; $proc.CloseMainWindow() | Out-Null } catch { }`
8666
8938
  ];
8667
8939
  try {
8668
- await execFileAsync(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8940
+ await execFileAsync2(WINDOWS_POWERSHELL, ["-NoProfile", "-Command", scriptLines.join("\n")]);
8669
8941
  } catch {
8670
8942
  }
8671
8943
  }
@@ -8827,7 +9099,7 @@ async function launch(opts) {
8827
9099
  args.push(...unityArgs);
8828
9100
  }
8829
9101
  return new Promise((resolve7, reject) => {
8830
- const child = (0, import_node_child_process.spawn)(unityPath, args, {
9102
+ const child = (0, import_node_child_process2.spawn)(unityPath, args, {
8831
9103
  stdio: "ignore",
8832
9104
  detached: true,
8833
9105
  // Git Bash (MSYS) がWindows パスをUnix 形式に自動変換するのを防ぐ
@@ -9012,6 +9284,37 @@ function registerFocusWindowCommand(program3, helpGroup) {
9012
9284
  });
9013
9285
  }
9014
9286
 
9287
+ // src/cli-project-error.ts
9288
+ function getProjectResolutionErrorLines(error) {
9289
+ if (error instanceof UnityServerNotRunningError) {
9290
+ return [
9291
+ "Error: Unity Editor is running, but Unity CLI Loop server is not.",
9292
+ "",
9293
+ ` Project: ${error.projectRoot}`,
9294
+ "",
9295
+ "Start the server from: Window > Unity CLI Loop > Server"
9296
+ ];
9297
+ }
9298
+ if (error instanceof UnityNotRunningError) {
9299
+ return [
9300
+ "Error: Unity Editor for this project is not running.",
9301
+ "",
9302
+ ` Project: ${error.projectRoot}`,
9303
+ "",
9304
+ "Start the Unity Editor for this project and try again."
9305
+ ];
9306
+ }
9307
+ return [
9308
+ "Error: Connected Unity instance belongs to a different project.",
9309
+ "",
9310
+ ` Project: ${error.expectedProjectRoot}`,
9311
+ ` Connected to: ${error.connectedProjectRoot}`,
9312
+ "",
9313
+ "Another Unity instance was found, but it belongs to a different project.",
9314
+ "Start the Unity Editor for this project, or use --project-path to specify the target."
9315
+ ];
9316
+ }
9317
+
9015
9318
  // src/cli.ts
9016
9319
  var FOCUS_WINDOW_COMMAND = "focus-window";
9017
9320
  var LAUNCH_COMMAND = "launch";
@@ -9272,24 +9575,16 @@ async function runWithErrorHandling(fn) {
9272
9575
  try {
9273
9576
  await fn();
9274
9577
  } catch (error) {
9275
- if (error instanceof UnityNotRunningError) {
9276
- console.error("\x1B[31mError: Unity Editor for this project is not running.\x1B[0m");
9277
- console.error("");
9278
- console.error(` Project: ${error.projectRoot}`);
9279
- console.error("");
9280
- console.error("Start the Unity Editor for this project and try again.");
9578
+ if (error instanceof UnityNotRunningError || error instanceof UnityServerNotRunningError) {
9579
+ for (const line of getProjectResolutionErrorLines(error)) {
9580
+ console.error(line.startsWith("Error: ") ? `\x1B[31m${line}\x1B[0m` : line);
9581
+ }
9281
9582
  process.exit(1);
9282
9583
  }
9283
9584
  if (error instanceof ProjectMismatchError) {
9284
- console.error("\x1B[31mError: Unity Editor for this project is not running.\x1B[0m");
9285
- console.error("");
9286
- console.error(` Project: ${error.expectedProjectRoot}`);
9287
- console.error(` Connected to: ${error.connectedProjectRoot}`);
9288
- console.error("");
9289
- console.error("Another Unity instance was found, but it belongs to a different project.");
9290
- console.error(
9291
- "Start the Unity Editor for this project, or use --project-path to specify the target."
9292
- );
9585
+ for (const line of getProjectResolutionErrorLines(error)) {
9586
+ console.error(line.startsWith("Error: ") ? `\x1B[31m${line}\x1B[0m` : line);
9587
+ }
9293
9588
  process.exit(1);
9294
9589
  }
9295
9590
  const message = error instanceof Error ? error.message : String(error);
@@ -9412,9 +9707,7 @@ compdef _uloop uloop`;
9412
9707
  }
9413
9708
  function getInstalledVersion(callback) {
9414
9709
  const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
9415
- const child = (0, import_child_process.spawn)(npmCommand, ["list", "-g", "uloop-cli", "--json"], {
9416
- shell: true
9417
- });
9710
+ const child = (0, import_child_process.spawn)(npmCommand, ["list", "-g", "uloop-cli", "--json"]);
9418
9711
  let stdout = "";
9419
9712
  child.stdout.on("data", (data) => {
9420
9713
  stdout += data.toString();
@@ -9461,8 +9754,7 @@ function updateCli() {
9461
9754
  console.log("Updating uloop-cli to the latest version...");
9462
9755
  const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
9463
9756
  const child = (0, import_child_process.spawn)(npmCommand, ["install", "-g", "uloop-cli@latest"], {
9464
- stdio: "inherit",
9465
- shell: true
9757
+ stdio: "inherit"
9466
9758
  });
9467
9759
  child.on("close", (code) => {
9468
9760
  if (code === 0) {
@@ -9755,5 +10047,12 @@ async function main() {
9755
10047
  }
9756
10048
  program2.parse();
9757
10049
  }
9758
- void main();
10050
+ if (process.env.JEST_WORKER_ID === void 0) {
10051
+ void main();
10052
+ }
10053
+ // Annotate the CommonJS export names for ESM import in node:
10054
+ 0 && (module.exports = {
10055
+ getInstalledVersion,
10056
+ updateCli
10057
+ });
9759
10058
  //# sourceMappingURL=cli.bundle.cjs.map