Skip to content

Commit

Permalink
Merge branch 'main' into ssr-client-assets
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored May 18, 2022
2 parents deb757c + 54aba72 commit 3d61a50
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 191 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-years-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Update "building for SSR..." log for SSG users to say "building entrypoints for prerendering..."
6 changes: 6 additions & 0 deletions .changeset/thirty-drinks-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'create-astro': patch
---

Fix [#3309](https://github.com/withastro/astro/issues/3309) default logger locale behavior.
6 changes: 3 additions & 3 deletions examples/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"preview": "astro preview"
},
"dependencies": {
"@algolia/client-search": "^4.13.0",
"@docsearch/css": "^3.0.0",
"@docsearch/react": "^3.0.0",
"@algolia/client-search": "^4.13.1",
"@docsearch/css": "^3.1.0",
"@docsearch/react": "^3.1.0",
"@types/react": "^17.0.45",
"preact": "^10.7.2",
"react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.1.0",
"lit": "^2.2.3"
"lit": "^2.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.1.0",
"lit": "^2.2.3",
"lit": "^2.2.4",
"preact": "^10.7.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/integrations-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.1.0",
"lit": "^2.2.3",
"lit": "^2.2.4",
"preact": "^10.7.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"@changesets/changelog-github": "0.4.4",
"@changesets/cli": "2.22.0",
"@octokit/action": "^3.18.1",
"@typescript-eslint/eslint-plugin": "^5.24.0",
"@typescript-eslint/parser": "^5.24.0",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"del": "^6.1.0",
"esbuild": "^0.14.39",
"eslint": "^8.15.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"dev": "astro-scripts dev \"src/**/*.ts\"",
"postbuild": "astro-scripts copy \"src/**/*.astro\"",
"benchmark": "node test/benchmark/dev.bench.js && node test/benchmark/build.bench.js",
"test": "mocha --exit --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js",
"test": "mocha --exit --timeout 20000 --ignore **/lit-element.test.js --ignore **/errors.test.js && mocha --timeout 20000 **/lit-element.test.js && mocha --timeout 20000 **/errors.test.js",
"test:match": "mocha --timeout 20000 -g",
"test:e2e": "playwright test e2e"
},
Expand Down
8 changes: 7 additions & 1 deletion packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ export async function staticBuild(opts: StaticBuildOptions) {

// Build your project (SSR application code, assets, client JS, etc.)
timer.ssr = performance.now();
info(opts.logging, 'build', 'Building for SSR...');
info(
opts.logging,
'build',
isBuildingToSSR(astroConfig)
? 'Building SSR entrypoints...'
: 'Building entrypoints for prerendering...'
);
const ssrResult = (await ssrBuild(opts, internals, pageInput)) as RollupOutput;
info(opts.logging, 'build', dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`));

Expand Down
22 changes: 10 additions & 12 deletions packages/astro/src/core/logger/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ export interface LogOptions {
level: LoggerLevel;
}

function getLoggerLocale(): string {
const defaultLocale = 'en-US';
if (process.env.LANG) {
const extractedLocale = process.env.LANG.split('.')[0].replace(/_/g, '-');
// Check if language code is atleast two characters long (ie. en, es).
// NOTE: if "c" locale is encountered, the default locale will be returned.
if (extractedLocale.length < 2) return defaultLocale;
else return extractedLocale.substring(0, 5);
} else return defaultLocale;
}

export const dateTimeFormat = new Intl.DateTimeFormat(getLoggerLocale(), {
// Hey, locales are pretty complicated! Be careful modifying this logic...
// If we throw at the top-level, international users can't use Astro.
//
// Using `[]` sets the default locale properly from the system!
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#parameters
//
// Here be the dragons we've slain:
// https://github.com/withastro/astro/issues/2625
// https://github.com/withastro/astro/issues/3309
export const dateTimeFormat = new Intl.DateTimeFormat([], {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
Expand Down
18 changes: 18 additions & 0 deletions packages/astro/test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,21 @@ describe('astro cli', () => {
});
});
});

describe('astro cli i18n', () => {
const LOCALES = ['en_US', 'sv_SE', 'es_419.UTF-8', 'es_ES@euro', 'C'];
LOCALES.forEach((locale) => {
it(`astro does NOT throw on "${locale}" locales`, async () => {
const projectRootURL = new URL('./fixtures/astro-basic/', import.meta.url);
let error = null;
try {
const proc = cli('dev', '--root', fileURLToPath(projectRootURL), { env: { LANG: locale } });
await parseCliDevStart(proc);
} catch (e) {
console.log(e);
error = e.message;
}
expect(error).to.be.null;
});
});
});
6 changes: 3 additions & 3 deletions packages/astro/test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as cheerio from 'cheerio';
describe('Error display', () => {
if (isWindows) return;

/** @type {import('./test-utils').Fixture} */
let fixture;
let devServer;

Expand Down Expand Up @@ -32,7 +33,7 @@ describe('Error display', () => {
});
});

describe('Framework components', () => {
describe('Framework components', function () {
let devServer;

before(async () => {
Expand All @@ -43,8 +44,7 @@ describe('Error display', () => {
await devServer.stop();
});

// Skip until https://github.com/withastro/astro/pull/3376 is revisited
it.skip('Errors recover when fixed', async () => {
it('Errors recover when fixed', async () => {
let html = await fixture.fetch('/svelte-syntax-error').then((res) => res.text());

// 1. Verify an error message is being shown.
Expand Down
1 change: 1 addition & 0 deletions packages/astro/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ polyfill(globalThis, {
* @property {() => Promise<PreviewServer>} preview
* @property {() => Promise<void>} clean
* @property {() => Promise<App>} loadTestAdapterApp
* @property {() => Promise<void>} onNextChange
*/

/**
Expand Down
23 changes: 11 additions & 12 deletions packages/create-astro/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ type ConsoleStream = Writable & {
fd: 1 | 2;
};

function getLoggerLocale(): string {
const defaultLocale = 'en-US';
if (process.env.LANG) {
const extractedLocale = process.env.LANG.split('.')[0].replace(/_/g, '-');
// Check if language code is atleast two characters long (ie. en, es).
// NOTE: if "c" locale is encountered, the default locale will be returned.
if (extractedLocale.length < 2) return defaultLocale;
else return extractedLocale;
} else return defaultLocale;
}

const dt = new Intl.DateTimeFormat(getLoggerLocale(), {
// Hey, locales are pretty complicated! Be careful modifying this logic...
// If we throw at the top-level, international users can't use Astro.
//
// Using `[]` sets the default locale properly from the system!
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#parameters
//
// Here be the dragons we've slain:
// https://github.com/withastro/astro/issues/2625
// https://github.com/withastro/astro/issues/3309
const dt = new Intl.DateTimeFormat([], {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});

export const defaultLogDestination = new Writable({
Expand Down
Loading

0 comments on commit 3d61a50

Please sign in to comment.