@memoized-dom/vite 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/graph/collector.d.ts +21 -0
- package/dist/graph/collector.d.ts.map +1 -0
- package/dist/graph/imports.d.ts +7 -0
- package/dist/graph/imports.d.ts.map +1 -0
- package/dist/hmr.d.ts +7 -0
- package/dist/hmr.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/options.d.ts +26 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/paths.d.ts +8 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/state.d.ts +12 -0
- package/dist/state.d.ts.map +1 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @memoized-dom/vite
|
|
2
|
+
|
|
3
|
+
Vite 8 adapter for compiler-linked memoized-dom applications.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { defineConfig } from 'vite';
|
|
7
|
+
import memoizedDom from '@memoized-dom/vite';
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [
|
|
11
|
+
memoizedDom({
|
|
12
|
+
entries: 'src/App.tsx',
|
|
13
|
+
rootId: 'App',
|
|
14
|
+
}),
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Entries are authored graph roots, not necessarily the browser bootstrap module.
|
|
20
|
+
The adapter follows local static value imports with Vite's resolver, compiles
|
|
21
|
+
the graph through `compileModules()`, and caches output per Vite environment.
|
|
22
|
+
|
|
23
|
+
Vite HMR cannot replace existing factory closures or their module state
|
|
24
|
+
bindings. A change to any managed graph file therefore invalidates all managed
|
|
25
|
+
modules through the environment module graph and requests a full browser
|
|
26
|
+
reload. This is conservative state-resetting development behavior, not
|
|
27
|
+
state-preserving component HMR.
|
|
28
|
+
|
|
29
|
+
Run the package-owned integration tests and adapter benchmark with:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun run --cwd packages/vite test
|
|
33
|
+
bun run --cwd packages/vite bench
|
|
34
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ResolvedAdapterOptions } from '../options';
|
|
2
|
+
import { type ParsedProgram } from './imports';
|
|
3
|
+
export interface ResolvedImport {
|
|
4
|
+
id: string;
|
|
5
|
+
external?: boolean | 'absolute';
|
|
6
|
+
}
|
|
7
|
+
export interface GraphPluginContext {
|
|
8
|
+
parse(source: string, options: {
|
|
9
|
+
lang: 'js' | 'jsx' | 'ts' | 'tsx';
|
|
10
|
+
}): ParsedProgram;
|
|
11
|
+
resolve(specifier: string, importer: string, options: {
|
|
12
|
+
skipSelf: true;
|
|
13
|
+
}): Promise<ResolvedImport | null>;
|
|
14
|
+
addWatchFile(file: string): void;
|
|
15
|
+
}
|
|
16
|
+
export interface CompiledGraph {
|
|
17
|
+
files: ReadonlySet<string>;
|
|
18
|
+
output: ReadonlyMap<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export declare function compileGraph(context: GraphPluginContext, root: string, entries: readonly string[], options: ResolvedAdapterOptions, overrides: ReadonlyMap<string, string>): Promise<CompiledGraph>;
|
|
21
|
+
//# sourceMappingURL=collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../src/graph/collector.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAOzD,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CACH,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;QAAE,IAAI,EAAE,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAA;KAAE,GAC7C,aAAa,CAAC;IACjB,OAAO,CACL,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,GAC1B,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAClC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAMD,wBAAsB,YAAY,CAChC,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,EAAE,sBAAsB,EAC/B,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,OAAO,CAAC,aAAa,CAAC,CAyDxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/graph/imports.ts"],"names":[],"mappings":"AAcA,UAAU,OAAO;IACf,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;CAC1B;AAUD,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAgBvD;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC"}
|
package/dist/hmr.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invalidates every Vite module backed by one linked compiler graph.
|
|
3
|
+
*/
|
|
4
|
+
import type { DevEnvironment, EnvironmentModuleNode } from 'vite';
|
|
5
|
+
import type { AdapterState } from './state';
|
|
6
|
+
export declare function invalidateManagedGraph(environment: DevEnvironment, state: AdapterState, timestamp: number): EnvironmentModuleNode[];
|
|
7
|
+
//# sourceMappingURL=hmr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACtB,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,cAAc,EAC3B,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,GAChB,qBAAqB,EAAE,CAgBzB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFile as N}from"node:fs/promises";import{compileModules as q}from"@memoized-dom/compiler";import{extname as D,isAbsolute as P,relative as A,resolve as O,sep as S}from"node:path";var K=new Set([".ts",".tsx",".js",".jsx"]);function f(e){let t=e.search(/[?#]/);return m(t===-1?e:e.slice(0,t))}function m(e){return O(e).replaceAll("\\","/")}function j(e,t){return t.map(n=>{if(P(n))return m(n);let i=n.startsWith("/")?n.slice(1):n;return m(O(e,i))})}function R(e,t){let n=A(e,t).split(S).join("/");return n!==".."&&!n.startsWith("../")&&!P(n)?`./${n}`:m(t)}function E(e,t){return e===void 0?!1:(e instanceof RegExp?[e]:e).some(i=>(i.lastIndex=0,i.test(t)))}function I(e,t,n){let i=m(t);if(!K.has(D(i))||i.includes("/node_modules/")||E(n.exclude,i))return!1;if(E(n.include,i))return!0;let l=A(e,i);return l!==".."&&!l.startsWith(`..${S}`)&&!P(l)}function G(e){let t=D(e);return t===".tsx"?"tsx":t===".ts"?"ts":t===".jsx"?"jsx":"js"}function T(e){return typeof e=="object"&&e!==null&&e.type==="ImportDeclaration"}function z(e){let t=[];for(let n of e.body){if(!T(n)||n.importKind==="type")continue;let i=n.specifiers??[];i.length>0&&i.every(l=>l.importKind==="type")||typeof n.source.value=="string"&&t.push(n.source.value)}return t}function b(e,t){return`${e}\0${t}`}async function V(e,t,n,i,l){let d=new Map,u=new Map,c=new Map,h=new Set;async function o(s){let a=f(s);if(h.has(a))return;h.add(a),e.addWatchFile(a);let v=R(t,a),g=l.get(a)??await N(a,"utf8");d.set(v,g),u.set(a,v);let y=e.parse(g,{lang:G(a)});for(let C of z(y)){let w=await e.resolve(C,a,{skipSelf:!0});if(w===null||w.external)continue;let M=f(w.id);I(t,M,i)&&(c.set(b(v,C),R(t,M)),await o(M))}}for(let s of n){if(!I(t,s,i))throw new Error(`memoized-dom: Vite entry is not an accepted source file: ${s}`);await o(s)}let r=q(Object.fromEntries(d),{...i.rootId===void 0?{}:{rootId:i.rootId},...i.runtimePath===void 0?{}:{runtimePath:i.runtimePath},resolveImport(s,a){return c.get(b(a,s))}}),p=new Map;for(let[s,a]of u)p.set(s,r[a]);return{files:new Set(u.keys()),output:p}}function F(e,t,n){let i=new Set;for(let l of t.files){let d=e.moduleGraph.getModulesByFile(l);if(d!==void 0)for(let u of d)e.moduleGraph.invalidateModule(u,i,n,!0)}return t.invalidate(),[...i]}function k(e){let t=typeof e.entries=="string"?[e.entries]:e.entries;if(t.length===0)throw new Error("memoized-dom: Vite adapter requires at least one entry");return{...e,entries:[...t]}}var x=class{files=new Set;output=new Map;compiling;replace(t){this.files.clear();for(let n of t.files)this.files.add(n);this.output.clear();for(let[n,i]of t.output)this.output.set(n,i)}invalidate(){this.output.clear()}};var W=/\.[jt]sx?(?:$|[?#])/;function $(e){let t=k(e),n=new Map,i,l=[];function d(o){let r=n.get(o);return r===void 0&&(r=new x,n.set(o,r)),r}function u(o){return{parse:(r,p)=>o.parse(r,p),resolve:(r,p,s)=>o.resolve(r,p,s),addWatchFile:r=>o.addWatchFile(r)}}async function c(o,r,p=new Map){if(i===void 0)throw new Error("memoized-dom: Vite graph compilation started before config resolution");r.compiling===void 0&&(r.compiling=V(u(o),i.root,l,t,p));let s=r.compiling;try{r.replace(await s)}finally{r.compiling===s&&(r.compiling=void 0)}}async function h(o,r,p){if(i===void 0||!W.test(p))return null;let s=f(p),a=d(o.environment);if(!(l.includes(s)||a.files.has(s))&&a.compiling===void 0)return null;let g=a.output.get(s);if(g!==void 0)return{code:g,map:null};a.compiling===void 0?await c(o,a,new Map([[s,r]])):await c(o,a);let y=a.output.get(s);if(y===void 0){if(!l.includes(s))return null;throw new Error(`memoized-dom: linked Vite graph omitted managed module ${s}`)}return{code:y,map:null}}return{name:"memoized-dom",enforce:"pre",perEnvironmentWatchChangeDuringDev:!0,perEnvironmentStartEndDuringDev:!0,applyToEnvironment(o){return o.name==="client"},configResolved(o){i=o,l=j(o.root,t.entries)},async buildStart(){await c(this,d(this.environment))},transform:{filter:{id:W},handler(o,r){return h(this,o,r)}},watchChange(o){let r=n.get(this.environment);r!==void 0&&r.files.has(f(o))&&r.invalidate()},hotUpdate(o){let r=n.get(this.environment),p=m(o.file);if(!(r===void 0||!r.files.has(p)))return F(this.environment,r,o.timestamp),this.environment.hot.send({type:"full-reload"}),[]}}}export{$ as default,$ as memoizedDom};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public configuration for the Vite connected-graph adapter.
|
|
3
|
+
*/
|
|
4
|
+
import type { CompileModulesOptions } from '@memoized-dom/compiler';
|
|
5
|
+
export interface MemoizedDomViteOptions extends Omit<CompileModulesOptions, 'aliases' | 'resolveImport'> {
|
|
6
|
+
/**
|
|
7
|
+
* Authored graph roots, relative to Vite's configured project root.
|
|
8
|
+
*
|
|
9
|
+
* Every local TypeScript/JavaScript dependency reachable from these entries
|
|
10
|
+
* is compiled as one linked graph.
|
|
11
|
+
*/
|
|
12
|
+
entries: string | readonly string[];
|
|
13
|
+
/**
|
|
14
|
+
* Additional source paths allowed outside the Vite project root.
|
|
15
|
+
*/
|
|
16
|
+
include?: RegExp | readonly RegExp[];
|
|
17
|
+
/**
|
|
18
|
+
* Source paths excluded from connected-graph compilation.
|
|
19
|
+
*/
|
|
20
|
+
exclude?: RegExp | readonly RegExp[];
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedAdapterOptions extends Omit<MemoizedDomViteOptions, 'entries'> {
|
|
23
|
+
entries: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function resolveAdapterOptions(options: MemoizedDomViteOptions): ResolvedAdapterOptions;
|
|
26
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,qBAAqB,EAAE,SAAS,GAAG,eAAe,CAAC;IAChE;;;;;OAKG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,sBAAsB,EAAE,SAAS,CAAC;IAC/C,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,sBAAsB,CAOxB"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ResolvedAdapterOptions } from './options';
|
|
2
|
+
export declare function cleanViteId(id: string): string;
|
|
3
|
+
export declare function normalizeFile(file: string): string;
|
|
4
|
+
export declare function entryFiles(root: string, entries: readonly string[]): readonly string[];
|
|
5
|
+
export declare function moduleId(root: string, file: string): string;
|
|
6
|
+
export declare function acceptsSource(root: string, file: string, options: ResolvedAdapterOptions): boolean;
|
|
7
|
+
export declare function parserLanguage(file: string): 'js' | 'jsx' | 'ts' | 'tsx';
|
|
8
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAIxD,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE,CAMnB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAU3D;AAWD,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAaT;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,GACX,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAM7B"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite 8 plugin backed by connected compiler graphs and full-reload HMR.
|
|
3
|
+
*/
|
|
4
|
+
import type { Plugin } from 'vite';
|
|
5
|
+
import { type MemoizedDomViteOptions } from './options';
|
|
6
|
+
export declare function memoizedDom(input: MemoizedDomViteOptions): Plugin;
|
|
7
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACV,MAAM,EAEP,MAAM,MAAM,CAAC;AAId,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,WAAW,CAAC;AAUnB,wBAAgB,WAAW,CACzB,KAAK,EAAE,sBAAsB,GAC5B,MAAM,CAwIR"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owns per-Vite-environment linked output and compilation coordination.
|
|
3
|
+
*/
|
|
4
|
+
import type { CompiledGraph } from './graph/collector';
|
|
5
|
+
export declare class AdapterState {
|
|
6
|
+
readonly files: Set<string>;
|
|
7
|
+
readonly output: Map<string, string>;
|
|
8
|
+
compiling: Promise<CompiledGraph> | undefined;
|
|
9
|
+
replace(graph: CompiledGraph): void;
|
|
10
|
+
invalidate(): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,YAAY;IACvB,QAAQ,CAAC,KAAK,cAAqB;IACnC,QAAQ,CAAC,MAAM,sBAA6B;IAC5C,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;IAE9C,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAOnC,UAAU,IAAI,IAAI;CAGnB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@memoized-dom/vite",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Vite 8 adapter for connected memoized-dom module graphs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "bun run ./scripts/clean.ts && esbuild ./src/index.ts --bundle --outfile=./dist/index.js --platform=node --format=esm --target=node20 --packages=external --minify && tsc -p tsconfig.build.json",
|
|
19
|
+
"test": "vitest run --config vitest.config.ts",
|
|
20
|
+
"bench": "bun run ./bench/run.ts"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@memoized-dom/compiler": "^0.0.1"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"vite": "^8.0.0"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|