@ethercorps/sveltekit-og 4.4.0-next.0 → 4.4.0-next.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/dist/plugin.d.ts CHANGED
@@ -2,5 +2,16 @@ import { unwasm, type UnwasmPluginOptions } from "unwasm/plugin";
2
2
  import type { Plugin as VitePlugin } from "vite";
3
3
  type Plugin = ReturnType<typeof unwasm>;
4
4
  export declare function rollupWasm(options?: UnwasmPluginOptions): Plugin;
5
+ /**
6
+ * Vite plugin: wires the wasm loader into the SSR bundle only. The client build
7
+ * (e.g. the /client entry) loads its wasm through Vite's own asset handling, and
8
+ * unwasm would break that.
9
+ *
10
+ * Gated at runtime rather than by Vite version: `import { version } from "vite"`
11
+ * resolves to this package's own copy of vite, not the consumer's.
12
+ * - Vite 6+: `applyToEnvironment` keeps the plugin off the client environment.
13
+ * - Vite 5: each hook no-ops unless the call carries `{ ssr: true }`.
14
+ * `apply: "build"` keeps parity with the previous `build.rollupOptions.plugins` wiring.
15
+ */
5
16
  export declare function sveltekitOG(options?: UnwasmPluginOptions): VitePlugin;
6
17
  export {};
package/dist/plugin.js CHANGED
@@ -6,24 +6,49 @@ export function rollupWasm(options) {
6
6
  ...options,
7
7
  });
8
8
  }
9
- export function sveltekitOG(options) {
9
+ /**
10
+ * Is this hook call for the server bundle? Vite 6+ (SvelteKit 3 builds through the
11
+ * Environment API) exposes `this.environment`; Vite 5 (SvelteKit 2 runs separate
12
+ * client and SSR builds) passes `{ ssr }` as the hook's last argument instead.
13
+ */
14
+ function isServer(ctx, args) {
15
+ if (ctx.environment)
16
+ return ctx.environment.config.consumer === "server";
17
+ const last = args[args.length - 1];
18
+ return typeof last === "object" && last !== null && last.ssr === true;
19
+ }
20
+ function serverOnly(hook) {
21
+ if (!hook)
22
+ return hook;
10
23
  return {
11
- name: "vite-plugin-sveltekit-og",
12
- // run after sveltekit(), whose config hook is what sets build.ssr
13
- enforce: "post",
14
- // SSR bundle only: the client build (e.g. the /client entry) loads its wasm
15
- // through Vite's own asset handling, and unwasm would break that. Vite computes
16
- // env.isSsrBuild before SvelteKit sets build.ssr, so check the merged config too.
17
- config(config, { isSsrBuild }) {
18
- if (!isSsrBuild && !config.build?.ssr)
19
- return;
20
- return {
21
- build: {
22
- rollupOptions: {
23
- plugins: [rollupWasm(options)],
24
- },
25
- },
26
- };
24
+ ...hook,
25
+ handler(...args) {
26
+ return isServer(this, args) ? hook.handler.apply(this, args) : null;
27
27
  },
28
28
  };
29
29
  }
30
+ /**
31
+ * Vite plugin: wires the wasm loader into the SSR bundle only. The client build
32
+ * (e.g. the /client entry) loads its wasm through Vite's own asset handling, and
33
+ * unwasm would break that.
34
+ *
35
+ * Gated at runtime rather than by Vite version: `import { version } from "vite"`
36
+ * resolves to this package's own copy of vite, not the consumer's.
37
+ * - Vite 6+: `applyToEnvironment` keeps the plugin off the client environment.
38
+ * - Vite 5: each hook no-ops unless the call carries `{ ssr: true }`.
39
+ * `apply: "build"` keeps parity with the previous `build.rollupOptions.plugins` wiring.
40
+ */
41
+ export function sveltekitOG(options) {
42
+ const wasm = rollupWasm(options);
43
+ // `applyToEnvironment` only exists in Vite 6+ types; this package compiles against Vite 5.
44
+ const plugin = {
45
+ ...wasm,
46
+ name: "vite-plugin-sveltekit-og",
47
+ apply: "build",
48
+ applyToEnvironment: (env) => env.config.consumer === "server",
49
+ resolveId: serverOnly(wasm.resolveId),
50
+ load: serverOnly(wasm.load),
51
+ transform: serverOnly(wasm.transform),
52
+ };
53
+ return plugin;
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethercorps/sveltekit-og",
3
- "version": "4.4.0-next.0",
3
+ "version": "4.4.0-next.1",
4
4
  "license": "MIT",
5
5
  "homepage": "https://sveltekit-og.dev",
6
6
  "repository": "github:etherCorps/sveltekit-og",