lawspec 0.31.1 → 0.31.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +89 -2
  2. package/README.md +85 -9
  3. package/api.mjs +14 -9
  4. package/authoring.mjs +899 -0
  5. package/beam-coverage.mjs +190 -65
  6. package/beam-doctor.mjs +343 -124
  7. package/bin/lawspec.mjs +1949 -661
  8. package/build.json +134 -128
  9. package/component-packages.mjs +662 -176
  10. package/component.d.ts +82 -20
  11. package/component.mjs +317 -94
  12. package/core.wasm +2 -2
  13. package/core_jsffi.js +5 -5
  14. package/doctor.mjs +558 -299
  15. package/examples-command.mjs +44 -23
  16. package/failure-database.mjs +60 -17
  17. package/files.mjs +122 -62
  18. package/index.d.ts +585 -312
  19. package/input-files.mjs +90 -25
  20. package/launcher.mjs +72 -31
  21. package/learn/coverage.json +184 -112
  22. package/learn/curriculum.json +4 -1
  23. package/learn/vendor/fantomas/{LawSpec.Learn.Formatter.5arcua4vy0.wasm → LawSpec.Learn.Formatter.poiijdbsl9.wasm} +0 -0
  24. package/learn/vendor/fantomas/dotnet.js +3 -3
  25. package/learn/vendor/manifest.json +4 -8
  26. package/lsp.mjs +444 -133
  27. package/mcp.mjs +250 -0
  28. package/native-evidence.mjs +668 -182
  29. package/native-examples.mjs +56 -19
  30. package/native-host.mjs +136 -42
  31. package/native-parsers/clojure.LICENSE +121 -0
  32. package/native-parsers/clojure.wasm +0 -0
  33. package/native-parsers/csharp.LICENSE +21 -0
  34. package/native-parsers/csharp.wasm +0 -0
  35. package/native-parsers/elixir.LICENSE +176 -0
  36. package/native-parsers/elixir.wasm +0 -0
  37. package/native-parsers/erlang.LICENSE +201 -0
  38. package/native-parsers/erlang.wasm +0 -0
  39. package/native-parsers/fsharp.LICENSE +21 -0
  40. package/native-parsers/fsharp.wasm +0 -0
  41. package/native-parsers/gleam.LICENSE +202 -0
  42. package/native-parsers/gleam.wasm +0 -0
  43. package/native-parsers/go.LICENSE +21 -0
  44. package/native-parsers/go.wasm +0 -0
  45. package/native-parsers/groovy.LICENSE +21 -0
  46. package/native-parsers/groovy.wasm +0 -0
  47. package/native-parsers/haskell.LICENSE +21 -0
  48. package/native-parsers/haskell.wasm +0 -0
  49. package/native-parsers/java.LICENSE +21 -0
  50. package/native-parsers/java.wasm +0 -0
  51. package/native-parsers/javascript.LICENSE +21 -0
  52. package/native-parsers/javascript.wasm +0 -0
  53. package/native-parsers/kotlin.LICENSE +9 -0
  54. package/native-parsers/kotlin.wasm +0 -0
  55. package/native-parsers/lock.json +114 -0
  56. package/native-parsers/prolog.LICENSE +21 -0
  57. package/native-parsers/prolog.wasm +0 -0
  58. package/native-parsers/python.LICENSE +21 -0
  59. package/native-parsers/python.wasm +0 -0
  60. package/native-parsers/rust.LICENSE +21 -0
  61. package/native-parsers/rust.wasm +0 -0
  62. package/native-parsers/scala.LICENSE +21 -0
  63. package/native-parsers/scala.wasm +0 -0
  64. package/native-parsers/swift.LICENSE +21 -0
  65. package/native-parsers/swift.wasm +0 -0
  66. package/native-parsers/typescript.LICENSE +21 -0
  67. package/native-parsers/typescript.wasm +0 -0
  68. package/node-events-reporter.mjs +41 -17
  69. package/package.json +4 -3
  70. package/project.mjs +338 -0
  71. package/proof.d.ts +93 -19
  72. package/proof.mjs +1538 -447
  73. package/read-only-hpack.mjs +6 -5
  74. package/scala-build-state.mjs +131 -41
  75. package/scala-coverage.mjs +57 -34
  76. package/scalars.mjs +23 -8
  77. package/templates.mjs +566 -617
  78. package/test-command.mjs +1671 -521
  79. package/learn/vendor/fantomas/LawSpec.Learn.Formatter.u1ne3a6xd2.wasm +0 -0
