sygnal 5.3.7 → 5.4.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.
Files changed (226) hide show
  1. package/README.md +53 -38
  2. package/dist/astro/client.cjs.js +18 -8106
  3. package/dist/astro/client.cjs.js.map +1 -0
  4. package/dist/astro/client.mjs +17 -8105
  5. package/dist/astro/client.mjs.map +1 -0
  6. package/dist/astro/index.cjs.js +768 -9
  7. package/dist/astro/index.cjs.js.map +1 -0
  8. package/dist/astro/index.mjs +768 -9
  9. package/dist/astro/index.mjs.map +1 -0
  10. package/dist/astro/server.cjs.js +4 -1
  11. package/dist/astro/server.cjs.js.map +1 -0
  12. package/dist/astro/server.mjs +4 -1
  13. package/dist/astro/server.mjs.map +1 -0
  14. package/dist/diagnostics.cjs.js +1297 -0
  15. package/dist/diagnostics.cjs.js.map +1 -0
  16. package/dist/diagnostics.esm.js +1267 -0
  17. package/dist/diagnostics.esm.js.map +1 -0
  18. package/dist/index.cjs.js +2981 -1386
  19. package/dist/index.cjs.js.map +1 -0
  20. package/dist/index.d.ts +848 -111
  21. package/dist/index.esm.js +2997 -1411
  22. package/dist/index.esm.js.map +1 -0
  23. package/dist/jsx-dev-runtime.cjs.js +15 -9
  24. package/dist/jsx-dev-runtime.cjs.js.map +1 -0
  25. package/dist/jsx-dev-runtime.esm.js +15 -9
  26. package/dist/jsx-dev-runtime.esm.js.map +1 -0
  27. package/dist/jsx-runtime.cjs.js +15 -9
  28. package/dist/jsx-runtime.cjs.js.map +1 -0
  29. package/dist/jsx-runtime.esm.js +15 -9
  30. package/dist/jsx-runtime.esm.js.map +1 -0
  31. package/dist/jsx.cjs.js +15 -9
  32. package/dist/jsx.cjs.js.map +1 -0
  33. package/dist/jsx.esm.js +15 -9
  34. package/dist/jsx.esm.js.map +1 -0
  35. package/dist/sygnal.min.js +2 -1
  36. package/dist/sygnal.min.js.map +1 -0
  37. package/dist/vike/+config.cjs.js +1 -0
  38. package/dist/vike/+config.cjs.js.map +1 -0
  39. package/dist/vike/+config.js +1 -0
  40. package/dist/vike/+config.js.map +1 -0
  41. package/dist/vike/ClientOnly.cjs.js +1 -0
  42. package/dist/vike/ClientOnly.cjs.js.map +1 -0
  43. package/dist/vike/ClientOnly.mjs +1 -0
  44. package/dist/vike/ClientOnly.mjs.map +1 -0
  45. package/dist/vike/onRenderClient.cjs.js +1 -0
  46. package/dist/vike/onRenderClient.cjs.js.map +1 -0
  47. package/dist/vike/onRenderClient.mjs +1 -0
  48. package/dist/vike/onRenderClient.mjs.map +1 -0
  49. package/dist/vike/onRenderHtml.cjs.js +1 -0
  50. package/dist/vike/onRenderHtml.cjs.js.map +1 -0
  51. package/dist/vike/onRenderHtml.mjs +1 -0
  52. package/dist/vike/onRenderHtml.mjs.map +1 -0
  53. package/dist/vite/plugin.cjs.js +670 -44
  54. package/dist/vite/plugin.cjs.js.map +1 -0
  55. package/dist/vite/plugin.mjs +670 -44
  56. package/dist/vite/plugin.mjs.map +1 -0
  57. package/llms.txt +250 -0
  58. package/package.json +15 -6
  59. package/src/astro/client.ts +13 -2
  60. package/src/astro/index.d.ts +24 -1
  61. package/src/astro/index.ts +40 -9
  62. package/src/astro/server.ts +3 -1
  63. package/src/collection.ts +5 -2
  64. package/src/component.ts +375 -330
  65. package/src/cycle/dom/MainDOMSource.ts +4 -0
  66. package/src/cycle/dom/classNameModule.ts +74 -0
  67. package/src/cycle/dom/controlledInputModule.ts +33 -0
  68. package/src/cycle/dom/enrichEventStream.ts +9 -3
  69. package/src/cycle/dom/makeDOMDriver.ts +1 -2
  70. package/src/cycle/dom/mockDOMSource.ts +62 -8
  71. package/src/cycle/dom/modules.ts +5 -1
  72. package/src/cycle/state/Collection.ts +13 -3
  73. package/src/cycle/state/StateSource.ts +1 -1
  74. package/src/cycle/state/pickCombine.ts +35 -1
  75. package/src/cycle/state/withState.ts +1 -1
  76. package/src/extra/devtools.ts +8 -0
  77. package/src/extra/diagnostics/checks/collections.ts +67 -0
  78. package/src/extra/diagnostics/checks/dom.ts +241 -0
  79. package/src/extra/diagnostics/checks/events.ts +68 -0
  80. package/src/extra/diagnostics/checks/index.ts +109 -0
  81. package/src/extra/diagnostics/checks/inspect.ts +319 -0
  82. package/src/extra/diagnostics/checks/props.ts +51 -0
  83. package/src/extra/diagnostics/checks/public.d.ts +211 -0
  84. package/src/extra/diagnostics/checks/rxjsHints.ts +88 -0
  85. package/src/extra/diagnostics/checks/shared.ts +119 -0
  86. package/src/extra/diagnostics/checks/state.ts +55 -0
  87. package/src/extra/diagnostics/checks/strict.ts +112 -0
  88. package/src/extra/diagnostics/checks/wiring.ts +65 -0
  89. package/src/extra/diagnostics/codes.ts +232 -0
  90. package/src/extra/diagnostics/index.ts +328 -0
  91. package/src/extra/diagnostics/legacy.ts +59 -0
  92. package/src/extra/driverFactories.ts +106 -58
  93. package/src/extra/eventDriver.ts +4 -0
  94. package/src/extra/flatten.ts +75 -0
  95. package/src/extra/reducers.ts +12 -5
  96. package/src/extra/run.ts +11 -0
  97. package/src/extra/testing.ts +890 -180
  98. package/src/extra/xstreamExtras.ts +269 -0
  99. package/src/index.d.ts +428 -17
  100. package/src/index.ts +7 -6
  101. package/src/pragma/index.ts +14 -9
  102. package/src/switchable.ts +10 -8
  103. package/src/vike/types.ts +21 -4
  104. package/src/vite/plugin.d.ts +95 -2
  105. package/src/vite/plugin.ts +720 -54
  106. package/dist/astro/astro/client.d.ts +0 -5
  107. package/dist/astro/astro/index.d.ts +0 -16
  108. package/dist/astro/astro/server.d.ts +0 -12
  109. package/dist/astro/client.d.ts +0 -5
  110. package/dist/astro/client.esm.js +0 -4665
  111. package/dist/astro/collection.d.ts +0 -12
  112. package/dist/astro/component.d.ts +0 -22
  113. package/dist/astro/cycle/dom/BodyDOMSource.d.ts +0 -10
  114. package/dist/astro/cycle/dom/DOMSource.d.ts +0 -11
  115. package/dist/astro/cycle/dom/DocumentDOMSource.d.ts +0 -12
  116. package/dist/astro/cycle/dom/ElementFinder.d.ts +0 -8
  117. package/dist/astro/cycle/dom/EventDelegator.d.ts +0 -34
  118. package/dist/astro/cycle/dom/IsolateModule.d.ts +0 -23
  119. package/dist/astro/cycle/dom/MainDOMSource.d.ts +0 -32
  120. package/dist/astro/cycle/dom/PriorityQueue.d.ts +0 -7
  121. package/dist/astro/cycle/dom/ScopeChecker.d.ts +0 -9
  122. package/dist/astro/cycle/dom/SymbolTree.d.ts +0 -9
  123. package/dist/astro/cycle/dom/VNodeWrapper.d.ts +0 -8
  124. package/dist/astro/cycle/dom/enrichEventStream.d.ts +0 -24
  125. package/dist/astro/cycle/dom/fromEvent.d.ts +0 -6
  126. package/dist/astro/cycle/dom/index.d.ts +0 -8
  127. package/dist/astro/cycle/dom/isolate.d.ts +0 -9
  128. package/dist/astro/cycle/dom/makeDOMDriver.d.ts +0 -11
  129. package/dist/astro/cycle/dom/mockDOMSource.d.ts +0 -17
  130. package/dist/astro/cycle/dom/modules.d.ts +0 -5
  131. package/dist/astro/cycle/dom/snabbdom.d.ts +0 -22
  132. package/dist/astro/cycle/dom/styleModule.d.ts +0 -13
  133. package/dist/astro/cycle/dom/thunk.d.ts +0 -11
  134. package/dist/astro/cycle/dom/utils.d.ts +0 -8
  135. package/dist/astro/cycle/isolate/index.d.ts +0 -42
  136. package/dist/astro/cycle/run/adapt.d.ts +0 -6
  137. package/dist/astro/cycle/run/index.d.ts +0 -36
  138. package/dist/astro/cycle/run/internals.d.ts +0 -8
  139. package/dist/astro/cycle/run/types.d.ts +0 -49
  140. package/dist/astro/cycle/state/Collection.d.ts +0 -29
  141. package/dist/astro/cycle/state/StateSource.d.ts +0 -20
  142. package/dist/astro/cycle/state/index.d.ts +0 -5
  143. package/dist/astro/cycle/state/pickCombine.d.ts +0 -3
  144. package/dist/astro/cycle/state/pickMerge.d.ts +0 -3
  145. package/dist/astro/cycle/state/types.d.ts +0 -18
  146. package/dist/astro/cycle/state/withState.d.ts +0 -17
  147. package/dist/astro/extra/classes.d.ts +0 -7
  148. package/dist/astro/extra/devtools.d.ts +0 -78
  149. package/dist/astro/extra/dragDriver.d.ts +0 -20
  150. package/dist/astro/extra/driverFactories.d.ts +0 -12
  151. package/dist/astro/extra/eventDriver.d.ts +0 -9
  152. package/dist/astro/extra/exactState.d.ts +0 -1
  153. package/dist/astro/extra/hmr.d.ts +0 -17
  154. package/dist/astro/extra/logDriver.d.ts +0 -2
  155. package/dist/astro/extra/processDrag.d.ts +0 -19
  156. package/dist/astro/extra/processForm.d.ts +0 -15
  157. package/dist/astro/extra/run.d.ts +0 -13
  158. package/dist/astro/extra/xstreamCompat.d.ts +0 -5
  159. package/dist/astro/index.d.ts +0 -19
  160. package/dist/astro/index.esm.js +0 -27
  161. package/dist/astro/jsx-dev-runtime.d.ts +0 -1
  162. package/dist/astro/jsx-runtime.d.ts +0 -4
  163. package/dist/astro/jsx.d.ts +0 -2
  164. package/dist/astro/pragma/fn.d.ts +0 -7
  165. package/dist/astro/pragma/index.d.ts +0 -7
  166. package/dist/astro/pragma/is.d.ts +0 -10
  167. package/dist/astro/server.d.ts +0 -12
  168. package/dist/astro/server.esm.js +0 -25
  169. package/dist/astro/switchable.d.ts +0 -7
  170. package/dist/collection.d.ts +0 -12
  171. package/dist/component.d.ts +0 -22
  172. package/dist/cycle/dom/BodyDOMSource.d.ts +0 -10
  173. package/dist/cycle/dom/DOMSource.d.ts +0 -11
  174. package/dist/cycle/dom/DocumentDOMSource.d.ts +0 -12
  175. package/dist/cycle/dom/ElementFinder.d.ts +0 -8
  176. package/dist/cycle/dom/EventDelegator.d.ts +0 -34
  177. package/dist/cycle/dom/IsolateModule.d.ts +0 -23
  178. package/dist/cycle/dom/MainDOMSource.d.ts +0 -32
  179. package/dist/cycle/dom/PriorityQueue.d.ts +0 -7
  180. package/dist/cycle/dom/ScopeChecker.d.ts +0 -9
  181. package/dist/cycle/dom/SymbolTree.d.ts +0 -9
  182. package/dist/cycle/dom/VNodeWrapper.d.ts +0 -8
  183. package/dist/cycle/dom/enrichEventStream.d.ts +0 -24
  184. package/dist/cycle/dom/fromEvent.d.ts +0 -6
  185. package/dist/cycle/dom/index.d.ts +0 -8
  186. package/dist/cycle/dom/isolate.d.ts +0 -9
  187. package/dist/cycle/dom/makeDOMDriver.d.ts +0 -11
  188. package/dist/cycle/dom/mockDOMSource.d.ts +0 -17
  189. package/dist/cycle/dom/modules.d.ts +0 -5
  190. package/dist/cycle/dom/snabbdom.d.ts +0 -22
  191. package/dist/cycle/dom/styleModule.d.ts +0 -13
  192. package/dist/cycle/dom/thunk.d.ts +0 -11
  193. package/dist/cycle/dom/utils.d.ts +0 -8
  194. package/dist/cycle/isolate/index.d.ts +0 -42
  195. package/dist/cycle/run/adapt.d.ts +0 -6
  196. package/dist/cycle/run/index.d.ts +0 -36
  197. package/dist/cycle/run/internals.d.ts +0 -8
  198. package/dist/cycle/run/types.d.ts +0 -49
  199. package/dist/cycle/state/Collection.d.ts +0 -29
  200. package/dist/cycle/state/StateSource.d.ts +0 -20
  201. package/dist/cycle/state/index.d.ts +0 -5
  202. package/dist/cycle/state/pickCombine.d.ts +0 -3
  203. package/dist/cycle/state/pickMerge.d.ts +0 -3
  204. package/dist/cycle/state/types.d.ts +0 -18
  205. package/dist/cycle/state/withState.d.ts +0 -17
  206. package/dist/extra/classes.d.ts +0 -7
  207. package/dist/extra/devtools.d.ts +0 -78
  208. package/dist/extra/dragDriver.d.ts +0 -20
  209. package/dist/extra/driverFactories.d.ts +0 -12
  210. package/dist/extra/eventDriver.d.ts +0 -9
  211. package/dist/extra/exactState.d.ts +0 -1
  212. package/dist/extra/hmr.d.ts +0 -17
  213. package/dist/extra/logDriver.d.ts +0 -2
  214. package/dist/extra/processDrag.d.ts +0 -19
  215. package/dist/extra/processForm.d.ts +0 -15
  216. package/dist/extra/run.d.ts +0 -13
  217. package/dist/extra/xstreamCompat.d.ts +0 -5
  218. package/dist/jsx-dev-runtime.d.ts +0 -1
  219. package/dist/jsx-dev-runtime.js +0 -224
  220. package/dist/jsx-runtime.d.ts +0 -4
  221. package/dist/jsx-runtime.js +0 -224
  222. package/dist/jsx.d.ts +0 -2
  223. package/dist/pragma/fn.d.ts +0 -7
  224. package/dist/pragma/index.d.ts +0 -7
  225. package/dist/pragma/is.d.ts +0 -10
  226. package/dist/switchable.d.ts +0 -7
