diff --git a/.gitignore b/.gitignore index 08161e2..2b73834 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ npm-debug.log .DS_Store .esm-cache +# Bundle +target + # Typescript *.tsbuildinfo .tsbuildinfo diff --git a/.travis.yml b/.travis.yml index 3b571ee..885debd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,19 @@ language: node_js node_js: + - "6" - "8" - "10" - "12" - "13" sudo: false + cache: directories: - node_modules + +install: + - yarn install --ignore-engines + +script: + - 'if [ "${TRAVIS_NODE_VERSION}" = "6" ] ; then yarn build:tsc ; else yarn build:microbundle ; fi ;' + - yarn test diff --git a/example/jsonrpc.js b/example/jsonrpc.js deleted file mode 100644 index b8a8257..0000000 --- a/example/jsonrpc.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; - -const jsonrpc = require('../jsonrpc'); - -const requestObj = jsonrpc.request('123', 'update', {list: [1, 2, 3]}); -const notificationObj = jsonrpc.notification('update', {list: [1, 2, 3]}) -const successObj = jsonrpc.success('123', 'OK') -const errorObj = jsonrpc.error('123', new jsonrpc.JsonRpcError('some error', 99)) -const parseObj = jsonrpc.parse('{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}') -const parseObjBatch = jsonrpc.parse( - JSON.stringify([ - {'jsonrpc': '2.0', 'method': 'sum', 'params': [1, 2, 4], 'id': '1'}, - {'jsonrpc': '2.0', 'method': 'foo.get', 'params': {'name': 'myself'}}, - {'jsonrpc': '2.0', 'result': 19, 'id': '2'}, - {'jsonrpc': '2.0', 'error': {'code': -32600, 'message': 'Invalid Request'}, 'id': null}, - ]) -) - -console.log(requestObj) -console.log(notificationObj) -console.log(successObj) -console.log(errorObj) -console.log(parseObj) -console.log(parseObjBatch) - -// RequestObject { -// jsonrpc: '2.0', -// id: '123', -// method: 'update', -// params: { list: [ 1, 2, 3 ] } } -// NotificationObject { -// jsonrpc: '2.0', -// method: 'update', -// params: { list: [ 1, 2, 3 ] } } -// SuccessObject { jsonrpc: '2.0', id: '123', result: 'OK' } -// ErrorObject { -// jsonrpc: '2.0', -// id: '123', -// error: JsonRpcError { message: 'some error', code: 99 } } -// JsonRpcParsed { -// payload: -// RequestObject { jsonrpc: '2.0', id: 1, method: 'subtract', params: [ 42, 23 ] }, -// type: 'request' } -// [ JsonRpcParsed { -// payload: -// RequestObject { jsonrpc: '2.0', id: '1', method: 'sum', params: [Array] }, -// type: 'request' }, -// JsonRpcParsed { -// payload: -// NotificationObject { jsonrpc: '2.0', method: 'foo.get', params: [Object] }, -// type: 'notification' }, -// JsonRpcParsed { -// payload: SuccessObject { jsonrpc: '2.0', id: '2', result: 19 }, -// type: 'success' }, -// JsonRpcParsed { -// payload: -// ErrorObject { jsonrpc: '2.0', id: null, error: [JsonRpcError] }, -// type: 'error' } ] - diff --git a/package.json b/package.json index 8e5b522..8efbee8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ ], "license": "MIT", "version": "2.1.0", - "source": "src/main/ts/index.ts", + "source": "jsonrpc.ts", "main": "jsonrpc.js", "module": "jsonrpc.mjs", "unpkg": "jsonrpc.umd.js", @@ -42,10 +42,10 @@ }, "scripts": { "build:tsc": "tsc -p tsconfig.build.json", - "build:microbundle": "microbundle jsonrpc.ts --name jsonrpc --strict", + "build:microbundle": "microbundle build jsonrpc.ts --name jsonrpc --strict", "build": "yarn build:microbundle", "lint": "tslint -p tsconfig.json -t stylish jsonrpc.ts", - "test": "npm run lint && tman" + "test": "yarn lint && tman" }, "files": [ "README.md", diff --git a/test/index.js b/test/index.js index a9798c9..357336e 100644 --- a/test/index.js +++ b/test/index.js @@ -4,8 +4,11 @@ const assert = require('assert') const tman = require('tman') test(require('../jsonrpc.js')) -test(require('../jsonrpc.umd')) -test(require('esm')(module)('../jsonrpc.mjs')) + +if (!process.version.match(/^v(6\.\d+)/)) { + test(require('../jsonrpc.umd')) + test(require('esm')(module)('../jsonrpc.mjs')) +} require('ts-node/register') test(require('../jsonrpc.ts').default)