Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vscode-sfcc-config-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'b2c-vs-extension': patch
---

Honor the `SFCC_CONFIG` environment variable when resolving instance configuration. Previously the extension only looked for a `dw.json` in the workspace folder and ignored a global `dw.json` referenced by `SFCC_CONFIG`, so projects that relied on that env var (e.g. alongside a project `.env`) resolved to "No B2C Commerce instance configured". The extension now threads `SFCC_CONFIG` through as the explicit config path, matching the CLI's `--config` flag.
2 changes: 1 addition & 1 deletion packages/b2c-vs-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@
"@types/react-dom": "18.3.1",
"@types/vscode": "^1.105.1",
"@vscode/test-cli": "^0.0.12",
"@vscode/test-electron": "^2.5.2",
"@vscode/test-electron": "^3.1.0",
"@vscode/vsce": "^3.9.1",
"c8": "catalog:",
"esbuild": "^0.24.0",
Expand Down
12 changes: 11 additions & 1 deletion packages/b2c-vs-extension/src/config-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,17 @@ export class B2CExtensionConfig implements vscode.Disposable {
}
}

const config = await resolveConfig({}, {workingDirectory, sourcesBefore: [new EnvSource()]});
// Honor SFCC_CONFIG (an explicit dw.json path), the same env var the CLI
// exposes via its `--config` flag. This is a file *path*, not a config
// field, so EnvSource can't carry it — it must be threaded through as
// `configPath`. Read it after the .env load so a project .env can set or
// override it, matching CLI precedence. Falls back to workingDirectory/dw.json.
const configPath = process.env.SFCC_CONFIG || undefined;
if (configPath) {
this.log.appendLine(`[Config] Using explicit config path from SFCC_CONFIG: ${configPath}`);
}

const config = await resolveConfig({}, {workingDirectory, configPath, sourcesBefore: [new EnvSource()]});
this.config = config;

if (!config.hasB2CInstanceConfig()) {
Expand Down
35 changes: 35 additions & 0 deletions packages/b2c-vs-extension/src/test/config-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import * as assert from 'assert';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import {B2CExtensionConfig} from '../config-provider.js';
Expand Down Expand Up @@ -56,4 +58,37 @@ suite('B2CExtensionConfig workspace discovery', () => {
log.dispose();
}
});

test('honors SFCC_CONFIG (global dw.json path) over the workspace dw.json', async () => {
// Regression: the extension previously ignored SFCC_CONFIG (a dw.json *path*,
// as exposed by the CLI's --config flag) and only ever loaded a dw.json from
// the workspace folder. A project relying on a global dw.json via SFCC_CONFIG
// resolved to "No B2C Commerce instance configured".
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'b2c-sfcc-config-'));
const globalDwJson = path.join(dir, 'dw.json');
fs.writeFileSync(globalDwJson, JSON.stringify({hostname: 'global-config.invalid', username: 'u', password: 'p'}));

const previous = process.env.SFCC_CONFIG;
process.env.SFCC_CONFIG = globalDwJson;

const log = vscode.window.createOutputChannel('B2C Config SFCC_CONFIG Test');
const provider = new B2CExtensionConfig(log);

try {
await provider.ensureResolved();
const instance = provider.getInstance();
assert.ok(instance, 'expected an instance resolved from SFCC_CONFIG');
assert.strictEqual(instance.config.hostname, 'global-config.invalid');
assert.strictEqual(provider.getConfigError(), null);
} finally {
provider.dispose();
log.dispose();
if (previous === undefined) {
delete process.env.SFCC_CONFIG;
} else {
process.env.SFCC_CONFIG = previous;
}
fs.rmSync(dir, {recursive: true, force: true});
}
});
});
77 changes: 61 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading