@bigcommerce/stencil-cli 8.7.0 → 8.8.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.
@@ -47,6 +47,7 @@ async function run() {
47
47
  const rawConfig = await themeConfig.getRawConfig();
48
48
  const timeout = cliOptions.timeout * 1000; // seconds
49
49
  const buildConfigManager = new BuildConfigManager({ timeout });
50
+ await buildConfigManager.initConfig();
50
51
  const bundle = new Bundle(
51
52
  THEME_PATH,
52
53
  themeConfig,
@@ -34,6 +34,12 @@ const options = {
34
34
  cache: cliOptions.cache,
35
35
  channelUrl: cliOptions.channelUrl,
36
36
  };
37
- const timeout = cliOptions.timeout * 1000; // seconds
38
- const buildConfigManager = new BuildConfigManager({ timeout });
39
- new StencilStart({ buildConfigManager }).run(options).catch(printCliResultErrorAndExit);
37
+
38
+ async function run() {
39
+ const timeout = cliOptions.timeout * 1000; // seconds
40
+ const buildConfigManager = new BuildConfigManager({ timeout });
41
+ await buildConfigManager.initConfig();
42
+ new StencilStart({ buildConfigManager }).run(options).catch(printCliResultErrorAndExit);
43
+ }
44
+
45
+ run();
@@ -6,6 +6,11 @@ import { createRequire } from 'node:module';
6
6
  import { THEME_PATH } from '../constants.js';
7
7
 
8
8
  const require = createRequire(import.meta.url);
9
+ const isJest = typeof process !== 'undefined' && 'JEST_WORKER_ID' in process.env;
10
+
11
+ const cornerstoneConfigLink = isJest
12
+ ? 'https://raw.githubusercontent.com/bigcommerce/stencil-cli/master/test/_mocks/build-config/valid-config/stencil.conf.cjs'
13
+ : 'https://raw.githubusercontent.com/bigcommerce/cornerstone/master/stencil.conf.cjs';
9
14
 
10
15
  class BuildConfigManager {
11
16
  constructor({ workDir = THEME_PATH, fs = fsModule, timeout = 20000 } = {}) {
@@ -19,7 +24,10 @@ class BuildConfigManager {
19
24
  this._worker = null;
20
25
  this._workerIsReady = false;
21
26
  this.timeout = timeout;
22
- const config = this._getConfig(this._buildConfigPath, this._oldBuildConfigPath);
27
+ }
28
+
29
+ async initConfig() {
30
+ const config = await this._getConfig(this._buildConfigPath, this._oldBuildConfigPath);
23
31
  this.development = config.development || this._devWorker;
24
32
  this.production = config.production || this._prodWorker;
25
33
  this.watchOptions = config.watchOptions;
@@ -42,7 +50,7 @@ class BuildConfigManager {
42
50
  this._worker.kill(signal);
43
51
  }
44
52
 
45
- _getConfig(configPath, oldConfigPath) {
53
+ async _getConfig(configPath, oldConfigPath) {
46
54
  if (this._fs.existsSync(configPath)) {
47
55
  // eslint-disable-next-line import/no-dynamic-require
48
56
  return require(configPath);
@@ -52,7 +60,28 @@ class BuildConfigManager {
52
60
  // eslint-disable-next-line import/no-dynamic-require
53
61
  return require(configPath);
54
62
  }
55
- return {};
63
+
64
+ // Fallback to cornerstone default stencil.conf.cjs
65
+ const content = await this.downloadFileFromGitHub(cornerstoneConfigLink);
66
+ this._fs.writeFileSync(configPath, content);
67
+
68
+ // eslint-disable-next-line import/no-dynamic-require
69
+ return require(configPath);
70
+ }
71
+
72
+ async downloadFileFromGitHub(rawUrl) {
73
+ try {
74
+ const response = await fetch(rawUrl);
75
+
76
+ if (!response.ok) {
77
+ console.log(`Failed to fetch file from ${rawUrl}: ${response.statusText}`);
78
+ }
79
+
80
+ return response.text();
81
+ } catch (error) {
82
+ console.error('Failed to fetch stencil.conf.cjs:', error);
83
+ return null;
84
+ }
56
85
  }
57
86
 
58
87
  _moveOldConfig(newPath, oldPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "8.7.0",
3
+ "version": "8.8.1",
4
4
  "type": "module",
5
5
  "description": "CLI tool to run BigCommerce Stores locally for theme development.",
6
6
  "main": "index.js",