Skip to content

Commit

Permalink
Merge branch 'main' into feat/create-astro-fancy
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Oct 28, 2022
2 parents f014a32 + 26ff429 commit 6bf8485
Show file tree
Hide file tree
Showing 33 changed files with 233 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-moles-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/solid-js': patch
---

Improve third-party solid packages config handling
5 changes: 5 additions & 0 deletions .changeset/four-donuts-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Support rendering `@motionone/solid` components
5 changes: 5 additions & 0 deletions .changeset/mighty-chairs-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix not included file extension in `url` metadata for newly added markdown files
5 changes: 5 additions & 0 deletions .changeset/new-pumas-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

Exports new runtime entrypoint's types
5 changes: 5 additions & 0 deletions .changeset/tasty-mugs-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Upgrade Vite to 3.2
5 changes: 5 additions & 0 deletions .changeset/wicked-pans-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Allow importing public files in SSR
26 changes: 15 additions & 11 deletions .github/workflows/check-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Retrieve existing PR reviews
id: set-reviews
run: |
echo ::set-output name=reviews::$(curl --request GET \
--url https://api.github.com/repos/${{github.repository}}/pulls/${{github.event.number}}/reviews \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}')
- name: Check if there is already a block on this PR
id: set-blocks
run: |
echo ::set-output name=blocks::$(echo '${{ steps.set-reviews.outputs.reviews }}' \
| jq '.[] | select(.user.id == 41898282 and .state == "CHANGES_REQUESTED") | length' \
| uniq)
uses: actions/github-script@v6
with:
script: |
const url = 'https://api.github.com/repos/' + context.repo.owner + '/' + context.repo.repo + '/pulls/' + context.issue.number + '/reviews';
console.log('reviews URL', url);
const result = await github.request(url);
console.log(result);
const reviews = result.data;
for(const review of reviews) {
if(review.user.id === 41898282 && review.state === 'CHANGES_REQUESTED') {
return 'block';
}
}
return '';
result-encoding: string

- uses: actions/checkout@v3
if: steps.set-blocks.outputs.blocks == ''
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"recast": "^0.20.5",
"rehype": "^12.0.1",
"resolve": "^1.22.0",
"rollup": "~2.78.0",
"rollup": "^2.79.1",
"semver": "^7.3.7",
"shiki": "^0.11.1",
"sirv": "^2.0.2",
Expand All @@ -158,7 +158,7 @@
"typescript": "*",
"unist-util-visit": "^4.1.0",
"vfile": "^5.3.2",
"vite": "~3.1.3",
"vite": "~3.2.1",
"vitefu": "^0.1.0",
"yargs-parser": "^21.0.1",
"zod": "^3.17.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
emptyOutDir: false,
manifest: false,
outDir: fileURLToPath(out),
copyPublicDir: !ssr,
rollupOptions: {
...viteConfig.build?.rollupOptions,
input: [],
Expand All @@ -138,7 +139,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
ssr: true,
// improve build performance
minify: false,
polyfillModulePreload: false,
modulePreload: { polyfill: false },
reportCompressedSize: false,
},
plugins: [
Expand All @@ -154,7 +155,6 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
settings.config.output === 'server' && vitePluginSSR(internals, settings.adapter!),
vitePluginAnalyzer(internals),
],
publicDir: ssr ? false : viteConfig.publicDir,
envPrefix: 'PUBLIC_',
base: settings.config.base,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function isAstroComponent(obj: any): obj is AstroComponent {
}

export function isAstroComponentFactory(obj: any): obj is AstroComponentFactory {
return obj == null ? false : !!obj.isAstroComponentFactory;
return obj == null ? false : obj.isAstroComponentFactory === true;
}

export async function* renderAstroComponent(
Expand Down
11 changes: 9 additions & 2 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function renderComponent(
_props: Record<string | number, any>,
slots: any = {}
): Promise<ComponentIterable> {
Component = await Component;
Component = (await Component) ?? Component;

switch (getComponentType(Component)) {
case 'fragment': {
Expand Down Expand Up @@ -133,7 +133,14 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`')
// If this component ran through `__astro_tag_component__`, we already know
// which renderer to match to and can skip the usual `check` calls.
// This will help us throw most relevant error message for modules with runtime errors
if (Component && (Component as any)[Renderer]) {
let isTagged = false;
try {
isTagged = Component && (Component as any)[Renderer];
} catch {
// Accessing `Component[Renderer]` may throw if `Component` is a Proxy that doesn't
// return the actual read-only value. In this case, ignore.
}
if (isTagged) {
const rendererName = (Component as any)[Renderer];
renderer = renderers.find(({ name }) => name === rendererName);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/vite-plugin-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export function getFileInfo(id: string, config: AstroConfig) {

const fileId = id.split('?')[0];
let fileUrl = fileId.includes('/pages/')
? fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(\/index)?\.(md|astro)$/, '')
? fileId
.replace(/^.*?\/pages\//, sitePathname)
.replace(/(\/index)?\.(md|markdown|mdown|mkdn|mkd|mdwn|md|astro)$/, '')
: undefined;
if (fileUrl && config.trailingSlash === 'always') {
fileUrl = appendForwardSlash(fileUrl);
Expand Down
17 changes: 12 additions & 5 deletions packages/astro/test/astro-global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ describe('Astro Global', () => {

describe('dev', () => {
let devServer;
let $;

before(async () => {
devServer = await fixture.startDevServer();
const html = await fixture.fetch('/blog/?foo=42').then((res) => res.text());
$ = cheerio.load(html);
});

after(async () => {
await devServer.stop();
});

it('Astro.request.url', async () => {
const html = await fixture.fetch('/blog/?foo=42').then((res) => res.text());
const $ = cheerio.load(html);
expect($('#pathname').text()).to.equal('/blog/');
expect($('#searchparams').text()).to.equal('{}');
expect($('#child-pathname').text()).to.equal('/blog/');
expect($('#nested-child-pathname').text()).to.equal('/blog/');
});

it('Astro.glob() returned `url` metadata of each markdown file extensions DOES NOT include the extension', async () => {
const html = await fixture.fetch('/blog/omit-markdown-extensions/').then((res) => res.text());
const $ = cheerio.load(html);
expect($('[data-any-url-contains-extension]').data('any-url-contains-extension')).to.equal(
false
);
});
});

describe('build', () => {
Expand Down Expand Up @@ -65,8 +72,8 @@ describe('Astro Global', () => {
it('Astro.glob() correctly returns meta info for MD and Astro files', async () => {
const html = await fixture.readFile('/glob/index.html');
const $ = cheerio.load(html);
expect($('[data-file]').length).to.equal(3);
expect($('.post-url[href]').length).to.equal(3);
expect($('[data-file]').length).to.equal(8);
expect($('.post-url[href]').length).to.equal(8);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
const markdownPosts = await Astro.glob('./post/**/*.{markdown,mdown,mkdn,mkd,mdwn,md}');
const markdownExtensions = /(\.(markdown|mdown|mkdn|mkd|mdwn|md))$/g
const aUrlContainsExtension = markdownPosts.some((page:any)=> {
return markdownExtensions.test(page.url)
})
---

<html>
<head>
<title>Extensions omitted</title>
</head>
<body>
<p data-any-url-contains-extension={JSON.stringify(aUrlContainsExtension)}>Placeholder</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'Another post'
layout: '../../layouts/post.astro'
---

# Another post
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'Another post'
layout: '../../layouts/post.astro'
---

# Another post
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'Another post'
layout: '../../layouts/post.astro'
---

# Another post
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'Another post'
layout: '../../layouts/post.astro'
---

# Another post
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Dynamic } from 'solid-js/web'

const BaseComponent = ({ tag } = {}) => {
return <Dynamic id="proxy-component" component={tag || 'div'}>Hello world</Dynamic>;
}

// Motion uses a Proxy to support syntax like `<Motion.div />` and `<Motion.button />` etc
// https://cdn.jsdelivr.net/npm/@motionone/[email protected]/dist/source/motion.jsx
const ProxyComponent = new Proxy(BaseComponent, {
get: (_, tag) => (props) => {
delete props.tag
return <BaseComponent {...props} tag={tag} />;
}
})

export default ProxyComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Hello from '../components/Hello.jsx';
import WithNewlines from '../components/WithNewlines.jsx';
import { Router } from "@solidjs/router";
import ProxyComponent from '../components/ProxyComponent.jsx';
---
<html>
<head><title>Solid</title></head>
Expand All @@ -10,6 +11,7 @@ import { Router } from "@solidjs/router";
<Hello client:load />
<WithNewlines client:load />
<Router />
<ProxyComponent client:load />
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions packages/astro/test/fixtures/vue-component/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<img id="vue-img" src="/favicon.svg" alt="logo" />
</template>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import Counter from '../components/Counter.vue'
import Img from '../components/Img.vue'
---
<html lang="en">
<head>
Expand Down Expand Up @@ -28,6 +29,7 @@ import Counter from '../components/Counter.vue'
<!-- Test that two client:visibles have unique uids -->
<Counter start="100" client:visible>SSR Rendered, client:visible</Counter>
<Counter start="1000" client:visible>SSR Rendered, client:visible</Counter>
<Img />
</main>
</body>
</html>
14 changes: 14 additions & 0 deletions packages/astro/test/solid-component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe('Solid component', () => {

// test 1: Works
expect($('.hello')).to.have.lengthOf(1);

// test 2: Support rendering proxy components
expect($('#proxy-component').text()).to.be.equal('Hello world');
});
});

Expand All @@ -38,6 +41,17 @@ describe('Solid component', () => {
await devServer.stop();
});

it('Can load a component', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);

// test 1: Works
expect($('.hello')).to.have.lengthOf(1);

// test 2: Support rendering proxy components
expect($('#proxy-component').text()).to.be.equal('Hello world');
});

it('scripts proxy correctly', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const $ = cheerio.load(html);
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/test/vue-component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ describe('Vue component', () => {
// test 5: components with identical render output and props have been deduplicated
const uniqueRootUIDs = $('astro-island').map((i, el) => $(el).attr('uid'));
expect(new Set(uniqueRootUIDs).size).to.equal(5);

// test 6: import public files work
expect($('#vue-img')).to.be.ok;
});
});

Expand Down
5 changes: 4 additions & 1 deletion packages/integrations/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"homepage": "https://docs.astro.build/en/guides/integrations-guide/cloudflare/",
"exports": {
".": "./dist/index.js",
"./runtime": "./dist/runtime.js",
"./runtime": {
"types": "./runtime.d.ts",
"default": "./dist/runtime.js"
},
"./server.advanced.js": "./dist/server.advanced.js",
"./server.directory.js": "./dist/server.directory.js",
"./package.json": "./package.json"
Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/cloudflare/runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type { WorkerRuntime, PagesRuntime } from './dist/runtime';

export { getRuntime } from './dist/runtime';
3 changes: 2 additions & 1 deletion packages/integrations/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"dev": "astro-scripts dev \"src/**/*.ts\""
},
"dependencies": {
"babel-preset-solid": "^1.4.2"
"babel-preset-solid": "^1.4.2",
"vitefu": "^0.1.0"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
Loading

0 comments on commit 6bf8485

Please sign in to comment.