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