diff --git a/app/routes/api.netlify-deploy.ts b/app/routes/api.netlify-deploy.ts index 48543e97..0bc1c5e4 100644 --- a/app/routes/api.netlify-deploy.ts +++ b/app/routes/api.netlify-deploy.ts @@ -1,5 +1,4 @@ import { type ActionFunctionArgs, json } from '@remix-run/cloudflare'; -import crypto from 'crypto'; import type { NetlifySiteInfo } from '~/types/netlify'; interface DeployRequestBody { @@ -8,6 +7,15 @@ interface DeployRequestBody { chatId: string; } +async function sha1(message: string) { + const msgBuffer = new TextEncoder().encode(message); + const hashBuffer = await crypto.subtle.digest('SHA-1', msgBuffer); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); + + return hashHex; +} + export async function action({ request }: ActionFunctionArgs) { try { const { siteId, files, token, chatId } = (await request.json()) as DeployRequestBody & { token: string }; @@ -104,7 +112,7 @@ export async function action({ request }: ActionFunctionArgs) { for (const [filePath, content] of Object.entries(files)) { // Ensure file path starts with a forward slash const normalizedPath = filePath.startsWith('/') ? filePath : '/' + filePath; - const hash = crypto.createHash('sha1').update(content).digest('hex'); + const hash = await sha1(content); fileDigests[normalizedPath] = hash; } diff --git a/vite.config.ts b/vite.config.ts index 60ea52bf..a2648264 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -93,6 +93,26 @@ export default defineConfig((config) => { }, build: { target: 'esnext', + rollupOptions: { + output: { + format: 'esm', + }, + }, + commonjsOptions: { + transformMixedEsModules: true, + }, + }, + optimizeDeps: { + esbuildOptions: { + define: { + global: 'globalThis', + }, + }, + }, + resolve: { + alias: { + buffer: 'vite-plugin-node-polyfills/polyfills/buffer', + }, }, plugins: [ nodePolyfills({