Skip to content

Commit 41b1bd7

Browse files
authored
download packages directly from npm (#1248)
* WIP * fix * tidy up * tidy up * put npm stuff in separate file * tidy up * remove ./ * tidy up * fix * lint * fix * always use same svelte version * fix pkg.pr.new versions * use jsDelivr for more stuff * remove packages_url stuff * lint * gah * fix `local` * lint * gah shut up typescript * remove unused stuff * tidy up * simplify some stuff * unused * only create tutorial bundler once * lint * tidy up * unused * move packages/editor into packages/repl, where it belongs * lint * DRY out * less reliance on globals * simplify * tighten up * tidy up * fix * bundler already discards stale results * drive-by fix * migrate component * get rid of `$bundle` store * tidy up * better status message * lint * reinstate imports array * lint * use jsDelivr API instead of fetching package.json * better error messages * use onversion mechanism * remove * use raw state * fix * explanatory comment
1 parent 0ee15d1 commit 41b1bd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+730
-1080
lines changed

apps/svelte.dev/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"d3-geo": "^3.1.0",
3939
"d3-geo-projection": "^4.0.0",
4040
"do-not-zip": "^1.0.0",
41-
"editor": "workspace:*",
4241
"flexsearch": "^0.7.43",
4342
"flru": "^1.0.2",
4443
"port-authority": "^2.0.1",

apps/svelte.dev/src/lib/tutorial/adapters/rollup/index.svelte.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,31 @@ import Bundler from '@sveltejs/repl/bundler';
22
// @ts-ignore package exports don't have types
33
import * as yootils from 'yootils';
44
import type { Adapter } from '$lib/tutorial';
5-
import type { File, Item } from 'editor';
5+
import type { File, Item } from '@sveltejs/repl/workspace';
66

7-
/** Rollup bundler singleton */
8-
let bundler: Bundler;
7+
let done = false;
98

109
export const state = new (class RollupState {
1110
progress = $state.raw({ value: 0, text: 'initialising' });
12-
bundle = $state.raw<any>(null);
13-
})();
14-
15-
/**
16-
* @returns {Promise<import('$lib/tutorial').Adapter>}
17-
*/
18-
export async function create(): Promise<Adapter> {
19-
bundler?.destroy();
20-
21-
state.progress = { value: 0, text: 'loading files' };
22-
23-
let done = false;
24-
2511
bundler = new Bundler({
26-
packages_url: 'https://unpkg.com',
2712
svelte_version: 'latest',
28-
onstatus(val) {
13+
onstatus: (val) => {
2914
if (!done && val === null) {
3015
done = true;
31-
state.progress = { value: 1, text: 'ready' };
16+
this.progress = { value: 1, text: 'ready' };
3217
}
3318
}
3419
});
20+
})();
3521

22+
export async function create(): Promise<Adapter> {
3623
state.progress = { value: 0.5, text: 'loading svelte compiler' };
3724

3825
/** Paths and contents of the currently loaded file stubs */
3926
let current_files: Item[] = [];
4027

4128
async function compile() {
42-
state.bundle = await bundler.bundle(
29+
state.bundler.bundle(
4330
current_files
4431
// TODO we can probably remove all the SvelteKit specific stuff from the tutorial content once this settles down
4532
.filter((f): f is File => f.name.startsWith('/src/lib/') && f.type === 'file')

apps/svelte.dev/src/lib/tutorial/adapters/webcontainer/index.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { get_depth } from '../../../utils/path.js';
77
import { escape_html } from '../../../utils/escape.js';
88
import { ready } from '../common/index.js';
99
import type { Adapter } from '$lib/tutorial';
10-
import type { Item, File } from 'editor';
10+
import type { Item, File } from '@sveltejs/repl/workspace';
1111

1212
const converter = new AnsiToHtml({
1313
fg: 'var(--sk-fg-3)'

apps/svelte.dev/src/lib/tutorial/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Writable } from 'svelte/store';
2-
import type { File, Directory, Item } from 'editor';
2+
import type { File, Directory, Item } from '@sveltejs/repl/workspace';
33

44
export interface Adapter {
55
/** Returns `false` if the reset was in such a way that a reload of the iframe isn't needed */

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import AppControls from './AppControls.svelte';
1111
import { compress_and_encode_text, decode_and_decompress_text } from './gzip.js';
1212
import { page } from '$app/state';
13-
import type { File } from 'editor';
13+
import type { File } from '@sveltejs/repl/workspace';
1414
1515
let { data } = $props();
1616
@@ -23,30 +23,11 @@
2323
2424
// svelte-ignore non_reactive_update
2525
let version = page.url.searchParams.get('version') || 'latest';
26-
let is_pr_or_commit_version = version.startsWith('pr-') || version.startsWith('commit-');
2726
2827
// Hashed URLs are less safe (we can't delete malicious REPLs), therefore
2928
// don't allow links to escape the sandbox restrictions
3029
const can_escape = browser && !page.url.hash;
3130
32-
if (version !== 'local' && !is_pr_or_commit_version) {
33-
$effect(() => {
34-
fetch(`https://unpkg.com/svelte@${version}/package.json`)
35-
.then((r) => r.json())
36-
.then((pkg) => {
37-
if (pkg.version !== version) {
38-
version = pkg.version;
39-
40-
let url = `/playground/${data.gist.id}?version=${version}`;
41-
if (location.hash) {
42-
url += location.hash;
43-
}
44-
replaceState(url, {});
45-
}
46-
});
47-
});
48-
}
49-
5031
afterNavigate(() => {
5132
name = data.gist.name;
5233
set_files();
@@ -244,6 +225,14 @@
244225
{onchange}
245226
{download}
246227
previewTheme={theme.current}
228+
onversion={(v) => {
229+
if (version === (version = v)) return;
230+
231+
const url = new URL(location.href);
232+
url.searchParams.set('version', v);
233+
234+
replaceState(url, {});
235+
}}
247236
/>
248237
</div>
249238
{/if}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import type { Gist, User } from '$lib/db/types';
88
import { browser } from '$app/environment';
99
import ModalDropdown from '$lib/components/ModalDropdown.svelte';
10-
import { untrack } from 'svelte';
1110
import SecondaryNav from '$lib/components/SecondaryNav.svelte';
12-
import type { File } from 'editor';
11+
import type { File } from '@sveltejs/repl/workspace';
1312
import type { Repl } from '@sveltejs/repl';
1413
1514
interface Props {

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,13 @@
66
import { mapbox_setup } from '../../../../../config.js';
77
import { page } from '$app/state';
88
import { decode_and_decompress_text } from '../gzip.js';
9-
import type { File } from 'editor';
9+
import type { File } from '@sveltejs/repl/workspace';
1010
1111
let { data } = $props();
1212
1313
let repl = $state() as ReturnType<typeof Repl>;
1414
1515
let version = page.url.searchParams.get('version') || 'latest';
16-
let is_pr_or_commit_version = version.startsWith('pr-') || version.startsWith('commit-');
17-
18-
if (version !== 'local' && !is_pr_or_commit_version) {
19-
$effect(() => {
20-
fetch(`https://unpkg.com/svelte@${version}/package.json`)
21-
.then((r) => r.json())
22-
.then((pkg) => {
23-
if (pkg.version !== data.version) {
24-
replaceState(`/playground/${data.gist.id}/embed?version=${pkg.version}`, {});
25-
}
26-
});
27-
});
28-
}
2916
3017
// TODO make this munging unnecessary
3118
function munge(data: any): File {
@@ -85,6 +72,14 @@
8572
injectedJS={mapbox_setup}
8673
previewTheme={theme.current}
8774
embedded={page.url.searchParams.has('output-only') ? 'output-only' : true}
75+
onversion={(v) => {
76+
if (version === v) return;
77+
78+
const url = new URL(location.href);
79+
url.searchParams.set('version', v);
80+
81+
replaceState(url, {});
82+
}}
8883
/>
8984
{/if}
9085
</div>

apps/svelte.dev/src/routes/tutorial/[...slug]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { afterNavigate, beforeNavigate } from '$app/navigation';
33
import { SplitPane } from '@rich_harris/svelte-split-pane';
44
import * as adapter from './adapter.svelte';
5-
import { Editor, Workspace } from 'editor';
5+
import { Workspace, type Item } from '@sveltejs/repl/workspace';
66
import ContextMenu from './filetree/ContextMenu.svelte';
77
import Filetree from './filetree/Filetree.svelte';
88
import ImageViewer from './ImageViewer.svelte';
@@ -14,7 +14,7 @@
1414
import OutputRollup from './OutputRollup.svelte';
1515
import { page } from '$app/state';
1616
import Controls from './Controls.svelte';
17-
import type { Item } from 'editor';
17+
import Editor from '@sveltejs/repl/editor';
1818
import type { Snapshot } from './$types.js';
1919
2020
interface Props {

apps/svelte.dev/src/routes/tutorial/[...slug]/Controls.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ModalDropdown from '$lib/components/ModalDropdown.svelte';
55
import type { Exercise, PartStub } from '$lib/tutorial';
66
import { Checkbox, Icon, Toolbox } from '@sveltejs/site-kit/components';
7-
import type { Workspace } from 'editor';
7+
import type { Workspace } from '@sveltejs/repl/workspace';
88
99
interface Props {
1010
index: PartStub[];

apps/svelte.dev/src/routes/tutorial/[...slug]/ImageViewer.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
/** @type {import('editor').File | null} */
2+
/** @type {import('@sveltejs/repl/workspace').File | null} */
33
export let selected;
44
55
const image_types = new Map([

0 commit comments

Comments
 (0)