Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add chalk@^4 explicitly #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EltonChou
Copy link

chalk V5

The compiled code will use require().
It will throw error if user installed chalk@^5.

@lukasgeiter
Copy link
Owner

Thanks for your PR. The only reason why I'm even using require() is that I wanted chalk to be an optional dependency.

@EltonChou
Copy link
Author

EltonChou commented Jan 12, 2025

Understand your purpose and it works properly if user installed chalk@^4.

Here is my test context.

Runtime: Node.js v22.12.0

package.json

{
  "name": "gettext-test",
  "packageManager": "[email protected]",
  "dependencies": {
    "chalk": "^5.4.1",
    "gettext-extractor": "^3.8.0"
  }
}

main.mjs (same result when using require() and .cjs)

import { GettextExtractor, JsExtractors } from 'gettext-extractor'

const extractor = new GettextExtractor()

extractor
  .createJsParser([
    JsExtractors.callExpression(['_', 'getText'], {
      arguments: {
        text: 0,
        context: 1,
      },
   })])
  .parseString('')

extractor.printStats()

Error message

node_modules/.store/gettext-extractor-npm-3.8.0-3b82f4373c/package/dist/utils/output.js:11
        return chalk ? chalk.green(value) : value;
                             ^

TypeError: chalk.green is not a function

@lukasgeiter
Copy link
Owner

Ideally we would change the import code that it works with v5 as well.

If that's not possible, we would have to add it as a dependency in package.json. But then we might as well replace the require() with a regular import, making the code compatible with v5.

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.

2 participants