effect-atom-svelte-devtools 0.0.0-stage → 0.2.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -2
  3. package/dist/atom-devtools.svelte +753 -0
  4. package/dist/atom-devtools.svelte.d.ts +39 -0
  5. package/dist/graph/atom-graph.svelte +244 -0
  6. package/dist/graph/atom-graph.svelte.d.ts +38 -0
  7. package/dist/graph/frame-graph.svelte +408 -0
  8. package/dist/graph/frame-graph.svelte.d.ts +52 -0
  9. package/dist/graph/index.d.ts +5 -0
  10. package/dist/graph/index.js +7 -0
  11. package/dist/graph/layout.d.ts +65 -0
  12. package/dist/graph/layout.js +531 -0
  13. package/dist/index.d.ts +14 -0
  14. package/dist/index.js +14 -0
  15. package/dist/internal/format.d.ts +27 -0
  16. package/dist/internal/format.js +183 -0
  17. package/dist/internal/graph-view.svelte +134 -0
  18. package/dist/internal/graph-view.svelte.d.ts +10 -0
  19. package/dist/internal/label.d.ts +35 -0
  20. package/dist/internal/label.js +139 -0
  21. package/dist/internal/model.svelte.d.ts +75 -0
  22. package/dist/internal/model.svelte.js +286 -0
  23. package/dist/internal/names.d.ts +29 -0
  24. package/dist/internal/names.js +55 -0
  25. package/dist/internal/settings-view.svelte +198 -0
  26. package/dist/internal/settings-view.svelte.d.ts +16 -0
  27. package/dist/internal/sheets-view.svelte +453 -0
  28. package/dist/internal/sheets-view.svelte.d.ts +11 -0
  29. package/dist/internal/shortcut.d.ts +22 -0
  30. package/dist/internal/shortcut.js +91 -0
  31. package/dist/internal/timeline-view.svelte +291 -0
  32. package/dist/internal/timeline-view.svelte.d.ts +9 -0
  33. package/dist/internal/transform.d.ts +17 -0
  34. package/dist/internal/transform.js +401 -0
  35. package/dist/vite.d.ts +52 -0
  36. package/dist/vite.js +97 -0
  37. package/package.json +78 -4
