@spotpatch/vite 1.2.1 → 1.2.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/index.js CHANGED
@@ -481,7 +481,7 @@ import path2 from "path";
481
481
  // package.json
482
482
  var package_default = {
483
483
  name: "@spotpatch/vite",
484
- version: "1.2.1",
484
+ version: "1.2.2",
485
485
  description: "Vite development plugin for SpotPatch.",
486
486
  license: "MIT",
487
487
  repository: {
@@ -1818,37 +1818,89 @@ async function handleAgentRequest(request, response, options, route, writeSucces
1818
1818
  }
1819
1819
 
1820
1820
  // src/server/editor.ts
1821
+ import { spawn } from "child_process";
1821
1822
  import launchEditor from "launch-editor";
1822
- var EDITOR_STARTUP_GRACE_MS = 150;
1823
- function editorCommand(editor) {
1824
- if (editor === "vscode") {
1825
- return "code";
1826
- }
1827
- if (editor === "cursor") {
1823
+ var EDITOR_STARTUP_GRACE_MS = 300;
1824
+ function normalizedEditorEnvironment(environment) {
1825
+ return [
1826
+ environment.TERM_PROGRAM,
1827
+ environment.VSCODE_GIT_ASKPASS_NODE,
1828
+ environment.VSCODE_GIT_ASKPASS_MAIN,
1829
+ environment.GIT_ASKPASS
1830
+ ].filter((value) => typeof value === "string").join("\n").replaceAll("\\", "/").toLowerCase();
1831
+ }
1832
+ function detectIntegratedEditor(environment) {
1833
+ const signature = normalizedEditorEnvironment(environment);
1834
+ if (signature === "cursor" || signature.includes("/cursor")) {
1828
1835
  return "cursor";
1829
1836
  }
1837
+ if (signature === "vscode" || signature.includes("visual studio code") || /(^|\/)(code|code-insiders)(\.exe)?($|\/)/u.test(signature)) {
1838
+ return "vscode";
1839
+ }
1830
1840
  return void 0;
1831
1841
  }
1832
- var launchConfiguredEditor = (target, editor) => new Promise((resolve, reject) => {
1833
- let settled = false;
1834
- const startupTimer = setTimeout(() => {
1835
- settled = true;
1836
- resolve();
1837
- }, EDITOR_STARTUP_GRACE_MS);
1838
- const rejectStartup = () => {
1839
- if (settled) {
1840
- return;
1841
- }
1842
- settled = true;
1843
- clearTimeout(startupTimer);
1844
- reject(new Error("The configured editor could not be started."));
1845
- };
1846
- try {
1847
- launchEditor(target, editorCommand(editor), rejectStartup);
1848
- } catch {
1849
- rejectStartup();
1850
- }
1842
+ function editorCommand(editor) {
1843
+ return editor === "cursor" ? "cursor" : "code";
1844
+ }
1845
+ var DEFAULT_DEPENDENCIES2 = Object.freeze({
1846
+ environment: process.env,
1847
+ fallbackLauncher: launchEditor,
1848
+ processSpawner: (command, arguments_, options) => spawn(command, [...arguments_], options),
1849
+ startupGraceMs: EDITOR_STARTUP_GRACE_MS
1851
1850
  });
1851
+ function createEditorLauncher(dependencies = DEFAULT_DEPENDENCIES2) {
1852
+ return (target, configuredEditor) => {
1853
+ const integratedEditor = detectIntegratedEditor(dependencies.environment);
1854
+ const resolvedEditor = configuredEditor === "auto" ? integratedEditor : configuredEditor;
1855
+ return new Promise((resolve, reject) => {
1856
+ let settled = false;
1857
+ const settle = (error, editor = resolvedEditor ?? "auto") => {
1858
+ if (settled) {
1859
+ return;
1860
+ }
1861
+ settled = true;
1862
+ clearTimeout(startupTimer);
1863
+ if (error === void 0) {
1864
+ resolve(editor);
1865
+ } else {
1866
+ reject(error);
1867
+ }
1868
+ };
1869
+ const startupTimer = setTimeout(settle, dependencies.startupGraceMs);
1870
+ const rejectStartup = () => {
1871
+ settle(new Error("The configured editor could not be started."));
1872
+ };
1873
+ try {
1874
+ if (resolvedEditor === void 0) {
1875
+ dependencies.fallbackLauncher(target, void 0, rejectStartup);
1876
+ return;
1877
+ }
1878
+ const child = dependencies.processSpawner(
1879
+ editorCommand(resolvedEditor),
1880
+ ["--goto", target],
1881
+ {
1882
+ env: dependencies.environment,
1883
+ stdio: "ignore",
1884
+ windowsHide: true
1885
+ }
1886
+ );
1887
+ child.once("error", rejectStartup);
1888
+ child.once("exit", (code, signal) => {
1889
+ if (code === 0) {
1890
+ settle(void 0, resolvedEditor);
1891
+ return;
1892
+ }
1893
+ if (code !== null || signal !== null) {
1894
+ rejectStartup();
1895
+ }
1896
+ });
1897
+ } catch {
1898
+ rejectStartup();
1899
+ }
1900
+ });
1901
+ };
1902
+ }
1903
+ var launchConfiguredEditor = createEditorLauncher();
1852
1904
 
1853
1905
  // src/server/request-security.ts
1854
1906
  import { timingSafeEqual } from "crypto";
@@ -2031,7 +2083,8 @@ async function handleOpenEditor(request, options) {
2031
2083
  const target = `${sourcePath}:${String(body.line)}:${String(body.column)}`;
2032
2084
  const editorLauncher = options.editorLauncher ?? launchConfiguredEditor;
2033
2085
  try {
2034
- await editorLauncher(target, options.options.editor);
2086
+ const editor = await editorLauncher(target, options.options.editor);
2087
+ return Object.freeze({ editor });
2035
2088
  } catch (error) {
2036
2089
  options.logger?.warn(
2037
2090
  `[spotpatch:server] ${options.options.editor === "auto" ? "The detected editor" : options.options.editor} rejected an editor request.`
@@ -2040,7 +2093,6 @@ async function handleOpenEditor(request, options) {
2040
2093
  cause: error
2041
2094
  });
2042
2095
  }
2043
- return Object.freeze({ editor: options.options.editor });
2044
2096
  }
2045
2097
  function createSpotPatchMiddleware(options) {
2046
2098
  return (request, response, next) => {