|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('node:fs') |
| 4 | +const path = require('node:path') |
| 5 | + |
| 6 | +// Get the directory of the script |
| 7 | +const scriptDir = __dirname |
| 8 | +const projectRoot = path.dirname(path.dirname(scriptDir)) |
| 9 | + |
| 10 | +// Read package-lock.json |
| 11 | +const packageLockPath = path.join(projectRoot, 'package-lock.json') |
| 12 | +const packageLock = JSON.parse(fs.readFileSync(packageLockPath, 'utf8')) |
| 13 | + |
| 14 | +// Extract versions from package-lock.json |
| 15 | +const getVersion = (packageName) => { |
| 16 | + const packagePath = `node_modules/${packageName}` |
| 17 | + return packageLock.packages[packagePath]?.version |
| 18 | +} |
| 19 | + |
| 20 | +const versions = { |
| 21 | + realtime: getVersion('@supabase/realtime-js'), |
| 22 | + functions: getVersion('@supabase/functions-js'), |
| 23 | + postgrest: getVersion('@supabase/postgrest-js'), |
| 24 | + auth: getVersion('@supabase/auth-js'), |
| 25 | + storage: getVersion('@supabase/storage-js'), |
| 26 | + node_fetch: getVersion('@supabase/node-fetch'), |
| 27 | +} |
| 28 | + |
| 29 | +// Read or create deno.json |
| 30 | +const denoJsonPath = path.join(scriptDir, 'deno.json') |
| 31 | +let denoJson = { |
| 32 | + lock: false, |
| 33 | + imports: {}, |
| 34 | +} |
| 35 | + |
| 36 | +try { |
| 37 | + if (fs.existsSync(denoJsonPath)) { |
| 38 | + denoJson = JSON.parse(fs.readFileSync(denoJsonPath, 'utf8')) |
| 39 | + } |
| 40 | +} catch (error) { |
| 41 | + console.warn('Warning: Could not read existing deno.json, creating new one') |
| 42 | +} |
| 43 | + |
| 44 | +// Update imports in deno.json |
| 45 | +denoJson.imports = { |
| 46 | + '@supabase/realtime-js': `npm:@supabase/realtime-js@${versions.realtime}`, |
| 47 | + '@supabase/functions-js': `npm:@supabase/functions-js@${versions.functions}`, |
| 48 | + '@supabase/postgrest-js': `npm:@supabase/postgrest-js@${versions.postgrest}`, |
| 49 | + '@supabase/auth-js': `npm:@supabase/auth-js@${versions.auth}`, |
| 50 | + '@supabase/storage-js': `npm:@supabase/storage-js@${versions.storage}`, |
| 51 | + '@supabase/node-fetch': `npm:@supabase/node-fetch@${versions.node_fetch}`, |
| 52 | +} |
| 53 | + |
| 54 | +// Write updated deno.json |
| 55 | +fs.writeFileSync(denoJsonPath, JSON.stringify(denoJson, null, 2) + '\n') |
| 56 | + |
| 57 | +console.log('Updated deno.json with versions from package-lock.json') |
0 commit comments