@poveste/plugin-vue 0.19.1 → 0.21.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 +7 -0
- package/dist/bundled/client/app/MountStory.js +32 -30
- package/dist/bundled/client/app/RenderStory.js +39 -44
- package/dist/bundled/client/app/Story.js +62 -60
- package/dist/bundled/client/app/global-components.js +5 -3
- package/dist/bundled/client/app/host.js +9 -5
- package/dist/bundled/client/app/util.js +46 -33
- package/dist/bundled/client/server/Story.js +13 -0
- package/dist/bundled/client/server/collect.js +41 -0
- package/dist/bundled/client/server/run.js +10 -39
- package/dist/bundled/client/server.js +1 -2
- package/dist/bundled/testing/index.js +168 -0
- package/dist/client/app/Story.d.ts +19 -1
- package/dist/client/app/Variant.d.ts +2 -2
- package/dist/client/app/global-components.d.ts +1 -0
- package/dist/client/app/host.d.ts +8 -0
- package/dist/client/app/util.d.ts +28 -0
- package/dist/client/server/Story.d.ts +21 -3
- package/dist/client/server/collect.d.ts +14 -0
- package/dist/client-dependencies.d.ts +2 -0
- package/dist/client-dependencies.js +2 -0
- package/dist/docgen/events.d.ts +9 -0
- package/dist/docgen/events.js +45 -0
- package/dist/docgen/extractor.d.ts +7 -0
- package/dist/docgen/extractor.js +60 -0
- package/dist/docgen/generic.d.ts +5 -0
- package/dist/docgen/generic.js +19 -0
- package/dist/docgen/meta.d.ts +12 -0
- package/dist/docgen/meta.js +76 -0
- package/dist/docgen/slots.d.ts +6 -0
- package/dist/docgen/slots.js +21 -0
- package/dist/index.node.d.ts +2 -0
- package/dist/index.node.js +24 -11
- package/dist/testing/index.d.ts +28 -0
- package/dist/testing/vite.d.ts +18 -0
- package/dist/testing/vite.js +171 -0
- package/dist/util/project-vue.d.ts +1 -0
- package/dist/util/project-vue.js +12 -0
- package/dist/util/vue-plugin.d.ts +10 -0
- package/dist/util/vue-plugin.js +28 -0
- package/package.json +33 -15
- package/src/client/app/MountStory.ts +2 -0
- package/src/client/app/RenderStory.ts +2 -1
- package/src/client/app/Story.ts +15 -3
- package/src/client/app/global-components.ts +4 -0
- package/src/client/app/host.ts +21 -2
- package/src/client/app/util.ts +65 -0
- package/src/client/server/Story.ts +15 -2
- package/src/client/server/collect.ts +83 -0
- package/src/client/server/run.ts +3 -63
- package/src/client-dependencies.ts +2 -0
- package/src/docgen/events.ts +55 -0
- package/src/docgen/extractor.ts +67 -0
- package/src/docgen/generic.ts +20 -0
- package/src/docgen/meta.ts +93 -0
- package/src/docgen/slots.ts +33 -0
- package/src/index.node.ts +27 -12
- package/src/testing/index.ts +286 -0
- package/src/testing/vite.ts +194 -0
- package/src/util/project-vue.ts +13 -0
- package/src/util/vue-plugin.ts +32 -0
- package/testing.d.ts +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function readSlotProps(typescript, program, slot) {
|
|
2
|
+
if (!program) {
|
|
3
|
+
return [];
|
|
4
|
+
}
|
|
5
|
+
const checker = program.getTypeChecker();
|
|
6
|
+
let type;
|
|
7
|
+
try {
|
|
8
|
+
type = slot.getTypeObject();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return type.getProperties().map((property) => {
|
|
14
|
+
const description = typescript.displayPartsToString(property.getDocumentationComment(checker));
|
|
15
|
+
return {
|
|
16
|
+
name: property.name,
|
|
17
|
+
type: checker.typeToString(checker.getTypeOfSymbol(property)),
|
|
18
|
+
...description ? { description } : {},
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
package/dist/index.node.d.ts
CHANGED
package/dist/index.node.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
1
|
import { createRequire } from 'node:module';
|
|
3
|
-
import {
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { CLIENT_DEPENDENCIES } from './client-dependencies.js';
|
|
4
4
|
import generateStoryCommand from './commands/generate-story.server.js';
|
|
5
5
|
import { VUE_SETUP_HOOK_NAMES } from './setup-hooks.js';
|
|
6
6
|
import { listComponentFiles } from './util/list-components.js';
|
|
7
|
+
import { projectVueVersion } from './util/project-vue.js';
|
|
7
8
|
import { VAPOR_INTEROP_ID, vaporInteropModule, withoutVaporPlugin } from './util/vapor.js';
|
|
9
|
+
import { requireVuePlugin } from './util/vue-plugin.js';
|
|
10
|
+
const SCRIPT_COMPONENT = /(?<!\.d)\.[cm]?[jt]sx?$/;
|
|
8
11
|
export function HstVue() {
|
|
9
12
|
return {
|
|
10
13
|
name: '@poveste/plugin-vue',
|
|
@@ -22,7 +25,16 @@ export function HstVue() {
|
|
|
22
25
|
config() {
|
|
23
26
|
return {
|
|
24
27
|
vite: {
|
|
28
|
+
// The chrome's client code imports these, and the scan never reaches them: it
|
|
29
|
+
// loads through virtual modules, so a cold `poveste dev` found them only when the
|
|
30
|
+
// page asked, re-bundled and reloaded a Nuxt reader's first page (#1477). Named
|
|
31
|
+
// through this package, which every Vue, Nuxt and Quasar book lists, because the
|
|
32
|
+
// book itself cannot resolve them under pnpm.
|
|
33
|
+
optimizeDeps: {
|
|
34
|
+
include: CLIENT_DEPENDENCIES.map(name => `@poveste/plugin-vue > ${name}`),
|
|
35
|
+
},
|
|
25
36
|
plugins: [
|
|
37
|
+
requireVuePlugin(),
|
|
26
38
|
withoutVaporPlugin(),
|
|
27
39
|
(() => {
|
|
28
40
|
let root = process.cwd();
|
|
@@ -52,6 +64,15 @@ export function HstVue() {
|
|
|
52
64
|
},
|
|
53
65
|
};
|
|
54
66
|
},
|
|
67
|
+
// A story file documents nothing: it names the components that do. A script file is
|
|
68
|
+
// offered too, for a component written with `defineComponent` (#1463); the extractor
|
|
69
|
+
// answers nothing for one that isn't.
|
|
70
|
+
docgen: {
|
|
71
|
+
match: file => (file.endsWith('.vue') || SCRIPT_COMPONENT.test(file)) && !/\.story\.[^/]+$/.test(file) && !file.includes('/node_modules/'),
|
|
72
|
+
module: fileURLToPath(new URL('./docgen/extractor.js', import.meta.url)),
|
|
73
|
+
// `vue-component-meta` requires `typescript` from where it is installed, an optional peer npm does not add.
|
|
74
|
+
typescript: createRequire(import.meta.url).resolve('vue-component-meta'),
|
|
75
|
+
},
|
|
55
76
|
supportPlugin: {
|
|
56
77
|
id: 'vue3',
|
|
57
78
|
moduleName: '@poveste/plugin-vue',
|
|
@@ -72,13 +93,5 @@ export function HstVue() {
|
|
|
72
93
|
},
|
|
73
94
|
};
|
|
74
95
|
}
|
|
75
|
-
function projectVueVersion(root) {
|
|
76
|
-
try {
|
|
77
|
-
const manifest = createRequire(join(root, 'package.json')).resolve('vue/package.json');
|
|
78
|
-
return JSON.parse(readFileSync(manifest, 'utf8')).version;
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
96
|
export * from './helpers.js';
|
|
97
|
+
export { povesteTesting } from './testing/vite.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Component } from 'vue';
|
|
2
|
+
export interface TestStoriesOptions {
|
|
3
|
+
/** The outer `describe`'s name. The story file's name by default. */
|
|
4
|
+
name?: string;
|
|
5
|
+
/**
|
|
6
|
+
* How long a variant's setup may take to settle, in milliseconds: an
|
|
7
|
+
* `initState` or an async `setup()` still pending then fails the test.
|
|
8
|
+
*/
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
type StoryComponent = Component & {
|
|
12
|
+
__file?: string;
|
|
13
|
+
doc?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Turns a story file into one test per variant. Each test renders the variant
|
|
17
|
+
* the way the preview does, and fails on what the preview would only log: an
|
|
18
|
+
* error from setup or render, a rejected `initState`, or a `[Vue warn]`.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { testStories } from '@poveste/plugin-vue/testing'
|
|
22
|
+
* import BaseButton from './BaseButton.story.vue'
|
|
23
|
+
*
|
|
24
|
+
* testStories(BaseButton)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function testStories(component: StoryComponent, options?: TestStoriesOptions): void;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface PovesteTestingOptions {
|
|
3
|
+
/** The book's poveste config file. Found from the Vite root by default. */
|
|
4
|
+
configFile?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* What a story needs in the user's own Vitest to render as `poveste dev` renders
|
|
8
|
+
* it: the book's setup file and the modules Poveste's client imports, with
|
|
9
|
+
* Poveste's own packages inlined so Vitest can serve those, and `vue` and the
|
|
10
|
+
* setup file pre-bundled for browser mode. Nothing else: no alias and no change
|
|
11
|
+
* to how anything resolves, so the test sees the project's Vite config as the
|
|
12
|
+
* project wrote it.
|
|
13
|
+
*
|
|
14
|
+
* Setup code that a plugin generates for `poveste dev`, such as the Nuxt app
|
|
15
|
+
* `@poveste/plugin-nuxt` boots, is left to the test environment, which already
|
|
16
|
+
* provides it: `@nuxt/test-utils`'s `nuxt` environment does in a Nuxt project.
|
|
17
|
+
*/
|
|
18
|
+
export declare function povesteTesting(options?: PovesteTestingOptions): Plugin;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { clientConfig, VIRTUAL_IDS } from '@poveste/shared';
|
|
5
|
+
import { getDefaultConfig, loadConfigFile, mergeConfig, resolveConfigFile } from 'poveste';
|
|
6
|
+
import { VUE_SETUP_HOOK_NAMES } from '../setup-hooks.js';
|
|
7
|
+
import { projectVueVersion } from '../util/project-vue.js';
|
|
8
|
+
import { VAPOR_INTEROP_ID, vaporInteropModule } from '../util/vapor.js';
|
|
9
|
+
const EMPTY_SETUP_ID = '\0poveste-testing:empty-setup';
|
|
10
|
+
const CONFIG_RESOLVED_ID = `\0${VIRTUAL_IDS.config}`;
|
|
11
|
+
const ENVIRONMENT_ID = 'virtual:$poveste-testing-environment';
|
|
12
|
+
// Vitest hands what it finds in `node_modules` to Node, which can't load the
|
|
13
|
+
// `virtual:` modules these packages import, so in a book that installs them no test
|
|
14
|
+
// ran (#1503). The workspace links them, and Vitest inlines a linked package.
|
|
15
|
+
const POVESTE_PACKAGES = [/\/node_modules\/poveste\//, /\/node_modules\/@poveste\//];
|
|
16
|
+
const EMPTY_SETUP = VUE_SETUP_HOOK_NAMES.map(name => `export const ${name} = undefined`).join('\n');
|
|
17
|
+
// `logEvent` from `poveste/client` reaches `@poveste/app`, which names these. A
|
|
18
|
+
// test never runs the code that reads them, but Vite's dependency scan follows
|
|
19
|
+
// the imports, and one it can't resolve skips pre-bundling and reloads the
|
|
20
|
+
// browser run partway through.
|
|
21
|
+
const INERT = {
|
|
22
|
+
[VIRTUAL_IDS.markdownFiles]: 'export const markdownFiles = []\n',
|
|
23
|
+
[VIRTUAL_IDS.componentDocs]: 'export const componentDocs = {}\n',
|
|
24
|
+
[VIRTUAL_IDS.supportPluginsClient]: 'export const clientSupportPlugins = {}\n',
|
|
25
|
+
};
|
|
26
|
+
// Nuxt boots in `@nuxt/test-utils`' `beforeAll`, after Vitest has collected the
|
|
27
|
+
// tests, and a story's own setup can call a Nuxt composable while it is being
|
|
28
|
+
// collected. So its own `setupNuxt` runs before collection, into the promise that
|
|
29
|
+
// `beforeAll` awaits, and Nuxt boots once and in full. Both names are internal to
|
|
30
|
+
// `@nuxt/test-utils`: if a version renames them, the story tests fail loudly.
|
|
31
|
+
function nuxtEnvironment(setupNuxt) {
|
|
32
|
+
return `import { tryUseNuxtApp } from '#app/nuxt'
|
|
33
|
+
import { setupNuxt } from ${JSON.stringify(setupNuxt)}
|
|
34
|
+
|
|
35
|
+
export async function environmentReady() {
|
|
36
|
+
const win = window
|
|
37
|
+
if (!win.__NUXT_VITEST_ENVIRONMENT__ || tryUseNuxtApp()) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
win.__NUXT_VITEST_ENVIRONMENT_PROMISE__ ??= setupNuxt()
|
|
41
|
+
await win.__NUXT_VITEST_ENVIRONMENT_PROMISE__
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function environmentApp() {
|
|
45
|
+
return tryUseNuxtApp()?.vueApp
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
const NO_ENVIRONMENT = `export async function environmentReady() {}\nexport function environmentApp() {\n return undefined\n}\n`;
|
|
50
|
+
// `@nuxt/test-utils`' own boot, by file: its `exports` don't list it.
|
|
51
|
+
function setupNuxtFile(root) {
|
|
52
|
+
try {
|
|
53
|
+
const file = join(dirname(createRequire(join(root, 'package.json')).resolve('@nuxt/test-utils/package.json')), 'dist/runtime/shared/nuxt.mjs');
|
|
54
|
+
return existsSync(file) ? file : undefined;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Root-relative, as `poveste dev` reads it: the docs write `/src/poveste.setup.ts`,
|
|
61
|
+
// which `resolve` takes as absolute, so pre-bundling scanned a file outside the
|
|
62
|
+
// book and the setup file's imports were found late, with a reload (#1507).
|
|
63
|
+
function setupFileOf(config) {
|
|
64
|
+
const setupFile = config.setupFile;
|
|
65
|
+
const file = typeof setupFile === 'string' ? setupFile : setupFile && 'browser' in setupFile ? setupFile.browser : undefined;
|
|
66
|
+
return file?.replace(/^\/+/, '');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* What a story needs in the user's own Vitest to render as `poveste dev` renders
|
|
70
|
+
* it: the book's setup file and the modules Poveste's client imports, with
|
|
71
|
+
* Poveste's own packages inlined so Vitest can serve those, and `vue` and the
|
|
72
|
+
* setup file pre-bundled for browser mode. Nothing else: no alias and no change
|
|
73
|
+
* to how anything resolves, so the test sees the project's Vite config as the
|
|
74
|
+
* project wrote it.
|
|
75
|
+
*
|
|
76
|
+
* Setup code that a plugin generates for `poveste dev`, such as the Nuxt app
|
|
77
|
+
* `@poveste/plugin-nuxt` boots, is left to the test environment, which already
|
|
78
|
+
* provides it: `@nuxt/test-utils`'s `nuxt` environment does in a Nuxt project.
|
|
79
|
+
*/
|
|
80
|
+
export function povesteTesting(options = {}) {
|
|
81
|
+
let root = process.cwd();
|
|
82
|
+
let config = {};
|
|
83
|
+
return {
|
|
84
|
+
name: 'poveste:testing',
|
|
85
|
+
async config(user) {
|
|
86
|
+
root = resolve(user.root ?? process.cwd());
|
|
87
|
+
const file = options.configFile ? resolve(root, options.configFile) : resolveConfigFile(root);
|
|
88
|
+
const fromFile = file ? await loadConfigFile(file) : {};
|
|
89
|
+
// As `poveste dev` reads it: the config file, then the Vite config's key.
|
|
90
|
+
const fromVite = (user.poveste
|
|
91
|
+
?? user.histoire ?? {});
|
|
92
|
+
config = mergeConfig(fromFile, fromVite);
|
|
93
|
+
// In browser mode Vite pre-bundles what its scan finds. It never sees `vue`,
|
|
94
|
+
// which compiled templates and this package's own bundle import, nor the
|
|
95
|
+
// setup file, which arrives as a virtual module. Each was bundled later,
|
|
96
|
+
// with a reload partway through the first run, and two copies of Vue
|
|
97
|
+
// failed it (#1503).
|
|
98
|
+
const setupFile = setupFileOf(config);
|
|
99
|
+
const optimizeDeps = {
|
|
100
|
+
include: ['vue'],
|
|
101
|
+
...setupFile ? { entries: [relative(root, resolve(root, setupFile)).split(sep).join('/')] } : {},
|
|
102
|
+
};
|
|
103
|
+
// `true` already inlines everything, and an array merged into it would not.
|
|
104
|
+
if (user.test?.server?.deps?.inline === true) {
|
|
105
|
+
return { optimizeDeps };
|
|
106
|
+
}
|
|
107
|
+
return { optimizeDeps, test: { server: { deps: { inline: POVESTE_PACKAGES } } } };
|
|
108
|
+
},
|
|
109
|
+
configResolved(resolved) {
|
|
110
|
+
root = resolved.root;
|
|
111
|
+
},
|
|
112
|
+
async resolveId(id, importer) {
|
|
113
|
+
if (id === VIRTUAL_IDS.setup) {
|
|
114
|
+
const file = setupFileOf(config);
|
|
115
|
+
if (file) {
|
|
116
|
+
return this.resolve(resolve(root, file), importer, { skipSelf: true });
|
|
117
|
+
}
|
|
118
|
+
return EMPTY_SETUP_ID;
|
|
119
|
+
}
|
|
120
|
+
if (id === VIRTUAL_IDS.generatedGlobalSetup) {
|
|
121
|
+
return EMPTY_SETUP_ID;
|
|
122
|
+
}
|
|
123
|
+
if (id === VIRTUAL_IDS.config) {
|
|
124
|
+
return CONFIG_RESOLVED_ID;
|
|
125
|
+
}
|
|
126
|
+
if (id === VAPOR_INTEROP_ID) {
|
|
127
|
+
return `\0${VAPOR_INTEROP_ID}`;
|
|
128
|
+
}
|
|
129
|
+
if (Object.hasOwn(INERT, id)) {
|
|
130
|
+
return `\0${id}`;
|
|
131
|
+
}
|
|
132
|
+
if (id === ENVIRONMENT_ID) {
|
|
133
|
+
return `\0${ENVIRONMENT_ID}`;
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
},
|
|
137
|
+
// A story's `<docs>` block, which `poveste dev` renders as markdown. A test
|
|
138
|
+
// renders the variants, not the docs, so it only has to import.
|
|
139
|
+
transform(_code, id) {
|
|
140
|
+
if (id.includes('?vue&type=docs')) {
|
|
141
|
+
return 'export default () => {}';
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
},
|
|
145
|
+
async load(id) {
|
|
146
|
+
if (id === EMPTY_SETUP_ID) {
|
|
147
|
+
return EMPTY_SETUP;
|
|
148
|
+
}
|
|
149
|
+
if (id === CONFIG_RESOLVED_ID) {
|
|
150
|
+
return `export const config = ${JSON.stringify(clientConfig({ ...getDefaultConfig(), ...config }))}\nexport const logos = {}\n`;
|
|
151
|
+
}
|
|
152
|
+
if (id === `\0${VAPOR_INTEROP_ID}`) {
|
|
153
|
+
return vaporInteropModule(projectVueVersion(root));
|
|
154
|
+
}
|
|
155
|
+
if (id.startsWith('\0') && Object.hasOwn(INERT, id.slice(1))) {
|
|
156
|
+
return INERT[id.slice(1)];
|
|
157
|
+
}
|
|
158
|
+
// The app the test environment boots: Nuxt's, under `@nuxt/test-utils`' `nuxt`
|
|
159
|
+
// environment. `poveste dev` renders a story inside the Nuxt app its plugin
|
|
160
|
+
// boots, and a test does the same. Told by Nuxt's own `#app` alias and the
|
|
161
|
+
// test utils being installed, not by `#imports`, which unimport also serves.
|
|
162
|
+
if (id === `\0${ENVIRONMENT_ID}`) {
|
|
163
|
+
const setupNuxt = setupNuxtFile(root);
|
|
164
|
+
return setupNuxt && await this.resolve('#app/nuxt', resolve(root, 'index.html'))
|
|
165
|
+
? nuxtEnvironment(setupNuxt)
|
|
166
|
+
: NO_ENVIRONMENT;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function projectVueVersion(root: string): string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export function projectVueVersion(root) {
|
|
5
|
+
try {
|
|
6
|
+
const manifest = createRequire(join(root, 'package.json')).resolve('vue/package.json');
|
|
7
|
+
return JSON.parse(readFileSync(manifest, 'utf8')).version;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* What to say when a book's Vite config has no Vue plugin. Without one, Vite
|
|
4
|
+
* answers the first `.vue` file with "Install @vitejs/plugin-vue", which sends a
|
|
5
|
+
* Quasar reader to install a package their project does not need: Quasar brings
|
|
6
|
+
* its own Vue plugin, and `HstQuasar()` is what hands it to Poveste (#1337).
|
|
7
|
+
*/
|
|
8
|
+
export declare function noVuePluginMessage(root: string, exists?: (path: string) => boolean): string;
|
|
9
|
+
/** Reports, once per process, a resolved Vite config with no Vue plugin in it. */
|
|
10
|
+
export declare function requireVuePlugin(): VitePlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const QUASAR_CONFIGS = ['quasar.config.js', 'quasar.config.mjs', 'quasar.config.cjs', 'quasar.config.ts'];
|
|
4
|
+
/**
|
|
5
|
+
* What to say when a book's Vite config has no Vue plugin. Without one, Vite
|
|
6
|
+
* answers the first `.vue` file with "Install @vitejs/plugin-vue", which sends a
|
|
7
|
+
* Quasar reader to install a package their project does not need: Quasar brings
|
|
8
|
+
* its own Vue plugin, and `HstQuasar()` is what hands it to Poveste (#1337).
|
|
9
|
+
*/
|
|
10
|
+
export function noVuePluginMessage(root, exists = existsSync) {
|
|
11
|
+
const fix = QUASAR_CONFIGS.some(name => exists(join(root, name)))
|
|
12
|
+
? 'This is a Quasar project: add `HstQuasar()` from `@poveste/plugin-quasar` to the config\'s `plugins`, which brings Quasar\'s own Vue plugin.'
|
|
13
|
+
: 'Add `@vitejs/plugin-vue` to `vite.config`, or in a Nuxt project `HstNuxt()` from `@poveste/plugin-nuxt` to the config\'s `plugins`.';
|
|
14
|
+
return `[poveste] The Vite config has no Vue plugin, so no \`.vue\` story can be compiled. ${fix}`;
|
|
15
|
+
}
|
|
16
|
+
/** Reports, once per process, a resolved Vite config with no Vue plugin in it. */
|
|
17
|
+
export function requireVuePlugin() {
|
|
18
|
+
let reported = false;
|
|
19
|
+
return {
|
|
20
|
+
name: 'poveste-plugin-vue:require-vue-plugin',
|
|
21
|
+
configResolved(config) {
|
|
22
|
+
if (!reported && !config.plugins.some(plugin => plugin.name === 'vite:vue')) {
|
|
23
|
+
reported = true;
|
|
24
|
+
console.error(noVuePluginMessage(config.root));
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poveste/plugin-vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Poveste plugin for Vue.
|
|
4
|
+
"version": "0.21.0",
|
|
5
|
+
"description": "Poveste plugin for Vue 3: stories as .vue files, controls, and a props, slots and events table read from your components' types",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sorin Gitlan",
|
|
8
8
|
"url": "https://x.com/50rayn"
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"types": "./dist/client/server.d.ts",
|
|
42
42
|
"default": "./dist/bundled/client/server.js"
|
|
43
43
|
},
|
|
44
|
+
"./testing": {
|
|
45
|
+
"types": "./dist/testing/index.d.ts",
|
|
46
|
+
"default": "./dist/bundled/testing/index.js"
|
|
47
|
+
},
|
|
44
48
|
"./components": {
|
|
45
49
|
"types": "./components.d.ts"
|
|
46
50
|
},
|
|
@@ -66,33 +70,46 @@
|
|
|
66
70
|
"collect.d.ts",
|
|
67
71
|
"components.d.ts",
|
|
68
72
|
"dist",
|
|
69
|
-
"src"
|
|
73
|
+
"src",
|
|
74
|
+
"testing.d.ts"
|
|
70
75
|
],
|
|
71
76
|
"engines": {
|
|
72
77
|
"node": ">=22.22.2"
|
|
73
78
|
},
|
|
74
79
|
"peerDependencies": {
|
|
75
|
-
"poveste": "^0.
|
|
80
|
+
"poveste": "^0.21.0",
|
|
81
|
+
"vitest": "^5.0.0",
|
|
76
82
|
"vue": "^3.5.43"
|
|
77
83
|
},
|
|
84
|
+
"peerDependenciesMeta": {
|
|
85
|
+
"vitest": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
78
89
|
"dependencies": {
|
|
79
|
-
"@poveste/controls": "^0.
|
|
80
|
-
"@poveste/shared": "^0.
|
|
81
|
-
"@poveste/vendors": "^0.
|
|
90
|
+
"@poveste/controls": "^0.21.0",
|
|
91
|
+
"@poveste/shared": "^0.21.0",
|
|
92
|
+
"@poveste/vendors": "^0.21.0",
|
|
82
93
|
"change-case": "^5.4.4",
|
|
83
94
|
"ignore": "^7.0.10",
|
|
84
|
-
"launch-editor": "^2.
|
|
95
|
+
"launch-editor": "^2.14.2",
|
|
85
96
|
"pathe": "^2.0.3",
|
|
86
|
-
"tinyglobby": "^0.2.17"
|
|
97
|
+
"tinyglobby": "^0.2.17",
|
|
98
|
+
"vue-component-meta": "^3.3.13"
|
|
87
99
|
},
|
|
88
100
|
"devDependencies": {
|
|
89
|
-
"@
|
|
90
|
-
"
|
|
91
|
-
"
|
|
101
|
+
"@fontsource/fira-mono": "^5.3.0",
|
|
102
|
+
"@tailwindcss/oxide": "^4.3.3",
|
|
103
|
+
"@types/node": "^26.6.5",
|
|
104
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
105
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
106
|
+
"concurrently": "^10.0.6",
|
|
107
|
+
"jsdom": "^30.1.3",
|
|
108
|
+
"poveste": "0.21.0",
|
|
92
109
|
"typescript": "6.0.3",
|
|
93
|
-
"vite": "^8.3.
|
|
94
|
-
"vitest": "^5.0.
|
|
95
|
-
"vue": "^3.5.
|
|
110
|
+
"vite": "^8.3.4",
|
|
111
|
+
"vitest": "^5.0.5",
|
|
112
|
+
"vue": "^3.5.44",
|
|
96
113
|
"vue-vapor-rc": "npm:vue@3.6.0-rc.10"
|
|
97
114
|
},
|
|
98
115
|
"scripts": {
|
|
@@ -100,6 +117,7 @@
|
|
|
100
117
|
"build:types": "tsc --declaration --emitDeclarationOnly",
|
|
101
118
|
"watch": "concurrently \"vite build --watch\" \"tsc -d -P tsconfig.build.json --watch\" \"pnpm run build:types --watch\"",
|
|
102
119
|
"test": "vitest run",
|
|
120
|
+
"test:story-tests": "vitest run --config vitest.story-tests.config.ts",
|
|
103
121
|
"test:dev": "vitest"
|
|
104
122
|
}
|
|
105
123
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@poveste/vendors/vue'
|
|
13
13
|
import { reactive } from 'vue'
|
|
14
14
|
import { createPreviewHost } from './host.js'
|
|
15
|
+
import { warnIfForeignVue } from './util.js'
|
|
15
16
|
|
|
16
17
|
export default _defineComponent({
|
|
17
18
|
name: 'MountStory',
|
|
@@ -34,6 +35,7 @@ export default _defineComponent({
|
|
|
34
35
|
},
|
|
35
36
|
|
|
36
37
|
setup(props) {
|
|
38
|
+
warnIfForeignVue('MountStory')
|
|
37
39
|
const el = _ref<HTMLDivElement>()
|
|
38
40
|
const renderContext = reactive({
|
|
39
41
|
mode: 'mount' as const,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '@poveste/vendors/vue'
|
|
13
13
|
import { reactive } from 'vue'
|
|
14
14
|
import { createPreviewHost } from './host.js'
|
|
15
|
-
import { syncStateBundledAndExternal } from './util.js'
|
|
15
|
+
import { syncStateBundledAndExternal, warnIfForeignVue } from './util.js'
|
|
16
16
|
|
|
17
17
|
export default _defineComponent({
|
|
18
18
|
name: 'RenderStory',
|
|
@@ -39,6 +39,7 @@ export default _defineComponent({
|
|
|
39
39
|
},
|
|
40
40
|
|
|
41
41
|
setup(props, { emit }) {
|
|
42
|
+
warnIfForeignVue('RenderStory')
|
|
42
43
|
const sandbox = _ref<HTMLDivElement>()
|
|
43
44
|
let host: ReturnType<typeof createPreviewHost> | null = null
|
|
44
45
|
let mounting = false
|
package/src/client/app/Story.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Story } from '@poveste/shared'
|
|
2
|
-
import type { PropType, VNode } from 'vue'
|
|
2
|
+
import type { Component, PropType, VNode } from 'vue'
|
|
3
3
|
import type { PreviewRenderContext } from './render-context.js'
|
|
4
4
|
import { omitInheritStoryProps } from '@poveste/shared'
|
|
5
5
|
import { cloneVNode, computed, defineComponent, h, isRef, reactive, useAttrs } from 'vue'
|
|
6
6
|
import { implicitStateContext, storyContext } from './context.js'
|
|
7
7
|
import { useRenderContext } from './render-context.js'
|
|
8
|
-
import { isWritableBinding, useInstance } from './util.js'
|
|
8
|
+
import { holdsVueApp, isComponentBinding, isWritableBinding, useInstance } from './util.js'
|
|
9
9
|
import Variant from './Variant.js'
|
|
10
10
|
|
|
11
11
|
export default defineComponent({
|
|
@@ -25,6 +25,18 @@ export default defineComponent({
|
|
|
25
25
|
type: Object as PropType<Story['meta']>,
|
|
26
26
|
default: undefined,
|
|
27
27
|
},
|
|
28
|
+
|
|
29
|
+
// Read at collection; declared so it is not passed on to the variants (#1398).
|
|
30
|
+
autoDocs: {
|
|
31
|
+
type: [Boolean, Array] as PropType<Story['autoDocs']>,
|
|
32
|
+
default: undefined,
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// The components the Docs tab documents, read from the source by auto-docs (#1432).
|
|
36
|
+
component: {
|
|
37
|
+
type: [Object, Function, Array] as PropType<Component | Component[]>,
|
|
38
|
+
default: undefined,
|
|
39
|
+
},
|
|
28
40
|
},
|
|
29
41
|
|
|
30
42
|
setup(props) {
|
|
@@ -53,7 +65,7 @@ export default defineComponent({
|
|
|
53
65
|
function addImplicitState(source: Record<string, any>, key: string) {
|
|
54
66
|
const value = source[key]
|
|
55
67
|
|
|
56
|
-
if (
|
|
68
|
+
if (isComponentBinding(value) || holdsVueApp(value)) {
|
|
57
69
|
return
|
|
58
70
|
}
|
|
59
71
|
|
|
@@ -28,6 +28,10 @@ export function registerGlobalComponents(app: App) {
|
|
|
28
28
|
|
|
29
29
|
app.component('Variant', Variant)
|
|
30
30
|
|
|
31
|
+
registerControlComponents(app)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function registerControlComponents(app: App) {
|
|
31
35
|
for (const [key, component] of Object.entries(components)) {
|
|
32
36
|
app.component(key, wrapControlComponent(component))
|
|
33
37
|
}
|
package/src/client/app/host.ts
CHANGED
|
@@ -27,6 +27,13 @@ interface PreviewHostOptions {
|
|
|
27
27
|
getVariant: () => Variant | null
|
|
28
28
|
renderContext: PreviewRenderContext
|
|
29
29
|
wrapInDiv?: boolean
|
|
30
|
+
/** A story test's: what the app would only log, it fails on. */
|
|
31
|
+
onError?: (err: unknown) => void
|
|
32
|
+
onWarn?: (message: string, trace: string) => void
|
|
33
|
+
/** A story test's: when the render's async setups have settled. */
|
|
34
|
+
onResolve?: () => void
|
|
35
|
+
/** A story test's, run after the app's own registrations and setup hooks. */
|
|
36
|
+
configureApp?: (app: App) => void
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
const PreviewHostRoot = defineComponent({
|
|
@@ -86,7 +93,7 @@ export function createPreviewHost(options: PreviewHostOptions) {
|
|
|
86
93
|
vnode = h('div', vnode)
|
|
87
94
|
}
|
|
88
95
|
|
|
89
|
-
return h(Suspense, {}, vnode)
|
|
96
|
+
return h(Suspense, options.onResolve ? { onResolve: options.onResolve } : {}, vnode)
|
|
90
97
|
},
|
|
91
98
|
})
|
|
92
99
|
|
|
@@ -98,7 +105,17 @@ export function createPreviewHost(options: PreviewHostOptions) {
|
|
|
98
105
|
storyId: options.getStory()?.id,
|
|
99
106
|
variantId: options.getVariant()?.id,
|
|
100
107
|
})
|
|
101
|
-
|
|
108
|
+
if (options.onError) {
|
|
109
|
+
options.onError(err)
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.error(err)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (options.onWarn) {
|
|
117
|
+
const onWarn = options.onWarn
|
|
118
|
+
app.config.warnHandler = (message, _instance, trace) => onWarn(message, trace)
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
// From Vue 3.6, a Vapor component inside a VDOM tree mounts only through this
|
|
@@ -123,6 +140,8 @@ export function createPreviewHost(options: PreviewHostOptions) {
|
|
|
123
140
|
|
|
124
141
|
await runSetupHooks(setupApi)
|
|
125
142
|
|
|
143
|
+
options.configureApp?.(app)
|
|
144
|
+
|
|
126
145
|
app.mount(target)
|
|
127
146
|
}
|
|
128
147
|
|