cleolibrary / CLEO-Redux

Experimental JavaScript runtime for GTA 3D era games/GTA IV/Bully
https://re.cleo.li
Other
214 stars 20 forks source link

inconsistent path resolution in imports and sdk commands #77

Open x87 opened 2 years ago

x87 commented 2 years ago

complex scripts could be organized in folders and subfolders. For example

- \CLEO
-- \MegaMod
--- \extra
---- addon.js
---- model.mjs
---- lib.dll
--- index.js

import statements allows usage of ./ as the current file's directory. It resolves to CLEO/MegaMod/extra/ in addon.js and to CLEO/MegaMod/ in index.js.

SDK commands allows ./ too. But it always resolves to the index.js directory, regardless of the file location.

addon.js

import './model.mjs'; // works

DynamicLibrary.Load('./lib.dll'); // does not work, `CLEO/MegaMod/lib.dll` does not exist

DynamicLibrary.Load('./extra/lib.dll'); // works
x87 commented 2 years ago

SDK command path allows CLEO\ prefix to be resolved as a path to CLEO directory. In imports there is no such logic, it resolves relative to current working directory (game root):

addon.js

import 'CLEO/MegaMod/extra/model.mjs'; // does not work if CLEO folder is not in root

DynamicLibrary.Load('CLEO/MegaMod/extra/lib.dll'); // works
x87 commented 2 years ago

Added a note in SDK docs https://re.cleo.li/docs/en/using-sdk.html#path-resolution-convention The workaround for SDK commands is to use __dirname for file path

DynamicLibrary.Load(__dirname + "\mylib.dll");