@graftland/hmr 0.2.0-beta.0 → 0.2.0-beta.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.
@@ -1,7 +1,7 @@
1
+ import { digest } from "./digest.js";
1
2
  import { registerHooks } from "node:module";
2
3
  import { fileURLToPath, pathToFileURL } from "node:url";
3
- import { Array, HashMap, HashSet, Option, Predicate, Schema, String } from "effect";
4
- import { Base64 } from "effect/encoding";
4
+ import { Array, Chunk, HashMap, HashSet, Option, Predicate, Schema, String } from "effect";
5
5
  // src/internal/modules.ts
6
6
  var RestartRequired = class extends Schema.TaggedError()("RestartRequired", { url: Schema.String }) {};
7
7
  const isMissingEntry = (url, cause) => String.startsWith("file:")(url) && Predicate.hasProperty(cause, "code") && (cause.code === "ERR_MODULE_NOT_FOUND" && Predicate.hasProperty(cause, "url") && cause.url === url || cause.code === "ENOENT" && Predicate.hasProperty(cause, "path") && cause.path === fileURLToPath(url));
@@ -21,7 +21,6 @@ const fileRequest = (specifier, parent) => {
21
21
  const modules = (base, include) => {
22
22
  const key = `graft-hmr-${++sessions}`;
23
23
  const prefix = `${key}:`;
24
- /** What `request` produces: the generation that imports a specifier. */
25
24
  const decodeRequest = Schema.decodeUnknownOption(Schema.TemplateLiteralParser([
26
25
  prefix,
27
26
  Schema.String.check(Schema.isPattern(/^\d+$/)),
@@ -30,148 +29,225 @@ const modules = (base, include) => {
30
29
  ]));
31
30
  let revision = 0;
32
31
  let importing;
33
- let dependencies = HashMap.empty();
32
+ let resolved;
33
+ let views = HashMap.empty();
34
34
  let edges = HashMap.empty();
35
- const link = (id, parent, child, request) => {
36
- const graph = Option.getOrElse(HashMap.get(edges, id), HashMap.empty);
37
- const children = Option.getOrElse(HashMap.get(graph, parent), HashMap.empty);
38
- edges = HashMap.set(edges, id, HashMap.set(graph, parent, HashMap.set(children, request ?? child, {
39
- generation: { id: Number(id) },
40
- parent,
41
- url: child,
42
- ...request === void 0 ? {} : { request }
43
- })));
35
+ let sources = HashMap.empty();
36
+ let dependencies = HashSet.empty();
37
+ let reachCache = HashMap.empty();
38
+ let retained = HashSet.empty();
39
+ let instantiatedViews = HashSet.empty();
40
+ const clean = (url) => {
41
+ const value = new URL(url);
42
+ value.searchParams.delete(key);
43
+ return value.href;
44
+ };
45
+ const version = (url) => {
46
+ if (url === void 0) return void 0;
47
+ const value = new URL(url).searchParams.get(key);
48
+ return value === null ? void 0 : Number(value);
49
+ };
50
+ const tag = (url, id) => {
51
+ const value = new URL(url);
52
+ value.searchParams.set(key, String.String(id));
53
+ return value.href;
44
54
  };
45
- const reachable = (id, roots) => {
46
- const graph = Option.getOrElse(HashMap.get(edges, id), HashMap.empty);
55
+ const route = (url, id) => Option.getOrElse(HashMap.get(Option.getOrElse(HashMap.get(views, id), HashMap.empty), url), () => tag(url, id));
56
+ const root = (attempt) => route(attempt.url, attempt.generation.id);
57
+ const children = (node) => Option.getOrElse(HashMap.get(edges, node), HashMap.empty);
58
+ const reachable = (node) => {
59
+ const cached = HashMap.get(reachCache, node);
60
+ if (Option.isSome(cached)) return cached.value;
47
61
  let seen = HashSet.empty();
48
- let pending = roots;
49
- while (Array.isReadonlyArrayNonEmpty(pending)) {
50
- const [url, ...rest] = pending;
51
- pending = rest;
52
- if (HashSet.has(seen, url)) continue;
53
- seen = HashSet.add(seen, url);
54
- pending = Array.appendAll(pending, Array.map(HashMap.toValues(Option.getOrElse(HashMap.get(graph, url), HashMap.empty)), (edge) => edge.url));
62
+ let pending = Chunk.of(node);
63
+ while (Chunk.isNonEmpty(pending)) {
64
+ const current = Chunk.headNonEmpty(pending);
65
+ pending = Chunk.drop(pending, 1);
66
+ if (HashSet.has(seen, current)) continue;
67
+ seen = HashSet.add(seen, current);
68
+ for (const edge of HashMap.values(children(current))) pending = Chunk.prepend(pending, edge.node);
55
69
  }
70
+ reachCache = HashMap.set(reachCache, node, seen);
56
71
  return seen;
57
72
  };
58
- const resolutionsFor = (attempt) => {
59
- const id = String.String(attempt.generation.id);
60
- const used = reachable(id, [attempt.url]);
61
- const graph = Option.getOrElse(HashMap.get(edges, id), HashMap.empty);
62
- return [...attempt.request === void 0 ? [] : [attempt], ...Array.flatMap(HashMap.toValues(graph), (children) => Array.filter(HashMap.toValues(children), (edge) => edge.request !== void 0 && HashSet.has(used, edge.parent)))];
73
+ const usedBy = (attempts) => {
74
+ const roots = HashSet.fromIterable(Array.map(attempts, root));
75
+ let used = HashSet.empty();
76
+ for (const node of roots) used = HashSet.union(used, reachable(node));
77
+ return used;
63
78
  };
64
- let sources = HashMap.empty();
65
- let resolved;
66
- const prepare = () => ({ id: ++revision });
67
- const clean = (url) => {
68
- const value = new URL(url);
69
- value.searchParams.delete(key);
70
- return value.href;
79
+ const link = (parent, node, request) => {
80
+ if (importing === void 0 && !HashSet.has(retained, parent) && !HashSet.has(instantiatedViews, version(parent))) return;
81
+ retained = HashSet.add(retained, node);
82
+ const url = clean(node);
83
+ const edge = {
84
+ node,
85
+ url,
86
+ generation: { id: version(node) },
87
+ ...request === void 0 ? {} : { request }
88
+ };
89
+ const previous = HashMap.get(children(parent), request ?? url);
90
+ if (Option.exists(previous, (previous) => previous.node === node && previous.request === request)) return;
91
+ edges = HashMap.set(edges, parent, HashMap.set(children(parent), request ?? url, edge));
92
+ reachCache = HashMap.empty();
71
93
  };
72
- const version = (url) => url === void 0 ? null : new URL(url).searchParams.get(key);
94
+ const resolutions = (attempts) => [...Array.filter(attempts, (attempt) => attempt.request !== void 0), ...Array.flatMap(Array.fromIterable(usedBy(attempts)), (node) => Array.filter(HashMap.toValues(children(node)), (edge) => edge.request !== void 0))];
73
95
  const unsupported = (url, format) => format === "commonjs" || format === "commonjs-typescript" || format === "addon" || String.endsWith(".node")(new URL(url).pathname);
74
- const requireRestart = (url, id) => {
75
- dependencies = HashMap.set(dependencies, id, HashSet.add(Option.getOrElse(HashMap.get(dependencies, id), HashSet.empty), url));
76
- if (importing !== void 0 && String.String(importing.generation.id) === id && importing.reload) throw RestartRequired.make({ url });
96
+ const requireRestart = (node) => {
97
+ if (importing !== void 0 || HashSet.has(retained, node)) dependencies = HashSet.add(dependencies, node);
98
+ if (importing?.reload === true && importing.generation.id === version(node)) throw RestartRequired.make({ url: clean(node) });
77
99
  };
78
- const record = (url, id, format) => {
79
- if (unsupported(url, format)) requireRestart(url, id);
100
+ const record = (node, format) => {
101
+ if (unsupported(clean(node), format)) requireRestart(node);
102
+ };
103
+ const invalidated = (attempts, dirty) => {
104
+ const used = usedBy(attempts);
105
+ let parents = HashMap.empty();
106
+ let pending = Chunk.empty();
107
+ for (const node of used) {
108
+ if (HashSet.has(dirty, clean(node))) pending = Chunk.prepend(pending, node);
109
+ for (const edge of HashMap.values(children(node))) {
110
+ parents = HashMap.set(parents, edge.node, HashSet.add(Option.getOrElse(HashMap.get(parents, edge.node), HashSet.empty), node));
111
+ if (edge.request !== void 0 && HashSet.has(dirty, edge.request)) pending = Chunk.prepend(pending, edge.node);
112
+ }
113
+ }
114
+ for (const attempt of attempts) if (attempt.request !== void 0 && HashSet.has(dirty, attempt.request)) pending = Chunk.prepend(pending, root(attempt));
115
+ let invalid = HashSet.empty();
116
+ while (Chunk.isNonEmpty(pending)) {
117
+ const node = Chunk.headNonEmpty(pending);
118
+ pending = Chunk.drop(pending, 1);
119
+ if (HashSet.has(invalid, node)) continue;
120
+ invalid = HashSet.add(invalid, node);
121
+ for (const parent of Option.getOrElse(HashMap.get(parents, node), HashSet.empty)) pending = Chunk.prepend(pending, parent);
122
+ }
123
+ return invalid;
124
+ };
125
+ const prepare = (attempts = [], invalid = HashSet.empty()) => {
126
+ const id = ++revision;
127
+ const seed = Array.reduce(attempts, 0, (id, attempt) => Math.max(id, attempt.generation.id));
128
+ let view = Option.getOrElse(HashMap.get(views, seed), HashMap.empty);
129
+ const used = usedBy(attempts);
130
+ for (const [url, node] of view) if (!HashSet.has(used, node) || HashSet.has(invalid, node)) view = HashMap.remove(view, url);
131
+ for (const node of used) {
132
+ if (HashSet.has(invalid, node)) continue;
133
+ const url = clean(node);
134
+ const previous = HashMap.get(view, url);
135
+ if (Option.isNone(previous) || version(previous.value) < version(node)) view = HashMap.set(view, url, node);
136
+ }
137
+ views = HashMap.set(views, id, view);
138
+ return { id };
80
139
  };
81
140
  const hooks = registerHooks({
82
141
  resolve(specifier, context, nextResolve) {
142
+ const parentNode = context.parentURL;
83
143
  const request = decodeRequest(specifier);
84
144
  const entry = Option.isSome(request);
85
145
  const id = Option.match(request, {
86
146
  onNone: () => version(context.parentURL),
87
- onSome: ([, id]) => id
147
+ onSome: ([, id]) => Number(id)
88
148
  });
89
- if (id === null) return nextResolve(specifier, context);
90
- const resolve = () => nextResolve(Option.match(request, {
149
+ if (id === void 0) return nextResolve(specifier, context);
150
+ const target = Option.match(request, {
91
151
  onNone: () => specifier,
92
152
  onSome: ([, , , target]) => target
93
- }), {
94
- ...context,
95
- parentURL: entry ? base : clean(context.parentURL)
96
153
  });
154
+ const parent = entry ? base : clean(context.parentURL);
155
+ const lexical = Option.getOrUndefined(fileRequest(target, parent));
97
156
  const result = (() => {
98
157
  try {
99
- return resolve();
158
+ return nextResolve(target, {
159
+ ...context,
160
+ parentURL: parent
161
+ });
100
162
  } catch (cause) {
101
163
  if (Predicate.hasProperty(cause, "url") && typeof cause.url === "string" && String.startsWith("file:")(cause.url)) {
102
164
  if (entry) resolved = cause.url;
103
- else if (context.parentURL !== void 0 && include(cause.url)) link(id, clean(context.parentURL), cause.url, Option.getOrUndefined(fileRequest(specifier, clean(context.parentURL))));
165
+ else if (include(cause.url)) link(parentNode, route(cause.url, id), lexical);
104
166
  }
105
167
  throw cause;
106
168
  }
107
169
  })();
108
170
  if (entry) resolved = result.url;
109
- if (!entry && result.url === "node:module" && context.parentURL !== void 0) {
110
- link(id, clean(context.parentURL), result.url);
111
- requireRestart(result.url, id);
171
+ if (!entry && result.url === "node:module") {
172
+ const node = route(result.url, id);
173
+ link(parentNode, node);
174
+ requireRestart(node);
112
175
  }
113
176
  if (!String.startsWith("file:")(result.url) || !entry && !include(result.url)) return result;
114
- if (!entry && context.parentURL !== void 0) link(id, clean(context.parentURL), result.url, Option.getOrUndefined(fileRequest(specifier, clean(context.parentURL))));
177
+ const node = route(result.url, id);
178
+ if (!entry) link(parentNode, node, lexical);
115
179
  const required = Array.contains(context.conditions, "require");
116
- if (required) requireRestart(result.url, id);
117
- else record(result.url, id, result.format);
118
- if (required || unsupported(result.url, result.format)) return result;
119
- const url = new URL(result.url);
120
- url.searchParams.set(key, id);
121
- return {
180
+ if (required) requireRestart(node);
181
+ else record(node, result.format);
182
+ return required || unsupported(result.url, result.format) ? result : {
122
183
  ...result,
123
- url: url.href
184
+ url: node
124
185
  };
125
186
  },
126
187
  load(url, context, nextLoad) {
127
188
  const id = version(url);
128
- if (id === null) return nextLoad(url, context);
189
+ if (id === void 0) return nextLoad(url, context);
190
+ instantiatedViews = HashSet.add(instantiatedViews, id);
129
191
  const original = clean(url);
130
- record(original, id, context.format);
192
+ record(url, context.format);
131
193
  const result = nextLoad(original, context);
132
194
  const source = result.source;
133
195
  if (source !== void 0 && source !== null) {
134
196
  const bytes = typeof source === "string" ? source : ArrayBuffer.isView(source) ? new Uint8Array(source.buffer, source.byteOffset, source.byteLength) : new Uint8Array(source);
135
- sources = HashMap.set(sources, id, HashMap.set(Option.getOrElse(HashMap.get(sources, id), HashMap.empty), original, Base64.encode(bytes)));
197
+ if (importing !== void 0 || HashSet.has(retained, url)) sources = HashMap.set(sources, url, digest(bytes));
136
198
  }
137
- record(original, id, result.format);
199
+ record(url, result.format);
138
200
  return result;
139
201
  }
140
202
  });
203
+ const files = (attempts) => {
204
+ let files = HashMap.empty();
205
+ const put = (url, node, resolution) => {
206
+ if (!String.startsWith("file:")(url) || HashSet.has(dependencies, node)) return;
207
+ const generation = version(node);
208
+ const previous = HashMap.get(files, url);
209
+ if (Option.exists(previous, (previous) => previous.generation > generation || previous.generation === generation && previous.resolution !== void 0)) return;
210
+ files = HashMap.set(files, url, {
211
+ generation,
212
+ content: Option.getOrUndefined(HashMap.get(sources, node)),
213
+ ...resolution === void 0 ? {} : { resolution }
214
+ });
215
+ };
216
+ for (const node of usedBy(attempts)) put(clean(node), node);
217
+ for (const attempt of resolutions(attempts)) if (attempt.request !== void 0) put(attempt.request, root(attempt), pathToFileURL(fileURLToPath(attempt.url)).href);
218
+ return files;
219
+ };
141
220
  return {
142
221
  prepare,
222
+ files,
223
+ resolutions,
224
+ invalidated,
225
+ affected: (attempt, invalid) => HashSet.has(invalid, root(attempt)),
143
226
  fileRequest: (specifier) => fileRequest(specifier, base),
144
- resolutions: (attempts) => Array.flatMap(attempts, resolutionsFor),
145
- files: (attempts) => Array.reduce(attempts, HashMap.empty(), (files, { generation, url, request }) => {
146
- const contents = Option.getOrElse(HashMap.get(sources, String.String(generation.id)), HashMap.empty);
147
- const unversioned = Option.getOrElse(HashMap.get(dependencies, String.String(generation.id)), HashSet.empty);
148
- const tracked = Array.reduce(Array.fromIterable(reachable(String.String(generation.id), [url])), files, (files, url) => {
149
- if (!String.startsWith("file:")(url) || HashSet.has(unversioned, url)) return files;
150
- if (Option.exists(HashMap.get(files, url), (current) => current.generation > generation.id || current.generation === generation.id && current.resolution !== void 0)) return files;
151
- return HashMap.set(files, url, {
152
- generation: generation.id,
153
- content: Option.getOrUndefined(HashMap.get(contents, url))
154
- });
155
- });
156
- return Array.reduce(resolutionsFor({
157
- generation,
158
- url,
159
- ...request === void 0 ? {} : { request }
160
- }), tracked, (files, edge) => {
161
- if (edge.request === void 0 || HashSet.has(unversioned, edge.url) || Option.exists(HashMap.get(files, edge.request), (file) => file.generation > generation.id)) return files;
162
- return HashMap.set(files, edge.request, {
163
- generation: generation.id,
164
- content: Option.getOrUndefined(HashMap.get(contents, edge.url)),
165
- resolution: pathToFileURL(fileURLToPath(edge.url)).href
166
- });
167
- });
168
- }),
169
227
  unsupported: (generation, roots) => {
170
- const found = Option.getOrElse(HashMap.get(dependencies, String.String(generation.id)), HashSet.empty);
171
- if (roots === void 0) return found;
172
- const used = reachable(String.String(generation.id), roots);
173
- return HashSet.filter(found, (url) => HashSet.has(used, url));
228
+ const used = roots === void 0 ? void 0 : usedBy(Array.map(roots, (url) => ({
229
+ url,
230
+ generation
231
+ })));
232
+ return HashSet.fromIterable(Array.map(Array.filter(Array.fromIterable(dependencies), (node) => used === void 0 ? version(node) === generation.id : HashSet.has(used, node)), clean));
233
+ },
234
+ collect: (attempts) => {
235
+ const used = usedBy(attempts);
236
+ const ownedViews = HashSet.fromIterable(Array.map(attempts, (attempt) => attempt.generation.id));
237
+ views = HashMap.filter(views, (_, id) => id === revision || HashSet.has(instantiatedViews, id) || HashSet.has(ownedViews, id));
238
+ const keep = (node) => HashSet.has(used, node) || HashSet.has(instantiatedViews, version(node));
239
+ retained = used;
240
+ sources = HashMap.filter(sources, (_, node) => keep(node));
241
+ edges = HashMap.filter(edges, (_, node) => keep(node));
242
+ dependencies = HashSet.filter(dependencies, keep);
243
+ reachCache = HashMap.filter(reachCache, (_, node) => HashSet.has(used, node));
174
244
  },
245
+ counts: () => ({
246
+ sources: HashMap.size(sources),
247
+ edges: HashMap.size(edges),
248
+ dependencies: HashSet.size(dependencies),
249
+ views: HashMap.size(views)
250
+ }),
175
251
  start: (generation, reload = false) => {
176
252
  importing = {
177
253
  generation,
@@ -186,7 +262,16 @@ const modules = (base, include) => {
186
262
  return `${prefix}${importing.generation.id}:${specifier}`;
187
263
  },
188
264
  resolved: () => Option.fromUndefinedOr(resolved),
189
- close: () => hooks.deregister()
265
+ close: () => {
266
+ hooks.deregister();
267
+ views = HashMap.empty();
268
+ sources = HashMap.empty();
269
+ edges = HashMap.empty();
270
+ dependencies = HashSet.empty();
271
+ reachCache = HashMap.empty();
272
+ retained = HashSet.empty();
273
+ instantiatedViews = HashSet.empty();
274
+ }
190
275
  };
191
276
  };
192
277
  export { RestartRequired, isMissingEntry, modules };
@@ -1 +1 @@
1
- {"version":3,"file":"modules.js","names":[],"sources":["../../src/internal/modules.ts"],"sourcesContent":["// Node's synchronous module hooks have no Effect equivalent.\nimport { Base64 } from \"effect/encoding\"\nimport { registerHooks } from \"node:module\"\nimport { fileURLToPath, pathToFileURL } from \"node:url\"\nimport {\n\tArray,\n\tHashMap,\n\tHashSet,\n\tOption,\n\tPredicate,\n\tSchema,\n\tString,\n} from \"effect\"\n\nexport class RestartRequired extends Schema.TaggedError<\n\tRestartRequired,\n\t{ readonly brand: unique symbol }\n>()(\"RestartRequired\", { url: Schema.String }) {}\n\n// Only a missing entry is disposable; missing dependencies still fail the reload.\nexport const isMissingEntry = (url: string, cause: unknown): boolean =>\n\tString.startsWith(\"file:\")(url) &&\n\tPredicate.hasProperty(cause, \"code\") &&\n\t((cause.code === \"ERR_MODULE_NOT_FOUND\" &&\n\t\tPredicate.hasProperty(cause, \"url\") &&\n\t\tcause.url === url) ||\n\t\t(cause.code === \"ENOENT\" &&\n\t\t\tPredicate.hasProperty(cause, \"path\") &&\n\t\t\tcause.path === fileURLToPath(url)))\n\n// Allocated only when a session starts; importing this module performs no I/O.\nlet sessions = 0\n\nexport interface Generation {\n\treadonly id: number\n}\n\n/** Bytes actually read by a particular native import attempt. */\nexport interface FileVersion {\n\treadonly generation: number\n\treadonly content: string | undefined\n\treadonly resolution?: string\n}\n\nexport interface Attempt {\n\treadonly generation: Generation\n\treadonly url: string\n\treadonly request?: string\n}\n\ninterface Dependency extends Attempt {\n\treadonly parent: string\n}\n\n/** Resolve local requests lexically; Node's cached physical target is a separate fact. */\nconst fileRequest = (\n\tspecifier: string,\n\tparent: string,\n): Option.Option<string> => {\n\tif (\n\t\t!Array.some([\"file:\", \"./\", \"../\", \"/\"], (prefix) =>\n\t\t\tString.startsWith(prefix)(specifier),\n\t\t)\n\t)\n\t\treturn Option.none()\n\tconst url = new URL(specifier, parent)\n\treturn url.protocol === \"file:\" ? Option.some(url.href) : Option.none()\n}\n\n/** A scoped Node hook. Mutable bindings bridge synchronous hooks to Effect. */\nexport const modules = (base: string, include: (url: string) => boolean) => {\n\tconst key = `graft-hmr-${++sessions}`\n\tconst prefix = `${key}:`\n\t/** What `request` produces: the generation that imports a specifier. */\n\tconst decodeRequest = Schema.decodeUnknownOption(\n\t\tSchema.TemplateLiteralParser([\n\t\t\tprefix,\n\t\t\tSchema.String.check(Schema.isPattern(/^\\d+$/)),\n\t\t\t\":\",\n\t\t\tSchema.String,\n\t\t]),\n\t)\n\tlet revision = 0\n\tlet importing:\n\t\t{ readonly generation: Generation; readonly reload: boolean } | undefined\n\t// Dependency facts outlive an import operation: apply may import modules later.\n\tlet dependencies = HashMap.empty<string, HashSet.HashSet<string>>()\n\tlet edges = HashMap.empty<\n\t\tstring,\n\t\tHashMap.HashMap<string, HashMap.HashMap<string, Dependency>>\n\t>()\n\tconst link = (\n\t\tid: string,\n\t\tparent: string,\n\t\tchild: string,\n\t\trequest?: string,\n\t) => {\n\t\tconst graph = Option.getOrElse(\n\t\t\tHashMap.get(edges, id),\n\t\t\tHashMap.empty<string, HashMap.HashMap<string, Dependency>>,\n\t\t)\n\t\tconst children = Option.getOrElse(\n\t\t\tHashMap.get(graph, parent),\n\t\t\tHashMap.empty<string, Dependency>,\n\t\t)\n\t\tedges = HashMap.set(\n\t\t\tedges,\n\t\t\tid,\n\t\t\tHashMap.set(\n\t\t\t\tgraph,\n\t\t\t\tparent,\n\t\t\t\tHashMap.set(children, request ?? child, {\n\t\t\t\t\tgeneration: { id: Number(id) },\n\t\t\t\t\tparent,\n\t\t\t\t\turl: child,\n\t\t\t\t\t...(request === undefined ? {} : { request }),\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t}\n\tconst reachable = (id: string, roots: ReadonlyArray<string>) => {\n\t\tconst graph = Option.getOrElse(\n\t\t\tHashMap.get(edges, id),\n\t\t\tHashMap.empty<string, HashMap.HashMap<string, Dependency>>,\n\t\t)\n\t\tlet seen = HashSet.empty<string>()\n\t\tlet pending = roots\n\t\twhile (Array.isReadonlyArrayNonEmpty(pending)) {\n\t\t\tconst [url, ...rest] = pending\n\t\t\tpending = rest\n\t\t\tif (HashSet.has(seen, url)) continue\n\t\t\tseen = HashSet.add(seen, url)\n\t\t\tpending = Array.appendAll(\n\t\t\t\tpending,\n\t\t\t\tArray.map(\n\t\t\t\t\tHashMap.toValues(\n\t\t\t\t\t\tOption.getOrElse(\n\t\t\t\t\t\t\tHashMap.get(graph, url),\n\t\t\t\t\t\t\tHashMap.empty<string, Dependency>,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\t(edge) => edge.url,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\treturn seen\n\t}\n\t// Both checks and polling derive resolution facts from the same owned graph.\n\tconst resolutionsFor = (attempt: Attempt): ReadonlyArray<Attempt> => {\n\t\tconst id = String.String(attempt.generation.id)\n\t\tconst used = reachable(id, [attempt.url])\n\t\tconst graph = Option.getOrElse(\n\t\t\tHashMap.get(edges, id),\n\t\t\tHashMap.empty<string, HashMap.HashMap<string, Dependency>>,\n\t\t)\n\t\treturn [\n\t\t\t...(attempt.request === undefined ? [] : [attempt]),\n\t\t\t...Array.flatMap(HashMap.toValues(graph), (children) =>\n\t\t\t\tArray.filter(\n\t\t\t\t\tHashMap.toValues(children),\n\t\t\t\t\t(edge) =>\n\t\t\t\t\t\tedge.request !== undefined && HashSet.has(used, edge.parent),\n\t\t\t\t),\n\t\t\t),\n\t\t]\n\t}\n\n\tlet sources = HashMap.empty<string, HashMap.HashMap<string, string>>()\n\tlet resolved: string | undefined\n\n\tconst prepare = (): Generation => ({\n\t\tid: ++revision,\n\t})\n\tconst clean = (url: string): string => {\n\t\tconst value = new URL(url)\n\t\tvalue.searchParams.delete(key)\n\t\treturn value.href\n\t}\n\tconst version = (url: string | undefined): string | null =>\n\t\turl === undefined ? null : new URL(url).searchParams.get(key)\n\tconst unsupported = (url: string, format: string | null | undefined) =>\n\t\tformat === \"commonjs\" ||\n\t\tformat === \"commonjs-typescript\" ||\n\t\tformat === \"addon\" ||\n\t\tString.endsWith(\".node\")(new URL(url).pathname)\n\tconst requireRestart = (url: string, id: string) => {\n\t\tdependencies = HashMap.set(\n\t\t\tdependencies,\n\t\t\tid,\n\t\t\tHashSet.add(\n\t\t\t\tOption.getOrElse(HashMap.get(dependencies, id), HashSet.empty<string>),\n\t\t\t\turl,\n\t\t\t),\n\t\t)\n\t\tif (\n\t\t\timporting !== undefined &&\n\t\t\tString.String(importing.generation.id) === id &&\n\t\t\timporting.reload\n\t\t)\n\t\t\tthrow RestartRequired.make({ url })\n\t}\n\n\tconst record = (\n\t\turl: string,\n\t\tid: string,\n\t\tformat: string | null | undefined,\n\t) => {\n\t\tif (unsupported(url, format)) requireRestart(url, id)\n\t}\n\n\tconst hooks = registerHooks({\n\t\tresolve(specifier, context, nextResolve) {\n\t\t\tconst request = decodeRequest(specifier)\n\t\t\tconst entry = Option.isSome(request)\n\t\t\tconst id = Option.match(request, {\n\t\t\t\tonNone: () => version(context.parentURL),\n\t\t\t\tonSome: ([, id]) => id,\n\t\t\t})\n\t\t\tif (id === null) return nextResolve(specifier, context)\n\t\t\tconst resolve = () =>\n\t\t\t\tnextResolve(\n\t\t\t\t\tOption.match(request, {\n\t\t\t\t\t\tonNone: () => specifier,\n\t\t\t\t\t\tonSome: ([, , , target]) => target,\n\t\t\t\t\t}),\n\t\t\t\t\t{\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\tparentURL: entry ? base : clean(context.parentURL!),\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\tconst result = (() => {\n\t\t\t\ttry {\n\t\t\t\t\treturn resolve()\n\t\t\t\t} catch (cause) {\n\t\t\t\t\t// Node reports the missing file even though resolution did not complete.\n\t\t\t\t\tif (\n\t\t\t\t\t\tPredicate.hasProperty(cause, \"url\") &&\n\t\t\t\t\t\ttypeof cause.url === \"string\" &&\n\t\t\t\t\t\tString.startsWith(\"file:\")(cause.url)\n\t\t\t\t\t) {\n\t\t\t\t\t\tif (entry) resolved = cause.url\n\t\t\t\t\t\telse if (context.parentURL !== undefined && include(cause.url))\n\t\t\t\t\t\t\tlink(\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\tclean(context.parentURL),\n\t\t\t\t\t\t\t\tcause.url,\n\t\t\t\t\t\t\t\tOption.getOrUndefined(\n\t\t\t\t\t\t\t\t\tfileRequest(specifier, clean(context.parentURL)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tthrow cause\n\t\t\t\t}\n\t\t\t})()\n\t\t\tif (entry) resolved = result.url\n\t\t\t// Acquiring node:module permits require calls that Node can satisfy\n\t\t\t// without hooks. Record this capability before any cache can hide them.\n\t\t\tif (\n\t\t\t\t!entry &&\n\t\t\t\tresult.url === \"node:module\" &&\n\t\t\t\tcontext.parentURL !== undefined\n\t\t\t) {\n\t\t\t\tlink(id, clean(context.parentURL), result.url)\n\t\t\t\trequireRestart(result.url, id)\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!String.startsWith(\"file:\")(result.url) ||\n\t\t\t\t(!entry && !include(result.url))\n\t\t\t)\n\t\t\t\treturn result\n\t\t\tif (!entry && context.parentURL !== undefined)\n\t\t\t\tlink(\n\t\t\t\t\tid,\n\t\t\t\t\tclean(context.parentURL),\n\t\t\t\t\tresult.url,\n\t\t\t\t\tOption.getOrUndefined(\n\t\t\t\t\t\tfileRequest(specifier, clean(context.parentURL)),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\tconst required = Array.contains(context.conditions, \"require\")\n\t\t\tif (required) requireRestart(result.url, id)\n\t\t\telse record(result.url, id, result.format)\n\t\t\tif (required || unsupported(result.url, result.format)) return result\n\t\t\tconst url = new URL(result.url)\n\t\t\turl.searchParams.set(key, id)\n\t\t\treturn { ...result, url: url.href }\n\t\t},\n\t\tload(url, context, nextLoad) {\n\t\t\tconst id = version(url)\n\t\t\tif (id === null) return nextLoad(url, context)\n\t\t\tconst original = clean(url)\n\t\t\trecord(original, id, context.format)\n\t\t\tconst result = nextLoad(original, context)\n\t\t\tconst source = result.source\n\t\t\tif (source !== undefined && source !== null) {\n\t\t\t\tconst bytes =\n\t\t\t\t\ttypeof source === \"string\"\n\t\t\t\t\t\t? source\n\t\t\t\t\t\t: ArrayBuffer.isView(source)\n\t\t\t\t\t\t\t? new Uint8Array(\n\t\t\t\t\t\t\t\t\tsource.buffer,\n\t\t\t\t\t\t\t\t\tsource.byteOffset,\n\t\t\t\t\t\t\t\t\tsource.byteLength,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: new Uint8Array(source)\n\t\t\t\tsources = HashMap.set(\n\t\t\t\t\tsources,\n\t\t\t\t\tid,\n\t\t\t\t\tHashMap.set(\n\t\t\t\t\t\tOption.getOrElse(\n\t\t\t\t\t\t\tHashMap.get(sources, id),\n\t\t\t\t\t\t\tHashMap.empty<string, string>,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toriginal,\n\t\t\t\t\t\tBase64.encode(bytes),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}\n\t\t\trecord(original, id, result.format)\n\t\t\treturn result\n\t\t},\n\t})\n\treturn {\n\t\tprepare,\n\t\tfileRequest: (specifier: string) => fileRequest(specifier, base),\n\t\tresolutions: (attempts: ReadonlyArray<Attempt>) =>\n\t\t\tArray.flatMap(attempts, resolutionsFor),\n\t\tfiles: (attempts: ReadonlyArray<Attempt>) =>\n\t\t\tArray.reduce(\n\t\t\t\tattempts,\n\t\t\t\tHashMap.empty<string, FileVersion>(),\n\t\t\t\t(files, { generation, url, request }) => {\n\t\t\t\t\tconst contents = Option.getOrElse(\n\t\t\t\t\t\tHashMap.get(sources, String.String(generation.id)),\n\t\t\t\t\t\tHashMap.empty<string, string>,\n\t\t\t\t\t)\n\t\t\t\t\tconst unversioned = Option.getOrElse(\n\t\t\t\t\t\tHashMap.get(dependencies, String.String(generation.id)),\n\t\t\t\t\t\tHashSet.empty<string>,\n\t\t\t\t\t)\n\t\t\t\t\tconst tracked = Array.reduce(\n\t\t\t\t\t\tArray.fromIterable(reachable(String.String(generation.id), [url])),\n\t\t\t\t\t\tfiles,\n\t\t\t\t\t\t(files, url) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!String.startsWith(\"file:\")(url) ||\n\t\t\t\t\t\t\t\tHashSet.has(unversioned, url)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn files\n\t\t\t\t\t\t\t// A retained failed lease must not override a newer import\n\t\t\t\t\t\t\t// of the same file just because its owner is visited last.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tOption.exists(\n\t\t\t\t\t\t\t\t\tHashMap.get(files, url),\n\t\t\t\t\t\t\t\t\t(current) =>\n\t\t\t\t\t\t\t\t\t\tcurrent.generation > generation.id ||\n\t\t\t\t\t\t\t\t\t\t(current.generation === generation.id &&\n\t\t\t\t\t\t\t\t\t\t\tcurrent.resolution !== undefined),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn files\n\t\t\t\t\t\t\treturn HashMap.set(files, url, {\n\t\t\t\t\t\t\t\tgeneration: generation.id,\n\t\t\t\t\t\t\t\tcontent: Option.getOrUndefined(HashMap.get(contents, url)),\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t\treturn Array.reduce(\n\t\t\t\t\t\tresolutionsFor({\n\t\t\t\t\t\t\tgeneration,\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t...(request === undefined ? {} : { request }),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\ttracked,\n\t\t\t\t\t\t(files, edge) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tedge.request === undefined ||\n\t\t\t\t\t\t\t\tHashSet.has(unversioned, edge.url) ||\n\t\t\t\t\t\t\t\tOption.exists(\n\t\t\t\t\t\t\t\t\tHashMap.get(files, edge.request),\n\t\t\t\t\t\t\t\t\t(file) => file.generation > generation.id,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn files\n\t\t\t\t\t\t\treturn HashMap.set(files, edge.request, {\n\t\t\t\t\t\t\t\tgeneration: generation.id,\n\t\t\t\t\t\t\t\tcontent: Option.getOrUndefined(HashMap.get(contents, edge.url)),\n\t\t\t\t\t\t\t\tresolution: pathToFileURL(fileURLToPath(edge.url)).href,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t),\n\t\tunsupported: (generation: Generation, roots?: ReadonlyArray<string>) => {\n\t\t\tconst found = Option.getOrElse(\n\t\t\t\tHashMap.get(dependencies, String.String(generation.id)),\n\t\t\t\tHashSet.empty<string>,\n\t\t\t)\n\t\t\tif (roots === undefined) return found\n\t\t\tconst used = reachable(String.String(generation.id), roots)\n\t\t\treturn HashSet.filter(found, (url) => HashSet.has(used, url))\n\t\t},\n\t\tstart: (generation: Generation, reload = false) => {\n\t\t\timporting = { generation, reload }\n\t\t},\n\t\tdiscard: () => {\n\t\t\timporting = undefined\n\t\t},\n\t\trequest: (specifier: string) => {\n\t\t\tresolved = undefined\n\t\t\treturn `${prefix}${importing!.generation.id}:${specifier}`\n\t\t},\n\t\tresolved: () => Option.fromUndefinedOr(resolved),\n\t\tclose: () => hooks.deregister(),\n\t}\n}\n"],"mappings":";;;;;AAcA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAGhD,MAAa,kBAAkB,KAAa,UAC3C,OAAO,WAAW,OAAO,CAAC,CAAC,GAAG,KAC9B,UAAU,YAAY,OAAO,MAAM,MACjC,MAAM,SAAS,0BAChB,UAAU,YAAY,OAAO,KAAK,KAClC,MAAM,QAAQ,OACb,MAAM,SAAS,YACf,UAAU,YAAY,OAAO,MAAM,KACnC,MAAM,SAAS,cAAc,GAAG;AAGnC,IAAI,WAAW;;AAwBf,MAAM,eACL,WACA,WAC2B;CAC3B,IACC,CAAC,MA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QAAQ,IAAI,OAAO,KAAK,SAAS;KACvC,YAAY,WAAW;KACvB,SAAS,OAAO,eAAe,QAAQ,IAAI,UAAU,KAAK,GAAG,CAAC;KAC9D,YAAY,cAAc,cAAc,KAAK,GAAG,CAAC,CAAC,CAAC;IACpD,CAAC;GACF,CACD;EACD,CACD;EACD,cAAc,YAAwB,UAAkC;GACvE,MAAM,QAAQ,OAAO,UACpB,QAAQ,IAAI,cAAc,OAAO,OAAO,WAAW,EAAE,CAAC,GACtD,QAAQ,KACT;GACA,IAAI,UAAU,KAAA,GAAW,OAAO;GAChC,MAAM,OAAO,UAAU,OAAO,OAAO,WAAW,EAAE,GAAG,KAAK;GAC1D,OAAO,QAAQ,OAAO,QAAQ,QAAQ,QAAQ,IAAI,MAAM,GAAG,CAAC;EAC7D;EACA,QAAQ,YAAwB,SAAS,UAAU;GAClD,YAAY;IAAE;IAAY;GAAO;EAClC;EACA,eAAe;GACd,YAAY,KAAA;EACb;EACA,UAAU,cAAsB;GAC/B,WAAW,KAAA;GACX,OAAO,GAAG,SAAS,UAAW,WAAW,GAAG,GAAG;EAChD;EACA,gBAAgB,OAAO,gBAAgB,QAAQ;EAC/C,aAAa,MAAM,WAAW;CAC/B;AACD"}
1
+ {"version":3,"file":"modules.js","names":[],"sources":["../../src/internal/modules.ts"],"sourcesContent":["// Node's synchronous module hooks have no Effect equivalent.\nimport { digest } from \"./digest\"\nimport { registerHooks } from \"node:module\"\nimport { fileURLToPath, pathToFileURL } from \"node:url\"\nimport {\n\tArray,\n\tChunk,\n\tHashMap,\n\tHashSet,\n\tOption,\n\tPredicate,\n\tSchema,\n\tString,\n} from \"effect\"\n\nexport class RestartRequired extends Schema.TaggedError<\n\tRestartRequired,\n\t{ readonly brand: unique symbol }\n>()(\"RestartRequired\", { url: Schema.String }) {}\n\n// Only a missing entry is disposable; missing dependencies still fail the reload.\nexport const isMissingEntry = (url: string, cause: unknown): boolean =>\n\tString.startsWith(\"file:\")(url) &&\n\tPredicate.hasProperty(cause, \"code\") &&\n\t((cause.code === \"ERR_MODULE_NOT_FOUND\" &&\n\t\tPredicate.hasProperty(cause, \"url\") &&\n\t\tcause.url === url) ||\n\t\t(cause.code === \"ENOENT\" &&\n\t\t\tPredicate.hasProperty(cause, \"path\") &&\n\t\t\tcause.path === fileURLToPath(url)))\n\n// Allocated only when a session starts; importing this module performs no I/O.\nlet sessions = 0\n\n/** A resolution view that allocates fresh URLs for new or invalidated instances. */\nexport interface Generation {\n\treadonly id: number\n}\n\n/** Digest of the bytes actually loaded by a concrete module instance. */\nexport interface FileVersion {\n\treadonly generation: number\n\treadonly content: string | undefined\n\treadonly resolution?: string\n}\n\nexport interface Attempt {\n\treadonly generation: Generation\n\treadonly url: string\n\treadonly request?: string\n}\n\ninterface Dependency extends Attempt {\n\treadonly node: string\n}\n\n/** Resolve local requests lexically; Node's cached physical target is a separate fact. */\nconst fileRequest = (\n\tspecifier: string,\n\tparent: string,\n): Option.Option<string> => {\n\tif (\n\t\t!Array.some([\"file:\", \"./\", \"../\", \"/\"], (prefix) =>\n\t\t\tString.startsWith(prefix)(specifier),\n\t\t)\n\t)\n\t\treturn Option.none()\n\tconst url = new URL(specifier, parent)\n\treturn url.protocol === \"file:\" ? Option.some(url.href) : Option.none()\n}\n\n/** A scoped Node hook. Mutable bindings bridge synchronous hooks to Effect. */\nexport const modules = (base: string, include: (url: string) => boolean) => {\n\tconst key = `graft-hmr-${++sessions}`\n\tconst prefix = `${key}:`\n\tconst decodeRequest = Schema.decodeUnknownOption(\n\t\tSchema.TemplateLiteralParser([\n\t\t\tprefix,\n\t\t\tSchema.String.check(Schema.isPattern(/^\\d+$/)),\n\t\t\t\":\",\n\t\t\tSchema.String,\n\t\t]),\n\t)\n\tlet revision = 0\n\tlet importing:\n\t\t{ readonly generation: Generation; readonly reload: boolean } | undefined\n\tlet resolved: string | undefined\n\t// Resolution views contain only routing identities. Old code can execute after\n\t// replacement (including teardown), so these persistent maps live until close.\n\t// Cached instances also retain their facts: Node does not replay static imports.\n\t// Leases restrict observation, not the lifetime of old routing targets.\n\tlet views = HashMap.empty<number, HashMap.HashMap<string, string>>()\n\tlet edges = HashMap.empty<string, HashMap.HashMap<string, Dependency>>()\n\tlet sources = HashMap.empty<string, string>()\n\tlet dependencies = HashSet.empty<string>()\n\tlet reachCache = HashMap.empty<string, HashSet.HashSet<string>>()\n\tlet retained = HashSet.empty<string>()\n\tlet instantiatedViews = HashSet.empty<number>()\n\tconst clean = (url: string): string => {\n\t\tconst value = new URL(url)\n\t\tvalue.searchParams.delete(key)\n\t\treturn value.href\n\t}\n\tconst version = (url: string | undefined): number | undefined => {\n\t\tif (url === undefined) return undefined\n\t\tconst value = new URL(url).searchParams.get(key)\n\t\treturn value === null ? undefined : Number(value)\n\t}\n\tconst tag = (url: string, id: number) => {\n\t\tconst value = new URL(url)\n\t\tvalue.searchParams.set(key, String.String(id))\n\t\treturn value.href\n\t}\n\tconst route = (url: string, id: number): string =>\n\t\tOption.getOrElse(\n\t\t\tHashMap.get(\n\t\t\t\tOption.getOrElse(HashMap.get(views, id), HashMap.empty<string, string>),\n\t\t\t\turl,\n\t\t\t),\n\t\t\t() => tag(url, id),\n\t\t)\n\n\tconst root = (attempt: Attempt) => route(attempt.url, attempt.generation.id)\n\tconst children = (node: string) =>\n\t\tOption.getOrElse(\n\t\t\tHashMap.get(edges, node),\n\t\t\tHashMap.empty<string, Dependency>,\n\t\t)\n\tconst reachable = (node: string) => {\n\t\tconst cached = HashMap.get(reachCache, node)\n\t\tif (Option.isSome(cached)) return cached.value\n\t\tlet seen = HashSet.empty<string>()\n\t\tlet pending: Chunk.Chunk<string> = Chunk.of(node)\n\t\twhile (Chunk.isNonEmpty(pending)) {\n\t\t\tconst current = Chunk.headNonEmpty(pending)\n\t\t\tpending = Chunk.drop(pending, 1)\n\t\t\tif (HashSet.has(seen, current)) continue\n\t\t\tseen = HashSet.add(seen, current)\n\t\t\tfor (const edge of HashMap.values(children(current)))\n\t\t\t\tpending = Chunk.prepend(pending, edge.node)\n\t\t}\n\t\treachCache = HashMap.set(reachCache, node, seen)\n\t\treturn seen\n\t}\n\tconst usedBy = (attempts: ReadonlyArray<Attempt>) => {\n\t\tconst roots = HashSet.fromIterable(Array.map(attempts, root))\n\t\tlet used = HashSet.empty<string>()\n\t\tfor (const node of roots) used = HashSet.union(used, reachable(node))\n\t\treturn used\n\t}\n\tconst link = (parent: string, node: string, request?: string) => {\n\t\tif (\n\t\t\timporting === undefined &&\n\t\t\t!HashSet.has(retained, parent) &&\n\t\t\t!HashSet.has(instantiatedViews, version(parent)!)\n\t\t)\n\t\t\treturn\n\t\tretained = HashSet.add(retained, node)\n\t\tconst url = clean(node)\n\t\tconst edge = {\n\t\t\tnode,\n\t\t\turl,\n\t\t\tgeneration: { id: version(node)! },\n\t\t\t...(request === undefined ? {} : { request }),\n\t\t}\n\t\tconst previous = HashMap.get(children(parent), request ?? url)\n\t\tif (\n\t\t\tOption.exists(\n\t\t\t\tprevious,\n\t\t\t\t(previous) => previous.node === node && previous.request === request,\n\t\t\t)\n\t\t)\n\t\t\treturn\n\t\tedges = HashMap.set(\n\t\t\tedges,\n\t\t\tparent,\n\t\t\tHashMap.set(children(parent), request ?? url, edge),\n\t\t)\n\t\treachCache = HashMap.empty()\n\t}\n\tconst resolutions = (\n\t\tattempts: ReadonlyArray<Attempt>,\n\t): ReadonlyArray<Attempt> => [\n\t\t...Array.filter(attempts, (attempt) => attempt.request !== undefined),\n\t\t...Array.flatMap(Array.fromIterable(usedBy(attempts)), (node) =>\n\t\t\tArray.filter(\n\t\t\t\tHashMap.toValues(children(node)),\n\t\t\t\t(edge) => edge.request !== undefined,\n\t\t\t),\n\t\t),\n\t]\n\tconst unsupported = (url: string, format: string | null | undefined) =>\n\t\tformat === \"commonjs\" ||\n\t\tformat === \"commonjs-typescript\" ||\n\t\tformat === \"addon\" ||\n\t\tString.endsWith(\".node\")(new URL(url).pathname)\n\tconst requireRestart = (node: string) => {\n\t\tif (importing !== undefined || HashSet.has(retained, node))\n\t\t\tdependencies = HashSet.add(dependencies, node)\n\t\tif (importing?.reload === true && importing.generation.id === version(node))\n\t\t\tthrow RestartRequired.make({ url: clean(node) })\n\t}\n\tconst record = (node: string, format: string | null | undefined) => {\n\t\tif (unsupported(clean(node), format)) requireRestart(node)\n\t}\n\t// One reverse traversal closes cycles and all importers of every dirty instance.\n\tconst invalidated = (\n\t\tattempts: ReadonlyArray<Attempt>,\n\t\tdirty: HashSet.HashSet<string>,\n\t) => {\n\t\tconst used = usedBy(attempts)\n\t\tlet parents = HashMap.empty<string, HashSet.HashSet<string>>()\n\t\tlet pending = Chunk.empty<string>()\n\t\tfor (const node of used) {\n\t\t\tif (HashSet.has(dirty, clean(node)))\n\t\t\t\tpending = Chunk.prepend(pending, node)\n\t\t\tfor (const edge of HashMap.values(children(node))) {\n\t\t\t\tparents = HashMap.set(\n\t\t\t\t\tparents,\n\t\t\t\t\tedge.node,\n\t\t\t\t\tHashSet.add(\n\t\t\t\t\t\tOption.getOrElse(\n\t\t\t\t\t\t\tHashMap.get(parents, edge.node),\n\t\t\t\t\t\t\tHashSet.empty<string>,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tnode,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\tif (edge.request !== undefined && HashSet.has(dirty, edge.request))\n\t\t\t\t\tpending = Chunk.prepend(pending, edge.node)\n\t\t\t}\n\t\t}\n\t\tfor (const attempt of attempts)\n\t\t\tif (attempt.request !== undefined && HashSet.has(dirty, attempt.request))\n\t\t\t\tpending = Chunk.prepend(pending, root(attempt))\n\t\tlet invalid = HashSet.empty<string>()\n\t\twhile (Chunk.isNonEmpty(pending)) {\n\t\t\tconst node = Chunk.headNonEmpty(pending)\n\t\t\tpending = Chunk.drop(pending, 1)\n\t\t\tif (HashSet.has(invalid, node)) continue\n\t\t\tinvalid = HashSet.add(invalid, node)\n\t\t\tfor (const parent of Option.getOrElse(\n\t\t\t\tHashMap.get(parents, node),\n\t\t\t\tHashSet.empty<string>,\n\t\t\t))\n\t\t\t\tpending = Chunk.prepend(pending, parent)\n\t\t}\n\t\treturn invalid\n\t}\n\tconst prepare = (\n\t\tattempts: ReadonlyArray<Attempt> = [],\n\t\tinvalid = HashSet.empty<string>(),\n\t): Generation => {\n\t\tconst id = ++revision\n\t\tconst seed = Array.reduce(attempts, 0, (id, attempt) =>\n\t\t\tMath.max(id, attempt.generation.id),\n\t\t)\n\t\tlet view = Option.getOrElse(\n\t\t\tHashMap.get(views, seed),\n\t\t\tHashMap.empty<string, string>,\n\t\t)\n\t\tconst used = usedBy(attempts)\n\t\t// Retain HAMT structure between views. Default routes need no stored entry;\n\t\t// only modules reused from older views need an explicit override.\n\t\tfor (const [url, node] of view)\n\t\t\tif (!HashSet.has(used, node) || HashSet.has(invalid, node))\n\t\t\t\tview = HashMap.remove(view, url)\n\t\tfor (const node of used) {\n\t\t\tif (HashSet.has(invalid, node)) continue\n\t\t\tconst url = clean(node)\n\t\t\tconst previous = HashMap.get(view, url)\n\t\t\tif (Option.isNone(previous) || version(previous.value)! < version(node)!)\n\t\t\t\tview = HashMap.set(view, url, node)\n\t\t}\n\n\t\tviews = HashMap.set(views, id, view)\n\t\treturn { id }\n\t}\n\tconst hooks = registerHooks({\n\t\tresolve(specifier, context, nextResolve) {\n\t\t\tconst parentNode = context.parentURL\n\t\t\tconst request = decodeRequest(specifier)\n\t\t\tconst entry = Option.isSome(request)\n\t\t\tconst id = Option.match(request, {\n\t\t\t\tonNone: () => version(context.parentURL),\n\t\t\t\tonSome: ([, id]) => Number(id),\n\t\t\t})\n\t\t\tif (id === undefined) return nextResolve(specifier, context)\n\t\t\tconst target = Option.match(request, {\n\t\t\t\tonNone: () => specifier,\n\t\t\t\tonSome: ([, , , target]) => target,\n\t\t\t})\n\t\t\tconst parent = entry ? base : clean(context.parentURL!)\n\t\t\tconst lexical = Option.getOrUndefined(fileRequest(target, parent))\n\t\t\tconst result = (() => {\n\t\t\t\ttry {\n\t\t\t\t\treturn nextResolve(target, { ...context, parentURL: parent })\n\t\t\t\t} catch (cause) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tPredicate.hasProperty(cause, \"url\") &&\n\t\t\t\t\t\ttypeof cause.url === \"string\" &&\n\t\t\t\t\t\tString.startsWith(\"file:\")(cause.url)\n\t\t\t\t\t) {\n\t\t\t\t\t\tif (entry) resolved = cause.url\n\t\t\t\t\t\telse if (include(cause.url))\n\t\t\t\t\t\t\tlink(parentNode!, route(cause.url, id), lexical)\n\t\t\t\t\t}\n\t\t\t\t\tthrow cause\n\t\t\t\t}\n\t\t\t})()\n\t\t\tif (entry) resolved = result.url\n\t\t\tif (!entry && result.url === \"node:module\") {\n\t\t\t\tconst node = route(result.url, id)\n\t\t\t\tlink(parentNode!, node)\n\t\t\t\trequireRestart(node)\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!String.startsWith(\"file:\")(result.url) ||\n\t\t\t\t(!entry && !include(result.url))\n\t\t\t)\n\t\t\t\treturn result\n\t\t\tconst node = route(result.url, id)\n\t\t\tif (!entry) link(parentNode!, node, lexical)\n\t\t\tconst required = Array.contains(context.conditions, \"require\")\n\t\t\tif (required) requireRestart(node)\n\t\t\telse record(node, result.format)\n\t\t\treturn required || unsupported(result.url, result.format)\n\t\t\t\t? result\n\t\t\t\t: { ...result, url: node }\n\t\t},\n\t\tload(url, context, nextLoad) {\n\t\t\tconst id = version(url)\n\t\t\tif (id === undefined) return nextLoad(url, context)\n\t\t\tinstantiatedViews = HashSet.add(instantiatedViews, id)\n\t\t\tconst original = clean(url)\n\t\t\trecord(url, context.format)\n\t\t\tconst result = nextLoad(original, context)\n\t\t\tconst source = result.source\n\t\t\tif (source !== undefined && source !== null) {\n\t\t\t\tconst bytes =\n\t\t\t\t\ttypeof source === \"string\"\n\t\t\t\t\t\t? source\n\t\t\t\t\t\t: ArrayBuffer.isView(source)\n\t\t\t\t\t\t\t? new Uint8Array(\n\t\t\t\t\t\t\t\t\tsource.buffer,\n\t\t\t\t\t\t\t\t\tsource.byteOffset,\n\t\t\t\t\t\t\t\t\tsource.byteLength,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: new Uint8Array(source)\n\t\t\t\tif (importing !== undefined || HashSet.has(retained, url))\n\t\t\t\t\tsources = HashMap.set(sources, url, digest(bytes))\n\t\t\t}\n\t\t\trecord(url, result.format)\n\t\t\treturn result\n\t\t},\n\t})\n\tconst files = (attempts: ReadonlyArray<Attempt>) => {\n\t\tlet files = HashMap.empty<string, FileVersion>()\n\t\tconst put = (url: string, node: string, resolution?: string) => {\n\t\t\tif (!String.startsWith(\"file:\")(url) || HashSet.has(dependencies, node))\n\t\t\t\treturn\n\t\t\tconst generation = version(node)!\n\t\t\tconst previous = HashMap.get(files, url)\n\t\t\tif (\n\t\t\t\tOption.exists(\n\t\t\t\t\tprevious,\n\t\t\t\t\t(previous) =>\n\t\t\t\t\t\tprevious.generation > generation ||\n\t\t\t\t\t\t(previous.generation === generation &&\n\t\t\t\t\t\t\tprevious.resolution !== undefined),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\treturn\n\t\t\tfiles = HashMap.set(files, url, {\n\t\t\t\tgeneration,\n\t\t\t\tcontent: Option.getOrUndefined(HashMap.get(sources, node)),\n\t\t\t\t...(resolution === undefined ? {} : { resolution }),\n\t\t\t})\n\t\t}\n\t\tfor (const node of usedBy(attempts)) put(clean(node), node)\n\t\tfor (const attempt of resolutions(attempts))\n\t\t\tif (attempt.request !== undefined)\n\t\t\t\tput(\n\t\t\t\t\tattempt.request,\n\t\t\t\t\troot(attempt),\n\t\t\t\t\tpathToFileURL(fileURLToPath(attempt.url)).href,\n\t\t\t\t)\n\t\treturn files\n\t}\n\treturn {\n\t\tprepare,\n\t\tfiles,\n\t\tresolutions,\n\t\tinvalidated,\n\t\taffected: (attempt: Attempt, invalid: HashSet.HashSet<string>) =>\n\t\t\tHashSet.has(invalid, root(attempt)),\n\t\tfileRequest: (specifier: string) => fileRequest(specifier, base),\n\t\tunsupported: (generation: Generation, roots?: ReadonlyArray<string>) => {\n\t\t\tconst used =\n\t\t\t\troots === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: usedBy(Array.map(roots, (url) => ({ url, generation })))\n\t\t\treturn HashSet.fromIterable(\n\t\t\t\tArray.map(\n\t\t\t\t\tArray.filter(Array.fromIterable(dependencies), (node) =>\n\t\t\t\t\t\tused === undefined\n\t\t\t\t\t\t\t? version(node) === generation.id\n\t\t\t\t\t\t\t: HashSet.has(used, node),\n\t\t\t\t\t),\n\t\t\t\t\tclean,\n\t\t\t\t),\n\t\t\t)\n\t\t},\n\t\tcollect: (attempts: ReadonlyArray<Attempt>) => {\n\t\t\tconst used = usedBy(attempts)\n\t\t\tconst ownedViews = HashSet.fromIterable(\n\t\t\t\tArray.map(attempts, (attempt) => attempt.generation.id),\n\t\t\t)\n\t\t\tviews = HashMap.filter(\n\t\t\t\tviews,\n\t\t\t\t(_, id) =>\n\t\t\t\t\tid === revision ||\n\t\t\t\t\tHashSet.has(instantiatedViews, id) ||\n\t\t\t\t\tHashSet.has(ownedViews, id),\n\t\t\t)\n\t\t\t// Old code can reach any default route in its instantiated view, even\n\t\t\t// after every lease on that target closed. Preserve its complete graph,\n\t\t\t// source baseline and native capabilities until the session closes.\n\t\t\tconst keep = (node: string) =>\n\t\t\t\tHashSet.has(used, node) ||\n\t\t\t\tHashSet.has(instantiatedViews, version(node)!)\n\t\t\tretained = used\n\t\t\tsources = HashMap.filter(sources, (_, node) => keep(node))\n\t\t\tedges = HashMap.filter(edges, (_, node) => keep(node))\n\t\t\tdependencies = HashSet.filter(dependencies, keep)\n\t\t\treachCache = HashMap.filter(reachCache, (_, node) =>\n\t\t\t\tHashSet.has(used, node),\n\t\t\t)\n\t\t},\n\t\t// Internal counters support deterministic retention tests and external benchmarks.\n\t\tcounts: () => ({\n\t\t\tsources: HashMap.size(sources),\n\t\t\tedges: HashMap.size(edges),\n\t\t\tdependencies: HashSet.size(dependencies),\n\t\t\tviews: HashMap.size(views),\n\t\t}),\n\t\tstart: (generation: Generation, reload = false) => {\n\t\t\timporting = { generation, reload }\n\t\t},\n\t\tdiscard: () => {\n\t\t\timporting = undefined\n\t\t},\n\t\trequest: (specifier: string) => {\n\t\t\tresolved = undefined\n\t\t\treturn `${prefix}${importing!.generation.id}:${specifier}`\n\t\t},\n\t\tresolved: () => Option.fromUndefinedOr(resolved),\n\t\tclose: () => {\n\t\t\thooks.deregister()\n\t\t\tviews = HashMap.empty()\n\t\t\tsources = HashMap.empty()\n\t\t\tedges = HashMap.empty()\n\t\t\tdependencies = HashSet.empty()\n\t\t\treachCache = HashMap.empty()\n\t\t\tretained = HashSet.empty()\n\t\t\tinstantiatedViews = HashSet.empty()\n\t\t},\n\t}\n}\n"],"mappings":";;;;;AAeA,IAAa,kBAAb,cAAqC,OAAO,YAG1C,CAAC,CAAC,mBAAmB,EAAE,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAGhD,MAAa,kBAAkB,KAAa,UAC3C,OAAO,WAAW,OAAO,CAAC,CAAC,GAAG,KAC9B,UAAU,YAAY,OAAO,MAAM,MACjC,MAAM,SAAS,0BAChB,UAAU,YAAY,OAAO,KAAK,KAClC,MAAM,QAAQ,OACb,MAAM,SAAS,YACf,UAAU,YAAY,OAAO,MAAM,KACnC,MAAM,SAAS,cAAc,GAAG;AAGnC,IAAI,WAAW;;AAyBf,MAAM,eACL,WACA,WAC2B;CAC3B,IACC,CAAC,MAAM,KAAK;EAAC;EAAS;EAAM;EAAO;CAAG,IAAI,WACzC,OAAO,WAAW,MAAM,CAAC,CAAC,SAAS,CACpC,GAEA,OAAO,OAAO,KAAK;CACpB,MAAM,MAAM,IAAI,IAAI,WAAW,MAAM;CACrC,OAAO,IAAI,aAAa,UAAU,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK;AACvE;;AAGA,MAAa,WAAW,MAAc,YAAsC;CAC3E,MAAM,MAAM,aAAa,EAAE;CAC3B,MAAM,SAAS,GAAG,IAAI;CACtB,MAAM,gB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IAAI,YAAY,EAAE,CAC5B;GAIA,MAAM,QAAQ,SACb,QAAQ,IAAI,MAAM,IAAI,KACtB,QAAQ,IAAI,mBAAmB,QAAQ,IAAI,CAAE;GAC9C,WAAW;GACX,UAAU,QAAQ,OAAO,UAAU,GAAG,SAAS,KAAK,IAAI,CAAC;GACzD,QAAQ,QAAQ,OAAO,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;GACrD,eAAe,QAAQ,OAAO,cAAc,IAAI;GAChD,aAAa,QAAQ,OAAO,aAAa,GAAG,SAC3C,QAAQ,IAAI,MAAM,IAAI,CACvB;EACD;EAEA,eAAe;GACd,SAAS,QAAQ,KAAK,OAAO;GAC7B,OAAO,QAAQ,KAAK,KAAK;GACzB,cAAc,QAAQ,KAAK,YAAY;GACvC,OAAO,QAAQ,KAAK,KAAK;EAC1B;EACA,QAAQ,YAAwB,SAAS,UAAU;GAClD,YAAY;IAAE;IAAY;GAAO;EAClC;EACA,eAAe;GACd,YAAY,KAAA;EACb;EACA,UAAU,cAAsB;GAC/B,WAAW,KAAA;GACX,OAAO,GAAG,SAAS,UAAW,WAAW,GAAG,GAAG;EAChD;EACA,gBAAgB,OAAO,gBAAgB,QAAQ;EAC/C,aAAa;GACZ,MAAM,WAAW;GACjB,QAAQ,QAAQ,MAAM;GACtB,UAAU,QAAQ,MAAM;GACxB,QAAQ,QAAQ,MAAM;GACtB,eAAe,QAAQ,MAAM;GAC7B,aAAa,QAAQ,MAAM;GAC3B,WAAW,QAAQ,MAAM;GACzB,oBAAoB,QAAQ,MAAM;EACnC;CACD;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graftland/hmr",
3
- "version": "0.2.0-beta.0",
3
+ "version": "0.2.0-beta.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.19.0"
@@ -33,7 +33,7 @@
33
33
  "vitest": "5.1.0"
34
34
  },
35
35
  "dependencies": {
36
- "@graftland/graft": "0.2.0-beta.0"
36
+ "@graftland/graft": "0.2.0-beta.1"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsdown",