Skip to content

Commit

Permalink
Merge branch 'main' into fix/leave-assets-with-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Sep 6, 2023
2 parents 7bcfdf0 + 35dff82 commit bbc8c89
Show file tree
Hide file tree
Showing 30 changed files with 204 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-rings-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes remote assets caching logic to not use expired assets
6 changes: 6 additions & 0 deletions .changeset/friendly-clocks-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-astro': patch
'astro': patch
---

Support detecting Bun when logging messages with package manager information.
5 changes: 5 additions & 0 deletions .changeset/modern-guests-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Fix serverless function naming conflicts for routes with identical filenames but different directory structures
5 changes: 5 additions & 0 deletions .changeset/twelve-cars-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix markdown page HMR
4 changes: 2 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"ora": "^7.0.1",
"p-limit": "^4.0.0",
"path-to-regexp": "^6.2.1",
"preferred-pm": "^3.0.3",
"preferred-pm": "^3.1.2",
"prompts": "^2.4.2",
"rehype": "^12.0.1",
"resolve": "^1.22.4",
Expand All @@ -172,7 +172,7 @@
"vfile": "^5.3.7",
"vite": "^4.4.9",
"vitefu": "^0.2.4",
"which-pm": "^2.0.0",
"which-pm": "^2.1.1",
"yargs-parser": "^21.1.1",
"zod": "3.21.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function generateImage(
const JSONData = JSON.parse(readFileSync(cachedFileURL, 'utf-8')) as RemoteCacheEntry;

// If the cache entry is not expired, use it
if (JSONData.expires < Date.now()) {
if (JSONData.expires > Date.now()) {
await fs.promises.writeFile(finalFileURL, Buffer.from(JSONData.data, 'base64'));

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ async function getInstallIntegrationsCommand({
return { pm: 'yarn', command: 'add', flags: [], dependencies };
case 'pnpm':
return { pm: 'pnpm', command: 'add', flags: [], dependencies };
case 'bun':
return { pm: 'bun', command: 'add', flags: [], dependencies };
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/cli/install-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function getInstallCommand(packages: string[], packageManager: string) {
return { pm: 'yarn', command: 'add', flags: [], dependencies: packages };
case 'pnpm':
return { pm: 'pnpm', command: 'add', flags: [], dependencies: packages };
case 'bun':
return { pm: 'bun', command: 'add', flags: [], dependencies: packages };
default:
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/cli/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import whichPm from 'which-pm';
import type yargs from 'yargs-parser';
import * as msg from '../../core/messages.js';
import { telemetry } from '../../events/index.js';
Expand All @@ -8,8 +9,9 @@ interface TelemetryOptions {
}

export async function notify() {
const packageManager = (await whichPm(process.cwd())).name ?? 'npm';
await telemetry.notify(() => {
console.log(msg.telemetryNotice() + '\n');
console.log(msg.telemetryNotice(packageManager) + '\n');
return true;
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export function serverStart({
.join('\n');
}

export function telemetryNotice() {
export function telemetryNotice(packageManager = 'npm') {
const headline = `${cyan('◆')} Astro collects completely anonymous usage data.`;
const why = dim(' This optional program helps shape our roadmap.');
const disable = dim(' Run `npm run astro telemetry disable` to opt-out.');
const disable = dim(` Run \`${packageManager} run astro telemetry disable\` to opt-out.`);
const details = ` Details: ${underline('https://astro.build/telemetry')}`;
return [headline, why, disable, details].map((v) => ' ' + v).join('\n');
}
Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function markdown({ settings, logger }: AstroPluginOptions): Plug
}

const code = escapeViteEnvReferences(`
import { unescapeHTML, spreadAttributes, createComponent, render, renderComponent } from ${JSON.stringify(
import { unescapeHTML, spreadAttributes, createComponent, render, renderComponent, maybeRenderHead } from ${JSON.stringify(
astroServerRuntimeModulePath
)};
import { AstroError, AstroErrorData } from ${JSON.stringify(astroErrorModulePath)};
Expand Down Expand Up @@ -180,10 +180,9 @@ export default function markdown({ settings, logger }: AstroPluginOptions): Plug
}, {
'default': () => render\`\${unescapeHTML(html)}\`
})}\`;`
: `render\`\${unescapeHTML(html)}\`;`
: `render\`\${maybeRenderHead(result)}\${unescapeHTML(html)}\`;`
}
});
Content[Symbol.for('astro.needsHeadRendering')] = ${layout ? 'false' : 'true'};
export default Content;
`);

Expand Down
5 changes: 5 additions & 0 deletions packages/astro/test/astro-pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ describe('Pages', () => {

expect($('#testing').length).to.be.greaterThan(0);
});

it('should have Vite client in dev', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
expect(html).to.include('/@vite/client', 'Markdown page does not have Vite client for HMR');
});
});
});
6 changes: 3 additions & 3 deletions packages/create-astro/src/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Context {
help: boolean;
prompt: typeof prompt;
cwd: string;
pkgManager: string;
packageManager: string;
username: string;
version: string;
skipHouston: boolean;
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function getContext(argv: string[]): Promise<Context> {
{ argv, permissive: true }
);

const pkgManager = detectPackageManager()?.name ?? 'npm';
const packageManager = detectPackageManager()?.name ?? 'npm';
const [username, version] = await Promise.all([getName(), getVersion()]);
let cwd = flags['_'][0];
let {
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function getContext(argv: string[]): Promise<Context> {
const context: Context = {
help,
prompt,
pkgManager,
packageManager,
username,
version,
skipHouston,
Expand Down
14 changes: 7 additions & 7 deletions packages/create-astro/src/actions/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { shell } from '../shell.js';
import type { Context } from './context';

export async function dependencies(
ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'pkgManager' | 'cwd' | 'dryRun'>
ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'packageManager' | 'cwd' | 'dryRun'>
) {
let deps = ctx.install ?? ctx.yes;
if (deps === undefined) {
Expand All @@ -25,15 +25,15 @@ export async function dependencies(
await info('--dry-run', `Skipping dependency installation`);
} else if (deps) {
await spinner({
start: `Installing dependencies with ${ctx.pkgManager}...`,
start: `Installing dependencies with ${ctx.packageManager}...`,
end: 'Dependencies installed',
while: () => {
return install({ pkgManager: ctx.pkgManager, cwd: ctx.cwd }).catch((e) => {
return install({ packageManager: ctx.packageManager, cwd: ctx.cwd }).catch((e) => {
error('error', e);
error(
'error',
`Dependencies failed to install, please run ${color.bold(
ctx.pkgManager + ' install'
ctx.packageManager + ' install'
)} to install them manually after setup.`
);
});
Expand All @@ -47,9 +47,9 @@ export async function dependencies(
}
}

async function install({ pkgManager, cwd }: { pkgManager: string; cwd: string }) {
if (pkgManager === 'yarn') await ensureYarnLock({ cwd });
return shell(pkgManager, ['install'], { cwd, timeout: 90_000, stdio: 'ignore' });
async function install({ packageManager, cwd }: { packageManager: string; cwd: string }) {
if (packageManager === 'yarn') await ensureYarnLock({ cwd });
return shell(packageManager, ['install'], { cwd, timeout: 90_000, stdio: 'ignore' });
}

async function ensureYarnLock({ cwd }: { cwd: string }) {
Expand Down
17 changes: 10 additions & 7 deletions packages/create-astro/src/actions/next-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import type { Context } from './context';

import { nextSteps, say } from '../messages.js';

export async function next(ctx: Pick<Context, 'cwd' | 'pkgManager' | 'skipHouston'>) {
export async function next(ctx: Pick<Context, 'cwd' | 'packageManager' | 'skipHouston'>) {
let projectDir = path.relative(process.cwd(), ctx.cwd);
const devCmd =
ctx.pkgManager === 'npm'
? 'npm run dev'
: ctx.pkgManager === 'bun'
? 'bun run dev'
: `${ctx.pkgManager} dev`;

const commandMap: { [key: string]: string } = {
npm: 'npm run dev',
bun: 'bun run dev',
yarn: 'yarn dev',
pnpm: 'pnpm dev',
};

const devCmd = commandMap[ctx.packageManager as keyof typeof commandMap] || 'npm run dev';
await nextSteps({ projectDir, devCmd });

if (!ctx.skipHouston) {
Expand Down
10 changes: 5 additions & 5 deletions packages/create-astro/test/dependencies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('dependencies', () => {
const context = {
cwd: '',
yes: true,
pkgManager: 'npm',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
};
Expand All @@ -21,7 +21,7 @@ describe('dependencies', () => {
it('prompt yes', async () => {
const context = {
cwd: '',
pkgManager: 'npm',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: true }),
install: undefined,
Expand All @@ -34,7 +34,7 @@ describe('dependencies', () => {
it('prompt no', async () => {
const context = {
cwd: '',
pkgManager: 'npm',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: false }),
install: undefined,
Expand All @@ -48,7 +48,7 @@ describe('dependencies', () => {
const context = {
cwd: '',
install: true,
pkgManager: 'npm',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: false }),
};
Expand All @@ -61,7 +61,7 @@ describe('dependencies', () => {
const context = {
cwd: '',
install: false,
pkgManager: 'npm',
packageManager: 'npm',
dryRun: true,
prompt: () => ({ deps: false }),
};
Expand Down
4 changes: 2 additions & 2 deletions packages/create-astro/test/next.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ describe('next steps', () => {
const fixture = setup();

it('no arguments', async () => {
await next({ skipHouston: false, cwd: './it/fixtures/not-empty', pkgManager: 'npm' });
await next({ skipHouston: false, cwd: './it/fixtures/not-empty', packageManager: 'npm' });
expect(fixture.hasMessage('Liftoff confirmed.')).to.be.true;
expect(fixture.hasMessage('npm run dev')).to.be.true;
expect(fixture.hasMessage('Good luck out there, astronaut!')).to.be.true;
});

it('--skip-houston', async () => {
await next({ skipHouston: true, cwd: './it/fixtures/not-empty', pkgManager: 'npm' });
await next({ skipHouston: true, cwd: './it/fixtures/not-empty', packageManager: 'npm' });
expect(fixture.hasMessage('Good luck out there, astronaut!')).to.be.false;
});
});
8 changes: 6 additions & 2 deletions packages/integrations/cloudflare/test/basics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ describe('Basic app', () => {
/** @type {import('./test-utils').WranglerCLI} */
let cli;

before(async () => {
before(async function () {
fixture = await loadFixture({
root: './fixtures/basics/',
});
await fixture.build();

cli = await runCLI('./fixtures/basics/', { silent: true, port: 8789 });
await cli.ready;
await cli.ready.catch((e) => {
console.log(e);
// if fail to start, skip for now as it's very flaky
this.skip();
});
});

after(async () => {
Expand Down
12 changes: 8 additions & 4 deletions packages/integrations/cloudflare/test/cf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ describe('Cf metadata and caches', () => {
/** @type {import('./test-utils').WranglerCLI} */
let cli;

before(async () => {
before(async function () {
fixture = await loadFixture({
root: './fixtures/cf/',
output: 'server',
adapter: cloudflare(),
});
await fixture.build();

cli = await runCLI('./fixtures/cf/', { silent: false, port: 8788 });
await cli.ready;
cli = await runCLI('./fixtures/cf/', { silent: true, port: 8786 });
await cli.ready.catch((e) => {
console.log(e);
// if fail to start, skip for now as it's very flaky
this.skip();
});
});

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

it('Load cf and caches API', async () => {
let res = await fetch(`http://127.0.0.1:8788/`);
let res = await fetch(`http://127.0.0.1:8786/`);
expect(res.status).to.equal(200);
let html = await res.text();
let $ = cheerio.load(html);
Expand Down
8 changes: 6 additions & 2 deletions packages/integrations/cloudflare/test/runtime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Runtime Locals', () => {
/** @type {import('./test-utils.js').WranglerCLI} */
let cli;

before(async () => {
before(async function () {
fixture = await loadFixture({
root: './fixtures/runtime/',
output: 'server',
Expand All @@ -18,7 +18,11 @@ describe('Runtime Locals', () => {
await fixture.build();

cli = await runCLI('./fixtures/runtime/', { silent: true, port: 8793 });
await cli.ready;
await cli.ready.catch((e) => {
console.log(e);
// if fail to start, skip for now as it's very flaky
this.skip();
});
});

after(async () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/integrations/cloudflare/test/with-solid-js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ describe('With SolidJS', () => {
/** @type {import('./test-utils').WranglerCLI} */
let cli;

before(async () => {
before(async function () {
fixture = await loadFixture({
root: './fixtures/with-solid-js/',
});
await fixture.build();

cli = await runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
await cli.ready;
await cli.ready.catch((e) => {
console.log(e);
// if fail to start, skip for now as it's very flaky
this.skip();
});
});

after(async () => {
Expand Down
Loading

0 comments on commit bbc8c89

Please sign in to comment.