package/src/switchable.ts CHANGED
@@ -1,14 +1,16 @@
1
- import xs, {Stream, resolveInteropDefault} from './extra/xstreamCompat';
2
- import * as dropRepeatsModule from 'xstream/extra/dropRepeats.js';
1
+ import xs, {Stream} from './extra/xstreamCompat';
2
+ import {dropRepeats} from './extra/xstreamExtras';
3
3
  import {h} from './cycle/dom/index';
4
+ import {fail} from './extra/diagnostics/legacy';
4
5
 
5
- const dropRepeats = resolveInteropDefault(dropRepeatsModule);
6
6
 
7
7
  interface SwitchableOptions {
8
8
  switched?: string | string[];
9
9
  stateSourceName?: string;
10
10
  }
11
11
 
12
+ const NAME_FIX = 'Pass a stream, a state key string, or a state => name function';
13
+
12
14
  export default function switchable(
13
15
  factories: Record<string, (sources: any) => any>,
14
16
  name$: any,
@@ -18,7 +20,7 @@ export default function switchable(
18
20
  const {switched = ['DOM'], stateSourceName = 'STATE'} = opts;
19
21
  const nameType = typeof name$;
20
22
 
21
- if (!name$) throw new Error(`Missing 'name$' parameter for switchable()`);
23
+ if (!name$) fail('SYG419', 'switchable', "Missing 'name$' parameter", NAME_FIX);
22
24
  if (
23
25
  !(
24
26
  nameType === 'string' ||
@@ -26,9 +28,7 @@ export default function switchable(
26
28
  name$ instanceof Stream
27
29
  )
28
30
  ) {
29
- throw new Error(
30
- `Invalid 'name$' parameter for switchable(): expects Stream, String, or Function`
31
- );
31
+ fail('SYG419', 'switchable', `Invalid 'name$' parameter: got ${nameType}`, NAME_FIX);
32
32
  }
33
33
 
34
34
  if (name$ instanceof Stream) {
@@ -51,7 +51,7 @@ export default function switchable(
51
51
  sources.state
52
52
  ).stream;
53
53
  if (!(state$ instanceof Stream))
54
- throw new Error(`Could not find the state source: ${stateSourceName}`);
54
+ fail('SYG607', 'switchable', `State source '${stateSourceName}' not found`, 'Pass the state source in sources, or set stateSourceName');
55
55
  const _name$ = state$
56
56
  .map(mapFunction)
57
57
  .filter((name: any) => typeof name === 'string')
@@ -113,6 +113,8 @@ function _switchable(
113
113
  },
114
114
  {}
115
115
  );
116
+ // B-024: every factory was instantiated above; dispose them all with the switchable
117
+ switchedSinks.__dispose = () => sinks.forEach(([, s]) => s.__dispose?.());
116
118
 
117
119
  return switchedSinks;
118
120
  }
package/src/vike/types.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
- * TypeScript declarations for vike-sygnal custom config settings.
2
+ * TypeScript declarations for 'sygnal/config' (also 'sygnal/vike' and
3
+ * 'sygnal/vike/config'): the Vike extension config (default export), and the
4
+ * custom config settings, which augment Vike's Config interface so users get
5
+ * autocomplete and type checking in their +config.ts files.
3
6
  *
4
- * These augment Vike's Config interface so users get autocomplete
5
- * and type checking in their +config.ts files.
7
+ * import vikeSygnal from 'sygnal/config'
8
+ * export default { extends: [vikeSygnal] }
6
9
  */
7
10
 
8
11
  declare global {
@@ -30,4 +33,18 @@ declare global {
30
33
  }
31
34
  }
32
35
 
33
- export {}
36
+ /**
37
+ * The Sygnal extension for Vike: put it in `extends` of your root +config.
38
+ * (Declared here; the value is the package's vike/+config entry.)
39
+ */
40
+ declare const vikeSygnal: {
41
+ name: 'sygnal'
42
+ clientRouting: boolean
43
+ hydrationCanBeAborted: boolean
44
+ onRenderHtml: string
45
+ onRenderClient: string
46
+ passToClient: string[]
47
+ meta: Record<string, any>
48
+ }
49
+
50
+ export default vikeSygnal
@@ -1,3 +1,56 @@
1
+ export type DiagnosticsMode = 'off' | 'collect' | 'warn' | 'error'
2
+
3
+ export interface DiagnosticsPluginOptions {
4
+ /**
5
+ * Runtime diagnostics mode in dev.
6
+ * @default 'warn'
7
+ */
8
+ mode?: DiagnosticsMode
9
+ /**
10
+ * Strict (canonical-form, SYG5xx) runtime checks: the dev snippet sets
11
+ * `globalThis.__SYGNAL_STRICT__ = true`. Also the default for `check.strict`.
12
+ * @default false
13
+ */
14
+ strict?: boolean
15
+ /** Diagnostic codes to drop, e.g. ['SYG105'] (runtime and static) */
16
+ ignore?: string[]
17
+ }
18
+
19
+ export interface CheckPluginOptions {
20
+ /**
21
+ * Also run sygnal-check's strict (SYG5xx) rules.
22
+ * @default the `diagnostics` strict setting
23
+ */
24
+ strict?: boolean
25
+ /**
26
+ * Files, directories or globs to check, relative to the Vite root.
27
+ * By default the existing ones of src/, pages/ and renderer/ (Vike apps),
28
+ * else the project root (node_modules, dist and other build output are
29
+ * skipped); a one-time notice is logged when the default finds no
30
+ * directory or when none of the given paths exists.
31
+ * @default ['src', 'pages', 'renderer'] (those that exist), else ['.']
32
+ */
33
+ include?: string[]
34
+ /**
35
+ * Codes to drop.
36
+ * @default the `diagnostics` ignore list
37
+ */
38
+ ignore?: string[]
39
+ /**
40
+ * Error-severity findings also open Vite's error overlay ('error');
41
+ * false: never. Every finding is printed in the terminal and logged in the
42
+ * browser console (sygnal-check's codes are currently all warnings or
43
+ * info, so in practice that is where they go). Warnings never use the
44
+ * overlay, because Vite's client reloads the page on the next HMR update
45
+ * while an overlay is open: 'warn' is still accepted, and treated as
46
+ * 'error' with a one-time notice. The overlay is sent only to the page that
47
+ * loads (not to every client), closed before each HMR update and sent
48
+ * again after the re-check.
49
+ * @default 'error'
50
+ */
51
+ overlay?: 'error' | 'warn' | false
52
+ }
53
+
1
54
  export interface SygnalPluginOptions {
2
55
  /**
3
56
  * Disable automatic JSX configuration.
@@ -10,21 +63,61 @@ export interface SygnalPluginOptions {
10
63
  * @default false
11
64
  */
12
65
  disableHmr?: boolean
66
+
67
+ /**
68
+ * Runtime diagnostics in dev (`vite`, never `vite build`). In every file
69
+ * that imports `run` from 'sygnal' the plugin sets the dev flag and imports
70
+ * 'sygnal/diagnostics' (the runtime checks); the Vike and Astro client
71
+ * entries get the same. 'off' injects nothing. Any other mode than 'warn',
72
+ * or an ignore list, is passed as run()'s `diagnostics` option, unless the
73
+ * run() call sets that option itself.
74
+ * @default 'warn'
75
+ */
76
+ diagnostics?: DiagnosticsMode | DiagnosticsPluginOptions
77
+
78
+ /**
79
+ * Run sygnal-check (an optional dependency) in dev on startup and after
80
+ * every source change. Findings go to the terminal and the browser console;
81
+ * error-severity findings also to Vite's error overlay.
82
+ * Skipped silently when sygnal-check isn't installed.
83
+ * @default true
84
+ */
85
+ check?: boolean | CheckPluginOptions
86
+
87
+ /**
88
+ * Under Vitest, add the 'sygnal/diagnostics' entry to `test.setupFiles`
89
+ * so tests (e.g. renderComponent) get the runtime checks.
90
+ * @default true
91
+ */
92
+ vitestSetup?: boolean
13
93
  }
14
94
 
15
95
  /**
16
96
  * Sygnal Vite plugin.
17
97
  *
18
- * Auto-configures JSX transform and injects HMR boilerplate.
98
+ * Auto-configures the JSX transform and injects HMR boilerplate. In dev
99
+ * (`vite`) it also turns on runtime diagnostics with the dev checks and runs
100
+ * sygnal-check when installed; under Vitest it adds the dev checks to the
101
+ * test setup. Nothing is added to production builds.
19
102
  *
20
103
  * @example
21
104
  * ```js
22
105
  * import sygnal from 'sygnal/vite'
23
106
  * export default defineConfig({ plugins: [sygnal()] })
107
+ *
108
+ * // stricter dev setup
109
+ * sygnal({ diagnostics: { mode: 'error', strict: true }, check: { strict: true } })
24
110
  * ```
25
111
  */
26
112
  export default function sygnal(options?: SygnalPluginOptions): {
27
113
  name: string
28
114
  config: (config: any, env: { command: string }) => any
29
- transform: (code: string, id: string) => { code: string; map: null } | null
115
+ configResolved: (config: any) => void
116
+ resolveId: {
117
+ order: 'pre'
118
+ handler: (source: string, importer: string | undefined, options?: any) => Promise<any>
119
+ }
120
+ load: (id: string) => string | null
121
+ configureServer: (server: any) => void
122
+ transform: (code: string, id: string, options?: { ssr?: boolean }) => { code: string; map: any } | null
30
123
  }