Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Vendored from [image-size](https://github.com/image-size/image-size) v2.0.2.
- Files removed: `fromFile.ts`, `index.ts`
- Added `avis` brand for AVIF sequences (`./types/heif.ts`)
- Added `detectType()` to handle files with out-of-order ftyp brands (`./types/heif.ts`)
- Updates `BitReader` properties assignment to work with `erasableSyntaxOnly`
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ export class BitReader {
// Skip the first 16 bits (2 bytes) of signature
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add to the README in that vendor folder that you did those changes? It helps when we upgrade image-size from upstream.

private byteOffset = 2
private bitOffset = 0
private readonly input: Uint8Array
private readonly endianness: 'big-endian' | 'little-endian'

constructor(
private readonly input: Uint8Array,
private readonly endianness: 'big-endian' | 'little-endian',
) {}
input: Uint8Array,
endianness: 'big-endian' | 'little-endian',
) {
this.input = input
this.endianness = endianness
}

/** Reads a specified number of bits, and move the offset */
getBits(length = 1): number {
Expand Down
81 changes: 38 additions & 43 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export async function add(names: string[], { flags }: AddOptions) {
}

switch (installResult) {
case UpdateResult.updated: {
case 'updated': {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly care, but why did this need to be updated, does the setting care about this?

Copy link
Copy Markdown
Member

@ematipico ematipico Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erasableSyntaxOnly enforces the use of syntax that disappears during the build. TS enums don't disappear, they are transformed into something else. The setting bans enums

if (hasCloudflareIntegration) {
const wranglerConfigURL = new URL('./wrangler.jsonc', configURL);
if (!existsSync(wranglerConfigURL)) {
Expand Down Expand Up @@ -371,7 +371,7 @@ export async function add(names: string[], { flags }: AddOptions) {
}
break;
}
case UpdateResult.cancelled: {
case 'cancelled': {
logger.info(
'SKIP_FORMAT',
msg.cancelled(
Expand All @@ -381,10 +381,10 @@ export async function add(names: string[], { flags }: AddOptions) {
);
break;
}
case UpdateResult.failure: {
case 'failure': {
throw createPrettyError(new Error(`Unable to install dependencies`));
}
case UpdateResult.none:
case 'none':
break;
}

Expand Down Expand Up @@ -448,14 +448,14 @@ export async function add(names: string[], { flags }: AddOptions) {
}

switch (configResult) {
case UpdateResult.cancelled: {
case 'cancelled': {
logger.info(
'SKIP_FORMAT',
msg.cancelled(`Your configuration has ${bold('NOT')} been updated.`),
);
break;
}
case UpdateResult.none: {
case 'none': {
const data = await getPackageJson();
if (data) {
const { dependencies = {}, devDependencies = {} } = data;
Expand All @@ -473,9 +473,9 @@ export async function add(names: string[], { flags }: AddOptions) {
break;
}
// NOTE: failure shouldn't happen in practice because `updateAstroConfig` doesn't return that.
// Pipe this to the same handling as `UpdateResult.updated` for now.
case UpdateResult.failure:
case UpdateResult.updated:
// Pipe this to the same handling as `'updated'` for now.
case 'failure':
case 'updated':
case undefined: {
const list = integrations
.map((integration) => ` - ${integration.integrationName}`)
Expand Down Expand Up @@ -513,22 +513,22 @@ export async function add(names: string[], { flags }: AddOptions) {
});

switch (updateTSConfigResult) {
case UpdateResult.none: {
case 'none': {
break;
}
case UpdateResult.cancelled: {
case 'cancelled': {
logger.info(
'SKIP_FORMAT',
msg.cancelled(`Your TypeScript configuration has ${bold('NOT')} been updated.`),
);
break;
}
case UpdateResult.failure: {
case 'failure': {
throw new Error(
`Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.`,
);
}
case UpdateResult.updated:
case 'updated':
logger.info('SKIP_FORMAT', msg.success(`Successfully updated tsconfig`));
}
}
Expand Down Expand Up @@ -652,12 +652,7 @@ function setAdapter(mod: ProxifiedModule<any>, adapter: IntegrationInfo, exportN
}
}

const enum UpdateResult {
none,
updated,
cancelled,
failure,
}
type UpdateResult = 'none' | 'updated' | 'cancelled' | 'failure';

async function updateAstroConfig({
configURL,
Expand All @@ -682,13 +677,13 @@ async function updateAstroConfig({
}).code;

if (input === output) {
return UpdateResult.none;
return 'none';
}

const diff = getDiffContent(input, output);

if (!diff) {
return UpdateResult.none;
return 'none';
}

logger.info(
Expand Down Expand Up @@ -716,9 +711,9 @@ async function updateAstroConfig({
if (await askToContinue({ flags, logger })) {
await fs.writeFile(fileURLToPath(configURL), output, { encoding: 'utf-8' });
logger.debug('add', `Updated astro config`);
return UpdateResult.updated;
return 'updated';
} else {
return UpdateResult.cancelled;
return 'cancelled';
}
}

Expand All @@ -736,7 +731,7 @@ async function updatePackageJsonOverrides({
const pkgURL = new URL('./package.json', configURL);
if (!existsSync(pkgURL)) {
logger.debug('add', 'No package.json found, skipping overrides update');
return UpdateResult.none;
return 'none';
}

const pkgPath = fileURLToPath(pkgURL);
Expand All @@ -753,14 +748,14 @@ async function updatePackageJsonOverrides({
}

if (!hasChanges) {
return UpdateResult.none;
return 'none';
}

const output = JSON.stringify(pkgJson, null, 2);
const diff = getDiffContent(input, output);

if (!diff) {
return UpdateResult.none;
return 'none';
}

logger.info(
Expand All @@ -777,9 +772,9 @@ async function updatePackageJsonOverrides({
if (await askToContinue({ flags, logger })) {
await fs.writeFile(pkgPath, output, { encoding: 'utf-8' });
logger.debug('add', 'Updated package.json overrides');
return UpdateResult.updated;
return 'updated';
} else {
return UpdateResult.cancelled;
return 'cancelled';
}
}

Expand All @@ -797,7 +792,7 @@ async function updatePackageJsonScripts({
const pkgURL = new URL('./package.json', configURL);
if (!existsSync(pkgURL)) {
logger.debug('add', 'No package.json found, skipping scripts update');
return UpdateResult.none;
return 'none';
}

const pkgPath = fileURLToPath(pkgURL);
Expand All @@ -814,14 +809,14 @@ async function updatePackageJsonScripts({
}

if (!hasChanges) {
return UpdateResult.none;
return 'none';
}

const output = JSON.stringify(pkgJson, null, 2);
const diff = getDiffContent(input, output);

if (!diff) {
return UpdateResult.none;
return 'none';
}

logger.info(
Expand All @@ -838,9 +833,9 @@ async function updatePackageJsonScripts({
if (await askToContinue({ flags, logger })) {
await fs.writeFile(pkgPath, output, { encoding: 'utf-8' });
logger.debug('add', 'Updated package.json scripts');
return UpdateResult.updated;
return 'updated';
} else {
return UpdateResult.cancelled;
return 'cancelled';
}
}

Expand Down Expand Up @@ -903,7 +898,7 @@ async function tryToInstallIntegrations({
strategies: ['install-metadata', 'lockfile', 'packageManager-field'],
});
logger.debug('add', `package manager: "${packageManager?.name}"`);
if (!packageManager) return UpdateResult.none;
if (!packageManager) return 'none';

const inheritedFlags = Object.entries(flags)
.map(([flag]) => {
Expand All @@ -917,7 +912,7 @@ async function tryToInstallIntegrations({
.flat() as string[];

const installCommand = resolveCommand(packageManager?.agent ?? 'npm', 'add', inheritedFlags);
if (!installCommand) return UpdateResult.none;
if (!installCommand) return 'none';

const installSpecifiers = await convertIntegrationsToInstallSpecifiers(integrations).then(
(specifiers) =>
Expand Down Expand Up @@ -951,16 +946,16 @@ async function tryToInstallIntegrations({
},
});
spinner.stop('Dependencies installed.');
return UpdateResult.updated;
return 'updated';
} catch (err: any) {
spinner.error('Error installing dependencies.');
logger.debug('add', 'Error installing dependencies', err);
// NOTE: `err.stdout` can be an empty string, so log the full error instead for a more helpful log
console.error('\n', err.stdout || err.message, '\n');
return UpdateResult.failure;
return 'failure';
}
} else {
return UpdateResult.cancelled;
return 'cancelled';
}
}

Expand Down Expand Up @@ -1100,14 +1095,14 @@ async function updateTSConfig(
);

if (!firstIntegrationWithTSSettings && includesToAppend.length === 0) {
return UpdateResult.none;
return 'none';
}

let inputConfig = await loadTSConfig(cwd);
let inputConfigText = '';

if (inputConfig === 'invalid-config' || inputConfig === 'unknown-error') {
return UpdateResult.failure;
return 'failure';
} else if (inputConfig === 'missing-config') {
logger.debug('add', "Couldn't find tsconfig.json or jsconfig.json, generating one");
inputConfig = {
Expand Down Expand Up @@ -1136,7 +1131,7 @@ async function updateTSConfig(
const diff = getDiffContent(inputConfigText, output);

if (!diff) {
return UpdateResult.none;
return 'none';
}

logger.info(
Expand Down Expand Up @@ -1181,9 +1176,9 @@ async function updateTSConfig(
encoding: 'utf-8',
});
logger.debug('add', `Updated ${configFileName} file`);
return UpdateResult.updated;
return 'updated';
} else {
return UpdateResult.cancelled;
return 'cancelled';
}
}

Expand Down
13 changes: 8 additions & 5 deletions packages/astro/src/content/loaders/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ function formatZodError(error: z.$ZodError): string[] {
}

export class LiveCollectionError extends Error {
constructor(
public readonly collection: string,
public readonly message: string,
public readonly cause?: Error,
) {
public readonly collection: string;
public readonly message: string;
public readonly cause?: Error;

constructor(collection: string, message: string, cause?: Error) {
super(message);
this.collection = collection;
this.message = message;
this.cause = cause;
this.name = 'LiveCollectionError';
if (cause?.stack) {
this.stack = cause.stack;
Expand Down
Loading
Loading