@geastack/cli 0.1.78 → 0.1.80

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/docs/SETUP.md CHANGED
@@ -14,7 +14,7 @@ npx gea doctor
14
14
  ## Minimum Setup
15
15
 
16
16
  ```sh
17
- npx @geastack/create-geastack my-app
17
+ npx create-geastack my-app
18
18
  cd my-app
19
19
  npx gea setup
20
20
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.78",
3
+ "version": "0.1.80",
4
4
  "description": "Command-line front door for GeaStack apps, targets, and local toolchains.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,13 +37,14 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@clack/prompts": "^1.8.0",
40
- "@geastack/simulator": "^0.1.2",
40
+ "@geastack/simulator": "^0.1.6",
41
41
  "picocolors": "^1.1.1",
42
42
  "serialport": "^13.0.0"
43
43
  },
44
44
  "starterDependencies": {
45
- "@geastack/core": "^0.1.12",
46
- "@geastack/targets": "^0.1.60"
45
+ "@geastack/core": "^0.1.23",
46
+ "@geastack/targets": "^0.1.77",
47
+ "@geastack/apple": "^0.2.9"
47
48
  },
48
49
  "scripts": {
49
50
  "check": "node --check bin/gea.mjs && node --check bin/create-geastack.mjs && find src test packages -name '*.mjs' -print0 | xargs -0 -n1 node --check",
@@ -348,7 +348,8 @@ function packageJson({ appId, displayName, targets, entry, coreDependency, cliDe
348
348
  '@geastack/core': coreDependency,
349
349
  '@geastack/cli': cliDependency,
350
350
  ...(needsTargetsPackage(targets) ? { '@geastack/targets': sourcePackage.dependencies?.['@geastack/targets'] || targetsDependencyDefault } : {}),
351
- ...(targets.windows ? { '@geastack/windows': sourcePackage.dependencies?.['@geastack/windows'] || windowsDependencyDefault } : {})
351
+ ...(targets.windows ? { '@geastack/windows': sourcePackage.dependencies?.['@geastack/windows'] || windowsDependencyDefault } : {}),
352
+ ...(targets.macos || targets.ios ? { '@geastack/apple': sourcePackage.dependencies?.['@geastack/apple'] || appleDependencyDefault } : {})
352
353
  },
353
354
  devDependencies: {
354
355
  ...(sourcePackage.devDependencies || {}),
@@ -370,6 +371,11 @@ function needsTargetsPackage(targets) {
370
371
  // own dependencies by `gea build --target windows`.
371
372
  const windowsDependencyDefault = '^0.1.0'
372
373
 
374
+ // The macOS and iOS targets ship inside @geastack/apple, resolved the same way
375
+ // by `gea build --target macos` and `gea build --target ios`. An app that
376
+ // declares either target without the package has nothing to build with.
377
+ const appleDependencyDefault = starterDependencies['@geastack/apple'] || '^0.2.9'
378
+
373
379
  function indexTsx(displayName) {
374
380
  return `import { ReactiveComponent, mount } from '@geastack/core'
375
381
  import './styles.css'
@@ -509,7 +515,11 @@ npx gea flash --monitor`
509
515
  ? `npx gea setup
510
516
  npx gea build --target windows
511
517
  npx gea run --target windows`
512
- : `npx gea setup
518
+ : targets.ios && !targets.macos
519
+ ? `npx gea setup
520
+ npx gea build --target ios
521
+ npx gea run --target ios`
522
+ : `npx gea setup
513
523
  npx gea build`
