datacore icon indicating copy to clipboard operation
datacore copied to clipboard

Add `__filename` and `__dirname` variables to JavaScript views

Open Gudine opened this issue 1 month ago • 0 comments

Add __filename and __dirname variables to JavaScript views

Adds Node's __filename and __dirname variables to Datacore's JavaScript views and dc.required scripts. These new variables make relative script imports possible, by doing the following:

// util.js
return { getNumber: () => 2 };

// script1/util.js
return { getNumber: () => 1 };

// script1/main.jsx
const { getNumber } = await dc.require(dc.resolvePath("util.js", __filename));

return function View() {
  // Correctly displays "1 = 1";
  return <p>{getNumber()} = 1</p>
}

Gudine avatar Oct 31 '25 20:10 Gudine