danielgindi/rollup-plugin-natives

Does not work with `aws-crt`

Closed this issue · 1 comments

The aws-crt seems to store the binaries in a non-standard location under MODULE_ROOT/dist/bin/PLATFORM-ARCH/aws-crt-nodejs.node. I am not sure if this is the reason this plugin is not picking up or if it has to do with the way the code that requires the native bindings are written although I expect it to be the former.

I understand this is possibly a support or feature request and not an issue with this library. I am willing to help contribute a solution to this library or to try to work with the aws-crt maintainers to work with this library. Please advise how I can help move this along.

@danielgindi I found a workaround that worked for my particular use case with this plugin. In aws-crt there is a binding.js file that dynamically finds the location of aws-crt-nodejs.node based on the PLATFORM and ARCHITECTURE. My workaround was to overwrite this file using my own rollup transformer before this plugin. It may be useful to add under a tips / tricks section for those using a module that follows a non-standard approach. Here's what I used:

    // other rollup plugins
    {
      transform(code, id) {
        if (id.endsWith('aws-crt/dist/native/binding.js')) {
          return `exports.default = require('../bin/${os.platform}-${os.arch}/aws-crt-nodejs.node');`;
        }
      },
    }
    // rollup-plugin-native