Skip to content

Conversation

@jamesharris-garmin
Copy link
Contributor

This patch fixes #230584 by applying the recommended fix from:

https://masteringjs.io/tutorials/node/__dirname-is-not-defined

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm @bpasero could you verify this is the right way to do this now?

@Tyriar Tyriar enabled auto-merge October 15, 2024 17:53
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is:

const __dirname = path.dirname(fileURLToPath(import.meta.url));

@bpasero
Copy link
Member

bpasero commented Oct 15, 2024

But I would not call out "ESM" specifically, this is just the way of doing it now 🤔

@Tyriar Tyriar merged commit 58cab99 into microsoft:main Oct 15, 2024
@bpasero
Copy link
Member

bpasero commented Oct 15, 2024

Follow up #231427

This is really a good catch and was missed during the ESM migration. We are bitten by the fact that the node.js types declare a global __dirname :-/

Update: I think we can have a ESLint rule to disallow...

@jamesharris-garmin jamesharris-garmin deleted the fix-server-cli branch October 15, 2024 19:53
@jamesharris-garmin
Copy link
Contributor Author

Thanks everyone for the quick turn around on this.

@prasanthcakewalk
Copy link

May not be worth changing anything, but I think the import here:

import path from 'path';

is not necessary, since dirname has already been imported here:
import { dirname, extname, resolve, join } from '../../base/common/path.js';

I think the import line could be removed and
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
could just be changed to
const __dirname = dirname(url.fileURLToPath(import.meta.url));
I could be wrong though; I'm not a typescript developer.

@bpasero
Copy link
Member

bpasero commented Oct 16, 2024

Yes thanks, will address that.

NikolaRHristov pushed a commit to CodeEditorLand/Editor that referenced this pull request Oct 16, 2024
…r-cli

Fix missing __dirname in --locate-shell-integration-path
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Nov 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

4 participants