@poveste/plugin-nuxt 0.18.3 → 0.19.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.
@@ -0,0 +1,2 @@
1
+ export declare const ignorePlugins: string[];
2
+ export declare function withoutIgnoredPlugins<T>(plugins: T): T;
@@ -0,0 +1,20 @@
1
+ export const ignorePlugins = [
2
+ 'nuxt:vite-node-server',
3
+ 'nuxt:dev-style-ssr',
4
+ 'nuxt:vite-relative-asset',
5
+ 'nuxt:cache-dir',
6
+ 'nuxt:dynamic-base-path',
7
+ 'nuxt:import-protection',
8
+ // Looks for Nuxt's client entry to inject a preload polyfill into. A book has
9
+ // none, so it raised `NUXT_B7005` and said it could not resolve the entry, at
10
+ // every start and build, with a fix hint that does not apply here (#1203).
11
+ 'nuxt:module-preload-polyfill',
12
+ ];
13
+ export function withoutIgnoredPlugins(plugins) {
14
+ if (!Array.isArray(plugins)) {
15
+ return plugins;
16
+ }
17
+ return plugins
18
+ .filter(plugin => !ignorePlugins.includes(plugin?.name))
19
+ .map(plugin => withoutIgnoredPlugins(plugin));
20
+ }
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export interface HstNuxtOptions {
8
8
  excludePlugins?: (string | RegExp)[];
9
9
  }
10
10
  export declare function isPluginExcluded(src: string, patterns: (string | RegExp)[]): boolean;
