@expressive/react 0.94.4 → 0.94.6
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/dist/vite.js +14 -1
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
2
3
|
|
|
3
4
|
//#region src/vite.ts
|
|
4
5
|
const SOURCE = /\.[cm]?[jt]sx?$/;
|
|
6
|
+
const INSTALLED = /[\\/]node_modules[\\/]/;
|
|
7
|
+
const RUNTIMES = ["@expressive/mvc", "@expressive/mvc/hot"];
|
|
5
8
|
/**
|
|
6
9
|
* Top-level classes a module can reassign, those declaring private members,
|
|
7
10
|
* and its exports by local binding.
|
|
@@ -122,6 +125,16 @@ function expressive() {
|
|
|
122
125
|
name: "@expressive/react:hot",
|
|
123
126
|
apply: "serve",
|
|
124
127
|
enforce: "post",
|
|
128
|
+
config(config) {
|
|
129
|
+
const from = createRequire(resolve(config.root || "", "package.json"));
|
|
130
|
+
return { optimizeDeps: { include: RUNTIMES.filter((id) => {
|
|
131
|
+
try {
|
|
132
|
+
return INSTALLED.test(from.resolve(id));
|
|
133
|
+
} catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}) } };
|
|
137
|
+
},
|
|
125
138
|
configResolved(config) {
|
|
126
139
|
root = config.root;
|
|
127
140
|
},
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { dirname } from 'node:path';\nimport type { Plugin } from 'vite';\n\ntype Node = { type: string; [key: string]: any };\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\n\n/**\n * Top-level classes a module can reassign, those declaring private members,\n * and its exports by local binding.\n */\nfunction scan(body: Node[]) {\n const classes: string[] = [];\n const hidden: string[] = [];\n const exports: Record<string, string> = {};\n\n function add(name: string, node: Node) {\n classes.push(name);\n\n if (node.body.body.some((member: Node) => member.key?.type == 'PrivateIdentifier')) hidden.push(name);\n }\n\n function collect(node: Node) {\n if (node.type == 'ClassDeclaration' && node.id) add(node.id.name, node);\n else if (node.type == 'VariableDeclaration' && node.kind != 'const')\n for (const { id, init } of node.declarations)\n if (id.type == 'Identifier' && init?.type == 'ClassExpression') add(id.name, init);\n }\n\n function names(node: Node): string[] {\n if (node.type == 'VariableDeclaration')\n return node.declarations.flatMap(({ id }: Node) => (id.type == 'Identifier' ? [id.name] : []));\n\n return [node.id.name];\n }\n\n for (const node of body) {\n if (node.type == 'ExportNamedDeclaration') {\n if (node.declaration) {\n collect(node.declaration);\n for (const name of names(node.declaration)) exports[name] = name;\n } else if (!node.source)\n for (const { local, exported } of node.specifiers)\n exports[exported.name ?? exported.value] = local.name;\n } else if (node.type == 'ExportDefaultDeclaration') {\n const { declaration } = node;\n\n collect(declaration);\n\n if (declaration.id) exports.default = declaration.id.name;\n } else collect(node);\n }\n\n return { classes, hidden, exports };\n}\n\nconst server = (notes: Record<string, string>, list: string) => `\\\n const __notes = ${JSON.stringify(notes)};\n const __before = import.meta.hot.data.expressive;\n const __classes = (import.meta.hot.data.expressive = { ${list} });\n const __warned = (import.meta.hot.data.warned ||= {});\n for (const key in __notes)\n if (__before && __classes[key] !== __before[key] && !__warned[key]) {\n __warned[key] = true;\n console.warn(__notes[key]);\n }`;\n\nconst browser = (id: string, notes: Record<string, string>, list: string) => `\\\n const __notes = ${JSON.stringify(notes)};\n const __flag = (key) => 'expressive:private:' + ${id} + ':' + key;\n for (const key in __notes)\n try {\n if (sessionStorage.getItem(__flag(key)) == 'due') {\n console.warn(__notes[key]);\n sessionStorage.setItem(__flag(key), 'shown');\n }\n } catch {}\n const __before = import.meta.hot.data.expressive;\n const __classes = (import.meta.hot.data.expressive = { ${list} });\n for (const key in __before)\n if (__classes[key] !== __before[key] && __classes[key]?.prototype instanceof __Model) {\n const note = __notes[key];\n if (note)\n try {\n if (!sessionStorage.getItem(__flag(key))) sessionStorage.setItem(__flag(key), 'due');\n } catch {\n console.warn(note);\n }\n dispatchEvent(new CustomEvent('expressive:reload', { detail: { module: ${id}, class: key, reason: note ? 'private members' : 'class changed shape' } }));\n location.reload();\n break;\n }`;\n\nconst patchClasses = (id: string, classes: string[]) => `\\\n{\n const __hot = __accept(${id}, { ${classes.join(', ')} });\n ${classes.map((name) => `${name} = __hot.${name};`).join('\\n ')}\n}`;\n\nconst acceptUpdates = (replace: string, record: string) => `\\\nif (import.meta.hot) {\n${replace}\n const __exports = { ${record} };\n import.meta.hot.accept((next) => {\n if (!next) return;\n for (const key in __exports) {\n const after = next[key];\n if (after !== __exports[key] && !(after?.prototype instanceof __Model) && (typeof after != 'function' || !/^[A-Z]/.test(after.name)))\n return import.meta.hot.invalidate(\\`\"\\${key}\" export cannot be hot-patched.\\`);\n }\n });\n}`;\n\n/**\n * Bind a module's classes to `hot.accept`. A Model class it could not patch\n * reloads the page; after an update, a changed component is left to React\n * Refresh and any other changed export invalidates importers.\n */\nfunction inject(id: string, body: Node[], ssr = false) {\n const { classes, hidden, exports } = scan(body);\n\n if (!classes.length) return '';\n\n const key = JSON.stringify(id);\n const list = classes.join(', ');\n const record = Object.entries(exports).map(([name, local]) => `${JSON.stringify(name)}: ${local}`);\n const effect = ssr ? 'replace it instead of patching' : 'will trigger a full reload';\n const notes = Object.fromEntries(\n hidden.map((name) => [name, `[expressive] ${name} (${id}) declares #private members, so edits to its module ${effect}. Use _ properties instead to keep HMR.`])\n );\n const replace = ssr ? server(notes, list) : browser(key, notes, list);\n\n const lines = [\n `import { Model as __Model } from '@expressive/mvc';`,\n `import { accept as __accept } from '@expressive/mvc/hot';`,\n patchClasses(key, classes),\n acceptUpdates(replace, record.join(', '))\n ];\n\n return `\\n${lines.join('\\n')}\\n`;\n}\n\n/** Hot-patch Model and Component classes in place during `vite` dev. */\nexport default function expressive(): Plugin {\n let root = '';\n let runtime: Promise<string | null | undefined> | undefined;\n\n return {\n name: '@expressive/react:hot',\n apply: 'serve',\n enforce: 'post',\n configResolved(config) {\n root = config.root;\n },\n async transform(code, id, options) {\n const [file] = id.split('?');\n\n if (!SOURCE.test(file) || file.includes('/node_modules/') || !code.includes('class'))\n return;\n\n runtime ||= this.resolve('@expressive/mvc/hot').then((found) => found && dirname(found.id));\n\n const own = await runtime;\n\n if (own && file.startsWith(own)) return;\n\n const output = inject(file.startsWith(root + '/') ? file.slice(root.length) : file, this.parse(code).body as Node[], options?.ssr);\n\n if (output) return { code: code + output, map: null };\n }\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, resolve } from 'node:path';\nimport type { Plugin } from 'vite';\n\ntype Node = { type: string; [key: string]: any };\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\nconst INSTALLED = /[\\\\/]node_modules[\\\\/]/;\nconst RUNTIMES = ['@expressive/mvc', '@expressive/mvc/hot'];\n\n/**\n * Top-level classes a module can reassign, those declaring private members,\n * and its exports by local binding.\n */\nfunction scan(body: Node[]) {\n const classes: string[] = [];\n const hidden: string[] = [];\n const exports: Record<string, string> = {};\n\n function add(name: string, node: Node) {\n classes.push(name);\n\n if (node.body.body.some((member: Node) => member.key?.type == 'PrivateIdentifier')) hidden.push(name);\n }\n\n function collect(node: Node) {\n if (node.type == 'ClassDeclaration' && node.id) add(node.id.name, node);\n else if (node.type == 'VariableDeclaration' && node.kind != 'const')\n for (const { id, init } of node.declarations)\n if (id.type == 'Identifier' && init?.type == 'ClassExpression') add(id.name, init);\n }\n\n function names(node: Node): string[] {\n if (node.type == 'VariableDeclaration')\n return node.declarations.flatMap(({ id }: Node) => (id.type == 'Identifier' ? [id.name] : []));\n\n return [node.id.name];\n }\n\n for (const node of body) {\n if (node.type == 'ExportNamedDeclaration') {\n if (node.declaration) {\n collect(node.declaration);\n for (const name of names(node.declaration)) exports[name] = name;\n } else if (!node.source)\n for (const { local, exported } of node.specifiers)\n exports[exported.name ?? exported.value] = local.name;\n } else if (node.type == 'ExportDefaultDeclaration') {\n const { declaration } = node;\n\n collect(declaration);\n\n if (declaration.id) exports.default = declaration.id.name;\n } else collect(node);\n }\n\n return { classes, hidden, exports };\n}\n\nconst server = (notes: Record<string, string>, list: string) => `\\\n const __notes = ${JSON.stringify(notes)};\n const __before = import.meta.hot.data.expressive;\n const __classes = (import.meta.hot.data.expressive = { ${list} });\n const __warned = (import.meta.hot.data.warned ||= {});\n for (const key in __notes)\n if (__before && __classes[key] !== __before[key] && !__warned[key]) {\n __warned[key] = true;\n console.warn(__notes[key]);\n }`;\n\nconst browser = (id: string, notes: Record<string, string>, list: string) => `\\\n const __notes = ${JSON.stringify(notes)};\n const __flag = (key) => 'expressive:private:' + ${id} + ':' + key;\n for (const key in __notes)\n try {\n if (sessionStorage.getItem(__flag(key)) == 'due') {\n console.warn(__notes[key]);\n sessionStorage.setItem(__flag(key), 'shown');\n }\n } catch {}\n const __before = import.meta.hot.data.expressive;\n const __classes = (import.meta.hot.data.expressive = { ${list} });\n for (const key in __before)\n if (__classes[key] !== __before[key] && __classes[key]?.prototype instanceof __Model) {\n const note = __notes[key];\n if (note)\n try {\n if (!sessionStorage.getItem(__flag(key))) sessionStorage.setItem(__flag(key), 'due');\n } catch {\n console.warn(note);\n }\n dispatchEvent(new CustomEvent('expressive:reload', { detail: { module: ${id}, class: key, reason: note ? 'private members' : 'class changed shape' } }));\n location.reload();\n break;\n }`;\n\nconst patchClasses = (id: string, classes: string[]) => `\\\n{\n const __hot = __accept(${id}, { ${classes.join(', ')} });\n ${classes.map((name) => `${name} = __hot.${name};`).join('\\n ')}\n}`;\n\nconst acceptUpdates = (replace: string, record: string) => `\\\nif (import.meta.hot) {\n${replace}\n const __exports = { ${record} };\n import.meta.hot.accept((next) => {\n if (!next) return;\n for (const key in __exports) {\n const after = next[key];\n if (after !== __exports[key] && !(after?.prototype instanceof __Model) && (typeof after != 'function' || !/^[A-Z]/.test(after.name)))\n return import.meta.hot.invalidate(\\`\"\\${key}\" export cannot be hot-patched.\\`);\n }\n });\n}`;\n\n/**\n * Bind a module's classes to `hot.accept`. A Model class it could not patch\n * reloads the page; after an update, a changed component is left to React\n * Refresh and any other changed export invalidates importers.\n */\nfunction inject(id: string, body: Node[], ssr = false) {\n const { classes, hidden, exports } = scan(body);\n\n if (!classes.length) return '';\n\n const key = JSON.stringify(id);\n const list = classes.join(', ');\n const record = Object.entries(exports).map(([name, local]) => `${JSON.stringify(name)}: ${local}`);\n const effect = ssr ? 'replace it instead of patching' : 'will trigger a full reload';\n const notes = Object.fromEntries(\n hidden.map((name) => [name, `[expressive] ${name} (${id}) declares #private members, so edits to its module ${effect}. Use _ properties instead to keep HMR.`])\n );\n const replace = ssr ? server(notes, list) : browser(key, notes, list);\n\n const lines = [\n `import { Model as __Model } from '@expressive/mvc';`,\n `import { accept as __accept } from '@expressive/mvc/hot';`,\n patchClasses(key, classes),\n acceptUpdates(replace, record.join(', '))\n ];\n\n return `\\n${lines.join('\\n')}\\n`;\n}\n\n/** Hot-patch Model and Component classes in place during `vite` dev. */\nexport default function expressive(): Plugin {\n let root = '';\n let runtime: Promise<string | null | undefined> | undefined;\n\n return {\n name: '@expressive/react:hot',\n apply: 'serve',\n enforce: 'post',\n config(config) {\n const from = createRequire(resolve(config.root || '', 'package.json'));\n const include = RUNTIMES.filter((id) => {\n try {\n return INSTALLED.test(from.resolve(id));\n } catch {\n return false;\n }\n });\n\n return { optimizeDeps: { include } };\n },\n configResolved(config) {\n root = config.root;\n },\n async transform(code, id, options) {\n const [file] = id.split('?');\n\n if (!SOURCE.test(file) || file.includes('/node_modules/') || !code.includes('class'))\n return;\n\n runtime ||= this.resolve('@expressive/mvc/hot').then((found) => found && dirname(found.id));\n\n const own = await runtime;\n\n if (own && file.startsWith(own)) return;\n\n const output = inject(file.startsWith(root + '/') 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B,KAAK,KAAK,CAAC;;;AAI/B,SAAwB,aAAqB;CAC3C,IAAI,OAAO;CACX,IAAI;AAEJ,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,OAAO,QAAQ;GACb,MAAM,OAAO,cAAc,QAAQ,OAAO,QAAQ,IAAI,eAAe,CAAC;AAStE,UAAO,EAAE,cAAc,EAAE,SART,SAAS,QAAQ,OAAO;AACtC,QAAI;AACF,YAAO,UAAU,KAAK,KAAK,QAAQ,GAAG,CAAC;YACjC;AACN,YAAO;;KAET,EAEgC,EAAE;;EAEtC,eAAe,QAAQ;AACrB,UAAO,OAAO;;EAEhB,MAAM,UAAU,MAAM,IAAI,SAAS;GACjC,MAAM,CAAC,QAAQ,GAAG,MAAM,IAAI;AAE5B,OAAI,CAAC,OAAO,KAAK,KAAK,IAAI,KAAK,SAAS,iBAAiB,IAAI,CAAC,KAAK,SAAS,QAAQ,CAClF;AAEF,eAAY,KAAK,QAAQ,sBAAsB,CAAC,MAAM,UAAU,SAAS,QAAQ,MAAM,GAAG,CAAC;GAE3F,MAAM,MAAM,MAAM;AAElB,OAAI,OAAO,KAAK,WAAW,IAAI,CAAE;GAEjC,MAAM,SAAS,OAAO,KAAK,WAAW,OAAO,IAAI,GAAG,KAAK,MAAM,KAAK,OAAO,GAAG,MAAM,KAAK,MAAM,KAAK,CAAC,MAAgB,SAAS,IAAI;AAElI,OAAI,OAAQ,QAAO;IAAE,MAAM,OAAO;IAAQ,KAAK;IAAM;;EAExD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressive/react",
|
|
3
|
-
"version": "0.94.
|
|
3
|
+
"version": "0.94.6",
|
|
4
4
|
"description": "Class-based reactive state for React. Define state and logic as plain classes; components update when the values they read change.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expressive",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"test": "bun run typecheck && bun run coverage"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@expressive/mvc": "^0.
|
|
67
|
+
"@expressive/mvc": "^0.95.0",
|
|
68
68
|
"@testing-library/react": "^16.3.0",
|
|
69
69
|
"@types/react": "^19",
|
|
70
70
|
"@types/react-dom": "^19",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"vite": "^7.3.1"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@expressive/mvc": "^0.
|
|
79
|
+
"@expressive/mvc": "^0.95.0",
|
|
80
80
|
"react": ">=16.14.0 <20.0.0",
|
|
81
81
|
"vite": ">=5"
|
|
82
82
|
},
|