@poveste/plugin-svelte 0.17.2 → 0.18.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Requires `svelte@^5.46.4` and `@sveltejs/vite-plugin-svelte@^7.3.0`. SvelteKit is supported
4
4
  by this same package — there is no separate plugin — through an optional
5
- `@sveltejs/kit@^2.53.0` peer.
5
+ `@sveltejs/kit@^2.53.0 || ^3.0.0` peer.
6
6
 
7
7
  The floor is not `^5.0.0` for a reason: Poveste requires Vite 8, only
8
8
  `@sveltejs/vite-plugin-svelte` v7 peers Vite 8, and v7 in turn requires `svelte@^5.46.4`.
@@ -1,17 +1,24 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
+ import process from 'node:process';
3
4
  import { dirname, join } from 'pathe';
4
5
  import { defaultColors } from 'poveste';
5
6
  import generateStoryCommand from './commands/generate-story.server.js';
6
7
  import { SVELTE_SETUP_HOOK_NAMES } from './setup-hooks.js';
7
8
  import { svelteAutoProps } from './util/auto-props-vite.js';
8
9
  import { svelteKitAssetsDir } from './util/kit-assets.js';
10
+ import { withoutSvelteKitServer } from './util/kit-server.js';
11
+ import { syncSvelteKit } from './util/kit-sync.js';
9
12
  import { listComponentFiles } from './util/list-components.js';
10
13
  import { disableStoryComponentHmr } from './util/story-hmr.js';
11
14
  export function HstSvelte() {
12
15
  return {
13
16
  name: '@poveste/plugin-svelte',
14
17
  async defaultConfig() {
18
+ const syncProblem = syncSvelteKit(process.cwd());
19
+ if (syncProblem) {
20
+ console.warn(`[@poveste/plugin-svelte] svelte-kit sync failed, so types and aliases Kit generates may be missing:\n${syncProblem}`);
21
+ }
15
22
  const svelteClientAliases = getSvelteClientAliases();
16
23
  const publicDir = await svelteKitAssetsDir(process.cwd());
17
24
  return {
@@ -39,6 +46,7 @@ export function HstSvelte() {
39
46
  plugins: [
40
47
  svelteAutoProps(),
41
48
  disableStoryComponentHmr(),
49
+ withoutSvelteKitServer(),
42
50
  ],
43
51
  ...svelteClientAliases.length ? { resolve: { alias: svelteClientAliases } } : {},
44
52
  ...publicDir ? { publicDir } : {},
@@ -8,3 +8,4 @@
8
8
  * (#463). This restores the one value that went with it.
9
9
  */
10
10
  export declare function svelteKitAssetsDir(cwd: string): Promise<string | undefined>;
11
+ export declare function declaresKit(cwd: string): boolean;
@@ -21,7 +21,7 @@ export async function svelteKitAssetsDir(cwd) {
21
21
  // the project and finds Kit through a sibling in a workspace store, which
22
22
  // reported a plain Svelte book as SvelteKit and pointed its `publicDir` at a
23
23
  // `static/` that does not exist — losing the `public/` it actually had.
24
- function declaresKit(cwd) {
24
+ export function declaresKit(cwd) {
25
25
  try {
26
26
  const manifest = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8'));
27
27
  return ['dependencies', 'devDependencies', 'peerDependencies']
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Keeps SvelteKit 3's dev server out of the book. Kit 3 moved its middleware and
4
+ * preview server from `vite-plugin-sveltekit-compile`, which poveste ignores, into
5
+ * `vite-plugin-sveltekit-setup`, whose config the book still needs: aliases,
6
+ * `server.fs`, `define`. So that plugin stays, and only its server hooks go (#1200).
7
+ *
8
+ * At `configResolved`, which runs before Vite collects the server hooks. Kit 2's
9
+ * `setup` has neither hook, so this changes nothing there.
10
+ */
11
+ export declare function withoutSvelteKitServer(): Plugin;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Keeps SvelteKit 3's dev server out of the book. Kit 3 moved its middleware and
3
+ * preview server from `vite-plugin-sveltekit-compile`, which poveste ignores, into
4
+ * `vite-plugin-sveltekit-setup`, whose config the book still needs: aliases,
5
+ * `server.fs`, `define`. So that plugin stays, and only its server hooks go (#1200).
6
+ *
7
+ * At `configResolved`, which runs before Vite collects the server hooks. Kit 2's
8
+ * `setup` has neither hook, so this changes nothing there.
9
+ */
10
+ export function withoutSvelteKitServer() {
11
+ return {
12
+ name: 'poveste:sveltekit-server',
13
+ enforce: 'pre',
14
+ configResolved(config) {
15
+ for (const plugin of config.plugins) {
16
+ if (plugin.name === 'vite-plugin-sveltekit-setup') {
17
+ delete plugin.configureServer;
18
+ delete plugin.configurePreviewServer;
19
+ }
20
+ }
21
+ },
22
+ };
23
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Runs `svelte-kit sync` in a SvelteKit project, as Kit's own dev server does on
3
+ * start. That runs in the middleware poveste removes, and Kit 3 writes its result
4
+ * under `node_modules/$app`, which `npm install <package>` deletes: a project that
5
+ * had just installed poveste could not start its dev server (#1200).
6
+ *
7
+ * Returns why it could not run, for the caller to report; a failed sync is the
8
+ * project's to fix, and the book may still start without it.
9
+ */
10
+ export declare function syncSvelteKit(cwd: string): string | undefined;
@@ -0,0 +1,31 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import process from 'node:process';
5
+ import { dirname, join } from 'pathe';
6
+ import { declaresKit } from './kit-assets.js';
7
+ /**
8
+ * Runs `svelte-kit sync` in a SvelteKit project, as Kit's own dev server does on
9
+ * start. That runs in the middleware poveste removes, and Kit 3 writes its result
10
+ * under `node_modules/$app`, which `npm install <package>` deletes: a project that
11
+ * had just installed poveste could not start its dev server (#1200).
12
+ *
13
+ * Returns why it could not run, for the caller to report; a failed sync is the
14
+ * project's to fix, and the book may still start without it.
15
+ */
16
+ export function syncSvelteKit(cwd) {
17
+ if (!declaresKit(cwd)) {
18
+ return undefined;
19
+ }
20
+ let cli;
21
+ try {
22
+ const manifestPath = createRequire(join(cwd, 'package.json')).resolve('@sveltejs/kit/package.json');
23
+ const { bin } = JSON.parse(readFileSync(manifestPath, 'utf8'));
24
+ cli = join(dirname(manifestPath), typeof bin === 'string' ? bin : bin['svelte-kit']);
25
+ }
26
+ catch {
27
+ return '@sveltejs/kit is declared but could not be resolved from the project';
28
+ }
29
+ const result = spawnSync(process.execPath, [cli, 'sync'], { cwd, encoding: 'utf8' });
30
+ return result.status === 0 ? undefined : (result.stderr || result.error?.message || `exited with ${result.status}`).trim();
31
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poveste/plugin-svelte",
3
3
  "type": "module",
4
- "version": "0.17.2",
4
+ "version": "0.18.0",
5
5
  "description": "Poveste plugin for Svelte 5 and SvelteKit support",
6
6
  "author": {
7
7
  "name": "Sorin Gitlan",
@@ -63,9 +63,9 @@
63
63
  "node": ">=24.15.0"
64
64
  },
65
65
  "peerDependencies": {
66
- "@sveltejs/kit": "^2.53.0",
66
+ "@sveltejs/kit": "^2.53.0 || ^3.0.0",
67
67
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
68
- "poveste": "^0.17.2",
68
+ "poveste": "^0.18.0",
69
69
  "svelte": "^5.46.4"
70
70
  },
71
71
  "peerDependenciesMeta": {
@@ -74,9 +74,9 @@
74
74
  }
75
75
  },
76
76
  "dependencies": {
77
- "@poveste/controls": "^0.17.2",
78
- "@poveste/shared": "^0.17.2",
79
- "@poveste/vendors": "^0.17.2",
77
+ "@poveste/controls": "^0.18.0",
78
+ "@poveste/shared": "^0.18.0",
79
+ "@poveste/vendors": "^0.18.0",
80
80
  "change-case": "^5.4.4",
81
81
  "ignore": "^7.0.10",
82
82
  "launch-editor": "^2.9.1",
@@ -89,7 +89,7 @@
89
89
  "concurrently": "^10.0.5",
90
90
  "fs-extra": "^11.4.1",
91
91
  "jsdom": "^30.1.1",
92
- "poveste": "0.17.2",
92
+ "poveste": "0.18.0",
93
93
  "svelte": "5.57.1",
94
94
  "svelte-preprocess": "^6.0.5",
95
95
  "typescript": "6.0.3",