@doweljs/vite 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,195 @@
1
+ /**
2
+ * The project-wide graph assembled from per-module analyses.
3
+ *
4
+ * Nodes are identified by `kind:name`. Names are unique the way the runtime
5
+ * requires: scopes share one name space, and slots, services and executions
6
+ * share another. Dependency references are resolved through each module's
7
+ * imports and re-exports, so edges cross module boundaries and barrels.
8
+ */
9
+ const nodeId = (declaration) => `${declaration.kind}:${declaration.name}`;
10
+ /** The runtime's name space for a declaration (see `keyOf` in `@doweljs/core/hot`). */
11
+ const nameKey = (declaration) => declaration.kind === 'scope' ? `scope ${declaration.name}` : declaration.name;
12
+ /** How deep re-export and import chains are followed. */
13
+ const MAX_HOPS = 8;
14
+ export class Registry {
15
+ modules = new Map();
16
+ /** Declarations by node id, then by module. */
17
+ byId = new Map();
18
+ /** Declaration counts by name key, then by module. */
19
+ byName = new Map();
20
+ set(id, analysis, resolved) {
21
+ this.delete(id);
22
+ this.modules.set(id, { analysis, resolved });
23
+ for (const declaration of analysis.declarations) {
24
+ index(this.byId, nodeId(declaration)).set(id, declaration);
25
+ const counts = index(this.byName, nameKey(declaration));
26
+ counts.set(id, (counts.get(id) ?? 0) + 1);
27
+ }
28
+ }
29
+ delete(id) {
30
+ const entry = this.modules.get(id);
31
+ if (entry === undefined)
32
+ return;
33
+ this.modules.delete(id);
34
+ for (const declaration of entry.analysis.declarations) {
35
+ unindex(this.byId, nodeId(declaration), id);
36
+ unindex(this.byName, nameKey(declaration), id);
37
+ }
38
+ }
39
+ /** Forgets every module of a deleted file, queries included. */
40
+ deleteFile(file) {
41
+ for (const id of [...this.modules.keys()]) {
42
+ if (id === file || id.startsWith(`${file}?`))
43
+ this.delete(id);
44
+ }
45
+ }
46
+ /** Names a module declares that are also declared elsewhere, or more than once in it. */
47
+ duplicatesOf(id) {
48
+ const entry = this.modules.get(id);
49
+ if (entry === undefined)
50
+ return [];
51
+ const keys = new Set(entry.analysis.declarations.map(nameKey));
52
+ return [...keys].flatMap((key) => duplicate(key, this.byName.get(key)));
53
+ }
54
+ graph() {
55
+ const nodes = [];
56
+ for (const [module, entry] of this.modules) {
57
+ for (const declaration of entry.analysis.declarations) {
58
+ nodes.push({
59
+ id: nodeId(declaration),
60
+ kind: declaration.kind,
61
+ name: declaration.name,
62
+ scope: this.resolveScope(module, declaration),
63
+ parent: declaration.kind === 'scope' && declaration.scopeRef !== null
64
+ ? this.resolveRef(module, declaration.scopeRef)
65
+ : null,
66
+ many: declaration.many,
67
+ module,
68
+ local: declaration.local,
69
+ start: declaration.start,
70
+ end: declaration.end,
71
+ deps: declaration.deps.map((dep) => {
72
+ const target = dep.ref === null ? null : this.resolveRef(module, dep.ref);
73
+ return {
74
+ key: dep.key,
75
+ target,
76
+ optional: dep.optional,
77
+ };
78
+ }),
79
+ });
80
+ }
81
+ }
82
+ const duplicates = [...this.byName].flatMap(([key, counts]) => duplicate(key, counts));
83
+ return { nodes, duplicates };
84
+ }
85
+ /**
86
+ * The scope name of a declaration: literal, or the name of the referenced
87
+ * scope declaration. An execution lives in the parent of the scope its
88
+ * runs open, as it does at runtime.
89
+ */
90
+ resolveScope(module, declaration) {
91
+ if (declaration.scope !== null)
92
+ return declaration.scope;
93
+ if (declaration.scopeRef === null)
94
+ return null;
95
+ const id = this.resolveRef(module, declaration.scopeRef);
96
+ const found = id === null ? null : this.find(id);
97
+ if (found === null)
98
+ return null;
99
+ return declaration.kind === 'execution'
100
+ ? this.resolveScope(found.module, found.declaration)
101
+ : found.declaration.name;
102
+ }
103
+ find(id) {
104
+ const declarations = this.byId.get(id);
105
+ if (declarations === undefined)
106
+ return null;
107
+ for (const [module, declaration] of declarations)
108
+ return { module, declaration };
109
+ return null;
110
+ }
111
+ /** Resolves a reference in a module to a node id, following imports and re-exports. */
112
+ resolveRef(module, ref, hops = 0) {
113
+ const entry = this.modules.get(module);
114
+ if (entry === undefined || hops > MAX_HOPS)
115
+ return null;
116
+ const local = entry.analysis.declarations.find((d) => d.local === ref.local);
117
+ if (local !== undefined)
118
+ return ref.member === null ? nodeId(local) : null;
119
+ const imported = entry.analysis.imports.get(ref.local);
120
+ const source = imported === undefined ? undefined : entry.resolved.get(imported.source);
121
+ if (imported === undefined || source === undefined)
122
+ return null;
123
+ if (imported.imported === '*') {
124
+ return ref.member === null ? null : this.resolveExport(source, ref.member, hops + 1);
125
+ }
126
+ return ref.member === null ? this.resolveExport(source, imported.imported, hops + 1) : null;
127
+ }
128
+ /** Resolves a name a module exports to a node id. */
129
+ resolveExport(module, name, hops) {
130
+ const entry = this.modules.get(module);
131
+ if (entry === undefined || hops > MAX_HOPS)
132
+ return null;
133
+ const local = entry.analysis.exports.get(name);
134
+ if (local !== undefined)
135
+ return this.resolveRef(module, { local, member: null }, hops + 1);
136
+ const reexport = entry.analysis.reexports.get(name);
137
+ if (reexport !== undefined) {
138
+ const source = entry.resolved.get(reexport.source);
139
+ if (source === undefined || reexport.imported === '*')
140
+ return null;
141
+ return this.resolveExport(source, reexport.imported, hops + 1);
142
+ }
143
+ for (const star of entry.analysis.stars) {
144
+ const source = entry.resolved.get(star);
145
+ const found = source === undefined ? null : this.resolveExport(source, name, hops + 1);
146
+ if (found !== null)
147
+ return found;
148
+ }
149
+ return null;
150
+ }
151
+ }
152
+ /**
153
+ * The import and re-export sources a module's graph edges may lead through:
154
+ * those `Registry` follows when it resolves the module's references and
155
+ * exports. The plugin resolves exactly these to module ids.
156
+ */
157
+ export function sourcesToResolve(analysis) {
158
+ const sources = new Set(analysis.stars);
159
+ for (const reexport of analysis.reexports.values())
160
+ sources.add(reexport.source);
161
+ const locals = new Set(analysis.exports.values());
162
+ for (const declaration of analysis.declarations) {
163
+ for (const ref of [declaration.scopeRef, ...declaration.deps.map((dep) => dep.ref)]) {
164
+ if (ref !== null)
165
+ locals.add(ref.local);
166
+ }
167
+ }
168
+ for (const local of locals) {
169
+ const imported = analysis.imports.get(local);
170
+ if (imported !== undefined)
171
+ sources.add(imported.source);
172
+ }
173
+ return sources;
174
+ }
175
+ function index(map, key) {
176
+ let inner = map.get(key);
177
+ if (inner === undefined) {
178
+ inner = new Map();
179
+ map.set(key, inner);
180
+ }
181
+ return inner;
182
+ }
183
+ function unindex(map, key, module) {
184
+ const inner = map.get(key);
185
+ inner?.delete(module);
186
+ if (inner?.size === 0)
187
+ map.delete(key);
188
+ }
189
+ function duplicate(key, counts) {
190
+ if (counts === undefined)
191
+ return [];
192
+ const modules = [...counts].flatMap(([module, count]) => Array(count).fill(module));
193
+ return modules.length > 1 ? [{ id: key, modules }] : [];
194
+ }
195
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/analysis/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+CH,MAAM,MAAM,GAAG,CAAC,WAA+C,EAAU,EAAE,CAC1E,GAAG,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,EAAE,CAAA;AAE1C,uFAAuF;AACvF,MAAM,OAAO,GAAG,CAAC,WAA+C,EAAU,EAAE,CAC3E,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAA;AAE9E,yDAAyD;AACzD,MAAM,QAAQ,GAAG,CAAC,CAAA;AAElB,MAAM,OAAO,QAAQ;IACH,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAA;IACnD,+CAA+C;IAC9B,IAAI,GAAG,IAAI,GAAG,EAAoC,CAAA;IACnE,sDAAsD;IACrC,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAA;IAEhE,GAAG,CAAC,EAAU,EAAE,QAAwB,EAAE,QAAqC;QAC9E,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACf,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,E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CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AACxD,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `@doweljs/vite`: Vite integration for dowel.
3
+ *
4
+ * - Hot replacement: editing a service swaps it (and its dependents) inside
5
+ * live containers without reloading, keeping unrelated instances such as
6
+ * database connections alive.
7
+ * - Diagnostics: duplicate slot or service names across modules are reported
8
+ * at transform time.
9
+ * - A static graph of every declaration, which `@doweljs/devtools` draws.
10
+ *
11
+ * ```ts
12
+ * import dowel from '@doweljs/vite'
13
+ * export default defineConfig({ plugins: [dowel()] })
14
+ * ```
15
+ */
16
+ import type { Plugin } from 'vite';
17
+ import { type Graph } from './analysis/registry.ts';
18
+ export type { Duplicate, Graph, GraphEdge, GraphNode } from './analysis/registry.ts';
19
+ export interface DowelPluginOptions {
20
+ /**
21
+ * How modules that declare slots or services take part in hot replacement.
22
+ * - `auto` (default): modules register their declarations on every
23
+ * evaluation, and accept their own updates when every export is a dowel
24
+ * declaration. Mixed modules fall back to Vite's normal propagation.
25
+ * - `always`: every declaring module accepts its own updates.
26
+ * - `false`: no hot replacement code is injected.
27
+ */
28
+ readonly hot?: 'auto' | 'always' | false;
29
+ /** Module ids to analyze. Default: every `.js`/`.ts` module. */
30
+ readonly include?: RegExp | readonly RegExp[];
31
+ /** Module ids to skip, in addition to `node_modules`, which is always skipped. */
32
+ readonly exclude?: RegExp | readonly RegExp[];
33
+ }
34
+ /** What other plugins can ask of the dowel plugin, found by its name in the resolved config. */
35
+ export interface DowelPluginApi {
36
+ /** The graph as currently known from static analysis. */
37
+ graph(): Graph;
38
+ /**
39
+ * Has every module given hot code import `id` too, so it runs in each
40
+ * environment that declares nodes. The devtools load their client this way.
41
+ */
42
+ addClientModule(id: string): void;
43
+ }
44
+ export interface DowelPlugin extends Plugin {
45
+ readonly api: DowelPluginApi;
46
+ }
47
+ export default function dowel(options?: DowelPluginOptions): DowelPlugin;
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,OAAO,EAAE,KAAK,KAAK,EAA8B,MAAM,wBAAwB,CAAA;AAI/E,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEpF,MAAM,WAAW,kBAAkB;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAA;IACxC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;IAC7C,kFAAkF;IAClF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CAC7C;AAED,gGAAgG;AAChG,MAAM,WAAW,cAAc;IAC9B,yDAAyD;IACzD,KAAK,IAAI,KAAK,CAAA;IACd;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CACjC;AAED,MAAM,WAAW,WAAY,SAAQ,MAAM;IAC1C,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAA;CAC5B;AAKD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CA4F3E"}
package/dist/index.js ADDED
@@ -0,0 +1,112 @@
1
+ /**
2
+ * `@doweljs/vite`: Vite integration for dowel.
3
+ *
4
+ * - Hot replacement: editing a service swaps it (and its dependents) inside
5
+ * live containers without reloading, keeping unrelated instances such as
6
+ * database connections alive.
7
+ * - Diagnostics: duplicate slot or service names across modules are reported
8
+ * at transform time.
9
+ * - A static graph of every declaration, which `@doweljs/devtools` draws.
10
+ *
11
+ * ```ts
12
+ * import dowel from '@doweljs/vite'
13
+ * export default defineConfig({ plugins: [dowel()] })
14
+ * ```
15
+ */
16
+ import { analyze, mayDeclare } from './analysis/analyze.js';
17
+ import { Registry, sourcesToResolve } from './analysis/registry.js';
18
+ import { inject } from './inject.js';
19
+ import { showHotErrors } from './overlay.js';
20
+ const DEFAULT_INCLUDE = /\.[cm]?[jt]sx?$/;
21
+ const DEFAULT_EXCLUDE = /node_modules/;
22
+ export default function dowel(options = {}) {
23
+ const hot = options.hot ?? 'auto';
24
+ const registry = new Registry();
25
+ const clients = new Set();
26
+ let serve = false;
27
+ /** Modules given hot code, by environment: each environment's runtime keeps its own registrations. */
28
+ const hotModules = new Set();
29
+ const hotKey = (environment, id) => `${environment ?? ''}\0${id}`;
30
+ /**
31
+ * A module that registered declarations and now has none still registers
32
+ * the empty set, so @doweljs/core/hot releases its names for other modules.
33
+ */
34
+ const release = (environment, code, id) => {
35
+ if (!serve || hot === false || !hotModules.has(hotKey(environment, id)))
36
+ return;
37
+ return inject(code, { id, locals: [], accept: false, clients: [] });
38
+ };
39
+ return {
40
+ name: '@doweljs/vite',
41
+ enforce: 'post',
42
+ api: {
43
+ graph: () => registry.graph(),
44
+ addClientModule: (id) => void clients.add(id),
45
+ },
46
+ config(config, { command }) {
47
+ // The injected `import "@doweljs/core/hot"` is invisible to the dependency scanner. Optimizing it
48
+ // together with dowel up front avoids a re-optimization and reload on first load, during
49
+ // which the two could be separate copies.
50
+ if (command !== 'serve' || hot === false)
51
+ return;
52
+ if (config.optimizeDeps?.exclude?.includes('@doweljs/core'))
53
+ return;
54
+ return { optimizeDeps: { include: ['@doweljs/core', '@doweljs/core/hot'] } };
55
+ },
56
+ configResolved(config) {
57
+ // No hot code where nothing replaces modules: test runners such as Vitest, or HMR turned off.
58
+ serve =
59
+ config.command === 'serve' &&
60
+ config.server.hmr !== false &&
61
+ process.env['VITEST'] === undefined;
62
+ },
63
+ transform: {
64
+ filter: {
65
+ id: {
66
+ include: patterns(options.include ?? DEFAULT_INCLUDE),
67
+ exclude: [DEFAULT_EXCLUDE, ...patterns(options.exclude ?? [])],
68
+ },
69
+ },
70
+ async handler(code, id) {
71
+ const analysis = mayDeclare(code) ? analyze(id, code) : null;
72
+ if (analysis === null) {
73
+ registry.delete(id);
74
+ return release(this.environment?.name, code, id);
75
+ }
76
+ // Only the sources the graph can follow, resolved in parallel.
77
+ const sources = sourcesToResolve(analysis);
78
+ const resolved = new Map();
79
+ await Promise.all([...sources].map(async (source) => {
80
+ const target = await this.resolve(source, id);
81
+ if (target !== null)
82
+ resolved.set(source, target.id);
83
+ }));
84
+ registry.set(id, analysis, resolved);
85
+ for (const duplicate of registry.duplicatesOf(id)) {
86
+ this.warn(`'${duplicate.id}' is declared more than once. Names must be unique; ` +
87
+ `hot replacement treats these as the same node.\n ${duplicate.modules.join('\n ')}`);
88
+ }
89
+ if (analysis.declarations.length === 0)
90
+ return release(this.environment?.name, code, id);
91
+ if (!serve || hot === false)
92
+ return;
93
+ hotModules.add(hotKey(this.environment?.name, id));
94
+ return inject(code, {
95
+ id,
96
+ locals: analysis.declarations.map((declaration) => declaration.local),
97
+ accept: hot === 'always' || analysis.selfContained,
98
+ clients: [...clients],
99
+ });
100
+ },
101
+ },
102
+ configureServer(server) {
103
+ server.watcher.on('unlink', (file) => registry.deleteFile(file));
104
+ if (hot !== false)
105
+ showHotErrors(server);
106
+ },
107
+ };
108
+ }
109
+ function patterns(value) {
110
+ return value instanceof RegExp ? [value] : [...value];
111
+ }
112
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAc,QAAQ,EAAE,gBAAgB,EAAE,MAAM,wBAAw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AG,KAAK,QAAQ,IAAI,QAAQ,CAAC,aAAa;oBAClD,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;iBACrB,CAAC,CAAA;YACH,CAAC;SACD;QAED,eAAe,CAAC,MAAM;YACrB,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;YAChE,IAAI,GAAG,KAAK,KAAK;gBAAE,aAAa,CAAC,MAAM,CAAC,CAAA;QACzC,CAAC;KACD,CAAA;AACF,CAAC;AAED,SAAS,QAAQ,CAAC,KAAiC;IAClD,OAAO,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAA;AACtD,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Appends the development-only hot replacement snippet to a module that
3
+ * declares slots or services. Appending keeps every original line in place,
4
+ * so the generated source map is a plain extension of the original.
5
+ */
6
+ import { MagicString } from 'magic-string';
7
+ export interface InjectOptions {
8
+ /** Module id, used as the registration key for `@doweljs/core/hot`. */
9
+ readonly id: string;
10
+ /** Local names of the module's slot and service declarations. */
11
+ readonly locals: readonly string[];
12
+ /** Whether the module should accept its own updates. */
13
+ readonly accept: boolean;
14
+ /** Modules other plugins asked every module with hot code to import. */
15
+ readonly clients: readonly string[];
16
+ }
17
+ export declare function inject(code: string, options: InjectOptions): {
18
+ code: string;
19
+ map: ReturnType<MagicString['generateMap']>;
20
+ };
21
+ //# sourceMappingURL=inject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C,MAAM,WAAW,aAAa;IAC7B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CACnC;AAED,wBAAgB,MAAM,CACrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,aAAa,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAA;CAAE,CAwB/D"}
package/dist/inject.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Appends the development-only hot replacement snippet to a module that
3
+ * declares slots or services. Appending keeps every original line in place,
4
+ * so the generated source map is a plain extension of the original.
5
+ */
6
+ import { MagicString } from 'magic-string';
7
+ import { HOT_ERROR } from './overlay.js';
8
+ export function inject(code, options) {
9
+ const s = new MagicString(code);
10
+ const declarations = options.locals.join(', ');
11
+ s.append(`
12
+
13
+ // @doweljs/vite: hot replacement
14
+ import * as __dowel_hot__ from "@doweljs/core/hot";
15
+ ${options.clients.map((client) => `import ${JSON.stringify(client)};\n`).join('')}if (import.meta.hot) {
16
+ __dowel_hot__.update(${JSON.stringify(options.id)}, { ${declarations} }).then(
17
+ (result) => {
18
+ if (result.changed.length > 0) console.info("[dowel] replaced " + result.changed.join(", "));
19
+ },
20
+ (error) => {
21
+ const message = __dowel_hot__.describeFailure(error);
22
+ console.error(message);
23
+ import.meta.hot.send(${JSON.stringify(HOT_ERROR)}, { message, stack: String((error && error.stack) || "") });
24
+ },
25
+ );
26
+ // Release the module's names once nothing imports it any more, so another module may declare them.
27
+ import.meta.hot.prune(() => __dowel_hot__.forget(${JSON.stringify(options.id)}));
28
+ ${options.accept ? '\timport.meta.hot.accept();\n' : ''}}
29
+ `);
30
+ // Only appended code changes, so a map at token boundaries is exact enough.
31
+ return { code: s.toString(), map: s.generateMap({ hires: 'boundary' }) };
32
+ }
33
+ //# sourceMappingURL=inject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAaxC,MAAM,UAAU,MAAM,CACrB,IAAY,EACZ,OAAsB;IAEtB,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;IAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC,CAAC,MAAM,CAAC;;;;EAIR,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;wBACzD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,YAAY;;;;;;;0BAO3C,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;;;;oDAIC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;EAC5E,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,EAAE;CACtD,CAAC,CAAA;IACD,4EAA4E;IAC5E,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,CAAA;AACzE,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hot replacement failures in Vite's error overlay. The injected code reports
3
+ * a failed update over its environment's hot channel; the plugin shows it in
4
+ * the browser, whichever environment it came from.
5
+ */
6
+ import type { ViteDevServer } from 'vite';
7
+ /** The event injected code sends when an update fails. */
8
+ export declare const HOT_ERROR = "dowel:error";
9
+ export interface HotErrorMessage {
10
+ readonly message: string;
11
+ readonly stack: string;
12
+ }
13
+ /** Shows the failures every environment of `server` reports in the browser's error overlay. */
14
+ export declare function showHotErrors(server: ViteDevServer): void;
15
+ //# sourceMappingURL=overlay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEzC,0DAA0D;AAC1D,eAAO,MAAM,SAAS,gBAAgB,CAAA;AAEtC,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACtB;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CASzD"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Hot replacement failures in Vite's error overlay. The injected code reports
3
+ * a failed update over its environment's hot channel; the plugin shows it in
4
+ * the browser, whichever environment it came from.
5
+ */
6
+ /** The event injected code sends when an update fails. */
7
+ export const HOT_ERROR = 'dowel:error';
8
+ /** Shows the failures every environment of `server` reports in the browser's error overlay. */
9
+ export function showHotErrors(server) {
10
+ for (const environment of Object.values(server.environments)) {
11
+ environment.hot.on(HOT_ERROR, (data) => {
12
+ server.environments.client.hot.send({
13
+ type: 'error',
14
+ err: { message: data.message, stack: data.stack, plugin: '@doweljs/vite' },
15
+ });
16
+ });
17
+ }
18
+ }
19
+ //# sourceMappingURL=overlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay.js","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAA;AAOtC,+FAA+F;AAC/F,MAAM,UAAU,aAAa,CAAC,MAAqB;IAClD,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9D,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAqB,EAAE,EAAE;YACvD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;gBACnC,IAAI,EAAE,OAAO;gBACb,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE;aAC1E,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACH,CAAC;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
- "name": "@doweljs/vite",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@doweljs/vite",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for dowel: hot replacement of services and graph diagnostics.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/doweljs/dowel.git",
9
+ "directory": "packages/vite"
10
+ },
11
+ "homepage": "https://github.com/doweljs/dowel/tree/main/packages/vite#readme",
12
+ "bugs": "https://github.com/doweljs/dowel/issues",
13
+ "type": "module",
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "@doweljs/source": "./src/index.ts",
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "src"
28
+ ],
29
+ "scripts": {
30
+ "typecheck": "tsc -p tsconfig.json --noEmit",
31
+ "build": "rm -rf dist && tsc -p tsconfig.build.json"
32
+ },
33
+ "peerDependencies": {
34
+ "@doweljs/core": "^0.1.0",
35
+ "vite": "^8.3.4"
36
+ },
37
+ "dependencies": {
38
+ "magic-string": "^1.4.3"
39
+ }
40
+ }