poveste 0.16.0 → 0.16.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.
|
@@ -1,4 +1,34 @@
|
|
|
1
|
+
import type { EvaluatedModuleNode } from 'vite/module-runner';
|
|
1
2
|
import { EvaluatedModules, ModuleRunner } from 'vite/module-runner';
|
|
2
3
|
export type Invoke = (name: string, data: unknown[]) => Promise<unknown>;
|
|
3
|
-
/**
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The file a CJS module should believe it is, for `require`, `__filename` and
|
|
6
|
+
* `__dirname`.
|
|
7
|
+
*
|
|
8
|
+
* A Vite id is root-relative, so `/node_modules/vue/index.js` is an id and not a
|
|
9
|
+
* path that exists. `isAbsolute()` answers "does this start with a separator",
|
|
10
|
+
* which that satisfies, so an id used to become a `filename` and the module's own
|
|
11
|
+
* `require('./dist/…')` resolved against a directory under the filesystem root.
|
|
12
|
+
* Quasar's config pulls `vue` through here, and a Quasar book could not collect a
|
|
13
|
+
* story at all (#1048).
|
|
14
|
+
*
|
|
15
|
+
* `file` is no better a source: measured over two books, it was `cleanUrl(id)` on
|
|
16
|
+
* every one of 1360 calls and a resolved path on none, so it differs from the id
|
|
17
|
+
* only in having the query stripped. It is read first because when the two ever do
|
|
18
|
+
* disagree Vite means `file`, not because being set makes it a path.
|
|
19
|
+
*
|
|
20
|
+
* So an absolute-looking candidate is accepted only if it names something — one
|
|
21
|
+
* `existsSync` against evaluating a module, and it is the question the old
|
|
22
|
+
* predicate meant to ask. `root` is the Vite root and not `process.cwd()`: they
|
|
23
|
+
* coincide only when the consumer runs poveste from the directory Vite is rooted
|
|
24
|
+
* at, and this branch is taken on most modules in a book.
|
|
25
|
+
*
|
|
26
|
+
* Vite's `/@fs/` ids — its escape hatch for a file outside the root — never reach
|
|
27
|
+
* here: `normalizeModuleId` strips the prefix server-side, so such a module arrives
|
|
28
|
+
* as a plain absolute path and is found by the first `existsSync`. Measured, not
|
|
29
|
+
* assumed: 81 of the Quasar book's modules resolve outside its root, all through
|
|
30
|
+
* that branch, and no id or file in either book carried the prefix.
|
|
31
|
+
*/
|
|
32
|
+
export declare function filenameOf(module: Readonly<EvaluatedModuleNode>, root: string): string;
|
|
33
|
+
/** A runner over a module server, reached through `invoke`. `root` is the Vite root. */
|
|
34
|
+
export declare function createRunner(invoke: Invoke, root: string, evaluatedModules?: EvaluatedModules): ModuleRunner;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import { createRequire } from 'node:module';
|
|
2
3
|
import { dirname, isAbsolute, join } from 'node:path';
|
|
3
4
|
import process from 'node:process';
|
|
@@ -19,18 +20,70 @@ function exportAll(exports, source) {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The file a CJS module should believe it is, for `require`, `__filename` and
|
|
25
|
+
* `__dirname`.
|
|
26
|
+
*
|
|
27
|
+
* A Vite id is root-relative, so `/node_modules/vue/index.js` is an id and not a
|
|
28
|
+
* path that exists. `isAbsolute()` answers "does this start with a separator",
|
|
29
|
+
* which that satisfies, so an id used to become a `filename` and the module's own
|
|
30
|
+
* `require('./dist/…')` resolved against a directory under the filesystem root.
|
|
31
|
+
* Quasar's config pulls `vue` through here, and a Quasar book could not collect a
|
|
32
|
+
* story at all (#1048).
|
|
33
|
+
*
|
|
34
|
+
* `file` is no better a source: measured over two books, it was `cleanUrl(id)` on
|
|
35
|
+
* every one of 1360 calls and a resolved path on none, so it differs from the id
|
|
36
|
+
* only in having the query stripped. It is read first because when the two ever do
|
|
37
|
+
* disagree Vite means `file`, not because being set makes it a path.
|
|
38
|
+
*
|
|
39
|
+
* So an absolute-looking candidate is accepted only if it names something — one
|
|
40
|
+
* `existsSync` against evaluating a module, and it is the question the old
|
|
41
|
+
* predicate meant to ask. `root` is the Vite root and not `process.cwd()`: they
|
|
42
|
+
* coincide only when the consumer runs poveste from the directory Vite is rooted
|
|
43
|
+
* at, and this branch is taken on most modules in a book.
|
|
44
|
+
*
|
|
45
|
+
* Vite's `/@fs/` ids — its escape hatch for a file outside the root — never reach
|
|
46
|
+
* here: `normalizeModuleId` strips the prefix server-side, so such a module arrives
|
|
47
|
+
* as a plain absolute path and is found by the first `existsSync`. Measured, not
|
|
48
|
+
* assumed: 81 of the Quasar book's modules resolve outside its root, all through
|
|
49
|
+
* that branch, and no id or file in either book carried the prefix.
|
|
50
|
+
*/
|
|
51
|
+
export function filenameOf(module, root) {
|
|
52
|
+
for (const candidate of [module.file, module.id]) {
|
|
53
|
+
if (candidate === undefined || candidate === null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const path = candidate.replace(/[?#].*$/, '');
|
|
57
|
+
if (!isAbsolute(path)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (existsSync(path)) {
|
|
61
|
+
return path;
|
|
62
|
+
}
|
|
63
|
+
const rooted = join(root, path);
|
|
64
|
+
if (existsSync(rooted)) {
|
|
65
|
+
return rooted;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return join(root, 'virtual-module');
|
|
69
|
+
}
|
|
22
70
|
/** As vite-node did: a CJS package's named exports are read through its default. */
|
|
23
71
|
class InteropEvaluator {
|
|
72
|
+
root;
|
|
24
73
|
// The runner offsets source maps by the lines a wrapper adds, which match Vite's own.
|
|
25
74
|
startOffset = new ESModulesEvaluator().startOffset;
|
|
75
|
+
constructor(root) {
|
|
76
|
+
this.root = root;
|
|
77
|
+
}
|
|
26
78
|
/**
|
|
27
79
|
* Vite's own evaluator passes only import bindings, so a CJS dependency inlined
|
|
28
80
|
* through `viteNodeInlineDeps` threw `exports is not defined` (#167).
|
|
29
81
|
*/
|
|
30
82
|
async runInlinedModule(context, code, module) {
|
|
31
83
|
const exports = context[ssrModuleExportsKey];
|
|
84
|
+
// Identity, not a location: only `.mjs` is read off it, below.
|
|
32
85
|
const path = (module.file || module.id).replace(/[?#].*$/, '');
|
|
33
|
-
const filename =
|
|
86
|
+
const filename = filenameOf(module, this.root);
|
|
34
87
|
let assignedExports;
|
|
35
88
|
let assigned = false;
|
|
36
89
|
const cjsExports = new Proxy(exports, {
|
|
@@ -99,8 +152,8 @@ const env = new Proxy(process.env, {
|
|
|
99
152
|
? undefined
|
|
100
153
|
: ['DEV', 'PROD', 'SSR'].includes(key) ? !!target[key] : target[key],
|
|
101
154
|
});
|
|
102
|
-
/** A runner over a module server, reached through `invoke`. */
|
|
103
|
-
export function createRunner(invoke, evaluatedModules = new EvaluatedModules()) {
|
|
155
|
+
/** A runner over a module server, reached through `invoke`. `root` is the Vite root. */
|
|
156
|
+
export function createRunner(invoke, root, evaluatedModules = new EvaluatedModules()) {
|
|
104
157
|
return new ModuleRunner({
|
|
105
158
|
transport: {
|
|
106
159
|
async invoke(message) {
|
|
@@ -116,5 +169,5 @@ export function createRunner(invoke, evaluatedModules = new EvaluatedModules())
|
|
|
116
169
|
sourcemapInterceptor: false,
|
|
117
170
|
evaluatedModules,
|
|
118
171
|
createImportMeta: modulePath => ({ ...createDefaultImportMeta(modulePath), env }),
|
|
119
|
-
}, new InteropEvaluator());
|
|
172
|
+
}, new InteropEvaluator(root));
|
|
120
173
|
}
|
|
@@ -59,7 +59,9 @@ async function collect(payload) {
|
|
|
59
59
|
;
|
|
60
60
|
globalThis[key] = value;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
// Memoised for the worker's life though `root` arrives per task: a worker pool
|
|
63
|
+
// belongs to one server, so every task it is sent carries that server's root.
|
|
64
|
+
const runner = _runner ?? (_runner = createRunner((name, data) => _invoke(name, data), payload.root, _evaluatedModules));
|
|
63
65
|
if (_domEnv) {
|
|
64
66
|
resetDomEnv(_domEnv);
|
|
65
67
|
}
|
package/dist/node/dom/env.js
CHANGED
|
@@ -62,6 +62,30 @@ export function createDomEnv() {
|
|
|
62
62
|
unobserve(_target) { }
|
|
63
63
|
takeRecords() { return []; }
|
|
64
64
|
};
|
|
65
|
+
/*
|
|
66
|
+
* jsdom implements `Screen` — seven properties, no `orientation` — and has no
|
|
67
|
+
* `ScreenOrientation` constructor at all, so the property is absent rather than
|
|
68
|
+
* present and inert. There is nothing to feature-detect but the absence, and
|
|
69
|
+
* nothing to assign through: the property has no setter, so this defines it
|
|
70
|
+
* rather than using the `||` the three above can.
|
|
71
|
+
*
|
|
72
|
+
* Quasar's Screen plugin reads it unguarded while installing — `const { type,
|
|
73
|
+
* angle } = window.screen.orientation` — so a Quasar book cannot collect a
|
|
74
|
+
* story without it (#1053). Quasar 2.34 added that read; 2.33 had none.
|
|
75
|
+
*/
|
|
76
|
+
if (window.screen !== undefined && window.screen.orientation === undefined) {
|
|
77
|
+
Object.defineProperty(window.screen, 'orientation', {
|
|
78
|
+
configurable: true,
|
|
79
|
+
value: {
|
|
80
|
+
type: 'landscape-primary',
|
|
81
|
+
angle: 0,
|
|
82
|
+
onchange: null,
|
|
83
|
+
addEventListener: () => { },
|
|
84
|
+
removeEventListener: () => { },
|
|
85
|
+
dispatchEvent: () => false,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
65
89
|
window.matchMedia = window.matchMedia || ((query) => ({
|
|
66
90
|
matches: false,
|
|
67
91
|
media: query,
|
package/dist/node/load.js
CHANGED
|
@@ -6,7 +6,7 @@ let _load;
|
|
|
6
6
|
export function useModuleLoader(options) {
|
|
7
7
|
const { server } = options;
|
|
8
8
|
const node = createModuleServer(server, { inline: [] });
|
|
9
|
-
const runner = createRunner((name, data) => node.invoke(name, data));
|
|
9
|
+
const runner = createRunner((name, data) => node.invoke(name, data), server.config.root);
|
|
10
10
|
function clearCache() {
|
|
11
11
|
server.moduleGraph.invalidateAll();
|
|
12
12
|
node.clearCache();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "poveste",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.1",
|
|
5
5
|
"description": "Interactive component playgrounds for Vue, Nuxt, Svelte, SvelteKit and Quasar — a drop-in fork of histoire, with Quasar support histoire does not ship.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sorin Gitlan",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@11ty/gray-matter": "^3.0.0",
|
|
77
|
-
"@poveste/app": "^0.16.
|
|
78
|
-
"@poveste/controls": "^0.16.
|
|
79
|
-
"@poveste/shared": "^0.16.
|
|
80
|
-
"@poveste/vendors": "^0.16.
|
|
77
|
+
"@poveste/app": "^0.16.1",
|
|
78
|
+
"@poveste/controls": "^0.16.1",
|
|
79
|
+
"@poveste/shared": "^0.16.1",
|
|
80
|
+
"@poveste/vendors": "^0.16.1",
|
|
81
81
|
"change-case": "^5.4.4",
|
|
82
82
|
"chokidar": "^5.0.0",
|
|
83
83
|
"defu": "^6.1.4",
|