0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix(cli): load polyfill before loading config during astro add (#10105)

* Adds crypto import to Vercel adapter

* Update the 'crypto' import to 'node:crypto'

* load polyfills before loading config

* add changeset

* load polyfills for `astro info`, `astro preferences` etc

* update changeset

* clarify impact

---------

Co-authored-by: lilnasy <69170106+lilnasy@users.noreply.github.com>
This commit is contained in:
Mohamed 2024-02-15 15:42:03 +01:00 committed by GitHub
parent 4f6b0def42
commit 1f598b3724
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fixes an issue where some astro commands failed if the astro config file or an integration used the global `crypto` object.

View file

@ -99,10 +99,10 @@ async function getRegistry(): Promise<string> {
export async function add(names: string[], { flags }: AddOptions) {
ensureProcessNodeEnv('production');
applyPolyfill();
const inlineConfig = flagsToAstroInlineConfig(flags);
const { userConfig } = await resolveConfig(inlineConfig, 'add');
telemetry.record(eventCliSession('add', userConfig));
applyPolyfill();
if (flags.help || names.length === 0) {
printHelp({
commandName: 'astro add',

View file

@ -3,12 +3,14 @@ import { createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js';
import { getPackage } from '../install-package.js';
import { resolveConfig } from '../../core/config/config.js';
import type { AstroConfig } from '../../@types/astro.js';
import { apply as applyPolyfill } from '../../core/polyfill.js';
type DBPackage = {
cli: (args: { flags: Arguments; config: AstroConfig }) => unknown;
};
export async function db({ flags }: { flags: Arguments }) {
applyPolyfill();
const logger = createLoggerFromFlags(flags);
const getPackageOpts = { skipAsk: flags.yes || flags.y, cwd: flags.root };
const dbPackage = await getPackage<DBPackage>('@astrojs/db', logger, getPackageOpts, []);

View file

@ -8,6 +8,7 @@ import type { AstroConfig, AstroUserConfig } from '../../@types/astro.js';
import { resolveConfig } from '../../core/config/index.js';
import { ASTRO_VERSION } from '../../core/constants.js';
import { flagsToAstroInlineConfig } from '../flags.js';
import { apply as applyPolyfill } from '../../core/polyfill.js';
interface InfoOptions {
flags: yargs.Arguments;
@ -47,6 +48,7 @@ export async function getInfoOutput({
}
export async function printInfo({ flags }: InfoOptions) {
applyPolyfill();
const { userConfig } = await resolveConfig(flagsToAstroInlineConfig(flags), 'info');
const output = await getInfoOutput({ userConfig, print: true });

View file

@ -16,6 +16,7 @@ import { createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js';
import { flattie } from 'flattie';
import { formatWithOptions } from 'node:util';
import { collectErrorMetadata } from '../../core/errors/dev/utils.js';
import { apply as applyPolyfill } from '../../core/polyfill.js';
interface PreferencesOptions {
flags: yargs.Arguments;
@ -45,6 +46,7 @@ export async function preferences(
value: string | undefined,
{ flags }: PreferencesOptions
): Promise<number> {
applyPolyfill();
if (!isValidSubcommand(subcommand) || flags?.help || flags?.h) {
msg.printHelp({
commandName: 'astro preferences',

View file

@ -12,6 +12,7 @@ import { createSettings } from '../config/settings.js';
import createStaticPreviewServer from './static-preview-server.js';
import { getResolvedHostForHttpServer } from './util.js';
import { ensureProcessNodeEnv } from '../util.js';
import { apply as applyPolyfills } from '../polyfill.js';
/**
* Starts a local server to serve your static dist/ directory. This command is useful for previewing
@ -20,6 +21,7 @@ import { ensureProcessNodeEnv } from '../util.js';
* @experimental The JavaScript API is experimental
*/
export default async function preview(inlineConfig: AstroInlineConfig): Promise<PreviewServer> {
applyPolyfills();
ensureProcessNodeEnv('production');
const logger = createNodeLogger(inlineConfig);
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, 'preview');