@pygmalionjs/pygmalion 0.2.14 → 0.2.15
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 +12 -0
- package/node/design-session.mjs +15 -1
- package/node/dev-mirror.mjs +23 -0
- package/node/vite.mjs +2 -0
- package/package.json +1 -1
- package/vite.d.ts +9 -0
package/README.md
CHANGED
|
@@ -86,6 +86,18 @@ When the mirror preview reloads the host Vite configuration,
|
|
|
86
86
|
`PYGMALION_PREVIEW_MODE=1` prevents the integration plugins from starting
|
|
87
87
|
recursively.
|
|
88
88
|
|
|
89
|
+
Mirror and session previews run as their own Vite processes, so the mode you
|
|
90
|
+
pass to the editor does not reach them. Set `preview.mode` when a screen only
|
|
91
|
+
exists under a specific env file — a feature flag that has to be off, a mock
|
|
92
|
+
profile a recipe depends on:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
export default definePygmalionProject({
|
|
96
|
+
// ...
|
|
97
|
+
preview: { mode: "e2e" },
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
89
101
|
## Register screens and scenarios
|
|
90
102
|
|
|
91
103
|
The host owns application-specific routes, fixtures, authentication, mock data,
|
package/node/design-session.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import os from 'node:os';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { promisify } from 'node:util';
|
|
10
|
+
import { normalizeViteMode } from './dev-mirror.mjs';
|
|
10
11
|
import { writeStyleEdit, writeTextEdit } from './inspect-plugin.mjs';
|
|
11
12
|
import { createUnifiedDiff } from './source-diff.mjs';
|
|
12
13
|
import { writeSourceOperations } from './source-operations.mjs';
|
|
@@ -289,6 +290,9 @@ export function pygmalionDesignSessionPlugin(options) {
|
|
|
289
290
|
options.previewConfig ?? fileURLToPath(new URL('./dev-view.vite.mjs', import.meta.url)),
|
|
290
291
|
);
|
|
291
292
|
const viteConfig = path.resolve(options.viteConfig ?? path.join(mirrorAppRoot, 'vite.config.ts'));
|
|
293
|
+
// Session previews are separate Vite processes too, so they need the same
|
|
294
|
+
// host-declared mode as the mirror or a session would render a different app.
|
|
295
|
+
const previewMode = normalizeViteMode(options.previewMode);
|
|
292
296
|
const sourceDirectory = (options.sourceDirectory ?? 'src').replace(/^\.?\//, '').replace(/\/$/, '') || '.';
|
|
293
297
|
const dependencies = options.dependencies ?? {};
|
|
294
298
|
const inspect = options.inspect ?? {};
|
|
@@ -503,7 +507,17 @@ export function pygmalionDesignSessionPlugin(options) {
|
|
|
503
507
|
|
|
504
508
|
const child = spawn(
|
|
505
509
|
process.execPath,
|
|
506
|
-
[
|
|
510
|
+
[
|
|
511
|
+
viteBin,
|
|
512
|
+
'--config',
|
|
513
|
+
wrapperConfig,
|
|
514
|
+
...(previewMode ? ['--mode', previewMode] : []),
|
|
515
|
+
'--host',
|
|
516
|
+
'127.0.0.1',
|
|
517
|
+
'--port',
|
|
518
|
+
String(port),
|
|
519
|
+
'--strictPort',
|
|
520
|
+
],
|
|
507
521
|
{
|
|
508
522
|
cwd: sessionAppRoot,
|
|
509
523
|
env: {
|
package/node/dev-mirror.mjs
CHANGED
|
@@ -122,6 +122,24 @@ function normalizeLocalSourceRef(value) {
|
|
|
122
122
|
return value.trim();
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* The mode becomes an argv entry for the spawned preview Vite, so it is
|
|
127
|
+
* restricted to the identifier shape Vite mode names actually use. Anything
|
|
128
|
+
* else could smuggle a second flag into that command line.
|
|
129
|
+
*/
|
|
130
|
+
export function normalizeViteMode(value) {
|
|
131
|
+
if (value == null) return null;
|
|
132
|
+
if (typeof value !== 'string' || !/^[A-Za-z0-9._-]+$/.test(value)) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
'Pygmalion preview.mode must be a Vite mode name ([A-Za-z0-9._-]+)',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (value.startsWith('-')) {
|
|
138
|
+
throw new Error('Pygmalion preview.mode must not start with "-"');
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
|
|
125
143
|
function normalizeManagedOutputPaths(value) {
|
|
126
144
|
if (value == null) return [];
|
|
127
145
|
if (!Array.isArray(value)) {
|
|
@@ -278,6 +296,10 @@ export function pygmalionDevMirrorPlugin(options) {
|
|
|
278
296
|
options.previewConfig ?? fileURLToPath(new URL('./dev-view.vite.mjs', import.meta.url)),
|
|
279
297
|
);
|
|
280
298
|
const viteConfig = path.resolve(options.viteConfig ?? path.join(mirrorAppRoot, 'vite.config.ts'));
|
|
299
|
+
// The mirror is a separate Vite process, so the editor's own `--mode` never
|
|
300
|
+
// reaches it. Hosts whose captured screens need a specific env file (a feature
|
|
301
|
+
// flag a screen depends on, a mock profile) declare that mode here.
|
|
302
|
+
const previewMode = normalizeViteMode(options.previewMode);
|
|
281
303
|
const inventory = options.inventory;
|
|
282
304
|
const inventoryOutputs = normalizeManagedOutputPaths(inventory?.outputs);
|
|
283
305
|
const managedPaths = normalizeManagedOutputPaths(
|
|
@@ -450,6 +472,7 @@ export function pygmalionDevMirrorPlugin(options) {
|
|
|
450
472
|
viteBin,
|
|
451
473
|
'--config',
|
|
452
474
|
wrapperConfig,
|
|
475
|
+
...(previewMode ? ['--mode', previewMode] : []),
|
|
453
476
|
'--host',
|
|
454
477
|
'127.0.0.1',
|
|
455
478
|
'--port',
|
package/node/vite.mjs
CHANGED
|
@@ -267,6 +267,7 @@ export function createPygmalionVitePlugins(config) {
|
|
|
267
267
|
previewConfig: project.preview.configFile,
|
|
268
268
|
viteConfig: project.preview.viteConfig,
|
|
269
269
|
viteBin: project.preview.viteBin,
|
|
270
|
+
previewMode: project.preview.mode,
|
|
270
271
|
previewPort: project.mirror.previewPort ?? project.preview.mirrorPort,
|
|
271
272
|
prefix: normalizeEndpoint(
|
|
272
273
|
project.mirror.prefix,
|
|
@@ -298,6 +299,7 @@ export function createPygmalionVitePlugins(config) {
|
|
|
298
299
|
previewConfig: project.preview.configFile,
|
|
299
300
|
viteConfig: project.preview.viteConfig,
|
|
300
301
|
viteBin: project.preview.viteBin,
|
|
302
|
+
previewMode: project.preview.mode,
|
|
301
303
|
previewPort:
|
|
302
304
|
project.sessions.previewPort ?? project.preview.sessionPort,
|
|
303
305
|
worktreesRoot: project.sessions.worktreesRoot,
|
package/package.json
CHANGED
package/vite.d.ts
CHANGED
|
@@ -60,6 +60,15 @@ export interface PygmalionPreviewConfig {
|
|
|
60
60
|
configFile?: string;
|
|
61
61
|
viteConfig?: string;
|
|
62
62
|
viteBin?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Vite mode for the mirror and session preview servers.
|
|
65
|
+
*
|
|
66
|
+
* Those run as separate Vite processes, so the editor's own `--mode` never
|
|
67
|
+
* reaches the previewed application. Set this when a captured screen depends
|
|
68
|
+
* on a specific env file — for example a feature flag that has to be off for
|
|
69
|
+
* the screen to exist at all. Defaults to Vite's own default mode.
|
|
70
|
+
*/
|
|
71
|
+
mode?: string;
|
|
63
72
|
mirrorPort?: number;
|
|
64
73
|
sessionPort?: number;
|
|
65
74
|
artifactFile?: string;
|