@gaganref/confect-cli 10.3.1-fork.95 → 10.6.0-fork.1
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/CHANGELOG.md +78 -0
- package/dist/Ansi.mjs +1 -2
- package/dist/BuildError.mjs +5 -5
- package/dist/BuildError.mjs.map +1 -1
- package/dist/Bundler.mjs +103 -76
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodeBlockWriter.mjs +1 -2
- package/dist/CodegenError.mjs +27 -17
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/ConfectDirectory.mjs +8 -3
- package/dist/ConfectDirectory.mjs.map +1 -1
- package/dist/ConvexConfig.mjs +23 -15
- package/dist/ConvexConfig.mjs.map +1 -1
- package/dist/ConvexDirectory.mjs +6 -4
- package/dist/ConvexDirectory.mjs.map +1 -1
- package/dist/Declaration.mjs +92 -56
- package/dist/Declaration.mjs.map +1 -1
- package/dist/DirectoryOptions.mjs +13 -8
- package/dist/DirectoryOptions.mjs.map +1 -1
- package/dist/DocName.mjs +1 -2
- package/dist/EntryPoint.mjs +17 -15
- package/dist/EntryPoint.mjs.map +1 -1
- package/dist/Evaluation.mjs +24 -13
- package/dist/Evaluation.mjs.map +1 -1
- package/dist/EvaluationWorker.mjs +5 -6
- package/dist/EvaluationWorker.mjs.map +1 -1
- package/dist/FunctionModule.mjs +85 -47
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/FunctionPath.mjs +1 -2
- package/dist/FunctionPath.mjs.map +1 -1
- package/dist/FunctionPaths.mjs +2 -3
- package/dist/GenerationSnapshot.mjs +30 -22
- package/dist/GenerationSnapshot.mjs.map +1 -1
- package/dist/GroupPath.mjs +6 -3
- package/dist/GroupPath.mjs.map +1 -1
- package/dist/GroupPaths.mjs +1 -2
- package/dist/ImplModulePath.mjs +1 -2
- package/dist/Json.mjs +13 -0
- package/dist/Json.mjs.map +1 -0
- package/dist/LeafModule.mjs +121 -41
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ManifestSections.mjs +23 -19
- package/dist/ManifestSections.mjs.map +1 -1
- package/dist/PackageSelfReference.mjs +32 -0
- package/dist/PackageSelfReference.mjs.map +1 -0
- package/dist/ProjectRoot.mjs +11 -3
- package/dist/ProjectRoot.mjs.map +1 -1
- package/dist/RelativeModulePath.mjs +1 -2
- package/dist/Remove.mjs +2 -3
- package/dist/Remove.mjs.map +1 -1
- package/dist/RestoreWatcher.mjs +1 -2
- package/dist/Rollback.mjs +7 -6
- package/dist/Rollback.mjs.map +1 -1
- package/dist/SectionFiles.mjs +77 -48
- package/dist/SectionFiles.mjs.map +1 -1
- package/dist/SnapshotError.mjs +3 -3
- package/dist/SnapshotError.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +1 -2
- package/dist/SpecModulePath.mjs +4 -4
- package/dist/SpecModulePath.mjs.map +1 -1
- package/dist/SyncState.mjs +3 -4
- package/dist/SyncState.mjs.map +1 -1
- package/dist/TableModule.mjs +18 -10
- package/dist/TableModule.mjs.map +1 -1
- package/dist/TableModulePath.mjs +3 -3
- package/dist/TableModulePath.mjs.map +1 -1
- package/dist/TypeScriptConfig.mjs +135 -0
- package/dist/TypeScriptConfig.mjs.map +1 -0
- package/dist/WatchBuild.mjs +107 -32
- package/dist/WatchBuild.mjs.map +1 -1
- package/dist/WatchGraph.mjs +4 -4
- package/dist/WatchGraph.mjs.map +1 -1
- package/dist/WatchTopology.mjs +5 -4
- package/dist/WatchTopology.mjs.map +1 -1
- package/dist/Watcher.mjs +179 -108
- package/dist/Watcher.mjs.map +1 -1
- package/dist/cliApp.mjs +5 -3
- package/dist/cliApp.mjs.map +1 -1
- package/dist/confect/codegen.mjs +95 -53
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/declaration.mjs +76 -42
- package/dist/confect/declaration.mjs.map +1 -1
- package/dist/confect/dev.mjs +18 -12
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/confect.mjs +4 -2
- package/dist/confect.mjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/log.mjs +13 -5
- package/dist/log.mjs.map +1 -1
- package/dist/package.json.mjs +5 -0
- package/dist/package.json.mjs.map +1 -0
- package/dist/templates.mjs +34 -22
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +36 -5
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -10
- package/dist/package.mjs +0 -6
- package/dist/package.mjs.map +0 -1
package/dist/Watcher.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { ProjectRoot } from "./ProjectRoot.mjs";
|
|
2
1
|
import { bundleWorkspacePlugin } from "./Bundler.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { Change, Failure, Outcome, State, captureBarrier, combine, complete, diagnostics, diff, emptyCapture, endRequest, getCompletion, initialProgress, isFresh, joinedWithoutCompletion, makeRequestId, observe, parse, request, start, verifyInputs } from "./WatchBuild.mjs";
|
|
3
|
+
import { make as make$1 } from "./WatchTopology.mjs";
|
|
4
|
+
import { add, empty, full, reconcile } from "./SyncState.mjs";
|
|
5
|
+
import { Kind, discover, isOptional, parse as parse$1 } from "./EntryPoint.mjs";
|
|
4
6
|
import { ConfectDirectory } from "./ConfectDirectory.mjs";
|
|
5
7
|
import "./ConvexConfig.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { add, empty, full, reconcile } from "./SyncState.mjs";
|
|
9
|
-
import { Change, Failure, Outcome, State, captureBarrier, complete, diagnostics, diff, emptyCapture, endRequest, getCompletion, initialProgress, isFresh, joinedWithoutCompletion, makeRequestId, observe, parse as parse$1, request, start, verifyInputs } from "./WatchBuild.mjs";
|
|
10
|
-
import { make as make$1 } from "./WatchTopology.mjs";
|
|
8
|
+
import { ConvexDirectory } from "./ConvexDirectory.mjs";
|
|
9
|
+
import { ProjectRoot } from "./ProjectRoot.mjs";
|
|
11
10
|
import { make as make$2 } from "./RestoreWatcher.mjs";
|
|
11
|
+
import { inputs } from "./SectionFiles.mjs";
|
|
12
|
+
import { discover as discover$1 } from "./PackageSelfReference.mjs";
|
|
13
|
+
import { aliasPatterns, buildOptions, discover as discover$2 } from "./TypeScriptConfig.mjs";
|
|
12
14
|
import * as Effect from "effect/Effect";
|
|
13
15
|
import * as FileSystem from "effect/FileSystem";
|
|
14
16
|
import * as Path from "effect/Path";
|
|
@@ -18,31 +20,37 @@ import { pipe } from "effect/Function";
|
|
|
18
20
|
import * as HashSet from "effect/HashSet";
|
|
19
21
|
import * as Match from "effect/Match";
|
|
20
22
|
import * as Option from "effect/Option";
|
|
21
|
-
import
|
|
23
|
+
import * as BundleRequire from "bundle-require";
|
|
22
24
|
import * as Context from "effect/Context";
|
|
23
25
|
import * as HashMap from "effect/HashMap";
|
|
24
26
|
import * as Ref from "effect/Ref";
|
|
25
27
|
import * as Scope from "effect/Scope";
|
|
26
28
|
import * as Schema from "effect/Schema";
|
|
29
|
+
import * as String from "effect/String";
|
|
27
30
|
import * as esbuild from "esbuild";
|
|
31
|
+
import * as Layer from "effect/Layer";
|
|
28
32
|
import * as Order from "effect/Order";
|
|
29
33
|
import * as Data from "effect/Data";
|
|
30
34
|
import * as Schedule from "effect/Schedule";
|
|
31
35
|
import * as Duration from "effect/Duration";
|
|
32
36
|
import * as Clock from "effect/Clock";
|
|
37
|
+
import * as Cache from "effect/Cache";
|
|
33
38
|
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
34
|
-
import * as
|
|
39
|
+
import * as Digest from "effect/crypto/Digest";
|
|
35
40
|
import * as Hex from "effect/encoding/Hex";
|
|
36
41
|
import * as Deferred from "effect/Deferred";
|
|
37
42
|
import * as Exit from "effect/Exit";
|
|
38
43
|
import * as Queue from "effect/Queue";
|
|
39
44
|
import * as Semaphore from "effect/Semaphore";
|
|
40
45
|
import * as Stream from "effect/Stream";
|
|
41
|
-
|
|
46
|
+
// src/Watcher.ts
|
|
42
47
|
const CoalesceQuiescence = Context.Reference("@confect/cli/Watcher/CoalesceQuiescence", { defaultValue: () => Duration.millis(50) });
|
|
43
48
|
const COALESCE_MAX_WAIT = Duration.seconds(5);
|
|
44
49
|
const WatcherLifecycle = Data.taggedEnum();
|
|
45
50
|
const RefreshOutcome = Data.taggedEnum();
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
46
54
|
const isRefreshSuccessful = (outcome) => RefreshOutcome.$match(outcome, {
|
|
47
55
|
Empty: () => true,
|
|
48
56
|
Observed: ({ outcome: observed }) => Outcome.$match(observed, {
|
|
@@ -61,7 +69,9 @@ var OperationError = class extends Schema.TaggedError()("WatcherOperationError",
|
|
|
61
69
|
cause: Schema.Unknown
|
|
62
70
|
}) {};
|
|
63
71
|
const ReportedBuildFailure = Schema.Struct({ errors: Schema.NonEmptyArray(Schema.Struct({ text: Schema.String })) });
|
|
64
|
-
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
65
75
|
const make = Effect.fnUntraced(function* () {
|
|
66
76
|
const quiescence = yield* CoalesceQuiescence;
|
|
67
77
|
const signal = yield* Queue.sliding(1);
|
|
@@ -69,7 +79,7 @@ const make = Effect.fnUntraced(function* () {
|
|
|
69
79
|
const restartQueue = yield* Queue.sliding(1);
|
|
70
80
|
const state = {
|
|
71
81
|
lifecycle: yield* Ref.make(WatcherLifecycle.Uninitialized()),
|
|
72
|
-
observation: yield* Ref.make(
|
|
82
|
+
observation: yield* Ref.make(HashMap.empty()),
|
|
73
83
|
lock: yield* Semaphore.make(1),
|
|
74
84
|
topology: yield* make$1(pendingRef),
|
|
75
85
|
declared: yield* Ref.make(false)
|
|
@@ -88,13 +98,22 @@ const make = Effect.fnUntraced(function* () {
|
|
|
88
98
|
convexConfigStructureWatcher(restart, state.declared)
|
|
89
99
|
], { concurrency: "unbounded" });
|
|
90
100
|
}).pipe(Effect.scoped),
|
|
91
|
-
duringRestore:
|
|
101
|
+
duringRestore: duringRestoreRef.pipe(Ref.get, Effect.flatten),
|
|
92
102
|
discardRestoreEchoes: refresh(state).pipe(Effect.ignore, Effect.andThen(Ref.set(pendingRef, empty))),
|
|
93
103
|
refresh: refresh(state),
|
|
94
104
|
next: Queue.take(signal).pipe(Effect.andThen(drainUntilQuiescent(signal, quiescence, COALESCE_MAX_WAIT)), Effect.andThen(state.topology.takePending), Effect.onInterrupt(() => Queue.offer(signal, void 0))),
|
|
95
105
|
pending: Ref.get(pendingRef),
|
|
96
106
|
requestRetry: Ref.update(pendingRef, full).pipe(Effect.andThen(Queue.offer(signal, void 0)), Effect.asVoid),
|
|
97
|
-
diagnostics: Ref.get(state.observation).pipe(Effect.map(
|
|
107
|
+
diagnostics: Ref.get(state.observation).pipe(Effect.map((observations) => Array.reduce(HashMap.values(observations), {
|
|
108
|
+
errors: [],
|
|
109
|
+
warnings: []
|
|
110
|
+
}, (combined, observation) => {
|
|
111
|
+
const diagnostic = diagnostics(observation);
|
|
112
|
+
return {
|
|
113
|
+
errors: [...combined.errors, ...diagnostic.errors],
|
|
114
|
+
warnings: [...combined.warnings, ...diagnostic.warnings]
|
|
115
|
+
};
|
|
116
|
+
})))
|
|
98
117
|
};
|
|
99
118
|
});
|
|
100
119
|
const drainUntilQuiescent = Effect.fnUntraced(function* (signal, quiescence, maxWait) {
|
|
@@ -108,12 +127,17 @@ const drainUntilQuiescent = Effect.fnUntraced(function* (signal, quiescence, max
|
|
|
108
127
|
});
|
|
109
128
|
yield* loop;
|
|
110
129
|
});
|
|
111
|
-
const esbuildOptions = (path, fs,
|
|
112
|
-
const
|
|
130
|
+
const esbuildOptions = (path, fs, digest, projectRoot, generatedDirectory, entries, notExternal, config, stateRef, captureRef, progressRef, signal, pendingRef, initial) => {
|
|
131
|
+
const JsonString = Schema.fromJsonString(Schema.String);
|
|
132
|
+
const groupKey = Option.match(config, {
|
|
133
|
+
onNone: () => "",
|
|
134
|
+
onSome: (selected) => selected.path
|
|
135
|
+
});
|
|
113
136
|
return {
|
|
137
|
+
...buildOptions(config),
|
|
114
138
|
absWorkingDir: projectRoot,
|
|
115
139
|
stdin: {
|
|
116
|
-
contents:
|
|
140
|
+
contents: Array.join(Array.map(entries, (entry) => `import ${Result.getOrThrow(Schema.encodeResult(JsonString)(entry.absolutePath))};`), "\n"),
|
|
117
141
|
resolveDir: projectRoot,
|
|
118
142
|
sourcefile: "confect-watch.ts",
|
|
119
143
|
loader: "ts"
|
|
@@ -126,7 +150,7 @@ const esbuildOptions = (path, fs, crypto, projectRoot, generatedDirectory, entri
|
|
|
126
150
|
logLevel: "silent",
|
|
127
151
|
plugins: [
|
|
128
152
|
bundleWorkspacePlugin(path, fs, notExternal),
|
|
129
|
-
externalPlugin({ notExternal: [...notExternal] }),
|
|
153
|
+
BundleRequire.externalPlugin({ notExternal: [...notExternal] }),
|
|
130
154
|
{
|
|
131
155
|
name: "notify-rebuild",
|
|
132
156
|
setup(build) {
|
|
@@ -135,7 +159,7 @@ const esbuildOptions = (path, fs, crypto, projectRoot, generatedDirectory, entri
|
|
|
135
159
|
yield* Ref.set(captureRef, emptyCapture);
|
|
136
160
|
}).pipe(Effect.as(void 0))));
|
|
137
161
|
build.onLoad({ filter: /.*/ }, (args) => Effect.runPromise(Effect.gen(function* () {
|
|
138
|
-
const fingerprint = yield* fs.readFile(args.path).pipe(Effect.flatMap((contents) =>
|
|
162
|
+
const fingerprint = yield* fs.readFile(args.path).pipe(Effect.flatMap((contents) => digest.digest(Digest.sha256, contents)), Effect.map(Hex.encode), Effect.result);
|
|
139
163
|
yield* Ref.update(captureRef, (capture) => Result.isSuccess(fingerprint) ? {
|
|
140
164
|
...capture,
|
|
141
165
|
fingerprints: HashMap.set(capture.fingerprints, args.path, fingerprint.success)
|
|
@@ -149,15 +173,17 @@ const esbuildOptions = (path, fs, crypto, projectRoot, generatedDirectory, entri
|
|
|
149
173
|
}).pipe(Effect.as(void 0))));
|
|
150
174
|
build.onEnd((result) => Effect.runPromise(Effect.gen(function* () {
|
|
151
175
|
const { generation } = yield* Ref.get(progressRef);
|
|
152
|
-
const
|
|
153
|
-
const
|
|
176
|
+
const observations = yield* Ref.get(stateRef);
|
|
177
|
+
const previous = Option.getOrElse(HashMap.get(observations, groupKey), State.Initial);
|
|
178
|
+
const capture = yield* Ref.get(captureRef);
|
|
179
|
+
const outcome = yield* parse(result, capture, (file) => path.resolve(projectRoot, file), digest);
|
|
154
180
|
const current = observe(previous, outcome);
|
|
155
|
-
yield* Ref.
|
|
181
|
+
yield* Ref.update(stateRef, HashMap.set(groupKey, current));
|
|
156
182
|
const change = diff(previous, current, generatedDirectory + path.sep);
|
|
157
183
|
yield* Ref.update(pendingRef, (pending) => Change.$match(change, {
|
|
158
184
|
Full: () => add(pending, entries, true),
|
|
159
|
-
Affected: ({ paths }) => add(pending,
|
|
160
|
-
Recovered: ({ paths }) => reconcile(add(pending,
|
|
185
|
+
Affected: ({ paths }) => add(pending, Array.filter(entries, (entry) => HashSet.has(paths, entry.inputPath))),
|
|
186
|
+
Recovered: ({ paths }) => reconcile(add(pending, Array.filter(entries, (entry) => HashSet.has(paths, entry.inputPath))))
|
|
161
187
|
}));
|
|
162
188
|
yield* Queue.offer(signal, void 0);
|
|
163
189
|
yield* Ref.update(progressRef, (progress) => complete(progress, {
|
|
@@ -177,15 +203,17 @@ const entryPointsWatcher = Effect.fnUntraced(function* (signal, pendingRef, rest
|
|
|
177
203
|
const fs = yield* FileSystem.FileSystem;
|
|
178
204
|
const projectRoot = yield* ProjectRoot.get;
|
|
179
205
|
const confectDirectory = yield* ConfectDirectory.get;
|
|
180
|
-
const
|
|
181
|
-
const
|
|
206
|
+
const realConfectDirectory = yield* fs.realPath(confectDirectory);
|
|
207
|
+
const generatedDirectory = path.join(realConfectDirectory, "_generated");
|
|
208
|
+
const cryptoContext = yield* Layer.build(NodeCrypto.layerDigest);
|
|
209
|
+
const digest = Context.get(cryptoContext, Digest.Digest);
|
|
182
210
|
const completedInitial = Deferred.make().pipe(Effect.tap((initial) => Deferred.succeed(initial, void 0)));
|
|
183
211
|
const sync = Effect.gen(function* () {
|
|
184
212
|
const revision = yield* watcher.topology.revision;
|
|
185
213
|
const current = yield* Ref.get(watcher.lifecycle);
|
|
186
214
|
const entries = yield* discover;
|
|
187
|
-
yield* Ref.set(watcher.declared,
|
|
188
|
-
const desiredPaths = HashSet.fromIterable(
|
|
215
|
+
yield* Ref.set(watcher.declared, Array.some(entries, Kind.$is("App")));
|
|
216
|
+
const desiredPaths = HashSet.fromIterable(Array.map(entries, (entry) => entry.absolutePath));
|
|
189
217
|
const key = pipe(Array.fromIterable(desiredPaths), Array.sort(Order.String), Array.join("\n"));
|
|
190
218
|
if (WatcherLifecycle.$match(current, {
|
|
191
219
|
Uninitialized: () => false,
|
|
@@ -205,13 +233,13 @@ const entryPointsWatcher = Effect.fnUntraced(function* (signal, pendingRef, rest
|
|
|
205
233
|
Uninitialized: () => Effect.void,
|
|
206
234
|
Empty: () => Ref.update(pendingRef, full),
|
|
207
235
|
Active: ({ entries: previousEntries, scope }) => Effect.gen(function* () {
|
|
208
|
-
const removedOptional =
|
|
236
|
+
const removedOptional = Array.filter(previousEntries, (entry) => isOptional(entry) && !HashSet.has(desiredPaths, entry.absolutePath));
|
|
209
237
|
yield* Ref.update(pendingRef, (pending) => add(full(pending), removedOptional));
|
|
210
238
|
yield* Scope.close(scope, Exit.void);
|
|
211
239
|
})
|
|
212
240
|
});
|
|
213
241
|
yield* Ref.set(watcher.lifecycle, WatcherLifecycle.Uninitialized());
|
|
214
|
-
yield* Ref.set(watcher.observation,
|
|
242
|
+
yield* Ref.set(watcher.observation, HashMap.empty());
|
|
215
243
|
if (!Array.isReadonlyArrayNonEmpty(entries)) {
|
|
216
244
|
yield* Ref.set(watcher.lifecycle, WatcherLifecycle.Empty());
|
|
217
245
|
yield* Ref.update(pendingRef, full);
|
|
@@ -221,103 +249,147 @@ const entryPointsWatcher = Effect.fnUntraced(function* (signal, pendingRef, rest
|
|
|
221
249
|
return;
|
|
222
250
|
}
|
|
223
251
|
const scope = yield* Scope.fork(parentScope, "sequential");
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
252
|
+
const configs = yield* Cache.make({
|
|
253
|
+
capacity: entries.length,
|
|
254
|
+
lookup: discover$2
|
|
255
|
+
});
|
|
256
|
+
const configured = yield* Effect.forEach(entries, (entry) => Effect.map(Cache.get(configs, path.dirname(entry.absolutePath)), (config) => ({
|
|
257
|
+
entry,
|
|
258
|
+
config,
|
|
259
|
+
key: Option.match(config, {
|
|
260
|
+
onNone: () => "",
|
|
261
|
+
onSome: (selected) => selected.path
|
|
234
262
|
})
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
263
|
+
}))).pipe(Effect.mapError((cause) => OperationError.make({
|
|
264
|
+
operation: "create",
|
|
265
|
+
cause
|
|
266
|
+
})));
|
|
267
|
+
const partitions = Array.groupWith(Array.sort(configured, Order.mapInput(Order.String, (selected) => selected.key)), (left, right) => left.key === right.key);
|
|
268
|
+
const groups = yield* Effect.forEach(partitions, (partition) => Effect.gen(function* () {
|
|
269
|
+
const config = Array.headNonEmpty(partition).config;
|
|
270
|
+
const groupEntries = Array.map(partition, (selected) => selected.entry);
|
|
271
|
+
const captureRef = yield* Ref.make(emptyCapture);
|
|
272
|
+
const progress = yield* Ref.make(initialProgress);
|
|
273
|
+
const initial = yield* Deferred.make();
|
|
274
|
+
const selfReferences = yield* Effect.forEach(Array.dedupe(Array.map(groupEntries, (entry) => path.dirname(entry.absolutePath))), discover$1).pipe(Effect.mapError((cause) => OperationError.make({
|
|
275
|
+
operation: "create",
|
|
239
276
|
cause
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
|
|
277
|
+
})));
|
|
278
|
+
const notExternal = [...aliasPatterns(config), ...Array.getSomes(selfReferences)];
|
|
279
|
+
const context = yield* Effect.acquireRelease(Effect.tryPromise({
|
|
280
|
+
try: () => esbuild.context(esbuildOptions(path, fs, digest, projectRoot, generatedDirectory, groupEntries, notExternal, config, watcher.observation, captureRef, progress, signal, pendingRef, initial)),
|
|
281
|
+
catch: (cause) => OperationError.make({
|
|
282
|
+
operation: "create",
|
|
283
|
+
cause
|
|
284
|
+
})
|
|
285
|
+
}), (ctx) => Effect.tryPromise({
|
|
286
|
+
try: () => ctx.dispose(),
|
|
287
|
+
catch: (cause) => OperationError.make({
|
|
288
|
+
operation: "dispose",
|
|
289
|
+
cause
|
|
290
|
+
})
|
|
291
|
+
}).pipe(Effect.orDie)).pipe(Scope.provide(scope));
|
|
292
|
+
const requestIds = /* @__PURE__ */ new WeakMap();
|
|
293
|
+
return {
|
|
294
|
+
initial,
|
|
295
|
+
context,
|
|
296
|
+
identifyRequest: (promise) => {
|
|
297
|
+
const existing = requestIds.get(promise);
|
|
298
|
+
if (existing !== void 0) return existing;
|
|
299
|
+
const id = makeRequestId();
|
|
300
|
+
requestIds.set(promise, id);
|
|
301
|
+
return id;
|
|
302
|
+
},
|
|
303
|
+
progress,
|
|
304
|
+
verifyInputs: (snapshot) => verifyInputs(snapshot, fs, digest)
|
|
305
|
+
};
|
|
306
|
+
}));
|
|
307
|
+
const initial = yield* Deferred.make();
|
|
243
308
|
yield* Ref.set(watcher.lifecycle, WatcherLifecycle.Active({
|
|
244
309
|
initial,
|
|
245
310
|
key,
|
|
246
311
|
scope,
|
|
247
312
|
entries,
|
|
248
|
-
|
|
249
|
-
identifyRequest: (promise) => {
|
|
250
|
-
const existing = requestIds.get(promise);
|
|
251
|
-
if (existing !== void 0) return existing;
|
|
252
|
-
const id = makeRequestId();
|
|
253
|
-
requestIds.set(promise, id);
|
|
254
|
-
return id;
|
|
255
|
-
},
|
|
256
|
-
progress,
|
|
257
|
-
verifyInputs: (snapshot) => verifyInputs(snapshot, fs, crypto)
|
|
313
|
+
groups
|
|
258
314
|
}));
|
|
259
|
-
yield* Effect.tryPromise({
|
|
315
|
+
yield* Effect.forEach(groups, ({ context }) => Effect.tryPromise({
|
|
260
316
|
try: () => context.watch(),
|
|
261
|
-
catch: (cause) =>
|
|
317
|
+
catch: (cause) => OperationError.make({
|
|
262
318
|
operation: "watch",
|
|
263
319
|
cause
|
|
264
320
|
})
|
|
265
|
-
});
|
|
321
|
+
}));
|
|
322
|
+
yield* Effect.forEach(groups, (group) => Deferred.await(group.initial)).pipe(Effect.andThen(Deferred.succeed(initial, void 0)), Effect.forkIn(scope));
|
|
266
323
|
yield* watcher.topology.reconcile(revision, initial);
|
|
267
324
|
}).pipe(Semaphore.withPermit(watcher.lock));
|
|
268
325
|
yield* sync;
|
|
269
326
|
return yield* Effect.forever(Queue.take(restartQueue).pipe(Effect.andThen(sync)));
|
|
270
|
-
}
|
|
327
|
+
});
|
|
271
328
|
const refreshCurrent = Effect.fnUntraced(function* (current) {
|
|
272
329
|
return yield* WatcherLifecycle.$match(current, {
|
|
273
330
|
Empty: () => Effect.succeed(RefreshOutcome.Empty()),
|
|
274
|
-
Uninitialized: () => Effect.fail(
|
|
331
|
+
Uninitialized: () => Effect.fail(OperationError.make({
|
|
275
332
|
operation: "refresh",
|
|
276
333
|
cause: "The dependency watcher is not initialized"
|
|
277
334
|
})),
|
|
278
|
-
Active: ({
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const promise = context.rebuild();
|
|
285
|
-
runSync(Ref.update(progress, (currentProgress) => request(currentProgress, identifyRequest(promise))));
|
|
286
|
-
return promise;
|
|
287
|
-
},
|
|
288
|
-
catch: (cause) => new OperationError({
|
|
289
|
-
operation: "rebuild",
|
|
290
|
-
cause
|
|
291
|
-
})
|
|
292
|
-
}).pipe(Effect.result);
|
|
293
|
-
const currentProgress = yield* Ref.get(progress);
|
|
294
|
-
const completed = getCompletion(currentProgress);
|
|
295
|
-
if (Result.isFailure(built)) {
|
|
296
|
-
const rejected = parseFailure(built.failure.cause);
|
|
297
|
-
if (Option.isNone(rejected)) return yield* built.failure;
|
|
298
|
-
if (joinedWithoutCompletion(currentProgress)) return Option.none();
|
|
299
|
-
if (Option.isNone(completed) || !Outcome.$is("Failed")(completed.value.outcome)) return yield* new OperationError({
|
|
300
|
-
operation: "rebuild",
|
|
301
|
-
cause: rejected.value.errors
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
if (joinedWithoutCompletion(currentProgress)) return Option.none();
|
|
305
|
-
const observed = yield* Effect.fromOption(completed).pipe(Effect.mapError(() => new OperationError({
|
|
306
|
-
operation: "rebuild",
|
|
307
|
-
cause: "esbuild completed without a build observation"
|
|
308
|
-
})));
|
|
309
|
-
if (isFresh(barrier, observed) && Outcome.$is("Succeeded")(observed.outcome)) {
|
|
310
|
-
if (!(yield* verifyInputs(observed.outcome.snapshot).pipe(Effect.mapError(({ cause }) => new OperationError({
|
|
335
|
+
Active: ({ groups }) => Effect.gen(function* () {
|
|
336
|
+
const outcomes = yield* Effect.forEach(groups, refreshGroup);
|
|
337
|
+
if (groups.length > 1) {
|
|
338
|
+
const unchanged = yield* Effect.forEach(Array.zip(groups, outcomes), ([group, outcome]) => Outcome.$match(outcome, {
|
|
339
|
+
Failed: () => Effect.succeed(true),
|
|
340
|
+
Succeeded: ({ snapshot }) => group.verifyInputs(snapshot).pipe(Effect.mapError(({ cause }) => OperationError.make({
|
|
311
341
|
operation: "refresh",
|
|
312
342
|
cause
|
|
313
|
-
})))
|
|
314
|
-
}
|
|
315
|
-
return Option.
|
|
316
|
-
}
|
|
317
|
-
return RefreshOutcome.Observed({ outcome:
|
|
318
|
-
})
|
|
343
|
+
})))
|
|
344
|
+
}));
|
|
345
|
+
if (!Array.every(unchanged, (matches) => matches)) return Option.none();
|
|
346
|
+
}
|
|
347
|
+
return Option.some(RefreshOutcome.Observed({ outcome: combine(outcomes) }));
|
|
348
|
+
}).pipe(Effect.repeat({ while: Option.isNone }), Effect.flatMap((outcome) => Effect.fromOption(outcome).pipe(Effect.orDie)))
|
|
319
349
|
});
|
|
320
350
|
});
|
|
351
|
+
const refreshGroup = Effect.fnUntraced(function* ({ context, identifyRequest, progress, verifyInputs }) {
|
|
352
|
+
const effectContext = yield* Effect.context();
|
|
353
|
+
const runSync = Effect.runSyncWith(effectContext);
|
|
354
|
+
const previousProgress = yield* Ref.get(progress);
|
|
355
|
+
const barrier = captureBarrier(previousProgress);
|
|
356
|
+
return (yield* Effect.gen(function* () {
|
|
357
|
+
const built = yield* Effect.tryPromise({
|
|
358
|
+
try: () => {
|
|
359
|
+
const promise = context.rebuild();
|
|
360
|
+
runSync(Ref.update(progress, (currentProgress) => request(currentProgress, identifyRequest(promise))));
|
|
361
|
+
return promise;
|
|
362
|
+
},
|
|
363
|
+
catch: (cause) => OperationError.make({
|
|
364
|
+
operation: "rebuild",
|
|
365
|
+
cause
|
|
366
|
+
})
|
|
367
|
+
}).pipe(Effect.result);
|
|
368
|
+
const currentProgress = yield* Ref.get(progress);
|
|
369
|
+
const completed = getCompletion(currentProgress);
|
|
370
|
+
if (Result.isFailure(built)) {
|
|
371
|
+
const rejected = Schema.decodeUnknownOption(ReportedBuildFailure)(built.failure.cause);
|
|
372
|
+
if (Option.isNone(rejected)) return yield* built.failure;
|
|
373
|
+
if (joinedWithoutCompletion(currentProgress)) return Option.none();
|
|
374
|
+
if (Option.isNone(completed) || !Outcome.$is("Failed")(completed.value.outcome)) return yield* OperationError.make({
|
|
375
|
+
operation: "rebuild",
|
|
376
|
+
cause: rejected.value.errors
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
if (joinedWithoutCompletion(currentProgress)) return Option.none();
|
|
380
|
+
const observed = yield* Effect.fromOption(completed).pipe(Effect.mapError(() => OperationError.make({
|
|
381
|
+
operation: "rebuild",
|
|
382
|
+
cause: "esbuild completed without a build observation"
|
|
383
|
+
})));
|
|
384
|
+
if (isFresh(barrier, observed) && Outcome.$is("Succeeded")(observed.outcome)) {
|
|
385
|
+
if (!(yield* verifyInputs(observed.outcome.snapshot).pipe(Effect.mapError(({ cause }) => OperationError.make({
|
|
386
|
+
operation: "refresh",
|
|
387
|
+
cause
|
|
388
|
+
}))))) return Option.none();
|
|
389
|
+
}
|
|
390
|
+
return Option.some(observed);
|
|
391
|
+
}).pipe(Effect.ensuring(Ref.update(progress, endRequest))).pipe(Effect.repeat({ while: (observed) => Option.isNone(observed) || !isFresh(barrier, observed.value) }), Effect.flatMap((observed) => Effect.fromOption(observed).pipe(Effect.orDie)))).outcome;
|
|
392
|
+
});
|
|
321
393
|
const refresh = (watcher) => watcher.lock.withPermit(Ref.get(watcher.lifecycle).pipe(Effect.flatMap(refreshCurrent)));
|
|
322
394
|
const confectStructureWatcher = Effect.fnUntraced(function* (signal, pendingRef, restart, restartEntry) {
|
|
323
395
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -341,7 +413,7 @@ const confectStructureWatcher = Effect.fnUntraced(function* (signal, pendingRef,
|
|
|
341
413
|
const removed = Schema.decodeUnknownOption(removedDirectory)(error.reason.cause);
|
|
342
414
|
if (Option.isNone(removed)) return false;
|
|
343
415
|
const relative = path.relative(confectDirectory, removed.value.path);
|
|
344
|
-
if (relative === "" || relative === ".." ||
|
|
416
|
+
if (relative === "" || relative === ".." || String.startsWith(`..${path.sep}`)(relative) || path.isAbsolute(relative)) return false;
|
|
345
417
|
if (!(yield* fs.exists(confectDirectory).pipe(Effect.orElseSucceed(() => false)))) return false;
|
|
346
418
|
yield* restart;
|
|
347
419
|
return true;
|
|
@@ -367,17 +439,16 @@ const convexConfigStructureWatcher = Effect.fnUntraced(function* (restart, decla
|
|
|
367
439
|
});
|
|
368
440
|
const flipDirtyAndSignal = (pendingRef, signal, restart, isLifecycleChange) => isLifecycleChange ? restart : Ref.update(pendingRef, full).pipe(Effect.andThen(Queue.offer(signal, void 0)));
|
|
369
441
|
const handleConfectChange = ({ relativePath, eventTag, signal, pendingRef, restart, restartEntry }) => {
|
|
370
|
-
if (
|
|
371
|
-
if (!
|
|
442
|
+
if (String.split(/[/\\]/)(relativePath).includes("_generated")) return Effect.void;
|
|
443
|
+
if (!String.endsWith(".ts")(relativePath)) return Effect.void;
|
|
372
444
|
const isLifecycleChange = Match.value(eventTag).pipe(Match.when("Update", () => false), Match.whenOr("Create", "Remove", () => true), Match.exhaustive);
|
|
373
|
-
const source = relativePath.split(/[/\\]/)
|
|
445
|
+
const source = Array.join(pipe(relativePath, String.split(/[/\\]/)), "/");
|
|
374
446
|
const regenerateIfInput = inputs.pipe(Effect.map((inputs) => inputs.includes(source)), Effect.orElseSucceed(() => false), Effect.flatMap((listed) => listed ? flipDirtyAndSignal(pendingRef, signal, restart, false) : Effect.void));
|
|
375
|
-
const entry = parse(relativePath);
|
|
447
|
+
const entry = parse$1(relativePath);
|
|
376
448
|
if (Option.isSome(entry)) return isLifecycleChange ? restartEntry(entry.value) : regenerateIfInput;
|
|
377
449
|
if (relativePath === "schema.ts") return flipDirtyAndSignal(pendingRef, signal, restart, isLifecycleChange);
|
|
378
450
|
return Match.value(eventTag).pipe(Match.whenOr("Create", "Remove", () => flipDirtyAndSignal(pendingRef, signal, restart, false)), Match.when("Update", () => regenerateIfInput), Match.exhaustive);
|
|
379
451
|
};
|
|
380
|
-
|
|
381
|
-
export { CoalesceQuiescence, OperationError, isRefreshSuccessful, make, parseFailure };
|
|
452
|
+
export { CoalesceQuiescence, OperationError, ReportedBuildFailure, isRefreshSuccessful, make };
|
|
382
453
|
|
|
383
454
|
//# sourceMappingURL=Watcher.mjs.map
|