@@ -0,0 +1,401 @@
1
+ // The atomLabels plugin's source transform: wraps each top-level declaration made by a call, such
2
+ // as `const todosAtom = Atom.make(...)`, in `label(...)` with the variable's name and where it is
3
+ // declared. `label` (./label.ts) decides at run time whether the value is an atom, so the transform
4
+ // needn't know what a call returns: `runtime.atom(...)`, `TodosRpc.query(...)` and a helper of the
5
+ // app's own are labelled just like `Atom.make(...)`. Inside functions, where wrapping every call
6
+ // would be noise, only `Atom.*` calls are.
7
+ //
8
+ // The parser is the one Svelte uses for scripts (acorn with TypeScript), so this works with any
9
+ // Vite version and needs no native binary.
10
+ import path from "node:path";
11
+ import { tsPlugin } from "@sveltejs/acorn-typescript";
12
+ import { Parser } from "acorn";
13
+ import MagicString from "magic-string";
14
+ /** The id the transformed code imports `label` from; the plugin resolves it to ./label.ts. */
15
+ export const labelModule = "virtual:effect-atom-svelte-devtools/label";
16
+ const labelBinding = "__effectAtomSvelteLabel";
17
+ const componentBinding = "__effectAtomSvelteComponent";
18
+ const callBinding = "__effectAtomSvelteCall";
19
+ /** A component's name from its file, as Svelte names it: `counter-list.svelte` is `CounterList`. */
20
+ export const componentName = (file) => path
21
+ .basename(file, ".svelte")
22
+ .split(/[^a-z0-9]+/iu)
23
+ .filter((part) => part !== "")
24
+ .map((part) => part[0]?.toUpperCase() + part.slice(1))
25
+ .join("") || "Component";
26
+ const parser = Parser.extend(tsPlugin());
27
+ // Type annotations around the call, as in `Atom.make(0) as Atom.Writable<number>`, are looked
28
+ // through: only the call is wrapped.
29
+ const wrappers = new Set([
30
+ "TSAsExpression",
31
+ "TSSatisfiesExpression",
32
+ "TSNonNullExpression",
33
+ "TSTypeAssertion",
34
+ "ParenthesizedExpression",
35
+ ]);
36
+ const unwrap = (node) => wrappers.has(node.type) ? unwrap(node.expression) : node;
37
+ /** The identifier a callee chain starts from: `Atom` in `Atom.make(...).pipe(...)`. */
38
+ const chainStart = (node) => {
39
+ if (node.type === "MemberExpression") {
40
+ return chainStart(node.object);
41
+ }
42
+ if (node.type === "CallExpression") {
43
+ return chainStart(node.callee);
44
+ }
45
+ return wrappers.has(node.type) ? chainStart(node.expression) : node;
46
+ };
47
+ /**
48
+ * A call to wrap, or `undefined`. Svelte's runes (`$state(...)`, `$derived.by(...)`) must stay as
49
+ * they are, and hooks (`useAtomValue(...)`) never return an atom, so both are left be.
50
+ */
51
+ const call = (init) => {
52
+ if (init === null || init === undefined) {
53
+ return undefined;
54
+ }
55
+ const node = unwrap(init);
56
+ if (node.type !== "CallExpression") {
57
+ return undefined;
58
+ }
59
+ const start = chainStart(node.callee);
60
+ if (start.type === "Identifier" &&
61
+ /^(?:\$|use[A-Z])/u.test(String(start.name))) {
62
+ return undefined;
63
+ }
64
+ return node;
65
+ };
66
+ /** Whether the call is `Atom.family(...)` (or a bare `family(...)`), whose members are labelled. */
67
+ const isFamily = (node) => {
68
+ const callee = node.callee;
69
+ const property = callee.type === "MemberExpression" ? callee.property : callee;
70
+ return property.type === "Identifier" && property.name === "family";
71
+ };
72
+ // The arguments `Atom.make` takes as a plain value, rather than a function or an effect.
73
+ const plainValues = new Set([
74
+ "Literal",
75
+ "TemplateLiteral",
76
+ "ObjectExpression",
77
+ "ArrayExpression",
78
+ "UnaryExpression",
79
+ ]);
80
+ /**
81
+ * Whether the call makes a state atom, such as `Atom.make(0)` or `Atom.make([]).pipe(...)`: one
82
+ * that holds what is written to it, which a hot reload can carry over.
83
+ */
84
+ const isState = (node) => {
85
+ const callee = node.callee;
86
+ if (callee.type !== "MemberExpression") {
87
+ return false;
88
+ }
89
+ const object = callee.object;
90
+ const property = callee.property;
91
+ if (property.type === "Identifier" && property.name === "pipe") {
92
+ return object.type === "CallExpression" && isState(object);
93
+ }
94
+ const [argument] = node.arguments;
95
+ return (object.type === "Identifier" &&
96
+ object.name === "Atom" &&
97
+ property.type === "Identifier" &&
98
+ property.name === "make" &&
99
+ argument !== undefined &&
100
+ plainValues.has(unwrap(argument).type));
101
+ };
102
+ /** A property's name, when it is written out: `todosAtom` in `{ todosAtom: ... }`. */
103
+ const propertyName = (property) => {
104
+ const key = property.key;
105
+ if (property.computed) {
106
+ return undefined;
107
+ }
108
+ if (key.type === "Identifier") {
109
+ return String(key.name);
110
+ }
111
+ return key.type === "Literal" && typeof key.value === "string"
112
+ ? key.value
113
+ : undefined;
114
+ };
115
+ /** Every node below `node`, depth first. */
116
+ const descendants = (node, found = []) => {
117
+ for (const value of Object.values(node)) {
118
+ const children = Array.isArray(value) ? value : [value];
119
+ for (const child of children) {
120
+ if (typeof child === "object" && child !== null && "type" in child) {
121
+ found.push(child);
122
+ descendants(child, found);
123
+ }
124
+ }
125
+ }
126
+ return found;
127
+ };
128
+ /**
129
+ * The calls to wrap in a program, offset by `base`: every call its top-level declarations make,
130
+ * also inside object literals (`oneByOne.todosAtom` in `const oneByOne = { todosAtom: ... }`), and
131
+ * any `Atom.*` call declared elsewhere, such as in a function that makes atoms.
132
+ *
133
+ * `once` says the program runs once per module, as a module or a `<script module>` does, not once
134
+ * per component; only then are state atoms its top level declares kept across hot reloads.
135
+ */
136
+ const sites = (program, base, defaultName, once) => {
137
+ const found = [];
138
+ const handled = new Set();
139
+ const add = (node, name, at, topLevel = true) => {
140
+ found.push({
141
+ at: base + at,
142
+ end: base + node.end,
143
+ family: isFamily(node),
144
+ keep: once && topLevel && isState(node),
145
+ local: !topLevel,
146
+ name,
147
+ start: base + node.start,
148
+ });
149
+ };
150
+ const members = (object, prefix) => {
151
+ for (const property of object.properties) {
152
+ const key = property.type === "Property" ? propertyName(property) : undefined;
153
+ if (key === undefined) {
154
+ continue;
155
+ }
156
+ const value = unwrap(property.value);
157
+ const node = call(value);
158
+ if (node) {
159
+ add(node, `${prefix}.${key}`, property.key.start);
160
+ }
161
+ else if (value.type === "ObjectExpression") {
162
+ members(value, `${prefix}.${key}`);
163
+ }
164
+ }
165
+ };
166
+ const declare = (declaration) => {
167
+ if (declaration.type !== "VariableDeclaration") {
168
+ return;
169
+ }
170
+ for (const declarator of declaration.declarations) {
171
+ handled.add(declarator);
172
+ const id = declarator.id;
173
+ if (id.type !== "Identifier" || !declarator.init) {
174
+ continue;
175
+ }
176
+ const init = unwrap(declarator.init);
177
+ const node = call(init);
178
+ if (node) {
179
+ add(node, String(id.name), id.start);
180
+ }
181
+ else if (init.type === "ObjectExpression") {
182
+ members(init, String(id.name));
183
+ }
184
+ }
185
+ };
186
+ for (const statement of program.body) {
187
+ if (statement.type === "ExportNamedDeclaration") {
188
+ const { declaration } = statement;
189
+ if (declaration) {
190
+ declare(declaration);
191
+ }
192
+ }
193
+ else if (statement.type === "ExportDefaultDeclaration") {
194
+ const node = call(statement.declaration);
195
+ if (node) {
196
+ add(node, defaultName, node.start);
197
+ }
198
+ }
199
+ else {
200
+ declare(statement);
201
+ }
202
+ }
203
+ for (const node of descendants(program)) {
204
+ if (node.type !== "VariableDeclarator" || handled.has(node)) {
205
+ continue;
206
+ }
207
+ const id = node.id;
208
+ const init = node.init ? call(node.init) : undefined;
209
+ const start = init ? chainStart(init.callee) : undefined;
210
+ if (id.type === "Identifier" &&
211
+ init &&
212
+ start?.type === "Identifier" &&
213
+ start.name === "Atom") {
214
+ add(init, String(id.name), id.start, false);
215
+ }
216
+ }
217
+ return found;
218
+ };
219
+ // A factory is named for what it makes: `todoAtom`, `makeSessionAtom`. `Atom` itself, hooks
220
+ // (`useAtom`) and checks (`isAtom`) never return a new atom.
221
+ const factoryName = /^(?!use[A-Z]|is[A-Z])[\w$]+Atom$/u;
222
+ /**
223
+ * The calls to atom factories in a program, offset by `base`: calls to a function whose name ends
224
+ * in `Atom`. At run time each result that is an atom is named after the call and its arguments,
225
+ * as `mapDraftAtom({"doc":1})`, so a cache that makes a new atom for a key it has seen shows it.
226
+ */
227
+ const factoryCalls = (program, base) => descendants(program).flatMap((node) => {
228
+ const callee = node.type === "CallExpression" ? node.callee : undefined;
229
+ return callee?.type === "Identifier" &&
230
+ factoryName.test(String(callee.name))
231
+ ? [
232
+ {
233
+ calleeEnd: base + callee.end,
234
+ calleeStart: base + callee.start,
235
+ name: String(callee.name),
236
+ },
237
+ ]
238
+ : [];
239
+ });
240
+ const parse = (code) => parser.parse(code, {
241
+ ecmaVersion: "latest",
242
+ sourceType: "module",
243
+ });
244
+ // Svelte's own pattern for finding scripts to preprocess (svelte/src/compiler/preprocess).
245
+ const scriptPattern = /<!--[^]*?-->|<script(?<attributes>(?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>(?<code>[\S\s]*?)<\/script>)/gu;
246
+ /** The scripts of a component: where each one's code starts, the code, and if it is the module script. */
247
+ const scripts = (source) => {
248
+ const found = [];
249
+ for (const match of source.matchAll(scriptPattern)) {
250
+ const [whole] = match;
251
+ const { attributes, code } = match.groups ?? {};
252
+ if (attributes === undefined || code === undefined) {
253
+ continue;
254
+ }
255
+ found.push({
256
+ code,
257
+ module: /\bmodule\b/u.test(attributes),
258
+ start: match.index + whole.indexOf(">") + 1,
259
+ });
260
+ }
261
+ return found;
262
+ };
263
+ /** 1-based line and column of each offset, from a table of where lines start. */
264
+ const locate = (source) => {
265
+ const starts = [0];
266
+ for (const match of source.matchAll(/\n/gu)) {
267
+ starts.push(match.index + 1);
268
+ }
269
+ return (offset) => {
270
+ let low = 0;
271
+ let high = starts.length - 1;
272
+ while (low < high) {
273
+ const middle = Math.ceil((low + high) / 2);
274
+ if ((starts[middle] ?? 0) <= offset) {
275
+ low = middle;
276
+ }
277
+ else {
278
+ high = middle - 1;
279
+ }
280
+ }
281
+ return `${low + 1}:${offset - (starts[low] ?? 0) + 1}`;
282
+ };
283
+ };
284
+ /** A short hash of some source, to tell whether it changed. */
285
+ const hash = (text) => {
286
+ let value = 0;
287
+ for (let index = 0; index < text.length; index += 1) {
288
+ // Modulo the largest prime below 2^32, so the product stays an exact integer.
289
+ value = (value * 31 + (text.codePointAt(index) ?? 0)) % 4_294_967_291;
290
+ }
291
+ return value.toString(36);
292
+ };
293
+ /**
294
+ * Where a file is, as the dev server addresses it, with forward slashes: relative to `root`, or
295
+ * outside it by its full path after `/@fs/`.
296
+ */
297
+ const address = (file, root) => {
298
+ const relative = path.relative(root, file);
299
+ const inside = !relative.startsWith("..") && !path.isAbsolute(relative);
300
+ const slashed = (inside ? relative : file).replaceAll("\\", "/");
301
+ return inside ? `/${slashed}` : `/@fs/${slashed.replace(/^\//u, "")}`;
302
+ };
303
+ /** Wraps each labelled declaration's call in `label(...)`, and each factory's callee in `call(...)`. */
304
+ const wrap = (output, code, found, calls, where) => {
305
+ for (const site of found) {
306
+ const options = {
307
+ ...(site.family ? { family: true } : {}),
308
+ // The declaration's source, hashed: an edit to it means the old value no longer applies.
309
+ ...(site.keep ? { keep: hash(code.slice(site.start, site.end)) } : {}),
310
+ ...(site.local ? { local: true } : {}),
311
+ };
312
+ const args = [
313
+ JSON.stringify(site.name),
314
+ JSON.stringify(where(site.at)),
315
+ ...(Object.keys(options).length > 0 ? [JSON.stringify(options)] : []),
316
+ ];
317
+ output.appendLeft(site.start, `${labelBinding}(`);
318
+ output.appendRight(site.end, `, ${args.join(", ")})`);
319
+ }
320
+ // After the sites: a declaration made by a factory's call wraps the call, callee and all.
321
+ for (const factory of calls) {
322
+ output.appendLeft(factory.calleeStart, `${callBinding}(`);
323
+ output.appendRight(factory.calleeEnd, `, ${JSON.stringify(factory.name)}, ${JSON.stringify(where(factory.calleeStart))})`);
324
+ }
325
+ };
326
+ /**
327
+ * Labels the atoms declared in a module or a component's scripts, and names the component at the
328
+ * top of its instance script, for the inspector scopes its hooks report to. Returns the new code and
329
+ * its source map, or `undefined` when there is nothing to do or the code doesn't parse (a component
330
+ * whose script needs a preprocessor, say), which leaves the file as it is.
331
+ */
332
+ export const labelAtoms = (code, file, root, { keep = true } = {}) => {
333
+ const svelte = file.endsWith(".svelte");
334
+ const defaultName = path.basename(file).replace(/\..*$/u, "");
335
+ let found = [];
336
+ let calls = [];
337
+ // Where the import of `label` goes.
338
+ let importAt = 0;
339
+ // Where a component's instance script starts, to name the component there.
340
+ let instanceAt;
341
+ try {
342
+ if (svelte) {
343
+ const blocks = scripts(code).map((block) => {
344
+ const program = parse(block.code);
345
+ return {
346
+ ...block,
347
+ calls: factoryCalls(program, block.start),
348
+ sites: sites(program, block.start, defaultName, block.module),
349
+ };
350
+ });
351
+ found = blocks.flatMap((block) => block.sites);
352
+ calls = blocks.flatMap((block) => block.calls);
353
+ // The module script if it uses the label module, as the instance script can see its imports
354
+ // but not the other way round.
355
+ const uses = (block) => block.sites.length > 0 || block.calls.length > 0;
356
+ const host = blocks.find((block) => block.module && uses(block)) ??
357
+ blocks.find(uses);
358
+ importAt = host?.start ?? 0;
359
+ instanceAt = blocks.find((block) => !block.module)?.start;
360
+ }
361
+ else {
362
+ const program = parse(code);
363
+ found = sites(program, 0, defaultName, true);
364
+ calls = factoryCalls(program, 0);
365
+ importAt = code.startsWith("#!") ? code.indexOf("\n") + 1 : 0;
366
+ }
367
+ }
368
+ catch {
369
+ return undefined;
370
+ }
371
+ if (found.length === 0 && calls.length === 0 && instanceAt === undefined) {
372
+ return undefined;
373
+ }
374
+ if (!keep) {
375
+ // A build has no hot reloads to keep values across.
376
+ found = found.map((site) => ({ ...site, keep: false }));
377
+ }
378
+ const at = locate(code);
379
+ const place = address(file, root);
380
+ const output = new MagicString(code);
381
+ const specifiers = [
382
+ ...(found.length > 0 ? [`label as ${labelBinding}`] : []),
383
+ ...(calls.length > 0 ? [`call as ${callBinding}`] : []),
384
+ ];
385
+ if (specifiers.length > 0) {
386
+ output.appendLeft(importAt, `import { ${specifiers.join(", ")} } from ${JSON.stringify(labelModule)};`);
387
+ }
388
+ if (instanceAt !== undefined) {
389
+ // Before anything else in the script, so the component's hooks see its name.
390
+ output.appendLeft(instanceAt, `import { component as ${componentBinding} } from ${JSON.stringify(labelModule)};${componentBinding}(${JSON.stringify(componentName(file))}, ${JSON.stringify(place)});`);
391
+ }
392
+ wrap(output, code, found, calls, (offset) => `${place}:${at(offset)}`);
393
+ return {
394
+ code: output.toString(),
395
+ map: output.generateMap({
396
+ hires: "boundary",
397
+ includeContent: true,
398
+ source: file,
399
+ }),
400
+ };
401
+ };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { FilterPattern, Plugin } from "vite";
2
+ /**
3
+ * Options for `atomLabels`.
4
+ *
5
+ * @since 0.2.0
6
+ * @category models
7
+ */
8
+ export interface AtomLabelsOptions {
9
+ /** Files to label. Defaults to Svelte components and JavaScript and TypeScript modules. */
10
+ readonly include?: FilterPattern | undefined;
11
+ /** Files to leave alone. Defaults to anything in `node_modules`. */
12
+ readonly exclude?: FilterPattern | undefined;
13
+ /**
14
+ * Labels production builds too, for an app that shows its atoms' names in production: the
15
+ * effect-atom-svelte docs draw each example's graph. Off by default.
16
+ */
17
+ readonly builds?: boolean | undefined;
18
+ }
19
+ /**
20
+ * Labels each atom declared at the top level of a module, or of a component's `<script>` or
21
+ * `<script module>`, with the name of its variable and where it is declared, for the devtools and
22
+ * anything else that reads `atom.label`:
23
+ *
24
+ * ```ts
25
+ * export const todosAtom = Atom.make(...) // label: ["todosAtom", "at todosAtom (/src/lib/todos.ts:4:14)"]
26
+ * ```
27
+ *
28
+ * The atom keeps its identity: it is labelled in place, not copied as `Atom.withLabel` does. A
29
+ * label the code sets itself wins. Members of an `Atom.family` are labelled with their argument,
30
+ * as `todoAtom(3)`.
31
+ *
32
+ * Only the dev server applies it, unless `builds` is set; production builds are left as they are,
33
+ * and never keep values across reloads. Put it before
34
+ * `sveltekit()` or `svelte()`, so it sees components before they are compiled.
35
+ *
36
+ * **Example** (Adding the plugin)
37
+ *
38
+ * ```ts
39
+ * // vite.config.ts
40
+ * import { sveltekit } from "@sveltejs/kit/vite";
41
+ * import { atomLabels } from "effect-atom-svelte-devtools/vite";
42
+ * import { defineConfig } from "vite";
43
+ *
44
+ * export default defineConfig({
45
+ * plugins: [atomLabels(), sveltekit()],
46
+ * });
47
+ * ```
48
+ *
49
+ * @since 0.2.0
50
+ * @category plugins
51
+ */
52
+ export declare const atomLabels: (options?: AtomLabelsOptions) => Plugin;
package/dist/vite.js ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The Vite plugin that names your atoms after the variables that hold them.
3
+ *
4
+ * @since 0.2.0
5
+ */
6
+ import { existsSync, realpathSync } from "node:fs";
7
+ import { createRequire } from "node:module";
8
+ import path from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import { createFilter, normalizePath } from "vite";
11
+ import { labelAtoms, labelModule } from "./internal/transform.js";
12
+ // ./internal/label.ts, or its build next to this file once the package is built.
13
+ const labelFile = (() => {
14
+ const built = fileURLToPath(new URL("internal/label.js", import.meta.url));
15
+ return existsSync(built)
16
+ ? built
17
+ : fileURLToPath(new URL("internal/label.ts", import.meta.url));
18
+ })();
19
+ /**
20
+ * Labels each atom declared at the top level of a module, or of a component's `<script>` or
21
+ * `<script module>`, with the name of its variable and where it is declared, for the devtools and
22
+ * anything else that reads `atom.label`:
23
+ *
24
+ * ```ts
25
+ * export const todosAtom = Atom.make(...) // label: ["todosAtom", "at todosAtom (/src/lib/todos.ts:4:14)"]
26
+ * ```
27
+ *
28
+ * The atom keeps its identity: it is labelled in place, not copied as `Atom.withLabel` does. A
29
+ * label the code sets itself wins. Members of an `Atom.family` are labelled with their argument,
30
+ * as `todoAtom(3)`.
31
+ *
32
+ * Only the dev server applies it, unless `builds` is set; production builds are left as they are,
33
+ * and never keep values across reloads. Put it before
34
+ * `sveltekit()` or `svelte()`, so it sees components before they are compiled.
35
+ *
36
+ * **Example** (Adding the plugin)
37
+ *
38
+ * ```ts
39
+ * // vite.config.ts
40
+ * import { sveltekit } from "@sveltejs/kit/vite";
41
+ * import { atomLabels } from "effect-atom-svelte-devtools/vite";
42
+ * import { defineConfig } from "vite";
43
+ *
44
+ * export default defineConfig({
45
+ * plugins: [atomLabels(), sveltekit()],
46
+ * });
47
+ * ```
48
+ *
49
+ * @since 0.2.0
50
+ * @category plugins
51
+ */
52
+ export const atomLabels = (options = {}) => {
53
+ const filter = createFilter(options.include ?? /\.(?:svelte|[cm]?[jt]s)$/u, options.exclude ?? /[\\/]node_modules[\\/]/u);
54
+ let root = process.cwd();
55
+ let serving = true;
56
+ // This package's code and the library's aren't the app's, even when a workspace links them from
57
+ // outside node_modules. Labelling the library would also loop: the label module imports it.
58
+ // Not import.meta.dirname, which Node only has from 20.11; Vite 5 runs on Node 18.
59
+ // oxlint-disable-next-line unicorn/prefer-import-meta-properties
60
+ const here = fileURLToPath(new URL(".", import.meta.url));
61
+ const packages = [normalizePath(here)];
62
+ return {
63
+ apply: (_, env) => options.builds === true || env.command === "serve",
64
+ configResolved(config) {
65
+ ({ root } = config);
66
+ serving = config.command === "serve";
67
+ try {
68
+ const require = createRequire(path.join(root, "package.json"));
69
+ const library = require.resolve("effect-atom-svelte/package.json");
70
+ packages.push(`${normalizePath(path.dirname(realpathSync(library)))}/`);
71
+ }
72
+ catch {
73
+ // The app can't resolve the library, so there is none of its code to skip.
74
+ }
75
+ const names = config.plugins.map((plugin) => plugin.name);
76
+ const svelte = names.findIndex((name) => name.startsWith("vite-plugin-svelte"));
77
+ if (svelte !== -1 &&
78
+ svelte < names.indexOf("effect-atom-svelte-devtools:labels")) {
79
+ config.logger.warn("effect-atom-svelte-devtools: atomLabels() comes after the Svelte plugin, so atoms declared in components aren't labelled. Put it before sveltekit() or svelte().");
80
+ }
81
+ },
82
+ enforce: "pre",
83
+ name: "effect-atom-svelte-devtools:labels",
84
+ resolveId(id) {
85
+ return id === labelModule ? labelFile : undefined;
86
+ },
87
+ transform(code, id) {
88
+ // Ids with a query are other views of a file, such as a component's styles.
89
+ if (id.includes("?") ||
90
+ !filter(id) ||
91
+ packages.some((directory) => id.startsWith(directory))) {
92
+ return undefined;
93
+ }
94
+ return labelAtoms(code, id, root, { keep: serving });
95
+ },
96
+ };
97
+ };
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "effect-atom-svelte-devtools",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "description": "Developer tools for effect-atom-svelte: atom names from your source, and a live view of the registry",
5
+ "keywords": [
6
+ "devtools",
7
+ "effect",
8
+ "effect-atom",
9
+ "effect-atom-svelte",
10
+ "svelte",
11
+ "vite-plugin"
12
+ ],
13
+ "homepage": "https://atom.jarrednorris.dev",
14
+ "bugs": "https://github.com/jarrednorrisdev/effect-atom-svelte/issues",
15
+ "license": "MIT",
16
+ "author": "Jarred Norris",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/jarrednorrisdev/effect-atom-svelte.git",
20
+ "directory": "packages/effect-atom-svelte-devtools"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "!dist/**/*.test.*"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "types": "./dist/index.d.ts",
29
+ "svelte": "./dist/index.js",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "svelte": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./graph": {
37
+ "types": "./dist/graph/index.d.ts",
38
+ "svelte": "./dist/graph/index.js",
39
+ "default": "./dist/graph/index.js"
40
+ },
41
+ "./vite": {
42
+ "types": "./dist/vite.d.ts",
43
+ "default": "./dist/vite.js"
44
+ },
45
+ "./package.json": "./package.json"
46
+ },
47
+ "scripts": {
48
+ "build": "svelte-package -i src -o dist",
49
+ "check": "svelte-check --tsconfig ./tsconfig.json",
50
+ "test": "vitest run"
51
+ },
52
+ "dependencies": {
53
+ "@sveltejs/acorn-typescript": "^1.0.13",
54
+ "acorn": "^8.18.0",
55
+ "esm-env": "^1.2.2",
56
+ "magic-string": "^0.30.21"
57
+ },
58
+ "devDependencies": {
59
+ "@sveltejs/package": "^3.0.0",
60
+ "@sveltejs/vite-plugin-svelte": "^7.2.0",
61
+ "@types/node": "^24",
62
+ "effect": "4.0.1",
63
+ "effect-atom-svelte": "workspace:*",
64
+ "svelte": "^5.57.2",
65
+ "svelte-check": "^4.6.0",
66
+ "vite": "^8.3.0",
67
+ "vitest": "^5.0.3"
68
+ },
69
+ "peerDependencies": {
70
+ "effect": "~4.0.0",
71
+ "effect-atom-svelte": "^0.2.0",
72
+ "svelte": "^5.57.2",
73
+ "vite": ">=5.0.0"
74
+ },
75
+ "peerDependenciesMeta": {
76
+ "vite": {
77
+ "optional": true
78
+ }
79
+ }
80
+ }