quiesco 0.6.0 → 0.8.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.
Files changed (64) hide show
  1. package/README.md +2 -2
  2. package/dist/app-dir.d.ts +13 -0
  3. package/dist/app-dir.d.ts.map +1 -0
  4. package/dist/app-dir.js +22 -0
  5. package/dist/app-dir.js.map +1 -0
  6. package/dist/cli.d.ts +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +6 -5
  9. package/dist/cli.js.map +1 -1
  10. package/dist/commands/build.d.ts +1 -1
  11. package/dist/commands/build.d.ts.map +1 -1
  12. package/dist/commands/build.js +21 -11
  13. package/dist/commands/build.js.map +1 -1
  14. package/dist/commands/doctor.d.ts +1 -1
  15. package/dist/commands/doctor.d.ts.map +1 -1
  16. package/dist/commands/doctor.js +75 -37
  17. package/dist/commands/doctor.js.map +1 -1
  18. package/dist/commands/init.d.ts.map +1 -1
  19. package/dist/commands/init.js +91 -16
  20. package/dist/commands/init.js.map +1 -1
  21. package/dist/commands/list.d.ts +1 -1
  22. package/dist/commands/list.d.ts.map +1 -1
  23. package/dist/commands/list.js +4 -2
  24. package/dist/commands/list.js.map +1 -1
  25. package/dist/commands/test.d.ts +2 -2
  26. package/dist/commands/test.d.ts.map +1 -1
  27. package/dist/commands/test.js +4 -2
  28. package/dist/commands/test.js.map +1 -1
  29. package/dist/commands/ui.d.ts +1 -1
  30. package/dist/commands/ui.d.ts.map +1 -1
  31. package/dist/commands/ui.js +4 -2
  32. package/dist/commands/ui.js.map +1 -1
  33. package/dist/commands/upgrade.d.ts.map +1 -1
  34. package/dist/commands/upgrade.js +58 -28
  35. package/dist/commands/upgrade.js.map +1 -1
  36. package/dist/context.d.ts +8 -0
  37. package/dist/context.d.ts.map +1 -1
  38. package/dist/context.js +22 -0
  39. package/dist/context.js.map +1 -1
  40. package/dist/dev-server.d.ts.map +1 -1
  41. package/dist/dev-server.js +4 -2
  42. package/dist/dev-server.js.map +1 -1
  43. package/dist/runner.d.ts +15 -0
  44. package/dist/runner.d.ts.map +1 -0
  45. package/dist/runner.js +41 -0
  46. package/dist/runner.js.map +1 -0
  47. package/dist/setup-steps.d.ts +8 -3
  48. package/dist/setup-steps.d.ts.map +1 -1
  49. package/dist/setup-steps.js +18 -8
  50. package/dist/setup-steps.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/app-dir.ts +26 -0
  53. package/src/cli.ts +6 -5
  54. package/src/commands/build.ts +20 -11
  55. package/src/commands/doctor.ts +76 -38
  56. package/src/commands/init.ts +101 -15
  57. package/src/commands/list.ts +4 -2
  58. package/src/commands/test.ts +5 -3
  59. package/src/commands/ui.ts +4 -2
  60. package/src/commands/upgrade.ts +58 -27
  61. package/src/context.ts +23 -0
  62. package/src/dev-server.ts +4 -2
  63. package/src/runner.ts +47 -0
  64. package/src/setup-steps.ts +20 -8
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `quiesco test [--platform ios|android|web] [--runner cucumber|jest|vitest] [--workers N] [runner arguments…]`
3
3
  * (requirements.md §6.12, Phase 6.10): sets QUIESCO_PLATFORM and runs the project's test runner with the
4
- * remaining arguments unchanged. Default runner: cucumber-js. `--workers N` (Phase 6.12) runs N workers,
4
+ * remaining arguments unchanged. Default runner: the project's (projectRunner). `--workers N` (Phase 6.12) runs N workers,
5
5
  * each on its own device, with the runner's own flags; those flags can also be passed directly.
