chore: update to prettier@2
This commit is contained in:
Родитель
b0856fdbc2
Коммит
8ccbfc2125
|
@ -0,0 +1,20 @@
|
|||
module.exports = {
|
||||
ignorePatterns: ['**/*.d.ts', '**/*.test.ts', '**/*.js'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['plugin:@typescript-eslint/recommended'],
|
||||
plugins: ['header'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/interface-name-prefix': ['error', { prefixWithI: 'always' }],
|
||||
'header/header': [
|
||||
'error',
|
||||
'block',
|
||||
'---------------------------------------------------------\n * Copyright (C) Microsoft Corporation. All rights reserved.\n *--------------------------------------------------------',
|
||||
],
|
||||
},
|
||||
};
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
24
package.json
24
package.json
|
@ -9,9 +9,9 @@
|
|||
"scripts": {
|
||||
"prepare": "tsc",
|
||||
"build": "tsc",
|
||||
"fmt": "node dist/index --write \"src/**/*.ts\" && npm run test:lint -- --fix",
|
||||
"fmt": "tsc && node dist/index --write \"src/**/*.ts\" && npm run test:lint -- --fix",
|
||||
"test": "npm run test:lint && npm run test:fmt",
|
||||
"test:lint": "tslint --project tsconfig.json \"src/**/*.ts\"",
|
||||
"test:lint": "eslint \"src/**/*.ts\"",
|
||||
"test:fmt": "node dist/index \"src/**/*.ts\" --check"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -31,20 +31,22 @@
|
|||
},
|
||||
"homepage": "https://github.com/mixer/parallel-prettier#readme",
|
||||
"dependencies": {
|
||||
"chalk": "^2.4.2",
|
||||
"commander": "^2.20.0",
|
||||
"chalk": "^4.0.0",
|
||||
"commander": "^5.0.0",
|
||||
"glob-stream": "^6.1.0",
|
||||
"ora": "^3.4.0",
|
||||
"prettier": "^1.17.0",
|
||||
"rxjs": "^6.5.1"
|
||||
"ora": "^4.0.3",
|
||||
"prettier": "^2.0.4",
|
||||
"rxjs": "^6.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob-stream": "^6.1.0",
|
||||
"@types/node": "^12.0.0",
|
||||
"@types/prettier": "^1.16.3",
|
||||
"tslint": "^5.16.0",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"typescript": "^3.4.5"
|
||||
"@types/prettier": "^2.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.27.0",
|
||||
"@typescript-eslint/parser": "^2.27.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-header": "^3.0.0",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"prettier": {
|
||||
"trailingComma": "all",
|
||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -1,20 +1,23 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import * as cluster from 'cluster';
|
||||
import * as commander from 'commander';
|
||||
import { cpus } from 'os';
|
||||
import * as prettier from 'prettier';
|
||||
|
||||
const { version } = require('../package.json');
|
||||
import { version } from '../package.json';
|
||||
|
||||
function startMaster() {
|
||||
const program: any = commander
|
||||
const program = commander
|
||||
.option(
|
||||
'--check, --list-different',
|
||||
'Whether to list unformatted files, instead of writing them out',
|
||||
)
|
||||
.option('--write', 'Whether to write files to the output')
|
||||
.option('--concurrency [value]', 'Maximum concurrency', cpus().length)
|
||||
.option('--concurrency [value]', 'Maximum concurrency', String(cpus().length))
|
||||
.option('--quiet, -q', 'If set, pprettier will not output progress')
|
||||
.version(`@mixer/parallel-prettier version ${version} / prettier version ${prettier.version}`)
|
||||
.parse(process.argv);
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import * as globStream from 'glob-stream';
|
||||
import { Observable } from 'rxjs';
|
||||
import { bufferCount, mergeMap } from 'rxjs/operators';
|
||||
|
@ -9,10 +13,10 @@ import { WorkerPool } from './worker-pool';
|
|||
const bufferSize = 50;
|
||||
|
||||
function runGlobs(files: string[]) {
|
||||
return new Observable<string>(subscriber => {
|
||||
return new Observable<string>((subscriber) => {
|
||||
const stream = globStream(files);
|
||||
stream.addListener('data', data => subscriber.next(data));
|
||||
stream.addListener('error', err => subscriber.error(err));
|
||||
stream.addListener('data', (data) => subscriber.next(data));
|
||||
stream.addListener('error', (err) => subscriber.error(err));
|
||||
stream.addListener('finish', () => subscriber.complete());
|
||||
stream.resume();
|
||||
});
|
||||
|
@ -25,11 +29,11 @@ export function spawnWorkers(options: IOptions) {
|
|||
runGlobs(options.files)
|
||||
.pipe(
|
||||
bufferCount(bufferSize),
|
||||
mergeMap(files => pool.format(files)),
|
||||
mergeMap((files) => pool.format(files)),
|
||||
)
|
||||
.subscribe(
|
||||
result => progress.update(result),
|
||||
err => {
|
||||
(result) => progress.update(result),
|
||||
(err) => {
|
||||
throw err;
|
||||
},
|
||||
() => {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import * as ora from 'ora';
|
||||
import { relative } from 'path';
|
||||
import { IFormatResults } from './protocol';
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* MessageType delimits the kind of message sent in the formatter IPC.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import * as cluster from 'cluster';
|
||||
import { fromEvent, Observable } from 'rxjs';
|
||||
import { filter, map, take, tap } from 'rxjs/operators';
|
||||
|
@ -15,7 +19,7 @@ import {
|
|||
*/
|
||||
export class WorkerPool {
|
||||
private readonly workers: Array<{ worker: cluster.Worker; active: number }> = [];
|
||||
private workIdCounter: number = 0;
|
||||
private workIdCounter = 0;
|
||||
|
||||
constructor(private readonly options: IOptions) {}
|
||||
|
||||
|
@ -35,7 +39,7 @@ export class WorkerPool {
|
|||
|
||||
return fromEvent<[WorkerMessage]>(target.worker, 'message').pipe(
|
||||
map(([m]) => m),
|
||||
filter(m => m.id === id),
|
||||
filter((m) => m.id === id),
|
||||
take(1),
|
||||
tap(() => {
|
||||
target.active--;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import { readFile, writeFile } from 'fs';
|
||||
import * as prettier from 'prettier';
|
||||
import { combineLatest, Observable, of, Subject } from 'rxjs';
|
||||
|
@ -33,7 +37,7 @@ function runFormatting(
|
|||
};
|
||||
|
||||
return of(...files.files).pipe(
|
||||
mergeMap(async file => {
|
||||
mergeMap(async (file) => {
|
||||
const contents = await readFileAsync(file.path, 'utf-8');
|
||||
const formatted = prettier.format(contents, {
|
||||
...(await prettier.resolveConfig(file.path)),
|
||||
|
@ -75,8 +79,9 @@ export function startWorker() {
|
|||
combineLatest(settings, files)
|
||||
.pipe(mergeMap(([s, f]) => runFormatting(s, f)))
|
||||
.subscribe(
|
||||
message => process.send!(message),
|
||||
err => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
(message) => process.send!(message),
|
||||
(err) => {
|
||||
throw err;
|
||||
},
|
||||
);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"noUnusedParameters": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"newLine": "LF",
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/tslint",
|
||||
"extends": ["tslint:recommended", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"no-var-requires": false
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче