@csedl/svelte-on-rails 10.2.0 → 11.0.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.
package/index.js CHANGED
@@ -1,7 +1,5 @@
1
- import SvelteOnRails from "./src/config.js";
2
- import {Application} from "@hotwired/stimulus"
3
- import {dispatchSvelteStreamEvent} from "./src/streams/dispatch-event.js";
4
- import {streamDebugLog} from "./src/logger.js";
1
+ import { SvelteOnRails } from "./src/config.js";
2
+ import { Application } from "@hotwired/stimulus"
5
3
 
6
4
 
7
5
  //console.error('test-error')
@@ -22,4 +20,4 @@ import turboStreamController from "./src/streams/turbo-stream-controller.js";
22
20
 
23
21
  Stimulus.register('svelte-on-rails-turbo-stream', turboStreamController)
24
22
 
25
- export { SvelteOnRails, dispatchSvelteStreamEvent, streamDebugLog };
23
+ export { SvelteOnRails };
package/package.json CHANGED
@@ -1,15 +1,25 @@
1
1
  {
2
2
  "name": "@csedl/svelte-on-rails",
3
- "version": "10.2.0",
3
+ "version": "11.0.0",
4
4
  "description": "Hydrates Svelte components from the svelte-on-rails gem and can handle Actions received by Web Socket.",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": "./index.js",
9
+
10
+ "./utils": "./utils/index.js",
11
+ "./config": "./src/config.js",
12
+
13
+ "./ssr": {
14
+ "types": "./types/ssr.d.ts",
15
+ "default": "./src/ssr/vite-plugins/dev-module-map.ts"
16
+ },
17
+
9
18
  "./src/streams/componentStreamListener": "./src/streams/componentStreamListener.js",
10
19
  "./src/streams/dispatch-event.js": "./src/streams/dispatch-event.js",
11
20
  "./src/logger.js": "./src/logger.js",
12
21
  "./src/config.js": "./src/config.js"
22
+
13
23
  },
14
24
  "peerDependencies": {
15
25
  "@hotwired/stimulus": "^3.2.2",
@@ -21,8 +31,7 @@
21
31
  },
22
32
  "keywords": [
23
33
  "svelte",
24
- "rails",
25
- "ssr"
34
+ "rails"
26
35
  ],
27
36
  "author": "Christian Sedlmair",
28
37
  "license": "LICENSE.md",
package/src/config.js CHANGED
@@ -1,5 +1,4 @@
1
- import {streamDebugLog} from "./logger.js";
2
- // src/config.js
1
+
3
2
  let _debug = false;
4
3
 
5
4
  let _lazyComponents = {}
@@ -7,7 +6,7 @@ let _defaultComponents = import.meta.glob("/**/*.svelte", { eager: false, import
7
6
 
8
7
  import {debugLog} from "./logger.js";
9
8
 
10
- const SvelteOnRails = {
9
+ export const SvelteOnRails = {
11
10
 
12
11
  async loadComponent(componentKey) {
13
12
 
@@ -15,7 +14,7 @@ const SvelteOnRails = {
15
14
 
16
15
  let components
17
16
  if (Object.keys(_lazyComponents).length === 0) {
18
- debugLog("lazyComponents not set: falling back to built-in «import.meta.glob(['/**/*.svelte'], {eager: false, import: 'default'})»");
17
+ debugLog("lazyComponents not set: falling back to default «import.meta.glob(['/**/*.svelte'], {eager: false, import: 'default'})»");
19
18
  components = _defaultComponents;
20
19
  } else {
21
20
  debugLog(`[svelte-on-rails] using given lazyComponents`);
@@ -24,12 +23,12 @@ const SvelteOnRails = {
24
23
 
25
24
 
26
25
  const loader = components[componentKey];
27
- console.log(`[svelte-on-rails:debug] loader`, loader);
26
+
28
27
  if (!loader) {
29
28
  throw new Error(`[svelte-on-rails] Component not found: ${componentKey} (relative to vites sourceCodeDir / frontend-folder)`);
30
29
  //return;
31
30
  } else {
32
- console.log(`[svelte-on-rails] Component found: ${componentKey}`);
31
+ debugLog(`[svelte-on-rails] Component found: ${componentKey}`);
33
32
  }
34
33
 
35
34
  // load and validate component
@@ -47,12 +46,12 @@ const SvelteOnRails = {
47
46
 
48
47
  // finish
49
48
 
50
- console.log(`[svelte-on-rails:debug] Component loaded:`, comp);
49
+ debugLog(`[svelte-on-rails:debug] Component loaded:`, comp);
51
50
  return comp;
52
51
  },
53
52
 
54
53
  set lazyComponents(value) {
55
- console.log(`[svelte-on-rails:debug] lazyComponents set:`, value);
54
+ debugLog(`[svelte-on-rails:debug] lazyComponents set:`, value);
56
55
  _lazyComponents = value;
57
56
  },
58
57
 
@@ -66,6 +65,4 @@ const SvelteOnRails = {
66
65
  },
67
66
  };
68
67
 
69
- window.SvelteOnRails = SvelteOnRails;
70
-
71
- export default SvelteOnRails;
68
+ window.SvelteOnRails = SvelteOnRails;
@@ -1,6 +1,6 @@
1
1
  import {mount, hydrate} from "svelte";
2
2
  import {debugLog} from "../logger.js";
3
- import SvelteOnRails from "../config.js";
3
+ import { SvelteOnRails } from "../config.js";
4
4
 
5
5
  // Store for tracking initialized Svelte component instances
6
6
  const svelteInstances = new WeakMap();
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Vite plugin that generates chunk-modules.json containing
3
+ * a map of output chunk filenames → array of original module paths included in each chunk
4
+ *
5
+ * @param options - Plugin options
6
+ * @param options.fileName - Name of the emitted manifest file (default: '.vite/chunk-modules.json')
7
+ * @param options.includeNodeModules - Whether to include node_modules paths (default: false)
8
+ * @param options.moduleFilter - Optional filter for modules to include/exclude
9
+ * @returns Vite plugin
10
+ */
11
+ /// <reference path="../../types/vite.d.ts" />
12
+
13
+
14
+ import type { Plugin, OutputBundle } from 'vite';
15
+
16
+ export function devModuleMap(
17
+ options: {
18
+ fileName?: string;
19
+ includeNodeModules?: boolean;
20
+ moduleFilter?: (id: string) => boolean;
21
+ } = {}
22
+ ): Plugin {
23
+ const {
24
+ fileName = '.vite/dev-module-map.json',
25
+ includeNodeModules = false,
26
+ moduleFilter = null,
27
+ } = options;
28
+
29
+ return {
30
+ name: 'chunk-modules-manifest',
31
+ enforce: 'post',
32
+
33
+ generateBundle(_options: unknown, bundle: OutputBundle) {
34
+ /** Map: chunk filename → module paths */
35
+ const manifest: Record<string, string[]> = {};
36
+
37
+ for (const [chunkFileName, info] of Object.entries(bundle)) {
38
+ if (info.type !== 'chunk') continue;
39
+
40
+ let modules = Object.keys(info.modules ?? {});
41
+
42
+ // Optional filtering
43
+ if (!includeNodeModules) {
44
+ modules = modules.filter((id) => !id.includes('node_modules'));
45
+ }
46
+ if (moduleFilter) {
47
+ modules = modules.filter(moduleFilter);
48
+ }
49
+
50
+ if (modules.length > 0) {
51
+ manifest[chunkFileName] = modules;
52
+ }
53
+ }
54
+
55
+ // Emit the manifest as an asset
56
+ this.emitFile({
57
+ type: 'asset',
58
+ fileName, // goes to outDir / fileName
59
+ source: JSON.stringify(manifest, null, 2),
60
+ });
61
+ },
62
+ };
63
+ }
@@ -0,0 +1,27 @@
1
+ declare module 'vite' {
2
+ export interface PluginContext {
3
+ emitFile(params: {
4
+ type: 'asset';
5
+ fileName: string;
6
+ source: string;
7
+ }): void;
8
+ }
9
+
10
+ export interface Plugin {
11
+ name: string;
12
+ enforce?: 'pre' | 'post';
13
+ generateBundle?(
14
+ this: PluginContext,
15
+ options: unknown,
16
+ bundle: OutputBundle,
17
+ isWrite?: boolean
18
+ ): void;
19
+ }
20
+
21
+ export interface OutputBundle {
22
+ [fileName: string]: {
23
+ type: 'chunk' | 'asset';
24
+ modules?: Record<string, unknown>;
25
+ };
26
+ }
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2022"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true,
8
+ "esModuleInterop": true,
9
+ "allowImportingTsExtensions": true,
10
+ "resolveJsonModule": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "strict": true,
13
+ "noEmit": true,
14
+ "skipLibCheck": true,
15
+ "typeRoots": ["./src/types", "./node_modules/@types"]
16
+ },
17
+ "include": [
18
+ "src/**/*.ts",
19
+ "src/types/**/*.d.ts"
20
+ ],
21
+ "exclude": ["node_modules", "dist"]
22
+ }
package/types/ssr.d.ts ADDED
@@ -0,0 +1,16 @@
1
+
2
+ // Minimal stub — real type comes from @types/vite in the consuming project
3
+ interface Plugin {
4
+ name: string;
5
+ // ... add other properties you actually use/return, if any
6
+ [key: string]: any;
7
+ }
8
+
9
+ export function devModuleMap(
10
+ options?: {
11
+ fileName?: string;
12
+ includeNodeModules?: boolean;
13
+ moduleFilter?: (id: string) => boolean;
14
+ }
15
+ ): Plugin;
16
+
package/utils/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { SvelteOnRails } from "../src/config.js"; // assuming config.js uses export default
2
+ export { dispatchSvelteStreamEvent } from "../src/streams/dispatch-event.js";
3
+ export { streamDebugLog } from "../src/logger.js";