From f45a7d2900a7db52ee55fd1864685d561211a2a2 Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Tue, 8 Mar 2022 11:12:00 +0900 Subject: [PATCH 1/2] Support named exports in esm modules --- index.js | 18 ++++++------------ package.json | 1 + test/esm.tests.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 test/esm.tests.js diff --git a/index.js b/index.js index a480f1dc..8cee4ce7 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,6 @@ -module.exports = { - verify: require('./verify'), - sign: require('./sign'), - JsonWebTokenError: require('./lib/JsonWebTokenError'), - NotBeforeError: require('./lib/NotBeforeError'), - TokenExpiredError: require('./lib/TokenExpiredError'), -}; - -Object.defineProperty(module.exports, 'decode', { - enumerable: false, - value: require('./decode'), -}); +module.exports.decode = require('./decode'); +module.exports.verify = require('./verify'); +module.exports.sign = require('./sign'); +module.exports.JsonWebTokenError = require('./lib/JsonWebTokenError'); +module.exports.NotBeforeError = require('./lib/NotBeforeError'); +module.exports.TokenExpiredError = require('./lib/TokenExpiredError'); diff --git a/package.json b/package.json index 81d63da8..cdd00a61 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "8.5.1", "description": "JSON Web Token implementation (symmetric and asymmetric)", "main": "index.js", + "exports": "./index.js", "nyc": { "check-coverage": true, "lines": 95, diff --git a/test/esm.tests.js b/test/esm.tests.js new file mode 100644 index 00000000..47e9bdd3 --- /dev/null +++ b/test/esm.tests.js @@ -0,0 +1,16 @@ +var expect = require('chai').expect; + +describe('encoding', function() { + + it('should import this module correctly', function () { + return import('jsonwebtoken').then(jwt => { + expect(jwt.sign).to.be.a('function'); + expect(jwt.decode).to.be.a('function'); + expect(jwt.verify).to.be.a('function'); + expect(jwt.JsonWebTokenError).to.be.a('function'); + expect(jwt.NotBeforeError).to.be.a('function'); + expect(jwt.TokenExpiredError).to.be.a('function'); + }); + }); + +}); From adf3a620ff39c5512162a06279322add7cfcb4db Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Thu, 22 Dec 2022 08:47:23 +0900 Subject: [PATCH 2/2] fix --- .eslintrc.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 572b76fd..f68554af 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,7 @@ { "root": true, "parserOptions": { - "ecmaVersion": 6 + "ecmaVersion": "latest" }, "env": { "es6": true, diff --git a/package.json b/package.json index f4d4f619..12a29c98 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "chai": "^4.1.2", "conventional-changelog": "~1.1.0", "cost-of-modules": "^1.0.1", - "eslint": "^4.19.1", + "eslint": "^8.30.0", "mocha": "^5.2.0", "nsp": "^2.6.2", "nyc": "^11.9.0",