Skip to content

Makes js-lint invoke bundled prettier cli rather than target repo's prettier #21

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

Conversation

CDeltakai
Copy link
Contributor

@CDeltakai CDeltakai commented May 8, 2025

Description

This PR replaces the current way js-lint invokes prettier by invoking its local version rather than trying to look for prettier on the target repo's PATH

Issues Fixed

Tasks

  • 1. Replace the way prettier is currently invoked by making it rely on local dependency first before trying to fallback on the target repo's PATH.

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

…invoke local prettier instead of repo prettier
Copy link

linear bot commented May 8, 2025

ENG-617

@CDeltakai CDeltakai self-assigned this May 8, 2025
@CDeltakai CDeltakai merged commit d01f8ad into staging May 9, 2025
5 checks passed
Comment on lines +141 to +145
const require = createRequire(import.meta.url);
let prettierBin: string | null = null;
try {
childProcess.execFileSync('prettier', prettierArgs, {
stdio: 'inherit',
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32',
cwd: process.cwd(),
});
// Resolves to @matrixai/lint/node_modules/prettier/bin/prettier.cjs
prettierBin = require.resolve('prettier/bin/prettier.cjs');
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use createRequire this is hack to allow for synchronous dynamic importing of code. If you need to resolve a path to an absolute use import.meta.url to get the current directory and use path.resolve to resolve that to an absolute path.

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

Successfully merging this pull request may close these issues.

Make js-lint self-contained by invoking the bundled Prettier CLI
2 participants