Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add noop service and make integrations that needs it use it #7903

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions .changeset/heavy-walls-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@astrojs/cloudflare': major
'@astrojs/netlify': major
'@astrojs/vercel': major
'astro': major
---

When using an adapter that supports neither Squoosh or Sharp, Astro will now automatically use an image service that does not support processing, but still provides the other benefits of `astro:assets` such as enforcing `alt`, no CLS etc to users
1 change: 1 addition & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"./assets/image-endpoint": "./dist/assets/image-endpoint.js",
"./assets/services/sharp": "./dist/assets/services/sharp.js",
"./assets/services/squoosh": "./dist/assets/services/squoosh.js",
"./assets/services/noop": "./dist/assets/services/noop.js",
"./content/runtime": "./dist/content/runtime.js",
"./content/runtime-assets": "./dist/content/runtime-assets.js",
"./debug": "./components/Debug.astro",
Expand Down
17 changes: 17 additions & 0 deletions packages/astro/src/assets/services/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { baseService, type LocalImageService } from './service.js';

// Empty service used for platforms that neither support Squoosh or Sharp.
const noopService: LocalImageService = {
validateOptions: baseService.validateOptions,
getURL: baseService.getURL,
parseURL: baseService.parseURL,
getHTMLAttributes: baseService.getHTMLAttributes,
async transform(inputBuffer, transformOptions) {
return {
data: inputBuffer,
format: transformOptions.format,
};
},
};

export default noopService;
11 changes: 3 additions & 8 deletions packages/astro/src/integrations/astroFeaturesValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type {
AstroFeatureMap,
SupportsKind,
} from '../@types/astro';
import { error, type LogOptions, warn } from '../core/logger/core.js';
import { bold } from 'kleur/colors';
import { error, warn, type LogOptions } from '../core/logger/core.js';

const STABLE = 'stable';
const DEPRECATED = 'deprecated';
Expand Down Expand Up @@ -140,9 +139,7 @@ function validateAssetsFeature(
error(
logging,
'astro',
`The currently selected adapter \`${adapterName}\` is not compatible with the service "Sharp". ${bold(
'Your project will NOT be able to build.'
)}`
`The currently selected adapter \`${adapterName}\` is not compatible with the image service "Sharp".`
);
return false;
}
Expand All @@ -151,9 +148,7 @@ function validateAssetsFeature(
error(
logging,
'astro',
`The currently selected adapter \`${adapterName}\` is not compatible with the service "Squoosh". ${bold(
'Your project will NOT be able to build.'
)}`
`The currently selected adapter \`${adapterName}\` is not compatible with the image service "Squoosh".`
);
return false;
}
Expand Down
13 changes: 12 additions & 1 deletion packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { SerializedSSRManifest } from '../core/app/types';
import type { PageBuildData } from '../core/build/types';
import { buildClientDirectiveEntrypoint } from '../core/client-directive/index.js';
import { mergeConfig } from '../core/config/index.js';
import { info, warn, error, type LogOptions, AstroIntegrationLogger } from '../core/logger/core.js';
import { AstroIntegrationLogger, error, info, warn, type LogOptions } from '../core/logger/core.js';
import { isServerLikeOutput } from '../prerender/utils.js';
import { validateSupportedFeatures } from './astroFeaturesValidation.js';

Expand Down Expand Up @@ -221,6 +221,17 @@ export async function runHookConfigDone({
);
}
}
if (!validationResult.assets) {
info(
logging,
'astro',
`The selected adapter ${adapter.name} does not support Sharp or Squoosh as image services. To ensure your project still build, image processing has been disabled.`
Princesseuh marked this conversation as resolved.
Show resolved Hide resolved
);
settings.config.image.service = {
entrypoint: 'astro/assets/services/noop',
config: {},
};
}
}
settings.adapter = adapter;
},
Expand Down
Loading