mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #49583 feat(bindings): Update to v1.5 by @ExE-Boss
This commit is contained in:
@@ -1,4 +1,39 @@
|
||||
import bindings = require('bindings');
|
||||
|
||||
// Use your bindings defined in your C files
|
||||
const result = bindings('binding.node').your_c_function();
|
||||
bindings('binding.node');
|
||||
bindings({
|
||||
arrow: process.env.NODE_BINDINGS_ARROW || ' → ',
|
||||
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled',
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
nodePreGyp: `node-v${process.versions.modules}-${process.platform}-${process.arch}`,
|
||||
version: process.versions.node,
|
||||
bindings: 'bindings.node',
|
||||
try: [
|
||||
// node-gyp's linked version in the "build" dir
|
||||
['module_root', 'build', 'bindings'],
|
||||
// node-waf and gyp_addon (a.k.a node-gyp)
|
||||
['module_root', 'build', 'Debug', 'bindings'],
|
||||
['module_root', 'build', 'Release', 'bindings'],
|
||||
// Debug files, for development (legacy behavior, remove for node v0.9)
|
||||
['module_root', 'out', 'Debug', 'bindings'],
|
||||
['module_root', 'Debug', 'bindings'],
|
||||
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
||||
['module_root', 'out', 'Release', 'bindings'],
|
||||
['module_root', 'Release', 'bindings'],
|
||||
// Legacy from node-waf, node <= 0.4.x
|
||||
['module_root', 'build', 'default', 'bindings'],
|
||||
// Production "Release" buildtype binary (meh...)
|
||||
['module_root', 'compiled', 'version', 'platform', 'arch', 'bindings'],
|
||||
// node-qbs builds
|
||||
['module_root', 'addon-build', 'release', 'install-root', 'bindings'],
|
||||
['module_root', 'addon-build', 'debug', 'install-root', 'bindings'],
|
||||
['module_root', 'addon-build', 'default', 'install-root', 'bindings'],
|
||||
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
||||
['module_root', 'lib', 'binding', 'nodePreGyp', 'bindings'],
|
||||
],
|
||||
});
|
||||
|
||||
bindings.getFileName(); // $ExpectType string
|
||||
bindings.getFileName('/node_modules/foo/index.js'); // $ExpectType string
|
||||
bindings.getRoot(process.cwd()); // $ExpectType string
|
||||
|
||||
43
types/bindings/index.d.ts
vendored
43
types/bindings/index.d.ts
vendored
@@ -1,13 +1,52 @@
|
||||
// Type definitions for bindings 1.3
|
||||
// Type definitions for bindings 1.5
|
||||
// Project: https://github.com/TooTallNate/node-bindings
|
||||
// Definitions by: Daniel Perez Alvarez <https://github.com/unindented>
|
||||
// ExE Boss <https://github.com/ExE-Boss>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node"/>
|
||||
|
||||
/**
|
||||
* The main `bindings()` function loads the compiled bindings for a given module.
|
||||
* It uses V8's Error API to determine the parent filename that this function is
|
||||
* being invoked from, which is then used to find the root directory.
|
||||
*/
|
||||
declare function bindings(mod: string): any;
|
||||
declare function bindings(mod: string | bindings.Options): any;
|
||||
declare namespace bindings {
|
||||
interface Options {
|
||||
/** @default process.env.NODE_BINDINGS_ARROW || ' → ' */
|
||||
arrow?: string;
|
||||
/** @default process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled' */
|
||||
compiled?: string;
|
||||
/** @default process.platform */
|
||||
platform?: NodeJS.Platform;
|
||||
/** @default process.arch */
|
||||
arch?: string;
|
||||
/** @default `node-v${process.versions.modules}-${process.platform}-${process.arch}` */
|
||||
nodePreGyp?: string;
|
||||
/** @default process.versions.node */
|
||||
version?: string;
|
||||
/** @default 'bindings.node' */
|
||||
bindings?: string;
|
||||
try?: ReadonlyArray<ReadonlyArray<string>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filename of the JavaScript file that invokes this function.
|
||||
* Used to help find the root directory of a module.
|
||||
* Optionally accepts an filename argument to skip when searching for the invoking filename
|
||||
*/
|
||||
function getFileName(calling_file?: string): string;
|
||||
|
||||
/**
|
||||
* Gets the root directory of a module, given an arbitrary filename
|
||||
* somewhere in the module tree. The "root directory" is the directory
|
||||
* containing the `package.json` file.
|
||||
*
|
||||
* In: /home/nate/node-native-module/lib/index.js
|
||||
* Out: /home/nate/node-native-module
|
||||
*/
|
||||
function getRoot(file: string): string;
|
||||
}
|
||||
|
||||
export = bindings;
|
||||
|
||||
Reference in New Issue
Block a user