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

Preproc #3390

Merged
merged 3 commits into from
Oct 31, 2019
Merged

Preproc #3390

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ async function runProcessors (preprocessors, file, content) {
file.sha = CryptoUtils.sha1(content)
}

function createPriorityPreprocessor (config, preprocessorPriority, basePath, injector) {
function createPriorityPreprocessor (config = {}, preprocessorPriority, basePath, injector) {
const emitter = injector.get('emitter')
const alreadyDisplayedErrors = {}
const instances = {}
let patterns = Object.keys(config)

function instantiatePreprocessor (name) {
if (alreadyDisplayedErrors[name]) {
Expand Down Expand Up @@ -108,25 +107,18 @@ function createPriorityPreprocessor (config, preprocessorPriority, basePath, inj

return p
}

let allPreprocessors = []
patterns.forEach((pattern) => {
allPreprocessors = _.union(allPreprocessors, config[pattern])
})
allPreprocessors.forEach(instantiatePreprocessor)
_.union.apply(_, Object.values(config)).forEach(instantiatePreprocessor)

return async function preprocess (file) {
patterns = Object.keys(config)

const buffer = await tryToRead(file.originalPath, log)
const isBinary = await isBinaryFile(buffer, buffer.length)

let preprocessorNames = []
patterns.forEach((pattern) => {
const preprocessorNames = Object.keys(config).reduce((res, pattern) => {
if (mm(file.originalPath, pattern, { dot: true })) {
preprocessorNames = _.union(preprocessorNames, config[pattern])
res = _.union(res, config[pattern])
anthony-redFox marked this conversation as resolved.
Show resolved Hide resolved
}
})
return res
}, [])

// Apply preprocessor priority.
const preprocessors = preprocessorNames
Expand Down