Skip to content

Commit 079e814

Browse files
Merge branch 'main' into pkg-pr-new-version
2 parents 9f77f63 + 7fb2f17 commit 079e814

File tree

5 files changed

+112
-8
lines changed

5 files changed

+112
-8
lines changed

.github/workflows/docs-preview-create.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [docs-preview-create]
66

77
env:
8-
BRANCH: sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}
8+
BRANCH: preview-${{ github.event.client_payload.package }}-${{ github.event.client_payload.pr }}
99

1010
jobs:
1111
Sync:
@@ -33,4 +33,28 @@ jobs:
3333
git config --global user.email "github-actions[bot]@users.noreply.github.com"
3434
3535
- name: Push
36+
id: push
3637
run: git add -A && git commit -m "sync docs" && git push -u origin ${{ env.BRANCH }}
38+
39+
- name: Find comment
40+
id: fc
41+
uses: peter-evans/find-comment@v3
42+
with:
43+
token: ${{ secrets.COMMENTER_TOKEN }}
44+
repository: ${{ github.event.client_payload.repo }}
45+
issue-number: ${{ github.event.client_payload.pr }}
46+
comment-author: 'Rich-Harris' # it's using my personal access token, not sure if there's a way to comment as a bot instead
47+
body-includes: _this is an automated message_
48+
49+
- name: Create comment
50+
if: steps.fc.outputs.comment-id == ''
51+
uses: peter-evans/create-or-update-comment@v4
52+
with:
53+
token: ${{ secrets.COMMENTER_TOKEN }}
54+
repository: ${{ github.event.client_payload.repo }}
55+
issue-number: ${{ github.event.client_payload.pr }}
56+
body: |
57+
preview: https://svelte-dev-git-${{ env.BRANCH }}-svelte.vercel.app/
58+
59+
_this is an automated message_
60+
edit-mode: replace

.github/workflows/docs-preview-delete.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
repository_dispatch:
55
types: [docs-preview-delete]
66

7+
env:
8+
BRANCH: preview-${{ github.event.client_payload.package }}-${{ github.event.client_payload.pr }}
9+
710
jobs:
811
Sync:
912
runs-on: ubuntu-latest
@@ -13,4 +16,4 @@ jobs:
1316
token: ${{ secrets.GH_TOKEN }}
1417

1518
- name: Delete branch
16-
run: git push origin :sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}
19+
run: git push origin :${{ env.BRANCH }}

apps/svelte.dev/content/tutorial/02-advanced-svelte/05-advanced-transitions/02-animations/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Then add it to the `<li>` elements:
2323
```svelte
2424
/// file: TodoList.svelte
2525
<li
26-
class:done
26+
class:done={todo.done}
2727
in:receive={{ key: todo.id }}
2828
out:send={{ key: todo.id }}
2929
+++animate:flip+++
@@ -35,7 +35,7 @@ The movement is a little slow in this case, so we can add a `duration` parameter
3535
```svelte
3636
/// file: TodoList.svelte
3737
<li
38-
class:done
38+
class:done={todo.done}
3939
in:receive={{ key: todo.id }}
4040
out:send={{ key: todo.id }}
4141
animate:flip+++={{ duration: 200 }}+++

apps/svelte.dev/scripts/sync-docs/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,72 @@ You will need to add a `SYNC_REQUEST_TOKEN` to the repo. First, create a persona
8383
- under 'Repository permissions', change 'Contents' to 'Read and write'
8484

8585
Then, go to `https://github.com/<ORG>/<REPO>/settings/secrets/actions`, click 'New repository secret' and paste in your newly generated personal access token.
86+
87+
## Previews
88+
89+
Preview deployments will be created for pull requests to external repos that result in documentation changes. In the external repo, add a `.github/workflows/docs-preview-create-request.yml` workflow...
90+
91+
```yml
92+
# https://github.com/sveltejs/svelte.dev/blob/main/apps/svelte.dev/scripts/sync-docs/README.md
93+
name: Docs preview create request
94+
95+
on:
96+
pull_request:
97+
branches:
98+
- main
99+
100+
jobs:
101+
dispatch:
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Repository Dispatch
105+
uses: peter-evans/repository-dispatch@v3
106+
with:
107+
token: ${{ secrets.SYNC_REQUEST_TOKEN }}
108+
repository: sveltejs/svelte.dev
109+
event-type: docs-preview-create
110+
client-payload: |-
111+
{
112+
"package": "<YOUR_PACKAGE_NAME>",
113+
"repo": "${{ github.repository }}",
114+
"owner": "${{ github.event.pull_request.head.repo.owner.login }}",
115+
"branch": "${{ github.event.pull_request.head.ref }}",
116+
"pr": ${{ github.event.pull_request.number }}
117+
}
118+
```
119+
120+
...and a `.github/workflows/docs-preview-delete-request.yml` workflow:
121+
122+
```yml
123+
# https://github.com/sveltejs/svelte.dev/blob/main/apps/svelte.dev/scripts/sync-docs/README.md
124+
name: Docs preview delete request
125+
126+
on:
127+
pull_request:
128+
branches:
129+
- main
130+
types: [closed]
131+
132+
jobs:
133+
dispatch:
134+
runs-on: ubuntu-latest
135+
steps:
136+
- name: Repository Dispatch
137+
uses: peter-evans/repository-dispatch@v3
138+
with:
139+
token: ${{ secrets.SYNC_REQUEST_TOKEN }}
140+
repository: sveltejs/svelte.dev
141+
event-type: docs-preview-delete
142+
client-payload: |-
143+
{
144+
"package": "cli",
145+
"repo": "${{ github.repository }}",
146+
"owner": "${{ github.event.pull_request.head.repo.owner.login }}",
147+
"branch": "${{ github.event.pull_request.head.ref }}",
148+
"pr": ${{ github.event.pull_request.number }}
149+
}
150+
```
151+
152+
These use the same `SYNC_REQUEST_TOKEN` as above.
153+
154+
Inside _this_ repo, the [`docs-preview-create.yml`](../../../../.github/workflows/docs-preview-create.yml) workflow creates a comment on the PR once the branch has been created, inferring the eventual Vercel preview deployment URL. It uses this repo's `COMMENTER_TOKEN` secret, which is a [personal access token](https://github.com/settings/personal-access-tokens/new) with write permissions on issues and pull requests.

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,20 @@ addEventListener('message', async (event) => {
100100
let result: CompileResult;
101101

102102
if (file.name.endsWith('.svelte')) {
103-
result = self.svelte.compile(file.contents, {
104-
generate: options.generate, // TODO do we need to adjust this for 3/4?
103+
const is_svelte_3_or_4 = !self.svelte.compileModule;
104+
const compilerOptions: any = {
105+
generate: is_svelte_3_or_4
106+
? options.generate === 'client'
107+
? 'dom'
108+
: 'ssr'
109+
: options.generate,
105110
dev: options.dev,
106-
modernAst: options.modernAst,
107111
filename: file.name
108-
});
112+
};
113+
if (!is_svelte_3_or_4) {
114+
compilerOptions.modernAst = options.modernAst; // else Svelte 3/4 will throw an "unknown option" error
115+
}
116+
result = self.svelte.compile(file.contents, compilerOptions);
109117
} else {
110118
result = self.svelte.compileModule(file.contents, {
111119
generate: options.generate,

0 commit comments

Comments
 (0)