@bigcommerce/stencil-cli 3.9.2 → 3.11.0

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ### Draft
2
+
3
+ ### 3.11.0 (2022-03-10)
4
+
5
+ - feat: strf-9440 Stencil Bundle: fail on scss failure compilation ([884](https://github.com/bigcommerce/stencil-cli/pull/884))
6
+
7
+ ### 3.10.1 (2022-02-24)
8
+
9
+ - fix: when there's no regions on the page ([878](https://github.com/bigcommerce/stencil-cli/pull/878))
10
+ - fix: STRF-9667 Storefront fallback logic works incorrectly on store with Stencil CLI ([877](https://github.com/bigcommerce/stencil-cli/pull/877))
11
+
12
+ ### 3.10.0 (2022-02-08)
13
+
14
+ - fix(storefront): bctheme-1000 handle regular css in stencil ([845](https://github.com/bigcommerce/stencil-cli/pull/845))
15
+ - chore: bump paper to 3.0.0 ([868](https://github.com/bigcommerce/stencil-cli/pull/868))
16
+
1
17
  ### 3.9.2 (2022-01-31)
2
18
 
3
19
  - chore: bump paper to latest ([863](https://github.com/bigcommerce/stencil-cli/pull/863))
@@ -14,6 +14,7 @@ const ValidatorSchemaTranslations = require('./validator/schema-translations');
14
14
  const privateThemeConfigValidationSchema = require('./schemas/privateThemeConfig.json');
15
15
  const themeConfigValidationSchema = require('./schemas/themeConfig.json');
16
16
  const themeValidationSchema = require('./schemas/themeSchema.json');
17
+ const cssCompiler = require('./css/compile');
17
18
 
18
19
  const VALID_IMAGE_TYPES = ['.jpg', '.jpeg', '.png', '.gif'];
19
20
  const WIDTH_COMPOSED = 600;
@@ -47,6 +48,7 @@ class BundleValidator {
47
48
  this._validateThemeSchema.bind(this),
48
49
  this._validateSchemaTranslations.bind(this),
49
50
  this._validateTemplatesFrontmatter.bind(this),
51
+ this._validateCssFiles.bind(this),
50
52
  ];
51
53
 
52
54
  if (!this.isPrivate) {
@@ -402,6 +404,43 @@ class BundleValidator {
402
404
  return true;
403
405
  }
404
406
 
407
+ async _validateCssFiles() {
408
+ const assetsPath = path.join(this.themePath, 'assets');
409
+ const stylesPath = path.join(this.themePath, 'assets/scss');
410
+ const rawConfig = await this.themeConfig.getRawConfig();
411
+ const compiler = rawConfig.css_compiler;
412
+
413
+ let cssFiles;
414
+ try {
415
+ const files = await fs.promises.readdir(stylesPath);
416
+ cssFiles = files.filter((file) => {
417
+ return file.slice(-(compiler.length + 1)) === `.${compiler}`;
418
+ });
419
+ } catch (e) {
420
+ throw new Error(`Error: ${e.message}, while reading files from "${stylesPath}".`.red);
421
+ }
422
+
423
+ for (const file of cssFiles) {
424
+ try {
425
+ /* eslint-disable-next-line no-await-in-loop */
426
+ await cssCompiler.compile(rawConfig, assetsPath, file);
427
+ } catch (e) {
428
+ const message = this.parseStencilStylesError(e);
429
+ throw new Error(
430
+ `${message} while compiling css files from "${stylesPath}/${file}".`.red,
431
+ );
432
+ }
433
+ }
434
+ }
435
+
436
+ parseStencilStylesError(e) {
437
+ if (e.formatted) {
438
+ return `${e.formatted.replace('Error: ', '')}: `;
439
+ }
440
+
441
+ return e.message;
442
+ }
443
+
405
444
  validateTrailingSymbols(data) {
406
445
  if (_.isObject(data)) {
407
446
  return _.every(data, (value) => this.validateTrailingSymbols(value));
@@ -31,6 +31,9 @@ async function getRenderedRegionsByPageType({ accessToken, storeUrl, pageType })
31
31
  }),
32
32
  });
33
33
 
34
+ if (!response.data.data) {
35
+ return { renderedRegions: [] };
36
+ }
34
37
  const {
35
38
  site: {
36
39
  content: {
@@ -75,6 +78,9 @@ async function getRenderedRegionsByPageTypeAndEntityId({
75
78
  }),
76
79
  });
77
80
 
81
+ if (!response.data.data) {
82
+ return { renderedRegions: [] };
83
+ }
78
84
  const {
79
85
  site: {
80
86
  content: {
@@ -0,0 +1,42 @@
1
+ const path = require('path');
2
+ const StencilStyles = require('@bigcommerce/stencil-styles');
3
+ const { promisify } = require('util');
4
+
5
+ const cssAssembler = require('../css-assembler');
6
+
7
+ const SASS_ENGINE_NAME = 'node-sass-fork';
8
+
9
+ const compile = async (configuration, themeAssetsPath, fileName) => {
10
+ const fileParts = path.parse(fileName);
11
+ const ext = configuration.css_compiler === 'css' ? configuration.css_compiler : 'scss';
12
+ const pathToFile = path.join(fileParts.dir, `${fileParts.name}.${ext}`);
13
+ const basePath = path.join(themeAssetsPath, `${ext}`);
14
+
15
+ let files;
16
+ try {
17
+ files = await promisify(cssAssembler.assemble)(pathToFile, basePath, `${ext}`, {});
18
+ } catch (err) {
19
+ console.error(err);
20
+ throw err;
21
+ }
22
+
23
+ const params = {
24
+ data: files[pathToFile],
25
+ files,
26
+ dest: path.join('/assets/css', fileName),
27
+ themeSettings: configuration.settings,
28
+ sourceMap: true,
29
+ autoprefixerOptions: {
30
+ cascade: configuration.autoprefixer_cascade,
31
+ browsers: configuration.autoprefixer_browsers,
32
+ },
33
+ };
34
+ const stencilStyles = new StencilStyles(console);
35
+ stencilStyles.activateEngine(SASS_ENGINE_NAME);
36
+
37
+ return stencilStyles.compileCss('scss', params);
38
+ };
39
+
40
+ module.exports = {
41
+ compile,
42
+ };
@@ -110,7 +110,12 @@ class Bundle {
110
110
  bundle: true,
111
111
  };
112
112
  return (callback) => {
113
- const basePath = path.join(this.themePath, 'assets', compiler);
113
+ let basePath;
114
+ if (compiler === 'css') {
115
+ basePath = path.join(this.themePath, 'assets/dist', compiler);
116
+ } else {
117
+ basePath = path.join(this.themePath, 'assets', compiler);
118
+ }
114
119
 
115
120
  console.log('%s Parsing Started...', compiler.toUpperCase());
116
121
  fs.readdir(basePath, (err, files) => {
@@ -395,7 +400,12 @@ class Bundle {
395
400
  case 'css':
396
401
  // Create the parsed tree files
397
402
  for (const [filename, data] of Object.entries(result)) {
398
- archiveJsonFile(data, `parsed/scss/${filename}.json`);
403
+ const ext =
404
+ this.configuration.css_compiler === 'css'
405
+ ? this.configuration.css_compiler
406
+ : 'scss';
407
+
408
+ archiveJsonFile(data, `parsed/${ext}/${filename}.json`);
399
409
  }
400
410
  break;
401
411
 
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "3.9.2",
3
+ "version": "3.11.0",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -537,9 +537,9 @@
537
537
  }
538
538
  },
539
539
  "@bigcommerce/stencil-paper": {
540
- "version": "3.0.0-rc.54",
541
- "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-paper/-/stencil-paper-3.0.0-rc.54.tgz",
542
- "integrity": "sha512-vCjVW7zBrsRu7CypgHs3WHoRGHvKXFTn3N8TJ3ZCaDbOuZJbPKE/+cr5M9Yl+OOglAQ5LCVwjPG7cn5HUg5OvA==",
540
+ "version": "3.0.0",
541
+ "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-paper/-/stencil-paper-3.0.0.tgz",
542
+ "integrity": "sha512-+8Zyln2L7yvoFabDzgXgSE+7it01Q5UZml+pq70qrx9GtsX+leIhdY01RoziDnES1I12qIx+bPUX+vM7oD1NZg==",
543
543
  "requires": {
544
544
  "@bigcommerce/stencil-paper-handlebars": "4.5.1",
545
545
  "accept-language-parser": "~1.4.1",
@@ -561,11 +561,11 @@
561
561
  }
562
562
  },
563
563
  "@bigcommerce/stencil-styles": {
564
- "version": "2.1.1",
565
- "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-styles/-/stencil-styles-2.1.1.tgz",
566
- "integrity": "sha512-6QwnLoqIUtLOAodUEH9O8hWin1dcHbziwqZFH7JQQrTNaLmi9/Z3Xy/YMIotSgK3ZHgeJcvIS+JrOFSOuhvbUg==",
564
+ "version": "2.1.2",
565
+ "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-styles/-/stencil-styles-2.1.2.tgz",
566
+ "integrity": "sha512-foXvMzWkn57N3HRQZKVb6Mz9eKloONJn7GsUXJPy5kb1F9wySfHon68TpYQfsJpbnkGjx14DXFQERrFB/+w2oQ==",
567
567
  "requires": {
568
- "@bigcommerce/node-sass": "https://github.com/bigcommerce-labs/node-sass.git#v3.5.1",
568
+ "@bigcommerce/node-sass": "git+https://git@github.com/bigcommerce-labs/node-sass.git#v3.5.1",
569
569
  "autoprefixer": "^6.7.3",
570
570
  "fibers": "^5.0.0",
571
571
  "lodash": "4.17.19",
@@ -575,8 +575,8 @@
575
575
  },
576
576
  "dependencies": {
577
577
  "@bigcommerce/node-sass": {
578
- "version": "https://github.com/bigcommerce-labs/node-sass.git#6d170210301f4b64c6b347a5b95c2c1ec57bd5ef",
579
- "from": "https://github.com/bigcommerce-labs/node-sass.git#v3.5.1",
578
+ "version": "git+https://git@github.com/bigcommerce-labs/node-sass.git#6d170210301f4b64c6b347a5b95c2c1ec57bd5ef",
579
+ "from": "git+https://git@github.com/bigcommerce-labs/node-sass.git#v3.5.1",
580
580
  "requires": {
581
581
  "async-foreach": "^0.1.3",
582
582
  "chalk": "^1.1.1",
@@ -3491,9 +3491,9 @@
3491
3491
  }
3492
3492
  },
3493
3493
  "caniuse-db": {
3494
- "version": "1.0.30001298",
3495
- "resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30001298.tgz",
3496
- "integrity": "sha512-bvIv7eUWHCWECqpyH7l76nigy9wjQITsqctAvREMGr4uVc19A2ssLXaNLPw6Nu33FaEeWAwPpWihpSY4v2SCKA=="
3494
+ "version": "1.0.30001314",
3495
+ "resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30001314.tgz",
3496
+ "integrity": "sha512-HFxfq3iFLkYedDSOYnBfdqIUVPDr9yNhtz+6rrXpzcSDEEROOqhFKlNA3hpOhwjyZCfz3GzSoE0pjvjOOPCp7A=="
3497
3497
  },
3498
3498
  "caniuse-lite": {
3499
3499
  "version": "1.0.30001261",
@@ -6436,9 +6436,9 @@
6436
6436
  }
6437
6437
  },
6438
6438
  "fibers": {
6439
- "version": "5.0.0",
6440
- "resolved": "https://registry.npmjs.org/fibers/-/fibers-5.0.0.tgz",
6441
- "integrity": "sha512-UpGv/YAZp7mhKHxDvC1tColrroGRX90sSvh8RMZV9leo+e5+EkRVgCEZPlmXeo3BUNQTZxUaVdLskq1Q2FyCPg==",
6439
+ "version": "5.0.1",
6440
+ "resolved": "https://registry.npmjs.org/fibers/-/fibers-5.0.1.tgz",
6441
+ "integrity": "sha512-VMC7Frt87Oo0AOJ6EcPFbi+tZmkQ4tD85aatwyWL6I9cYMJmm2e+pXUJsfGZ36U7MffXtjou2XIiWJMtHriErw==",
6442
6442
  "requires": {
6443
6443
  "detect-libc": "^1.0.3"
6444
6444
  }
@@ -13681,9 +13681,9 @@
13681
13681
  }
13682
13682
  },
13683
13683
  "sass": {
13684
- "version": "1.47.0",
13685
- "resolved": "https://registry.npmjs.org/sass/-/sass-1.47.0.tgz",
13686
- "integrity": "sha512-GtXwvwgD7/6MLUZPnlA5/8cdRgC9SzT5kAnnJMRmEZQFRE3J56Foswig4NyyyQGsnmNvg6EUM/FP0Pe9Y2zywQ==",
13684
+ "version": "1.49.9",
13685
+ "resolved": "https://registry.npmjs.org/sass/-/sass-1.49.9.tgz",
13686
+ "integrity": "sha512-YlYWkkHP9fbwaFRZQRXgDi3mXZShslVmmo+FVK3kHLUELHHEYrCmL1x6IUjC7wLS6VuJSAFXRQS/DxdsC4xL1A==",
13687
13687
  "requires": {
13688
13688
  "chokidar": ">=3.0.0 <4.0.0",
13689
13689
  "immutable": "^4.0.0",
@@ -14445,9 +14445,9 @@
14445
14445
  "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
14446
14446
  },
14447
14447
  "source-map-js": {
14448
- "version": "1.0.1",
14449
- "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.1.tgz",
14450
- "integrity": "sha512-4+TN2b3tqOCd/kaGRJ/sTYA0tR0mdXx26ipdolxcwtJVqEnqNYvlCAt1q3ypy4QMlYus+Zh34RNtYLoq2oQ4IA=="
14448
+ "version": "1.0.2",
14449
+ "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
14450
+ "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw=="
14451
14451
  },
14452
14452
  "source-map-resolve": {
14453
14453
  "version": "0.5.3",
@@ -15436,9 +15436,9 @@
15436
15436
  "integrity": "sha512-6Gurc1n//gjp9eQNXjD9O3M/sMwVtN5S8Lv9bvOYBfKfDNiIIhqiyi01vMBO45u4zkDE420w/e0se7Vs+sIg+g=="
15437
15437
  },
15438
15438
  "uglify-js": {
15439
- "version": "3.15.0",
15440
- "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.0.tgz",
15441
- "integrity": "sha512-x+xdeDWq7FiORDvyIJ0q/waWd4PhjBNOm5dQUOq2AKC0IEjxOS66Ha9tctiVDGcRQuh69K7fgU5oRuTK4cysSg==",
15439
+ "version": "3.15.1",
15440
+ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.1.tgz",
15441
+ "integrity": "sha512-FAGKF12fWdkpvNJZENacOH0e/83eG6JyVQyanIJaBXCN1J11TUQv1T1/z8S+Z0CG0ZPk1nPcreF/c7lrTd0TEQ==",
15442
15442
  "optional": true
15443
15443
  },
15444
15444
  "uglify-to-browserify": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "3.9.2",
3
+ "version": "3.11.0",
4
4
  "description": "CLI tool to run BigCommerce Stores locally for theme development.",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -45,8 +45,8 @@
45
45
  "package-lock.json"
46
46
  ],
47
47
  "dependencies": {
48
- "@bigcommerce/stencil-paper": "3.0.0-rc.54",
49
- "@bigcommerce/stencil-styles": "2.1.1",
48
+ "@bigcommerce/stencil-paper": "3.0.0",
49
+ "@bigcommerce/stencil-styles": "2.1.2",
50
50
  "@hapi/boom": "^8.0.1",
51
51
  "@hapi/glue": "^6.2.0",
52
52
  "@hapi/h2o2": "^8.3.2",
@@ -371,7 +371,7 @@ function getAcceptLanguageHeader(request) {
371
371
  ) {
372
372
  return internals.options.storeSettingsLocale.default_shopper_language;
373
373
  }
374
- return request.headers['accept-language'];
374
+ return request.headers['accept-language'].toLowerCase();
375
375
  }
376
376
 
377
377
  /**
@@ -1,18 +1,13 @@
1
1
  const _ = require('lodash');
2
2
  const Boom = require('@hapi/boom');
3
- const StencilStyles = require('@bigcommerce/stencil-styles');
4
3
  const path = require('path');
5
- const { promisify } = require('util');
6
-
7
- const cssAssembler = require('../../../lib/css-assembler');
8
4
  const utils = require('../../lib/utils');
5
+ const cssCompiler = require('../../../lib/css/compile');
9
6
 
10
7
  const internals = {
11
8
  options: {},
12
9
  };
13
10
 
14
- const SASS_ENGINE_NAME = 'node-sass-fork';
15
-
16
11
  function register(server, options) {
17
12
  internals.options = _.defaultsDeep(options, internals.options);
18
13
 
@@ -60,37 +55,12 @@ internals.cssHandler = async (request, h) => {
60
55
  request.app.themeConfig.setVariation(variationIndex);
61
56
 
62
57
  // Get the theme configuration
63
- const fileName = internals.getOriginalFileName(request.params.fileName);
64
- const fileParts = path.parse(fileName);
65
- const pathToFile = path.join(fileParts.dir, `${fileParts.name}.scss`);
66
- const basePath = path.join(internals.getThemeAssetsPath(), 'scss');
67
-
68
- let files;
69
- try {
70
- files = await promisify(cssAssembler.assemble)(pathToFile, basePath, 'scss', {});
71
- } catch (err) {
72
- console.error(err);
73
- throw Boom.badData(err);
74
- }
75
-
76
58
  const configuration = await request.app.themeConfig.getConfig();
77
-
78
- const params = {
79
- data: files[pathToFile],
80
- files,
81
- dest: path.join('/assets/css', fileName),
82
- themeSettings: configuration.settings,
83
- sourceMap: true,
84
- autoprefixerOptions: {
85
- cascade: configuration.autoprefixer_cascade,
86
- browsers: configuration.autoprefixer_browsers,
87
- },
88
- };
89
- const stencilStyles = new StencilStyles(console);
90
- stencilStyles.activateEngine(SASS_ENGINE_NAME);
59
+ const fileName = internals.getOriginalFileName(request.params.fileName);
60
+ const themeAssetsPath = internals.getThemeAssetsPath();
91
61
 
92
62
  try {
93
- const css = await stencilStyles.compileCss('scss', params);
63
+ const css = await cssCompiler.compile(configuration, themeAssetsPath, fileName);
94
64
  return h.response(css).type('text/css');
95
65
  } catch (err) {
96
66
  console.error(err);