514
524
  return `# ${displayName}
515
525
 
@@ -0,0 +1,22 @@
1
+ // PATH is spelled `Path` in a Windows environment. process.env answers
2
+ // `env.PATH` regardless because Node makes it case-insensitive there, but a
3
+ // plain object copied from it (`{ ...process.env, GEA_X: ... }`, which is how
4
+ // every child environment in this CLI is built) keeps the original key only,
5
+ // and `env.PATH` on that copy is undefined. Writing `PATH` next to `Path`
6
+ // then leaves two keys, and the child process picks one of them: on Windows
7
+ // it took the freshly written one, which held only the ESP-IDF tool dirs, so
8
+ // cmake could not find node or git and no ESP32 target could configure.
9
+ // Every read and write of PATH goes through here so there is only ever one
10
+ // key, whatever it is called.
11
+ export function envPathKey(env = process.env) {
12
+ if (Object.prototype.hasOwnProperty.call(env, 'PATH')) return 'PATH'
13
+ return Object.keys(env).find((key) => key.toUpperCase() === 'PATH') || 'PATH'
14
+ }
15
+
16
+ export function envPath(env = process.env) {
17
+ return String(env[envPathKey(env)] || '')
18
+ }
19
+
20
+ export function withEnvPath(env, value) {
21
+ return { ...env, [envPathKey(env)]: value }
22
+ }
@@ -14,6 +14,7 @@ import { listAppSources } from './source-set.mjs'
14
14
  import { writeFlashPlan } from './partitions.mjs'
15
15
  import { generateWifiConfig } from './wifi-config.mjs'
16
16
  import { hint, warn } from '../report.mjs'
17
+ import { envPath } from '../env-path.mjs'
17
18
 
18
19
  // The ESP-IDF build. Everything the old bash board script decided about a
19
20
  // build lives here: where the build directory is, what the app-local
@@ -80,7 +81,9 @@ export function applySdkconfigPolicy(sdkconfig, { selection, app, capabilities,
80
81
  unset('CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE')
81
82
  unset('CONFIG_PARTITION_TABLE_TWO_OTA')
82
83
  set('CONFIG_PARTITION_TABLE_CUSTOM', 'y')
83
- set('CONFIG_PARTITION_TABLE_CUSTOM_FILENAME', `"${partitionCsv}"`)
84
+ // sdkconfig is read by Kconfig and CMake, both of which treat a backslash
85
+ // as an escape; a Windows path loses every separator on the way through.
86
+ set('CONFIG_PARTITION_TABLE_CUSTOM_FILENAME', `"${cmakeValue(partitionCsv)}"`)
84
87
  }
85
88
 
86
89
  // The console transport follows the board's wiring. A module reached over a
@@ -341,7 +344,7 @@ export function prepareEsp32Build({ ctx, selection, app = null, env = ctx.env ||
341
344
  catalog: loadChipCatalogFromDir(ctx.chipsPackageDir),
342
345
  appDefines: new Set((app?.defines || []).map((define) => define.split('=')[0]))
343
346
  })
344
- idfArgs.push(`-DGEA_BOARD_DEFINITION=${selection.targetDefinition}`, `-DGEA_CUSTOM_TARGET_DIR=${outDir}`)
347
+ idfArgs.push(`-DGEA_BOARD_DEFINITION=${cmakeValue(selection.targetDefinition)}`, `-DGEA_CUSTOM_TARGET_DIR=${cmakeValue(outDir)}`)
345
348
  childEnv.GEA_BOARD_DEFINITION = selection.targetDefinition
346
349
  childEnv.GEA_CUSTOM_TARGET_DIR = outDir
347
350
  boardPartitionCsv = generated.partitionCsv
@@ -438,9 +441,9 @@ function preparePartitions(app, config, buildDir, targetId) {
438
441
  // the native host functions its TSX calls.
439
442
  GEA_EMBEDDED_APP_GEATSC_PLUGINS: app.compilerPlugins.map((plugin) => path.join(app.root, plugin)).join(';')
440
443
  }
441
- idfArgs.push(`-DGEA_EMBEDDED_APP=${app.id}`, `-DGEA_EMBEDDED_APP_META=${meta}`)
444
+ idfArgs.push(`-DGEA_EMBEDDED_APP=${app.id}`, `-DGEA_EMBEDDED_APP_META=${cmakeValue(meta)}`)
442
445
  if (cssDpr) idfArgs.push(`-DGEA_EMBEDDED_CSS_DEVICE_PIXEL_RATIO=${cssDpr}`)
443
- for (const [name, value] of Object.entries(appNative)) if (value) idfArgs.push(`-D${name}=${value}`)
446
+ for (const [name, value] of Object.entries(appNative)) if (value) idfArgs.push(`-D${name}=${cmakeValue(value)}`)
444
447
  idfArgs.push(
445
448
  `-DGEA_EMBEDDED_CAPABILITY_NETWORK=${capabilities.network ? 1 : 0}`,
446
449
  `-DGEA_EMBEDDED_CAPABILITY_BLE=${capabilities.ble ? 1 : 0}`,
@@ -450,8 +453,8 @@ function preparePartitions(app, config, buildDir, targetId) {
450
453
  // CMake cache propagation; environment values stay visible there, so
451
454
  // conditional components such as bt enter the dependency graph.
452
455
  childEnv.GEA_EMBEDDED_APP = app.id
453
- childEnv.GEA_EMBEDDED_APP_META = meta
454
- for (const [name, value] of Object.entries(appNative)) if (value) childEnv[name] = value
456
+ childEnv.GEA_EMBEDDED_APP_META = cmakeValue(meta)
457
+ for (const [name, value] of Object.entries(appNative)) if (value) childEnv[name] = cmakeValue(value)
455
458
  childEnv.GEA_EMBEDDED_CAPABILITY_NETWORK = capabilities.network ? '1' : '0'
456
459
  childEnv.GEA_EMBEDDED_CAPABILITY_BLE = capabilities.ble ? '1' : '0'
457
460
  childEnv.GEA_EMBEDDED_CAPABILITY_AUDIO = capabilities.audio ? '1' : '0'
@@ -486,8 +489,18 @@ function executableNames(name, env) {
486
489
  return [name, ...extensions.map((extension) => name + extension)]
487
490
  }
488
491
 
492
+ // A path handed to CMake on its command line, or through the environment
493
+ // the component-requirements pass reads. Windows paths carry backslashes,
494
+ // and ESP-IDF re-parses the registered sources as CMake code during that
495
+ // pass, where `C:\Users` is an invalid character escape and configure
496
+ // dies. CMake accepts forward slashes on every platform, so the CLI never
497
+ // hands it a backslash.
498
+ export function cmakeValue(value, platform = process.platform) {
499
+ return platform === 'win32' ? String(value).replace(/\\/g, '/') : String(value)
500
+ }
501
+
489
502
  function commandExists(name, env) {
490
- const dirs = String(env.PATH || '').split(path.delimiter).filter(Boolean)
503
+ const dirs = envPath(env).split(path.delimiter).filter(Boolean)
491
504
  const names = executableNames(name, env)
492
505
  return dirs.some((dir) => names.some((candidate) => existsSync(path.join(dir, candidate))))
493
506
  }
@@ -511,7 +524,7 @@ export function configureArguments(prepared, env) {
511
524
  }
512
525
  args.push('-G', generator)
513
526
  }
514
- args.push('-B', prepared.buildDir, `-DSDKCONFIG=${prepared.sdkconfigFile}`, `-DSDKCONFIG_DEFAULTS=${prepared.defaultsArg || prepared.defaultsFile}`)
527
+ args.push('-B', cmakeValue(prepared.buildDir), `-DSDKCONFIG=${cmakeValue(prepared.sdkconfigFile)}`, `-DSDKCONFIG_DEFAULTS=${cmakeValue(prepared.defaultsArg || prepared.defaultsFile)}`)
515
528
  return args
516
529
  }
517
530
 
@@ -3,6 +3,8 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs'
3
3
  import os from 'node:os'
4
4
  import path from 'node:path'
5
5
 
6
+ import { envPath, withEnvPath } from '../env-path.mjs'
7
+
6
8
  // ESP-IDF activation without `source export.sh`. export.sh re-checks Python,
7
9
  // dependencies, outdated tools and shell completion on every invocation; the
8
10
  // installation itself already knows the exact tool paths (idf_tools.py
@@ -157,21 +159,24 @@ export function activateEspIdf({ env = process.env, home = os.homedir(), log = (
157
159
  activationCache.set(cacheKey, exported)
158
160
  log(`Using ESP-IDF ${espIdfVersion(idfDir)?.full || ''} at ${idfDir} (python env ${pythonEnv})`)
159
161
  }
160
- const exportedPath = (exported.PATH || '').replace(/\$PATH|%PATH%/g, env.PATH || '')
162
+ const callerPath = envPath(env)
163
+ const exportedPath = (exported.PATH || '').replace(/\$PATH|%PATH%/g, callerPath)
161
164
  return {
162
165
  idfDir,
163
166
  version: espIdfVersion(idfDir),
164
167
  pythonEnv,
165
168
  python,
166
169
  idfPy: path.join(idfDir, 'tools', 'idf.py'),
167
- env: {
168
- ...env,
169
- ...Object.fromEntries(Object.entries(exported).filter(([key]) => key !== 'PATH' && key !== 'IDF_DEACTIVATE_FILE_PATH')),
170
- IDF_PATH: idfDir,
171
- IDF_PYTHON_ENV_PATH: pythonEnv,
172
- VIRTUAL_ENV: pythonEnv,
173
- PATH: [path.join(pythonEnv, venvBin), exportedPath || env.PATH || ''].filter(Boolean).join(path.delimiter)
174
- }
170
+ env: withEnvPath(
171
+ {
172
+ ...env,
173
+ ...Object.fromEntries(Object.entries(exported).filter(([key]) => key !== 'PATH' && key !== 'IDF_DEACTIVATE_FILE_PATH')),
174
+ IDF_PATH: idfDir,
175
+ IDF_PYTHON_ENV_PATH: pythonEnv,
176
+ VIRTUAL_ENV: pythonEnv
177
+ },
178
+ [path.join(pythonEnv, venvBin), exportedPath || callerPath].filter(Boolean).join(path.delimiter)
179
+ )
175
180
  }
176
181
  }
177
182
 
package/src/gea.mjs CHANGED
@@ -95,11 +95,24 @@ export async function runGea(argv, io = {}) {
95
95
  // this host is not (a Windows-only app on a Mac, a Mac-only app on Linux)
96
96
  // has nothing to select: falling into board selection would report a
97
97
  // missing --board for an app that declares no board at all.
98
- if (command === 'build' && !target && app && !declaresBoardTarget(app) && (app.targets?.macos || app.targets?.windows)) {
99
- const desktop = ['macos', 'windows'].filter((platform) => app.targets?.[platform])
98
+ if (command === 'build' && !target && app && !declaresBoardTarget(app) && (app.targets?.macos || app.targets?.windows || app.targets?.ios)) {
99
+ const desktop = ['macos', 'windows', 'ios'].filter((platform) => app.targets?.[platform])
100
100
  fail(`'${app.id}' declares no target that builds on this host by default. Pass --target ${desktop.join(' or --target ')}.`, ExitCode.usage)
101
101
  }
102
102
  }
103
+ // iOS is the third platform driven by one script inside @geastack/apple,
104
+ // resolved like macOS from the app's own dependencies. It never has a host
105
+ // default: a bare `gea build` cannot know simulator from device, so the iOS
106
+ // build is always the documented `gea build --target ios [--mode simulator|device]`,
107
+ // and `gea run --target ios` builds, installs and launches it.
108
+ if ((command === 'build' || command === 'run') && target === 'ios') {
109
+ const app = parsed.options.app || rest[0] ? findAppById(ctx, String(parsed.options.app || rest[0])) : findCurrentApp(cwd)
110
+ if (!app?.targets?.ios) {
111
+ fail(app ? `'${app.id}' does not declare gea.targets.ios.` : 'No app selected. Pass --app <id> or run inside a Gea app folder.', ExitCode.usage)
112
+ }
113
+ const { runIos } = await import('./ios/adapter.mjs')
114
+ return runIos({ app, env, dryRun: flag(parsed, 'dry-run'), stdout, mode: option(parsed, 'mode', ''), run: command === 'run' })
115
+ }
103
116
  // `web` names two targets, and both are driven by gea, so it leaves the
104
117
  // refusal below the way macos does above. `gea simulate` is the WASM device
105
118
  // simulator; `gea {dev,build} --target web` is a real DOM/CSS web app. A bare
@@ -217,6 +230,12 @@ ${heading('Run on this machine (no board needed):')}
217
230
  gea dev [app] [--port N] real DOM + CSS dev server with HMR (same as --target web)
218
231
  gea build --target web [app] [--out-dir d] build the app as a real web app
219
232
 
233
+ ${heading('Native desktop and mobile apps (scripts ship in @geastack/apple and @geastack/windows):')}
234
+ gea build --target macos [app] build a Mac .app (a bare gea build does this on a Mac for a Mac-only app)
235
+ gea build --target ios [app] [--mode simulator|device] generate the Xcode project and build the iOS .app
236
+ gea run --target ios [app] [--mode simulator|device] build, then install and launch on a simulator or iPhone
237
+ gea build|run --target windows [app] build (and launch) the Windows executable
238
+
220
239
  ${heading('Build and deploy (device commands take --board <alias>, see gea boards list; with one registered board it can be left out):')}
221
240
  gea build --board <alias> [--app <id>] build firmware (ESP-IDF / Pico SDK / geaos) [--verbose] [--output file.bin]
222
241
  gea flash --board <alias> [--app <id>] build + flash over USB [--monitor] [--manual-boot] [--no-reset] [--flash-baud N]
@@ -0,0 +1,30 @@
1
+ import { spawnSync } from 'node:child_process'
2
+
3
+ import { CliError, ExitCode, fail } from '../errors.mjs'
4
+ import { appleChildEnv, appleTargetScript } from '../macos/adapter.mjs'
5
+ import { formatCommand } from '../run.mjs'
6
+
7
+ // iOS mirrors macOS: a platform, not a board, driven by one script shipped
8
+ // inside @geastack/apple and resolved from the app's own dependencies. The
9
+ // script takes a destination -- `simulator` (the default) or `device` -- which
10
+ // `--mode` selects. `gea build --target ios` compiles the .app and stops;
11
+ // `gea run --target ios` also installs and launches it on the picked simulator
12
+ // or attached iPhone, which is the script's own default behaviour. The script
13
+ // reads GEA_IOS_SKIP_LAUNCH, so a caller who already set it keeps their choice.
14
+ export function runIos({ app, env, dryRun = false, stdout, mode = '', run = false }) {
15
+ const destination = mode || 'simulator'
16
+ if (destination !== 'simulator' && destination !== 'device') {
17
+ fail(`--mode ${mode} is not an iOS destination; expected simulator or device.`, ExitCode.usage)
18
+ }
19
+ const { script, require } = appleTargetScript(app, 'ios', 'build-ios.sh')
20
+ const childEnv = appleChildEnv(app, env, require)
21
+ if (!run && childEnv.GEA_IOS_SKIP_LAUNCH === undefined) childEnv.GEA_IOS_SKIP_LAUNCH = '1'
22
+ if (dryRun) {
23
+ stdout(formatCommand(['bash', script, app.id, destination]))
24
+ return 0
25
+ }
26
+ const result = spawnSync('bash', [script, app.id, destination], { cwd: app.root, env: childEnv, stdio: 'inherit' })
27
+ if (result.error) throw result.error
28
+ if (result.status !== 0) throw new CliError(`iOS build failed (${result.status ?? 1}).`, ExitCode.deployFailed)
29
+ return 0
30
+ }
@@ -13,31 +13,48 @@ import { formatCommand } from '../run.mjs'
13
13
  // app's own module resolution is what finds it. An app declares `targets.macos`
14
14
  // and nothing else; the script reads the rest from the same manifest.
15
15
  export function runMacos({ app, env, dryRun = false, stdout }) {
16
+ const { script, require } = appleTargetScript(app, 'macos', 'build-macos.sh')
17
+ const childEnv = appleChildEnv(app, env, require)
18
+ if (dryRun) {
19
+ stdout(formatCommand(['bash', script, app.id]))
20
+ return 0
21
+ }
22
+ const result = spawnSync('bash', [script, app.id], { cwd: app.root, env: childEnv, stdio: 'inherit' })
23
+ if (result.error) throw result.error
24
+ if (result.status !== 0) throw new CliError(`macOS build failed (${result.status ?? 1}).`, ExitCode.deployFailed)
25
+ return 0
26
+ }
27
+
28
+ // Both Apple targets ship as one script each inside @geastack/apple, and both
29
+ // resolve it the same way: through the app's own dependencies. iOS reuses this
30
+ // from src/ios/adapter.mjs rather than restating the resolution.
31
+ export function appleTargetScript(app, platform, scriptName) {
16
32
  const require = createRequire(path.join(app.root, 'package.json'))
17
33
  let appleRoot = ''
18
34
  try {
19
35
  appleRoot = path.dirname(require.resolve('@geastack/apple/package.json'))
20
36
  } catch {
21
- fail(`'${app.id}' targets macOS but @geastack/apple is not installed in ${app.root} — run npm install there.`, ExitCode.missingDependency)
37
+ fail(`'${app.id}' targets ${platformLabel(platform)} but @geastack/apple is not installed in ${app.root} — run npm install there.`, ExitCode.missingDependency)
22
38
  }
23
- const script = path.join(appleRoot, 'targets', 'macos', 'build-macos.sh')
24
- if (!existsSync(script)) fail(`macOS build script not found: ${script}`, ExitCode.missingDependency)
25
- // The script resolves the app through this CLI again. It is spawned with the
26
- // app's own folder as its cwd and that is the whole handoff: `createContext`
27
- // resolves a project from cwd, and a root's own package.json is one of the
28
- // places discovery looks, so an app outside the examples workspace resolves
29
- // like any other. Nothing announces the path a second time.
39
+ const script = path.join(appleRoot, 'targets', platform, scriptName)
40
+ if (!existsSync(script)) fail(`${platformLabel(platform)} build script not found: ${script}`, ExitCode.missingDependency)
41
+ return { script, require }
42
+ }
43
+
44
+ // The script resolves the app through this CLI again. It is spawned with the
45
+ // app's own folder as its cwd and that is the whole handoff: `createContext`
46
+ // resolves a project from cwd, and a root's own package.json is one of the
47
+ // places discovery looks, so an app outside the examples workspace resolves
48
+ // like any other. Nothing announces the path a second time.
49
+ export function appleChildEnv(app, env, require) {
30
50
  const childEnv = { ...env }
31
51
  const plugins = geatscPluginsOf(app, require)
32
52
  if (plugins.length > 0) childEnv.GEA_EXTRA_GEATSC_PLUGINS = plugins.join(path.delimiter)
33
- if (dryRun) {
34
- stdout(formatCommand(['bash', script, app.id]))
35
- return 0
36
- }
37
- const result = spawnSync('bash', [script, app.id], { cwd: app.root, env: childEnv, stdio: 'inherit' })
38
- if (result.error) throw result.error
39
- if (result.status !== 0) throw new CliError(`macOS build failed (${result.status ?? 1}).`, ExitCode.deployFailed)
40
- return 0
53
+ return childEnv
54
+ }
55
+
56
+ function platformLabel(platform) {
57
+ return platform === 'ios' ? 'iOS' : 'macOS'
41
58
  }
42
59
 
43
60
  // Compiler plugins come from the packages the app depends on.
@@ -5,6 +5,7 @@ import path from 'node:path'
5
5
 
6
6
  import { resolvePicotoolSelection } from '../boards/usb.mjs'
7
7
  import { CliError, ExitCode, fail } from '../errors.mjs'
8
+ import { envPath } from '../env-path.mjs'
8
9
  import { appCmakeMeta } from '../manifest.mjs'
9
10
  import { formatCommand } from '../run.mjs'
10
11
 
@@ -71,7 +72,7 @@ export function prepareArmToolchain(env, stderr = () => {}) {
71
72
 
72
73
  export function cmakeBinary(env) {
73
74
  if (env.CMAKE) return env.CMAKE
74
- for (const dir of String(env.PATH || '').split(path.delimiter)) {
75
+ for (const dir of envPath(env).split(path.delimiter)) {
75
76
  if (dir && existsSync(path.join(dir, 'cmake'))) return path.join(dir, 'cmake')
76
77
  }
77
78
  for (const candidate of ['/opt/homebrew/bin/cmake', '/usr/local/bin/cmake', '/Applications/CMake.app/Contents/bin/cmake']) {
package/src/toolchain.mjs CHANGED
@@ -2,6 +2,8 @@ import path from 'node:path'
2
2
  import { execFileSync } from 'node:child_process'
3
3
  import { existsSync } from 'node:fs'
4
4
 
5
+ import { envPath } from './env-path.mjs'
6
+
5
7
  export function nodeAtLeast(major, minor) {
6
8
  const [actualMajor, actualMinor] = process.versions.node.split('.').map((value) => Number.parseInt(value, 10))
7
9
  return actualMajor > major || (actualMajor === major && actualMinor >= minor)
@@ -21,7 +23,7 @@ export function commandVersion(command, args, env = process.env) {
21
23
  // it -- a toolchain a build needs is worth failing on before the build starts,
22
24
  // with the same answer doctor would have given.
23
25
  export function onPath(name, env = process.env) {
24
- return String(env.PATH || '')
26
+ return envPath(env)
25
27
  .split(path.delimiter)
26
28
  .some((dir) => dir && existsSync(path.join(dir, name)))
27
29
  }
@@ -152,7 +152,7 @@ export function buildSimulatorApp({ app, env, dryRun = false, stdout }) {
152
152
 
153
153
  export async function runSimulate({ ctx, app, env, dryRun = false, stdout, port, open = true, view = {} }) {
154
154
  const { simulatorDir, paths } = buildSimulatorApp({ app, env, dryRun, stdout })
155
- const url = await startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout })
155
+ const url = await startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout, view })
156
156
  if (dryRun) return 0
157
157
  stdout(`Simulating ${app.id}: ${url}`)
158
158
  if (open) openBrowser(url, env)
@@ -166,7 +166,7 @@ export async function runSimulate({ ctx, app, env, dryRun = false, stdout, port,
166
166
  // the relocated dist root be passed as inline config that vite merges over the
167
167
  // package's own vite.config.ts, instead of being smuggled through env vars the
168
168
  // config would have to read back.
169
- async function startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout }) {
169
+ async function startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout, view = {} }) {
170
170
  const appRoot = path.join(simulatorDir, 'simulator')
171
171
  const configFile = path.join(appRoot, 'vite.config.ts')
172
172
  if (dryRun) {
@@ -182,7 +182,11 @@ async function startSimulatorServer({ ctx, app, env, simulatorDir, paths, port,
182
182
  // Vite's default cacheDir is <root>/node_modules/.vite -- inside the
183
183
  // installed package, which may be read-only and is not this app's to dirty.
184
184
  cacheDir: paths.viteCache,
185
- define: { __GEA_APP_INDEX__: JSON.stringify(appIndexFor(ctx, app)) },
185
+ publicDir: path.dirname(paths.public),
186
+ define: {
187
+ __GEA_APP_INDEX__: JSON.stringify(appIndexFor(ctx, app)),
188
+ __GEA_WEB_DIST_FS_ROOT__: JSON.stringify(paths.dist)
189
+ },
186
190
  server: {
187
191
  port,
188
192
  fs: { allow: [appRoot, paths.dist, paths.public] }