Skip to content

Add __filename and __dirname variables to JavaScript views#150

Open
Gudine wants to merge 1 commit intoblacksmithgu:masterfrom
Gudine:__filename
Open

Add __filename and __dirname variables to JavaScript views#150
Gudine wants to merge 1 commit intoblacksmithgu:masterfrom
Gudine:__filename

Conversation

@Gudine
Copy link
Contributor

@Gudine Gudine commented Oct 31, 2025

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>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant