@pacaf/wizard-ux 2.0.0 → 3.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pacaf/wizard-ux",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Browser-based setup wizard for Power Apps Code Apps (parallel to @pacaf/wizard CLI).",
@@ -34,6 +34,7 @@
34
34
  "@fastify/websocket": "^10.0.1",
35
35
  "@fluentui/react-components": "^9.56.0",
36
36
  "@fluentui/react-icons": "^2.0.260",
37
+ "@pacaf/wizard": "workspace:*",
37
38
  "@tanstack/react-query": "^5.62.0",
38
39
  "@xterm/addon-fit": "^0.10.0",
39
40
  "@xterm/addon-web-links": "^0.11.0",
package/server/index.mjs CHANGED
@@ -7,7 +7,6 @@ import { resolve, dirname, join } from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import { randomBytes } from 'node:crypto';
9
9
  import { spawn } from 'node:child_process';
10
- import { createServer as createViteServer } from 'vite';
11
10
 
12
11
  import stateRoutes from './routes/state.mjs';
13
12
  import systemRoutes from './routes/system.mjs';
@@ -22,7 +21,9 @@ const ROOT_DIR = resolve(UX_DIR, '..');
22
21
 
23
22
  const HOST = '127.0.0.1';
24
23
  const PORT = Number(process.env.WIZARD_UX_PORT || 5174);
25
- const IS_PROD = process.env.NODE_ENV === 'production';
24
+ // When installed as a published package, dist/ is always shipped and vite is
25
+ // not a runtime dep. Only treat this as "dev mode" when the caller opts in.
26
+ const IS_DEV = process.env.NODE_ENV === 'development' || process.env.WIZARD_UX_DEV === '1';
26
27
 
27
28
  const CSRF_TOKEN = randomBytes(24).toString('hex');
28
29
 
@@ -36,7 +37,7 @@ await app.register(cors, {
36
37
  // Otherwise only accept the well-known localhost origins.
37
38
  if (!origin) return cb(null, true);
38
39
  if (origin === `http://${HOST}:${PORT}` || origin === `http://localhost:${PORT}`) return cb(null, true);
39
- if (!IS_PROD && (origin === `http://${HOST}:5175` || origin === 'http://localhost:5175')) return cb(null, true);
40
+ if (IS_DEV && (origin === `http://${HOST}:5175` || origin === 'http://localhost:5175')) return cb(null, true);
40
41
  cb(new Error('Origin not allowed'), false);
41
42
  },
42
43
  credentials: true,
@@ -75,21 +76,26 @@ await app.register(streamRoutes, { prefix: '/api/steps', rootDir: ROOT_DIR });
75
76
  await app.register(ptyRoutes, { rootDir: ROOT_DIR, csrfToken: CSRF_TOKEN });
76
77
  await app.register(onepasswordRoutes, { prefix: '/api/1password' });
77
78
 
78
- // Serve the UI — Vite middleware in dev, static dist/ in prod
79
- if (IS_PROD) {
80
- const distDir = join(UX_DIR, 'dist');
81
- if (existsSync(distDir)) {
82
- const fastifyStatic = (await import('@fastify/static')).default;
83
- await app.register(fastifyStatic, { root: distDir, prefix: '/' });
84
- app.setNotFoundHandler((req, reply) => {
85
- if (req.url.startsWith('/api/')) return reply.code(404).send({ error: 'Not found' });
86
- // SPA fallback
87
- reply.sendFile('index.html');
88
- });
89
- } else {
90
- app.log.warn('Production build not found in dist/. Run `npm run build` inside wizard-ux.');
79
+ // Serve the UI — prebuilt dist/ by default; vite middleware only in dev mode
80
+ const distDir = join(UX_DIR, 'dist');
81
+ const haveDist = existsSync(distDir);
82
+
83
+ if (!IS_DEV && haveDist) {
84
+ const fastifyStatic = (await import('@fastify/static')).default;
85
+ await app.register(fastifyStatic, { root: distDir, prefix: '/' });
86
+ app.setNotFoundHandler((req, reply) => {
87
+ if (req.url.startsWith('/api/')) return reply.code(404).send({ error: 'Not found' });
88
+ // SPA fallback
89
+ reply.sendFile('index.html');
90
+ });
91
+ } else if (IS_DEV) {
92
+ let createViteServer;
93
+ try {
94
+ ({ createServer: createViteServer } = await import('vite'));
95
+ } catch (err) {
96
+ app.log.error('Dev mode requested (NODE_ENV=development or WIZARD_UX_DEV=1) but `vite` is not installed. Install it as a devDependency or run without WIZARD_UX_DEV.');
97
+ throw err;
91
98
  }
92
- } else {
93
99
  const vite = await createViteServer({
94
100
  root: UX_DIR,
95
101
  server: { middlewareMode: true, hmr: { port: 5176 } },
@@ -113,6 +119,9 @@ if (IS_PROD) {
113
119
  reply.code(500).send(String(e));
114
120
  }
115
121
  });
122
+ } else {
123
+ app.log.error(`No prebuilt UI found at ${distDir} and dev mode is not enabled. Reinstall @pacaf/wizard-ux or set WIZARD_UX_DEV=1.`);
124
+ throw new Error('wizard-ux/dist missing');
116
125
  }
117
126
 
118
127
  await app.listen({ host: HOST, port: PORT });
@@ -3,7 +3,7 @@ import { execSync, execFileSync } from 'node:child_process';
3
3
  import { existsSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { homedir, platform, release } from 'node:os';
6
- import { pacPath as resolvePacPath, runSafe } from '../../../wizard/lib/shell.mjs';
6
+ import { pacPath as resolvePacPath, runSafe } from '@pacaf/wizard/lib/shell.mjs';
7
7
 
8
8
  function safeRun(cmd) {
9
9
  try { return execSync(cmd, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim(); }
@@ -1,7 +1,7 @@
1
1
  // Step 1 — Prerequisites. Read-only checks, no questions.
2
2
  import { platform } from 'node:os';
3
3
  import { execFileSync, execSync } from 'node:child_process';
4
- import { pacPath, runSafe } from '../../../wizard/lib/shell.mjs';
4
+ import { pacPath, runSafe } from '@pacaf/wizard/lib/shell.mjs';
5
5
 
6
6
  function hasCommand(name) {
7
7
  try {