Skip to content

Commit

Permalink
Merge branch 'main' into prerender_two
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryWu1234 authored Feb 21, 2023
2 parents 19f08b7 + a9a40d0 commit ad90c54
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 49 deletions.
7 changes: 7 additions & 0 deletions .changeset/breezy-coats-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': patch
'@astrojs/netlify': patch
'@astrojs/node': patch
---

Updated Undici to 5.20.0. This fixes a security issue and handling of cookies in certain cases in dev
6 changes: 6 additions & 0 deletions .changeset/eighty-rockets-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/netlify': patch
'@astrojs/vercel': patch
---

Use .mjs extension when building to support CJS environments
5 changes: 5 additions & 0 deletions .changeset/great-colts-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Prompt for git initialization last, so all configurations can get added to the initial commit
5 changes: 5 additions & 0 deletions .changeset/rare-pumpkins-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

`create-astro` help info add `--typescript` flag
4 changes: 3 additions & 1 deletion examples/blog/src/components/HeaderLink.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
export interface Props extends astroHTML.JSX.AnchorHTMLAttributes {}
import type { HTMLAttributes } from 'astro/types';
type Props = HTMLAttributes<'a'>;
const { href, class: className, ...props } = Astro.props;
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/src/content/docs/en/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ This is the `docs` starter template. It contains all of the features that you ne

To get started with this theme, check out the `README.md` in your new project directory. It provides documentation on how to use and customize this template for your own project. Keep the README around so that you can always refer back to it as you build.

Found a missing feature that you can't live without? Please suggest it on Discord [(#ideas-and-suggestions channel)](https://astro.build/chat) and even consider adding it yourself on GitHub! Astro is an open source project and contributions from developers like you are how we grow!
Found a missing feature that you can't live without? Please suggest it [on our Discord](https://astro.build/chat) and even consider adding it yourself on GitHub! Astro is an open source project and contributions from developers like you are how we grow!

Good luck out there, Astronaut. 🧑‍🚀
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"rollup": "^3.9.0",
"sass": "^1.52.2",
"srcset-parse": "^1.1.0",
"undici": "^5.14.0",
"undici": "^5.20.0",
"unified": "^10.1.2"
},
"engines": {
Expand Down
6 changes: 0 additions & 6 deletions packages/astro/src/vite-plugin-astro-server/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ export async function writeWebResponse(res: http.ServerResponse, webResponse: Re

const _headers = Object.fromEntries(headers.entries());

// Undici 5.19.1 includes a `getSetCookie` helper that returns an array of all the `set-cookies` headers.
// Previously, `headers.entries()` would already have those merged, but it seems like this isn't the case anymore, weird.
if ((headers as any)['getSetCookie']) {
_headers['set-cookie'] = (headers as any).getSetCookie();
}

// Attach any set-cookie headers added via Astro.cookies.set()
const setCookieHeaders = Array.from(getSetCookiesFromResponse(webResponse));
if (setCookieHeaders.length) {
Expand Down
1 change: 1 addition & 0 deletions packages/create-astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ May be provided in place of prompts
| `--no` (`-n`) | Skip all prompt by declining defaults. |
| `--dry-run` | Walk through steps without executing. |
| `--skip-houston` | Skip Houston animation. |
| `--typescript <option>` | TypeScript option: `strict` / `strictest` / `relaxed`. |

[examples]: https://github.com/withastro/astro/tree/main/examples
[typescript]: https://github.com/withastro/astro/tree/main/packages/astro/tsconfigs
1 change: 1 addition & 0 deletions packages/create-astro/src/actions/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function help() {
['--no (-n)', 'Skip all prompt by declining defaults.'],
['--dry-run', 'Walk through steps without executing.'],
['--skip-houston', 'Skip Houston animation.'],
['--typescript <option>', 'TypeScript option: strict | strictest | relaxed.'],
],
},
});
Expand Down
12 changes: 11 additions & 1 deletion packages/create-astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ export async function main() {
return;
}

const steps = [intro, projectName, template, dependencies, git, typescript, next];
const steps = [
intro,
projectName,
template,
dependencies,
typescript,

// Steps which write to files need to go above git
git,
next,
];

for (const step of steps) {
await step(ctx);
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test-fn": "mocha --exit --timeout 20000 test/functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net ./test/edge-functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net --allow-env ./test/edge-functions/",
"test": "npm run test-fn"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
build: {
client: outDir,
server: new URL('./.netlify/edge-functions/', config.root),
serverEntry: 'entry.js',
serverEntry: 'entry.mjs',
},
});
},
Expand Down
33 changes: 5 additions & 28 deletions packages/integrations/netlify/src/netlify-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,11 @@ export const createExports = (manifest: SSRManifest, args: Args) => {
isBase64Encoded: responseIsBase64Encoded,
};

// Special-case set-cookie which has to be set an different way :/
// The fetch API does not have a way to get multiples of a single header, but instead concatenates
// them. There are non-standard ways to do it, and node-fetch gives us headers.raw()
// See https://github.com/whatwg/fetch/issues/973 for discussion
if (response.headers.has('set-cookie')) {
if ('raw' in response.headers) {
// Node fetch allows you to get the raw headers, which includes multiples of the same type.
// This is needed because Set-Cookie *must* be called for each cookie, and can't be
// concatenated together.
type HeadersWithRaw = Headers & {
raw: () => Record<string, string[]>;
};

const rawPacked = (response.headers as HeadersWithRaw).raw();
if ('set-cookie' in rawPacked) {
fnResponse.multiValueHeaders = {
'set-cookie': rawPacked['set-cookie'],
};
}
} else {
const cookies = response.headers.get('set-cookie');

if (cookies) {
fnResponse.multiValueHeaders = {
'set-cookie': Array.isArray(cookies) ? cookies : splitCookiesString(cookies),
};
}
}
const cookies = response.headers.get('set-cookie');
if (cookies) {
fnResponse.multiValueHeaders = {
'set-cookie': Array.isArray(cookies) ? cookies : splitCookiesString(cookies),
};
}

// Apply cookies set via Astro.cookies.set/delete
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'astro/config';
import { netlifyEdgeFunctions } from '@astrojs/netlify';

export default defineConfig({
adapter: netlifyEdgeFunctions({
dist: new URL('./dist/', import.meta.url),
}),
output: 'server',
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-netlify-prerender",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/netlify": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
export const prerender = true
---

<html>
<head>
<title>testing</title>
</head>
<body>
<h1>testing</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-ignore
import { runBuild } from './test-utils.ts';
// @ts-ignore
import { assertEquals } from './deps.ts';

// @ts-ignore
Deno.test({
name: 'Prerender',
async fn() {
let close = await runBuild('./fixtures/prerender/');
const { default: handler } = await import(
'./fixtures/prerender/.netlify/edge-functions/entry.mjs'
);
const response = await handler(new Request('http://example.com/index.html'));
assertEquals(response, undefined, 'No response because this is an asset');
await close();
},
});
2 changes: 1 addition & 1 deletion packages/integrations/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"cheerio": "^1.0.0-rc.11",
"mocha": "^9.2.2",
"node-mocks-http": "^1.11.0",
"undici": "^5.14.0"
"undici": "^5.20.0"
}
}
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function vercelServerless({
updateConfig({
outDir,
build: {
serverEntry: 'entry.js',
serverEntry: 'entry.mjs',
client: new URL('./static/', outDir),
server: new URL('./dist/', config.root),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';

export default defineConfig({
adapter: vercel(),
output: 'server'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-serverless-prerender",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
export const prerender = true
---

<html>
<head>
<title>testing</title>
</head>
<body>
<h1>testing</h1>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/integrations/vercel/test/serverless-prerender.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';

describe('Serverless prerender', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/serverless-prerender/',
});
});

it('build successful', async () => {
await fixture.build();
expect(fixture.readFile('/static/index.html')).to.be.ok;
});
});
2 changes: 1 addition & 1 deletion packages/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dset": "^3.1.2",
"is-docker": "^3.0.0",
"is-wsl": "^2.2.0",
"undici": "^5.14.0",
"undici": "^5.20.0",
"which-pm-runs": "^1.1.0"
},
"devDependencies": {
Expand Down
35 changes: 29 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad90c54

Please sign in to comment.