@poveste/plugin-nuxt 0.5.2 → 0.6.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/dist/index.d.ts +9 -1
- package/dist/index.js +30 -3
- package/package.json +11 -11
- package/src/index.ts +42 -3
- package/LICENSE +0 -22
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import type { Plugin } from 'poveste';
|
|
2
|
-
export
|
|
2
|
+
export interface HstNuxtOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Client plugins to drop from the story sandbox, matched against each
|
|
5
|
+
* plugin's resolved `src` (string `includes` or `RegExp`). Added on top of
|
|
6
|
+
* the built-in defaults, not replacing them.
|
|
7
|
+
*/
|
|
8
|
+
excludePlugins?: (string | RegExp)[];
|
|
9
|
+
}
|
|
10
|
+
export declare function HstNuxt(options?: HstNuxtOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -9,12 +9,17 @@ const ignorePlugins = [
|
|
|
9
9
|
'nuxt:dynamic-base-path',
|
|
10
10
|
'nuxt:import-protection',
|
|
11
11
|
];
|
|
12
|
-
|
|
12
|
+
// Some Nuxt modules register client plugins that assume a full Nuxt runtime the
|
|
13
|
+
// headless story sandbox can't provide, so they 500 the iframe on entry boot;
|
|
14
|
+
// @nuxtjs/i18n's are dropped by default (#65), and `excludePlugins` drops more
|
|
15
|
+
// without patching this package (#277).
|
|
16
|
+
const DEFAULT_EXCLUDED_PLUGINS = [/[\\/]@nuxtjs[\\/]i18n[\\/].*[\\/]plugins[\\/]/];
|
|
17
|
+
export function HstNuxt(options = {}) {
|
|
13
18
|
let nuxt;
|
|
14
19
|
return {
|
|
15
20
|
name: '@poveste/plugin-nuxt',
|
|
16
21
|
async defaultConfig() {
|
|
17
|
-
const nuxtViteConfig = await useNuxtViteConfig();
|
|
22
|
+
const nuxtViteConfig = await useNuxtViteConfig([...DEFAULT_EXCLUDED_PLUGINS, ...(options.excludePlugins ?? [])]);
|
|
18
23
|
const { viteConfig } = nuxtViteConfig;
|
|
19
24
|
nuxt = nuxtViteConfig.nuxt; // We save it to close it later
|
|
20
25
|
const plugins = viteConfig.plugins.filter((p) => !ignorePlugins.includes(p?.name));
|
|
@@ -98,13 +103,17 @@ export async function setupVue3 () {
|
|
|
98
103
|
},
|
|
99
104
|
};
|
|
100
105
|
}
|
|
101
|
-
async function useNuxtViteConfig() {
|
|
106
|
+
async function useNuxtViteConfig(excludePlugins) {
|
|
102
107
|
const { loadNuxt, buildNuxt } = await import('@nuxt/kit');
|
|
103
108
|
const nuxt = await loadNuxt({
|
|
104
109
|
// cwd: process.cwd(),
|
|
105
110
|
ready: false,
|
|
106
111
|
dev: true,
|
|
107
112
|
overrides: {
|
|
113
|
+
// Keep the auxiliary instance out of the host's `.nuxt`: it regenerates
|
|
114
|
+
// `imports.d.ts` and friends, which any later type-aware lint or vue-tsc
|
|
115
|
+
// run would then read instead of the application's own (#223).
|
|
116
|
+
buildDir: '.nuxt/poveste',
|
|
108
117
|
devtools: { enabled: false },
|
|
109
118
|
ssr: false,
|
|
110
119
|
experimental: {
|
|
@@ -124,6 +133,16 @@ async function useNuxtViteConfig() {
|
|
|
124
133
|
}
|
|
125
134
|
const runtimeDir = fileURLToPath(new URL('../runtime', import.meta.url));
|
|
126
135
|
nuxt.options.build.templates.push({ src: join(runtimeDir, 'composables.mjs'), filename: 'poveste/composables.mjs' }, { src: join(runtimeDir, 'components.mjs'), filename: 'poveste/components.mjs' });
|
|
136
|
+
// Drop the sandbox-incompatible client plugins named by `excludePlugins`, so
|
|
137
|
+
// they don't 500 the story iframe on entry boot. See DEFAULT_EXCLUDED_PLUGINS.
|
|
138
|
+
nuxt.hook('app:resolve', (app) => {
|
|
139
|
+
app.plugins = app.plugins.filter((p) => {
|
|
140
|
+
const src = p.src ?? '';
|
|
141
|
+
// `match`, not `test`: it doesn't advance a caller's /g regex `lastIndex`, so
|
|
142
|
+
// matching stays stateless without mutating an input we don't own.
|
|
143
|
+
return !excludePlugins.some(pattern => typeof pattern === 'string' ? src.includes(pattern) : src.match(pattern) !== null);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
127
146
|
nuxt.hook('app:templates', (app) => {
|
|
128
147
|
app.templates = app.templates.filter(template => template.filename !== 'app-component.mjs');
|
|
129
148
|
app.templates.push({ src: join(runtimeDir, 'app-component.mjs'), filename: 'app-component.mjs' });
|
|
@@ -155,6 +174,14 @@ async function useNuxtViteConfig() {
|
|
|
155
174
|
nuxt.hook('vite:configResolved', (config, { isClient }) => {
|
|
156
175
|
if (isClient) {
|
|
157
176
|
resolve(config);
|
|
177
|
+
// The resolved config is all this instance is for. Left running,
|
|
178
|
+
// `buildNuxt` goes on to build the Nuxt client, start Nitro and
|
|
179
|
+
// open Nuxt's own dev server — seconds of work on every `poveste
|
|
180
|
+
// dev` and `poveste build`, a `NUXT_B7005` warning for the entry
|
|
181
|
+
// it does not have, and an HMR socket on 24678 that collides with
|
|
182
|
+
// any other Nuxt dev server on the machine (#220, #221). The catch
|
|
183
|
+
// below has always known this sentinel; nothing threw it.
|
|
184
|
+
throw new Error('_stop_');
|
|
158
185
|
}
|
|
159
186
|
});
|
|
160
187
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poveste/plugin-nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "Poveste plugin to integrate with Nuxt 4",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sorin Gitlan"
|
|
@@ -22,10 +22,14 @@
|
|
|
22
22
|
"main": "./dist/index.js",
|
|
23
23
|
"module": "./dist/index.js",
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rimraf dist && tsc -d",
|
|
27
|
+
"watch": "tsc -d -w --sourceMap"
|
|
28
|
+
},
|
|
25
29
|
"peerDependencies": {
|
|
30
|
+
"@poveste/plugin-vue": "workspace:^",
|
|
26
31
|
"nuxt": "^4.5.0",
|
|
27
|
-
"
|
|
28
|
-
"poveste": "^0.5.2"
|
|
32
|
+
"poveste": "workspace:^"
|
|
29
33
|
},
|
|
30
34
|
"dependencies": {
|
|
31
35
|
"@nuxt/kit": "^4.5.2",
|
|
@@ -37,12 +41,8 @@
|
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@nuxt/schema": "^4.5.2",
|
|
39
43
|
"@types/node": "^22.10.1",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "rimraf dist && tsc -d",
|
|
46
|
-
"watch": "tsc -d -w --sourceMap"
|
|
44
|
+
"poveste": "workspace:*",
|
|
45
|
+
"typescript": "catalog:",
|
|
46
|
+
"vite": "catalog:"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -14,13 +14,28 @@ const ignorePlugins = [
|
|
|
14
14
|
'nuxt:import-protection',
|
|
15
15
|
]
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export interface HstNuxtOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Client plugins to drop from the story sandbox, matched against each
|
|
20
|
+
* plugin's resolved `src` (string `includes` or `RegExp`). Added on top of
|
|
21
|
+
* the built-in defaults, not replacing them.
|
|
22
|
+
*/
|
|
23
|
+
excludePlugins?: (string | RegExp)[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Some Nuxt modules register client plugins that assume a full Nuxt runtime the
|
|
27
|
+
// headless story sandbox can't provide, so they 500 the iframe on entry boot;
|
|
28
|
+
// @nuxtjs/i18n's are dropped by default (#65), and `excludePlugins` drops more
|
|
29
|
+
// without patching this package (#277).
|
|
30
|
+
const DEFAULT_EXCLUDED_PLUGINS: (string | RegExp)[] = [/[\\/]@nuxtjs[\\/]i18n[\\/].*[\\/]plugins[\\/]/]
|
|
31
|
+
|
|
32
|
+
export function HstNuxt(options: HstNuxtOptions = {}): Plugin {
|
|
18
33
|
let nuxt: Nuxt
|
|
19
34
|
return {
|
|
20
35
|
name: '@poveste/plugin-nuxt',
|
|
21
36
|
|
|
22
37
|
async defaultConfig() {
|
|
23
|
-
const nuxtViteConfig = await useNuxtViteConfig()
|
|
38
|
+
const nuxtViteConfig = await useNuxtViteConfig([...DEFAULT_EXCLUDED_PLUGINS, ...(options.excludePlugins ?? [])])
|
|
24
39
|
const { viteConfig } = nuxtViteConfig
|
|
25
40
|
|
|
26
41
|
nuxt = nuxtViteConfig.nuxt // We save it to close it later
|
|
@@ -111,13 +126,17 @@ export async function setupVue3 () {
|
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
|
|
114
|
-
async function useNuxtViteConfig() {
|
|
129
|
+
async function useNuxtViteConfig(excludePlugins: (string | RegExp)[]) {
|
|
115
130
|
const { loadNuxt, buildNuxt } = await import('@nuxt/kit')
|
|
116
131
|
const nuxt = await loadNuxt({
|
|
117
132
|
// cwd: process.cwd(),
|
|
118
133
|
ready: false,
|
|
119
134
|
dev: true,
|
|
120
135
|
overrides: {
|
|
136
|
+
// Keep the auxiliary instance out of the host's `.nuxt`: it regenerates
|
|
137
|
+
// `imports.d.ts` and friends, which any later type-aware lint or vue-tsc
|
|
138
|
+
// run would then read instead of the application's own (#223).
|
|
139
|
+
buildDir: '.nuxt/poveste',
|
|
121
140
|
devtools: { enabled: false },
|
|
122
141
|
ssr: false,
|
|
123
142
|
experimental: {
|
|
@@ -141,6 +160,18 @@ async function useNuxtViteConfig() {
|
|
|
141
160
|
{ src: join(runtimeDir, 'components.mjs'), filename: 'poveste/components.mjs' },
|
|
142
161
|
)
|
|
143
162
|
|
|
163
|
+
// Drop the sandbox-incompatible client plugins named by `excludePlugins`, so
|
|
164
|
+
// they don't 500 the story iframe on entry boot. See DEFAULT_EXCLUDED_PLUGINS.
|
|
165
|
+
nuxt.hook('app:resolve', (app) => {
|
|
166
|
+
app.plugins = app.plugins.filter((p) => {
|
|
167
|
+
const src = p.src ?? ''
|
|
168
|
+
// `match`, not `test`: it doesn't advance a caller's /g regex `lastIndex`, so
|
|
169
|
+
// matching stays stateless without mutating an input we don't own.
|
|
170
|
+
return !excludePlugins.some(pattern =>
|
|
171
|
+
typeof pattern === 'string' ? src.includes(pattern) : src.match(pattern) !== null)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
144
175
|
nuxt.hook('app:templates', (app) => {
|
|
145
176
|
app.templates = app.templates.filter(template => template.filename !== 'app-component.mjs')
|
|
146
177
|
app.templates.push({ src: join(runtimeDir, 'app-component.mjs'), filename: 'app-component.mjs' })
|
|
@@ -175,6 +206,14 @@ async function useNuxtViteConfig() {
|
|
|
175
206
|
nuxt.hook('vite:configResolved', (config, { isClient }) => {
|
|
176
207
|
if (isClient) {
|
|
177
208
|
resolve(config as any)
|
|
209
|
+
// The resolved config is all this instance is for. Left running,
|
|
210
|
+
// `buildNuxt` goes on to build the Nuxt client, start Nitro and
|
|
211
|
+
// open Nuxt's own dev server — seconds of work on every `poveste
|
|
212
|
+
// dev` and `poveste build`, a `NUXT_B7005` warning for the entry
|
|
213
|
+
// it does not have, and an HMR socket on 24678 that collides with
|
|
214
|
+
// any other Nuxt dev server on the machine (#220, #221). The catch
|
|
215
|
+
// below has always known this sentinel; nothing threw it.
|
|
216
|
+
throw new Error('_stop_')
|
|
178
217
|
}
|
|
179
218
|
})
|
|
180
219
|
})
|
package/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Guillaume Chau (original "histoire" project)
|
|
4
|
-
Copyright (c) 2026 Sorin Gitlan (poveste fork)
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|