Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make --ignore relative
  • Loading branch information
blakeembrey committed Nov 27, 2019
1 parent 4b265bf commit ea6e1da
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/index.ts
Expand Up @@ -252,13 +252,8 @@ export function create (options: CreateOptions = {}): Register {
...(options.ignoreDiagnostics || [])
].map(Number)

const ignore = options.skipIgnore ? [] : (
options.ignore || ['/node_modules/']
).map(str => new RegExp(str))

// Require the TypeScript compiler and configuration.
const cwd = options.dir ? resolve(options.dir) : process.cwd()
const isScoped = options.scope ? (fileName: string) => relative(cwd, fileName).charAt(0) !== '.' : () => true
const typeCheck = options.typeCheck === true || options.transpileOnly !== true
const compiler = require.resolve(options.compiler || 'typescript', { paths: [cwd, __dirname] })
const ts: typeof _ts = require(compiler)
Expand All @@ -269,6 +264,11 @@ export function create (options: CreateOptions = {}): Register {
const configDiagnosticList = filterDiagnostics(config.errors, ignoreDiagnostics)
const outputCache = new Map<string, string>()

const isScoped = options.scope ? (relname: string) => relname.charAt(0) !== '.' : () => true
const shouldIgnore = createIgnore(options.skipIgnore ? [] : (
options.ignore || ['/node_modules/']
).map(str => new RegExp(str)))

const diagnosticHost: _ts.FormatDiagnosticsHost = {
getNewLine: () => ts.sys.newLine,
getCurrentDirectory: () => cwd,
Expand Down Expand Up @@ -462,18 +462,24 @@ export function create (options: CreateOptions = {}): Register {

let active = true
const enabled = (enabled?: boolean) => enabled === undefined ? active : (active = !!enabled)
const ignored = (fileName: string) => !active || !isScoped(fileName) || shouldIgnore(fileName, ignore)
const ignored = (fileName: string) => {
if (!active) return true
const relname = relative(cwd, fileName)
return !isScoped(relname) || shouldIgnore(relname)
}

return { ts, config, compile, getTypeInfo, ignored, enabled }
}

/**
* Check if the filename should be ignored.
*/
function shouldIgnore (filename: string, ignore: RegExp[]) {
const relname = normalizeSlashes(filename)
function createIgnore (ignore: RegExp[]) {
return (relname: string) => {
const path = normalizeSlashes(relname)

return ignore.some(x => x.test(relname))
return ignore.some(x => x.test(path))
}
}

/**
Expand Down

0 comments on commit ea6e1da

Please sign in to comment.