Skip to content

Commit

Permalink
chore: merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 21, 2024
2 parents 8309c61 + b9c05f4 commit 285c6e3
Show file tree
Hide file tree
Showing 56 changed files with 586 additions and 272 deletions.
9 changes: 9 additions & 0 deletions .changeset/strong-stingrays-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@astrojs/solid-js': patch
'@astrojs/vue': patch
'@astrojs/svelte': patch
'@astrojs/react': patch
'@astrojs/preact': patch
---

Resolve `vite` peer dependency problem for strict package managers like **Yarn in PnP mode**.
68 changes: 34 additions & 34 deletions .github/scripts/announce.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { globby as glob } from 'globby';
import { fileURLToPath } from 'node:url';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { globby as glob } from 'globby';
import { setOutput } from './utils.mjs';

const { GITHUB_REF = 'main' } = process.env;
Expand All @@ -18,34 +18,34 @@ const descriptors = [
'updates',
];
const verbs = [
"just went out!",
"just launched!",
"now available!",
"in the wild!",
"now live!",
"hit the registry!",
"to share!",
"for you!",
"for y’all! 🤠",
"comin’ your way!",
"comin’ atcha!",
"comin’ in hot!",
"freshly minted on the blockchain! (jk)",
"[is] out (now with 100% more reticulated splines!)",
"(as seen on TV!)",
"just dropped!",
"– artisanally hand-crafted just for you.",
"– oh happy day!",
"– enjoy!",
"now out. Be the first on your block to download!",
"made with love 💕",
"[is] out! Our best [version] yet!",
"[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!",
"... HUZZAH!",
"[has] landed!",
"landed! The internet just got a little more fun.",
"– from our family to yours.",
"– go forth and build!"
'just went out!',
'just launched!',
'now available!',
'in the wild!',
'now live!',
'hit the registry!',
'to share!',
'for you!',
'for y’all! 🤠',
'comin’ your way!',
'comin’ atcha!',
'comin’ in hot!',
'freshly minted on the blockchain! (jk)',
'[is] out (now with 100% more reticulated splines!)',
'(as seen on TV!)',
'just dropped!',
'– artisanally hand-crafted just for you.',
'– oh happy day!',
'– enjoy!',
'now out. Be the first on your block to download!',
'made with love 💕',
'[is] out! Our best [version] yet!',
'[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!',
'... HUZZAH!',
'[has] landed!',
'landed! The internet just got a little more fun.',
'– from our family to yours.',
'– go forth and build!',
];
const extraVerbs = [
'new',
Expand All @@ -72,7 +72,7 @@ const plurals = new Map([

function pluralize(text) {
return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) =>
plurals.has(match) ? plurals.get(match) : `${match}s`
plurals.has(match) ? plurals.get(match) : `${match}s`,
);
}

Expand All @@ -91,7 +91,7 @@ async function generatePackageMap() {
const pkgFile = fileURLToPath(new URL(pkg, packageRoot));
const content = await readFile(pkgFile).then((res) => JSON.parse(res.toString()));
packageMap.set(content.name, `./packages/${pkg.replace('/package.json', '')}`);
})
}),
);
}

Expand All @@ -110,7 +110,7 @@ async function generateMessage() {
version,
url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString(),
};
})
}),
);

const emoji = item(emojis);
Expand All @@ -122,7 +122,7 @@ async function generateMessage() {
if (packages.length === 1) {
const { name, version, url } = packages[0];
message += `${emoji} \`${name}@${version}\` ${singularlize(
verb
verb,
)}\nRead the [release notes →](<${url}>)\n`;
} else {
message += `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
Expand Down
54 changes: 35 additions & 19 deletions .github/scripts/bundle-size.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { build } from 'esbuild';
import { existsSync } from 'node:fs';
import { build } from 'esbuild';

const CLIENT_RUNTIME_PATH = 'packages/astro/src/runtime/client/';

function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 B';
if (bytes === 0) return '0 B';

const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

const i = Math.floor(Math.log(bytes) / Math.log(k));
const i = Math.floor(Math.log(bytes) / Math.log(k));

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

export default async function checkBundleSize({ github, context }) {
Expand All @@ -24,7 +24,7 @@ export default async function checkBundleSize({ github, context }) {
pull_number: PR_NUM,
});
const clientRuntimeFiles = files.filter((file) => {
return file.filename.startsWith(CLIENT_RUNTIME_PATH) && file.status !== 'removed'
return file.filename.startsWith(CLIENT_RUNTIME_PATH) && file.status !== 'removed';
});
if (clientRuntimeFiles.length === 0) return;

Expand All @@ -35,17 +35,24 @@ export default async function checkBundleSize({ github, context }) {
const output = await bundle(clientRuntimeFiles);

for (let [filename, { oldSize, newSize, sourceFile }] of Object.entries(output)) {
filename = ['idle', 'load', 'media', 'only', 'visible'].includes(filename) ? `client:${filename}` : filename;
const prefix = (newSize - oldSize) === 0 ? '' : (newSize - oldSize) > 0 ? '+ ' : '- ';
filename = ['idle', 'load', 'media', 'only', 'visible'].includes(filename)
? `client:${filename}`
: filename;
const prefix = newSize - oldSize === 0 ? '' : newSize - oldSize > 0 ? '+ ' : '- ';
const change = `${prefix}${formatBytes(newSize - oldSize)}`;
table.push(`| [\`${filename}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${context.payload.pull_request.head.ref}/${sourceFile}) | ${formatBytes(oldSize)} | ${formatBytes(newSize)} | ${change} |`);
table.push(
`| [\`${filename}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${context.payload.pull_request.head.ref}/${sourceFile}) | ${formatBytes(oldSize)} | ${formatBytes(newSize)} | ${change} |`,
);
}

const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: PR_NUM
})
const comment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Bundle Size Check'));
issue_number: PR_NUM,
});
const comment = comments.find(
(comment) =>
comment.user.login === 'github-actions[bot]' && comment.body.includes('Bundle Size Check'),
);
const method = comment ? 'updateComment' : 'createComment';
const payload = comment ? { comment_id: comment.id } : { issue_number: PR_NUM };
await github.rest.issues[method]({
Expand All @@ -60,27 +67,36 @@ ${table.join('\n')}`,
}

async function bundle(files) {

const { metafile } = await build({
entryPoints: [...files.map(({ filename }) => filename), ...files.map(({ filename }) => `main/${filename}`).filter(f => existsSync(f))],
entryPoints: [
...files.map(({ filename }) => filename),
...files.map(({ filename }) => `main/${filename}`).filter((f) => existsSync(f)),
],
bundle: true,
minify: true,
sourcemap: false,
target: ['es2018'],
outdir: 'out',
external: ['astro:*', 'aria-query', 'axobject-query'],
metafile: true,
})
});

return Object.entries(metafile.outputs).reduce((acc, [filename, info]) => {
filename = filename.slice('out/'.length);
if (filename.startsWith('main/')) {
filename = filename.slice('main/'.length).replace(CLIENT_RUNTIME_PATH, '').replace('.js', '');
const oldSize = info.bytes;
return Object.assign(acc, { [filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { oldSize }) });
return Object.assign(acc, {
[filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { oldSize }),
});
}
filename = filename.replace(CLIENT_RUNTIME_PATH, '').replace('.js', '');
const newSize = info.bytes;
return Object.assign(acc, { [filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, { newSize, sourceFile: Object.keys(info.inputs).find(src => src.endsWith('.ts')) }) });
return Object.assign(acc, {
[filename]: Object.assign(acc[filename] ?? { oldSize: 0, newSize: 0 }, {
newSize,
sourceFile: Object.keys(info.inputs).find((src) => src.endsWith('.ts')),
}),
});
}, {});
}
86 changes: 40 additions & 46 deletions .github/scripts/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
import * as fs from 'node:fs'
import * as os from 'node:os'
import * as crypto from 'node:crypto'
import * as crypto from 'node:crypto';
import * as fs from 'node:fs';
import * as os from 'node:os';

/** Based on https://github.com/actions/toolkit/blob/4e3b068ce116d28cb840033c02f912100b4592b0/packages/core/src/file-command.ts */
export function setOutput(key, value) {
const filePath = process.env['GITHUB_OUTPUT'] || ''
if (filePath) {
return issueFileCommand('OUTPUT', prepareKeyValueMessage(key, value))
}
process.stdout.write(os.EOL)
const filePath = process.env['GITHUB_OUTPUT'] || '';
if (filePath) {
return issueFileCommand('OUTPUT', prepareKeyValueMessage(key, value));
}
process.stdout.write(os.EOL);
}

function issueFileCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`]
if (!filePath) {
throw new Error(
`Unable to find environment variable for file command ${command}`
)
}
if (!fs.existsSync(filePath)) {
throw new Error(`Missing file at path: ${filePath}`)
}

fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, {
encoding: 'utf8'
})
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
throw new Error(`Unable to find environment variable for file command ${command}`);
}
if (!fs.existsSync(filePath)) {
throw new Error(`Missing file at path: ${filePath}`);
}

fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, {
encoding: 'utf8',
});
}

function prepareKeyValueMessage(key, value) {
const delimiter = `gh-delimiter-${crypto.randomUUID()}`
const convertedValue = toCommandValue(value)

// These should realistically never happen, but just in case someone finds a
// way to exploit uuid generation let's not allow keys or values that contain
// the delimiter.
if (key.includes(delimiter)) {
throw new Error(
`Unexpected input: name should not contain the delimiter "${delimiter}"`
)
}

if (convertedValue.includes(delimiter)) {
throw new Error(
`Unexpected input: value should not contain the delimiter "${delimiter}"`
)
}

return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`
const delimiter = `gh-delimiter-${crypto.randomUUID()}`;
const convertedValue = toCommandValue(value);

// These should realistically never happen, but just in case someone finds a
// way to exploit uuid generation let's not allow keys or values that contain
// the delimiter.
if (key.includes(delimiter)) {
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
}

if (convertedValue.includes(delimiter)) {
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
}

return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
}

function toCommandValue(input) {
if (input === null || input === undefined) {
return ''
} else if (typeof input === 'string' || input instanceof String) {
return input
}
return JSON.stringify(input)
if (input === null || input === undefined) {
return '';
} else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ jobs:
- name: Build Packages
run: pnpm run build

- name: Lint
- name: Lint source code
run: pnpm run lint:ci

- name: Lint publish code
run: pnpm run publint

test:
name: "Test: ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})"
runs-on: ${{ matrix.os }}
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/continuous_benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ on:
pull_request:
branches:
- main
paths:
- 'packages/astro/src/**/*.ts'
- 'benchmark/**'
push:
branches:
- main
paths:
- 'packages/astro/src/**/*.ts'
- 'benchmark/**'

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
FORCE_COLOR: true
CODSPEED_TOKEN: ${{ secrets.CODSPEED_TOKEN }}
CODSPEED: true

jobs:
codspeed:
if: ${{ github.repository_owner == 'withastro' }}
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -47,4 +51,5 @@ jobs:
timeout-minutes: 30
with:
run: pnpm benchmark codspeed
token: ${{ secrets.CODSPEED_TOKEN }}

4 changes: 2 additions & 2 deletions STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Anything enforced by linting and formatting is considered a **style rule.** It i

These style rules are maintained in configuration files, and therefore not documented in this document. Read any of the following configuration files to learn more about the style rules that we strictly enforced across the codebase:

- [ESLint](https://github.com/withastro/astro/blob/main/.eslintrc.cjs) (Linting)
- [Prettier](https://github.com/withastro/astro/blob/main/.prettierrc.json) (Formatting)
- [ESLint](https://github.com/withastro/astro/blob/main/eslint.config.js) (Linting)
- [Prettier](https://github.com/withastro/astro/blob/main/prettier.config.js) (Formatting)

Alternatively, don't worry too much about style rules and trust that our tools will catch these issues for you and offer inline suggestions as you work.

Expand Down
Loading

0 comments on commit 285c6e3

Please sign in to comment.