From 9697730f3947b0b905b92ae5f2e10e482bedbf80 Mon Sep 17 00:00:00 2001 From: Alain Armand Date: Fri, 8 Jan 2021 23:28:52 +0100 Subject: [PATCH] adds nodejs support --- .gitignore | 3 ++- package.json | 3 +++ src/Warp/Warp_XHR.re | 12 +++++++++++- yarn.lock | 5 +++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e748d0b..df82247 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ lib *.bs.js .bsb.lock -src/Test.re \ No newline at end of file +src/Test.re +_esy/default/cache/project-b082af3cc22dec67e1d89d9154b3384d diff --git a/package.json b/package.json index 94ddb1b..9d6a2a3 100644 --- a/package.json +++ b/package.json @@ -25,5 +25,8 @@ "license": "MIT", "devDependencies": { "bs-platform": "^7.3.2" + }, + "dependencies": { + "xmlhttprequest": "^1.8.0" } } diff --git a/src/Warp/Warp_XHR.re b/src/Warp/Warp_XHR.re index 631b543..3bb7de4 100644 --- a/src/Warp/Warp_XHR.re +++ b/src/Warp/Warp_XHR.re @@ -17,9 +17,19 @@ let decodeReadyState = readyState => | 4 => Done | _ => Unknown }; +[@bs.val] external window: 'a = "window"; [@bs.new] external make: unit => t = "XMLHttpRequest"; +[@bs.new] [@bs.module "xmlhttprequest"] external makeNode: unit => t = "XMLHttpRequest"; + +let make = () => + if (Js.typeof(window) !== "undefined") { + make(); + } else { + makeNode(); + }; + [@bs.get] external readyStateExternal: t => int = "readyState"; let readyState = (xhr: t) => decodeReadyState(readyStateExternal(xhr)); @@ -209,4 +219,4 @@ external removeEventListenerWithOptions: } ) => unit = - "removeEventListener"; \ No newline at end of file + "removeEventListener"; diff --git a/yarn.lock b/yarn.lock index 5de634a..24da65c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,3 +6,8 @@ bs-platform@^7.3.2: version "7.3.2" resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-7.3.2.tgz#301f5c9b4e8cf5713cb60ca22e145e56e793affe" integrity sha512-seJL5g4anK9la4erv+B2o2sMHQCxDF6OCRl9en3hbaUos/S3JsusQ0sPp4ORsbx5eXfHLYBwPljwKXlgpXtsgQ== + +xmlhttprequest@^1.8.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" + integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=