@innovatorved/code-lab 0.1.1 → 0.1.3
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/dist/code-lab.css +78 -31
- package/dist/code-lab.d.ts +1 -0
- package/dist/code-lab.esm.js +226 -93
- package/dist/code-lab.js +226 -93
- package/dist/shell.esm.js +38 -8
- package/dist/shell.js +38 -8
- package/package.json +1 -1
- package/src/code-lab.css +78 -31
- package/src/shell.js +38 -8
- package/src/shell.ts +38 -8
- package/src/workbench.js +188 -85
- package/src/workbench.ts +188 -85
package/src/shell.ts
CHANGED
|
@@ -2025,6 +2025,16 @@ function __initShellModule(root: any) {
|
|
|
2025
2025
|
const requestedBranch = options.branch || parsed.branch || null;
|
|
2026
2026
|
const { owner, repo } = parsed;
|
|
2027
2027
|
|
|
2028
|
+
const signal = options.signal || null;
|
|
2029
|
+
const throwIfAborted = () => {
|
|
2030
|
+
if (signal && signal.aborted) {
|
|
2031
|
+
const abortErr = new Error('fatal: clone cancelled (SIGINT)');
|
|
2032
|
+
abortErr.name = 'AbortError';
|
|
2033
|
+
throw abortErr;
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
throwIfAborted();
|
|
2037
|
+
|
|
2028
2038
|
if (onProgress) {
|
|
2029
2039
|
onProgress({
|
|
2030
2040
|
phase: 'metadata',
|
|
@@ -2040,7 +2050,8 @@ function __initShellModule(root: any) {
|
|
|
2040
2050
|
try {
|
|
2041
2051
|
if (!resolvedBranch) {
|
|
2042
2052
|
const metaRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
2043
|
-
headers: { Accept: 'application/vnd.github.v3+json' }
|
|
2053
|
+
headers: { Accept: 'application/vnd.github.v3+json' },
|
|
2054
|
+
signal
|
|
2044
2055
|
});
|
|
2045
2056
|
if (metaRes.status === 404) {
|
|
2046
2057
|
repoNotFound = true;
|
|
@@ -2058,9 +2069,10 @@ function __initShellModule(root: any) {
|
|
|
2058
2069
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
2059
2070
|
|
|
2060
2071
|
for (const cand of branchCandidates) {
|
|
2072
|
+
throwIfAborted();
|
|
2061
2073
|
const treeRes = await fetchFn(
|
|
2062
2074
|
`https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(cand)}?recursive=1`,
|
|
2063
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
2075
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
2064
2076
|
);
|
|
2065
2077
|
if (treeRes.ok) {
|
|
2066
2078
|
const treeJson = await treeRes.json();
|
|
@@ -2086,8 +2098,10 @@ function __initShellModule(root: any) {
|
|
|
2086
2098
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
2087
2099
|
|
|
2088
2100
|
for (const cand of branchCandidates) {
|
|
2101
|
+
throwIfAborted();
|
|
2089
2102
|
const flatRes = await fetchFn(
|
|
2090
|
-
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat
|
|
2103
|
+
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`,
|
|
2104
|
+
{ signal }
|
|
2091
2105
|
);
|
|
2092
2106
|
if (flatRes && flatRes.ok) {
|
|
2093
2107
|
const flatJson = await flatRes.json();
|
|
@@ -2161,28 +2175,34 @@ function __initShellModule(root: any) {
|
|
|
2161
2175
|
const BATCH_SIZE = 12;
|
|
2162
2176
|
|
|
2163
2177
|
for (let i = 0; i < selectedFiles.length; i += BATCH_SIZE) {
|
|
2178
|
+
throwIfAborted();
|
|
2164
2179
|
const batch = selectedFiles.slice(i, i + BATCH_SIZE);
|
|
2165
2180
|
await Promise.all(
|
|
2166
2181
|
batch.map(async (entry) => {
|
|
2182
|
+
throwIfAborted();
|
|
2167
2183
|
const encodedPath = entry.repoPath.split('/').map(encodeURIComponent).join('/');
|
|
2168
2184
|
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
2169
2185
|
const cdnUrl = `https://cdn.jsdelivr.net/gh/${owner}/${repo}@${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
2170
2186
|
|
|
2171
2187
|
let text = null;
|
|
2172
2188
|
try {
|
|
2173
|
-
const r1 = await fetchFn(rawUrl);
|
|
2189
|
+
const r1 = await fetchFn(rawUrl, { signal });
|
|
2174
2190
|
if (r1 && r1.ok) {
|
|
2175
2191
|
text = await r1.text();
|
|
2176
2192
|
}
|
|
2177
|
-
} catch (_) {
|
|
2193
|
+
} catch (_) {
|
|
2194
|
+
if (signal && signal.aborted) throw _;
|
|
2195
|
+
}
|
|
2178
2196
|
|
|
2179
2197
|
if (text === null) {
|
|
2180
2198
|
try {
|
|
2181
|
-
const r2 = await fetchFn(cdnUrl);
|
|
2199
|
+
const r2 = await fetchFn(cdnUrl, { signal });
|
|
2182
2200
|
if (r2 && r2.ok) {
|
|
2183
2201
|
text = await r2.text();
|
|
2184
2202
|
}
|
|
2185
|
-
} catch (_) {
|
|
2203
|
+
} catch (_) {
|
|
2204
|
+
if (signal && signal.aborted) throw _;
|
|
2205
|
+
}
|
|
2186
2206
|
}
|
|
2187
2207
|
|
|
2188
2208
|
if (text !== null && text.length <= maxFileSize) {
|
|
@@ -2213,6 +2233,8 @@ function __initShellModule(root: any) {
|
|
|
2213
2233
|
);
|
|
2214
2234
|
}
|
|
2215
2235
|
|
|
2236
|
+
throwIfAborted();
|
|
2237
|
+
|
|
2216
2238
|
if (onProgress) {
|
|
2217
2239
|
onProgress({
|
|
2218
2240
|
phase: 'mounting',
|
|
@@ -2238,7 +2260,7 @@ function __initShellModule(root: any) {
|
|
|
2238
2260
|
try {
|
|
2239
2261
|
const commitsRes = await fetchFn(
|
|
2240
2262
|
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${encodeURIComponent(resolvedBranch)}&per_page=10`,
|
|
2241
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
2263
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
2242
2264
|
);
|
|
2243
2265
|
if (commitsRes && commitsRes.ok) {
|
|
2244
2266
|
const commitsJson = await commitsRes.json();
|
|
@@ -4499,6 +4521,7 @@ function __initShellModule(root: any) {
|
|
|
4499
4521
|
targetDir,
|
|
4500
4522
|
branch: branchOpt,
|
|
4501
4523
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4524
|
+
signal: ctx.signal,
|
|
4502
4525
|
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
4503
4526
|
onProgress: (ev) => {
|
|
4504
4527
|
if (!ev) return;
|
|
@@ -4539,6 +4562,9 @@ function __initShellModule(root: any) {
|
|
|
4539
4562
|
`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`;
|
|
4540
4563
|
return { code: 0, stdout, stderr: '' };
|
|
4541
4564
|
} catch (err) {
|
|
4565
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
4566
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
4567
|
+
}
|
|
4542
4568
|
const msg = err && err.message ? err.message : String(err);
|
|
4543
4569
|
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
4544
4570
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
@@ -4866,6 +4892,7 @@ function __initShellModule(root: any) {
|
|
|
4866
4892
|
targetDir: repoRoot,
|
|
4867
4893
|
branch: gitState.branch,
|
|
4868
4894
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
4895
|
+
signal: ctx.signal,
|
|
4869
4896
|
onFile: (absPath) => ctx.emitMutation('change', absPath)
|
|
4870
4897
|
});
|
|
4871
4898
|
gitState.headSnapshot = Object.assign({}, result.headSnapshot);
|
|
@@ -4875,6 +4902,9 @@ function __initShellModule(root: any) {
|
|
|
4875
4902
|
stderr: ''
|
|
4876
4903
|
};
|
|
4877
4904
|
} catch (err) {
|
|
4905
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
4906
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
4907
|
+
}
|
|
4878
4908
|
const msg = err && err.message ? err.message : String(err);
|
|
4879
4909
|
return { code: 1, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
4880
4910
|
}
|