AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
6.96k stars 651 forks source link

Incompatibility of utils.isNode Function with signal-exit in AlaSQL #1889

Closed Warfront1 closed 3 months ago

Warfront1 commented 4 months ago

An issue has been identified where the utils.isNode function in AlaSQL does not function as expected when used in conjunction with signal-exit.

The issue is in the way that AlaSQL determines if it is running on Node [1][2][3] depends on utils.global.process.reallyExit being untampered with. It would appear that signal-exit modifies exit and/or reallyExit to the extent that the utils.isNode returns false. It is highly likely that any other dependency working around/with exit/reallyExit will have a problem with utils.isNode. I have only isolated this problem with signal-exit, but I would image that there are many other incompatible dependencies.

Here is a complete MRE Dockerfile.

FROM node:16
WORKDIR /test
RUN npm init -y
RUN npm install alasql@4.2.7 signal-exit@3.0.7
# Create the Node.js script inline
RUN echo "const onExit = require('signal-exit');\n\
onExit(() => console.log('exit'));\n\
const alasql = require('alasql');\n\
const utils = alasql.utils;\n\
console.log('The current value of utils.isNode is: ', utils.isNode);\n\
" > utilsNodeCheck.js
# Run the Node.js script
CMD ["node", "utilsNodeCheck.js"]

As such, any conditional logic based upon utils.isNode is likely to have incorrect behavior. This issue boils up to problems such as the inability to import files on your local file system likely including CSV, JSON, TAB, IndexedDB, LocalStorage, and SQLite files. The error message in such a case would typically be the following: TypeError: Only absolute URLs are supported

mathiasrw commented 4 months ago

Do you know any better way to detect node?

vishal6557 commented 3 months ago

@mathiasrw @Warfront1 I have created the PR; please have a look, and any feedback is appreciated.