@algolia/wizard 0.103.0-rc.217.760 → 0.103.0-rc.217.761

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.
Files changed (2) hide show
  1. package/dist/main.js +42 -25
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -2467,7 +2467,7 @@ async function ensureApplication(resumeAppId) {
2467
2467
  // package.json
2468
2468
  var package_default = {
2469
2469
  name: "@algolia/wizard",
2470
- version: "0.103.0-rc.217.760",
2470
+ version: "0.103.0-rc.217.761",
2471
2471
  description: "Magically implement Algolia functionality in your codebase",
2472
2472
  type: "module",
2473
2473
  engines: {
@@ -3216,6 +3216,18 @@ async function hasSymlinkParent(ctx, target) {
3216
3216
  }
3217
3217
  return false;
3218
3218
  }
3219
+ var fileLocks = /* @__PURE__ */ new Map();
3220
+ async function withFileLock(target, fn) {
3221
+ const previous = fileLocks.get(target) ?? Promise.resolve();
3222
+ const run2 = previous.then(fn);
3223
+ const settled = run2.catch(() => void 0);
3224
+ fileLocks.set(target, settled);
3225
+ try {
3226
+ return await run2;
3227
+ } finally {
3228
+ if (fileLocks.get(target) === settled) fileLocks.delete(target);
3229
+ }
3230
+ }
3219
3231
  function symlinkTargetError(target) {
3220
3232
  return `Refused: ${target} is a symbolic link.`;
3221
3233
  }
@@ -3464,7 +3476,10 @@ function writeFileTool(ctx) {
3464
3476
  return secretEnvWriteRefusal(filePath);
3465
3477
  }
3466
3478
  try {
3467
- const writeError = await safeWriteFile(ctx, resolved2.target, content);
3479
+ const writeError = await withFileLock(
3480
+ resolved2.target,
3481
+ () => safeWriteFile(ctx, resolved2.target, content)
3482
+ );
3468
3483
  if (writeError) return writeError;
3469
3484
  useWizard.getState().recordWrittenFile(resolved2.target);
3470
3485
  return `Wrote to ${filePath}`;
@@ -3530,29 +3545,31 @@ function editFileTool(ctx) {
3530
3545
  return "Error: oldString and newString are identical. No change made.";
3531
3546
  }
3532
3547
  try {
3533
- const unsafe = await validateSafeWriteTarget(ctx, resolved2.target);
3534
- if (unsafe) return unsafe;
3535
- let content;
3536
- try {
3537
- content = await readFile5(resolved2.target, "utf8");
3538
- } catch (err) {
3539
- if (err.code === "ENOENT") {
3540
- return `Error: ${filePath} does not exist. To create it, use writeFile.`;
3548
+ return await withFileLock(resolved2.target, async () => {
3549
+ const unsafe = await validateSafeWriteTarget(ctx, resolved2.target);
3550
+ if (unsafe) return unsafe;
3551
+ let content;
3552
+ try {
3553
+ content = await readFile5(resolved2.target, "utf8");
3554
+ } catch (err) {
3555
+ if (err.code === "ENOENT") {
3556
+ return `Error: ${filePath} does not exist. To create it, use writeFile.`;
3557
+ }
3558
+ throw err;
3541
3559
  }
3542
- throw err;
3543
- }
3544
- const matches = countOccurrences(content, oldString);
3545
- if (matches === 0) {
3546
- return `Error: oldString not found in ${filePath}. Read the file again and copy the exact text, including whitespace.`;
3547
- }
3548
- if (matches > 1 && !replaceAll) {
3549
- return `Error: oldString matches ${matches} places in ${filePath}. Add surrounding lines to make it unique, or set replaceAll to true.`;
3550
- }
3551
- const updated = replaceAll ? content.split(oldString).join(newString) : replaceFirst(content, oldString, newString);
3552
- const writeError = await safeWriteFile(ctx, resolved2.target, updated);
3553
- if (writeError) return writeError;
3554
- useWizard.getState().recordWrittenFile(resolved2.target);
3555
- return matches > 1 ? `Edited ${filePath} (${matches} replacements)` : `Edited ${filePath}. ${editedSnippet(updated, content.indexOf(oldString), newString)}`;
3560
+ const matches = countOccurrences(content, oldString);
3561
+ if (matches === 0) {
3562
+ return `Error: oldString not found in ${filePath}. Read the file again and copy the exact text, including whitespace.`;
3563
+ }
3564
+ if (matches > 1 && !replaceAll) {
3565
+ return `Error: oldString matches ${matches} places in ${filePath}. Add surrounding lines to make it unique, or set replaceAll to true.`;
3566
+ }
3567
+ const updated = replaceAll ? content.split(oldString).join(newString) : replaceFirst(content, oldString, newString);
3568
+ const writeError = await safeWriteFile(ctx, resolved2.target, updated);
3569
+ if (writeError) return writeError;
3570
+ useWizard.getState().recordWrittenFile(resolved2.target);
3571
+ return matches > 1 ? `Edited ${filePath} (${matches} replacements)` : `Edited ${filePath}. ${editedSnippet(updated, content.indexOf(oldString), newString)}`;
3572
+ });
3556
3573
  } catch (err) {
3557
3574
  return `Error editing ${filePath}: ${err.message}`;
3558
3575
  }
@@ -10145,7 +10162,7 @@ async function resetProjectState() {
10145
10162
  // package.json with { type: 'json' }
10146
10163
  var package_default2 = {
10147
10164
  name: "@algolia/wizard",
10148
- version: "0.103.0-rc.217.760",
10165
+ version: "0.103.0-rc.217.761",
10149
10166
  description: "Magically implement Algolia functionality in your codebase",
10150
10167
  type: "module",
10151
10168
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.103.0-rc.217.760",
3
+ "version": "0.103.0-rc.217.761",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {