Skip to content

Commit

Permalink
Removes fileURLToPath dependency from @astrojs/image SSR producti…
Browse files Browse the repository at this point in the history
…on endpoint (#4048)

* removing fileURLToPath dependency from SSR production endpoint

* chore: add changeset
  • Loading branch information
Tony Sullivan committed Jul 25, 2022
1 parent ab8f490 commit e60d6d9
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-tables-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Removes Node's `fileURLToPath` dependency in the production SSR endpoint
6 changes: 3 additions & 3 deletions packages/integrations/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"image-type": "^4.1.0",
"mrmime": "^1.0.0",
"sharp": "^0.30.6",
"slash": "^4.0.0"
"slash": "^4.0.0",
"tiny-glob": "^0.2.9"
},
"devDependencies": {
"@types/etag": "^1.8.1",
"@types/sharp": "^0.30.4",
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"tiny-glob": "^0.2.9"
"astro-scripts": "workspace:*"
}
}
6 changes: 3 additions & 3 deletions packages/integrations/image/src/build/ssg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { OUTPUT_DIR } from '../constants.js';
import type { SSRImageService, TransformOptions } from '../types.js';
import { isRemoteImage, loadLocalImage, loadRemoteImage } from '../utils/images.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/image/src/build/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import path from 'path';
import fs from 'node:fs/promises';
import path from 'node:path';
import glob from 'tiny-glob';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { ensureDir } from '../utils/paths.js';

async function globImages(dir: URL) {
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/image/src/endpoints/prod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { APIRoute } from 'astro';
import etag from 'etag';
import { lookup } from 'mrmime';
import { fileURLToPath } from 'url';
// @ts-ignore
import loader from 'virtual:image-loader';
import { isRemoteImage, loadLocalImage, loadRemoteImage } from '../utils/images.js';
Expand All @@ -20,8 +19,9 @@ export const get: APIRoute = async ({ request }) => {
if (isRemoteImage(transform.src)) {
inputBuffer = await loadRemoteImage(transform.src);
} else {
const pathname = fileURLToPath(new URL(`../client${transform.src}`, import.meta.url));
inputBuffer = await loadLocalImage(pathname);
const clientRoot = new URL('../client/', import.meta.url);
const localPath = new URL('.' + transform.src, clientRoot);
inputBuffer = await loadLocalImage(localPath.pathname);
}

if (!inputBuffer) {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/image/src/lib/get-picture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { lookup } from 'mrmime';
import { extname } from 'path';
import { extname } from 'node:path';
import { ImageAttributes, ImageMetadata, OutputFormat, TransformOptions } from '../types.js';
import { parseAspectRatio } from '../utils/images.js';
import { getImage } from './get-image.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/image/src/utils/images.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises';
import fs from 'node:fs/promises';
import type { OutputFormat, TransformOptions } from '../types.js';

export function isOutputFormat(value: string): value is OutputFormat {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/image/src/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises';
import fs from 'node:fs/promises';
import sizeOf from 'image-size';
import { ImageMetadata, InputFormat } from '../types.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/image/src/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import { OUTPUT_DIR } from '../constants.js';
import type { TransformOptions } from '../types.js';
import { isRemoteImage } from './images.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/image/src/vite-plugin-astro-image.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AstroConfig } from 'astro';
import type { PluginContext } from 'rollup';
import slash from 'slash';
import { pathToFileURL } from 'url';
import { pathToFileURL } from 'node:url';
import type { Plugin, ResolvedConfig } from 'vite';
import type { IntegrationOptions } from './types.js';
import { metadata } from './utils/metadata.js';
Expand Down
5 changes: 1 addition & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e60d6d9

Please sign in to comment.