Skip to content

Commit

Permalink
Apply airbnb#17
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarBarrett authored and nrako committed Oct 9, 2020
1 parent 45015a4 commit dc74751
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default declare(({
if (typeof importPath !== 'string') {
throw new TypeError('`applyPlugin` `importPath` must be a string');
}
const { ignorePattern, caseSensitive, filename: providedFilename } = state.opts;
const { ignorePattern, caseSensitive, filename: providedFilename, root, alias } = state.opts;
const { file, filename } = state;
if (ignorePattern) {
// Only set the ignoreRegex once:
Expand All @@ -61,10 +61,20 @@ export default declare(({
// This plugin only applies for SVGs:
if (extname(importPath) === '.svg') {
const iconPath = filename || providedFilename;
const svgPath = resolve.sync(importPath, { basedir: dirname(iconPath) });
if (caseSensitive && !fileExistsWithCaseSync(svgPath)) {
throw new Error(`File path didn't match case of file on disk: ${svgPath}`);
const aliasMatch = alias[importPath.split('/')[0]];
let svgPath;

if (aliasMatch) {
const resolveRoot = resolve(process.cwd(), root || './');
const aliasedPath = resolve(resolveRoot, aliasMatch);
svgPath = aliasedPath + importPath.replace(aliasMatch , '');
} else {
svgPath = resolve.sync(importPath, { basedir: dirname(iconPath) });
if (caseSensitive && !fileExistsWithCaseSync(svgPath)) {
throw new Error(`File path didn't match case of file on disk: ${svgPath}`);
}
}

if (!svgPath) {
throw new Error(`File path does not exist: ${importPath}`);
}
Expand Down

0 comments on commit dc74751

Please sign in to comment.