11
- export declare function wrapPluginsForTolerantBoot(source: string): string;
11
+ export declare function wrapPluginsForTolerantBoot(source: string, root?: string): string;
12
12
  export declare function wrapPluginTemplates(templates: {
13
13
  filename?: string;
14
14
  getContents?: (ctx: any) => string | Promise<string>;
package/dist/index.js CHANGED
@@ -1,15 +1,8 @@
1
- import { join } from 'node:path';
1
+ import { isAbsolute, join, relative } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import replace from '@rollup/plugin-replace';
4
4
  import { onPovesteCleanup } from 'poveste';
5
- const ignorePlugins = [
6
- 'nuxt:vite-node-server',
7
- 'nuxt:dev-style-ssr',
8
- 'nuxt:vite-relative-asset',
9
- 'nuxt:cache-dir',
10
- 'nuxt:dynamic-base-path',
11
- 'nuxt:import-protection',
12
- ];
5
+ import { ignorePlugins, withoutIgnoredPlugins } from './ignored-plugins.js';
13
6
  // Some Nuxt modules register client plugins that assume a full Nuxt runtime the
14
7
  // headless story sandbox can't provide. The general net is `wrapPluginsForTolerantBoot`
15
8
  // below, which skips one that throws rather than 500-ing the iframe; this list drops
@@ -28,8 +21,19 @@ export function isPluginExcluded(src, patterns) {
28
21
  // ordering by transforming its output rather than reimplementing it. Returns the
29
22
  // source untouched if the `export default [...]` shape is not found, so an
30
23
  // upstream format change degrades to today's behaviour instead of breaking.
31
- export function wrapPluginsForTolerantBoot(source) {
32
- const wrapped = source.replace(/export default (\[[\s\S]*?\])/, 'export default $1.map(__povesteTolerant)');
24
+ export function wrapPluginsForTolerantBoot(source, root) {
25
+ // Each plugin's import path, handed to the guard so it can name a plugin that
26
+ // has no name of its own (#1063). From the project root where there is one:
27
+ // the paths are written into the book, and Nuxt imports by absolute path.
28
+ const sources = new Map();
29
+ for (const [, named, bare, , path] of source.matchAll(/import\s+(?:\{\s*default\s+as\s+([\w$]+)\s*\}|([\w$]+))\s+from\s+(['"])(.+?)\3/g)) {
30
+ const from = path;
31
+ sources.set((named ?? bare), root && isAbsolute(from) ? relative(root, from).replaceAll('\\', '/') : from);
32
+ }
33
+ const wrapped = source.replace(/export default (\[[\s\S]*?\])/, (_, list) => {
34
+ const from = list.slice(1, -1).split(',').map(name => name.trim()).filter(Boolean).map(name => sources.get(name) ?? null);
35
+ return `export default ${list}.map((plugin, index) => __povesteTolerant(plugin, ${JSON.stringify(from)}[index]))`;
36
+ });
33
37
  if (wrapped === source) {
34
38
  return source;
35
39
  }
@@ -49,7 +53,7 @@ export function wrapPluginTemplates(templates) {
49
53
  continue;
50
54
  }
51
55
  wrappedTemplates.add(template);
52
- template.getContents = async (ctx) => wrapPluginsForTolerantBoot(await original(ctx));
56
+ template.getContents = async (ctx) => wrapPluginsForTolerantBoot(await original(ctx), ctx?.nuxt?.options?.rootDir);
53
57
  }
54
58
  }
55
59
  export function HstNuxt(options = {}) {
@@ -219,6 +223,11 @@ async function useNuxtViteConfig(excludePlugins, isBuild) {
219
223
  }
220
224
  }
221
225
  });
226
+ // The same plugins are dropped from the config this returns. This instance
227
+ // resolves that config first, and the ones that complain do it there too.
228
+ nuxt.hook('vite:extendConfig', (config) => {
229
+ Object.assign(config, { plugins: withoutIgnoredPlugins(config.plugins) });
230
+ });
222
231
  return {
223
232
  // Captured from `vite:configResolved`, so it is the resolved config.
224
233
  viteConfig: await new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poveste/plugin-nuxt",
3
3
  "type": "module",
4
- "version": "0.18.3",
4
+ "version": "0.19.1",
5
5
  "description": "Poveste plugin to integrate with Nuxt 4",
6
6
  "author": {
7
7
  "name": "Sorin Gitlan",
@@ -49,9 +49,9 @@
49
49
  "node": ">=22.22.2"
50
50
  },
51
51
  "peerDependencies": {
52
- "@poveste/plugin-vue": "^0.18.3",
52
+ "@poveste/plugin-vue": "^0.19.1",
53
53
  "nuxt": "^4.5.0",
54
- "poveste": "^0.18.3"
54
+ "poveste": "^0.19.1"
55
55
  },
56
56
  "dependencies": {
57
57
  "@nuxt/kit": "^4.5.2",
@@ -62,7 +62,7 @@
62
62
  "devDependencies": {
63
63
  "@nuxt/schema": "^4.5.2",
64
64
  "@types/node": "^26.6.3",
65
- "poveste": "0.18.3",
65
+ "poveste": "0.19.1",
66
66
  "typescript": "6.0.3",
67
67
  "vite": "^8.3.1",
68
68
  "vitest": "^5.0.2"
@@ -7,7 +7,13 @@
7
7
  //
8
8
  // This catches setup-time failures only. A plugin that throws at module import
9
9
  // fails before this runs — drop those with HstNuxt({ excludePlugins }).
10
- export function __povesteTolerant(plugin) {
10
+ //
11
+ // `src` is the path the plugin was imported from. `defineNuxtPlugin(() => {})`,
12
+ // the form Nuxt's docs teach first, has no name: a function's `.name` is then
13
+ // `''`, which `??` does not fall through, and the warning named nothing. Two of
14
+ // them printed the same line twice (#1063). The path is also what
15
+ // `excludePlugins` matches, so it is what the reader needs for the remedy.
16
+ export function __povesteTolerant(plugin, src) {
11
17
  if (typeof plugin !== 'function') {
12
18
  return plugin
13
19
  }
@@ -17,7 +23,7 @@ export function __povesteTolerant(plugin) {
17
23
  }
18
24
  catch (error) {
19
25
  console.warn(
20
- `[poveste] Nuxt client plugin ${plugin._name ?? plugin.name ?? '(anonymous)'} `
26
+ `[poveste] Nuxt client plugin ${plugin._name || plugin.name || (src ? `from ${src}` : '(anonymous)')} `
21
27
  + 'threw while setting up in the story sandbox; skipping it. Drop it with '
22
28
  + 'HstNuxt({ excludePlugins }) if it can never run headless.',
23
29
  error,