@gxp-dev/tools 2.0.93 → 2.1.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.
@@ -7,9 +7,17 @@
7
7
 
8
8
  const path = require("path")
9
9
  const fs = require("fs")
10
- const { spawn } = require("child_process")
10
+ const childProcess = require("child_process")
11
11
  const shell = require("shelljs")
12
12
  const dotenv = require("dotenv")
13
+
14
+ // Module-private spawn reference so tests can swap in a stub via
15
+ // `setSpawnForTesting`. Production code paths still call the real
16
+ // `child_process.spawn` because the default closes over it.
17
+ let _spawn = childProcess.spawn
18
+ function setSpawnForTesting(fn) {
19
+ _spawn = fn || childProcess.spawn
20
+ }
13
21
  const {
14
22
  findProjectRoot,
15
23
  resolveGxPaths,
@@ -53,7 +61,7 @@ function createLogger(jsonMode) {
53
61
  * Returns the child process.
54
62
  */
55
63
  function spawnService(name, command, logger) {
56
- const child = spawn(command, {
64
+ const child = _spawn(command, {
57
65
  shell: true,
58
66
  stdio: ["ignore", "pipe", "pipe"],
59
67
  env: process.env,
@@ -289,8 +297,9 @@ function devCommand(argv) {
289
297
  logger.info("🎭 Mock API will be enabled")
290
298
  }
291
299
 
292
- // Socket server starts by default unless --no-socket is passed
293
- const noSocket = argv["no-socket"]
300
+ // Socket server starts by default unless --no-socket is passed. See
301
+ // shouldDisableSocket() for the yargs-negation quirk it papers over.
302
+ const noSocket = shouldDisableSocket(argv)
294
303
  let serverJsPath = ""
295
304
  if (!noSocket) {
296
305
  // Check for local server.js first, then runtime directory
@@ -340,9 +349,10 @@ function devCommand(argv) {
340
349
  if (!process.env.NODE_LOG_LEVEL) {
341
350
  process.env.NODE_LOG_LEVEL = argv["node-log-level"] || "info"
342
351
  }
343
- if (!process.env.NODE_PORT) {
344
- process.env.NODE_PORT = String(finalPort)
345
- }
352
+ // NODE_PORT is the source of truth for the socket server (server.cjs reads
353
+ // process.env). Always set it to the resolved finalPort so that a CLI
354
+ // `--port` overrides anything that dotenv loaded from .env earlier.
355
+ process.env.NODE_PORT = String(finalPort)
346
356
  if (!process.env.COMPONENT_PATH) {
347
357
  process.env.COMPONENT_PATH = argv["component-path"] || "./src/Plugin.vue"
348
358
  }
@@ -401,12 +411,15 @@ function devCommand(argv) {
401
411
  // Normalize path separators to forward slashes for cross-platform shell compatibility
402
412
  const normalizedViteConfigPath = viteConfigPath.replace(/\\/g, "/")
403
413
 
404
- // Build the canonical service list (raw commands, no concurrently wrapping)
414
+ // Build the canonical service list (raw commands, no concurrently wrapping).
415
+ // Pass --port to vite directly: vite's loadEnv() only reads .env files —
416
+ // it does NOT inherit from process.env — so setting NODE_PORT above isn't
417
+ // enough on its own. The CLI flag wins over the config every time.
405
418
  const services = []
406
419
  services.push({
407
420
  name: "VITE",
408
421
  color: "cyan",
409
- command: `npx vite dev --config "${normalizedViteConfigPath}"`,
422
+ command: `npx vite dev --config "${normalizedViteConfigPath}" --port ${finalPort}`,
410
423
  })
411
424
 
412
425
  if (serverJsPath) {
@@ -455,6 +468,23 @@ function devCommand(argv) {
455
468
  shell.exec(command)
456
469
  }
457
470
 
471
+ /**
472
+ * Pure helper exposed for unit testing the `--no-socket` flag-parsing fix.
473
+ * yargs interprets `--no-socket` from the CLI as `argv.socket = false`
474
+ * (boolean negation), NOT as `argv["no-socket"] = true`. We accept either
475
+ * form so the flag behaves the way the help text advertises.
476
+ */
477
+ function shouldDisableSocket(argv) {
478
+ return argv["no-socket"] === true || argv.socket === false
479
+ }
480
+
458
481
  module.exports = {
459
482
  devCommand,
483
+ // Exposed for unit testing. These are pure-ish helpers that drive the
484
+ // NDJSON logger and child-process orchestration used by `gxdev dev`.
485
+ createLogger,
486
+ spawnService,
487
+ runServicesJson,
488
+ shouldDisableSocket,
489
+ setSpawnForTesting,
460
490
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gxp-dev/tools",
3
- "version": "2.0.93",
3
+ "version": "2.1.0",
4
4
  "description": "Dev tools to create platform plugins",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {
@@ -20,8 +20,10 @@
20
20
  "scripts": {
21
21
  "prepare": "git config core.hooksPath .githooks || true",
22
22
  "test": "vitest run",
23
+ "test:run": "vitest run",
23
24
  "test:watch": "vitest",
24
25
  "test:coverage": "vitest run --coverage",
26
+ "test:e2e": "RUN_CLI_E2E=1 vitest run --config vitest.e2e.config.js",
25
27
  "dev": "concurrently 'vite dev' 'nodemon config/server.js'",
26
28
  "dev-app": "vite dev",
27
29
  "ext:firefox": "web-ext run --source-dir browser-extensions/firefox",
@@ -123,16 +123,28 @@ function hasLocalFile(fileName) {
123
123
  /**
124
124
  * Try to load the `@tailwindcss/vite` plugin from the project's node_modules.
125
125
  *
126
- * Tailwind 4 ships as a dev-only base CSS framework — `tailwindcss` and
127
- * `@tailwindcss/vite` are declared in the project's devDependencies and
128
- * imported via `@import "tailwindcss";` inside the theme-layouts (which are
129
- * dev-only; the production build entry is `src/Plugin.vue`). Loading the
130
- * Vite plugin here lets that import generate utility CSS without each
131
- * project having to wire it up in `vite.extend.js`. If the user has removed
132
- * Tailwind we silently skip the layouts work without it, just without
133
- * Tailwind's default styling.
126
+ * Tailwind 4 is a DEV-ONLY base CSS framework here declared in the project's
127
+ * devDependencies and imported via `@import "tailwindcss";` inside the
128
+ * theme-layouts. We deliberately do not run it during `vite build`:
129
+ *
130
+ * 1. The layouts aren't part of the production build (entry is
131
+ * `src/Plugin.vue`), so there's no `@import "tailwindcss"` reaching the
132
+ * build graph and the generated utilities would have nowhere to live.
133
+ * 2. The plugin scans the whole project (including `node_modules`) for
134
+ * candidate class names. `@gxp-dev/uikit` ships compiled Vue files
135
+ * containing arbitrary-value classes like
136
+ * `bg-[var(--keyboard_key_active_background_color,var(--primary))]`,
137
+ * which Tailwind 4 lowers to CSS with spaces in the var name — invalid
138
+ * CSS that breaks `lightningcss` minification at build time.
139
+ *
140
+ * In dev (`command === "serve"`) we load it; in build we skip and let the
141
+ * platform supply Tailwind at runtime (per `app-manifest.json.baseFramework`).
142
+ * Silently no-ops if the user has uninstalled Tailwind.
134
143
  */
135
- async function loadTailwindPlugin() {
144
+ async function loadTailwindPlugin(command) {
145
+ if (command !== "serve") {
146
+ return null
147
+ }
136
148
  try {
137
149
  const mod = await import("@tailwindcss/vite")
138
150
  const plugin = mod.default ?? mod
@@ -438,9 +450,10 @@ export default defineConfig(async (ctx) => {
438
450
  const useHttps = getHttpsConfig(env) !== undefined
439
451
 
440
452
  // Load Tailwind 4 Vite plugin from the project's node_modules if present.
441
- const tailwindPlugin = await loadTailwindPlugin()
453
+ // Dev-only production builds skip it (see loadTailwindPlugin docs).
454
+ const tailwindPlugin = await loadTailwindPlugin(ctx.command)
442
455
  if (tailwindPlugin) {
443
- console.log("🎨 Tailwind: @tailwindcss/vite plugin loaded")
456
+ console.log("🎨 Tailwind: @tailwindcss/vite plugin loaded (dev)")
444
457
  }
445
458
 
446
459
  // Get API proxy target for non-mock environments