Skip to content

Commit 8875194

Browse files
committed
feat: allow version to be `commit-[commithash]
1 parent f3ae981 commit 8875194

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function load({ fetch, params, url }) {
1313

1414
let version = url.searchParams.get('version') || 'latest';
1515

16-
let is_pr_version = version.startsWith('pr-');
16+
let is_pr_or_commit_version = version.startsWith('pr-') || version.startsWith('commit-');
1717

1818
return {
1919
gist,
@@ -27,6 +27,6 @@ export async function load({ fetch, params, url }) {
2727
}))
2828
})),
2929
version: url.searchParams.get('version') || 'latest',
30-
is_pr_version
30+
is_pr_or_commit_version
3131
};
3232
}

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
const can_escape = browser && !$page.url.hash;
2727
2828
onMount(() => {
29-
if (version !== 'local' && !data.is_pr_version) {
29+
if (version !== 'local' && !data.is_pr_or_commit_version) {
3030
fetch(`https://unpkg.com/svelte@${version}/package.json`)
3131
.then((r) => r.json())
3232
.then((pkg) => {
@@ -151,7 +151,7 @@
151151
const svelteUrl =
152152
browser && version === 'local'
153153
? `${location.origin}/playground/local`
154-
: data.is_pr_version
154+
: data.is_pr_or_commit_version
155155
? version
156156
: `https://unpkg.com/svelte@${version}`;
157157

packages/editor/src/lib/compile-worker/worker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ addEventListener('message', async (event) => {
1919
const svelte_url = `https://unpkg.com/svelte@${event.data.version}`;
2020
let local_files: Awaited<ReturnType<typeof parseTar>> | undefined;
2121
let package_json;
22-
if (event.data.version.startsWith('pr-')) {
23-
const ref = event.data.version.substring('pr-'.length);
22+
let local_version = event.data.version;
23+
const starts_with_pr = local_version.startsWith('pr-');
24+
const starts_with_commit = local_version.startsWith('commit-');
25+
if (starts_with_pr || starts_with_commit) {
26+
const ref = starts_with_pr
27+
? local_version.substring('pr-'.length)
28+
: local_version.substring('commit-'.length);
2429

2530
const maybe_tar = await fetch(`https://pkg.pr.new/svelte@${ref}`);
2631
if (maybe_tar.headers.get('content-type') === 'application/tar+gzip') {

packages/repl/src/lib/Repl.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
5252
const workspace = new Workspace([dummy], {
5353
initial: 'App.svelte',
54-
svelte_version: svelteUrl.startsWith('pr-') ? svelteUrl : svelteUrl.split('@')[1],
54+
svelte_version:
55+
svelteUrl.startsWith('pr-') || svelteUrl.startsWith('commit-')
56+
? svelteUrl
57+
: svelteUrl.split('@')[1],
5558
onupdate() {
5659
rebundle();
5760
onchange?.();

packages/repl/src/lib/workers/bundler/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ self.addEventListener('message', async (event: MessageEvent<BundleMessageData>)
4040
case 'init': {
4141
({ packages_url, svelte_url } = event.data);
4242

43-
if (svelte_url.startsWith('pr-')) {
43+
const starts_with_pr = svelte_url.startsWith('pr-');
44+
const starts_with_commit = svelte_url.startsWith('commit-');
45+
46+
if (starts_with_pr || starts_with_commit) {
4447
let local_files: Awaited<ReturnType<typeof parseTar>>;
4548

46-
const ref = svelte_url.substring('pr-'.length);
49+
const ref = starts_with_pr
50+
? svelte_url.substring('pr-'.length)
51+
: svelte_url.substring('commit-'.length);
4752

4853
const maybe_tar = await fetch(`https://pkg.pr.new/svelte@${ref}`);
4954
if (maybe_tar.headers.get('content-type') === 'application/tar+gzip') {

0 commit comments

Comments
 (0)