Skip to content

Conversation

@Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Sep 14, 2025

Basically centralizes the detection of crypto and sqlite. Also I rewrote some code to avoid the loading of crypto and sqlite module to early.

Maybe it makes sense to have some smaller PRs, if you dont think runtimeFeatures instance/class is a good solution. But with runtimeFeatures Instance, we could actually disable specific features and test it.

We could actually also have a little crypto ponyfill

'use strict'

const { featureSet } = require('../../util/feature-detection.js')
/** @type {import('node:crypto')} */
const crypto = featureSet.has('crypto')
  ? require('node:crypto')
  : {
      getHashes: () => [],
      hash: (algorithm, data, outputEncoding) => {
        return outputEncoding === undefined || outputEncoding === 'buffer'
          ? Buffer.alloc(0)
          : ''
      },
      randomBytes: (size) => {
        const buf = Buffer.allocUnsafe(size)
        for (let i = 0; i < size; i++) {
          buf[i] = Math.floor(Math.random() * 256)
        }
        return buf
      },
      randomInt: function randomInt (max) {
        return Math.floor(Math.random() * max)
      },
      randomFillSync: function randomFillSync (buffer, _offset, _size) {
        for (let i = 0; i < buffer.length; ++i) {
          buffer[i] = Math.random() * 255 | 0
        }
        return buffer
      }
    }

module.exports = crypto

This relates to...

Rationale

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

Comment on lines +11 to +21
function detectRuntimeFeatureByNodeModule (moduleName) {
try {
require(moduleName)
return true
} catch (err) {
if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') {
throw err
}
return false
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be better to return the module itself as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually try to avoid to have a second require cache or something like that.

I actually think also about a check for zsdt or maybe markAsClonable.

It could help have us to test branches which are supported by the engine.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Sep 16, 2025

@metcoder95
I added more "features".

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 56fe3b7 into main Sep 18, 2025
28 of 29 checks passed
@Uzlopak Uzlopak deleted the runtime-features branch September 18, 2025 13:22
@github-actions github-actions bot mentioned this pull request Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants