Skip to content

Commit

Permalink
Fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Sep 23, 2021
1 parent 3c20e7b commit 1f9184c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 71 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/release-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
run: yarn changeset version --snapshot compiler
- # 2. discard examples/docs/www changes (just in case)
run: git checkout -- examples/ docs/ www/
- # 3: auth
- # 3: use compiler--next renderers (but don’t commit)
run: cd packages/astro && yarn add @astrojs/renderer-preact@next--compiler @astrojs/renderer-react@next--compiler @astrojs/renderer-svelte@next--compiler @astrojs/renderer-vue@next--compiler && cd ../..
- # 4: auth
run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > ${{ github.workspace }}/.npmrc
- # 4: publish!
- # 5: publish!
run: yarn release --tag next--compiler

8 changes: 4 additions & 4 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"dependencies": {
"@astrojs/compiler": "^0.1.0-canary.46",
"@astrojs/markdown-remark": "^0.3.1",
"@astrojs/renderer-preact": "0.0.0-compiler-2021821225719",
"@astrojs/renderer-react": "0.0.0-compiler-2021821225719",
"@astrojs/renderer-svelte": "0.0.0-compiler-2021821225719",
"@astrojs/renderer-vue": "0.0.0-compiler-2021821225719",
"@astrojs/renderer-preact": "^0.2.2",
"@astrojs/renderer-react": "^0.2.1",
"@astrojs/renderer-svelte": "^0.1.2",
"@astrojs/renderer-vue": "^0.1.8",
"@babel/core": "^7.15.5",
"@web/rollup-plugin-html": "^1.9.1",
"astring": "^1.7.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export async function renderToString(result: any, componentFactory: AstroCompone

export async function renderPage(result: any, Component: AstroComponentFactory, props: any, children: any) {
const template = await renderToString(result, Component, props, children);
const styles = Array.from(result.styles).map((style) => `<style>${style}</style>`);
const styles = Array.from(result.styles).map((style: any) => renderElement('style', style));
const scripts = Array.from(result.scripts);
return template.replace('</head>', styles.join('\n') + scripts.join('\n') + '</head>');
}
Expand Down
40 changes: 12 additions & 28 deletions packages/astro/src/runtime/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,25 @@ const cache = new Map();

// TODO: improve validation and error handling here.
async function resolveRenderers(viteServer: ViteDevServer, ids: string[]) {
const resolve = viteServer.config.createResolver();
const renderers = await Promise.all(
ids.map(async (renderer) => {
if (cache.has(renderer)) return cache.get(renderer);
const resolvedRenderer: any = {};

const resolvedRenderer: any = {};
// We can dynamically import the renderer by itself because it shouldn't have
// any non-standard imports, the index is just meta info.
// The other entrypoints need to be loaded through Vite.
const { default: instance } = await import(renderer);

// This resolves the renderer's entrypoints to a final URL through Vite
const getPath = async (src: string) => {
const spec = path.posix.join(instance.name, src);
const resolved = await resolve(spec);
if (!resolved) {
throw new Error(`Unable to resolve "${spec}" to a package!`);
}
return resolved;
};

resolvedRenderer.name = instance.name;
if (instance.client) {
resolvedRenderer.source = await getPath(instance.client);
}
if (Array.isArray(instance.hydrationPolyfills)) {
resolvedRenderer.hydrationPolyfills = await Promise.all(instance.hydrationPolyfills.map((src: string) => getPath(src)));
}
if (Array.isArray(instance.polyfills)) {
resolvedRenderer.polyfills = await Promise.all(instance.polyfills.map((src: string) => getPath(src)));
}

const { url } = await viteServer.moduleGraph.ensureEntryFromUrl(await getPath(instance.server));
const { default: server } = await viteServer.ssrLoadModule(url);
resolvedRenderer.ssr = server;
const {
default: { name, client, polyfills, hydrationPolyfills, server },
} = await import(renderer);

resolvedRenderer.name = name;
if (client) resolvedRenderer.source = path.posix.join(renderer, client);
if (Array.isArray(hydrationPolyfills)) resolvedRenderer.hydrationPolyfills = hydrationPolyfills.map((src: string) => path.posix.join(renderer, src));
if (Array.isArray(polyfills)) resolvedRenderer.polyfills = polyfills.map((src: string) => path.posix.join(renderer, src));
const { url } = await viteServer.moduleGraph.ensureEntryFromUrl(path.posix.join(renderer, server));
const { default: rendererSSR } = await viteServer.ssrLoadModule(url);
resolvedRenderer.ssr = rendererSSR;

cache.set(renderer, resolvedRenderer);
return resolvedRenderer;
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/renderer-lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*",
"./server.js": "./server.js",
"./client-shim.js": "./client-shim.js",
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/renderer-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*",
"./client": "./client.js",
"./server": "./server.js",
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/renderer-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*",
"./client": "./client.js",
"./server": "./server.js",
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/renderer-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*",
"./client": "./client.js",
"./server": "./server.js",
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/renderer-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*",
"./client": "./client.js",
"./server": "./server.js",
"./package.json": "./package.json"
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/renderer-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*",
"./client": "./client.js",
"./server": "./server.js",
"./package.json": "./package.json"
Expand Down
36 changes: 0 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,42 +113,6 @@
dependencies:
typescript "^4.3.5"

"@astrojs/[email protected]":
version "0.0.0-compiler-2021821225719"
resolved "https://registry.yarnpkg.com/@astrojs/renderer-preact/-/renderer-preact-0.0.0-compiler-2021821225719.tgz#d6f987ae94820220269e863967dac4203970fc48"
integrity sha512-IonFU0ATk9/jfL8P7AgGryHmEWAtirjbfUX/aQYIejOC+H+c6jD7OUIBNGi1KLo5wY9IwCQ06FK/UBOkuboPXw==
dependencies:
"@babel/plugin-transform-react-jsx" "^7.14.5"
preact "^10.5.14"
preact-render-to-string "^5.1.19"

"@astrojs/[email protected]":
version "0.0.0-compiler-2021821225719"
resolved "https://registry.yarnpkg.com/@astrojs/renderer-react/-/renderer-react-0.0.0-compiler-2021821225719.tgz#b0d86875b9c4fd5a7180d1c45424b69276414843"
integrity sha512-018I1M5Ea1P6/eVdW5azxTpoyjXjp9lBGCfSYTW7Zn0UIP9Ry2BgD9BH6cYvHqIK9hyI/5u7VjZttPPP0r/yLA==
dependencies:
"@babel/plugin-transform-react-jsx" "^7.14.5"
react "^17.0.2"
react-dom "^17.0.2"

"@astrojs/[email protected]":
version "0.0.0-compiler-2021821225719"
resolved "https://registry.yarnpkg.com/@astrojs/renderer-svelte/-/renderer-svelte-0.0.0-compiler-2021821225719.tgz#0f3af4c9990caf1e7e870c8e6adfeddfd5437640"
integrity sha512-1uEd8+Bo3pHkmn3gmup+HTNR4Nmuu1YH1bDQHIucq7TtiWfUK2FufR7SrlaoXT2otSB4TUwwIq1dKvhgjtUJMQ==
dependencies:
"@sveltejs/vite-plugin-svelte" "^1.0.0-next.19"
svelte "^3.42.3"

"@astrojs/[email protected]":
version "0.0.0-compiler-2021821225719"
resolved "https://registry.yarnpkg.com/@astrojs/renderer-vue/-/renderer-vue-0.0.0-compiler-2021821225719.tgz#56654e2f775a14d1b88a58d5b7854c780c877413"
integrity sha512-D6uQwxLtSlKjq2ql6aUkqplimb4zR3xs8kLLQMhfpn6cnXiqwzwzdRYvM8f6q05fO/lNrvDp+m0ed4jbGZKQSg==
dependencies:
"@vitejs/plugin-vue" "^1.6.0"
"@vue/compiler-sfc" "^3.2.6"
"@vue/server-renderer" "^3.2.6"
vue "^3.2.6"

"@babel/[email protected]":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"
Expand Down

0 comments on commit 1f9184c

Please sign in to comment.