diff --git a/.gitignore b/.gitignore index 60f7cd5..9d080a7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,20 @@ test.js npm-debug.log .DS_Store -.esm-cache \ No newline at end of file +.esm-cache + +# Bundle +target + +# Typescript +*.tsbuildinfo +.tsbuildinfo +buildcache +.buildcache +.rts2_cache_cjs +.rts2_cache_es +.rts2_cache_umd + +# Yarn +yarn.lock +yarn-error.log diff --git a/.travis.yml b/.travis.yml index a25b5c0..32b76bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,23 @@ language: node_js +sudo: false + node_js: - "6" - "8" - "10" -sudo: false + - "12" + - "13" + cache: directories: - node_modules + +before_install: + - sudo apt-get install moreutils + +install: + - yarn install + - yarn build + +script: + - yarn test diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..cbce7d6 --- /dev/null +++ b/browser.js @@ -0,0 +1,26 @@ +// Browser AMD Polyfill +(function (cxt) { + const window = cxt.window + if (typeof window !== 'undefined') { + if (window.define) { + return + } + window.define = function(name, required, moduleFn) { + if (typeof name !== 'string') { + return window.define('anonymous' + Math.random(), name, required) + } + var modules = window.define.modules + var require = function() { throw new Error("AMD require not supported!")} + var exports = modules[name] = {} + var resolved = [require, exports] + for (var i = 2; i < required.length; i++) { + var m = modules[required[i]] + if (!m) throw new Error("AMD module `" + required[i] + "` not found!") + resolved.push(m) + } + moduleFn.apply(null, resolved) + } + window.define.modules = {} + window.define.amd = true + } +})(this) diff --git a/example/jsonrpc.js b/example/jsonrpc.js index b8a8257..428a9c9 100644 --- a/example/jsonrpc.js +++ b/example/jsonrpc.js @@ -1,6 +1,6 @@ "use strict"; -const jsonrpc = require('../jsonrpc'); +const jsonrpc = require('../target/umd/jsonrpc'); const requestObj = jsonrpc.request('123', 'update', {list: [1, 2, 3]}); const notificationObj = jsonrpc.notification('update', {list: [1, 2, 3]}) diff --git a/jsonrpc.d.ts b/jsonrpc.d.ts deleted file mode 100644 index 1a68567..0000000 --- a/jsonrpc.d.ts +++ /dev/null @@ -1,203 +0,0 @@ -export declare type ID = string | number; -export declare type Defined = string | number | boolean | object | null; -export declare type RpcParams = object | Defined[]; -/** - * JsonRpc Class - * - * @return {Object} JsonRpc object - * @api public - */ -export interface IJsonRpcType { - readonly jsonrpc: string; -} -export declare class JsonRpc implements IJsonRpcType { - static VERSION: string; - readonly jsonrpc: string; - constructor(); - serialize(): string; -} -export declare class RequestObject extends JsonRpc { - id: ID; - method: string; - params?: RpcParams; - constructor(id: ID, method: string, params?: RpcParams); -} -export declare class NotificationObject extends JsonRpc { - method: string; - params?: RpcParams; - constructor(method: string, params?: RpcParams); -} -export declare class SuccessObject extends JsonRpc { - id: ID; - result: Defined; - constructor(id: ID, result: Defined); -} -export declare class ErrorObject extends JsonRpc { - id: ID; - error: JsonRpcError; - constructor(id: ID, error: JsonRpcError); -} -/** - * JsonRpcParsed Class - * - * @param {JsonRpc|JsonRpcError} payload - * @param {type: } type - * @api public - */ -export declare const enum RpcStatusType { - request = "request", - notification = "notification", - success = "success", - error = "error", - invalid = "invalid" -} -export declare class JsonRpcParsed { - payload: JsonRpc | JsonRpcError; - type: RpcStatusType; - constructor(payload: JsonRpc | JsonRpcError, type: RpcStatusType); -} -/** - * JsonRpcError Class - * - * @param {String} message - * @param {Integer} code - * @return {String} name: optional - * @api public - */ -export declare class JsonRpcError { - static invalidRequest: (data: any) => JsonRpcError; - static methodNotFound: (data: any) => JsonRpcError; - static invalidParams: (data: any) => JsonRpcError; - static internalError: (data: any) => JsonRpcError; - static parseError: (data: any) => JsonRpcError; - message: string; - code: number; - data?: any; - constructor(message: string, code: number, data?: any); -} -/** - * Creates a JSON-RPC 2.0 request object - * - * @param {String|Integer} id - * @param {String} method - * @param {Object|Array} [params]: optional - * @return {Object} JsonRpc object - * @api public - */ -export declare function request(id: ID, method: string, params?: RpcParams): RequestObject; -/** - * Creates a JSON-RPC 2.0 notification object - * - * @param {String} method - * @param {Object|Array} [params]: optional - * @return {Object} JsonRpc object - * @api public - */ -export declare function notification(method: string, params?: RpcParams): NotificationObject; -/** - * Creates a JSON-RPC 2.0 success response object - * - * @param {String|Integer} id - * @param {Mixed} result - * @return {Object} JsonRpc object - * @api public - */ -export declare function success(id: ID, result: Defined): SuccessObject; -/** - * Creates a JSON-RPC 2.0 error response object - * - * @param {String|Integer} id - * @param {Object} JsonRpcError error - * @return {Object} JsonRpc object - * @api public - */ -export declare function error(id: ID, err: JsonRpcError): ErrorObject; -export interface IParsedObjectSuccess { - type: RpcStatusType.success; - payload: SuccessObject; -} -export interface IParsedObjectNotification { - type: RpcStatusType.notification; - payload: NotificationObject; -} -export interface IParsedObjectRequest { - type: RpcStatusType.request; - payload: RequestObject; -} -export interface IParsedObjectError { - type: RpcStatusType.error; - payload: ErrorObject; -} -export interface IParsedObjectInvalid { - type: RpcStatusType.invalid; - payload: JsonRpcError; -} -/** - * Takes a JSON-RPC 2.0 payload (String) and tries to parse it into a JSON. - * If successful, determine what object is it (response, notification, - * success, error, or invalid), and return it's type and properly formatted object. - * - * @param {String} msg - * @return {Object|Array} an array, or an object of this format: - * - * { - * type: - * payload: - * } - * - * @api public - */ -export declare type IParsedObject = IParsedObjectSuccess | IParsedObjectNotification | IParsedObjectRequest | IParsedObjectError | IParsedObjectInvalid; -export declare function parse(message: string): IParsedObject | IParsedObject[]; -/** - * Takes a JSON-RPC 2.0 payload (Object) or batch (Object[]) and tries to parse it. - * If successful, determine what objects are inside (response, notification, - * success, error, or invalid), and return their types and properly formatted objects. - * - * @param {Object|Array} jsonrpcObj - * @return {Object|Array} a single object or an array of `JsonRpcParsed` objects with `type` and `payload`: - * - * { - * type: - * payload: - * } - * - * @api public - */ -export declare function parseJsonRpcObject(jsonrpcObj: JsonRpc | JsonRpc[]): IParsedObject | IParsedObject[]; -/** - * Alias for `parse` method. - * Takes a JSON-RPC 2.0 payload (String) and tries to parse it into a JSON. - * @api public - */ -export declare const parseJsonRpcString: typeof parse; -/** - * Takes a JSON-RPC 2.0 payload (Object) and tries to parse it into a JSON. - * If successful, determine what object is it (response, notification, - * success, error, or invalid), and return it's type and properly formatted object. - * - * @param {Object} obj - * @return {Object} an `JsonRpcParsed` object with `type` and `payload`: - * - * { - * type: - * payload: - * } - * - * @api public - */ -export declare function parseObject(obj: any): IParsedObject; -declare const jsonrpc: { - JsonRpc: typeof JsonRpc; - JsonRpcError: typeof JsonRpcError; - request: typeof request; - notification: typeof notification; - success: typeof success; - error: typeof error; - parse: typeof parse; - parseObject: typeof parseObject; - parseJsonRpcObject: typeof parseJsonRpcObject; - parseJsonRpcString: typeof parse; -}; -export default jsonrpc; -export { jsonrpc }; diff --git a/jsonrpc.js b/jsonrpc.js deleted file mode 100644 index c4fb404..0000000 --- a/jsonrpc.js +++ /dev/null @@ -1,412 +0,0 @@ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - // **Github:** https://github.com/teambition/jsonrpc-lite - // - // http://www.jsonrpc.org/specification - // **License:** MIT - 'use strict'; - Object.defineProperty(exports, "__esModule", { value: true }); - var hasOwnProperty = Object.prototype.hasOwnProperty; - var isInteger = typeof Number.isSafeInteger === 'function' - ? Number.isSafeInteger // ECMAScript 2015 - : function (num) { - return typeof num === 'number' && isFinite(num) && num === Math.floor(num) && Math.abs(num) <= 9007199254740991; - }; - var JsonRpc = /** @class */ (function () { - function JsonRpc() { - this.jsonrpc = '2.0'; - } - JsonRpc.prototype.serialize = function () { - return JSON.stringify(this); - }; - JsonRpc.VERSION = '2.0'; - return JsonRpc; - }()); - exports.JsonRpc = JsonRpc; - var RequestObject = /** @class */ (function (_super) { - __extends(RequestObject, _super); - function RequestObject(id, method, params) { - var _this = _super.call(this) || this; - _this.id = id; - _this.method = method; - if (params !== undefined) { - _this.params = params; - } - return _this; - } - return RequestObject; - }(JsonRpc)); - exports.RequestObject = RequestObject; - var NotificationObject = /** @class */ (function (_super) { - __extends(NotificationObject, _super); - function NotificationObject(method, params) { - var _this = _super.call(this) || this; - _this.method = method; - if (params !== undefined) { - _this.params = params; - } - return _this; - } - return NotificationObject; - }(JsonRpc)); - exports.NotificationObject = NotificationObject; - var SuccessObject = /** @class */ (function (_super) { - __extends(SuccessObject, _super); - function SuccessObject(id, result) { - var _this = _super.call(this) || this; - _this.id = id; - _this.result = result; - return _this; - } - return SuccessObject; - }(JsonRpc)); - exports.SuccessObject = SuccessObject; - var ErrorObject = /** @class */ (function (_super) { - __extends(ErrorObject, _super); - // tslint:disable-next-line:no-shadowed-variable - function ErrorObject(id, error) { - var _this = _super.call(this) || this; - _this.id = id; - _this.error = error; - _this.id = id; - _this.error = error; - return _this; - } - return ErrorObject; - }(JsonRpc)); - exports.ErrorObject = ErrorObject; - var JsonRpcParsed = /** @class */ (function () { - function JsonRpcParsed(payload, type) { - this.payload = payload; - this.type = type; - this.payload = payload; - this.type = type; - } - return JsonRpcParsed; - }()); - exports.JsonRpcParsed = JsonRpcParsed; - /** - * JsonRpcError Class - * - * @param {String} message - * @param {Integer} code - * @return {String} name: optional - * @api public - */ - var JsonRpcError = /** @class */ (function () { - function JsonRpcError(message, code, data) { - this.message = message; - this.code = isInteger(code) ? code : 0; - if (data != null) { - this.data = data; - } - } - JsonRpcError.invalidRequest = function (data) { - return new JsonRpcError('Invalid request', -32600, data); - }; - JsonRpcError.methodNotFound = function (data) { - return new JsonRpcError('Method not found', -32601, data); - }; - JsonRpcError.invalidParams = function (data) { - return new JsonRpcError('Invalid params', -32602, data); - }; - JsonRpcError.internalError = function (data) { - return new JsonRpcError('Internal error', -32603, data); - }; - JsonRpcError.parseError = function (data) { - return new JsonRpcError('Parse error', -32700, data); - }; - return JsonRpcError; - }()); - exports.JsonRpcError = JsonRpcError; - /** - * Creates a JSON-RPC 2.0 request object - * - * @param {String|Integer} id - * @param {String} method - * @param {Object|Array} [params]: optional - * @return {Object} JsonRpc object - * @api public - */ - function request(id, method, params) { - var object = new RequestObject(id, method, params); - validateMessage(object, true); - return object; - } - exports.request = request; - /** - * Creates a JSON-RPC 2.0 notification object - * - * @param {String} method - * @param {Object|Array} [params]: optional - * @return {Object} JsonRpc object - * @api public - */ - function notification(method, params) { - var object = new NotificationObject(method, params); - validateMessage(object, true); - return object; - } - exports.notification = notification; - /** - * Creates a JSON-RPC 2.0 success response object - * - * @param {String|Integer} id - * @param {Mixed} result - * @return {Object} JsonRpc object - * @api public - */ - function success(id, result) { - var object = new SuccessObject(id, result); - validateMessage(object, true); - return object; - } - exports.success = success; - /** - * Creates a JSON-RPC 2.0 error response object - * - * @param {String|Integer} id - * @param {Object} JsonRpcError error - * @return {Object} JsonRpc object - * @api public - */ - function error(id, err) { - var object = new ErrorObject(id, err); - validateMessage(object, true); - return object; - } - exports.error = error; - function parse(message) { - if (!isString(message)) { - return new JsonRpcParsed(JsonRpcError.invalidRequest(message), "invalid" /* invalid */); - } - var jsonrpcObj; - try { - jsonrpcObj = JSON.parse(message); - } - catch (err) { - return new JsonRpcParsed(JsonRpcError.parseError(message), "invalid" /* invalid */); - } - return parseJsonRpcObject(jsonrpcObj); - } - exports.parse = parse; - /** - * Takes a JSON-RPC 2.0 payload (Object) or batch (Object[]) and tries to parse it. - * If successful, determine what objects are inside (response, notification, - * success, error, or invalid), and return their types and properly formatted objects. - * - * @param {Object|Array} jsonrpcObj - * @return {Object|Array} a single object or an array of `JsonRpcParsed` objects with `type` and `payload`: - * - * { - * type: - * payload: - * } - * - * @api public - */ - function parseJsonRpcObject(jsonrpcObj) { - if (!Array.isArray(jsonrpcObj)) { - return parseObject(jsonrpcObj); - } - if (jsonrpcObj.length === 0) { - return new JsonRpcParsed(JsonRpcError.invalidRequest(jsonrpcObj), "invalid" /* invalid */); - } - var parsedObjectArray = []; - for (var i = 0, len = jsonrpcObj.length; i < len; i++) { - parsedObjectArray[i] = parseObject(jsonrpcObj[i]); - } - return parsedObjectArray; - } - exports.parseJsonRpcObject = parseJsonRpcObject; - /** - * Alias for `parse` method. - * Takes a JSON-RPC 2.0 payload (String) and tries to parse it into a JSON. - * @api public - */ - exports.parseJsonRpcString = parse; - /** - * Takes a JSON-RPC 2.0 payload (Object) and tries to parse it into a JSON. - * If successful, determine what object is it (response, notification, - * success, error, or invalid), and return it's type and properly formatted object. - * - * @param {Object} obj - * @return {Object} an `JsonRpcParsed` object with `type` and `payload`: - * - * { - * type: - * payload: - * } - * - * @api public - */ - function parseObject(obj) { - var err = null; - var payload = null; - var payloadType = "invalid" /* invalid */; - if (obj == null || obj.jsonrpc !== JsonRpc.VERSION) { - err = JsonRpcError.invalidRequest(obj); - payloadType = "invalid" /* invalid */; - } - else if (!hasOwnProperty.call(obj, 'id')) { - var tmp = obj; - payload = new NotificationObject(tmp.method, tmp.params); - err = validateMessage(payload); - payloadType = "notification" /* notification */; - } - else if (hasOwnProperty.call(obj, 'method')) { - var tmp = obj; - payload = new RequestObject(tmp.id, tmp.method, tmp.params); - err = validateMessage(payload); - payloadType = "request" /* request */; - } - else if (hasOwnProperty.call(obj, 'result')) { - var tmp = obj; - payload = new SuccessObject(tmp.id, tmp.result); - err = validateMessage(payload); - payloadType = "success" /* success */; - } - else if (hasOwnProperty.call(obj, 'error')) { - var tmp = obj; - payloadType = "error" /* error */; - if (tmp.error == null) { - err = JsonRpcError.internalError(tmp); - } - else { - var errorObj = new JsonRpcError(tmp.error.message, tmp.error.code, tmp.error.data); - if (errorObj.message !== tmp.error.message || errorObj.code !== tmp.error.code) { - err = JsonRpcError.internalError(tmp); - } - else { - payload = new ErrorObject(tmp.id, errorObj); - err = validateMessage(payload); - } - } - } - if (err == null && payload != null) { - return new JsonRpcParsed(payload, payloadType); - } - return new JsonRpcParsed(err != null ? err : JsonRpcError.invalidRequest(obj), "invalid" /* invalid */); - } - exports.parseObject = parseObject; - // if error, return error, else return null - function validateMessage(obj, throwIt) { - var err = null; - if (obj instanceof RequestObject) { - err = checkId(obj.id); - if (err == null) { - err = checkMethod(obj.method); - } - if (err == null) { - err = checkParams(obj.params); - } - } - else if (obj instanceof NotificationObject) { - err = checkMethod(obj.method); - if (err == null) { - err = checkParams(obj.params); - } - } - else if (obj instanceof SuccessObject) { - err = checkId(obj.id); - if (err == null) { - err = checkResult(obj.result); - } - } - else if (obj instanceof ErrorObject) { - err = checkId(obj.id, true); - if (err == null) { - err = checkError(obj.error); - } - } - if (throwIt && err != null) { - throw err; - } - return err; - } - function checkId(id, maybeNull) { - if (maybeNull && id === null) { - return null; - } - return isString(id) || isInteger(id) - ? null - : JsonRpcError.internalError('"id" must be provided, a string or an integer.'); - } - function checkMethod(method) { - return isString(method) ? null : JsonRpcError.invalidRequest(method); - } - function checkResult(result) { - return result === undefined - ? JsonRpcError.internalError('Result must exist for success Response objects') - : null; - } - function checkParams(params) { - if (params === undefined) { - return null; - } - if (Array.isArray(params) || isObject(params)) { - // ensure params can be stringify - try { - JSON.stringify(params); - return null; - } - catch (err) { - return JsonRpcError.parseError(params); - } - } - return JsonRpcError.invalidParams(params); - } - function checkError(err) { - if (!(err instanceof JsonRpcError)) { - return JsonRpcError.internalError('Error must be an instance of JsonRpcError'); - } - if (!isInteger(err.code)) { - return JsonRpcError.internalError('Invalid error code. It must be an integer.'); - } - if (!isString(err.message)) { - return JsonRpcError.internalError('Message must exist or must be a string.'); - } - return null; - } - function isString(obj) { - return obj !== '' && typeof obj === 'string'; - } - function isObject(obj) { - return obj != null && typeof obj === 'object' && !Array.isArray(obj); - } - var jsonrpc = { - JsonRpc: JsonRpc, - JsonRpcError: JsonRpcError, - request: request, - notification: notification, - success: success, - error: error, - parse: parse, - parseObject: parseObject, - parseJsonRpcObject: parseJsonRpcObject, - parseJsonRpcString: exports.parseJsonRpcString, - }; - exports.jsonrpc = jsonrpc; - exports.default = jsonrpc; -}); -//# sourceMappingURL=jsonrpc.js.map \ No newline at end of file diff --git a/jsonrpc.js.map b/jsonrpc.js.map deleted file mode 100644 index 11da60a..0000000 --- a/jsonrpc.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"jsonrpc.js","sourceRoot":"","sources":["jsonrpc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;IAAA,yDAAyD;IACzD,EAAE;IACF,uCAAuC;IACvC,mBAAmB;IACnB,YAAY,CAAA;;IAMZ,IAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAA;IACtD,IAAM,SAAS,GAA6B,OAAO,MAAM,CAAC,aAAa,KAAK,UAAU;QACpF,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,kBAAkB;QACzC,CAAC,CAAC,UAAU,GAAG;YACb,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAA;QACjH,CAAC,CAAA;IAYH;QAIE;YACE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACtB,CAAC;QAED,2BAAS,GAAT;YACE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;QATM,eAAO,GAAW,KAAK,CAAA;QAWhC,cAAC;KAAA,AAZD,IAYC;IAZY,0BAAO;IAcpB;QAAmC,iCAAO;QAIxC,uBAAa,EAAM,EAAE,MAAc,EAAE,MAAkB;YAAvD,YACE,iBAAO,SAMR;YALC,KAAI,CAAC,EAAE,GAAG,EAAE,CAAA;YACZ,KAAI,CAAC,MAAM,GAAG,MAAM,CAAA;YACpB,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481,7 +481,7 @@ function isObject (obj: any): boolean { return obj != null && typeof obj === 'object' && !Array.isArray(obj) } -const jsonrpc = { +const jsonRpcGlobal = { JsonRpc, JsonRpcError, request, @@ -494,5 +494,24 @@ const jsonrpc = { parseJsonRpcString, } -export default jsonrpc -export { jsonrpc } +export default jsonRpcGlobal +export const jsonrpc: typeof jsonRpcGlobal = jsonRpcGlobal + +function getGlobalThis (): any { + if (typeof globalThis !== 'undefined') { return globalThis } + if (typeof self !== 'undefined') { return self } + if (typeof window !== 'undefined') { return window } + if (typeof global !== 'undefined') { return global } + // @ts-ignore + if (typeof this !== 'undefined') { return this } + + throw new Error('Unable to locate global `this`') +} + +declare global { + const jsonrpc: typeof jsonRpcGlobal + + interface Window { jsonrpc: typeof jsonRpcGlobal } +} + +getGlobalThis().jsonrpc = jsonRpcGlobal diff --git a/package-lock.json b/package-lock.json index c73aeda..0a9dcd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -161,6 +161,12 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "esm": { + "version": "3.2.25", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", + "dev": true + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -334,6 +340,25 @@ "has-flag": "^3.0.0" } }, + "terser": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-4.4.0.tgz", + "integrity": "sha512-oDG16n2WKm27JO8h4y/w3iqBGAOSCtq7k8dRmrn4Wf9NouL0b2WpMHGChFGZq4nFAQy1FsNJrVQHfurXOSTmOA==", + "dev": true, + "requires": { + "commander": "^2.20.0", + "source-map": "~0.6.1", + "source-map-support": "~0.5.12" + }, + "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + } + } + }, "thunks": { "version": "4.9.4", "resolved": "https://registry.npmjs.org/thunks/-/thunks-4.9.4.tgz", diff --git a/package.json b/package.json index 9c59d5b..2b4c20d 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,15 @@ ], "license": "MIT", "version": "2.1.0", - "main": "jsonrpc.js", - "types": "jsonrpc.d.ts", + "source": "jsonrpc.ts", + "main": "target/umd/jsonrpc.js", + "module": "target/mjs/jsonrpc.mjs", + "unpkg": "target/umd/jsonrpc.js", + "browser": "target/umd/jsonrpc.js", + "types": "target/umd/jsonrpc.d.ts", + "typescript": { + "definition": "target/umd/jsonrpc.d.ts" + }, "repository": { "type": "git", "url": "git@github.com:teambition/jsonrpc-lite.git" @@ -25,6 +32,8 @@ "dependencies": {}, "devDependencies": { "@types/node": "^12.11.1", + "esm": "^3.2.25", + "terser": "^4.4.0", "tman": "^1.9.0", "ts-node": "^8.4.1", "tslint": "^5.20.0", @@ -32,15 +41,19 @@ "typescript": "^3.6.4" }, "scripts": { - "build": "tsc -p tsconfig.build.json", + "build:umd": "tsc -p tsconfig.build.json --module UMD --target ES5 --outDir ./target/umd", + "polyfill": "cat browser.js target/umd/jsonrpc.js | sponge target/umd/jsonrpc.js", + "build:mjs": "tsc -p tsconfig.build.json --module es2015 --target ES6 --outDir ./target/mjs", + "build:es5": "tsc -p tsconfig.build.json --module CommonJS --target ES5 --outDir ./target/es5", + "build": "yarn build:es5 && yarn build:mjs && yarn build:umd && yarn polyfill && yarn compact && yarn namefix", + "compact": "for f in $(find target -name '*.js'); do short=${f%.js}; terser -c -m --source-map -o $short.js -- $f; done", + "namefix": "find target/mjs -name '*.js*' -exec bash -c ' mv $0 ${0/.js/.mjs}' {} \\;", "lint": "tslint -p tsconfig.json -t stylish jsonrpc.ts", - "test": "npm run lint && tman" + "test": "yarn lint && tman" }, "files": [ "README.md", - "jsonrpc.js", - "jsonrpc.js.map", "jsonrpc.ts", - "jsonrpc.d.ts" + "target" ] } diff --git a/test/index.js b/test/index.js index 7717452..680ff1c 100644 --- a/test/index.js +++ b/test/index.js @@ -3,7 +3,9 @@ const assert = require('assert') const tman = require('tman') -test(require('../jsonrpc')) +test(require('../target/es5/jsonrpc.js')) +test(require('../target/umd/jsonrpc.js')) +test(require('esm')(module)('../target/mjs/jsonrpc.mjs')) require('ts-node/register') test(require('../jsonrpc.ts').default) @@ -392,5 +394,9 @@ function test (jsonrpc) { tman.it('jsonrpc.parseJsonRpcString', function() { assert.strictEqual(jsonrpc.parse, jsonrpc.parseJsonRpcString) }) + + tman.it('jsonrpc exposed as global', function() { + assert.strictEqual(!!global.jsonrpc, true) + }) }) } diff --git a/tsconfig.build.json b/tsconfig.build.json index 131509a..f46e4b6 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,11 +2,12 @@ "extends": "./tsconfig.json", "compilerOptions": { "target": "es5", - "module": "UMD", + "module": "CommonJs", + "allowUmdGlobalAccess": true, "outDir": "./", "importHelpers": false, "noEmitHelpers": false, - "lib": ["es5"] + "lib": ["es5", "DOM"] }, "include": [ "jsonrpc.ts" @@ -14,6 +15,7 @@ "exclude": [ "node_modules", "build", + "target", "test" ] } diff --git a/tsconfig.json b/tsconfig.json index bfe602b..f6958eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,21 +2,21 @@ "compileOnSave": false, "compilerOptions": { "target": "es2018", - "module": "commonjs", "moduleResolution": "node", "outDir": "./build", "typeRoots": [ "node_modules/@types" ], "lib": [ - "es2018" + "es2018", + "dom" ], "sourceMap": true, "declaration": true, - "importHelpers": true, + "importHelpers": false, + "noEmitHelpers": false, "newLine": "LF", "skipLibCheck": true, - "noEmitHelpers": true, "noImplicitReturns": false, "strict": true, "strictNullChecks": true, @@ -31,6 +31,7 @@ "exclude": [ "node_modules", "build", + "target", "test" ] }