Skip to content

Commit

Permalink
fix: dynamically load prettier (#19948)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
viceice and rarkins committed Jan 20, 2023
1 parent 5bf6eab commit 813a8bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/expose.cjs
Expand Up @@ -14,4 +14,12 @@ function re2() {
return require('re2');
}

module.exports = { dirname: __dirname, re2, pkg };
/**
* return's prettier
* @returns {typeof import('prettier')}
*/
function prettier() {
return require('prettier');
}

module.exports = { dirname: __dirname, re2, pkg, prettier };
@@ -1,8 +1,9 @@
import detectIndent from 'detect-indent';
import JSON5 from 'json5';
import prettier, { BuiltInParserName } from 'prettier';
import type { BuiltInParserName } from 'prettier';
import upath from 'upath';
import { migrateConfig } from '../../../../config/migration';
import { prettier } from '../../../../expose.cjs';
import { logger } from '../../../../logger';
import { readLocalFile } from '../../../../util/fs';
import { getFileList } from '../../../../util/git';
Expand Down Expand Up @@ -68,7 +69,7 @@ export async function applyPrettierFormatting(
useTabs: indent?.type === 'tab',
};

return prettier.format(content, options);
return prettier().format(content, options);
} finally {
logger.trace('applyPrettierFormatting - END');
}
Expand Down

0 comments on commit 813a8bc

Please sign in to comment.