Remove usage of createRequire in core image (#6488)

* Add fallback for hosts without import.meta.url

* Try using an import

* Add image-size as external

* Make image-size external

* Apply suggestions from code review

* leave image-size alone
This commit is contained in:
Matthew Phillips 2023-03-09 16:08:47 -05:00 committed by GitHub
parent dbd61c111d
commit bfd67ea749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Remove use of createRequire breaking non-Node hosts.

View file

@ -1,9 +1,7 @@
import { createRequire } from 'module';
import fs from 'node:fs/promises'; import fs from 'node:fs/promises';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { ImageMetadata, InputFormat } from '../types.js'; import { ImageMetadata, InputFormat } from '../types.js';
const require = createRequire(import.meta.url); import sizeOf from 'image-size';
const sizeOf = require('image-size');
export interface Metadata extends ImageMetadata { export interface Metadata extends ImageMetadata {
orientation?: number; orientation?: number;

View file

@ -67,6 +67,7 @@ export async function sync(
{ {
server: { middlewareMode: true, hmr: false }, server: { middlewareMode: true, hmr: false },
optimizeDeps: { entries: [] }, optimizeDeps: { entries: [] },
ssr: { external: ['image-size'] },
logLevel: 'silent', logLevel: 'silent',
}, },
{ settings, logging, mode: 'build', command: 'build', fs } { settings, logging, mode: 'build', command: 'build', fs }