New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hard-bindings-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hard-bindings-loader

Webpack loader for node addons using 'bindings' module to load.

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

hard-bindings-loader

A webpack loader for node addon modules that handles the recommended require("bindings")("myaddon.node") pattern.

Very early, use at your own risk, but feedback welcome!

Usage

No options at the moment, always emits all .node files directly in the output directory.

// webpack.config.js
module.exports = {
  externals: [
    // Don't try to pack referenced .node files
    function(context, request, callback) {
      if (/\.node$/.test(request)) {
        return callback(null, `commonjs ${request}`);
      }
      return callback();
    },
  ],
  module: {
    rules: [
      // ...
      // Rewrites and emits
      {
        test: /\.m?js$/,
        loader: "hard-bindings-loader",
      },
    ],
  },
};

In theory this should also work well chained with 'node-loader' to bundle the binary into the JS bundle, but I haven't tried.

Behavior

Recognizes require('bindings')('foo.node'), uses (roughly) require('bindings')({ path: true, bindings: 'foo.node' }) to get the built addon module, re-writes the require to require('./foo.node'), and emits the referenced file at that relative path.

Should also handle require('bindings')({ bindings: 'foo.node', ... }), including with path: true to just get the path, but that has even less testing than the rest of this module.

No options are supported yet, in theory this should support most everything file-loader does to control the .node file output.

FAQs

Package last updated on 21 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts