sindresorhus / meow

🐈 CLI app helper
MIT License
3.53k stars 150 forks source link

Cannot read package information if using meow in ESM #176

Closed LitoMore closed 3 years ago

LitoMore commented 3 years ago

meow is using module.parent.filename as parentDir to read package info:

const parentDir = path.dirname(module.parent && module.parent.filename ? module.parent.filename : '.');

But in ESM, we cannot use __filename anymore.

Do you have any plan move this package to ESM?

@sindresorhus And I wonder how you would solve this problem?

LitoMore commented 3 years ago

We can resolve #125 at the same time.

sindresorhus commented 3 years ago

Yeah. PR welcome to move meow to ESM.

See:

LitoMore commented 3 years ago

I'm going to use this code below to instead CommonJS module's __filename:

import {fileURLToPath} from 'url';

const __filename = fileURLToPath(import.meta.url);
sindresorhus commented 3 years ago

This is not fixed until we add back support for the package.json reading.

LitoMore commented 3 years ago

I tested this issue on the main branch and looks good.

Is there any edge case that will cause the read package issue?

sindresorhus commented 3 years ago

I'm not sure what you're asking. You removed the old workaround for clearing the require cache. We now need to allow the user to pass in import.meta somehow to be able to know the meow consumer's CWD.

LitoMore commented 3 years ago

Oh, I see. Let me continue on this work.