@@ -1,58 +1,75 @@
1
1
  // Generated from templates/npm/examples-command.mjs by lawspec-dev generate. Do not edit.
2
- import { readFile, readdir, mkdir } from "node:fs/promises";
3
- import path from "node:path";
4
- import { createCompiler } from "./api.mjs";
5
- import { programTargets as targets, artifactTargets } from "./templates.mjs";
6
- import { safePath, planWrites, applyWrites } from "./files.mjs";
7
- import { exportNativePayments } from "./native-examples.mjs";
2
+ import {readFile, readdir, mkdir} from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import {createCompiler} from './api.mjs';
5
+ import {programTargets as targets, artifactTargets} from './templates.mjs';
6
+ import {safePath, planWrites, applyWrites} from './files.mjs';
7
+ import {exportNativePayments} from './native-examples.mjs';
8
8
 
9
- export async function generateExamples(options) {
9
+ export async function generateExamples(options)
10
+ {
10
11
  const selected = options.target ? [options.target] : targets;
11
12
  if (selected.some(t => artifactTargets.includes(t)))
12
- throw new Error("examples exports program targets; use init and generate for artifact targets");
13
- if (selected.some((t) => !targets.includes(t)))
13
+ throw new Error(
14
+ 'examples exports program targets; use init and generate for artifact targets',
15
+ );
16
+ if (selected.some(t => !targets.includes(t)))
14
17
  throw new Error(`Unknown target: ${options.target}`);
15
- if (options.example !== undefined) {
16
- if (options.example !== "payments") throw new Error(`Unknown example: ${options.example}`);
18
+ if (options.example !== undefined)
19
+ {
20
+ if (options.example !== 'payments')
21
+ throw new Error(`Unknown example: ${options.example}`);
17
22
  return exportNativePayments(options, selected);
18
23
  }
19
24
  const projectRoot = process.cwd();
20
- const outputDirectory = options.output || "example_artifacts";
25
+ const outputDirectory = options.output || 'example_artifacts';
21
26
  const root = await safePath(projectRoot, outputDirectory);
22
- const directory = new URL("./examples/specs/", import.meta.url);
27
+ const directory = new URL('./examples/specs/', import.meta.url);
23
28
  const sources = await Promise.all(
24
29
  (await readdir(directory))
25
- .filter((n) => n.endsWith(".lawspec"))
30
+ .filter(n => n.endsWith('.lawspec'))
26
31
  .sort()
27
- .map(async (name) => ({
32
+ .map(async name => ({
28
33
  path: name,
29
- content: await readFile(new URL(name, directory), "utf8"),
34
+ content: await readFile(new URL(name, directory), 'utf8'),
30
35
  })),
31
36
  );
32
37
  const compiler = await createCompiler();
33
38
  const artifacts = [];
34
- for (const target of selected) {
39
+ for (const target of selected)
40
+ {
35
41
  const result = await compiler.planGeneration({
36
42
  schemaVersion: 5,
37
- languageProfile: '1.0-rc.2', verification: {layers: ['proof','exhaustive','property','examples','runtime','model']},
43
+ languageProfile: '1.0-rc.2',
44
+ verification: {
45
+ layers: [
46
+ 'proof',
47
+ 'exhaustive',
48
+ 'property',
49
+ 'examples',
50
+ 'runtime',
51
+ 'model',
52
+ ],
53
+ },
38
54
  sources,
39
55
  target,
40
56
  machineBits: options.machineBits ?? 64,
41
57
  minify: options.minify === true,
42
58
  });
43
59
  if (result.diagnostics.length)
44
- throw Object.assign(new Error("Bundled examples failed to compile"), {
60
+ throw Object.assign(new Error('Bundled examples failed to compile'), {
45
61
  diagnostics: result.diagnostics,
46
62
  });
47
63
  artifacts.push(result.files);
48
64
  }
49
65
  // Recheck the destination after compilation, before creating output files.
50
66
  await safePath(projectRoot, outputDirectory);
51
- await mkdir(root, { recursive: true });
67
+ await mkdir(root, {recursive: true});
52
68
  const plans = [];
53
- for (let i = 0; i < selected.length; i++) {
69
+ for (let i = 0; i < selected.length; i++)
70
+ {
54
71
  const targetRoot = await safePath(root, selected[i]);
55
- await mkdir(targetRoot, { recursive: true });
72
+ await mkdir(targetRoot, {recursive: true});
56
73
  plans.push(await planWrites(targetRoot, artifacts[i]));
57
74
  }
58
75
  await applyWrites(plans);
@@ -60,7 +77,11 @@ export async function generateExamples(options) {
60
77
  target: selected[i],
61
78
  languageProfile: '1.0-rc.2',
62
79
  directory: plan.root,
63
- files: artifacts[i].map((f) => ({ path: f.path, ownership: f.ownership, placement: f.placement })),
80
+ files: artifacts[i].map(f => ({
81
+ path: f.path,
82
+ ownership: f.ownership,
83
+ placement: f.placement,
84
+ })),
64
85
  changes: plan.changes.length,
65
86
  preservedAdapters: plan.preserved,
66
87
  adapterUpdates: plan.adapterUpdates,
@@ -1,46 +1,89 @@
1
1
  // Generated from templates/npm/failure-database.mjs by lawspec-dev generate. Do not edit.
2
2
  // Failed seeds and framework counterexamples belong to one project root.
3
3
  import {createHash} from 'node:crypto';
4
- import {cp, mkdir, mkdtemp, readFile, rename, rm, writeFile} from 'node:fs/promises';
4
+ import {
5
+ cp,
6
+ mkdir,
7
+ mkdtemp,
8
+ readFile,
9
+ rename,
10
+ rm,
11
+ writeFile,
12
+ } from 'node:fs/promises';
5
13
  import path from 'node:path';
6
14
  import {readOptional} from './files.mjs';
7
15
 
8
- export const projectKey = root => createHash('sha256').update(path.resolve(root)).digest('hex').slice(0, 12);
16
+ export const projectKey = root =>
17
+ createHash('sha256').update(path.resolve(root)).digest('hex').slice(0, 12);
9
18
 
10
- function parseDatabase(text) {
19
+ function parseDatabase(text)
20
+ {
11
21
  const database = JSON.parse(text);
12
22
  if (!database || typeof database !== 'object' || Array.isArray(database))
13
- throw new Error('The failure database must contain a map of law identities to failures');
23
+ throw new Error(
24
+ 'The failure database must contain a map of law identities to failures',
25
+ );
14
26
  return database;
15
27
  }
16
28
 
17
- export async function failureDatabase(configRoot, language, root) {
29
+ export async function failureDatabase(configRoot, language, root)
30
+ {
18
31
  const legacy = path.join(configRoot, '.lawspec/failures', language);
19
32
  const directory = path.join(legacy, projectKey(root));
20
33
  const file = path.join(directory, 'laws.json');
21
34
  const current = await readOptional(file);
22
- if (current !== null) return {directory, file, database: parseDatabase(current)};
35
+ if (current !== null)
36
+ return {directory, file, database: parseDatabase(current)};
23
37
 
24
38
  // Old databases identify only the language. Preserve them and copy their
25
39
  // failures once into each project's initial state so no counterexample is
26
40
  // lost. Subsequent passes and failures change only that project's copy.
27
- const database = parseDatabase((await readOptional(path.join(legacy, 'laws.json'))) ?? '{}');
41
+ const database = parseDatabase(
42
+ (await readOptional(path.join(legacy, 'laws.json'))) ?? '{}',
43
+ );
28
44
  await mkdir(legacy, {recursive: true});
29
45
  const temporary = await mkdtemp(path.join(legacy, '.migrate-'));
30
- try {
31
- for (const name of ['inputs', 'hypothesis', 'proptest-regressions.txt']) {
32
- try { await cp(path.join(legacy, name), path.join(temporary, name), {recursive: true}); }
33
- catch (error) { if (error.code !== 'ENOENT') throw error; }
46
+ try
47
+ {
48
+ for (const name of ['inputs', 'hypothesis', 'proptest-regressions.txt'])
49
+ {
50
+ try
51
+ {
52
+ await cp(path.join(legacy, name), path.join(temporary, name), {
53
+ recursive: true,
54
+ });
55
+ }
56
+ catch (error)
57
+ {
58
+ if (error.code !== 'ENOENT') throw error;
59
+ }
34
60
  }
35
- await writeFile(path.join(temporary, 'laws.json'), JSON.stringify(database, null, 2) + '\n');
36
- try { await rename(temporary, directory); }
37
- catch (error) {
61
+ await writeFile(
62
+ path.join(temporary, 'laws.json'),
63
+ JSON.stringify(database, null, 2) + '\n',
64
+ );
65
+ try
66
+ {
67
+ await rename(temporary, directory);
68
+ }
69
+ catch (error)
70
+ {
38
71
  // Another invocation may have initialized the same project while this
39
72
  // one copied the legacy data. Its complete database takes precedence.
40
- if (!['EEXIST', 'ENOTEMPTY'].includes(error.code) || await readOptional(file) === null) throw error;
73
+ if (
74
+ !['EEXIST', 'ENOTEMPTY'].includes(error.code) ||
75
+ (await readOptional(file)) === null
76
+ )
77
+ throw error;
41
78
  }
42
- } finally {
79
+ }
80
+ finally
81
+ {
43
82
  await rm(temporary, {recursive: true, force: true});
44
83
  }
45
- return {directory, file, database: parseDatabase(await readFile(file, 'utf8'))};
84
+ return {
85
+ directory,
86
+ file,
87
+ database: parseDatabase(await readFile(file, 'utf8')),
88
+ };
46
89
  }
package/files.mjs CHANGED
@@ -10,106 +10,162 @@ import {
10
10
  lstat,
11
11
  realpath,
12
12
  link,
13
- } from "node:fs/promises";
14
- import path from "node:path";
15
- import crypto from "node:crypto";
16
- export const digest = (text) =>
17
- crypto.createHash("sha256").update(text).digest("hex");
13
+ } from 'node:fs/promises';
14
+ import path from 'node:path';
15
+ import crypto from 'node:crypto';
16
+ export const digest = text =>
17
+ crypto.createHash('sha256').update(text).digest('hex');
18
18
  // Share source discovery between CLI commands.
19
- export async function collectSources(root,entries,relativeTo=root){
20
- const files=[];
21
- async function visit(file){
22
- const info=await lstat(file);
23
- if(info.isSymbolicLink())throw new Error(`Symbolic links are not supported in LawSpec sources: ${file}`);
24
- if(info.isDirectory())for(const entry of (await readdir(file)).sort())await visit(path.join(file,entry));
25
- else if(file.endsWith('.lawspec'))files.push(file);
19
+ export async function collectSources(root, entries, relativeTo = root)
20
+ {
21
+ const files = [];
22
+ async function visit(file)
23
+ {
24
+ const info = await lstat(file);
25
+ if (info.isSymbolicLink())
26
+ throw new Error(
27
+ `Symbolic links are not supported in LawSpec sources: ${file}`,
28
+ );
29
+ if (info.isDirectory())
30
+ for (const entry of (await readdir(file)).sort())
31
+ await visit(path.join(file, entry));
32
+ else if (file.endsWith('.lawspec')) files.push(file);
26
33
  }
27
- if(!Array.isArray(entries)||entries.some(entry=>typeof entry!=='string'))throw new Error('sources must be an array of paths');
28
- for(const source of entries)await visit(path.resolve(root,source));
29
- if(!files.length)throw new Error('No .lawspec source files found');
30
- return Promise.all([...new Set(files)].sort().map(async file=>({
31
- path:path.relative(relativeTo,file).split(path.sep).join('/'),content:await readFile(file,'utf8')})));
34
+ if (
35
+ !Array.isArray(entries) ||
36
+ entries.some(entry => typeof entry !== 'string')
37
+ )
38
+ throw new Error('sources must be an array of paths');
39
+ for (const source of entries) await visit(path.resolve(root, source));
40
+ if (!files.length) throw new Error('No .lawspec source files found');
41
+ return Promise.all(
42
+ [...new Set(files)].sort().map(async file => ({
43
+ path: path.relative(relativeTo, file).split(path.sep).join('/'),
44
+ content: await readFile(file, 'utf8'),
45
+ })),
46
+ );
32
47
  }
33
- export async function readOptional(file) {
34
- try {
35
- return await readFile(file, "utf8");
36
- } catch (e) {
37
- if (e.code === "ENOENT") return null;
48
+ export async function readOptional(file)
49
+ {
50
+ try
51
+ {
52
+ return await readFile(file, 'utf8');
53
+ }
54
+ catch (e)
55
+ {
56
+ if (e.code === 'ENOENT') return null;
38
57
  throw e;
39
58
  }
40
59
  }
41
- export async function safePath(root, relative) {
60
+ export async function safePath(root, relative)
61
+ {
42
62
  if (
43
- typeof relative !== "string" ||
63
+ typeof relative !== 'string' ||
44
64
  !relative ||
45
65
  path.isAbsolute(relative) ||
46
- relative.split(/[\\/]/).some((p) => p === ".." || p === ".")
66
+ relative.split(/[\\/]/).some(p => p === '..' || p === '.')
47
67
  )
48
68
  throw new Error(`Unsafe output path: ${relative}`);
49
69
  const resolved = path.resolve(root, relative);
50
70
  if (!resolved.startsWith(path.resolve(root) + path.sep))
51
71
  throw new Error(`Output escapes project: ${relative}`);
52
- const realRoot = await realpath(root);
72
+ let realRoot;
73
+ try
74
+ {
75
+ const info = await stat(root);
76
+ if (!info.isDirectory())
77
+ {
78
+ throw new Error(`Output root is not a directory: ${path.resolve(root)}`);
79
+ }
80
+ realRoot = await realpath(root);
81
+ }
82
+ catch (error)
83
+ {
84
+ if (error.code === 'ENOENT')
85
+ {
86
+ throw new Error(
87
+ `Output root does not exist: ${path.resolve(root)}. Create it or initialize the target before generation.`,
88
+ {cause: error},
89
+ );
90
+ }
91
+ throw error;
92
+ }
53
93
  let cursor = root;
54
- for (const part of relative.split("/")) {
94
+ for (const part of relative.split('/'))
95
+ {
55
96
  cursor = path.join(cursor, part);
56
- try {
97
+ try
98
+ {
57
99
  const stat = await lstat(cursor);
58
100
  if (stat.isSymbolicLink())
59
101
  throw new Error(`Refusing symbolic-link output: ${relative}`);
60
102
  const real = await realpath(cursor);
61
103
  if (real !== realRoot && !real.startsWith(realRoot + path.sep))
62
104
  throw new Error(`Output escapes project: ${relative}`);
63
- } catch (e) {
64
- if (e.code !== "ENOENT") throw e;
105
+ }
106
+ catch (e)
107
+ {
108
+ if (e.code !== 'ENOENT') throw e;
65
109
  }
66
110
  }
67
111
  return resolved;
68
112
  }
69
- export async function atomicWrite(file, content, exclusive = false) {
70
- await mkdir(path.dirname(file), { recursive: true });
113
+ export async function atomicWrite(file, content, exclusive = false)
114
+ {
115
+ await mkdir(path.dirname(file), {recursive: true});
71
116
  const tmp = `${file}.lawspec-${crypto.randomUUID()}.tmp`;
72
- try {
73
- await writeFile(tmp, content, { flag: "wx" });
117
+ try
118
+ {
119
+ await writeFile(tmp, content, {flag: 'wx'});
74
120
  if (exclusive) await link(tmp, file);
75
121
  else await rename(tmp, file);
76
- } finally {
77
- try {
122
+ }
123
+ finally
124
+ {
125
+ try
126
+ {
78
127
  await unlink(tmp);
79
- } catch (e) {
80
- if (e.code !== "ENOENT") throw e;
128
+ }
129
+ catch (e)
130
+ {
131
+ if (e.code !== 'ENOENT') throw e;
81
132
  }
82
133
  }
83
134
  }
84
- export async function planWrites(root, artifacts, {manifest = ".lawspec/generated.json"} = {}) {
135
+ export async function planWrites(
136
+ root,
137
+ artifacts,
138
+ {manifest = '.lawspec/generated.json'} = {},
139
+ )
140
+ {
85
141
  const manifestPath = await safePath(root, manifest);
86
142
  const previousText = await readOptional(manifestPath);
87
143
  const previous =
88
- previousText === null
89
- ? { version: 1, files: {} }
90
- : JSON.parse(previousText);
144
+ previousText === null ? {version: 1, files: {}} : JSON.parse(previousText);
91
145
  if (
92
146
  previous.version !== 1 ||
93
147
  !previous.files ||
94
- typeof previous.files !== "object"
148
+ typeof previous.files !== 'object'
95
149
  )
96
- throw new Error("Invalid ownership manifest");
150
+ throw new Error('Invalid ownership manifest');
97
151
  const seen = new Set();
98
152
  const changes = [];
99
153
  const preserved = [];
100
154
  const adapterUpdates = [];
101
155
  const adapterHashes = {};
102
156
  const next = {};
103
- for (const artifact of artifacts) {
157
+ for (const artifact of artifacts)
158
+ {
104
159
  if (seen.has(artifact.path))
105
160
  throw new Error(`Duplicate output: ${artifact.path}`);
106
161
  seen.add(artifact.path);
107
162
  const file = await safePath(root, artifact.path);
108
163
  const old = await readOptional(file);
109
- if (artifact.ownership === "user") {
164
+ if (artifact.ownership === 'user')
165
+ {
110
166
  if (
111
167
  artifact.adapterReference !== undefined &&
112
- typeof artifact.adapterReference !== "string"
168
+ typeof artifact.adapterReference !== 'string'
113
169
  )
114
170
  throw new Error(`Invalid adapter reference: ${artifact.path}`);
115
171
  // Compare compiler-owned canonical scaffolds, never normalized user code.
@@ -127,7 +183,7 @@ export async function planWrites(root, artifacts, {manifest = ".lawspec/generate
127
183
  });
128
184
  if (old === null)
129
185
  changes.push({
130
- action: "create",
186
+ action: 'create',
131
187
  file,
132
188
  relative: artifact.path,
133
189
  content: artifact.content,
@@ -136,8 +192,8 @@ export async function planWrites(root, artifacts, {manifest = ".lawspec/generate
136
192
  else preserved.push(artifact.path);
137
193
  continue;
138
194
  }
139
- if (artifact.ownership !== "generated")
140
- throw new Error("Unknown artifact ownership");
195
+ if (artifact.ownership !== 'generated')
196
+ throw new Error('Unknown artifact ownership');
141
197
  const recorded = previous.files[artifact.path];
142
198
  if (old !== null && (!recorded || digest(old) !== recorded))
143
199
  throw new Error(
@@ -146,54 +202,58 @@ export async function planWrites(root, artifacts, {manifest = ".lawspec/generate
146
202
  next[artifact.path] = digest(artifact.content);
147
203
  if (old !== artifact.content)
148
204
  changes.push({
149
- action: old === null ? "create" : "update",
205
+ action: old === null ? 'create' : 'update',
150
206
  file,
151
207
  relative: artifact.path,
152
208
  content: artifact.content,
153
209
  expected: old,
154
210
  });
155
211
  }
156
- for (const [relative, hash] of Object.entries(previous.files)) {
212
+ for (const [relative, hash] of Object.entries(previous.files))
213
+ {
157
214
  if (seen.has(relative)) continue;
158
215
  const file = await safePath(root, relative);
159
216
  const old = await readOptional(file);
160
217
  if (old === null) continue;
161
218
  if (digest(old) !== hash)
162
219
  throw new Error(`Refusing to remove edited generated file: ${relative}`);
163
- changes.push({ action: "remove", file, relative, expected: old });
220
+ changes.push({action: 'remove', file, relative, expected: old});
164
221
  }
165
222
  const manifestContent =
166
223
  JSON.stringify(
167
- { version: 1, files: next, adapters: adapterHashes },
224
+ {version: 1, files: next, adapters: adapterHashes},
168
225
  null,
169
226
  2,
170
- ) + "\n";
227
+ ) + '\n';
171
228
  if (manifestContent !== previousText)
172
229
  changes.push({
173
- action: previousText === null ? "create" : "update",
230
+ action: previousText === null ? 'create' : 'update',
174
231
  file: manifestPath,
175
232
  relative: manifest,
176
233
  content: manifestContent,
177
234
  expected: previousText,
178
235
  });
179
- return { root, changes, preserved, adapterUpdates };
236
+ return {root, changes, preserved, adapterUpdates};
180
237
  }
181
- export async function applyWrites(plans) {
238
+ export async function applyWrites(plans)
239
+ {
182
240
  // Recheck every file before the first mutation, including concurrent edits since planning.
183
241
  for (const plan of plans)
184
- for (const change of plan.changes) {
242
+ for (const change of plan.changes)
243
+ {
185
244
  await safePath(plan.root, change.relative);
186
245
  if ((await readOptional(change.file)) !== change.expected)
187
246
  throw new Error(`File changed during generation: ${change.relative}`);
188
247
  }
189
248
  for (const plan of plans)
190
- for (const change of plan.changes) {
191
- if (change.action === "remove") await unlink(change.file);
249
+ for (const change of plan.changes)
250
+ {
251
+ if (change.action === 'remove') await unlink(change.file);
192
252
  else
193
253
  await atomicWrite(
194
254
  change.file,
195
255
  change.content,
196
- change.action === "create",
256
+ change.action === 'create',
197
257
  );
198
258
  }
199
259
  }