Skip to content

Commit

Permalink
feat: make the cli work with/without prettier-eslint peer (#438)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: bump all upgradable (dev)Dependencies except pure ESM
  • Loading branch information
JounQin committed Aug 14, 2022
1 parent 58101c1 commit 39c38b5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
10 changes: 9 additions & 1 deletion package.json
Expand Up @@ -26,7 +26,16 @@
"JounQin (https://www.1stG.me) <admin@1stg.me>"
],
"license": "MIT",
"peerDependencies": {
"prettier-eslint": "*"
},
"peerDependenciesMeta": {
"prettier-eslint": {
"optional": true
}
},
"dependencies": {
"@prettier/eslint": "npm:prettier-eslint@^15.0.1",
"arrify": "^2.0.1",
"boolify": "^1.0.1",
"camelcase-keys": "^7.0.2",
Expand All @@ -42,7 +51,6 @@
"lodash.memoize": "^4.1.2",
"loglevel-colored-level-prefix": "^1.0.0",
"messageformat": "^2.3.0",
"prettier-eslint": "^15.0.1",
"rxjs": "^7.5.6",
"yargs": "^13.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/format-files.js
Expand Up @@ -5,14 +5,14 @@ import fs from 'fs';
import glob from 'glob';
import { bindNodeCallback, from, of } from 'rxjs';
import { catchError, concatAll, distinct, map, mergeMap } from 'rxjs/operators';
import format from 'prettier-eslint';
import chalk from 'chalk';
import getStdin from 'get-stdin';
import nodeIgnore from 'ignore';
import findUp from 'find-up';
import memoize from 'lodash.memoize';
import indentString from 'indent-string';
import getLogger from 'loglevel-colored-level-prefix';
import format from './prettier-eslint';
import * as messages from './messages';

const LINE_SEPERATOR_REGEX = /(\r|\n|\r\n)/;
Expand Down
2 changes: 1 addition & 1 deletion src/format-files.test.js
@@ -1,10 +1,10 @@
/* eslint no-console:0 */
import fsMock from 'fs';
import findUpMock from 'find-up';
import formatMock from 'prettier-eslint';
import globMock from 'glob';
import mockGetStdin from 'get-stdin';
import getLogger from 'loglevel-colored-level-prefix';
import formatMock from './prettier-eslint';
import formatFiles from './format-files';

jest.mock('fs');
Expand Down
17 changes: 17 additions & 0 deletions src/prettier-eslint.js
@@ -0,0 +1,17 @@
const getLogger = require('loglevel-colored-level-prefix');

const logger = getLogger({ prefix: 'prettier-eslint-cli' });

try {
// if `prettier-eslint` is installed by the user manually
module.exports = require('prettier-eslint');
} catch (err) /* istanbul ignore next */ {
logger.info('We detected that no `prettier-eslint` is installed.');
logger.info('We will use our internal fallback one instead.');
logger.info(
'You can install `prettier-eslint` as dependency to skip this message.'
);

// it is an internal dependency using `prettier-eslint` as fallback
module.exports = require('@prettier/eslint');
}
2 changes: 1 addition & 1 deletion test/tests/cli.spec.js
Expand Up @@ -24,7 +24,7 @@ test('help outputs usage information and flags', async () => {
// terminal I think)...
const stdout = await runPrettierESLintCLI('--help');
expect(stdout).toMatch(/Usage:.*?<globs>.../);
expect(stdout).toContain('Options:\n');
expect(stdout).toContain('Valid options:\n');
// just a sanity check.
// If it's ever longer than 2000 then we've probably got a problem...
// eslint-disable-next-line jest/no-conditional-in-test
Expand Down

0 comments on commit 39c38b5

Please sign in to comment.