Merge branch 'main' into test/e2e-hydration
This commit is contained in:
commit
262a21ddf8
48 changed files with 556 additions and 997 deletions
5
.changeset/eight-feet-reflect.md
Normal file
5
.changeset/eight-feet-reflect.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/netlify': minor
|
||||
---
|
||||
|
||||
Updating out directories for Netlify Functions
|
5
.changeset/fair-kangaroos-talk.md
Normal file
5
.changeset/fair-kangaroos-talk.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/netlify': minor
|
||||
---
|
||||
|
||||
Change out directories on dist and serverEntry
|
5
.changeset/red-bikes-happen.md
Normal file
5
.changeset/red-bikes-happen.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/lit': patch
|
||||
---
|
||||
|
||||
Added tests and fix a small edge case for when you call render with no props/attrs
|
5
.changeset/silent-books-train.md
Normal file
5
.changeset/silent-books-train.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/partytown': patch
|
||||
---
|
||||
|
||||
Add config options for integration
|
5
.changeset/silver-toes-retire.md
Normal file
5
.changeset/silver-toes-retire.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Remove `nodeVersion` option for `serverless` target. Now it is inferred from Vercel
|
5
.changeset/stupid-donkeys-care.md
Normal file
5
.changeset/stupid-donkeys-care.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes issue with loading md pages in project with a space in folder name
|
5
.changeset/tiny-donuts-own.md
Normal file
5
.changeset/tiny-donuts-own.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Allow using aliases for hydrated scripts
|
|
@ -42,7 +42,7 @@ Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll
|
|||
| [create-astro](packages/create-astro) | [![create-astro version](https://img.shields.io/npm/v/create-astro.svg?label=%20)](packages/create-astro/CHANGELOG.md) |
|
||||
| [@astrojs/react](packages/integrations/react) | [![astro version](https://img.shields.io/npm/v/@astrojs/react.svg?label=%20)](packages/integrations/react/CHANGELOG.md) |
|
||||
| [@astrojs/preact](packages/integrations/preact) | [![astro version](https://img.shields.io/npm/v/@astrojs/preact.svg?label=%20)](packages/integrations/preact/CHANGELOG.md) |
|
||||
| [@astrojs/solid-js](packages/integrations/solid-js) | [![astro version](https://img.shields.io/npm/v/@astrojs/solid-js.svg?label=%20)](packages/integrations/solid-js/CHANGELOG.md) |
|
||||
| [@astrojs/solid-js](packages/integrations/solid) | [![astro version](https://img.shields.io/npm/v/@astrojs/solid-js.svg?label=%20)](packages/integrations/solid-js/CHANGELOG.md) |
|
||||
| [@astrojs/svelte](packages/integrations/svelte) | [![astro version](https://img.shields.io/npm/v/@astrojs/svelte.svg?label=%20)](packages/integrations/svelte/CHANGELOG.md) |
|
||||
| [@astrojs/vue](packages/integrations/vue) | [![astro version](https://img.shields.io/npm/v/@astrojs/vue.svg?label=%20)](packages/integrations/vue/CHANGELOG.md) |
|
||||
| [@astrojs/lit](packages/integrations/lit) | [![astro version](https://img.shields.io/npm/v/@astrojs/lit.svg?label=%20)](packages/integrations/lit/CHANGELOG.md) |
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"preact": "^10.7.2",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0",
|
||||
"solid-js": "^1.3.17",
|
||||
"solid-js": "^1.4.1",
|
||||
"svelte": "^3.48.0",
|
||||
"vue": "^3.2.33"
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@types/react": "^18.0.9",
|
||||
"@types/react-dom": "^18.0.3",
|
||||
"@types/react-dom": "^18.0.4",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0"
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
"astro": "^1.0.0-beta.28"
|
||||
},
|
||||
"dependencies": {
|
||||
"solid-js": "^1.3.17"
|
||||
"solid-js": "^1.4.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
"@astrojs/tailwind": "^0.2.1",
|
||||
"@astrojs/turbolinks": "^0.1.2",
|
||||
"astro": "^1.0.0-beta.28",
|
||||
"solid-js": "^1.3.17"
|
||||
"solid-js": "^1.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@webcomponents/template-shadowroot": "^0.1.0",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"@astrojs/node": "^0.1.1",
|
||||
"@astrojs/svelte": "^0.1.3",
|
||||
"astro": "^1.0.0-beta.28",
|
||||
"concurrently": "^7.1.0",
|
||||
"concurrently": "^7.2.0",
|
||||
"lightcookie": "^1.0.25",
|
||||
"unocss": "^0.15.6",
|
||||
"vite-imagetools": "^4.0.3"
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
"@octokit/action": "^3.18.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
||||
"@typescript-eslint/parser": "^5.23.0",
|
||||
"del": "^6.0.0",
|
||||
"del": "^6.1.0",
|
||||
"esbuild": "^0.14.39",
|
||||
"eslint": "^8.15.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
|
|
|
@ -8,8 +8,8 @@ export function loadFixture(inlineConfig) {
|
|||
// without this, the main `loadFixture` helper will resolve relative to `packages/astro/test`
|
||||
return baseLoadFixture({
|
||||
...inlineConfig,
|
||||
root: new URL(inlineConfig.root, import.meta.url).toString()
|
||||
})
|
||||
root: new URL(inlineConfig.root, import.meta.url).toString(),
|
||||
});
|
||||
}
|
||||
|
||||
export function onAfterHMR(page) {
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
"prompts": "^2.4.2",
|
||||
"recast": "^0.20.5",
|
||||
"resolve": "^1.22.0",
|
||||
"rollup": "^2.72.1",
|
||||
"rollup": "^2.73.0",
|
||||
"semver": "^7.3.7",
|
||||
"serialize-javascript": "^6.0.0",
|
||||
"shiki": "^0.10.1",
|
||||
|
@ -136,8 +136,8 @@
|
|||
"zod": "^3.16.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/types": "^7.17.0",
|
||||
"@playwright/test": "^1.21.1",
|
||||
"@babel/types": "^7.17.10",
|
||||
"@playwright/test": "^1.22.0",
|
||||
"@types/babel__core": "^7.1.19",
|
||||
"@types/babel__generator": "^7.6.4",
|
||||
"@types/babel__traverse": "^7.17.1",
|
||||
|
@ -152,7 +152,7 @@
|
|||
"@types/mocha": "^9.1.1",
|
||||
"@types/parse5": "^6.0.3",
|
||||
"@types/path-browserify": "^1.0.0",
|
||||
"@types/prettier": "^2.6.0",
|
||||
"@types/prettier": "^2.6.1",
|
||||
"@types/resolve": "^1.20.2",
|
||||
"@types/rimraf": "^3.0.2",
|
||||
"@types/send": "^0.17.1",
|
||||
|
|
|
@ -195,7 +195,6 @@ class AstroBuilder {
|
|||
try {
|
||||
await this.build(setupData);
|
||||
} catch (_err) {
|
||||
debugger;
|
||||
throw fixViteErrorMessage(createSafeError(_err), setupData.viteServer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,18 +160,11 @@ export async function render(
|
|||
pathname,
|
||||
scripts,
|
||||
// Resolves specifiers in the inline hydrated scripts, such as "@astrojs/preact/client.js"
|
||||
// TODO: Can we pass the hydration code more directly through Vite, so that we
|
||||
// don't need to copy-paste and maintain Vite's import resolution here?
|
||||
async resolve(s: string) {
|
||||
const [resolvedUrl, resolvedPath] = await viteServer.moduleGraph.resolveUrl(s);
|
||||
if (resolvedPath.includes('node_modules/.vite')) {
|
||||
return resolvedPath.replace(/.*?node_modules\/\.vite/, '/node_modules/.vite');
|
||||
if (s.startsWith('/@fs')) {
|
||||
return s;
|
||||
}
|
||||
// NOTE: This matches the same logic that Vite uses to add the `/@id/` prefix.
|
||||
if (!resolvedUrl.startsWith('.') && !resolvedUrl.startsWith('/')) {
|
||||
return '/@id' + prependForwardSlash(resolvedUrl);
|
||||
}
|
||||
return '/@fs' + prependForwardSlash(resolvedPath);
|
||||
return '/@id' + prependForwardSlash(s);
|
||||
},
|
||||
renderers,
|
||||
request,
|
||||
|
|
|
@ -603,10 +603,7 @@ export async function renderHead(result: SSRResult): Promise<string> {
|
|||
if ('data-astro-component-hydration' in script.props) {
|
||||
needsHydrationStyles = true;
|
||||
}
|
||||
return renderElement('script', {
|
||||
...script,
|
||||
props: { ...script.props, 'astro-script': result._metadata.pathname + '/script-' + i },
|
||||
});
|
||||
return renderElement('script', script);
|
||||
});
|
||||
if (needsHydrationStyles) {
|
||||
styles.push(
|
||||
|
|
|
@ -9,8 +9,8 @@ import type { Plugin } from 'vite';
|
|||
import type { AstroConfig } from '../@types/astro';
|
||||
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
||||
import { pagesVirtualModuleId } from '../core/app/index.js';
|
||||
import { appendForwardSlash } from '../core/path.js';
|
||||
import { resolvePages } from '../core/util.js';
|
||||
import { appendForwardSlash, prependForwardSlash } from '../core/path.js';
|
||||
import { resolvePages, viteID } from '../core/util.js';
|
||||
|
||||
interface AstroPluginOptions {
|
||||
config: AstroConfig;
|
||||
|
@ -156,7 +156,9 @@ ${setup}`.trim();
|
|||
site: config.site ? new URL(config.base, config.site).toString() : undefined,
|
||||
sourcefile: id,
|
||||
sourcemap: 'inline',
|
||||
internalURL: `/@fs${new URL('../runtime/server/index.js', import.meta.url).pathname}`,
|
||||
internalURL: `/@fs${prependForwardSlash(
|
||||
viteID(new URL('../runtime/server/index.js', import.meta.url))
|
||||
)}`,
|
||||
});
|
||||
|
||||
tsResult = `\nexport const metadata = ${JSON.stringify(metadata)};
|
||||
|
|
38
packages/astro/test/alias.test.js
Normal file
38
packages/astro/test/alias.test.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { isWindows, loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Aliases', () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/alias/',
|
||||
});
|
||||
});
|
||||
|
||||
if (isWindows) return;
|
||||
|
||||
describe('dev', () => {
|
||||
let devServer;
|
||||
|
||||
before(async () => {
|
||||
devServer = await fixture.startDevServer();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await devServer.stop();
|
||||
});
|
||||
|
||||
it.only('can load client components', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
// Should render aliased element
|
||||
expect($('#client').text()).to.equal('test');
|
||||
|
||||
const scripts = $('script').toArray();
|
||||
expect(scripts.length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,12 +1,17 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import { loadFixture, isWindows } from './test-utils.js';
|
||||
|
||||
describe('Pages', () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ root: './fixtures/astro-pages/' });
|
||||
fixture = await loadFixture({ root: './fixtures/astro pages/' });
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
describe('Build', () => {
|
||||
before(async () => {
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
|
@ -17,3 +22,25 @@ describe('Pages', () => {
|
|||
expect($('h1').text()).to.equal('Name with index');
|
||||
});
|
||||
});
|
||||
|
||||
if (isWindows) return;
|
||||
|
||||
describe('Development', () => {
|
||||
let devServer;
|
||||
|
||||
before(async () => {
|
||||
devServer = await fixture.startDevServer();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await devServer.stop();
|
||||
});
|
||||
|
||||
it('Is able to load md pages', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('#testing').length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
14
packages/astro/test/fixtures/alias/astro.config.mjs
vendored
Normal file
14
packages/astro/test/fixtures/alias/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import svelte from '@astrojs/svelte';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
integrations: [svelte()],
|
||||
vite: {
|
||||
resolve: {
|
||||
alias: [
|
||||
{ find:/^component:(.*)$/, replacement: '/src/components/$1' }
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
9
packages/astro/test/fixtures/alias/package.json
vendored
Normal file
9
packages/astro/test/fixtures/alias/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/aliases",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/svelte": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
2
packages/astro/test/fixtures/alias/src/components/Client.svelte
vendored
Normal file
2
packages/astro/test/fixtures/alias/src/components/Client.svelte
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
<script></script>
|
||||
<div id="client">test</div>
|
25
packages/astro/test/fixtures/alias/src/pages/index.astro
vendored
Normal file
25
packages/astro/test/fixtures/alias/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
import Client from 'component:Client.svelte'
|
||||
---
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Svelte Client</title>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
font-family: system-ui;
|
||||
margin: 0;
|
||||
}
|
||||
body {
|
||||
padding: 2rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<Client client:load />
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
1
packages/astro/test/fixtures/astro pages/src/pages/index.md
vendored
Normal file
1
packages/astro/test/fixtures/astro pages/src/pages/index.md
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
# Testing
|
|
@ -3,12 +3,12 @@
|
|||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*",
|
||||
"@astrojs/preact": "workspace:*",
|
||||
"@astrojs/react": "workspace:*",
|
||||
"@astrojs/svelte": "workspace:*",
|
||||
"@test/component-library-shared": "workspace:*",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0"
|
||||
"astro": "workspace:*",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,8 @@ export async function loadFixture(inlineConfig) {
|
|||
},
|
||||
};
|
||||
|
||||
const resolveUrl = (url) => `http://${'127.0.0.1'}:${config.server.port}${url.replace(/^\/?/, '/')}`;
|
||||
const resolveUrl = (url) =>
|
||||
`http://${'127.0.0.1'}:${config.server.port}${url.replace(/^\/?/, '/')}`;
|
||||
|
||||
let cleanupCallbacks = [];
|
||||
|
||||
|
@ -117,8 +118,7 @@ export async function loadFixture(inlineConfig) {
|
|||
},
|
||||
config,
|
||||
resolveUrl,
|
||||
fetch: (url, init) =>
|
||||
fetch(resolveUrl(url), init),
|
||||
fetch: (url, init) => fetch(resolveUrl(url), init),
|
||||
preview: async (opts = {}) => {
|
||||
const previewServer = await preview(config, { logging, telemetry, ...opts });
|
||||
return previewServer;
|
||||
|
|
|
@ -28,14 +28,16 @@
|
|||
"scripts": {
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\""
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"test": "mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lit-labs/ssr": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*"
|
||||
"astro-scripts": "workspace:*",
|
||||
"cheerio": "^1.0.0-rc.10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@webcomponents/template-shadowroot": "^0.1.0",
|
||||
|
|
|
@ -29,6 +29,7 @@ function* render(tagName, attrs, children) {
|
|||
|
||||
// LitElementRenderer creates a new element instance, so copy over.
|
||||
const Ctr = getCustomElementConstructor(tagName);
|
||||
if (attrs) {
|
||||
for (let [name, value] of Object.entries(attrs)) {
|
||||
// check if this is a reactive property
|
||||
if (name in Ctr.prototype) {
|
||||
|
@ -37,6 +38,7 @@ function* render(tagName, attrs, children) {
|
|||
instance.setAttribute(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instance.connectedCallback();
|
||||
|
||||
|
|
86
packages/integrations/lit/test/server.test.js
Normal file
86
packages/integrations/lit/test/server.test.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
import { expect } from 'chai';
|
||||
import server from '../server.js';
|
||||
import { LitElement, html } from 'lit';
|
||||
import * as cheerio from 'cheerio';
|
||||
|
||||
const { check, renderToStaticMarkup } = server;
|
||||
|
||||
describe('check', () => {
|
||||
it('should be false with no component', async () => {
|
||||
expect(await check()).to.equal(false);
|
||||
});
|
||||
|
||||
it('should be false with a registered non-lit component', async () => {
|
||||
const tagName = 'non-lit-component';
|
||||
customElements.define(tagName, class TestComponent extends HTMLElement {});
|
||||
expect(await check(tagName)).to.equal(false);
|
||||
});
|
||||
|
||||
it('should be true with a registered lit component', async () => {
|
||||
const tagName = 'lit-component';
|
||||
customElements.define(tagName, class extends LitElement {});
|
||||
expect(await check(tagName)).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderToStaticMarkup', () => {
|
||||
it('should throw error if trying to render an unregistered component', async () => {
|
||||
const tagName = 'non-registrered-component';
|
||||
try {
|
||||
await renderToStaticMarkup(tagName);
|
||||
} catch (e) {
|
||||
expect(e).to.be.an.instanceOf(TypeError);
|
||||
}
|
||||
});
|
||||
|
||||
it('should render emtpy component with default markup', async () => {
|
||||
const tagName = 'nothing-component';
|
||||
customElements.define(tagName, class extends LitElement {});
|
||||
const render = await renderToStaticMarkup(tagName);
|
||||
expect(render).to.deep.equal({
|
||||
html: `<${tagName}><template shadowroot="open"><!--lit-part--><!--/lit-part--></template></${tagName}>`,
|
||||
});
|
||||
});
|
||||
|
||||
it('should render component with default markup', async () => {
|
||||
const tagName = 'simple-component';
|
||||
customElements.define(
|
||||
tagName,
|
||||
class extends LitElement {
|
||||
render() {
|
||||
return html`<p>hola</p>`;
|
||||
}
|
||||
}
|
||||
);
|
||||
const render = await renderToStaticMarkup(tagName);
|
||||
const $ = cheerio.load(render.html);
|
||||
expect($(`${tagName} template`).html()).to.contain('<p>hola</p>');
|
||||
});
|
||||
|
||||
it('should render component with properties and attributes', async () => {
|
||||
const tagName = 'props-and-attrs-component';
|
||||
const attr1 = 'test';
|
||||
const prop1 = 'Daniel';
|
||||
customElements.define(
|
||||
tagName,
|
||||
class extends LitElement {
|
||||
static properties = {
|
||||
prop1: { type: String },
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.prop1 = 'someone';
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`<p>Hello ${this.prop1}</p>`;
|
||||
}
|
||||
}
|
||||
);
|
||||
const render = await renderToStaticMarkup(tagName, { prop1, attr1 });
|
||||
const $ = cheerio.load(render.html);
|
||||
expect($(tagName).attr('attr1')).to.equal(attr1);
|
||||
expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`);
|
||||
});
|
||||
});
|
|
@ -39,7 +39,7 @@ export default defineConfig({
|
|||
|
||||
### dist
|
||||
|
||||
We build to a `netlify` directory at the base of your project. To change this, use the `dist` option:
|
||||
We build to a `dist` directory at the base of your project. To change this, use the `dist` option:
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'astro/config';
|
||||
|
|
|
@ -72,7 +72,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
|||
if (dist) {
|
||||
config.outDir = dist;
|
||||
} else {
|
||||
config.outDir = new URL('./netlify/', config.root);
|
||||
config.outDir = new URL('./dist/', config.root);
|
||||
}
|
||||
},
|
||||
'astro:config:done': ({ config, setAdapter }) => {
|
||||
|
@ -82,7 +82,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
|||
'astro:build:start': async ({ buildConfig }) => {
|
||||
entryFile = buildConfig.serverEntry.replace(/\.m?js/, '');
|
||||
buildConfig.client = _config.outDir;
|
||||
buildConfig.server = new URL('./edge-functions/', _config.outDir);
|
||||
buildConfig.server = new URL('./.netlify/edge-functions/', _config.root);
|
||||
buildConfig.serverEntry = 'entry.js';
|
||||
},
|
||||
'astro:build:setup': ({ vite, target }) => {
|
||||
|
|
|
@ -24,7 +24,7 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat
|
|||
if (dist) {
|
||||
config.outDir = dist;
|
||||
} else {
|
||||
config.outDir = new URL('./netlify/', config.root);
|
||||
config.outDir = new URL('./dist/', config.root);
|
||||
}
|
||||
},
|
||||
'astro:config:done': ({ config, setAdapter }) => {
|
||||
|
@ -34,7 +34,7 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat
|
|||
'astro:build:start': async ({ buildConfig }) => {
|
||||
entryFile = buildConfig.serverEntry.replace(/\.m?js/, '');
|
||||
buildConfig.client = _config.outDir;
|
||||
buildConfig.server = new URL('./functions/', _config.outDir);
|
||||
buildConfig.server = new URL('./.netlify/functions-internal/', _config.root);
|
||||
},
|
||||
'astro:build:done': async ({ routes, dir }) => {
|
||||
await createRedirects(routes, dir, entryFile, false);
|
||||
|
|
|
@ -24,7 +24,10 @@ describe('Cookies', () => {
|
|||
});
|
||||
|
||||
it('Can set multiple', async () => {
|
||||
const entryURL = new URL('./fixtures/cookies/dist/functions/entry.mjs', import.meta.url);
|
||||
const entryURL = new URL(
|
||||
'./fixtures/cookies/.netlify/functions-internal/entry.mjs',
|
||||
import.meta.url
|
||||
);
|
||||
const { handler } = await import(entryURL);
|
||||
const resp = await handler({
|
||||
httpMethod: 'POST',
|
||||
|
|
|
@ -59,6 +59,38 @@ Partytown should be ready-to-use with zero config. If you have an existing 3rd p
|
|||
|
||||
If you open the "Network" tab from [your browser's dev tools](https://developer.chrome.com/docs/devtools/open/), you should see the `partytown` proxy intercepting this request.
|
||||
|
||||
## Configuration
|
||||
|
||||
### config.debug
|
||||
|
||||
You can set debug mode using this integration's `config.debug` option. If `config.debug` is unset, it will fall back to `true` if the command is `dev`.
|
||||
|
||||
```js
|
||||
// astro.config.mjs
|
||||
export default {
|
||||
integrations: [partytown({
|
||||
// Example: Disable debug mode.
|
||||
config: { debug: false },
|
||||
})],
|
||||
}
|
||||
```
|
||||
|
||||
### config.forward
|
||||
|
||||
Because we’re moving third-party scripts to a web worker, the main thread needs to know which variables to patch on window, and when these services are called, the data is correctly forwarded to the web worker. You can to set it on the `config.forward` option.
|
||||
|
||||
```js
|
||||
// astro.config.mjs
|
||||
export default {
|
||||
integrations: [partytown({
|
||||
// Example: Add dataLayer.push as a forwarding-event.
|
||||
config: { forward: ["dataLayer.push"] },
|
||||
})],
|
||||
}
|
||||
```
|
||||
|
||||
## Read more
|
||||
|
||||
[Head to the Partytown docs](https://partytown.builder.io/configuration) for configuration options and more usage examples. You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
||||
|
||||
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
||||
|
|
|
@ -7,7 +7,16 @@ import { createRequire } from 'module';
|
|||
import path from 'path';
|
||||
const resolve = createRequire(import.meta.url).resolve;
|
||||
|
||||
export default function createPlugin(): AstroIntegration {
|
||||
type PartytownOptions =
|
||||
| {
|
||||
config?: {
|
||||
forward?: string[];
|
||||
debug?: boolean;
|
||||
};
|
||||
}
|
||||
| undefined;
|
||||
|
||||
export default function createPlugin(options: PartytownOptions): AstroIntegration {
|
||||
let config: AstroConfig;
|
||||
let partytownSnippetHtml: string;
|
||||
const partytownEntrypoint = resolve('@builder.io/partytown/package.json');
|
||||
|
@ -16,7 +25,9 @@ export default function createPlugin(): AstroIntegration {
|
|||
name: '@astrojs/partytown',
|
||||
hooks: {
|
||||
'astro:config:setup': ({ config: _config, command, injectScript }) => {
|
||||
partytownSnippetHtml = partytownSnippet({ debug: command === 'dev' });
|
||||
const forward = options?.config?.forward || [];
|
||||
const debug = options?.config?.debug || command === 'dev';
|
||||
partytownSnippetHtml = partytownSnippet({ debug, forward });
|
||||
injectScript('head-inline', partytownSnippetHtml);
|
||||
},
|
||||
'astro:config:done': ({ config: _config }) => {
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^17.0.45",
|
||||
"@types/react-dom": "^17.0.16",
|
||||
"@types/react-dom": "^17.0.17",
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*",
|
||||
"react": "^18.1.0",
|
||||
|
|
|
@ -31,12 +31,12 @@
|
|||
"dev": "astro-scripts dev \"src/**/*.ts\""
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-preset-solid": "^1.3.17"
|
||||
"babel-preset-solid": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*",
|
||||
"solid-js": "^1.3.17"
|
||||
"solid-js": "^1.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"solid-js": "^1.3.6"
|
||||
|
|
|
@ -59,19 +59,6 @@ import vercel from '@astrojs/vercel/serverless';
|
|||
import vercel from '@astrojs/vercel/static';
|
||||
```
|
||||
|
||||
### Node.js version
|
||||
|
||||
When deploying to `serverless` you can choose what version of Node.js you want to target: `12.x`, `14.x` or `16.x` (default).
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel({ nodeVersion: '14.x' })
|
||||
});
|
||||
```
|
||||
|
||||
## Limitations
|
||||
|
||||
**A few known complex packages (example: [puppeteer](https://github.com/puppeteer/puppeteer)) do not support bundling and therefore will not work properly with this adapter.** By default, Vercel doesn't include npm installed files & packages from your project's `./node_modules` folder. To address this, the `@astrojs/vercel` adapter automatically bundles your final build output using `esbuild`.
|
||||
|
|
|
@ -14,11 +14,7 @@ function getAdapter(): AstroAdapter {
|
|||
};
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
nodeVersion?: '12.x' | '14.x' | '16.x';
|
||||
}
|
||||
|
||||
export default function vercelEdge({ nodeVersion = '16.x' }: Options = {}): AstroIntegration {
|
||||
export default function vercelEdge(): AstroIntegration {
|
||||
let _config: AstroConfig;
|
||||
let functionFolder: URL;
|
||||
let serverEntry: string;
|
||||
|
@ -57,7 +53,7 @@ export default function vercelEdge({ nodeVersion = '16.x' }: Options = {}): Astr
|
|||
// Serverless function config
|
||||
// https://vercel.com/docs/build-output-api/v3#vercel-primitives/serverless-functions/configuration
|
||||
await writeJson(new URL(`./.vc-config.json`, functionFolder), {
|
||||
runtime: `nodejs${nodeVersion}`,
|
||||
runtime: getRuntime(),
|
||||
handler: serverEntry,
|
||||
launcherType: 'Nodejs',
|
||||
});
|
||||
|
@ -76,3 +72,9 @@ export default function vercelEdge({ nodeVersion = '16.x' }: Options = {}): Astr
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getRuntime() {
|
||||
const version = process.version.slice(1); // 'v16.5.0' --> '16.5.0'
|
||||
const major = version.split('.')[0]; // '16.5.0' --> '16'
|
||||
return `nodejs${major}.x`;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/dlv": "^1.1.2",
|
||||
"@types/node": "^14.18.17",
|
||||
"@types/node": "^14.18.18",
|
||||
"astro-scripts": "workspace:*"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
"@rollup/plugin-typescript": "^8.3.2",
|
||||
"@types/chai": "^4.3.1",
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/node": "^14.18.17",
|
||||
"@types/node": "^14.18.18",
|
||||
"@ungap/structured-clone": "^0.3.4",
|
||||
"abort-controller": "^3.0.0",
|
||||
"chai": "^4.3.6",
|
||||
|
@ -66,7 +66,7 @@
|
|||
"magic-string": "^0.25.9",
|
||||
"mocha": "^9.2.2",
|
||||
"node-fetch": "^3.2.4",
|
||||
"rollup": "^2.72.1",
|
||||
"rollup": "^2.73.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"tslib": "^2.4.0",
|
||||
"typescript": "^4.6.4",
|
||||
|
|
1117
pnpm-lock.yaml
1117
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,5 @@
|
|||
Date,Commits (24hr),Issues (24hr),Issues:BUG (24hr),Issues:RFC (24hr),Issues:DOC (24hr),PRs (24hr),Open PRs,Open Issues,Bugs: Needs Triage,Bugs: Accepted,RFC: In Progress,RFC: Accepted,Date (ISO)
|
||||
"Monday, May 16, 2022",2,1,1,0,0,2,12,75,36,31,0,0,"2022-05-16T12:06:42.223Z"
|
||||
"Sunday, May 15, 2022",1,2,2,0,0,1,11,74,35,31,0,0,"2022-05-15T12:01:59.884Z"
|
||||
"Saturday, May 14, 2022",1,4,4,0,0,3,10,72,33,31,0,0,"2022-05-14T12:01:51.743Z"
|
||||
"Friday, May 13, 2022",17,6,6,0,0,5,7,70,35,28,0,0,"2022-05-13T12:01:50.988Z"
|
||||
|
|
|
Loading…
Reference in a new issue