astro 4.15.3 → 4.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,5 +10,5 @@ interface IntegrationInfo {
10
10
  type: 'integration' | 'adapter';
11
11
  }
12
12
  export declare function add(names: string[], { flags }: AddOptions): Promise<void>;
13
- export declare function setAdapter(mod: ProxifiedModule<any>, adapter: IntegrationInfo): void;
13
+ export declare function setAdapter(mod: ProxifiedModule<any>, adapter: IntegrationInfo, exportName: string): void;
14
14
  export {};
@@ -247,7 +247,7 @@ async function add(names, { flags }) {
247
247
  if (isAdapter(integration)) {
248
248
  const officialExportName = OFFICIAL_ADAPTER_TO_IMPORT_MAP[integration.id];
249
249
  if (officialExportName) {
250
- setAdapter(mod, integration);
250
+ setAdapter(mod, integration, officialExportName);
251
251
  } else {
252
252
  logger.info(
253
253
  "SKIP_FORMAT",
@@ -371,14 +371,14 @@ function addIntegration(mod, integration) {
371
371
  config.integrations.push(builders.functionCall(integrationId));
372
372
  }
373
373
  }
374
- function setAdapter(mod, adapter) {
374
+ function setAdapter(mod, adapter, exportName) {
375
375
  const config = getDefaultExportOptions(mod);
376
376
  const adapterId = toIdent(adapter.id);
377
377
  if (!mod.imports.$items.some((imp) => imp.local === adapterId)) {
378
378
  mod.imports.$append({
379
379
  imported: "default",
380
380
  local: adapterId,
381
- from: adapter.packageName
381
+ from: exportName
382
382
  });
383
383
  }
384
384
  if (!config.output) {
@@ -0,0 +1,6 @@
1
+ import { type Flags } from '../flags.js';
2
+ interface CreateKeyOptions {
3
+ flags: Flags;
4
+ }
5
+ export declare function createKey({ flags }: CreateKeyOptions): Promise<0 | 1>;
6
+ export {};
@@ -0,0 +1,27 @@
1
+ import { createNodeLogger } from "../../core/config/logging.js";
2
+ import { createKey as createCryptoKey, encodeKey } from "../../core/encryption.js";
3
+ import { flagsToAstroInlineConfig } from "../flags.js";
4
+ async function createKey({ flags }) {
5
+ try {
6
+ const inlineConfig = flagsToAstroInlineConfig(flags);
7
+ const logger = createNodeLogger(inlineConfig);
8
+ const keyPromise = createCryptoKey();
9
+ const key = await keyPromise;
10
+ const encoded = await encodeKey(key);
11
+ logger.info(
12
+ "crypto",
13
+ `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.
14
+
15
+ ASTRO_KEY=${encoded}`
16
+ );
17
+ } catch (err) {
18
+ if (err != null) {
19
+ console.error(err.toString());
20
+ }
21
+ return 1;
22
+ }
23
+ return 0;
24
+ }
25
+ export {
26
+ createKey
27
+ };
package/dist/cli/index.js CHANGED
@@ -12,6 +12,7 @@ async function printAstroHelp() {
12
12
  ["add", "Add an integration."],
13
13
  ["build", "Build your project and write it to disk."],
14
14
  ["check", "Check your project for errors."],
15
+ ["create-key", "Create a cryptography key"],
15
16
  ["db", "Manage your Astro database."],
16
17
  ["dev", "Start the development server."],
17
18
  ["docs", "Open documentation in your web browser."],
@@ -55,6 +56,7 @@ function resolveCommand(flags) {
55
56
  "build",
56
57
  "preview",
57
58
  "check",
59
+ "create-key",
58
60
  "docs",
59
61
  "db",
60
62
  "info",
@@ -81,6 +83,11 @@ async function runCommand(cmd, flags) {
81
83
  await printInfo({ flags });
82
84
  return;
83
85
  }
86
+ case "create-key": {
87
+ const { createKey } = await import("./create-key/index.js");
88
+ const exitCode = await createKey({ flags });
89
+ return process.exit(exitCode);
90
+ }
84
91
  case "docs": {
85
92
  const { docs } = await import("./docs/index.js");
86
93
  await docs({ flags });
@@ -15,7 +15,7 @@ import { resolveConfig } from "../config/config.js";
15
15
  import { createNodeLogger } from "../config/logging.js";
16
16
  import { createSettings } from "../config/settings.js";
17
17
  import { createVite } from "../create-vite.js";
18
- import { createKey } from "../encryption.js";
18
+ import { createKey, getEnvironmentKey, hasEnvironmentKey } from "../encryption.js";
19
19
  import { levels, timerMessage } from "../logger/core.js";
20
20
  import { apply as applyPolyfill } from "../polyfill.js";
21
21
  import { createRouteManifest } from "../routing/index.js";
@@ -131,6 +131,8 @@ class AstroBuilder {
131
131
  "build",
132
132
  green(`\u2713 Completed in ${getTimeStat(this.timer.init, performance.now())}.`)
133
133
  );
134
+ const hasKey = hasEnvironmentKey();
135
+ const keyPromise = hasKey ? getEnvironmentKey() : createKey();
134
136
  const opts = {
135
137
  allPages,
136
138
  settings: this.settings,
@@ -141,7 +143,7 @@ class AstroBuilder {
141
143
  pageNames,
142
144
  teardownCompiler: this.teardownCompiler,
143
145
  viteConfig,
144
- key: createKey()
146
+ key: keyPromise
145
147
  };
146
148
  const { internals, ssrOutputChunkNames, contentFileNames } = await viteBuild(opts);
147
149
  await staticBuild(opts, internals, ssrOutputChunkNames, contentFileNames);
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.15.3";
1
+ const ASTRO_VERSION = "4.15.4";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
22
22
  await telemetry.record([]);
23
23
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
24
24
  const logger = restart.container.logger;
25
- const currentVersion = "4.15.3";
25
+ const currentVersion = "4.15.4";
26
26
  const isPrerelease = currentVersion.includes("-");
27
27
  if (!isPrerelease) {
28
28
  try {
@@ -2,6 +2,18 @@
2
2
  * Creates a CryptoKey object that can be used to encrypt any string.
3
3
  */
4
4
  export declare function createKey(): Promise<CryptoKey>;
5
+ /**
6
+ * Get the encoded value of the ASTRO_KEY env var.
7
+ */
8
+ export declare function getEncodedEnvironmentKey(): string;
9
+ /**
10
+ * See if the environment variable key ASTRO_KEY is set.
11
+ */
12
+ export declare function hasEnvironmentKey(): boolean;
13
+ /**
14
+ * Get the environment variable key and decode it into a CryptoKey.
15
+ */
16
+ export declare function getEnvironmentKey(): Promise<CryptoKey>;
5
17
  /**
6
18
  * Takes a key that has been serialized to an array of bytes and returns a CryptoKey
7
19
  */
@@ -11,6 +11,22 @@ async function createKey() {
11
11
  );
12
12
  return key;
13
13
  }
14
+ const ENVIRONMENT_KEY_NAME = "ASTRO_KEY";
15
+ function getEncodedEnvironmentKey() {
16
+ return process.env[ENVIRONMENT_KEY_NAME] || "";
17
+ }
18
+ function hasEnvironmentKey() {
19
+ return getEncodedEnvironmentKey() !== "";
20
+ }
21
+ async function getEnvironmentKey() {
22
+ if (!hasEnvironmentKey()) {
23
+ throw new Error(
24
+ `There is no environment key defined. If you see this error there is a bug in Astro.`
25
+ );
26
+ }
27
+ const encodedKey = getEncodedEnvironmentKey();
28
+ return decodeKey(encodedKey);
29
+ }
14
30
  async function importKey(bytes) {
15
31
  const key = await crypto.subtle.importKey("raw", bytes, ALGORITHM, true, ["encrypt", "decrypt"]);
16
32
  return key;
@@ -60,5 +76,8 @@ export {
60
76
  decryptString,
61
77
  encodeKey,
62
78
  encryptString,
79
+ getEncodedEnvironmentKey,
80
+ getEnvironmentKey,
81
+ hasEnvironmentKey,
63
82
  importKey
64
83
  };
@@ -7,7 +7,7 @@ export type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
7
7
  * rather than specific to a single command, function, use, etc. The label will be
8
8
  * shown in the log message to the user, so it should be relevant.
9
9
  */
10
- export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'sync' | 'toolbar' | 'assets' | 'env' | 'update' | 'SKIP_FORMAT';
10
+ export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'crypto' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'sync' | 'toolbar' | 'assets' | 'env' | 'update' | 'SKIP_FORMAT';
11
11
  export interface LogOptions {
12
12
  dest: LogWritable<LogMessage>;
13
13
  level: LoggerLevel;
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "4.15.3";
41
+ const version = "4.15.4";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -270,7 +270,7 @@ function printHelp({
270
270
  message.push(
271
271
  linebreak(),
272
272
  ` ${bgGreen(black(` ${commandName} `))} ${green(
273
- `v${"4.15.3"}`
273
+ `v${"4.15.4"}`
274
274
  )} ${headline}`
275
275
  );
276
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.15.3",
3
+ "version": "4.15.4",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",