quiesco 0.2.0 → 0.4.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 (65) hide show
  1. package/README.md +3 -1
  2. package/dist/cli.d.ts +2 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +11 -6
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/doctor.d.ts.map +1 -1
  7. package/dist/commands/doctor.js +81 -7
  8. package/dist/commands/doctor.js.map +1 -1
  9. package/dist/commands/init.d.ts.map +1 -1
  10. package/dist/commands/init.js +108 -22
  11. package/dist/commands/init.js.map +1 -1
  12. package/dist/commands/list.d.ts +16 -0
  13. package/dist/commands/list.d.ts.map +1 -0
  14. package/dist/commands/list.js +56 -0
  15. package/dist/commands/list.js.map +1 -0
  16. package/dist/commands/test.d.ts +20 -1
  17. package/dist/commands/test.d.ts.map +1 -1
  18. package/dist/commands/test.js +14 -6
  19. package/dist/commands/test.js.map +1 -1
  20. package/dist/commands/ui.d.ts +43 -0
  21. package/dist/commands/ui.d.ts.map +1 -0
  22. package/dist/commands/ui.js +121 -0
  23. package/dist/commands/ui.js.map +1 -0
  24. package/dist/context.d.ts +22 -0
  25. package/dist/context.d.ts.map +1 -1
  26. package/dist/context.js +31 -0
  27. package/dist/context.js.map +1 -1
  28. package/dist/dev-server.d.ts +2 -0
  29. package/dist/dev-server.d.ts.map +1 -1
  30. package/dist/dev-server.js +4 -2
  31. package/dist/dev-server.js.map +1 -1
  32. package/dist/packages.d.ts +17 -0
  33. package/dist/packages.d.ts.map +1 -0
  34. package/dist/packages.js +40 -0
  35. package/dist/packages.js.map +1 -0
  36. package/dist/progress/render.d.ts +31 -0
  37. package/dist/progress/render.d.ts.map +1 -0
  38. package/dist/progress/render.js +89 -0
  39. package/dist/progress/render.js.map +1 -0
  40. package/dist/progress/run.d.ts +24 -0
  41. package/dist/progress/run.d.ts.map +1 -0
  42. package/dist/progress/run.js +95 -0
  43. package/dist/progress/run.js.map +1 -0
  44. package/dist/progress/sticky.d.ts +25 -0
  45. package/dist/progress/sticky.d.ts.map +1 -0
  46. package/dist/progress/sticky.js +90 -0
  47. package/dist/progress/sticky.js.map +1 -0
  48. package/dist/project.d.ts +23 -0
  49. package/dist/project.d.ts.map +1 -0
  50. package/dist/project.js +74 -0
  51. package/dist/project.js.map +1 -0
  52. package/package.json +3 -3
  53. package/src/cli.ts +11 -7
  54. package/src/commands/doctor.ts +83 -7
  55. package/src/commands/init.ts +101 -19
  56. package/src/commands/list.ts +65 -0
  57. package/src/commands/test.ts +17 -7
  58. package/src/commands/ui.ts +152 -0
  59. package/src/context.ts +50 -0
  60. package/src/dev-server.ts +6 -2
  61. package/src/packages.ts +42 -0
  62. package/src/progress/render.ts +117 -0
  63. package/src/progress/run.ts +105 -0
  64. package/src/progress/sticky.ts +95 -0
  65. package/src/project.ts +76 -0
package/src/project.ts ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Where an Expo project renders its root (issue #20): the entry file, the component it registers, and
3
+ * the files `<QuiescoRoot>` may be in.
4
+ */
5
+ import path from 'node:path';
6
+
7
+ import type { CliContext } from './context.js';
8
+
9
+ const SOURCE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js'];
10
+
11
+ /** Root layouts of Expo Router apps and the usual root component files. */
12
+ const ROOT_CANDIDATES = ['app/_layout', 'src/app/_layout', 'App', 'src/App'].flatMap((base) => SOURCE_EXTENSIONS.map((ext) => `${base}${ext}`));
13
+
14
+ /** `file` as given or with a source extension (or as a directory with an index file); null when none exists. */
15
+ export function resolveSource(ctx: CliContext, file: string): string | null {
16
+ const candidates = [file, ...SOURCE_EXTENSIONS.map((ext) => `${file}${ext}`), ...SOURCE_EXTENSIONS.map((ext) => path.join(file, `index${ext}`))];
17
+ return candidates.find((f) => /\.[cm]?[jt]sx?$/.test(f) && ctx.exists(f)) ?? null;
18
+ }
19
+
20
+ /** The project's entry file from package.json "main"; null for package entries (expo-router/entry) or when missing. */
21
+ export function entryFile(ctx: CliContext, main: string | undefined): string | null {
22
+ return main === undefined ? null : resolveSource(ctx, path.join(ctx.cwd, main));
23
+ }
24
+
25
+ /**
26
+ * The component an entry registers with `registerRootComponent(App)`, when `App` is imported from a local
27
+ * file: its name and that file. null for anything else (inline components, packages, several calls).
28
+ */
29
+ export function registeredRoot(ctx: CliContext, entry: string, source: string): { name: string; file: string | null; importPath: string } | null {
30
+ const calls = [...source.matchAll(/registerRootComponent\(\s*([A-Za-z_$][\w$]*)\s*\)/g)];
31
+ if (calls.length !== 1) return null;
32
+ const name = (calls[0] as RegExpMatchArray)[1] as string;
33
+ const imported = new RegExp(`import\\s+(?:${name}\\b|\\{[^}]*\\b(?:default\\s+as\\s+)?${name}\\b[^}]*\\})[^;'"]*from\\s+['"](\\.{1,2}/[^'"]+)['"]`).exec(source);
34
+ if (imported === null) return null;
35
+ const importPath = imported[1] as string;
36
+ return { name, file: resolveSource(ctx, path.resolve(path.dirname(entry), importPath)), importPath };
37
+ }
38
+
39
+ /** The files `<QuiescoRoot>` is looked for in: the usual root files, the entry and the component it registers. */
40
+ export function rootSourceFiles(ctx: CliContext, main: string | undefined): string[] {
41
+ const files = ROOT_CANDIDATES.map((f) => path.join(ctx.cwd, f));
42
+ const entry = entryFile(ctx, main);
43
+ if (entry !== null) {
44
+ files.push(entry);
45
+ const root = registeredRoot(ctx, entry, ctx.readFile(entry) ?? '');
46
+ if (root?.file != null) files.push(root.file);
47
+ }
48
+ return [...new Set(files)].filter((f) => ctx.exists(f));
49
+ }
50
+
51
+ /**
52
+ * Issue #20: wrap the component an entry registers in `<QuiescoRoot>`, without JSX (the entry is often
53
+ * index.ts). Returns the new source, or null when the entry does not have the plain
54
+ * `registerRootComponent(App)` shape with a local `App`, or already mentions QuiescoRoot.
55
+ */
56
+ export function wrapRegisteredRoot(ctx: CliContext, entry: string, source: string): string | null {
57
+ if (source.includes('QuiescoRoot')) return null;
58
+ const root = registeredRoot(ctx, entry, source);
59
+ if (root === null) return null;
60
+ const agentImport = /^import '@quiesco\/agent';/m;
61
+ let out = agentImport.test(source)
62
+ ? source.replace(agentImport, "import { QuiescoRoot } from '@quiesco/agent';")
63
+ : `import { QuiescoRoot } from '@quiesco/agent'; // first: Quiesco hooks into React before the app loads\n${source}`;
64
+ out = out.replace(/(import\s[^;]*?from\s+['"]expo['"];?\n|import\s+['"]expo['"];?\n)/, `$1import { createElement } from 'react';\n`);
65
+ if (!out.includes("import { createElement } from 'react';")) out = out.replace(/(^import \{ QuiescoRoot \}[^\n]*\n)/m, `$1import { createElement } from 'react';\n`);
66
+ const wrapper = [
67
+ `// <QuiescoRoot> connects the app to Quiesco and remounts it for the soft reset before each scenario`,
68
+ `// (it renders ${root.name} unchanged in builds without EXPO_PUBLIC_QUIESCO=1).`,
69
+ `function QuiescoApp() {`,
70
+ ` return createElement(QuiescoRoot, null, createElement(${root.name}));`,
71
+ `}`,
72
+ ``,
73
+ `registerRootComponent(QuiescoApp)`,
74
+ ].join('\n');
75
+ return out.replace(/registerRootComponent\(\s*[A-Za-z_$][\w$]*\s*\)/, wrapper);
76
+ }