Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Sep 6, 2024
1 parent bd1d4aa commit c0c9645
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/astro/e2e/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for (let i = 0; i < testFiles.length; i++) {
const file = testFiles[i];
if (file.endsWith('.test.js')) {
// Port 4045 is an unsafe port in Chrome, so skip it.
if((4000 + i) === 4045) {
if (4000 + i === 4045) {
i++;
}
testFileToPort.set(file, 4000 + i);
Expand Down
40 changes: 21 additions & 19 deletions packages/astro/src/cli/create-key/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import { type Flags, flagsToAstroInlineConfig } from '../flags.js';
import { createNodeLogger } from '../../core/config/logging.js';
import { createKey as createCryptoKey,encodeKey } from '../../core/encryption.js';
import { createKey as createCryptoKey, encodeKey } from '../../core/encryption.js';
import { type Flags, flagsToAstroInlineConfig } from '../flags.js';

interface CreateKeyOptions {
flags: Flags;
}

export async function createKey({ flags }: CreateKeyOptions): Promise<0 | 1> {
try {
const inlineConfig = flagsToAstroInlineConfig(flags);
const logger = createNodeLogger(inlineConfig);
try {
const inlineConfig = flagsToAstroInlineConfig(flags);
const logger = createNodeLogger(inlineConfig);

const keyPromise = createCryptoKey();
const key = await keyPromise;
const encoded = await encodeKey(key);
const keyPromise = createCryptoKey();
const key = await keyPromise;
const encoded = await encodeKey(key);

logger.info('crypto', `Generated a key to encrypt props passed to Server islands. To reuse the same key across builds, set this value as ASTRO_KEY in an environment variable on your build server.
logger.info(
'crypto',
`Generated a key to encrypt props passed to Server islands. To reuse the same key across builds, set this value as ASTRO_KEY in an environment variable on your build server.
ASTRO_KEY=${encoded}`);
} catch(err: unknown) {
if(err != null) {
// eslint-disable-next-line no-console
console.error(err.toString());
}
return 1;
}
ASTRO_KEY=${encoded}`,
);
} catch (err: unknown) {
if (err != null) {
// eslint-disable-next-line no-console
console.error(err.toString());
}
return 1;
}

return 0;
return 0;
}
6 changes: 4 additions & 2 deletions packages/astro/src/core/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export function hasEnvironmentKey(): boolean {
*/
export async function getEnvironmentKey(): Promise<CryptoKey> {
// This should never happen, because we always check `hasEnvironmentKey` before this is called.
if(!hasEnvironmentKey()) {
throw new Error(`There is no environment key defined. If you see this error there is a bug in Astro.`)
if (!hasEnvironmentKey()) {
throw new Error(
`There is no environment key defined. If you see this error there is a bug in Astro.`,
);
}
const encodedKey = getEncodedEnvironmentKey();
return decodeKey(encodedKey);
Expand Down

0 comments on commit c0c9645

Please sign in to comment.