Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@dtkdtk/jsnut

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@dtkdtk/jsnut

What is "JSNut"? JSNut is a NodeJS NUTive module build tool`

unpublished
latest
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

JSNut :: Tool for building native NodeJS modules

What is "JSNut"? JSNut is a NodeJS NUTive module build tool. It is very easy to use: npx -- @dtkdtk/jsnut build -f ./src/module.cc -o ./dist/ --onlymod will compile module.cc file into a native NodeJS addon (module.node), which you can import into your JS code using require("./module.node")

API

  • command jsnut

Features

  • Auto-generation of package.json and binding.gyp files
  • Configurable output directory and output file name
  • sort_includes tool [experimental]

Usage

Type npx @dtkdtk/jsnut help to get command help.

Type npx -- @dtkdtk/jsnut build <-f filename> <-o outdir> [-n modname] [--clean|--onlymod] to compile C++ file

Example

[!IMPORTANT]
using namespace STH; in any file causes compilation errors. Please use STH::... instead.

src/module.cc

#include <nan.h>
#include <iostream>
#include "otherfile.hh"

#define MODULE_NAME some_code

void do_nothing(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
    std::cout   << "nothing and "
                << otherfile_function()
                << std::endl;
}

void MODULE_INIT(v8::Local<v8::Object> exports)
{
	auto context = exports->GetCreationContextChecked();
	exports->Set(
		context,
		Nan::New("do_nothing").ToLocalChecked(),
		Nan::New<v8::FunctionTemplate>(do_nothing)->GetFunction(context).ToLocalChecked()
	);
}

NODE_MODULE(MODULE_NAME, MODULE_INIT)

src/otherfile.hh

int otherfile_function();

src/otherfile.cc

#include "otherfile.hh"
int otherfile_function()
{
    return 7;
}

./build-native-addons.bash

#!/usr/bin/env bash
#Warning: it calculates the path to the files from package.json
npx -- @dtkdtk/jsnut build  \
    -f "./src/module.cc"    \
    -f "./src/otherfile.hh" \
    -f "./src/otherfile.cc" \
    -o "./dist"             \
    --clean;
sleep 10s

Result: (file tree)

  • src/
    • otherfile.cc
    • otherfile.hh
    • module.cc
  • dist/
    • module.node (first specified source file name)
    • module.sln
    • module.vcxproj

About the '#include's sorting

[!WARNING]
This feature is experimental and uncompleted (and so unperfect). Use at your own risk

To sort, use the jsnut sort_includes <...src_dirs> command

#include directives are sorted as follows:

  • Your project headers ("ui/app.h")
  • Extern libraries (must contain / or .) (<node.h>)

[!NOTE]
Standard C headers are into this category

  • Your libraries (must be in the "lib" directory) ("lib/api.h")
  • Standart C++ headers (without .h extension) (<iostream>) There is an empty line between categories. The order was borrowed from Google, but with some changes.

[!WARNING]
The tool will remove any not-multiline comments in the '#include's block. Please put them rather (or later) than '#include' directives

Keywords

native

FAQs

Package last updated on 30 Apr 2024

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