mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 14:02:43 +08:00
refactor: use standard node resolution and use async/await instead of rxjs
This commit is contained in:
parent
7ef64dbe46
commit
bebd8b6c09
@ -5,25 +5,16 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import { resolve } from '@angular-devkit/core/node';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
Configuration as ConfigurationNS,
|
||||
Linter as LinterNS,
|
||||
} from 'tslint'; // tslint:disable-line:no-implicit-dependencies
|
||||
import * as tsLint from 'tslint'; // tslint:disable-line:no-implicit-dependencies
|
||||
import * as ts from 'typescript'; // tslint:disable-line:no-implicit-dependencies
|
||||
import { SchematicContext, TaskExecutor } from '../../src';
|
||||
import { TslintFixTaskOptions } from './options';
|
||||
|
||||
|
||||
type ConfigurationT = typeof ConfigurationNS;
|
||||
type LinterT = typeof LinterNS;
|
||||
|
||||
|
||||
function _loadConfiguration(
|
||||
Configuration: ConfigurationT,
|
||||
Configuration: typeof tsLint.Configuration,
|
||||
options: TslintFixTaskOptions,
|
||||
root: string,
|
||||
file?: string,
|
||||
@ -90,14 +81,10 @@ function _listAllFiles(root: string): string[] {
|
||||
|
||||
|
||||
export default function (): TaskExecutor<TslintFixTaskOptions> {
|
||||
return (options: TslintFixTaskOptions, context: SchematicContext) => {
|
||||
return new Observable(obs => {
|
||||
return async (options: TslintFixTaskOptions, context: SchematicContext) => {
|
||||
const root = process.cwd();
|
||||
const tslint = require(resolve('tslint', {
|
||||
basedir: root,
|
||||
checkGlobal: true,
|
||||
checkLocal: true,
|
||||
}));
|
||||
const tslint = await import('tslint'); // tslint:disable-line:no-implicit-dependencies
|
||||
|
||||
const includes = (
|
||||
Array.isArray(options.includes)
|
||||
? options.includes
|
||||
@ -109,8 +96,8 @@ export default function(): TaskExecutor<TslintFixTaskOptions> {
|
||||
: (options.files ? [options.files] : [])
|
||||
);
|
||||
|
||||
const Linter = tslint.Linter as LinterT;
|
||||
const Configuration = tslint.Configuration as ConfigurationT;
|
||||
const Linter = tslint.Linter;
|
||||
const Configuration = tslint.Configuration;
|
||||
let program: ts.Program | undefined = undefined;
|
||||
let filesToLint: string[] = files;
|
||||
|
||||
@ -118,10 +105,9 @@ export default function(): TaskExecutor<TslintFixTaskOptions> {
|
||||
const tsConfigPath = path.join(process.cwd(), options.tsConfigPath);
|
||||
|
||||
if (!fs.existsSync(tsConfigPath)) {
|
||||
obs.error(new Error('Could not find tsconfig.'));
|
||||
|
||||
return;
|
||||
throw new Error('Could not find tsconfig.');
|
||||
}
|
||||
|
||||
program = Linter.createProgram(tsConfigPath);
|
||||
filesToLint = Linter.getFileNames(program);
|
||||
}
|
||||
@ -192,11 +178,7 @@ export default function(): TaskExecutor<TslintFixTaskOptions> {
|
||||
}
|
||||
|
||||
if (!options.ignoreErrors && result.errorCount > 0) {
|
||||
obs.error(new Error('Lint errors were found.'));
|
||||
} else {
|
||||
obs.next();
|
||||
obs.complete();
|
||||
throw new Error('Lint errors were found.');
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user