@innovatorved/code-lab 0.1.0 → 0.1.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/README.md +3 -3
- package/dist/code-lab.css +209 -1
- package/dist/code-lab.esm.js +253 -16
- package/dist/code-lab.js +253 -16
- package/dist/shell.esm.js +52 -1
- package/dist/shell.js +52 -1
- package/package.json +2 -2
- package/src/code-lab.css +209 -1
- package/src/shell.js +52 -1
- package/src/shell.ts +28 -1
- package/src/workbench.js +201 -15
- package/src/workbench.ts +201 -15
package/dist/shell.js
CHANGED
|
@@ -2005,6 +2005,10 @@
|
|
|
2005
2005
|
}
|
|
2006
2006
|
|
|
2007
2007
|
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
2008
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
2009
|
+
if (onProgress) {
|
|
2010
|
+
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
2011
|
+
}
|
|
2008
2012
|
const parsed = parseGitHubRepoUrl(repoInput);
|
|
2009
2013
|
if (!parsed) {
|
|
2010
2014
|
throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
|
|
@@ -2028,6 +2032,10 @@
|
|
|
2028
2032
|
let rawTreeEntries = null;
|
|
2029
2033
|
let repoNotFound = false;
|
|
2030
2034
|
|
|
2035
|
+
if (onProgress) {
|
|
2036
|
+
onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2031
2039
|
// Strategy A: GitHub REST API (with automatic fallback if rate-limited)
|
|
2032
2040
|
try {
|
|
2033
2041
|
if (!resolvedBranch) {
|
|
@@ -2132,6 +2140,11 @@
|
|
|
2132
2140
|
|
|
2133
2141
|
filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
|
|
2134
2142
|
const selectedFiles = filtered.slice(0, maxFiles);
|
|
2143
|
+
const totalToDownload = selectedFiles.length;
|
|
2144
|
+
|
|
2145
|
+
if (onProgress) {
|
|
2146
|
+
onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
|
|
2147
|
+
}
|
|
2135
2148
|
|
|
2136
2149
|
if (!vfs.existsSync(targetDir)) {
|
|
2137
2150
|
vfs.mkdirSync(targetDir, { recursive: true });
|
|
@@ -2177,6 +2190,9 @@
|
|
|
2177
2190
|
headSnapshot[entry.destPath] = text;
|
|
2178
2191
|
filesWritten++;
|
|
2179
2192
|
totalBytes += text.length;
|
|
2193
|
+
if (onProgress) {
|
|
2194
|
+
onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
|
|
2195
|
+
}
|
|
2180
2196
|
if (typeof options.onFile === 'function') {
|
|
2181
2197
|
options.onFile(absPath, text, entry.destPath);
|
|
2182
2198
|
}
|
|
@@ -2185,6 +2201,10 @@
|
|
|
2185
2201
|
);
|
|
2186
2202
|
}
|
|
2187
2203
|
|
|
2204
|
+
if (onProgress) {
|
|
2205
|
+
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2188
2208
|
// Write .git metadata inside targetDir
|
|
2189
2209
|
const gitDir = PosixPath.join(targetDir, '.git');
|
|
2190
2210
|
if (!vfs.existsSync(gitDir)) {
|
|
@@ -2233,6 +2253,10 @@
|
|
|
2233
2253
|
];
|
|
2234
2254
|
}
|
|
2235
2255
|
|
|
2256
|
+
if (onProgress) {
|
|
2257
|
+
onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2236
2260
|
return {
|
|
2237
2261
|
owner,
|
|
2238
2262
|
repo,
|
|
@@ -4432,12 +4456,37 @@
|
|
|
4432
4456
|
dirDisplayName = parsed.repo;
|
|
4433
4457
|
}
|
|
4434
4458
|
|
|
4459
|
+
// Stream clone progress to the terminal as it happens (no end-of-run buffering).
|
|
4460
|
+
const canStream = typeof ctx.onStdout === 'function';
|
|
4461
|
+
const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
|
|
4462
|
+
streamLine(`Cloning into '${dirDisplayName}'...\n`);
|
|
4463
|
+
let enumeratedEmitted = false;
|
|
4464
|
+
let lastProgressPct = -1;
|
|
4465
|
+
|
|
4435
4466
|
try {
|
|
4436
4467
|
const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
|
|
4437
4468
|
targetDir,
|
|
4438
4469
|
branch: branchOpt,
|
|
4439
4470
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4440
|
-
onFile: (absPath) => ctx.emitMutation('create', absPath)
|
|
4471
|
+
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
4472
|
+
onProgress: (ev) => {
|
|
4473
|
+
if (!ev) return;
|
|
4474
|
+
if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
|
|
4475
|
+
enumeratedEmitted = true;
|
|
4476
|
+
streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
|
|
4477
|
+
streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
|
|
4478
|
+
}
|
|
4479
|
+
if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
|
|
4480
|
+
const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
|
|
4481
|
+
if (pct >= lastProgressPct + 10) {
|
|
4482
|
+
lastProgressPct = pct;
|
|
4483
|
+
streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
if (ev.phase === 'mounting') {
|
|
4487
|
+
streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4441
4490
|
});
|
|
4442
4491
|
|
|
4443
4492
|
gitState.branch = result.branch;
|
|
@@ -4451,6 +4500,7 @@
|
|
|
4451
4500
|
|
|
4452
4501
|
const count = Math.max(1, result.filesWritten);
|
|
4453
4502
|
const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
|
|
4503
|
+
streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
|
|
4454
4504
|
const stdout =
|
|
4455
4505
|
`Cloning into '${dirDisplayName}'...\n` +
|
|
4456
4506
|
`remote: Enumerating objects: ${count}, done.\n` +
|
|
@@ -4459,6 +4509,7 @@
|
|
|
4459
4509
|
return { code: 0, stdout, stderr: '' };
|
|
4460
4510
|
} catch (err) {
|
|
4461
4511
|
const msg = err && err.message ? err.message : String(err);
|
|
4512
|
+
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
4462
4513
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
4463
4514
|
}
|
|
4464
4515
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innovatorved/code-lab",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Standalone browser-native IDE Workbench, POSIX Shell & Coreutils, PTY Terminal, and Web Worker Node.js/Bun Virtual Runtime.",
|
|
5
5
|
"main": "./dist/code-lab.js",
|
|
6
6
|
"module": "./dist/code-lab.esm.js",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"build": "bun run tools/bundle.js",
|
|
73
73
|
"typecheck": "bun x tsc --noEmit",
|
|
74
74
|
"test": "bun run tests/test-all-builds.js",
|
|
75
|
-
"test:all": "bun run tools/bundle.js && bun run tests/test-all-builds.js && bun run tests/test-runtime-advanced.js && bun run tests/test-option1-shell-bun-http.js && bun run tests/test-coreutils-adversarial.js && bun run tests/test-stress-shell.js && bun run tests/test-workbench-ui.js && bun run tests/test-terminal-streaming.js && bun run tests/test-m1-adversarial-challenger.js && bun run tests/test-m1-interruption-lifecycle-stress.js && bun run tests/test-gfm-markdown.js && bun run tests/test-m2-adversarial-syntax.js && bun run tests/test-m2-adversarial-interactive.js && bun run tests/test-web-preview.js && bun run tests/test-preview-sw.js",
|
|
75
|
+
"test:all": "bun run tools/bundle.js && bun run tests/test-all-builds.js && bun run tests/test-runtime-advanced.js && bun run tests/test-option1-shell-bun-http.js && bun run tests/test-coreutils-adversarial.js && bun run tests/test-stress-shell.js && bun run tests/test-workbench-ui.js && bun run tests/test-terminal-streaming.js && bun run tests/test-git-clone-streaming.js && bun run tests/test-m1-adversarial-challenger.js && bun run tests/test-m1-interruption-lifecycle-stress.js && bun run tests/test-gfm-markdown.js && bun run tests/test-m2-adversarial-syntax.js && bun run tests/test-m2-adversarial-interactive.js && bun run tests/test-web-preview.js && bun run tests/test-preview-sw.js",
|
|
76
76
|
"pack:check": "bun pm pack --dry-run"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
package/src/code-lab.css
CHANGED
|
@@ -1803,12 +1803,26 @@ code-lab,
|
|
|
1803
1803
|
display: flex;
|
|
1804
1804
|
align-items: center;
|
|
1805
1805
|
justify-content: space-between;
|
|
1806
|
+
gap: 8px;
|
|
1806
1807
|
height: 36px;
|
|
1807
1808
|
padding: 0 14px;
|
|
1808
1809
|
background: var(--cl-bg);
|
|
1809
1810
|
border-bottom: 1px solid var(--cl-border);
|
|
1810
1811
|
flex-shrink: 0;
|
|
1811
1812
|
user-select: none;
|
|
1813
|
+
min-width: 0;
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
/* Keep the Clear / minimize controls pinned while the tab strip scrolls. */
|
|
1817
|
+
.codelab-drawer__bar > div:last-child {
|
|
1818
|
+
flex-shrink: 0;
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
/* On narrow/guided layouts, drop the tab pill badges so labels never wrap. */
|
|
1822
|
+
@media (max-width: 720px) {
|
|
1823
|
+
.codelab-drawer__tab .codelab-drawer__pill {
|
|
1824
|
+
display: none;
|
|
1825
|
+
}
|
|
1812
1826
|
}
|
|
1813
1827
|
|
|
1814
1828
|
.codelab-drawer__tabs {
|
|
@@ -1816,6 +1830,17 @@ code-lab,
|
|
|
1816
1830
|
align-items: center;
|
|
1817
1831
|
gap: 4px;
|
|
1818
1832
|
height: 100%;
|
|
1833
|
+
flex: 1 1 auto;
|
|
1834
|
+
flex-wrap: nowrap;
|
|
1835
|
+
min-width: 0;
|
|
1836
|
+
overflow-x: auto;
|
|
1837
|
+
overflow-y: hidden;
|
|
1838
|
+
scrollbar-width: none;
|
|
1839
|
+
-ms-overflow-style: none;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
.codelab-drawer__tabs::-webkit-scrollbar {
|
|
1843
|
+
display: none;
|
|
1819
1844
|
}
|
|
1820
1845
|
|
|
1821
1846
|
.codelab-drawer__tab {
|
|
@@ -1831,6 +1856,8 @@ code-lab,
|
|
|
1831
1856
|
border: none;
|
|
1832
1857
|
cursor: pointer;
|
|
1833
1858
|
transition: all 100ms ease;
|
|
1859
|
+
flex-shrink: 0;
|
|
1860
|
+
white-space: nowrap;
|
|
1834
1861
|
}
|
|
1835
1862
|
|
|
1836
1863
|
.codelab-drawer__tab:hover {
|
|
@@ -2319,7 +2346,7 @@ code-lab,
|
|
|
2319
2346
|
font-size: 11.5px;
|
|
2320
2347
|
color: var(--cl-fg-muted);
|
|
2321
2348
|
user-select: none;
|
|
2322
|
-
overflow
|
|
2349
|
+
overflow: visible;
|
|
2323
2350
|
}
|
|
2324
2351
|
|
|
2325
2352
|
.codelab-guide__expand-btn {
|
|
@@ -2353,12 +2380,30 @@ code-lab,
|
|
|
2353
2380
|
display: inline-flex;
|
|
2354
2381
|
}
|
|
2355
2382
|
|
|
2383
|
+
.codelab-breadcrumbs__left {
|
|
2384
|
+
display: inline-flex;
|
|
2385
|
+
align-items: center;
|
|
2386
|
+
gap: 8px;
|
|
2387
|
+
min-width: 0;
|
|
2388
|
+
flex: 1 1 auto;
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2356
2391
|
.codelab-breadcrumbs__path {
|
|
2357
2392
|
display: inline-flex;
|
|
2358
2393
|
align-items: center;
|
|
2359
2394
|
gap: 4px;
|
|
2360
2395
|
min-width: 0;
|
|
2361
2396
|
white-space: nowrap;
|
|
2397
|
+
overflow-x: auto;
|
|
2398
|
+
scrollbar-width: none;
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
.codelab-breadcrumbs__path::-webkit-scrollbar {
|
|
2402
|
+
display: none;
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
.codelab-breadcrumbs__item--folder {
|
|
2406
|
+
color: var(--cl-fg-muted);
|
|
2362
2407
|
}
|
|
2363
2408
|
|
|
2364
2409
|
.codelab-breadcrumbs__item {
|
|
@@ -2412,6 +2457,161 @@ code-lab,
|
|
|
2412
2457
|
flex-shrink: 0;
|
|
2413
2458
|
}
|
|
2414
2459
|
|
|
2460
|
+
/* ── Workspace Folder Switcher (breadcrumb dropdown) ───────────────────── */
|
|
2461
|
+
.codelab-folder-switcher {
|
|
2462
|
+
position: relative;
|
|
2463
|
+
display: inline-flex;
|
|
2464
|
+
align-items: center;
|
|
2465
|
+
flex-shrink: 0;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
.codelab-folder-switcher__toggle {
|
|
2469
|
+
display: inline-flex;
|
|
2470
|
+
align-items: center;
|
|
2471
|
+
gap: 5px;
|
|
2472
|
+
height: 20px;
|
|
2473
|
+
padding: 0 7px;
|
|
2474
|
+
border: 1px solid var(--cl-border);
|
|
2475
|
+
border-radius: 4px;
|
|
2476
|
+
background: var(--cl-bg);
|
|
2477
|
+
color: var(--cl-fg-muted);
|
|
2478
|
+
font-family: var(--cl-font-sans);
|
|
2479
|
+
font-size: 11px;
|
|
2480
|
+
cursor: pointer;
|
|
2481
|
+
white-space: nowrap;
|
|
2482
|
+
box-sizing: border-box;
|
|
2483
|
+
transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
.codelab-folder-switcher__toggle:hover,
|
|
2487
|
+
.codelab-folder-switcher.is-open .codelab-folder-switcher__toggle {
|
|
2488
|
+
background: var(--cl-bg-hover);
|
|
2489
|
+
color: var(--cl-fg);
|
|
2490
|
+
border-color: var(--cl-border-strong);
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
.codelab-folder-switcher__toggle.is-scoped {
|
|
2494
|
+
color: var(--cl-fg);
|
|
2495
|
+
border-color: var(--cl-border-strong);
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
.codelab-folder-switcher__label {
|
|
2499
|
+
max-width: 160px;
|
|
2500
|
+
overflow: hidden;
|
|
2501
|
+
text-overflow: ellipsis;
|
|
2502
|
+
white-space: nowrap;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
.codelab-folder-switcher__menu {
|
|
2506
|
+
position: absolute;
|
|
2507
|
+
top: calc(100% + 5px);
|
|
2508
|
+
left: 0;
|
|
2509
|
+
z-index: 90;
|
|
2510
|
+
min-width: 230px;
|
|
2511
|
+
max-width: 340px;
|
|
2512
|
+
max-height: 300px;
|
|
2513
|
+
overflow-y: auto;
|
|
2514
|
+
padding: 4px;
|
|
2515
|
+
background: var(--cl-bg-elevated);
|
|
2516
|
+
border: 1px solid var(--cl-border-strong);
|
|
2517
|
+
border-radius: 6px;
|
|
2518
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
|
|
2519
|
+
display: flex;
|
|
2520
|
+
flex-direction: column;
|
|
2521
|
+
gap: 1px;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
.codelab-folder-switcher__section {
|
|
2525
|
+
padding: 4px 8px 6px;
|
|
2526
|
+
font-family: var(--cl-font-sans);
|
|
2527
|
+
font-size: 10px;
|
|
2528
|
+
text-transform: uppercase;
|
|
2529
|
+
letter-spacing: 0.05em;
|
|
2530
|
+
color: var(--cl-fg-subtle);
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
.codelab-folder-switcher__option {
|
|
2534
|
+
display: flex;
|
|
2535
|
+
align-items: center;
|
|
2536
|
+
gap: 6px;
|
|
2537
|
+
width: 100%;
|
|
2538
|
+
padding: 5px 8px;
|
|
2539
|
+
border: none;
|
|
2540
|
+
border-radius: 4px;
|
|
2541
|
+
background: transparent;
|
|
2542
|
+
color: var(--cl-fg-muted);
|
|
2543
|
+
font-family: var(--cl-font-mono);
|
|
2544
|
+
font-size: 11.5px;
|
|
2545
|
+
text-align: left;
|
|
2546
|
+
cursor: pointer;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
.codelab-folder-switcher__option:hover {
|
|
2550
|
+
background: var(--cl-bg-hover);
|
|
2551
|
+
color: var(--cl-fg);
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
.codelab-folder-switcher__option.active {
|
|
2555
|
+
background: var(--cl-bg-hover);
|
|
2556
|
+
color: var(--cl-fg);
|
|
2557
|
+
font-weight: 600;
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
.codelab-folder-switcher__icon {
|
|
2561
|
+
display: inline-flex;
|
|
2562
|
+
flex-shrink: 0;
|
|
2563
|
+
color: var(--cl-fg-subtle);
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
.codelab-folder-switcher__name {
|
|
2567
|
+
overflow: hidden;
|
|
2568
|
+
text-overflow: ellipsis;
|
|
2569
|
+
white-space: nowrap;
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
.codelab-folder-switcher__path {
|
|
2573
|
+
margin-left: auto;
|
|
2574
|
+
padding-left: 12px;
|
|
2575
|
+
color: var(--cl-fg-subtle);
|
|
2576
|
+
font-size: 10px;
|
|
2577
|
+
overflow: hidden;
|
|
2578
|
+
text-overflow: ellipsis;
|
|
2579
|
+
white-space: nowrap;
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
.codelab-folder-switcher__empty {
|
|
2583
|
+
padding: 8px;
|
|
2584
|
+
font-size: 11px;
|
|
2585
|
+
color: var(--cl-fg-muted);
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
/* Scoped-explorer "back to workspace" row */
|
|
2589
|
+
.codelab-scope-up {
|
|
2590
|
+
display: flex;
|
|
2591
|
+
align-items: center;
|
|
2592
|
+
gap: 8px;
|
|
2593
|
+
width: 100%;
|
|
2594
|
+
padding: 5px 10px;
|
|
2595
|
+
margin-bottom: 2px;
|
|
2596
|
+
border: none;
|
|
2597
|
+
border-bottom: 1px dashed var(--cl-border);
|
|
2598
|
+
background: transparent;
|
|
2599
|
+
color: var(--cl-fg-muted);
|
|
2600
|
+
font-family: var(--cl-font-mono);
|
|
2601
|
+
font-size: 11.5px;
|
|
2602
|
+
text-align: left;
|
|
2603
|
+
cursor: pointer;
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
.codelab-scope-up:hover {
|
|
2607
|
+
color: var(--cl-fg);
|
|
2608
|
+
background: var(--cl-bg-hover);
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
.codelab-scope-up__arrow {
|
|
2612
|
+
color: var(--cl-fg-subtle);
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2415
2615
|
.codelab-breadcrumb__btn,
|
|
2416
2616
|
.codelab-breadcrumbs__btn {
|
|
2417
2617
|
display: inline-flex;
|
|
@@ -3958,6 +4158,14 @@ code-lab,
|
|
|
3958
4158
|
to { opacity: 1; transform: translateY(0); }
|
|
3959
4159
|
}
|
|
3960
4160
|
|
|
4161
|
+
.codelab-toast--info .codelab-toast__icon { color: var(--cl-blue); }
|
|
4162
|
+
|
|
4163
|
+
.codelab-toast--error {
|
|
4164
|
+
border-color: var(--cl-red);
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
.codelab-toast--error .codelab-toast__icon { color: var(--cl-red); }
|
|
4168
|
+
|
|
3961
4169
|
.codelab-toast__icon {
|
|
3962
4170
|
color: var(--cl-green);
|
|
3963
4171
|
flex: 0 0 auto;
|
package/src/shell.js
CHANGED
|
@@ -1986,6 +1986,10 @@
|
|
|
1986
1986
|
}
|
|
1987
1987
|
|
|
1988
1988
|
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
1989
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
1990
|
+
if (onProgress) {
|
|
1991
|
+
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
1992
|
+
}
|
|
1989
1993
|
const parsed = parseGitHubRepoUrl(repoInput);
|
|
1990
1994
|
if (!parsed) {
|
|
1991
1995
|
throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
|
|
@@ -2009,6 +2013,10 @@
|
|
|
2009
2013
|
let rawTreeEntries = null;
|
|
2010
2014
|
let repoNotFound = false;
|
|
2011
2015
|
|
|
2016
|
+
if (onProgress) {
|
|
2017
|
+
onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2012
2020
|
// Strategy A: GitHub REST API (with automatic fallback if rate-limited)
|
|
2013
2021
|
try {
|
|
2014
2022
|
if (!resolvedBranch) {
|
|
@@ -2113,6 +2121,11 @@
|
|
|
2113
2121
|
|
|
2114
2122
|
filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
|
|
2115
2123
|
const selectedFiles = filtered.slice(0, maxFiles);
|
|
2124
|
+
const totalToDownload = selectedFiles.length;
|
|
2125
|
+
|
|
2126
|
+
if (onProgress) {
|
|
2127
|
+
onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
|
|
2128
|
+
}
|
|
2116
2129
|
|
|
2117
2130
|
if (!vfs.existsSync(targetDir)) {
|
|
2118
2131
|
vfs.mkdirSync(targetDir, { recursive: true });
|
|
@@ -2158,6 +2171,9 @@
|
|
|
2158
2171
|
headSnapshot[entry.destPath] = text;
|
|
2159
2172
|
filesWritten++;
|
|
2160
2173
|
totalBytes += text.length;
|
|
2174
|
+
if (onProgress) {
|
|
2175
|
+
onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
|
|
2176
|
+
}
|
|
2161
2177
|
if (typeof options.onFile === 'function') {
|
|
2162
2178
|
options.onFile(absPath, text, entry.destPath);
|
|
2163
2179
|
}
|
|
@@ -2166,6 +2182,10 @@
|
|
|
2166
2182
|
);
|
|
2167
2183
|
}
|
|
2168
2184
|
|
|
2185
|
+
if (onProgress) {
|
|
2186
|
+
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2169
2189
|
// Write .git metadata inside targetDir
|
|
2170
2190
|
const gitDir = PosixPath.join(targetDir, '.git');
|
|
2171
2191
|
if (!vfs.existsSync(gitDir)) {
|
|
@@ -2214,6 +2234,10 @@
|
|
|
2214
2234
|
];
|
|
2215
2235
|
}
|
|
2216
2236
|
|
|
2237
|
+
if (onProgress) {
|
|
2238
|
+
onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2217
2241
|
return {
|
|
2218
2242
|
owner,
|
|
2219
2243
|
repo,
|
|
@@ -4413,12 +4437,37 @@
|
|
|
4413
4437
|
dirDisplayName = parsed.repo;
|
|
4414
4438
|
}
|
|
4415
4439
|
|
|
4440
|
+
// Stream clone progress to the terminal as it happens (no end-of-run buffering).
|
|
4441
|
+
const canStream = typeof ctx.onStdout === 'function';
|
|
4442
|
+
const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
|
|
4443
|
+
streamLine(`Cloning into '${dirDisplayName}'...\n`);
|
|
4444
|
+
let enumeratedEmitted = false;
|
|
4445
|
+
let lastProgressPct = -1;
|
|
4446
|
+
|
|
4416
4447
|
try {
|
|
4417
4448
|
const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
|
|
4418
4449
|
targetDir,
|
|
4419
4450
|
branch: branchOpt,
|
|
4420
4451
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4421
|
-
onFile: (absPath) => ctx.emitMutation('create', absPath)
|
|
4452
|
+
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
4453
|
+
onProgress: (ev) => {
|
|
4454
|
+
if (!ev) return;
|
|
4455
|
+
if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
|
|
4456
|
+
enumeratedEmitted = true;
|
|
4457
|
+
streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
|
|
4458
|
+
streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
|
|
4459
|
+
}
|
|
4460
|
+
if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
|
|
4461
|
+
const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
|
|
4462
|
+
if (pct >= lastProgressPct + 10) {
|
|
4463
|
+
lastProgressPct = pct;
|
|
4464
|
+
streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4467
|
+
if (ev.phase === 'mounting') {
|
|
4468
|
+
streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
|
|
4469
|
+
}
|
|
4470
|
+
}
|
|
4422
4471
|
});
|
|
4423
4472
|
|
|
4424
4473
|
gitState.branch = result.branch;
|
|
@@ -4432,6 +4481,7 @@
|
|
|
4432
4481
|
|
|
4433
4482
|
const count = Math.max(1, result.filesWritten);
|
|
4434
4483
|
const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
|
|
4484
|
+
streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
|
|
4435
4485
|
const stdout =
|
|
4436
4486
|
`Cloning into '${dirDisplayName}'...\n` +
|
|
4437
4487
|
`remote: Enumerating objects: ${count}, done.\n` +
|
|
@@ -4440,6 +4490,7 @@
|
|
|
4440
4490
|
return { code: 0, stdout, stderr: '' };
|
|
4441
4491
|
} catch (err) {
|
|
4442
4492
|
const msg = err && err.message ? err.message : String(err);
|
|
4493
|
+
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
4443
4494
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
4444
4495
|
}
|
|
4445
4496
|
}
|
package/src/shell.ts
CHANGED
|
@@ -4487,12 +4487,37 @@ function __initShellModule(root: any) {
|
|
|
4487
4487
|
dirDisplayName = parsed.repo;
|
|
4488
4488
|
}
|
|
4489
4489
|
|
|
4490
|
+
// Stream clone progress to the terminal as it happens (no end-of-run buffering).
|
|
4491
|
+
const canStream = typeof ctx.onStdout === 'function';
|
|
4492
|
+
const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
|
|
4493
|
+
streamLine(`Cloning into '${dirDisplayName}'...\n`);
|
|
4494
|
+
let enumeratedEmitted = false;
|
|
4495
|
+
let lastProgressPct = -1;
|
|
4496
|
+
|
|
4490
4497
|
try {
|
|
4491
4498
|
const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
|
|
4492
4499
|
targetDir,
|
|
4493
4500
|
branch: branchOpt,
|
|
4494
4501
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4495
|
-
onFile: (absPath) => ctx.emitMutation('create', absPath)
|
|
4502
|
+
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
4503
|
+
onProgress: (ev) => {
|
|
4504
|
+
if (!ev) return;
|
|
4505
|
+
if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
|
|
4506
|
+
enumeratedEmitted = true;
|
|
4507
|
+
streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
|
|
4508
|
+
streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
|
|
4509
|
+
}
|
|
4510
|
+
if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
|
|
4511
|
+
const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
|
|
4512
|
+
if (pct >= lastProgressPct + 10) {
|
|
4513
|
+
lastProgressPct = pct;
|
|
4514
|
+
streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
if (ev.phase === 'mounting') {
|
|
4518
|
+
streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4496
4521
|
});
|
|
4497
4522
|
|
|
4498
4523
|
gitState.branch = result.branch;
|
|
@@ -4506,6 +4531,7 @@ function __initShellModule(root: any) {
|
|
|
4506
4531
|
|
|
4507
4532
|
const count = Math.max(1, result.filesWritten);
|
|
4508
4533
|
const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
|
|
4534
|
+
streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
|
|
4509
4535
|
const stdout =
|
|
4510
4536
|
`Cloning into '${dirDisplayName}'...\n` +
|
|
4511
4537
|
`remote: Enumerating objects: ${count}, done.\n` +
|
|
@@ -4514,6 +4540,7 @@ function __initShellModule(root: any) {
|
|
|
4514
4540
|
return { code: 0, stdout, stderr: '' };
|
|
4515
4541
|
} catch (err) {
|
|
4516
4542
|
const msg = err && err.message ? err.message : String(err);
|
|
4543
|
+
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
4517
4544
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
4518
4545
|
}
|
|
4519
4546
|
}
|