@bigcommerce/stencil-cli 3.10.1 → 3.13.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,5 +1,18 @@
1
1
  ### Draft
2
2
 
3
+ ### 3.13.0 (2022-04-08)
4
+
5
+ - feat: strf-9718 Add OAuth token to headers ([903](https://github.com/bigcommerce/stencil-cli/pull/903))
6
+
7
+ ### 3.12.0 (2022-03-29)
8
+
9
+ - feat: allow .css-files imports within SCSS files ([882](https://github.com/bigcommerce/stencil-cli/pull/882))
10
+ - bump paper version ([897](https://github.com/bigcommerce/stencil-cli/pull/897))
11
+
12
+ ### 3.11.0 (2022-03-10)
13
+
14
+ - feat: strf-9440 Stencil Bundle: fail on scss failure compilation ([884](https://github.com/bigcommerce/stencil-cli/pull/884))
15
+
3
16
  ### 3.10.1 (2022-02-24)
4
17
 
5
18
  - fix: when there's no regions on the page ([878](https://github.com/bigcommerce/stencil-cli/pull/878))
@@ -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));
@@ -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
+ };
@@ -23,17 +23,20 @@ function assemble(cssFiles, absolutePath, type, options, callback) {
23
23
 
24
24
  const parseImports = (cssFileAlias, parseImportsCallback) => {
25
25
  const normalizedCssFileAlias = cssFileAlias.replace(/(\.scss)$/g, '');
26
- const cssFilePath = path.join(absolutePath, normalizedCssFileAlias + ext);
26
+ const typedCssFilePath = path.join(absolutePath, normalizedCssFileAlias + ext);
27
+ const rawCssFilePath = path.join(absolutePath, normalizedCssFileAlias + '.css');
27
28
  const cssFileAliasDir = path.parse(normalizedCssFileAlias).dir;
28
29
 
29
- const fileParts = path.parse(cssFilePath);
30
+ const fileParts = path.parse(typedCssFilePath);
30
31
  const underscoredFilePath = path.join(fileParts.dir, `_${fileParts.base}`);
31
32
  let filePath;
32
33
 
33
- if (fs.existsSync(cssFilePath)) {
34
- filePath = cssFilePath;
34
+ if (fs.existsSync(typedCssFilePath)) {
35
+ filePath = typedCssFilePath;
35
36
  } else if (fs.existsSync(underscoredFilePath)) {
36
37
  filePath = underscoredFilePath;
38
+ } else if (ext === '.scss' && fs.existsSync(rawCssFilePath)) {
39
+ filePath = rawCssFilePath;
37
40
  } else {
38
41
  // File doesn't exist, just return to skip it
39
42
  parseImportsCallback();
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "3.10.1",
3
+ "version": "3.13.0",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -537,35 +537,35 @@
537
537
  }
538
538
  },
539
539
  "@bigcommerce/stencil-paper": {
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==",
540
+ "version": "3.0.5",
541
+ "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-paper/-/stencil-paper-3.0.5.tgz",
542
+ "integrity": "sha512-jIjISuMcW5CSk2CYwhWl1CpVKBUqsTVDUyvPL05XjWQo8/fzAJm/9JL8r52FjfeUrepHkFfTPMoa0mU76S4qNA==",
543
543
  "requires": {
544
- "@bigcommerce/stencil-paper-handlebars": "4.5.1",
544
+ "@bigcommerce/stencil-paper-handlebars": "4.5.5",
545
545
  "accept-language-parser": "~1.4.1",
546
546
  "messageformat": "~0.2.2"
547
547
  }
548
548
  },
549
549
  "@bigcommerce/stencil-paper-handlebars": {
550
- "version": "4.5.1",
551
- "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-paper-handlebars/-/stencil-paper-handlebars-4.5.1.tgz",
552
- "integrity": "sha512-drdYQDXFI8BI/H4/ACmYJUA1QfCbpYVp8MxG/B+JNZypg6UzTnWRJOvCKqohfr9obnLbSdL+nMjVol2cq/RmgQ==",
550
+ "version": "4.5.5",
551
+ "resolved": "https://registry.npmjs.org/@bigcommerce/stencil-paper-handlebars/-/stencil-paper-handlebars-4.5.5.tgz",
552
+ "integrity": "sha512-RoakM7Z5e/wZhKiuUNPCr1SgAMsR2stWnNqZydRqSV7ZSJdKxfCE4R0t8Y+ZMpgZPGvSOrIWrAcMaty5gLZhsw==",
553
553
  "requires": {
554
554
  "@bigcommerce/handlebars-v4": "4.7.6",
555
555
  "handlebars": "3.0.8",
556
556
  "handlebars-helpers": "0.8.4",
557
557
  "handlebars-utils": "^1.0.6",
558
558
  "he": "^1.2.0",
559
- "lodash": "^4.17.13",
559
+ "lodash": "^4.17.21",
560
560
  "stringz": "^0.1.1"
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.1",
15440
- "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.1.tgz",
15441
- "integrity": "sha512-FAGKF12fWdkpvNJZENacOH0e/83eG6JyVQyanIJaBXCN1J11TUQv1T1/z8S+Z0CG0ZPk1nPcreF/c7lrTd0TEQ==",
15439
+ "version": "3.15.3",
15440
+ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.3.tgz",
15441
+ "integrity": "sha512-6iCVm2omGJbsu3JWac+p6kUiOpg3wFO2f8lIXjfEb8RrmLjzog1wTPMmwKB7swfzzqxj9YM+sGUM++u1qN4qJg==",
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.10.1",
3
+ "version": "3.13.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",
49
- "@bigcommerce/stencil-styles": "2.1.1",
48
+ "@bigcommerce/stencil-paper": "3.0.5",
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",
package/server/index.js CHANGED
@@ -20,6 +20,8 @@ function buildManifest(srcManifest, options) {
20
20
  pluginsByName['./plugins/router/router.module'].apiKey = options.dotStencilFile.apiKey;
21
21
  pluginsByName['./plugins/router/router.module'].port = options.dotStencilFile.port;
22
22
  pluginsByName['./plugins/router/router.module'].stencilCliVersion = options.stencilCliVersion;
23
+ pluginsByName['./plugins/router/router.module'].accessToken =
24
+ options.dotStencilFile.accessToken;
23
25
  pluginsByName['./plugins/renderer/renderer.module'].useCache = options.useCache;
24
26
  pluginsByName['./plugins/renderer/renderer.module'].username = options.dotStencilFile.username;
25
27
  pluginsByName['./plugins/renderer/renderer.module'].token = options.dotStencilFile.token;
@@ -119,7 +119,10 @@ internals.registerRoutes = (server) => {
119
119
  )}`;
120
120
  const urlParams = req.url.search || '';
121
121
  const uri = `${host}${req.path}${urlParams}`;
122
- const headers = { 'stencil-cli': internals.options.stencilCliVersion };
122
+ const headers = {
123
+ 'stencil-cli': internals.options.stencilCliVersion,
124
+ 'x-auth-token': internals.options.accessToken,
125
+ };
123
126
  return { uri, headers };
124
127
  },
125
128
  passThrough: true,
@@ -167,6 +170,8 @@ internals.registerRoutes = (server) => {
167
170
  {
168
171
  origin: internals.options.storeUrl,
169
172
  host: internals.options.storeUrl.replace(/http[s]?:\/\//, ''),
173
+ 'stencil-cli': internals.options.stencilCliVersion,
174
+ 'x-auth-token': internals.options.accessToken,
170
175
  },
171
176
  ),
172
177
  }),
@@ -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
 
@@ -62,35 +57,10 @@ internals.cssHandler = async (request, h) => {
62
57
  // Get the theme configuration
63
58
  const configuration = await request.app.themeConfig.getConfig();
64
59
  const fileName = internals.getOriginalFileName(request.params.fileName);
65
- const fileParts = path.parse(fileName);
66
- const ext = configuration.css_compiler === 'css' ? configuration.css_compiler : 'scss';
67
- const pathToFile = path.join(fileParts.dir, `${fileParts.name}.${ext}`);
68
- const basePath = path.join(internals.getThemeAssetsPath(), `${ext}`);
69
-
70
- let files;
71
- try {
72
- files = await promisify(cssAssembler.assemble)(pathToFile, basePath, `${ext}`, {});
73
- } catch (err) {
74
- console.error(err);
75
- throw Boom.badData(err);
76
- }
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);
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);