summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Florian Lefebvre <ematipico@users.noreply.github.com> 2024-06-05 10:41:15 +0000
committerGravatar astrobot-houston <fred+astrobot@astro.build> 2024-06-05 10:41:15 +0000
commitb24838f798ecde616430da940f7b9a01135445a0 (patch)
treeb17f9f0c475b27b9adbab6cf0b900dce1da7747d
parent2668ef984104574f25f29ef75e2572a0745d1666 (diff)
downloadastro-b24838f798ecde616430da940f7b9a01135445a0.tar.gz
astro-b24838f798ecde616430da940f7b9a01135445a0.tar.zst
astro-b24838f798ecde616430da940f7b9a01135445a0.zip
[ci] format
-rw-r--r--examples/container-with-vitest/test/ReactWrapper.test.ts4
-rw-r--r--packages/astro/client.d.ts2
-rw-r--r--packages/astro/config.d.ts2
-rw-r--r--packages/astro/src/@types/astro.ts30
-rw-r--r--packages/astro/src/container/index.ts10
-rw-r--r--packages/astro/src/core/app/pipeline.ts2
-rw-r--r--packages/astro/src/core/base-pipeline.ts6
-rw-r--r--packages/astro/src/core/config/schema.ts2
-rw-r--r--packages/astro/src/core/create-vite.ts2
-rw-r--r--packages/astro/src/env/schema.ts20
-rw-r--r--packages/astro/src/env/vite-plugin-env.ts8
-rw-r--r--packages/astro/src/virtual-modules/env-setup.ts2
-rw-r--r--packages/astro/src/vite-plugin-inject-env-ts/index.ts4
-rw-r--r--packages/astro/templates/env/module.mjs6
-rw-r--r--packages/astro/test/astro-sync.test.js2
-rw-r--r--packages/astro/test/env-public.test.js6
-rw-r--r--packages/astro/test/env-secret.test.js4
-rw-r--r--packages/astro/test/units/env/env-validators.test.js2
18 files changed, 54 insertions, 60 deletions
diff --git a/examples/container-with-vitest/test/ReactWrapper.test.ts b/examples/container-with-vitest/test/ReactWrapper.test.ts
index 70b938708..6adbff6cf 100644
--- a/examples/container-with-vitest/test/ReactWrapper.test.ts
+++ b/examples/container-with-vitest/test/ReactWrapper.test.ts
@@ -1,8 +1,8 @@
+import { loadRenderers } from 'astro:container';
+import { getContainerRenderer } from '@astrojs/react';
import { experimental_AstroContainer as AstroContainer } from 'astro/container';
import { expect, test } from 'vitest';
import ReactWrapper from '../src/components/ReactWrapper.astro';
-import { loadRenderers } from 'astro:container';
-import { getContainerRenderer } from '@astrojs/react';
const renderers = await loadRenderers([getContainerRenderer()]);
const container = await AstroContainer.create({
diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts
index 64d9e477f..8a277f5aa 100644
--- a/packages/astro/client.d.ts
+++ b/packages/astro/client.d.ts
@@ -165,7 +165,7 @@ declare module 'astro:components' {
}
declare module 'astro:env/setup' {
- export * from 'astro/virtual-modules/env-setup.js'
+ export * from 'astro/virtual-modules/env-setup.js';
}
type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
diff --git a/packages/astro/config.d.ts b/packages/astro/config.d.ts
index e4a93b941..a7d827a1f 100644
--- a/packages/astro/config.d.ts
+++ b/packages/astro/config.d.ts
@@ -42,4 +42,4 @@ export function passthroughImageService(): ImageServiceConfig;
/**
* Return a valid env field to use in this Astro config for `experimental.env.schema`.
*/
-export const envField: EnvField; \ No newline at end of file
+export const envField: EnvField;
diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts
index e178afea7..baba559e3 100644
--- a/packages/astro/src/@types/astro.ts
+++ b/packages/astro/src/@types/astro.ts
@@ -20,6 +20,7 @@ import type { AstroTimer } from '../core/config/timer.js';
import type { TSConfig } from '../core/config/tsconfig.js';
import type { AstroCookies } from '../core/cookies/index.js';
import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js';
+import type { EnvSchema } from '../env/schema.js';
import type { getToolbarServerCommunicationHelpers } from '../integrations/hooks.js';
import type { AstroPreferences } from '../preferences/index.js';
import type {
@@ -47,7 +48,6 @@ import type {
} from '../transitions/events.js';
import type { DeepPartial, OmitIndexSignature, Simplify, WithRequired } from '../type-utils.js';
import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
-import type { EnvSchema } from '../env/schema.js';
export type { AstroIntegrationLogger, ToolbarServerHelpers };
@@ -2073,7 +2073,7 @@ export interface AstroUserConfig {
* import { PUBLIC_APP_ID } from "astro:env/client"
* import { PUBLIC_API_URL, getSecret } from "astro:env/server"
* const API_TOKEN = getSecret("API_TOKEN")
- *
+ *
* const data = await fetch(`${PUBLIC_API_URL}/users`, {
* method: "POST",
* headers: {
@@ -2084,13 +2084,13 @@ export interface AstroUserConfig {
* })
* ---
* ```
- *
+ *
* To define the data type and properties of your environment variables, declare a schema in your Astro config in `experimental.env.schema`. The `envField` helper allows you define your variable as a string, number, or boolean and pass properties in an object:
- *
+ *
* ```js
* // astro.config.mjs
* import { defineConfig, envField } from "astro/config"
- *
+ *
* export default defineConfig({
* experimental: {
* env: {
@@ -2103,32 +2103,32 @@ export interface AstroUserConfig {
* }
* })
* ```
- *
+ *
* There are currently 3 data types supported: strings, numbers and booleans.
- *
+ *
* There are three kinds of variables, determined by the combination of `context` (`client` or `server`) and `access` (`private` or `public`) settings defined in your [`env.schema`](#experimentalenvschema):
- *
+ *
* - **Public client variables**: These variables end up in both your final client and server bundles, and can be accessed from both client and server through the `astro:env/client` module:
- *
+ *
* ```js
* import { PUBLIC_API_URL } from "astro:env/client"
* ```
- *
+ *
* - **Public server variables**: These variables end up in your final server bundle and can be accessed on the server through the `astro:env/server` module:
- *
+ *
* ```js
* import { PUBLIC_PORT } from "astro:env/server"
* ```
- *
+ *
* - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `getSecret()` helper function available from the `astro:env/server` module:
- *
+ *
* ```js
* import { getSecret } from "astro:env/server"
- *
+ *
* const API_SECRET = getSecret("API_SECRET") // typed
* const SECRET_NOT_IN_SCHEMA = getSecret("SECRET_NOT_IN_SCHEMA") // string | undefined
* ```
- *
+ *
* **Note:** Secret client variables are not supported because there is no safe way to send this data to the client. Therefore, it is not possible to configure both `context: "client"` and `access: "secret"` in your schema.
*
* For a complete overview, and to give feedback on this experimental API, see the [Astro Env RFC](https://github.com/withastro/roadmap/blob/feat/astro-env-rfc/proposals/0046-astro-env.md).
diff --git a/packages/astro/src/container/index.ts b/packages/astro/src/container/index.ts
index d4b677602..015d19272 100644
--- a/packages/astro/src/container/index.ts
+++ b/packages/astro/src/container/index.ts
@@ -169,7 +169,7 @@ export type AstroContainerOptions = {
/**
* @default {}
* @description
- *
+ *
* The raw manifest from the build output.
*/
manifest?: SSRManifest;
@@ -261,7 +261,13 @@ export class experimental_AstroContainer {
): Promise<experimental_AstroContainer> {
const { streaming = false, manifest, renderers = [], resolve } = containerOptions;
const astroConfig = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), 'container');
- return new experimental_AstroContainer({ streaming, manifest, renderers, astroConfig, resolve });
+ return new experimental_AstroContainer({
+ streaming,
+ manifest,
+ renderers,
+ astroConfig,
+ resolve,
+ });
}
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
diff --git a/packages/astro/src/core/app/pipeline.ts b/packages/astro/src/core/app/pipeline.ts
index b7e70e489..3eec8068f 100644
--- a/packages/astro/src/core/app/pipeline.ts
+++ b/packages/astro/src/core/app/pipeline.ts
@@ -46,7 +46,7 @@ export class AppPipeline extends Pipeline {
undefined,
undefined,
undefined,
- false,
+ false
);
pipeline.#manifestData = manifestData;
return pipeline;
diff --git a/packages/astro/src/core/base-pipeline.ts b/packages/astro/src/core/base-pipeline.ts
index 0758fdf03..533094bb2 100644
--- a/packages/astro/src/core/base-pipeline.ts
+++ b/packages/astro/src/core/base-pipeline.ts
@@ -8,12 +8,12 @@ import type {
SSRManifest,
SSRResult,
} from '../@types/astro.js';
-import { createI18nMiddleware } from '../i18n/middleware.js';
-import type { Logger } from './logger/core.js';
-import { RouteCache } from './render/route-cache.js';
import { setGetEnv } from '../env/runtime.js';
+import { createI18nMiddleware } from '../i18n/middleware.js';
import { AstroError } from './errors/errors.js';
import { AstroErrorData } from './errors/index.js';
+import type { Logger } from './logger/core.js';
+import { RouteCache } from './render/route-cache.js';
/**
* The `Pipeline` represents the static parts of rendering that do not change between requests.
diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts
index d3b5f7390..15025a765 100644
--- a/packages/astro/src/core/config/schema.ts
+++ b/packages/astro/src/core/config/schema.ts
@@ -12,8 +12,8 @@ import type { OutgoingHttpHeaders } from 'node:http';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { z } from 'zod';
-import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from '../path.js';
import { EnvSchema } from '../../env/schema.js';
+import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from '../path.js';
// The below types are required boilerplate to workaround a Zod issue since v3.21.2. Since that version,
// Zod's compiled TypeScript would "simplify" certain values to their base representation, causing references
diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts
index eba0bea5e..163c16482 100644
--- a/packages/astro/src/core/create-vite.ts
+++ b/packages/astro/src/core/create-vite.ts
@@ -11,6 +11,7 @@ import {
astroContentImportPlugin,
astroContentVirtualModPlugin,
} from '../content/index.js';
+import { astroEnv } from '../env/vite-plugin-env.js';
import astroInternationalization from '../i18n/vite-plugin-i18n.js';
import astroPrefetch from '../prefetch/vite-plugin-prefetch.js';
import astroDevToolbar from '../toolbar/vite-plugin-dev-toolbar.js';
@@ -37,7 +38,6 @@ import { createViteLogger } from './logger/vite.js';
import { vitePluginMiddleware } from './middleware/vite-plugin.js';
import { joinPaths } from './path.js';
import { isObject } from './util.js';
-import { astroEnv } from '../env/vite-plugin-env.js';
interface CreateViteOptions {
settings: AstroSettings;
diff --git a/packages/astro/src/env/schema.ts b/packages/astro/src/env/schema.ts
index 555bb1a60..5e13cbb17 100644
--- a/packages/astro/src/env/schema.ts
+++ b/packages/astro/src/env/schema.ts
@@ -18,7 +18,7 @@ const BooleanSchema = z.object({
});
const EnvFieldType = z.discriminatedUnion('type', [StringSchema, NumberSchema, BooleanSchema]);
-export type EnvFieldType = z.infer<typeof EnvFieldType>
+export type EnvFieldType = z.infer<typeof EnvFieldType>;
const PublicClientEnvFieldMetadata = z.object({
context: z.literal('client'),
@@ -37,11 +37,9 @@ const KEY_REGEX = /^[A-Z_]+$/;
export const EnvSchema = z
.record(
- z
- .string()
- .regex(KEY_REGEX, {
- message: 'A valid variable name can only contain uppercase letters and underscores.',
- }),
+ z.string().regex(KEY_REGEX, {
+ message: 'A valid variable name can only contain uppercase letters and underscores.',
+ }),
z.intersection(
z.union([
PublicClientEnvFieldMetadata,
@@ -53,19 +51,13 @@ export const EnvSchema = z
)
.superRefine((schema, ctx) => {
for (const [key, value] of Object.entries(schema)) {
- if (
- key.startsWith(PUBLIC_PREFIX) &&
- value.access !== 'public'
- ) {
+ if (key.startsWith(PUBLIC_PREFIX) && value.access !== 'public') {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `An environment variable whose name is prefixed by "${PUBLIC_PREFIX}" must be public.`,
});
}
- if (
- value.access === 'public' &&
- !key.startsWith(PUBLIC_PREFIX)
- ) {
+ if (value.access === 'public' && !key.startsWith(PUBLIC_PREFIX)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `An environment variable that is public must have a name prefixed by "${PUBLIC_PREFIX}".`,
diff --git a/packages/astro/src/env/vite-plugin-env.ts b/packages/astro/src/env/vite-plugin-env.ts
index 5b1faf237..a7fc66727 100644
--- a/packages/astro/src/env/vite-plugin-env.ts
+++ b/packages/astro/src/env/vite-plugin-env.ts
@@ -1,5 +1,8 @@
-import { loadEnv, type Plugin } from 'vite';
+import type fsMod from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { type Plugin, loadEnv } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
+import { AstroError, AstroErrorData } from '../core/errors/index.js';
import {
ENV_TYPES_FILE,
MODULE_TEMPLATE_URL,
@@ -10,9 +13,6 @@ import {
} from './constants.js';
import type { EnvSchema } from './schema.js';
import { getEnvFieldType, validateEnvVariable } from './validators.js';
-import { AstroError, AstroErrorData } from '../core/errors/index.js';
-import type fsMod from 'node:fs';
-import { fileURLToPath } from 'node:url';
// TODO: reminders for when astro:env comes out of experimental
// Types should always be generated (like in types/content.d.ts). That means the client module will be empty
diff --git a/packages/astro/src/virtual-modules/env-setup.ts b/packages/astro/src/virtual-modules/env-setup.ts
index e4416472e..c86452975 100644
--- a/packages/astro/src/virtual-modules/env-setup.ts
+++ b/packages/astro/src/virtual-modules/env-setup.ts
@@ -1 +1 @@
-export { setGetEnv, type GetEnv } from '../env/runtime.js'; \ No newline at end of file
+export { setGetEnv, type GetEnv } from '../env/runtime.js';
diff --git a/packages/astro/src/vite-plugin-inject-env-ts/index.ts b/packages/astro/src/vite-plugin-inject-env-ts/index.ts
index 277ef3434..3ebecce2d 100644
--- a/packages/astro/src/vite-plugin-inject-env-ts/index.ts
+++ b/packages/astro/src/vite-plugin-inject-env-ts/index.ts
@@ -4,9 +4,9 @@ import { fileURLToPath } from 'node:url';
import { bold } from 'kleur/colors';
import { type Plugin, normalizePath } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
-import { type Logger } from '../core/logger/core.js';
import { ACTIONS_TYPES_FILE } from '../actions/consts.js';
import { CONTENT_TYPES_FILE } from '../content/consts.js';
+import { type Logger } from '../core/logger/core.js';
import { ENV_TYPES_FILE } from '../env/constants.js';
export function getEnvTsPath({ srcDir }: { srcDir: URL }) {
@@ -112,4 +112,4 @@ export async function setUpEnvTs({
await fs.promises.writeFile(envTsPath, referenceDefs.join('\n'), 'utf-8');
logger.info('types', `Added ${bold(envTsPathRelativetoRoot)} type declarations`);
}
-} \ No newline at end of file
+}
diff --git a/packages/astro/templates/env/module.mjs b/packages/astro/templates/env/module.mjs
index dda3b179d..602cb8527 100644
--- a/packages/astro/templates/env/module.mjs
+++ b/packages/astro/templates/env/module.mjs
@@ -1,9 +1,5 @@
-import {
- getEnv,
- validateEnvVariable,
- createInvalidVariableError,
-} from 'astro/env/runtime';
import { schema } from 'virtual:astro:env/internal';
+import { createInvalidVariableError, getEnv, validateEnvVariable } from 'astro/env/runtime';
export const getSecret = (key) => {
const rawVariable = getEnv(key);
diff --git a/packages/astro/test/astro-sync.test.js b/packages/astro/test/astro-sync.test.js
index 58f5c2860..bfa8ab883 100644
--- a/packages/astro/test/astro-sync.test.js
+++ b/packages/astro/test/astro-sync.test.js
@@ -133,4 +133,4 @@ describe('astro sync', () => {
);
});
});
-}); \ No newline at end of file
+});
diff --git a/packages/astro/test/env-public.test.js b/packages/astro/test/env-public.test.js
index 37492883b..491ae3128 100644
--- a/packages/astro/test/env-public.test.js
+++ b/packages/astro/test/env-public.test.js
@@ -1,8 +1,8 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
import { ServerOnlyModule } from '../dist/core/errors/errors-data.js';
import { AstroError } from '../dist/core/errors/errors.js';
+import { loadFixture } from './test-utils.js';
describe('astro:env public variables', () => {
/** @type {Awaited<ReturnType<typeof loadFixture>>} */
@@ -42,8 +42,8 @@ describe('astro:env public variables', () => {
});
it('throws if server module is called on the client', async () => {
- const error = await fixture.build().catch(err => err);
- assert.equal(error instanceof AstroError, true)
+ const error = await fixture.build().catch((err) => err);
+ assert.equal(error instanceof AstroError, true);
assert.equal(error.name, ServerOnlyModule.name);
});
});
diff --git a/packages/astro/test/env-secret.test.js b/packages/astro/test/env-secret.test.js
index 26347c022..08e84b700 100644
--- a/packages/astro/test/env-secret.test.js
+++ b/packages/astro/test/env-secret.test.js
@@ -1,8 +1,8 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
-import testAdapter from './test-adapter.js';
import * as cheerio from 'cheerio';
+import testAdapter from './test-adapter.js';
+import { loadFixture } from './test-utils.js';
describe('astro:env public variables', () => {
/** @type {Awaited<ReturnType<typeof loadFixture>>} */
diff --git a/packages/astro/test/units/env/env-validators.test.js b/packages/astro/test/units/env/env-validators.test.js
index 92092a185..2df220919 100644
--- a/packages/astro/test/units/env/env-validators.test.js
+++ b/packages/astro/test/units/env/env-validators.test.js
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
-import { validateEnvVariable, getEnvFieldType } from '../../../dist/env/validators.js';
+import { getEnvFieldType, validateEnvVariable } from '../../../dist/env/validators.js';
/**
* @typedef {Parameters<typeof validateEnvVariable>} Params