Skip to content

Commit

Permalink
[minor] Use prebuildify
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jul 5, 2018
1 parent a3e2ac4 commit 0359d66
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .npmignore
@@ -1,5 +1,3 @@
prebuilds/
coverage/
build/
test/
appveyor.yml
Expand Down
13 changes: 13 additions & 0 deletions .travis.yml
Expand Up @@ -7,3 +7,16 @@ node_js:
os:
- linux
- osx
before_deploy:
- ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-$(uname -m).tar"
- npm run prebuild
- tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds" .
deploy:
provider: releases
api_key:
secure: VCE2AgIOeQFDHWw9g+pRmh8KibbIoTstKlUsVVHrWrICTCYdoSA7ivvhy40MRi8uJwK+cMbsf3auSLYJ6siUdcm46S+5IiU65ZBCGhzhaFOJPmVdzbqK2TNM3dEVFePsnLq1Oki5YzbdjZg46AIZFrAhCmuFahicnDcY9cN2/fg=
file: "$ARCHIVE_NAME"
skip_cleanup: true
on:
tags: true
node: "10"
17 changes: 16 additions & 1 deletion appveyor.yml
@@ -1,3 +1,5 @@
build: off
configuration: Release
environment:
matrix:
- nodejs_version: "10"
Expand All @@ -15,4 +17,17 @@ test_script:
- node --version
- npm --version
- npm test
build: off
after_test:
- ps: If ($env:nodejs_version -eq "10") { npm run prebuild }
- ps: $env:ARTIFACT_NAME_PREFIX = if (Test-Path env:APPVEYOR_REPO_TAG_NAME) { $env:APPVEYOR_REPO_TAG_NAME } else { 'latest' }
artifacts:
- path: prebuilds
name: $(ARTIFACT_NAME_PREFIX)-win-$(PLATFORM)
deploy:
- provider: GitHub
artifact: /.*\.zip/
auth_token:
secure: CkWRNlzH+wmCa3+TRydWfvmSH7tevR81aAypEhXTR9ka5q0Ja8lAIPDwtPb+Ux9l
on:
appveyor_repo_tag: true
nodejs_version: "10"
2 changes: 1 addition & 1 deletion index.js
@@ -1,7 +1,7 @@
'use strict';

try {
module.exports = require('bindings')('validation');
module.exports = require('node-gyp-build')(__dirname);
} catch (e) {
module.exports = require('./fallback');
}
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -4,6 +4,8 @@
"description": "Check if a buffer contains valid UTF-8",
"main": "index.js",
"scripts": {
"install": "node-gyp-build",
"prebuild": "prebuildify --napi",
"test": "mocha"
},
"repository": {
Expand All @@ -20,9 +22,10 @@
},
"homepage": "https://github.com/websockets/utf-8-validate",
"dependencies": {
"bindings": "~1.3.0"
"node-gyp-build": "~3.4.0"
},
"devDependencies": {
"mocha": "~5.2.0"
"mocha": "~5.2.0",
"prebuildify": "~2.7.0"
}
}
22 changes: 11 additions & 11 deletions test/test.js
@@ -1,19 +1,19 @@
'use strict';

const assert = require('assert');
const path = require('path');
const fs = require('fs');
const { join } = require('path');
const { readFileSync } = require('fs');
const { strictEqual } = require('assert');

const txt = fs.readFileSync(path.join(__dirname, 'fixtures', 'lorem-ipsum.txt'));
const txt = readFileSync(join(__dirname, 'fixtures', 'lorem-ipsum.txt'));

function use(isValidUTF8) {
return function () {
it('returns true with an empty buffer', function () {
assert.strictEqual(isValidUTF8(Buffer.alloc(0)), true);
strictEqual(isValidUTF8(Buffer.alloc(0)), true);
});

it('returns true for a valid utf8 string', function () {
assert.strictEqual(isValidUTF8(Buffer.from(txt)), true);
strictEqual(isValidUTF8(Buffer.from(txt)), true);
});

it('returns false for an erroneous string', function () {
Expand All @@ -22,28 +22,28 @@ function use(isValidUTF8) {
0xa0, 0x80, 0x65, 0x64, 0x69, 0x74, 0x65, 0x64
]);

assert.strictEqual(isValidUTF8(invalid), false);
strictEqual(isValidUTF8(invalid), false);
});

it('returns true for valid cases from the autobahn test suite', function () {
assert.strictEqual(
strictEqual(
isValidUTF8(Buffer.from('\xf0\x90\x80\x80')),
true
);
assert.strictEqual(
strictEqual(
isValidUTF8(Buffer.from([0xf0, 0x90, 0x80, 0x80])),
true
);
});

it('returns false for erroneous autobahn strings', function () {
assert.strictEqual(
strictEqual(
isValidUTF8(Buffer.from([0xce, 0xba, 0xe1, 0xbd])),
false
);
});
};
}

describe('bindings', use(require('bindings')('validation')));
describe('bindings', use(require('node-gyp-build')(join(__dirname, '..'))));
describe('fallback', use(require('../fallback')));

0 comments on commit 0359d66

Please sign in to comment.