Skip to content

Commit b734187

Browse files
committed
Conversion to use dependency injection
1 parent e95d5b0 commit b734187

File tree

9 files changed

+162
-56
lines changed

9 files changed

+162
-56
lines changed

.gitignore

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
/node_modules
2-
/test/build
3-
/?.js
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
node_modules
15+
npm-debug.log
16+
.nyc_output/
17+
coverage
18+
build
19+
node-addon-api

.travis.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
sudo: false
22

33
env:
4-
- CXX=g++-4.8
4+
- CXX=g++-4.9
55
addons:
66
apt:
77
sources:
88
- ubuntu-toolchain-r-test
99
packages:
10-
- g++-4.8
10+
- g++-4.9
1111

1212
language: node_js
1313

1414
node_js:
15-
- "4"
16-
- "5"
1715
- "6"
18-
- "7"
1916
- "8"
17+
- "9"
2018

21-
install:
22-
- PATH="`npm bin`:`npm bin -g`:$PATH"
23-
# Node 0.8 comes with a too obsolete npm
24-
- if [[ "`node --version`" =~ ^v0\.8\. ]]; then npm install -g [email protected] ; fi
25-
# Install dependencies and build
26-
- npm install
27-
28-
script:
29-
# Output useful info for debugging
30-
- node --version
31-
- npm --version
32-
# Run tests
33-
- npm test
19+
after_success:
20+
- npm install coveralls
21+
- nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2012 Nathan Rajlich <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
'Software'), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
ref-struct
2-
==========
1+
ref-struct-di
2+
=============
33
### Create ABI-compliant "[struct][]" instances on top of Buffers
4-
[![Build Status](https://secure.travis-ci.org/TooTallNate/ref-struct.svg)](https://travis-ci.org/TooTallNate/ref-struct)
5-
[![Build Status](https://ci.appveyor.com/api/projects/status/6v4h5v5kh9kmtke8?svg=true)](https://ci.appveyor.com/project/TooTallNate/ref-struct)
64

5+
[![NPM Version](https://img.shields.io/npm/v/ref-struct-di.svg?style=flat)](https://npmjs.org/package/ref-struct-di)
6+
[![NPM Downloads](https://img.shields.io/npm/dm/ref-struct-di.svg?style=flat)](https://npmjs.org/package/ref-struct-di)
7+
[![Build Status](https://travis-ci.org/node-ffi-napi/ref-struct-di.svg?style=flat&branch=master)](https://travis-ci.org/node-ffi-napi/ref-struct-di?branch=master)
8+
[![Coverage Status](https://coveralls.io/repos/node-ffi-napi/ref-struct-di/badge.svg?branch=master)](https://coveralls.io/r/node-ffi-napi/ref-struct-di?branch=master)
9+
[![Dependency Status](https://david-dm.org/node-ffi-napi/ref-struct-di.svg?style=flat)](https://david-dm.org/node-ffi-napi/ref-struct-di)
710

811
This module offers a "struct" implementation on top of Node.js Buffers
912
using the ref "type" interface.
1013

14+
**Note**: The only difference to `ref-struct` is that this module takes its
15+
dependency on `ref` via dependency injection, so that it is easier to use
16+
e.g. `ref-napi` instead.
17+
1118
Installation
1219
------------
1320

1421
Install with `npm`:
1522

1623
``` bash
17-
$ npm install ref-struct
24+
$ npm install ref-struct-di
1825
```
1926

2027

@@ -32,7 +39,7 @@ struct timeval {
3239

3340
``` js
3441
var ref = require('ref')
35-
var StructType = require('ref-struct')
42+
var StructType = require('ref-struct-di')(ref)
3643

3744
// define the time types
3845
var time_t = ref.types.long

appveyor.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,25 @@
22

33
# Test against these versions of Node.js.
44
environment:
5-
# Visual Studio Version
6-
MSVS_VERSION: 2013
75
# Test against these versions of Node.js and io.js
86
matrix:
9-
- nodejs_version: "4"
7+
# node.js
108
- nodejs_version: "6"
11-
- nodejs_version: "7"
129
- nodejs_version: "8"
10+
- nodejs_version: "9"
1311

1412
platform:
1513
- x86
1614
- x64
1715

1816
# Install scripts. (runs after repo cloning)
1917
install:
20-
# Get the latest stable version of Node 0.STABLE.latest
21-
- ps: if($env:nodejs_version -eq "0.8") {Install-Product node $env:nodejs_version}
22-
- ps: if($env:nodejs_version -ne "0.8") {Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)}
23-
# Node 0.8 comes with a too obsolete npm
24-
- IF %nodejs_version% == 0.8 (npm install -g [email protected])
25-
# Install latest NPM only for node.js versions until built in node-gyp adds io.js support
26-
# Update is required for node.js 0.8 because built in npm(node-gyp) does not know VS2013
27-
- IF %nodejs_version% LSS 1 (npm install -g npm@2)
28-
- IF %nodejs_version% LSS 1 set PATH=%APPDATA%\npm;%PATH%
29-
# Typical npm stuff.
30-
- npm install --msvs_version=%MSVS_VERSION%
18+
- python -V
19+
- set PYTHON=python
20+
- ps: Install-Product node $env:nodejs_version $env:platform
21+
- node -p process.arch
22+
- node -p process.version
23+
- npm install
3124

3225
# Post-install test scripts.
3326
test_script:

code-of-conduct.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project maintainer at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+

lib/struct.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
'use strict';
22
/**
33
* An interface for modeling and instantiating C-style data structures. This is
44
* not a constructor per-say, but a constructor generator. It takes an array of
@@ -46,7 +46,6 @@
4646
* Module dependencies.
4747
*/
4848

49-
var ref = require('ref')
5049
var util = require('util')
5150
var assert = require('assert')
5251
var debug = require('debug')('ref:struct')
@@ -55,7 +54,7 @@ var debug = require('debug')('ref:struct')
5554
* Module exports.
5655
*/
5756

58-
module.exports = Struct
57+
module.exports = function (ref) {
5958

6059
/**
6160
* The Struct "type" meta-constructor.
@@ -358,3 +357,7 @@ proto.inspect = function inspect () {
358357
proto.ref = function ref () {
359358
return this['ref.buffer']
360359
}
360+
361+
return Struct;
362+
363+
};

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "ref-struct",
2+
"name": "ref-struct-di",
33
"description": "Create ABI-compliant \"struct\" instances on top of Buffers",
44
"keywords": [
55
"struct",
@@ -10,24 +10,29 @@
1010
"ffi"
1111
],
1212
"version": "1.1.0",
13-
"author": "Nathan Rajlich <[email protected]> (http://tootallnate.net)",
13+
"author": "Anna Henningsen <[email protected]>",
14+
"contributors": [
15+
"Nathan Rajlich <[email protected]>"
16+
],
1417
"repository": {
1518
"type": "git",
16-
"url": "git://github.com/TooTallNate/ref-struct.git"
19+
"url": "git://github.com/node-ffi-napi/ref-struct-di.git"
1720
},
1821
"main": "./lib/struct.js",
1922
"license": "MIT",
2023
"scripts": {
21-
"test": "node-gyp rebuild --directory test && mocha -gc --reporter spec"
24+
"test": "node-gyp rebuild --directory test && nyc mocha -gc --reporter spec"
2225
},
2326
"dependencies": {
24-
"debug": "2",
25-
"ref": "1"
27+
"debug": "^3.1.0"
2628
},
2729
"devDependencies": {
30+
"binding": "^3.0.3",
2831
"bindings": "~1.2.0",
29-
"nan": "2",
30-
"mocha": "*",
31-
"ref-array": "~1.1.2"
32+
"mocha": "^4.0.1",
33+
"nan": "^2.8.0",
34+
"nyc": "^11.3.0",
35+
"ref-array": "^1.2.0",
36+
"ref-napi": "^1.4.0"
3237
}
3338
}

test/struct.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
1+
'use strict';
22
var assert = require('assert')
33
, ref = require('ref')
44
, ArrayType = require('ref-array')
5-
, Struct = require('../')
5+
, Struct = require('../')(ref)
66
, bindings = require('bindings')({ module_root: __dirname, bindings: 'struct_tests' })
77

88
describe('Struct', function () {

0 commit comments

Comments
 (0)