From 0359d669a4b3c9d5cfbe30984f05fa47c9efc5e0 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 5 Jul 2018 08:41:38 +0200 Subject: [PATCH] [minor] Use prebuildify --- .npmignore | 2 -- .travis.yml | 13 +++++++++++++ appveyor.yml | 17 ++++++++++++++++- index.js | 2 +- package.json | 7 +++++-- test/test.js | 22 +++++++++++----------- 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/.npmignore b/.npmignore index 4bb4179..4b55984 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,3 @@ -prebuilds/ -coverage/ build/ test/ appveyor.yml diff --git a/.travis.yml b/.travis.yml index 509666a..9a0671c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/appveyor.yml b/appveyor.yml index eba8783..de49a88 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,5 @@ +build: off +configuration: Release environment: matrix: - nodejs_version: "10" @@ -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" diff --git a/index.js b/index.js index e7bfde8..8c30561 100644 --- a/index.js +++ b/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'); } diff --git a/package.json b/package.json index c34873a..d32e129 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } } diff --git a/test/test.js b/test/test.js index 88fcc29..e2d4495 100644 --- a/test/test.js +++ b/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 () { @@ -22,22 +22,22 @@ 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 ); @@ -45,5 +45,5 @@ function use(isValidUTF8) { }; } -describe('bindings', use(require('bindings')('validation'))); +describe('bindings', use(require('node-gyp-build')(join(__dirname, '..')))); describe('fallback', use(require('../fallback')));