@limrun/api 0.77.3 → 0.78.1
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/CHANGELOG.md +26 -0
- package/folder-sync.d.mts +2 -0
- package/folder-sync.d.mts.map +1 -1
- package/folder-sync.d.ts +2 -0
- package/folder-sync.d.ts.map +1 -1
- package/folder-sync.js +1 -1
- package/folder-sync.js.map +1 -1
- package/folder-sync.mjs +1 -1
- package/folder-sync.mjs.map +1 -1
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +5 -2
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/ios-client.d.mts +85 -0
- package/ios-client.d.mts.map +1 -1
- package/ios-client.d.ts +85 -0
- package/ios-client.d.ts.map +1 -1
- package/ios-client.js +52 -8
- package/ios-client.js.map +1 -1
- package/ios-client.mjs +50 -7
- package/ios-client.mjs.map +1 -1
- package/package.json +11 -1
- package/project-identity.d.mts +20 -0
- package/project-identity.d.mts.map +1 -0
- package/project-identity.d.ts +20 -0
- package/project-identity.d.ts.map +1 -0
- package/project-identity.js +197 -0
- package/project-identity.js.map +1 -0
- package/project-identity.mjs +192 -0
- package/project-identity.mjs.map +1 -0
- package/resources/xcode-instances-helpers.d.mts +6 -0
- package/resources/xcode-instances-helpers.d.mts.map +1 -1
- package/resources/xcode-instances-helpers.d.ts +6 -0
- package/resources/xcode-instances-helpers.d.ts.map +1 -1
- package/resources/xcode-instances-helpers.js +5 -0
- package/resources/xcode-instances-helpers.js.map +1 -1
- package/resources/xcode-instances-helpers.mjs +5 -0
- package/resources/xcode-instances-helpers.mjs.map +1 -1
- package/src/folder-sync.ts +3 -1
- package/src/index.ts +1 -0
- package/src/ios-client.ts +162 -7
- package/src/project-identity.ts +178 -0
- package/src/resources/xcode-instances-helpers.ts +11 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/ios-client.ts
CHANGED
|
@@ -181,11 +181,94 @@ export type ElementTreeNode = {
|
|
|
181
181
|
|
|
182
182
|
export type ElementTree = ElementTreeNode[];
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Which reader answers an element tree request.
|
|
186
|
+
* - `accessibility` (default): the tree assistive technologies see. It leaves out elements the
|
|
187
|
+
* software keyboard covers and has no container types for navigation bars or tab bars.
|
|
188
|
+
* - `xcuitest`: XCTest's own snapshot, the tree XCUITest queries. Navigation bars, tab bars, the
|
|
189
|
+
* keyboard and alerts arrive as typed containers with their children. Full-tree reads only:
|
|
190
|
+
* omit `point` and `visibleOnly`. Takes about a second per read.
|
|
191
|
+
*/
|
|
192
|
+
export type ElementTreeSource = 'accessibility' | 'xcuitest';
|
|
193
|
+
|
|
184
194
|
export type ElementTreeOptions = {
|
|
185
195
|
/** Skip branches whose nonempty frames fall outside the display. Full-tree reads only. Defaults to false. */
|
|
186
196
|
visibleOnly?: boolean;
|
|
197
|
+
/** Which reader answers. Defaults to `accessibility`. */
|
|
198
|
+
source?: ElementTreeSource;
|
|
199
|
+
/**
|
|
200
|
+
* Wait up to this many milliseconds, at most 30000, for the screen to settle before answering:
|
|
201
|
+
* until two reads in a row match and the screen stops animating. A blinking text caret does not
|
|
202
|
+
* count as activity. {@link ElementTreeRead.idle} says whether it settled in time.
|
|
203
|
+
*/
|
|
204
|
+
waitForIdleTimeoutMs?: number;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/** The software keyboard on screen. `frame` uses the element tree's coordinates. */
|
|
208
|
+
export type KeyboardState = {
|
|
209
|
+
frame: ElementTreeFrame;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* An alert covering the app. `system` is a system prompt, such as a permission request; `app` is the
|
|
214
|
+
* app's own alert or confirmation dialog. Sheets are not reported.
|
|
215
|
+
*/
|
|
216
|
+
export type ModalState = {
|
|
217
|
+
kind: 'system' | 'app';
|
|
218
|
+
label: string | null;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/** An element tree together with what the server reports about the screen around it. */
|
|
222
|
+
export type ElementTreeRead = {
|
|
223
|
+
tree: ElementTree;
|
|
224
|
+
/**
|
|
225
|
+
* The software keyboard on full-tree reads from the `accessibility` source, or `null` when it is
|
|
226
|
+
* hidden. Absent on point reads, and on `xcuitest` reads, whose tree has XCTest's own Keyboard element.
|
|
227
|
+
*/
|
|
228
|
+
keyboard?: KeyboardState | null;
|
|
229
|
+
/** The alert covering the app on `xcuitest` reads, or `null` when there is none. Absent on other reads. */
|
|
230
|
+
modal?: ModalState | null;
|
|
231
|
+
/** Whether the screen settled in time. Present only when `waitForIdleTimeoutMs` was set. */
|
|
232
|
+
idle?: boolean;
|
|
187
233
|
};
|
|
188
234
|
|
|
235
|
+
/** Where typed text would go. */
|
|
236
|
+
export type FocusedElement = {
|
|
237
|
+
/** The element that reports focus, or `null` when none does. */
|
|
238
|
+
element: ElementTreeNode | null;
|
|
239
|
+
/**
|
|
240
|
+
* The software keyboard, or `null` when it is hidden. A keyboard with no element means the focused
|
|
241
|
+
* input is under the keyboard, which iOS leaves out of the tree: typeText still reaches it, and
|
|
242
|
+
* setElementValue fails with the `covered_by_keyboard` code.
|
|
243
|
+
*/
|
|
244
|
+
keyboard: KeyboardState | null;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* An iOS command the instance rejected. `message` is the server's error text; servers that predate
|
|
249
|
+
* error codes leave `code` and `written` undefined.
|
|
250
|
+
*/
|
|
251
|
+
export class CommandError extends Error {
|
|
252
|
+
/**
|
|
253
|
+
* The reason, stable to branch on: `no_focused_element`, `covered_by_keyboard`,
|
|
254
|
+
* `element_not_found`, `ambiguous_selector`, `ambiguous_focus`, `no_usable_frame`, `busy`,
|
|
255
|
+
* `invalid_request`, `unavailable`, `input_failed` or `internal`. New codes may appear.
|
|
256
|
+
*/
|
|
257
|
+
readonly code: string | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Set by typeText, setElementValue and pressKey: `none` when nothing reached the app, so a retry
|
|
260
|
+
* cannot double the text, and `unknown` when input had started.
|
|
261
|
+
*/
|
|
262
|
+
readonly written: 'none' | 'unknown' | undefined;
|
|
263
|
+
|
|
264
|
+
constructor(message: string, code?: string, written?: 'none' | 'unknown') {
|
|
265
|
+
super(message);
|
|
266
|
+
this.name = 'CommandError';
|
|
267
|
+
this.code = code;
|
|
268
|
+
this.written = written;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
189
272
|
export type ElementTreeResultMessage = {
|
|
190
273
|
type: 'elementTreeResult';
|
|
191
274
|
id: string;
|
|
@@ -780,6 +863,10 @@ export type PerformActionResult = {
|
|
|
780
863
|
elementLabel?: string;
|
|
781
864
|
elementType?: string;
|
|
782
865
|
error?: string;
|
|
866
|
+
/** Why the action failed; see {@link CommandError.code}. */
|
|
867
|
+
code?: string;
|
|
868
|
+
/** Whether a failed text action's input reached the app; see {@link CommandError.written}. */
|
|
869
|
+
written?: 'none' | 'unknown';
|
|
783
870
|
};
|
|
784
871
|
|
|
785
872
|
/**
|
|
@@ -833,6 +920,18 @@ export type InstanceClient = {
|
|
|
833
920
|
*/
|
|
834
921
|
elementTreeRaw: (point?: AccessibilityPoint, options?: ElementTreeOptions) => Promise<string>;
|
|
835
922
|
|
|
923
|
+
/**
|
|
924
|
+
* Get the element tree with what the server reports about the screen: the software keyboard,
|
|
925
|
+
* the alert covering the app, and whether the screen settled.
|
|
926
|
+
* @param point Optional point to get the element at that specific location
|
|
927
|
+
*/
|
|
928
|
+
readElementTree: (point?: AccessibilityPoint, options?: ElementTreeOptions) => Promise<ElementTreeRead>;
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Get the element typed text would go to, and the software keyboard.
|
|
932
|
+
*/
|
|
933
|
+
focusedElement: () => Promise<FocusedElement>;
|
|
934
|
+
|
|
836
935
|
/**
|
|
837
936
|
* Tap at the specified coordinates on the active screen (uses native screen dimensions)
|
|
838
937
|
* @param x X coordinate in points
|
|
@@ -1739,6 +1838,12 @@ type ServerResponse = {
|
|
|
1739
1838
|
type: string;
|
|
1740
1839
|
id: string;
|
|
1741
1840
|
error?: string;
|
|
1841
|
+
code?: string;
|
|
1842
|
+
written?: 'none' | 'unknown';
|
|
1843
|
+
// elementTree and focusedElement fields
|
|
1844
|
+
keyboard?: KeyboardState | null;
|
|
1845
|
+
modal?: ModalState | null;
|
|
1846
|
+
idle?: boolean;
|
|
1742
1847
|
// Response-specific fields
|
|
1743
1848
|
base64?: string;
|
|
1744
1849
|
width?: number;
|
|
@@ -2280,6 +2385,13 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2280
2385
|
};
|
|
2281
2386
|
};
|
|
2282
2387
|
|
|
2388
|
+
// A failed batch reports its error at the top level; the failing action's result carries the code.
|
|
2389
|
+
const commandError = (message: ServerResponse): CommandError => {
|
|
2390
|
+
const failedAction = message.results?.find((result) => result.error);
|
|
2391
|
+
const source = failedAction ?? message;
|
|
2392
|
+
return new CommandError(message.error!, source.code, source.written);
|
|
2393
|
+
};
|
|
2394
|
+
|
|
2283
2395
|
// Generic request sender with timeout and response handling
|
|
2284
2396
|
const sendRequest = <T>(
|
|
2285
2397
|
type: string,
|
|
@@ -2534,7 +2646,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2534
2646
|
|
|
2535
2647
|
if (message.error) {
|
|
2536
2648
|
logger.debug(`Server error for ${message.type}: ${message.error}`);
|
|
2537
|
-
request.reject(
|
|
2649
|
+
request.reject(commandError(message));
|
|
2538
2650
|
return;
|
|
2539
2651
|
}
|
|
2540
2652
|
|
|
@@ -2640,6 +2752,8 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2640
2752
|
screenshot,
|
|
2641
2753
|
elementTree,
|
|
2642
2754
|
elementTreeRaw,
|
|
2755
|
+
readElementTree,
|
|
2756
|
+
focusedElement,
|
|
2643
2757
|
tap,
|
|
2644
2758
|
tapWithScreenSize,
|
|
2645
2759
|
tapElement,
|
|
@@ -2735,18 +2849,58 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2735
2849
|
return sendRequest<ScreenshotData>('screenshot', options);
|
|
2736
2850
|
};
|
|
2737
2851
|
|
|
2852
|
+
// An idle wait runs on the server before it answers, so the request waits for it too.
|
|
2853
|
+
const elementTreeTimeoutMs = (options: ElementTreeOptions) =>
|
|
2854
|
+
30_000 + (options.waitForIdleTimeoutMs ?? 0);
|
|
2855
|
+
|
|
2738
2856
|
const elementTree = (
|
|
2739
2857
|
point?: AccessibilityPoint,
|
|
2740
2858
|
options: ElementTreeOptions = {},
|
|
2741
2859
|
): Promise<ElementTree> => {
|
|
2742
|
-
return sendRequest<ElementTree>(
|
|
2860
|
+
return sendRequest<ElementTree>(
|
|
2861
|
+
'elementTree',
|
|
2862
|
+
{ point, ...options },
|
|
2863
|
+
undefined,
|
|
2864
|
+
elementTreeTimeoutMs(options),
|
|
2865
|
+
);
|
|
2743
2866
|
};
|
|
2744
2867
|
|
|
2745
2868
|
const elementTreeRaw = (
|
|
2746
2869
|
point?: AccessibilityPoint,
|
|
2747
2870
|
options: ElementTreeOptions = {},
|
|
2748
2871
|
): Promise<string> => {
|
|
2749
|
-
return sendRequest<string>(
|
|
2872
|
+
return sendRequest<string>(
|
|
2873
|
+
'elementTree',
|
|
2874
|
+
{ point, ...options },
|
|
2875
|
+
(msg) => msg.json ?? '',
|
|
2876
|
+
elementTreeTimeoutMs(options),
|
|
2877
|
+
);
|
|
2878
|
+
};
|
|
2879
|
+
|
|
2880
|
+
const readElementTree = (
|
|
2881
|
+
point?: AccessibilityPoint,
|
|
2882
|
+
options: ElementTreeOptions = {},
|
|
2883
|
+
): Promise<ElementTreeRead> => {
|
|
2884
|
+
return sendRequest<ElementTreeRead>(
|
|
2885
|
+
'elementTree',
|
|
2886
|
+
{ point, ...options },
|
|
2887
|
+
(msg) => {
|
|
2888
|
+
const read: ElementTreeRead = { tree: parseElementTree(msg.json ?? '[]') };
|
|
2889
|
+
// Absent and null differ: null answers "none", absent means the read does not report it.
|
|
2890
|
+
if (msg.keyboard !== undefined) read.keyboard = msg.keyboard;
|
|
2891
|
+
if (msg.modal !== undefined) read.modal = msg.modal;
|
|
2892
|
+
if (msg.idle !== undefined) read.idle = msg.idle;
|
|
2893
|
+
return read;
|
|
2894
|
+
},
|
|
2895
|
+
elementTreeTimeoutMs(options),
|
|
2896
|
+
);
|
|
2897
|
+
};
|
|
2898
|
+
|
|
2899
|
+
const focusedElement = (): Promise<FocusedElement> => {
|
|
2900
|
+
return sendRequest<FocusedElement>('focusedElement', {}, (msg) => ({
|
|
2901
|
+
element: msg.json ? (JSON.parse(msg.json) as ElementTreeNode) : null,
|
|
2902
|
+
keyboard: msg.keyboard ?? null,
|
|
2903
|
+
}));
|
|
2750
2904
|
};
|
|
2751
2905
|
|
|
2752
2906
|
const tap = (x: number, y: number): Promise<void> => {
|
|
@@ -2784,11 +2938,12 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2784
2938
|
);
|
|
2785
2939
|
};
|
|
2786
2940
|
|
|
2787
|
-
// The server fails absent selectors fast with
|
|
2788
|
-
//
|
|
2789
|
-
//
|
|
2790
|
-
// screen")
|
|
2941
|
+
// The server fails absent selectors fast with the element_not_found code. The phrases cover
|
|
2942
|
+
// servers that predate codes: the first is the fail-fast phrase the e2e suite pins, and the
|
|
2943
|
+
// other two are pre-fail-fast servers, whose touch path reports a miss after its own sweep
|
|
2944
|
+
// ("was not found on screen") and whose ax path reports "not found for selector".
|
|
2791
2945
|
const isAbsentSelectorError = (error: unknown): boolean => {
|
|
2946
|
+
if (error instanceof CommandError && error.code === 'element_not_found') return true;
|
|
2792
2947
|
const message = error instanceof Error ? error.message : String(error);
|
|
2793
2948
|
return /matched nothing in the accessibility tree|was not found on screen after scrolling|Accessibility element not found for selector/.test(
|
|
2794
2949
|
message,
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
/** What a project is, wherever it is checked out. */
|
|
5
|
+
export type ProjectIdentity = {
|
|
6
|
+
/** Origin host and repository path, without credentials or the .git suffix. */
|
|
7
|
+
repository: string;
|
|
8
|
+
/** Path from the checkout root to the project, with forward slashes. Empty at the root. */
|
|
9
|
+
directory: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Identify a project from its Git checkout, so clones and worktrees of one repository agree.
|
|
14
|
+
* Reads repository-local files only. Returns undefined outside a checkout, without an origin,
|
|
15
|
+
* or when the metadata cannot be read with confidence.
|
|
16
|
+
*/
|
|
17
|
+
export function projectIdentity(projectPath: string): ProjectIdentity | undefined {
|
|
18
|
+
try {
|
|
19
|
+
const cwd = fs.realpathSync(projectPath);
|
|
20
|
+
const checkout = findCheckout(cwd);
|
|
21
|
+
if (!checkout) return undefined;
|
|
22
|
+
const { root, gitDir } = checkout;
|
|
23
|
+
const common = readOptional(path.join(gitDir, 'commondir'))?.trim();
|
|
24
|
+
const commonDir = common ? path.resolve(gitDir, common) : gitDir;
|
|
25
|
+
const config = parseConfig(readOptional(path.join(commonDir, 'config')) ?? '');
|
|
26
|
+
if (/^(true|yes|on|1)$/i.test(config.get('extensions.worktreeconfig')?.slice(-1)[0] ?? '')) {
|
|
27
|
+
for (const [name, values] of parseConfig(readOptional(path.join(gitDir, 'config.worktree')) ?? '')) {
|
|
28
|
+
config.set(name, [...(config.get(name) ?? []), ...values]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Git fetch uses the first URL when a remote declares more than one.
|
|
32
|
+
const origin = config.get('remote.origin.url')?.[0];
|
|
33
|
+
if (!origin) return undefined;
|
|
34
|
+
const repository = repositoryIdentity(origin);
|
|
35
|
+
if (!repository) return undefined;
|
|
36
|
+
const directory = path.relative(root, cwd).split(path.sep).join('/');
|
|
37
|
+
if (directory === '..' || directory.startsWith('../')) return undefined;
|
|
38
|
+
return { repository, directory };
|
|
39
|
+
} catch {
|
|
40
|
+
// Missing or unsupported metadata leaves the project unidentified.
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Name the folder a project syncs into. A checkout at the repository root is named after the
|
|
47
|
+
* repository, not after the local folder, so every clone and worktree lands in the same place
|
|
48
|
+
* and reuses the same build state. Returns undefined when the project cannot be identified.
|
|
49
|
+
*/
|
|
50
|
+
export function projectFolderName(projectPath: string): string | undefined {
|
|
51
|
+
const project = projectIdentity(projectPath);
|
|
52
|
+
if (!project) return undefined;
|
|
53
|
+
const name = path.posix.basename(project.directory || project.repository);
|
|
54
|
+
return /^[A-Za-z0-9_][A-Za-z0-9._+-]*$/.test(name) ? name : undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function findCheckout(start: string): { root: string; gitDir: string } | undefined {
|
|
58
|
+
for (let root = start; ; root = path.dirname(root)) {
|
|
59
|
+
const marker = path.join(root, '.git');
|
|
60
|
+
if (fs.lstatSync(marker, { throwIfNoEntry: false })) {
|
|
61
|
+
if (fs.statSync(marker).isDirectory()) return { root, gitDir: marker };
|
|
62
|
+
const gitFile = /^gitdir: (.+)$/.exec(fs.readFileSync(marker, 'utf8').trim());
|
|
63
|
+
// A broken nested checkout must not inherit the parent repository's key.
|
|
64
|
+
if (!gitFile) return undefined;
|
|
65
|
+
return { root, gitDir: path.resolve(root, gitFile[1]!) };
|
|
66
|
+
}
|
|
67
|
+
if (path.dirname(root) === root) return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function readOptional(file: string): string | undefined {
|
|
72
|
+
try {
|
|
73
|
+
return fs.readFileSync(file, 'utf8');
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return undefined;
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Read repository-local settings without inheriting machine-specific Git configuration. */
|
|
81
|
+
function parseConfig(text: string): Map<string, string[]> {
|
|
82
|
+
const config = new Map<string, string[]>();
|
|
83
|
+
let section = '';
|
|
84
|
+
for (let line of configLines(text)) {
|
|
85
|
+
line = line.trim();
|
|
86
|
+
if (!line) continue;
|
|
87
|
+
if (line.startsWith('[')) {
|
|
88
|
+
const header = /^\[([\w.-]+)(?:[ \t]+"((?:[^"\\]|\\.)*)")?\](.*)$/.exec(line);
|
|
89
|
+
if (!header) throw new Error('Invalid Git config section');
|
|
90
|
+
section = header[1]!.toLowerCase();
|
|
91
|
+
if (header[2] !== undefined) section += `.${header[2].replace(/\\(.)/g, '$1')}`;
|
|
92
|
+
line = header[3]!.trim();
|
|
93
|
+
if (!line) continue;
|
|
94
|
+
}
|
|
95
|
+
const setting = /^([a-z][a-z0-9-]*)(?:[ \t]*=[ \t]*(.*))?$/i.exec(line);
|
|
96
|
+
if (!section || !setting) throw new Error('Invalid Git config setting');
|
|
97
|
+
const name = `${section}.${setting[1]!.toLowerCase()}`;
|
|
98
|
+
// Includes can replace the origin. Require an explicit key instead of guessing from a partial config.
|
|
99
|
+
if (
|
|
100
|
+
name === 'include.path' ||
|
|
101
|
+
(section.startsWith('includeif.') && setting[1]!.toLowerCase() === 'path')
|
|
102
|
+
) {
|
|
103
|
+
throw new Error('Git config includes require an explicit snapshot key');
|
|
104
|
+
}
|
|
105
|
+
const value = setting[2] === undefined ? 'true' : configValue(setting[2]);
|
|
106
|
+
config.set(name, [...(config.get(name) ?? []), value]);
|
|
107
|
+
}
|
|
108
|
+
return config;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Comments and continuations depend on quoting, so splitting at '#' or newlines alone loses URLs. */
|
|
112
|
+
function configLines(text: string): string[] {
|
|
113
|
+
const lines: string[] = [];
|
|
114
|
+
let line = '';
|
|
115
|
+
let quoted = false;
|
|
116
|
+
let comment = false;
|
|
117
|
+
text = text.replace(/\r\n/g, '\n');
|
|
118
|
+
for (let i = 0; i < text.length; i++) {
|
|
119
|
+
const char = text[i]!;
|
|
120
|
+
if (char === '\n') {
|
|
121
|
+
if (quoted) throw new Error('Unterminated Git config quote');
|
|
122
|
+
lines.push(line);
|
|
123
|
+
line = '';
|
|
124
|
+
comment = false;
|
|
125
|
+
} else if (!comment) {
|
|
126
|
+
if (char === '\\') {
|
|
127
|
+
const next = text[++i];
|
|
128
|
+
if (next === undefined) throw new Error('Incomplete Git config escape');
|
|
129
|
+
if (next !== '\n') line += char + next;
|
|
130
|
+
} else if (!quoted && (char === '#' || char === ';')) {
|
|
131
|
+
comment = true;
|
|
132
|
+
} else {
|
|
133
|
+
if (char === '"') quoted = !quoted;
|
|
134
|
+
line += char;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (quoted) throw new Error('Unterminated Git config quote');
|
|
139
|
+
lines.push(line);
|
|
140
|
+
return lines;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function configValue(raw: string): string {
|
|
144
|
+
const escapes: Record<string, string> = { n: '\n', t: '\t', b: '\b', '\\': '\\', '"': '"' };
|
|
145
|
+
let value = '';
|
|
146
|
+
for (let i = 0; i < raw.length; i++) {
|
|
147
|
+
const char = raw[i]!;
|
|
148
|
+
if (char === '\\') {
|
|
149
|
+
const escaped = escapes[raw[++i]!];
|
|
150
|
+
if (escaped === undefined) throw new Error('Invalid Git config escape');
|
|
151
|
+
value += escaped;
|
|
152
|
+
} else if (char !== '"') {
|
|
153
|
+
value += char;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function repositoryIdentity(remote: string): string | undefined {
|
|
160
|
+
let host: string;
|
|
161
|
+
let repo: string;
|
|
162
|
+
if (remote.includes('://')) {
|
|
163
|
+
const url = new URL(remote);
|
|
164
|
+
if (!['https:', 'http:', 'ssh:', 'git:'].includes(url.protocol)) return undefined;
|
|
165
|
+
host = url.host.toLowerCase();
|
|
166
|
+
repo = url.pathname;
|
|
167
|
+
} else {
|
|
168
|
+
const scp = /^(?:[^/@:\s]+@)?([^/:\s]+):(.+)$/.exec(remote);
|
|
169
|
+
if (!scp || /^[A-Za-z]:[\\/]/.test(remote)) return undefined;
|
|
170
|
+
host = scp[1]!.toLowerCase();
|
|
171
|
+
repo = scp[2]!;
|
|
172
|
+
}
|
|
173
|
+
repo = repo.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
|
|
174
|
+
if (!repo || repo.split('/').some((part) => !part || part === '.' || part === '..')) return undefined;
|
|
175
|
+
// GitHub repository names are case-insensitive; other hosts may preserve case.
|
|
176
|
+
if (host === 'github.com') repo = repo.toLowerCase();
|
|
177
|
+
return `${host}/${repo}`;
|
|
178
|
+
}
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
type FolderSyncOptions,
|
|
49
49
|
} from '../folder-sync';
|
|
50
50
|
import { createIgnoreFn } from '../folder-sync-ignore';
|
|
51
|
+
import { projectFolderName } from '../project-identity';
|
|
51
52
|
import {
|
|
52
53
|
createBuildRun,
|
|
53
54
|
type BuildRunOptions,
|
|
@@ -104,6 +105,12 @@ export type SyncOptions = {
|
|
|
104
105
|
additionalFiles?: AdditionalFileSyncEntry[];
|
|
105
106
|
/** Called after every successful sync, including watch-triggered re-syncs. */
|
|
106
107
|
onSyncComplete?: FolderSyncOptions['onSyncComplete'];
|
|
108
|
+
/**
|
|
109
|
+
* Folder the project syncs into on the instance. Defaults to a name taken from the Git
|
|
110
|
+
* repository, so every clone and worktree of a project shares one folder and its build state.
|
|
111
|
+
* A project outside Git uses the local folder's name.
|
|
112
|
+
*/
|
|
113
|
+
rootName?: string;
|
|
107
114
|
};
|
|
108
115
|
|
|
109
116
|
export type XcodeRunOptions = BuildRunOptions;
|
|
@@ -1021,6 +1028,9 @@ export class XcodeInstances extends GeneratedXcodeInstances {
|
|
|
1021
1028
|
},
|
|
1022
1029
|
async sync(localCodePath: string, opts?: SyncOptions): Promise<SyncResult> {
|
|
1023
1030
|
const { cacheKey, basisCacheDir } = deriveBasisCache(localCodePath, opts?.basisCacheDir);
|
|
1031
|
+
// Build state on the instance is tied to this folder's path. A name taken from the local
|
|
1032
|
+
// folder gives each worktree its own path, so none could reuse another's snapshot.
|
|
1033
|
+
const rootName = opts?.rootName ?? projectFolderName(localCodePath);
|
|
1024
1034
|
const codeSyncOpts: FolderSyncOptions = {
|
|
1025
1035
|
apiUrl,
|
|
1026
1036
|
token,
|
|
@@ -1043,6 +1053,7 @@ export class XcodeInstances extends GeneratedXcodeInstances {
|
|
|
1043
1053
|
syncSymlinks: true,
|
|
1044
1054
|
...(opts?.additionalFiles && { additionalFiles: opts.additionalFiles }),
|
|
1045
1055
|
...(opts?.onSyncComplete ? { onSyncComplete: opts.onSyncComplete } : {}),
|
|
1056
|
+
...(rootName ? { rootName } : {}),
|
|
1046
1057
|
};
|
|
1047
1058
|
|
|
1048
1059
|
const result = await syncFolderImpl(localCodePath, codeSyncOpts);
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.78.1'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.78.1";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.78.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.78.1'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|