From 725bf76663830cde23eee6acfea70c868dad8df4 Mon Sep 17 00:00:00 2001 From: Izaak Gough Date: Mon, 17 Aug 2026 12:55:33 +0100 Subject: [PATCH] refactor(storage-resize-images): use Node built-ins for uuid and mkdir Drops the mkdirp and uuid dependencies in favour of crypto.randomUUID() and fs.promises.mkdir with recursive. The extension removed the same two packages before the kit was created. --- kits/storage-resize-images/package-lock.json | 32 +------------------ kits/storage-resize-images/package.json | 4 +-- .../src/file-operations.ts | 7 ++-- .../storage-resize-images/src/resize-image.ts | 6 ++-- kits/storage-resize-images/src/util.ts | 6 ++-- 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/kits/storage-resize-images/package-lock.json b/kits/storage-resize-images/package-lock.json index 6ac2cb053..862bb606c 100644 --- a/kits/storage-resize-images/package-lock.json +++ b/kits/storage-resize-images/package-lock.json @@ -14,10 +14,8 @@ "firebase-admin": "^13.2.0", "firebase-functions": "7.3.2", "genkit": "^1.2.0", - "mkdirp": "^3.0.1", "p-queue": "^6.6.2", - "sharp": "^0.35.3", - "uuid": "^11.0.5" + "sharp": "^0.35.3" }, "engines": { "node": ">=22" @@ -6039,21 +6037,6 @@ "node": ">=16 || 14 >=14.17" } }, - "node_modules/mkdirp": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", - "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", - "license": "MIT", - "bin": { - "mkdirp": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/module-details-from-path": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/module-details-from-path/-/module-details-from-path-1.0.4.tgz", @@ -7337,19 +7320,6 @@ "node": ">= 0.4.0" } }, - "node_modules/uuid": { - "version": "11.1.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz", - "integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "license": "MIT", - "bin": { - "uuid": "dist/esm/bin/uuid" - } - }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/kits/storage-resize-images/package.json b/kits/storage-resize-images/package.json index 123267ccc..14fa1f97e 100644 --- a/kits/storage-resize-images/package.json +++ b/kits/storage-resize-images/package.json @@ -30,9 +30,7 @@ "firebase-admin": "^13.2.0", "firebase-functions": "7.3.2", "genkit": "^1.2.0", - "mkdirp": "^3.0.1", "p-queue": "^6.6.2", - "sharp": "^0.35.3", - "uuid": "^11.0.5" + "sharp": "^0.35.3" } } \ No newline at end of file diff --git a/kits/storage-resize-images/src/file-operations.ts b/kits/storage-resize-images/src/file-operations.ts index e56441706..9ef27a400 100644 --- a/kits/storage-resize-images/src/file-operations.ts +++ b/kits/storage-resize-images/src/file-operations.ts @@ -14,12 +14,11 @@ * limitations under the License. */ +import * as crypto from "node:crypto"; import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; import type { Bucket, File } from "@google-cloud/storage"; -import { mkdirp } from "mkdirp"; -import { v4 as uuidv4 } from "uuid"; import type { ResolvedResizeImagesConfig } from "./export-config"; import * as logs from "./logs"; import { countNegativeTraversals, type StorageObjectMetadata } from "./util"; @@ -29,11 +28,11 @@ export async function downloadOriginalFile( filePath: string, verbose: boolean ): Promise<[string, File]> { - const localFile = path.join(os.tmpdir(), uuidv4()); + const localFile = path.join(os.tmpdir(), crypto.randomUUID()); const tempLocalDir = path.dirname(localFile); if (verbose) logs.tempDirectoryCreating(tempLocalDir); - await mkdirp(tempLocalDir); + await fs.promises.mkdir(tempLocalDir, { recursive: true }); if (verbose) logs.tempDirectoryCreated(tempLocalDir); const remoteFile = bucket.file(filePath); diff --git a/kits/storage-resize-images/src/resize-image.ts b/kits/storage-resize-images/src/resize-image.ts index 117e10cdc..e49b4352f 100644 --- a/kits/storage-resize-images/src/resize-image.ts +++ b/kits/storage-resize-images/src/resize-image.ts @@ -14,12 +14,12 @@ * limitations under the License. */ +import * as crypto from "node:crypto"; import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; import type { Bucket } from "@google-cloud/storage"; import sharp from "sharp"; -import { v4 as uuidv4 } from "uuid"; import type { ResolvedResizeImagesConfig } from "./export-config"; import { SUPPORTED_EXTENSIONS, @@ -124,7 +124,7 @@ export const modifyImage = async ({ let modifiedFile: string | undefined; try { - modifiedFile = path.join(os.tmpdir(), uuidv4()); + modifiedFile = path.join(os.tmpdir(), crypto.randomUUID()); const metadata = constructMetadata( modifiedFileName, imageContentType, @@ -204,7 +204,7 @@ export const constructMetadata = ( config.cacheControlHeader ?? objectMetadata.cacheControl; if (config.regenerateToken && customMetadata.firebaseStorageDownloadTokens) { - customMetadata.firebaseStorageDownloadTokens = uuidv4(); + customMetadata.firebaseStorageDownloadTokens = crypto.randomUUID(); } return metadata; }; diff --git a/kits/storage-resize-images/src/util.ts b/kits/storage-resize-images/src/util.ts index bce45dd29..f37b84c1c 100644 --- a/kits/storage-resize-images/src/util.ts +++ b/kits/storage-resize-images/src/util.ts @@ -14,13 +14,13 @@ * limitations under the License. */ +import * as crypto from "node:crypto"; import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; import type { Bucket, FileMetadata } from "@google-cloud/storage"; import { logger } from "firebase-functions"; import sharp from "sharp"; -import { v4 as uuidv4 } from "uuid"; import { SUPPORTED_CONTENT_TYPES, SUPPORTED_EXTENSIONS } from "./global"; import * as logs from "./logs"; @@ -105,7 +105,7 @@ export async function replaceWithConfiguredPlaceholder( ); const placeholderFile = bucket.file(placeholderPath); - const tempPlaceholder = path.join(os.tmpdir(), uuidv4()); + const tempPlaceholder = path.join(os.tmpdir(), crypto.randomUUID()); await placeholderFile.download({ destination: tempPlaceholder }); @@ -125,7 +125,7 @@ export async function replaceWithDefaultPlaceholder( localFile: string ): Promise { const localPlaceholderFile = path.join(__dirname, "placeholder.png"); - const tempPlaceholder = path.join(os.tmpdir(), uuidv4()); + const tempPlaceholder = path.join(os.tmpdir(), crypto.randomUUID()); fs.copyFileSync(localPlaceholderFile, tempPlaceholder); fs.unlinkSync(localFile); fs.renameSync(tempPlaceholder, localFile);