6
6
  * Everything after a `--` goes to the runner as-is, and the `--` itself is dropped (issue #7): cucumber-js
7
7
  * would read every argument after it as a path.
@@ -13,6 +13,7 @@ import { loadConfig } from '@quiesco/core';
13
13
 
14
14
  import type { CliContext } from '../context.js';
15
15
  import { parsePlatform, takeFlag, takeOption } from '../context.js';
16
+ import { projectRunner } from '../runner.js';
16
17
  import { ensureDevServer } from '../dev-server.js';
17
18
  import { cucumberFormatArgs, progressWanted, runWithProgress } from '../progress/run.js';
18
19
 
@@ -49,7 +50,8 @@ When nothing answers at devClient.metroUrl (native) or apps.web.url (web) on thi
49
50
 
50
51
  Options:
51
52
  --platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
52
- --runner cucumber|jest|vitest Test runner (default: cucumber, i.e. cucumber-js)
53
+ --runner cucumber|jest|vitest Test runner (default: the one whose @quiesco package
54
+ is installed; cucumber when several or none are)
53
55
  --workers N Run N workers, each on a device of its own
54
56
  --no-progress No progress bar (it shows on a terminal, not in CI; or QUIESCO_PROGRESS=0)
55
57
  -h, --help Show this help (\`quiesco test -- --help\` shows the runner's)
@@ -84,7 +86,7 @@ export async function testCommand(args: readonly string[], ctx: CliContext, deps
84
86
  ctx.err('quiesco test: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco test --help.');
85
87
  return 2;
86
88
  }
87
- const runner = r.value ?? 'cucumber';
89
+ const runner = r.value ?? projectRunner(ctx);
88
90
  if (!isRunner(runner)) {
89
91
  ctx.err(`quiesco test: unknown runner "${runner}" (cucumber, jest or vitest).`);
90
92
  return 2;
@@ -13,6 +13,7 @@ import { listTests } from '@quiesco/core';
13
13
 
14
14
  import type { CliContext } from '../context.js';
15
15
  import { parsePlatform, takeFlag, takeOption } from '../context.js';
16
+ import { projectRunner } from '../runner.js';
16
17
  import { ensureDevServer } from '../dev-server.js';
17
18
  import { cucumberFormatArgs } from '../progress/run.js';
18
19
  import { RUNNERS, defaultTestDeps, isRunner } from './test.js';
@@ -24,7 +25,8 @@ failures with Quiesco's evidence. Needs @quiesco/ui in the project (npm i -D @qu
24
25
 
25
26
  Options:
26
27
  --platform ios|android|web Platform to test (or set QUIESCO_PLATFORM)
27
- --runner cucumber|jest|vitest Test runner (default: cucumber)
28
+ --runner cucumber|jest|vitest Test runner (default: the one whose @quiesco package
29
+ is installed; cucumber when several or none are)
28
30
  --workers N Run N workers, each on a device of its own
29
31
  --port N Port of the UI (default: a free one)
30
32
  --no-open Do not open the browser
@@ -97,7 +99,7 @@ export async function uiCommand(args: readonly string[], ctx: CliContext, deps:
97
99
  ctx.err('quiesco ui: choose a platform with --platform ios|android|web (or set QUIESCO_PLATFORM). See quiesco ui --help.');
98
100
  return 2;
99
101
  }
100
- const runner = r.value ?? 'cucumber';
102
+ const runner = r.value ?? projectRunner(ctx);
101
103
  if (!isRunner(runner)) {
102
104
  ctx.err(`quiesco ui: unknown runner "${runner}" (cucumber, jest or vitest).`);
103
105
  return 2;
@@ -7,12 +7,16 @@
7
7
  *
8
8
  * Only changes it can make safely; anything else is listed with what to do. Running it again changes
9
9
  * nothing. `--dry-run` lists the changes without making them.
10
+ *
11
+ * With `appDir` (or `--app-dir`, issue #54) the app's packages (agent, native, expo-plugin) and files
12
+ * (app.json, <QuiescoRoot>) are upgraded in the app's directory, the rest in the working directory.
10
13
  */
11
14
  import path from 'node:path';
12
15
 
13
16
  import type { QuiescoConfig } from '@quiesco/core';
14
17
  import { loadConfig } from '@quiesco/core';
15
18
 
19
+ import { APP_DIR_OPTION, appContext } from '../app-dir.js';
16
20
  import type { CliContext, CliPlatform } from '../context.js';
17
21
  import { PLATFORMS, takeFlag, takeOption } from '../context.js';
18
22
  import { installedVersion, isQuiescoPackage } from '../packages.js';
@@ -33,11 +37,13 @@ const CUCUMBER_FILES = ['cucumber.mjs', 'cucumber.js', 'cucumber.cjs', 'cucumber
33
37
  /** The line 0.1.x wrote into cucumber.mjs (issue #8). */
34
38
  const OLD_PATHS_LINE = /^[ \t]*paths:[ \t]*\[[ \t]*['"]features\/\*\*\/\*\.feature['"][ \t]*\],?[ \t]*\r?\n/m;
35
39
 
36
- /** Quiesco packages to install: the ones the platforms need and every other one the project already has. */
37
- function packagesToInstall(pkg: PackageJson, platforms: readonly CliPlatform[]): { runtime: string[]; dev: string[] } {
38
- const needed = [...RUNTIME, ...DEV, ...(platforms.includes('web') ? WEB_DEV : [])].filter(isQuiescoPackage);
40
+ /** The app's own packages, installed in the app when the tests are elsewhere (appDir, issue #54). */
41
+ const APP_PACKAGES = [...RUNTIME, '@quiesco/expo-plugin'];
42
+
43
+ /** Quiesco packages to install: the `needed` ones and every other one the project already has. */
44
+ function packagesToInstall(pkg: PackageJson, needed: readonly string[]): { runtime: string[]; dev: string[] } {
39
45
  const present = [...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})].filter(isQuiescoPackage);
40
- const all = [...new Set([...needed, ...present])];
46
+ const all = [...new Set([...needed.filter(isQuiescoPackage), ...present])];
41
47
  // Keep each package in the group it is in; new ones go where init puts them.
42
48
  const isRuntime = (n: string): boolean => pkg.dependencies?.[n] !== undefined || (pkg.devDependencies?.[n] === undefined && RUNTIME.includes(n));
43
49
  return { runtime: all.filter(isRuntime), dev: all.filter((n) => !isRuntime(n)) };
@@ -126,13 +132,24 @@ export async function upgradeCommand(args: readonly string[], ctx: CliContext, d
126
132
  rest = skipInstall.rest;
127
133
  const dryRun = takeFlag(rest, '--dry-run');
128
134
  rest = dryRun.rest;
135
+ const appDirOpt = takeOption(rest, APP_DIR_OPTION);
136
+ rest = appDirOpt.rest;
129
137
  if (rest.length > 0) {
130
138
  ctx.err(`quiesco init --upgrade: unknown arguments ${rest.join(' ')}`);
131
139
  return 2;
132
140
  }
133
- const pkg = readJson<PackageJson>(ctx, path.join(ctx.cwd, 'package.json'));
141
+ let config: QuiescoConfig | null = null;
142
+ let configError = '';
143
+ try {
144
+ config = await deps.loadConfig(ctx.cwd);
145
+ } catch (e) {
146
+ configError = (e as Error).message.split('\n')[0] ?? '';
147
+ }
148
+ const app = appContext(ctx, config, appDirOpt.value);
149
+ const separate = app !== ctx;
150
+ const pkg = readJson<PackageJson>(app, path.join(app.cwd, 'package.json'));
134
151
  if (pkg === null || (pkg.dependencies?.['expo'] === undefined && pkg.devDependencies?.['expo'] === undefined)) {
135
- ctx.err(`quiesco init --upgrade: ${ctx.cwd} is not an Expo project (no expo dependency in package.json).`);
152
+ ctx.err(`quiesco init --upgrade: ${app.cwd} is not an Expo project (no expo dependency in package.json).${separate ? '' : ' Tests in a package of their own: set appDir in quiesco.config or pass --app-dir.'}`);
136
153
  return 1;
137
154
  }
138
155
  let platforms: CliPlatform[];
@@ -143,43 +160,57 @@ export async function upgradeCommand(args: readonly string[], ctx: CliContext, d
143
160
  return 2;
144
161
  }
145
162
  platforms = platformsOpt.value.split(',') as CliPlatform[];
163
+ } else if (config !== null) {
164
+ platforms = PLATFORMS.filter((p) => config.apps[p] !== undefined);
146
165
  } else {
147
- try {
148
- const config = await deps.loadConfig(ctx.cwd);
149
- platforms = PLATFORMS.filter((p) => config.apps[p] !== undefined);
150
- } catch (e) {
151
- ctx.err(`quiesco init --upgrade: cannot read quiesco.config (${(e as Error).message.split('\n')[0] ?? ''}).`);
152
- ctx.err('Run quiesco init for a new setup, or name the platforms: quiesco init --upgrade --platforms ios,android,web');
153
- return 1;
154
- }
166
+ ctx.err(`quiesco init --upgrade: cannot read quiesco.config (${configError}).`);
167
+ ctx.err('Run quiesco init for a new setup, or name the platforms: quiesco init --upgrade --platforms ios,android,web');
168
+ return 1;
155
169
  }
156
170
 
157
171
  const steps: InitStep[] = [];
158
172
  const log: StepLog = { ctx, steps, dryRun: dryRun.present };
173
+ // The app's steps; the same as `log` unless the app is elsewhere.
174
+ const appLog: StepLog = { ...log, ctx: app };
159
175
 
160
- // 1. Every Quiesco package at this CLI's version.
161
- const { runtime, dev } = packagesToInstall(pkg, platforms);
162
- const current = [...runtime, ...dev].map((n) => installedVersion(ctx, n));
163
- if (packagesOpt.value === undefined && current.every((v) => v === ctx.version)) {
164
- steps.push({ status: 'skipped', what: 'versions', note: `${current.length} Quiesco packages at ${ctx.version}` });
165
- } else {
166
- const ok = await installPackages(log, {
167
- pm: detectPackageManager(ctx),
176
+ // 1. Every Quiesco package at this CLI's version: one project, or the app's in the app and the rest here.
177
+ const needed = [...RUNTIME, ...DEV, ...(platforms.includes('web') ? WEB_DEV : [])];
178
+ const testPkg = separate ? readJson<PackageJson>(ctx, path.join(ctx.cwd, 'package.json')) : null;
179
+ if (separate && testPkg === null) {
180
+ ctx.err(`quiesco init --upgrade: no package.json in ${ctx.cwd} (the test project).`);
181
+ return 1;
182
+ }
183
+ const sets: { log: StepLog; packages: { runtime: string[]; dev: string[] } }[] = separate
184
+ ? [
185
+ { log: appLog, packages: packagesToInstall(pkg, APP_PACKAGES) },
186
+ { log, packages: packagesToInstall(testPkg as PackageJson, needed.filter((n) => !APP_PACKAGES.includes(n))) },
187
+ ]
188
+ : [{ log, packages: packagesToInstall(pkg, needed) }];
189
+ for (const set of sets) {
190
+ const { runtime, dev } = set.packages;
191
+ const where = separate ? ` in ${path.relative(ctx.cwd, set.log.ctx.cwd) || '.'}` : '';
192
+ const current = [...runtime, ...dev].map((n) => installedVersion(set.log.ctx, n));
193
+ if (packagesOpt.value === undefined && current.every((v) => v === ctx.version)) {
194
+ steps.push({ status: 'skipped', what: 'versions', note: `${current.length} Quiesco packages at ${ctx.version}${where}` });
195
+ continue;
196
+ }
197
+ const ok = await installPackages(set.log, {
198
+ pm: detectPackageManager(set.log.ctx),
168
199
  runtime,
169
200
  dev,
170
- ...(packagesOpt.value !== undefined ? { packagesDir: packagesOpt.value } : {}),
201
+ ...(packagesOpt.value !== undefined ? { packagesDir: path.resolve(ctx.cwd, packagesOpt.value) } : {}),
171
202
  skipInstall: skipInstall.present,
172
203
  });
173
204
  if (!ok) return 1;
174
205
  }
175
206
 
176
- // 2. What older inits wrote.
207
+ // 2. What older inits wrote: the test setup here, app.json and <QuiescoRoot> in the app.
177
208
  fixCucumberPaths(log);
178
209
  ensureTsconfig(log);
179
- const app = ensureAppIds(log, platforms);
180
- fixConfigPlaceholders(log, app);
210
+ const appJson = ensureAppIds(appLog, platforms);
211
+ fixConfigPlaceholders(log, appJson);
181
212
  ensureScripts(log, platforms);
182
- ensureRoot(log);
213
+ ensureRoot(appLog);
183
214
 
184
215
  printSteps(ctx, steps);
185
216
  ctx.out('');
package/src/context.ts CHANGED
@@ -6,6 +6,7 @@ import { spawn as nodeSpawn } from 'node:child_process';
6
6
  import fs from 'node:fs';
7
7
  import { createRequire } from 'node:module';
8
8
  import path from 'node:path';
9
+ import { createInterface } from 'node:readline/promises';
9
10
 
10
11
  export interface ExecResult {
11
12
  code: number;
@@ -37,6 +38,11 @@ export interface CliContext {
37
38
  nodeVersion: string;
38
39
  /** Whether a person is at the terminal (stdout is a TTY), not a CI job. */
39
40
  interactive: boolean;
41
+ /**
42
+ * Ask the person at the terminal to pick one of `options` (numbered; Enter takes `defaultValue`).
43
+ * Returns `defaultValue` when stdin is not a terminal.
44
+ */
45
+ choose(question: string, options: readonly { value: string; label: string }[], defaultValue: string): Promise<string>;
40
46
  /** Start a long-running process (Metro) in its own process group, its output appended to `logFile`. */
41
47
  spawnBackground(command: string, args: readonly string[], options: { cwd: string; env: NodeJS.ProcessEnv; logFile: string }): BackgroundProcess;
42
48
  /** GET `url`; null when nothing answers (connection refused, timeout). */
@@ -120,6 +126,23 @@ export function defaultContext(): CliContext {
120
126
  platform: process.platform,
121
127
  nodeVersion: process.versions.node,
122
128
  interactive: process.stdout.isTTY === true,
129
+ choose: async (question, options, defaultValue) => {
130
+ if (process.stdin.isTTY !== true) return defaultValue;
131
+ const def = Math.max(0, options.findIndex((o) => o.value === defaultValue));
132
+ process.stdout.write(`${question}\n${options.map((o, i) => ` ${i + 1}) ${o.label}`).join('\n')}\n`);
133
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
134
+ try {
135
+ for (;;) {
136
+ const answer = (await rl.question(`Choose 1-${options.length} [${def + 1}]: `)).trim();
137
+ if (answer === '') return defaultValue;
138
+ const byNumber = options[Number(answer) - 1];
139
+ const picked = /^\d+$/.test(answer) ? byNumber : options.find((o) => o.value === answer.toLowerCase());
140
+ if (picked !== undefined) return picked.value;
141
+ }
142
+ } finally {
143
+ rl.close();
144
+ }
145
+ },
123
146
  spawnBackground: (command, args, options) => {
124
147
  fs.mkdirSync(path.dirname(options.logFile), { recursive: true });
125
148
  const log = fs.openSync(options.logFile, 'a');
package/src/dev-server.ts CHANGED
@@ -59,8 +59,10 @@ export async function ensureDevServer(ctx: CliContext, config: QuiescoConfig, pl
59
59
  const [command, ...args] = (opts.command ?? ['npx', 'expo', 'start', '--port', '{port}']).map((a) => a.replaceAll('{port}', port));
60
60
  if (command === undefined) throw new Error('devServer.command is empty');
61
61
  const logFile = path.join(ctx.cwd, config.artifacts?.dir ?? 'artifacts', 'metro.log');
62
- ctx.out(`quiesco: starting Metro (${[command, ...args].join(' ')}) with EXPO_PUBLIC_QUIESCO=1; log: ${path.relative(ctx.cwd, logFile)}`);
63
- const proc = ctx.spawnBackground(command, args, { cwd: ctx.cwd, env: { ...ctx.env, EXPO_PUBLIC_QUIESCO: '1' }, logFile });
62
+ // Metro serves the app: in appDir when the tests are a package of their own (issue #54).
63
+ const appDir = config.appDir ?? ctx.cwd;
64
+ ctx.out(`quiesco: starting Metro (${[command, ...args].join(' ')})${appDir !== ctx.cwd ? ` in ${appDir}` : ''} with EXPO_PUBLIC_QUIESCO=1; log: ${path.relative(ctx.cwd, logFile)}`);
65
+ const proc = ctx.spawnBackground(command, args, { cwd: appDir, env: { ...ctx.env, EXPO_PUBLIC_QUIESCO: '1' }, logFile });
64
66
  const offInterrupt = ctx.onInterrupt(() => proc.stop());
65
67
  const server: DevServer = {
66
68
  env: {},
package/src/runner.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The test runners Quiesco drives, and which one a project uses. `quiesco init` asks for one (Vitest by
3
+ * default) and installs its packages; `quiesco test` / `ui` / `list` without `--runner` use the one whose
4
+ * Quiesco package the project has.
5
+ */
6
+ import path from 'node:path';
7
+
8
+ import type { CliContext } from './context.js';
9
+
10
+ /** In the order `quiesco init` offers them: the first is the default. */
11
+ export const RUNNER_NAMES = ['vitest', 'jest', 'cucumber'] as const;
12
+ export type RunnerName = (typeof RUNNER_NAMES)[number];
13
+
14
+ export function isRunnerName(v: string | undefined): v is RunnerName {
15
+ return v !== undefined && (RUNNER_NAMES as readonly string[]).includes(v);
16
+ }
17
+
18
+ /** The devDependencies each runner needs: Quiesco's integration and the runner itself. */
19
+ export const RUNNER_PACKAGES: Record<RunnerName, readonly string[]> = {
20
+ vitest: ['@quiesco/vitest', 'vitest'],
21
+ jest: ['@quiesco/jest', 'jest'],
22
+ cucumber: ['@quiesco/cucumber', '@cucumber/cucumber'],
23
+ };
24
+
25
+ export const RUNNER_LABELS: Record<RunnerName, string> = {
26
+ vitest: 'Vitest (recommended): tests in TypeScript, app as a test fixture',
27
+ jest: 'Jest: tests in JavaScript, app as the global quiesco.app',
28
+ cucumber: 'Cucumber: Gherkin features with step definitions',
29
+ };
30
+
31
+ /**
32
+ * The runner whose Quiesco package (@quiesco/vitest, @quiesco/jest, @quiesco/cucumber) is in package.json.
33
+ * With none or several of them: cucumber, the default of Quiesco 0.6 and earlier (projects set up then
34
+ * keep running the same way); `--runner` picks another.
35
+ */
36
+ export function projectRunner(ctx: CliContext): RunnerName {
37
+ const text = ctx.readFile(path.join(ctx.cwd, 'package.json'));
38
+ let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> } = {};
39
+ try {
40
+ pkg = text === null ? {} : (JSON.parse(text) as typeof pkg);
41
+ } catch {
42
+ // unreadable package.json: the default
43
+ }
44
+ const has = (name: string): boolean => pkg.dependencies?.[name] !== undefined || pkg.devDependencies?.[name] !== undefined;
45
+ const found = RUNNER_NAMES.filter((r) => has(RUNNER_PACKAGES[r][0] as string));
46
+ return found.length === 1 ? (found[0] as RunnerName) : 'cucumber';
47
+ }
@@ -49,8 +49,8 @@ export interface StepLog {
49
49
 
50
50
  /** Installed into `dependencies`: the app bundles them (stubbed / excluded in production builds). */
51
51
  export const RUNTIME = ['@quiesco/agent', '@quiesco/native'];
52
- /** Installed into `devDependencies`. */
53
- export const DEV = ['quiesco', '@quiesco/core', '@quiesco/cucumber', '@quiesco/expo-plugin', '@cucumber/cucumber'];
52
+ /** Installed into `devDependencies`, with the chosen runner's packages (RUNNER_PACKAGES). */
53
+ export const DEV = ['quiesco', '@quiesco/core', '@quiesco/expo-plugin'];
54
54
  export const WEB_DEV = ['@quiesco/web', 'playwright'];
55
55
  /** Internal packages pulled in by the ones above; only pinned when installing from tarballs. */
56
56
  const TRANSITIVE = ['@quiesco/protocol'];
@@ -295,22 +295,34 @@ export function ensureTsconfig(log: StepLog): void {
295
295
 
296
296
  // ---- scripts ----
297
297
 
298
- export function e2eScripts(platforms: readonly CliPlatform[]): Record<string, string> {
298
+ /** `testArgs`: appended to each `quiesco test` (`--config vitest.e2e.config.mts` when init wrote that file). */
299
+ export function e2eScripts(platforms: readonly CliPlatform[], testArgs = ''): Record<string, string> {
300
+ const extra = testArgs === '' ? '' : ` ${testArgs}`;
299
301
  return {
300
302
  'e2e:start': 'EXPO_PUBLIC_QUIESCO=1 expo start',
301
- ...(platforms.includes('web') ? { 'e2e:web': 'EXPO_PUBLIC_QUIESCO=1 expo export --platform web && quiesco test --platform web' } : {}),
302
- ...(platforms.includes('android') ? { 'e2e:build:android': 'quiesco build android', 'e2e:android': 'quiesco test --platform android' } : {}),
303
- ...(platforms.includes('ios') ? { 'e2e:build:ios': 'quiesco build ios', 'e2e:ios': 'quiesco test --platform ios' } : {}),
303
+ ...(platforms.includes('web') ? { 'e2e:web': `EXPO_PUBLIC_QUIESCO=1 expo export --platform web && quiesco test --platform web${extra}` } : {}),
304
+ ...(platforms.includes('android') ? { 'e2e:build:android': 'quiesco build android', 'e2e:android': `quiesco test --platform android${extra}` } : {}),
305
+ ...(platforms.includes('ios') ? { 'e2e:build:ios': 'quiesco build ios', 'e2e:ios': `quiesco test --platform ios${extra}` } : {}),
304
306
  };
305
307
  }
306
308
 
309
+ /** `pm run <script>` as the person types it (`npm run x`, `pnpm x`, `yarn x`, `bun run x`). */
310
+ export function runScript(pm: PackageManager, script: string): string {
311
+ return pm === 'pnpm' || pm === 'yarn' ? `${pm} ${script}` : `${pm} run ${script}`;
312
+ }
313
+
314
+ /** `npx <command>` for the package manager (`pnpm exec`, `yarn`, `bunx`): runs the project's own binary. */
315
+ export function execBin(pm: PackageManager, command: string): string {
316
+ return { npm: 'npx', pnpm: 'pnpm exec', yarn: 'yarn', bun: 'bunx' }[pm] + ` ${command}`;
317
+ }
318
+
307
319
  /** Add the e2e scripts that are missing; existing scripts of the same name are left alone. */
308
- export function ensureScripts(log: StepLog, platforms: readonly CliPlatform[]): void {
320
+ export function ensureScripts(log: StepLog, platforms: readonly CliPlatform[], testArgs = ''): void {
309
321
  const { ctx, steps } = log;
310
322
  const pkgFile = path.join(ctx.cwd, 'package.json');
311
323
  const pkg = readJson<PackageJson>(ctx, pkgFile) as PackageJson;
312
324
  const scripts = { ...(pkg.scripts ?? {}) };
313
- const wanted = e2eScripts(platforms);
325
+ const wanted = e2eScripts(platforms, testArgs);
314
326
  const added = Object.keys(wanted).filter((k) => scripts[k] === undefined);
315
327
  if (added.length === 0) {
316
328
  steps.push({ status: 'skipped', what: 'scripts', note: 'the e2e scripts exist' });