Skip to content

Commit ea6e1da

Browse files
committedNov 27, 2019
Make --ignore relative
1 parent 4b265bf commit ea6e1da

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
 

‎src/index.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,8 @@ export function create (options: CreateOptions = {}): Register {
252252
...(options.ignoreDiagnostics || [])
253253
].map(Number)
254254

255-
const ignore = options.skipIgnore ? [] : (
256-
options.ignore || ['/node_modules/']
257-
).map(str => new RegExp(str))
258-
259255
// Require the TypeScript compiler and configuration.
260256
const cwd = options.dir ? resolve(options.dir) : process.cwd()
261-
const isScoped = options.scope ? (fileName: string) => relative(cwd, fileName).charAt(0) !== '.' : () => true
262257
const typeCheck = options.typeCheck === true || options.transpileOnly !== true
263258
const compiler = require.resolve(options.compiler || 'typescript', { paths: [cwd, __dirname] })
264259
const ts: typeof _ts = require(compiler)
@@ -269,6 +264,11 @@ export function create (options: CreateOptions = {}): Register {
269264
const configDiagnosticList = filterDiagnostics(config.errors, ignoreDiagnostics)
270265
const outputCache = new Map<string, string>()
271266

267+
const isScoped = options.scope ? (relname: string) => relname.charAt(0) !== '.' : () => true
268+
const shouldIgnore = createIgnore(options.skipIgnore ? [] : (
269+
options.ignore || ['/node_modules/']
270+
).map(str => new RegExp(str)))
271+
272272
const diagnosticHost: _ts.FormatDiagnosticsHost = {
273273
getNewLine: () => ts.sys.newLine,
274274
getCurrentDirectory: () => cwd,
@@ -462,18 +462,24 @@ export function create (options: CreateOptions = {}): Register {
462462

463463
let active = true
464464
const enabled = (enabled?: boolean) => enabled === undefined ? active : (active = !!enabled)
465-
const ignored = (fileName: string) => !active || !isScoped(fileName) || shouldIgnore(fileName, ignore)
465+
const ignored = (fileName: string) => {
466+
if (!active) return true
467+
const relname = relative(cwd, fileName)
468+
return !isScoped(relname) || shouldIgnore(relname)
469+
}
466470

467471
return { ts, config, compile, getTypeInfo, ignored, enabled }
468472
}
469473

470474
/**
471475
* Check if the filename should be ignored.
472476
*/
473-
function shouldIgnore (filename: string, ignore: RegExp[]) {
474-
const relname = normalizeSlashes(filename)
477+
function createIgnore (ignore: RegExp[]) {
478+
return (relname: string) => {
479+
const path = normalizeSlashes(relname)
475480

476-
return ignore.some(x => x.test(relname))
481+
return ignore.some(x => x.test(path))
482+
}
477483
}
478484

479485
/**

0 commit comments

Comments
 (0)
Please sign in to comment.