Skip to content

Commit

Permalink
refactor(nestedpatterns): trigger warning message only after checking…
Browse files Browse the repository at this point in the history
… for whether it's actually a pattern file (#1311)

* refactor(nestedpatterns): show nested pattern warning only for pattern files #1309

* refactor(nestedpatterns): show nested pattern warning only for pattern files #1309

…iles by moving the pattern test before the warning message #1309
  • Loading branch information
mfranzke authored Apr 17, 2021
1 parent 437c96e commit b908c2f
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/core/src/lib/loadPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ let fs = require('fs-extra'); //eslint-disable-line prefer-const
// loads a pattern from disk, creates a Pattern object from it and
// all its associated files, and records it in patternlab.patterns[]
module.exports = function(relPath, patternlab) {
const fileObject = path.parse(relPath);

//extract some information
const filename = fileObject.base;
const ext = fileObject.ext;
const patternsPath = patternlab.config.paths.source.patterns;

// skip non-pattern files
if (!patternEngines.isPatternFile(filename, patternlab)) {
return null;
}

// Determine patterns nested too deep and show a warning
const relativeDepth = (relPath.match(/\w(?=\\)|\w(?=\/)/g) || []).length;
if (relativeDepth > 3) {
logger.warning('');
Expand Down Expand Up @@ -51,18 +64,6 @@ module.exports = function(relPath, patternlab) {
logger.warning('');
}

const fileObject = path.parse(relPath);

//extract some information
const filename = fileObject.base;
const ext = fileObject.ext;
const patternsPath = patternlab.config.paths.source.patterns;

// skip non-pattern files
if (!patternEngines.isPatternFile(filename, patternlab)) {
return null;
}

//make a new Pattern Object
const currentPattern = new Pattern(relPath, null, patternlab);

Expand Down

0 comments on commit b908c2f

Please sign in to comment.