@bigcommerce/stencil-cli 9.0.3 → 9.1.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/lib/BuildConfigManager.js +31 -11
- package/lib/stencil-bundle.js +1 -0
- package/package.json +1 -1
|
@@ -2,10 +2,9 @@ import { once } from 'lodash-es';
|
|
|
2
2
|
import { fork } from 'child_process';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fsModule from 'fs';
|
|
5
|
-
import {
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { THEME_PATH } from '../constants.js';
|
|
7
7
|
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
8
|
const isJest = typeof process !== 'undefined' && 'JEST_WORKER_ID' in process.env;
|
|
10
9
|
|
|
11
10
|
const cornerstoneConfigLink = isJest
|
|
@@ -16,8 +15,10 @@ class BuildConfigManager {
|
|
|
16
15
|
constructor({ workDir = THEME_PATH, fs = fsModule, timeout = 20000 } = {}) {
|
|
17
16
|
this.oldConfigFileName = 'stencil.conf.js';
|
|
18
17
|
this.configFileName = 'stencil.conf.cjs';
|
|
18
|
+
this.esmConfigFileName = 'stencil.conf.mjs';
|
|
19
19
|
this._workDir = workDir;
|
|
20
20
|
this._buildConfigPath = path.join(workDir, this.configFileName);
|
|
21
|
+
this._esmBuildConfigPath = path.join(workDir, this.esmConfigFileName);
|
|
21
22
|
this._oldBuildConfigPath = path.join(workDir, this.oldConfigFileName);
|
|
22
23
|
this._fs = fs;
|
|
23
24
|
this._onReadyCallbacks = [];
|
|
@@ -27,15 +28,19 @@ class BuildConfigManager {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
async initConfig() {
|
|
30
|
-
const config = await this._getConfig(
|
|
31
|
+
const config = await this._getConfig(
|
|
32
|
+
this._resolveBuildConfigPath(),
|
|
33
|
+
this._oldBuildConfigPath,
|
|
34
|
+
);
|
|
31
35
|
this.development = config.development || this._devWorker;
|
|
32
36
|
this.production = config.production || this._prodWorker;
|
|
33
37
|
this.watchOptions = config.watchOptions;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
initWorker() {
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
const buildConfigPath = this._resolveBuildConfigPath();
|
|
42
|
+
if (this._fs.existsSync(buildConfigPath)) {
|
|
43
|
+
this._worker = fork(buildConfigPath, [], { cwd: this._workDir });
|
|
39
44
|
this._worker.on('message', (message) => {
|
|
40
45
|
if (message === 'ready') {
|
|
41
46
|
this._workerIsReady = true;
|
|
@@ -50,23 +55,38 @@ class BuildConfigManager {
|
|
|
50
55
|
this._worker.kill(signal);
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
// Prefer an ESM stencil.conf.mjs when the theme provides one; otherwise
|
|
59
|
+
// use the CommonJS stencil.conf.cjs (which legacy stencil.conf.js files
|
|
60
|
+
// get renamed to)
|
|
61
|
+
_resolveBuildConfigPath() {
|
|
62
|
+
if (this._fs.existsSync(this._esmBuildConfigPath)) {
|
|
63
|
+
return this._esmBuildConfigPath;
|
|
64
|
+
}
|
|
65
|
+
return this._buildConfigPath;
|
|
66
|
+
}
|
|
67
|
+
|
|
53
68
|
async _getConfig(configPath, oldConfigPath) {
|
|
54
69
|
if (this._fs.existsSync(configPath)) {
|
|
55
|
-
|
|
56
|
-
return require(configPath);
|
|
70
|
+
return this._importConfig(configPath);
|
|
57
71
|
}
|
|
58
72
|
if (this._fs.existsSync(oldConfigPath)) {
|
|
59
73
|
this._moveOldConfig(configPath, oldConfigPath);
|
|
60
|
-
|
|
61
|
-
return require(configPath);
|
|
74
|
+
return this._importConfig(configPath);
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
// Fallback to cornerstone default stencil.conf.cjs
|
|
65
78
|
const content = await this.downloadFileFromGitHub(cornerstoneConfigLink);
|
|
66
79
|
this._fs.writeFileSync(configPath, content);
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
return this._importConfig(configPath);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Dynamic import() loads both ESM and CommonJS configs. CommonJS exposes
|
|
85
|
+
// module.exports as the default export; ESM configs use named exports
|
|
86
|
+
async _importConfig(configPath) {
|
|
87
|
+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
88
|
+
const configModule = await import(pathToFileURL(configPath).href);
|
|
89
|
+
return configModule.default ?? configModule;
|
|
70
90
|
}
|
|
71
91
|
|
|
72
92
|
async downloadFileFromGitHub(rawUrl) {
|
package/lib/stencil-bundle.js
CHANGED