| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import { io } from './utils' |
| |
|
| | if (process.env.NEXT_RUNTIME === 'edge') { |
| | |
| | } else { |
| | const nodeCrypto = require('node:crypto') as typeof import('node:crypto') |
| |
|
| | |
| | |
| |
|
| | |
| |
|
| | const randomUUIDExpression = "`require('node:crypto').randomUUID()`" |
| | try { |
| | const _randomUUID = nodeCrypto.randomUUID |
| | nodeCrypto.randomUUID = function randomUUID() { |
| | io(randomUUIDExpression, 'random') |
| | return _randomUUID.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${randomUUIDExpression} extension. When using \`cacheComponents\` calling this function will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| |
|
| | const randomBytesExpression = "`require('node:crypto').randomBytes(size)`" |
| | try { |
| | const _randomBytes = nodeCrypto.randomBytes |
| | |
| | nodeCrypto.randomBytes = function randomBytes() { |
| | if (typeof arguments[1] !== 'function') { |
| | |
| | io(randomBytesExpression, 'random') |
| | } |
| | return _randomBytes.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${randomBytesExpression} extension. When using \`cacheComponents\` calling this function without a callback argument will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| |
|
| | const randomFillSyncExpression = |
| | "`require('node:crypto').randomFillSync(...)`" |
| | try { |
| | const _randomFillSync = nodeCrypto.randomFillSync |
| | |
| | nodeCrypto.randomFillSync = function randomFillSync() { |
| | io(randomFillSyncExpression, 'random') |
| | return _randomFillSync.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${randomFillSyncExpression} extension. When using \`cacheComponents\` calling this function will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| |
|
| | const randomIntExpression = "`require('node:crypto').randomInt(min, max)`" |
| | try { |
| | const _randomInt = nodeCrypto.randomInt |
| | |
| | nodeCrypto.randomInt = function randomInt() { |
| | if (typeof arguments[2] !== 'function') { |
| | |
| | io(randomIntExpression, 'random') |
| | } |
| | return _randomInt.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${randomBytesExpression} extension. When using \`cacheComponents\` calling this function without a callback argument will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| |
|
| | const generatePrimeSyncExpression = |
| | "`require('node:crypto').generatePrimeSync(...)`" |
| | try { |
| | const _generatePrimeSync = nodeCrypto.generatePrimeSync |
| | |
| | nodeCrypto.generatePrimeSync = function generatePrimeSync() { |
| | io(generatePrimeSyncExpression, 'random') |
| | return _generatePrimeSync.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${generatePrimeSyncExpression} extension. When using \`cacheComponents\` calling this function will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| |
|
| | const generateKeyPairSyncExpression = |
| | "`require('node:crypto').generateKeyPairSync(...)`" |
| | try { |
| | const _generateKeyPairSync = nodeCrypto.generateKeyPairSync |
| | |
| | nodeCrypto.generateKeyPairSync = function generateKeyPairSync() { |
| | io(generateKeyPairSyncExpression, 'random') |
| | return _generateKeyPairSync.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${generateKeyPairSyncExpression} extension. When using \`cacheComponents\` calling this function will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| |
|
| | const generateKeySyncExpression = |
| | "`require('node:crypto').generateKeySync(...)`" |
| | try { |
| | const _generateKeySync = nodeCrypto.generateKeySync |
| | nodeCrypto.generateKeySync = function generateKeySync() { |
| | io(generateKeySyncExpression, 'random') |
| | return _generateKeySync.apply(this, arguments as any) |
| | } |
| | } catch { |
| | console.error( |
| | `Failed to install ${generateKeySyncExpression} extension. When using \`cacheComponents\` calling this function will not correctly trigger dynamic behavior.` |
| | ) |
| | } |
| | } |
| |
|