@bigcommerce/stencil-cli 5.3.2 → 5.3.4

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.
@@ -5,6 +5,7 @@ const path = require('path');
5
5
  const upath = require('upath');
6
6
 
7
7
  const partialRegex = /\{\{>\s*([_|\-|a-zA-Z0-9@'"/]+)[^{]*?}}/g;
8
+ const partialWithoutBracketsRegex = /[^>{{}}\s*]+/g;
8
9
  const dynamicComponentRegex = /\{\{\s*?dynamicComponent\s*(?:'|")([_|\-|a-zA-Z0-9/]+)(?:'|").*?}}/g;
9
10
  const includeRegex = /{{2}>\s*([_|\-|a-zA-Z0-9/]+)[^{]*?}{2}/g;
10
11
  const pathStringRegex = /^["'].+["']$/;
@@ -23,12 +24,24 @@ const defineBaseRoute = (route) => route.split('/').slice(0, 3).join('/');
23
24
  const applyExternalPath = (templateName, templates) => {
24
25
  return templates.map((t) => `${defineBaseRoute(templateName)}/${t}`);
25
26
  };
27
+ const modifyNestedPartial = (partial) => {
28
+ const partialFragments = partial.match(partialWithoutBracketsRegex);
29
+
30
+ if (partialFragments) {
31
+ return [`${partialFragments.shift()}'`, ...partialFragments].join(' ');
32
+ }
33
+
34
+ return partialFragments;
35
+ };
36
+
26
37
  const replacePartialNames = (content, partialRoute) => {
27
38
  return content.replace(
28
39
  includeRegex,
29
- (__, partialName) => `{{> '${defineBaseRoute(partialRoute)}/${partialName}' }}`,
40
+ (partialName) =>
41
+ `{{> '${defineBaseRoute(partialRoute)}/${modifyNestedPartial(partialName)} }}`,
30
42
  );
31
43
  };
44
+
32
45
  const trimPartial = (partial) => {
33
46
  if (pathStringRegex.test(partial)) {
34
47
  return partial.slice(1, -1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "5.3.2",
3
+ "version": "5.3.4",
4
4
  "description": "CLI tool to run BigCommerce Stores locally for theme development.",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -21,7 +21,6 @@ const {
21
21
  } = require('../../../lib/utils/frontmatter');
22
22
 
23
23
  const networkUtils = new NetworkUtils();
24
- const { DEFAULT_CUSTOM_LAYOUTS_CONFIG } = require('../../../constants');
25
24
 
26
25
  const internals = {
27
26
  options: {},
@@ -79,14 +78,12 @@ internals.getResponse = async (request) => {
79
78
  const withoutPageQuery = new URL(fullUrl.toString());
80
79
  withoutPageQuery.searchParams.delete('page');
81
80
 
82
- const { customLayouts } = internals.options;
83
-
84
81
  const httpOpts = {
85
82
  url: withoutPageQuery.toString(),
86
83
  headers: internals.buildReqHeaders({
87
84
  request,
88
85
  stencilOptions: { get_template_file: true, get_data_only: true },
89
- extraHeaders: { host: storeUrlObj.host, stencil_custom_templates: customLayouts },
86
+ extraHeaders: { host: storeUrlObj.host },
90
87
  }),
91
88
  accessToken: internals.options.accessToken,
92
89
  data: request.payload,
@@ -119,7 +116,6 @@ internals.getResponse = async (request) => {
119
116
  // clear when making a non-get request because smth may be changed
120
117
  cache.clear();
121
118
  }
122
-
123
119
  const response = await networkUtils.sendApiRequest(httpOpts);
124
120
 
125
121
  internals.processResHeaders(response.headers);
@@ -137,6 +133,7 @@ internals.getResponse = async (request) => {
137
133
  ? JSON.parse(await readFromStream(response.data))
138
134
  : response.data;
139
135
 
136
+ internals.updateTemplatePath(request.path, bcAppData);
140
137
  // cache response
141
138
  cache.put(
142
139
  requestSignature,
@@ -156,13 +153,10 @@ internals.getResponse = async (request) => {
156
153
  * @param request
157
154
  * @param response
158
155
  * @param responseArgs
159
- * @param customLayouts
160
156
  * @returns {*}
161
157
  */
162
158
  internals.parseResponse = async (bcAppData, request, response, responseArgs) => {
163
159
  const { httpOpts, storeUrlObj } = responseArgs;
164
- // eslint-disable-next-line camelcase
165
- const { stencil_custom_templates } = httpOpts.headers;
166
160
 
167
161
  if (typeof bcAppData !== 'object' || !('pencil_response' in bcAppData)) {
168
162
  delete response.headers['x-frame-options'];
@@ -185,7 +179,6 @@ internals.parseResponse = async (bcAppData, request, response, responseArgs) =>
185
179
  stencilConfig: internals.getResourceConfig(bcAppData, request, configuration),
186
180
  extraHeaders: {
187
181
  host: storeUrlObj.host,
188
- stencil_custom_templates,
189
182
  },
190
183
  });
191
184
  httpOpts.responseType = 'json'; // In the second request we always expect json
@@ -344,9 +337,9 @@ internals.redirect = async (response, request) => {
344
337
  *
345
338
  * @param {string} requestPath
346
339
  * @param {Object} data
347
- * @returns {string}
340
+ * @returns {void}
348
341
  */
349
- internals.getTemplatePath = (requestPath, data) => {
342
+ internals.updateTemplatePath = (requestPath, data) => {
350
343
  const customLayouts = internals.options.customLayouts || {};
351
344
  const pageType = data.page_type;
352
345
  let templatePath;
@@ -369,10 +362,10 @@ internals.getTemplatePath = (requestPath, data) => {
369
362
 
370
363
  if (templatePath) {
371
364
  templatePath = path.join('pages/custom', pageType, templatePath.replace(/\.html$/, ''));
365
+ // eslint-disable-next-line no-param-reassign
366
+ data.template_file = templatePath;
372
367
  }
373
368
  }
374
-
375
- return templatePath || data.template_file;
376
369
  };
377
370
 
378
371
  function getAcceptLanguageHeader(request) {
@@ -413,7 +406,7 @@ internals.getPencilResponse = (data, request, response, configuration, renderedR
413
406
 
414
407
  return new PencilResponse(
415
408
  {
416
- template_file: internals.getTemplatePath(request.path, data),
409
+ template_file: data.template_file,
417
410
  templates: data.templates,
418
411
  remote: data.remote,
419
412
  remote_data: data.remote_data,
@@ -451,14 +444,9 @@ internals.buildReqHeaders = ({
451
444
  ? JSON.parse(request.headers['stencil-options'])
452
445
  : {};
453
446
 
454
- const templates =
455
- JSON.stringify(extraHeaders.stencil_custom_templates) ||
456
- JSON.stringify(DEFAULT_CUSTOM_LAYOUTS_CONFIG);
457
-
458
447
  const headers = {
459
448
  'stencil-options': JSON.stringify({ ...stencilOptions, ...currentOptions }),
460
449
  'accept-encoding': 'identity',
461
- 'stencil-custom-templates': templates,
462
450
  };
463
451
 
464
452
  const config = request.headers['stencil-config'];
@@ -466,8 +454,6 @@ internals.buildReqHeaders = ({
466
454
  if ((!config || config === '{}') && stencilConfig) {
467
455
  headers['stencil-config'] = JSON.stringify(stencilConfig);
468
456
  }
469
- // eslint-disable-next-line no-param-reassign
470
- delete extraHeaders.stencil_custom_templates;
471
457
 
472
458
  return { ...request.headers, ...headers, ...extraHeaders };
473
459
  };