@bigcommerce/stencil-cli 7.1.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
1
  require('colors');
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
+ const cheerio = require('cheerio');
4
5
 
5
6
  const cssCompiler = require('./css/compile');
6
7
  const { recursiveReadDir } = require('./utils/fsUtils');
7
8
 
8
9
  /* eslint-disable no-useless-escape */
9
- const STYLESHEET_REGEXP = /{{\s*stylesheet\s*([\/a-zA-Z'"\.-]+)\s*}}/i;
10
+ const STYLESHEET_REGEXP = /{{\s*stylesheet\s*([\/a-zA-Z'"\.-]+)\s*}}/gi;
10
11
 
11
12
  class ScssValidator {
12
13
  /**
@@ -36,7 +37,6 @@ class ScssValidator {
36
37
  );
37
38
  } catch (e) {
38
39
  const message = this.parseStencilStylesError(e);
39
- console.log(e.file);
40
40
  throw new Error(
41
41
  `${message} while compiling css files from "${stylesPath}/${file}".`.red,
42
42
  );
@@ -58,15 +58,18 @@ class ScssValidator {
58
58
  const cssFiles = [];
59
59
  for await (const file of files) {
60
60
  const content = await fs.promises.readFile(file, { encoding: 'utf-8' });
61
- const result = content.match(STYLESHEET_REGEXP);
61
+ const result = content.matchAll(STYLESHEET_REGEXP);
62
62
  if (result) {
63
- // remove quotes
64
- const fileName = result[1].slice(1, -1);
65
-
66
- const filePath = this.tryToResolveCssFileLocation(fileName, result);
67
- if (!cssFiles.includes(filePath)) {
68
- // check if file exist
69
- cssFiles.push(filePath);
63
+ for (const item of result) {
64
+ // remove quotes
65
+ const filePath = item[1].slice(1, -1);
66
+ const fileName = this.tryToResolveCssFileLocation(filePath);
67
+ if (
68
+ !this.isStyleSheetAComment(content, filePath) &&
69
+ !cssFiles.includes(fileName)
70
+ ) {
71
+ cssFiles.push(fileName);
72
+ }
70
73
  }
71
74
  }
72
75
  }
@@ -74,28 +77,46 @@ class ScssValidator {
74
77
  return cssFiles;
75
78
  }
76
79
 
80
+ isStyleSheetAComment(content, cssFilePath) {
81
+ const $ = cheerio.load(content);
82
+ const comments = $('*')
83
+ .contents()
84
+ .filter(function () {
85
+ return this.nodeType === 8;
86
+ });
87
+ for (const comment of comments) {
88
+ const { data } = comment;
89
+ if (data && data.includes('stylesheet') && data.includes(cssFilePath)) {
90
+ return true;
91
+ }
92
+ }
93
+
94
+ return false;
95
+ }
96
+
77
97
  // returns relative path starting from root scss/css folder
78
- tryToResolveCssFileLocation(fileName, result) {
98
+ tryToResolveCssFileLocation(filePath) {
79
99
  const possibleLocations = [
80
- fileName,
81
- fileName.replace('/css/', '/scss/'),
82
- fileName.replace('/scss/', '/css/'),
83
- fileName.replace('/css/', '/scss/').replace('.css', '.scss'),
84
- fileName.replace('/scss/', '/css/').replace('.scss', '.css'),
100
+ filePath,
101
+ filePath.replace('/css/', '/scss/'),
102
+ filePath.replace('/scss/', '/css/'),
103
+ filePath.replace('/css/', '/scss/').replace('.css', '.scss'),
104
+ filePath.replace('/scss/', '/css/').replace('.scss', '.css'),
85
105
  ];
86
106
 
87
107
  for (const location of possibleLocations) {
88
- const filePath = path.join(this.themePath, location);
89
- if (fs.existsSync(filePath)) {
108
+ const fullFilePath = path.join(this.themePath, location);
109
+ if (fs.existsSync(fullFilePath)) {
90
110
  if (!this.isRootCssFile(location)) {
91
111
  return this.getCssFileWithoutRootFolder(location);
92
112
  }
93
- const fileParts = path.parse(filePath);
113
+ const fileParts = path.parse(fullFilePath);
94
114
  return fileParts.name;
95
115
  }
96
116
  }
97
117
 
98
- throw new Error(`Couldn't find file for this statement: ${result[0]}`.red);
118
+ console.log(`Couldn't validate scss compilation for this file path: ${filePath}`.yellow);
119
+ return null;
99
120
  }
100
121
 
101
122
  // root folders are /assets/css /assets/scss
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "CLI tool to run BigCommerce Stores locally for theme development.",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -61,7 +61,7 @@
61
61
  "async": "^3.2.3",
62
62
  "axios": "^0.27.2",
63
63
  "browser-sync": "^2.27.9",
64
- "cheerio": "^1.0.0-rc.10",
64
+ "cheerio": "^1.0.0-rc.12",
65
65
  "colors": "1.4.0",
66
66
  "commander": "^6.1.0",
67
67
  "confidence": "^5.0.1",