diff --git a/.editorconfig b/.editorconfig index 6b0ca6b..a05e25f 100755 --- a/.editorconfig +++ b/.editorconfig @@ -9,13 +9,9 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[package.json] +[{package.json, *.yaml, *.yml}] indent_style = space indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true [*.md] trim_trailing_whitespace = false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21a541e..acbc607 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,3 +21,5 @@ jobs: if: matrix.os == 'ubuntu-latest' - name: Compile run: npm install --verbose + - name: Run tests + run: npm test diff --git a/.idea/dictionaries/pokusew.xml b/.idea/dictionaries/pokusew.xml index ed13db8..cfb0407 100644 --- a/.idea/dictionaries/pokusew.xml +++ b/.idea/dictionaries/pokusew.xml @@ -1,13 +1,17 @@ + addon addons + debian doctoc gitignore npmignore pcsc pcsclite picc + pokusew + scard \ No newline at end of file diff --git a/.npmignore b/.npmignore index 1a12ee5..419a643 100644 --- a/.npmignore +++ b/.npmignore @@ -33,5 +33,6 @@ nbproject/private/ # node, npm node_modules/ -# built Node.js C++ addon +# built Node.js C++ addon (must be build specifically on the target platform, +# which is done automatically during installation via node-gyp) /build/ diff --git a/README.md b/README.md index e37fc7d..674697e 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ Bindings over pcsclite to access Smart Cards. It works in **Linux**, **macOS** a - [Disabling drivers to make pcsclite working on Linux](#disabling-drivers-to-make-pcsclite-working-on-linux) - [Which Node.js versions are supported?](#which-nodejs-versions-are-supported) - [Can I use this library in my React Native app?](#can-i-use-this-library-in-my-react-native-app) +- [Frequent errors](#frequent-errors) + - [Error: Cannot find module '../build/Release/pcsclite.node'](#error-cannot-find-module-buildreleasepcsclitenode) - [License](#license) @@ -345,6 +347,34 @@ or in **Electron.js and NW.js** desktop apps. On the other hand, these requireme On top of that, React Native does not contain any Node.js runtime. +## Frequent errors + +### Error: Cannot find module '../build/Release/pcsclite.node' + +@pokusew/pcsclite uses **Node Native Modules** (Node.js C++ Addon) to access PC/SC API (pcsclite). +The Node.js native C++ addon is built during installation via [node-gyp](https://github.com/nodejs/node-gyp) +(see package.json > scripts > [install](https://github.com/pokusew/node-pcsclite/blob/master/package.json#L37)). +When you see the error `Cannot find module '../build/Release/pcsclite.node'`, something probably +**went wrong during the installation**. + +Follow the steps below to resolve your problem: +1. If **there are any errors** in the output of the `npm install` resp. `yarn install`, + * **ensure you meet all the requirements** described in the [Installation](#installation) section of this README. + Then try reinstalling @pokusew/pcsclite (npm uninstall / yarn remove and then npm install / yarn add). + * **If the problem persists**, [open a new issue](https://github.com/pokusew/node-pcsclite/issues/new) + and be sure to include the output of the `npm install` resp. `yarn install` + and the details about your platform, OS, Node.js version and npm/yarn version. +2. If **there are no errors** during the installation, + * then try reinstalling @pokusew/pcsclite (npm uninstall / yarn remove and then npm install / yarn add). + * If it does not help, then examine the contents of the folder `node_modules/@pokusew/pcsclite` in your project + (in case you installed @pokusew/pcsclite as a dependency). There should be a `build` folder with + a `Release` folder inside. In the `Release` folder, there should be a `pcsclite.node` file. + It is possible that this file is somewhere else. Whether you find the file somewhere or not, + please [open a new issue](https://github.com/pokusew/node-pcsclite/issues/new) + and describe the problem and be sure to include the details + about your platform, OS, Node.js version and npm/yarn version. + + ## License [ISC](/LICENSE.md) diff --git a/lib/pcsclite.js b/lib/pcsclite.js index 0e7b949..da043cc 100644 --- a/lib/pcsclite.js +++ b/lib/pcsclite.js @@ -1,7 +1,13 @@ "use strict"; const EventEmitter = require('events'); -const pcsclite = require('bindings')('pcsclite'); + +// pcsclite.node is a Node.js native C++ addon that is compiled during installation +// via node-gyp (see package.json > scripts > install) +// the build output name and directory is constant so we can require it directly +// see https://github.com/nodejs/node-gyp/issues/263, https://github.com/nodejs/node-gyp/issues/631 +const pcsclite = require('../build/Release/pcsclite.node'); + const { PCSCLite, CardReader } = pcsclite; diff --git a/package.json b/package.json index e01c535..3d4face 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "test": "mocha --exit" }, "dependencies": { - "bindings": "^1.5.0", "nan": "^2.14.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 6e37cb3..cf105ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -86,13 +86,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.0.0.tgz#23c0df14f6a88077f5f986c0d167ec03c3d5537c" integrity sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow== -bindings@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" - integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== - dependencies: - file-uri-to-path "1.0.0" - brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -238,11 +231,6 @@ esprima@^4.0.0: resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -file-uri-to-path@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" - integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== - fill-range@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"