From 11c34ac72cd2b817e93edd1e830ecd29f2b10f38 Mon Sep 17 00:00:00 2001 From: alekswilc Date: Mon, 24 Jun 2024 02:37:39 +0200 Subject: [PATCH] add support to node <18 --- package-lock.json | 11 +++++------ package.json | 2 +- scripts/build.js | 4 ++++ src/Payload.ts | 2 +- src/index.ts | 11 +++++++++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 097fb1d..76a6428 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "@alekswilc/ray", - "version": "1.0.28", + "version": "1.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@alekswilc/ray", - "version": "1.0.28", + "version": "1.1.2", "license": "ISC", "dependencies": { "@permafrost-dev/pretty-format": "^1.1.5", - "stacktrace-js": "^2.0.2" + "stacktrace-js": "^2.0.2", + "uuid": "^10.0.0" }, "devDependencies": { "@types/node": "^20.14.2", @@ -18,8 +19,7 @@ "dts-bundle-generator": "^9.5.1", "esbuild": "^0.21.5", "fast-glob": "^3.3.2", - "typescript": "^5.4.5", - "uuid": "^10.0.0" + "typescript": "^5.4.5" } }, "node_modules/@esbuild/aix-ppc64": { @@ -886,7 +886,6 @@ "version": "10.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", - "dev": true, "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" diff --git a/package.json b/package.json index aedd88c..a14766b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "typescript": "^5.4.5" }, "name": "@alekswilc/ray", - "version": "1.1.1", + "version": "1.1.3", "main": "./build/aleksray.cjs", "module": "./build/aleksray.mjs", "typings": "./build/aleksray.d.ts", diff --git a/scripts/build.js b/scripts/build.js index 8eaad0f..573c827 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -26,6 +26,7 @@ const _ = async () => { platform: "node", outExtension: { '.js': '.cjs', }, bundle: true, + target: [ 'node12', ], external: ['@permafrost-dev/pretty-format', 'uuid', 'stacktrace-js'] }); @@ -36,6 +37,7 @@ const _ = async () => { sourcemap: "external", platform: "node", outExtension: { '.js': '.cjs', }, + target: [ 'node12', ], bundle: true, // external: ['@permafrost-dev/pretty-format', 'p-queue', 'stacktrace-js'] }); @@ -52,6 +54,7 @@ const _ = async () => { platform: "node", outExtension: { '.js': '.mjs', }, bundle: true, + target: [ 'node12', ], external: ['@permafrost-dev/pretty-format', 'uuid', 'stacktrace-js'] }); @@ -62,6 +65,7 @@ const _ = async () => { format: "esm", sourcemap: "external", platform: "node", + target: [ 'node12', ], outExtension: { '.js': '.mjs', }, bundle: true, // external: ['@permafrost-dev/pretty-format', 'p-queue', 'stacktrace-js'] diff --git a/src/Payload.ts b/src/Payload.ts index b64017b..33bc3cc 100644 --- a/src/Payload.ts +++ b/src/Payload.ts @@ -13,7 +13,7 @@ export interface IPayload { } } -const LIB_STACK_SOURCES = () => [...(process.env.ALEKSRAY_LIB_STACK_SOURCES?.split(';') || []), '@alekswilc/ray', '@alekswilc\\ray', 'standalone-aleksray-bundle.js', 'standalone-aleksray-bundle.mjs', 'aleksray.js', 'aleksray.mjs'] +const LIB_STACK_SOURCES = () => [...(process.env.ALEKSRAY_LIB_STACK_SOURCES?.split(';') || []), '@alekswilc/ray', '@alekswilc\\ray', 'standalone-aleksray-bundle.cjs', 'standalone-aleksray-bundle.mjs', 'aleksray.cjs', 'aleksray.mjs'] export class Payload { public static create(data: Omit & Partial) { diff --git a/src/index.ts b/src/index.ts index 6b7d0ec..c348715 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,13 @@ +if (!global.fetch) { + try { + global.fetch = require('node-fetch'); + } catch (e) { + if (e instanceof Error && e.message.includes('Cannot find module')) { + throw new Error('@alekswilc/ray -> Please install node-fetch (npm i node-fetch@2) for compatibility') + } + } +} + + export { ray, Ray, IOptions } from './Ray'; export { Request, Payload, IRequest, IPayload } from './Payload'; \ No newline at end of file