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

feat: make the cli work with/without prettier-eslint peer #438

Merged
merged 1 commit into from Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
JounQin marked this conversation as resolved.
Show resolved Hide resolved
}
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