-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add server island metadata * Append servercomponent metadata * Add localName to serverComponents output * Add tests * linting * Updated changeset * fix: ormatting --------- Co-authored-by: Princesseuh <[email protected]>
- Loading branch information
1 parent
3e25858
commit 9fb8d5d
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@astrojs/compiler': minor | ||
--- | ||
|
||
Adds `serverComponents` metadata | ||
|
||
This adds a change necessary to support server islands. During transformation the compiler discovers `server:defer` directives and appends them to the `serverComponents` array. This is exported along with the other metadata so that it can be used inside of Astro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { fileURLToPath } from 'node:url'; | ||
import { transform } from '@astrojs/compiler'; | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
const FIXTURE = ` | ||
--- | ||
import Avatar from './Avatar.astro'; | ||
import {Other} from './Other.astro'; | ||
--- | ||
<Avatar server:defer /> | ||
<Other server:defer /> | ||
`; | ||
|
||
let result: Awaited<ReturnType<typeof transform>>; | ||
test.before(async () => { | ||
result = await transform(FIXTURE, { | ||
resolvePath: async (s: string) => { | ||
const out = new URL(s, import.meta.url); | ||
return fileURLToPath(out); | ||
}, | ||
}); | ||
}); | ||
|
||
test('component metadata added', () => { | ||
assert.equal(result.serverComponents.length, 2); | ||
}); | ||
|
||
test('path resolved to the filename', () => { | ||
const m = result.serverComponents[0]; | ||
assert.ok(m.specifier !== m.resolvedPath); | ||
}); | ||
|
||
test('localName is the name used in the template', () => { | ||
assert.equal(result.serverComponents[0].localName, 'Avatar'); | ||
assert.equal(result.serverComponents[1].localName, 'Other'); | ||
}); | ||
|
||
test('exportName is the export name of the imported module', () => { | ||
assert.equal(result.serverComponents[0].exportName, 'default'); | ||
assert.equal(result.serverComponents[1].exportName, 'Other'); | ||
}); | ||
|
||
test.run(); |