Merge branch 'main' into add-Minification

This commit is contained in:
wulinsheng123 2023-04-20 09:38:46 +08:00 committed by GitHub
commit 1cbc00bfca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 88 additions and 120 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---
Refactor static adapter to use updateConfig method

View file

@ -24,6 +24,9 @@ env:
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
FORCE_COLOR: true FORCE_COLOR: true
ASTRO_TELEMETRY_DISABLED: true ASTRO_TELEMETRY_DISABLED: true
# 7 GiB by default on GitHub, setting to 6 GiB
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
NODE_OPTIONS: --max-old-space-size=6144
jobs: jobs:
lint: lint:
@ -112,11 +115,13 @@ jobs:
needs: build needs: build
strategy: strategy:
matrix: matrix:
OS: [ubuntu-latest, windows-latest] OS: [ubuntu-latest]
NODE_VERSION: [16, 18] NODE_VERSION: [16, 18]
include: include:
- os: macos-latest - os: macos-latest
NODE_VERSION: 16 NODE_VERSION: 16
- os: windows-latest
NODE_VERSION: 16
fail-fast: false fail-fast: false
env: env:
NODE_VERSION: ${{ matrix.NODE_VERSION }} NODE_VERSION: ${{ matrix.NODE_VERSION }}
@ -221,4 +226,3 @@ jobs:
run: pnpm run test:smoke run: pnpm run test:smoke
env: env:
SKIP_OG: 1 SKIP_OG: 1
NODE_OPTIONS: "--max-old-space-size=4096"

View file

@ -7,17 +7,17 @@ We welcome contributions of any size and skill level. As an open source project,
## Quick Guide ## Quick Guide
### Prerequisite ### Prerequisites
```shell ```shell
node: "^14.18.0 || >=16.12.0" node: "^>=16.12.0"
pnpm: "^7.9.5" pnpm: "^8.2.0"
# otherwise, your build will fail # otherwise, your build will fail
``` ```
### Setting up your local repo ### Setting up your local repo
Astro uses pnpm workspaces, so you should **always run `pnpm install` from the top-level project directory.** running `pnpm install` in the top-level project root will install dependencies for `astro`, and every package in the repo. Astro uses pnpm workspaces, so you should **always run `pnpm install` from the top-level project directory**. Running `pnpm install` in the top-level project root will install dependencies for `astro`, and every package in the repo.
```shell ```shell
git clone && cd ... git clone && cd ...
@ -35,7 +35,7 @@ To automatically handle merge conflicts in `pnpm-lock.yaml`, you should run the
```shell ```shell
pnpm add -g @pnpm/merge-driver pnpm add -g @pnpm/merge-driver
pnpx npm-merge-driver install --driver-name pnpm-merge-driver --driver "pnpm-merge-driver %A %O %B %P" --files pnpm-lock.yaml pnpm dlx npm-merge-driver install --driver-name pnpm-merge-driver --driver "pnpm-merge-driver %A %O %B %P" --files pnpm-lock.yaml
``` ```
### Using GitHub Codespaces for development ### Using GitHub Codespaces for development
@ -44,7 +44,7 @@ To get started, create a codespace for this repository by clicking this 👇
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro)
Your new codespace will open in a web-based version of Visual Studio Code. All development dependcies will be preinstalled and the tests will run automatically ensuring you've got a green base from which to start working. Your new codespace will open in a web-based version of Visual Studio Code. All development dependencies will be preinstalled, and the tests will run automatically ensuring you've got a green base from which to start working.
**Note**: Dev containers is now an open spec which is supported by [GitHub Codespaces](https://github.com/codespaces) and [other supporting tools](https://containers.dev/supporting). **Note**: Dev containers is now an open spec which is supported by [GitHub Codespaces](https://github.com/codespaces) and [other supporting tools](https://containers.dev/supporting).
@ -63,7 +63,7 @@ During the development process, you may want to test your changes to ensure they
1. Run any of the examples in the `/examples` folder. They are linked to use the local Astro source code, so you can see the effects of your changes. 1. Run any of the examples in the `/examples` folder. They are linked to use the local Astro source code, so you can see the effects of your changes.
``` ```shell
pnpm --filter @example/minimal run dev pnpm --filter @example/minimal run dev
``` ```
@ -77,7 +77,7 @@ Overall, it's up to personal preference which method to use. For smaller changes
You can debug vite by prefixing any command with `DEBUG` like so: You can debug vite by prefixing any command with `DEBUG` like so:
``` ```shell
DEBUG=vite:* astro dev # debug everything in Vite DEBUG=vite:* astro dev # debug everything in Vite
DEBUG=vite:[name] astro dev # debug specific process, e.g. "vite:deps" or "vite:transform" DEBUG=vite:[name] astro dev # debug specific process, e.g. "vite:deps" or "vite:transform"
``` ```
@ -168,7 +168,7 @@ Server-side rendering (SSR) can be complicated. The Astro package (`packages/ast
- `core/`: Code that executes **in the top-level scope** (in Node). Within, youll find code that powers the `astro build` and `astro dev` commands, as well as top-level SSR code. - `core/`: Code that executes **in the top-level scope** (in Node). Within, youll find code that powers the `astro build` and `astro dev` commands, as well as top-level SSR code.
- `runtime/`: Code that executes **in different scopes** (i.e. not in a pure Node context). Youll have to think about code differently here. - `runtime/`: Code that executes **in different scopes** (i.e. not in a pure Node context). Youll have to think about code differently here.
- `client/`: Code that executes **in the browser.** Astros partial hydration code lives here, and only browser-compatible code can be used. - `client/`: Code that executes **in the browser.** Astros partial hydration code lives here, and only browser-compatible code can be used.
- `server/`: Code that executes **inside Vites SSR.** Though this is a Node environment inside, this will be executed independently from `core/` and may have to be structured differently. - `server/`: Code that executes **inside Vites SSR.** Though this is a Node environment inside, this will be executed independently of `core/` and may have to be structured differently.
- `vite-plugin-*/`: Any Vite plugins that Astro needs to run. For the most part, these also execute within Vite similar to `src/runtime/server/`, but its also helpful to think about them as independent modules. _Note: at the moment these are internal while theyre in development_ - `vite-plugin-*/`: Any Vite plugins that Astro needs to run. For the most part, these also execute within Vite similar to `src/runtime/server/`, but its also helpful to think about them as independent modules. _Note: at the moment these are internal while theyre in development_
### Thinking about SSR ### Thinking about SSR
@ -198,7 +198,7 @@ By default, `create-astro` and [astro.new](https://astro.new) point to this bran
## Releasing Astro ## Releasing Astro
_Note: Only [core maintainers (L3+)](https://github.com/withastro/.github/blob/main/GOVERNANCE.md#level-3-l3---core-maintainer) can release new versions of Astro._ _Note: Only [core maintainers (L3+)](https://github.com/withastro/.github/blob/main/GOVERNANCE.md#level-3-l3---core) can release new versions of Astro._
The repo is set up with automatic releases, using the changeset GitHub action & bot. The repo is set up with automatic releases, using the changeset GitHub action & bot.
@ -230,15 +230,15 @@ git reset --hard
By default, every package with a changeset will be released. If you only want to target a smaller subset of packages for release, you can consider clearing out the `.changesets` directory to replace all existing changesets with a single changeset of only the packages that you want to release. Just be sure not to commit or push this to `main`, since it will destroy existing changesets that you will still want to eventually release. By default, every package with a changeset will be released. If you only want to target a smaller subset of packages for release, you can consider clearing out the `.changesets` directory to replace all existing changesets with a single changeset of only the packages that you want to release. Just be sure not to commit or push this to `main`, since it will destroy existing changesets that you will still want to eventually release.
Full documentation: https://github.com/atlassian/changesets/blob/main/docs/snapshot-releases.md Full documentation: https://github.com/changesets/changesets/blob/main/docs/snapshot-releases.md
### Releasing `astro@next` (aka "prerelease mode") ### Releasing `astro@next` (aka "prerelease mode")
Sometimes, the repo will enter into "prerelease mode". In prerelease mode, our normal release process will publish npm versions under the `next` dist-tag, instead of the default `latest` tag. We do this from time-to-time to test large features before sharing them with the larger Astro audience. Sometimes, the repo will enter into "prerelease mode". In prerelease mode, our normal release process will publish npm versions under the `next` dist-tag, instead of the default `latest` tag. We do this from time-to-time to test large features before sharing them with the larger Astro audience.
While in prerelease mode, follow the normal release process to release `astro@next` instead of `astro@latest`. To release `astro@latest` instead, see [Releasing `astro@latest` while in prerelease mode](#user-content-releasing-astrolatest-while-in-prerelease-mode). While in prerelease mode, follow the normal release process to release `astro@next` instead of `astro@latest`. To release `astro@latest` instead, see [Releasing `astro@latest` while in prerelease mode](#releasing-astrolatest-while-in-prerelease-mode).
Full documentation: https://github.com/atlassian/changesets/blob/main/docs/prereleases.md Full documentation: https://github.com/changesets/changesets/blob/main/docs/prereleases.md
### Entering prerelease mode ### Entering prerelease mode

View file

@ -40,6 +40,7 @@ ${chosenMethod} requests are not available when building a static site. Update y
return response; return response;
} }
// TODO: Remove support for old API in Astro 3.0
if (handler.length > 1) { if (handler.length > 1) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn(` console.warn(`
@ -57,6 +58,7 @@ Update your code to remove this warning.`);
if (prop in target) { if (prop in target) {
return Reflect.get(target, prop); return Reflect.get(target, prop);
} else if (prop in params) { } else if (prop in params) {
// TODO: Remove support for old API in Astro 3.0
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn(` console.warn(`
API routes no longer pass params as the first argument. Instead an object containing a params property is provided in the form of: API routes no longer pass params as the first argument. Instead an object containing a params property is provided in the form of:

View file

@ -10,38 +10,6 @@ describe('API routes', () => {
await fixture.build(); await fixture.build();
}); });
describe('Deprecated API', () => {
it('two argument supported', async () => {
const one = JSON.parse(await fixture.readFile('/old-api/twoarg/one.json'));
expect(one).to.deep.equal({
param: 'one',
pathname: '/old-api/twoarg/one.json',
});
const two = JSON.parse(await fixture.readFile('/old-api/twoarg/two.json'));
expect(two).to.deep.equal({
param: 'two',
pathname: '/old-api/twoarg/two.json',
});
});
it('param first argument is supported', async () => {
const one = JSON.parse(await fixture.readFile('/old-api/onearg/one.json'));
expect(one).to.deep.equal({
param: 'one',
});
});
});
describe('1.0 API', () => {
it('Receives a context argument', async () => {
const one = JSON.parse(await fixture.readFile('/context/data/one.json'));
expect(one).to.deep.equal({
param: 'one',
pathname: '/context/data/one.json',
});
});
});
describe('Binary data', () => { describe('Binary data', () => {
it('can be returned from a response', async () => { it('can be returned from a response', async () => {
const dat = await fixture.readFile('/binary.dat', null); const dat = await fixture.readFile('/binary.dat', null);

View file

@ -53,7 +53,6 @@ describe('Environment Variables', () => {
it('includes public env in client-side JS', async () => { it('includes public env in client-side JS', async () => {
let dirs = await fixture.readdir('/_astro'); let dirs = await fixture.readdir('/_astro');
console.log(dirs);
let found = false; let found = false;
// Look in all of the .js files to see if the public env is inlined. // Look in all of the .js files to see if the public env is inlined.

View file

@ -1,5 +1,5 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { loadFixture } from './test-utils.js'; import { loadFixture, silentLogging } from './test-utils.js';
describe('Development Routing', () => { describe('Development Routing', () => {
describe('No site config', () => { describe('No site config', () => {
@ -10,7 +10,9 @@ describe('Development Routing', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ root: './fixtures/without-site-config/' }); fixture = await loadFixture({ root: './fixtures/without-site-config/' });
devServer = await fixture.startDevServer(); devServer = await fixture.startDevServer({
logging: silentLogging,
});
}); });
after(async () => { after(async () => {

View file

@ -1,6 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { load as cheerioLoad } from 'cheerio'; import { load as cheerioLoad } from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture, silentLogging } from './test-utils.js';
describe('Dynamic endpoint collision', () => { describe('Dynamic endpoint collision', () => {
describe('build', () => { describe('build', () => {
@ -31,7 +31,9 @@ describe('Dynamic endpoint collision', () => {
root: './fixtures/dynamic-endpoint-collision/', root: './fixtures/dynamic-endpoint-collision/',
}); });
devServer = await fixture.startDevServer(); devServer = await fixture.startDevServer({
logging: silentLogging,
});
}); });
after(async () => { after(async () => {

View file

@ -1,6 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture, silentLogging } from './test-utils.js';
describe('Errors in JavaScript', () => { describe('Errors in JavaScript', () => {
/** @type {import('./test-utils').Fixture} */ /** @type {import('./test-utils').Fixture} */
@ -12,8 +12,13 @@ describe('Errors in JavaScript', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/error-bad-js', root: './fixtures/error-bad-js',
vite: {
logLevel: 'silent',
},
});
devServer = await fixture.startDevServer({
logging: silentLogging,
}); });
devServer = await fixture.startDevServer();
}); });
after(async () => { after(async () => {

View file

@ -1,5 +1,5 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { loadFixture } from './test-utils.js'; import { loadFixture, silentLogging } from './test-utils.js';
describe('Can handle errors that are not instanceof Error', () => { describe('Can handle errors that are not instanceof Error', () => {
/** @type {import('./test-utils').Fixture} */ /** @type {import('./test-utils').Fixture} */
@ -12,7 +12,9 @@ describe('Can handle errors that are not instanceof Error', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/error-non-error', root: './fixtures/error-non-error',
}); });
devServer = await fixture.startDevServer(); devServer = await fixture.startDevServer({
logging: silentLogging,
});
}); });
after(async () => { after(async () => {

View file

@ -1,23 +0,0 @@
export function getStaticPaths() {
return [
{
params: {
param: 'one'
}
},
{
params: {
param: 'two'
}
},
]
}
export function get(params) {
return {
body: JSON.stringify({
param: params.param
})
};
}

View file

@ -1,24 +0,0 @@
export function getStaticPaths() {
return [
{
params: {
param: 'one'
}
},
{
params: {
param: 'two'
}
},
]
}
export function get(params, request) {
return {
body: JSON.stringify({
param: params.param,
pathname: new URL(request.url).pathname
})
};
}

View file

@ -8,7 +8,9 @@
"@astrojs/svelte": "workspace:*", "@astrojs/svelte": "workspace:*",
"@test/component-library-shared": "workspace:*", "@test/component-library-shared": "workspace:*",
"astro": "workspace:*", "astro": "workspace:*",
"preact": "^10.13.2",
"react": "^18.1.0", "react": "^18.1.0",
"react-dom": "^18.1.0" "react-dom": "^18.1.0",
"svelte": "^3.58.0"
} }
} }

View file

@ -28,7 +28,4 @@
margin-top: 2em; margin-top: 2em;
place-items: center; place-items: center;
} }
.message {
text-align: center;
}
</style> </style>

View file

@ -9,7 +9,7 @@ export function get() {
}; };
} }
export async function post(params, request) { export async function post({ params, request }) {
const body = await request.text(); const body = await request.text();
return new Response(body === `some data` ? `ok` : `not ok`, { return new Response(body === `some data` ? `ok` : `not ok`, {
status: 200, status: 200,

View file

@ -5,7 +5,7 @@ export async function getStaticPaths() {
] ]
} }
export async function get(params) { export async function get({ params }) {
return { return {
body: JSON.stringify({ body: JSON.stringify({
slug: params.slug, slug: params.slug,

View file

@ -5,7 +5,7 @@ export async function getStaticPaths() {
]; ];
} }
export async function get(params) { export async function get({ params }) {
return { return {
body: JSON.stringify({ body: JSON.stringify({
slug: params.slug, slug: params.slug,

View file

@ -5,7 +5,7 @@ export async function getStaticPaths() {
]; ];
} }
export async function get(params) { export async function get({ params }) {
return { return {
body: JSON.stringify({ body: JSON.stringify({
slug: params.slug, slug: params.slug,

View file

@ -1,6 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { load as cheerioLoad } from 'cheerio'; import { load as cheerioLoad } from 'cheerio';
import { isWindows, loadFixture } from './test-utils.js'; import { isWindows, loadFixture, silentLogging } from './test-utils.js';
let fixture; let fixture;
@ -103,7 +103,9 @@ describe('React Components', () => {
let devServer; let devServer;
before(async () => { before(async () => {
devServer = await fixture.startDevServer(); devServer = await fixture.startDevServer({
logging: silentLogging,
});
}); });
after(async () => { after(async () => {

View file

@ -18,7 +18,6 @@ describe('srcDir', () => {
const relPath = $('link').attr('href'); const relPath = $('link').attr('href');
const css = await fixture.readFile(relPath); const css = await fixture.readFile(relPath);
console.log(css);
expect(css).to.match(/body{color:green}/); expect(css).to.match(/body{color:green}/);
}); });
}); });

View file

@ -68,6 +68,12 @@ export const defaultLogging = {
level: 'error', level: 'error',
}; };
/** @type {import('../src/core/logger/core').LogOptions} */
export const silentLogging = {
dest: nodeLogDestination,
level: 'silent',
};
/** /**
* Load Astro fixture * Load Astro fixture
* @param {AstroConfig} inlineConfig Astro config partial (note: must specify `root`) * @param {AstroConfig} inlineConfig Astro config partial (note: must specify `root`)

View file

@ -19,12 +19,17 @@ export default function vercelStatic({ analytics }: VercelStaticConfig = {}): As
return { return {
name: '@astrojs/vercel', name: '@astrojs/vercel',
hooks: { hooks: {
'astro:config:setup': ({ command, config, injectScript }) => { 'astro:config:setup': ({ command, config, updateConfig, injectScript }) => {
if (command === 'build' && analytics) { if (command === 'build' && analytics) {
injectScript('page', 'import "@astrojs/vercel/analytics"'); injectScript('page', 'import "@astrojs/vercel/analytics"');
} }
config.outDir = new URL('./static/', getVercelOutput(config.root)); const outDir = new URL('./static/', getVercelOutput(config.root));
config.build.format = 'directory'; updateConfig({
outDir,
build: {
format: 'directory',
},
});
}, },
'astro:config:done': ({ setAdapter, config }) => { 'astro:config:done': ({ setAdapter, config }) => {
setAdapter(getAdapter()); setAdapter(getAdapter());

View file

@ -13,13 +13,13 @@ describe('Fetch', () => {
it('Fetch with https', async () => { it('Fetch with https', async () => {
const { fetch } = target const { fetch } = target
const response = await fetch('https://api.openbrewerydb.org/breweries') const response = await fetch('https://astro.build')
expect(response.constructor).to.equal(target.Response) expect(response.constructor).to.equal(target.Response)
const json = await response.json() const html = await response.text()
expect(json).to.be.an('array') expect(html).to.include('<html')
}) })
it('Fetch with data', async () => { it('Fetch with data', async () => {

View file

@ -2242,12 +2242,18 @@ importers:
astro: astro:
specifier: workspace:* specifier: workspace:*
version: link:../../.. version: link:../../..
preact:
specifier: ^10.13.2
version: 10.13.2
react: react:
specifier: ^18.1.0 specifier: ^18.1.0
version: 18.2.0 version: 18.2.0
react-dom: react-dom:
specifier: ^18.1.0 specifier: ^18.1.0
version: 18.2.0(react@18.2.0) version: 18.2.0(react@18.2.0)
svelte:
specifier: ^3.58.0
version: 3.58.0
packages/astro/test/fixtures/component-library-shared: packages/astro/test/fixtures/component-library-shared:
dependencies: dependencies:
@ -15363,6 +15369,10 @@ packages:
/preact@10.12.0: /preact@10.12.0:
resolution: {integrity: sha512-+w8ix+huD8CNZemheC53IPjMUFk921i02o30u0K6h53spMX41y/QhVDnG/nU2k42/69tvqWmVsgNLIiwRAcmxg==} resolution: {integrity: sha512-+w8ix+huD8CNZemheC53IPjMUFk921i02o30u0K6h53spMX41y/QhVDnG/nU2k42/69tvqWmVsgNLIiwRAcmxg==}
/preact@10.13.2:
resolution: {integrity: sha512-q44QFLhOhty2Bd0Y46fnYW0gD/cbVM9dUVtNTDKPcdXSMA7jfY+Jpd6rk3GB0lcQss0z5s/6CmVP0Z/hV+g6pw==}
dev: false
/prebuild-install@7.1.1: /prebuild-install@7.1.1:
resolution: {integrity: sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==} resolution: {integrity: sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==}
engines: {node: '>=10'} engines: {node: '>=10'}
@ -16705,6 +16715,11 @@ packages:
resolution: {integrity: sha512-S+87/P0Ve67HxKkEV23iCdAh/SX1xiSfjF1HOglno/YTbSTW7RniICMCofWGdJJbdjw3S+0PfFb1JtGfTXE0oQ==} resolution: {integrity: sha512-S+87/P0Ve67HxKkEV23iCdAh/SX1xiSfjF1HOglno/YTbSTW7RniICMCofWGdJJbdjw3S+0PfFb1JtGfTXE0oQ==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
/svelte@3.58.0:
resolution: {integrity: sha512-brIBNNB76mXFmU/Kerm4wFnkskBbluBDCjx/8TcpYRb298Yh2dztS2kQ6bhtjMcvUhd5ynClfwpz5h2gnzdQ1A==}
engines: {node: '>= 8'}
dev: false
/svg-tags@1.0.0: /svg-tags@1.0.0:
resolution: {integrity: sha512-ovssysQTa+luh7A5Weu3Rta6FJlFBBbInjOh722LIt6klpU2/HtdUbszju/G4devcvk8PGt7FCLv5wftu3THUA==} resolution: {integrity: sha512-ovssysQTa+luh7A5Weu3Rta6FJlFBBbInjOh722LIt6klpU2/HtdUbszju/G4devcvk8PGt7FCLv5wftu3THUA==}
dev: false dev: false