Skip to content

Commit

Permalink
fix: find babel-loader on Windows, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed May 28, 2020
1 parent 811bcdd commit e5f0654
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/clean-for-cypress.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
const debug = require('debug')('find-webpack')
const path = require('path')

// note: modifies the argument object in place
const addCypressToEslintRules = (webpackOptions) => {
Expand Down Expand Up @@ -34,6 +35,18 @@ const addCypressToEslintRules = (webpackOptions) => {
}
}

/**
* Returns true if the provided loader path includes "babel-loader".
* Uses current OS path separator to split the loader path correctly.
*/
const isBabelLoader = (loaderPath) => {
if (!loaderPath) {
return false
}
const loaderPathParts = loaderPath.split(path.sep)
return loaderPathParts.some((pathPart) => pathPart === 'babel-loader')
}

const findBabelRule = (webpackOptions) => {
if (!webpackOptions) {
return
Expand All @@ -57,7 +70,7 @@ const findBabelRule = (webpackOptions) => {
oneOfRule.oneOf.forEach((rule) => debug('rule %o', rule))

const babelRule = oneOfRule.oneOf.find(
(rule) => rule.loader && rule.loader.includes('/babel-loader/'),
(rule) => rule.loader && isBabelLoader(rule.loader),
)
return babelRule
}
Expand Down

0 comments on commit e5f0654

Please sign in to comment.