Skip to content

Commit c289b86

Browse files
fix: vs ext file lint passes now
1 parent 472e61e commit c289b86

File tree

5 files changed

+88
-65
lines changed

5 files changed

+88
-65
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineConfig } from '@vscode/test-cli';
1+
import {defineConfig} from '@vscode/test-cli';
22

33
export default defineConfig({
4-
files: 'out/test/**/*.test.js',
4+
files: 'out/test/**/*.test.js',
55
});

packages/b2c-vs-extension/eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ headerPlugin.rules.header.meta.schema = false;
1616

1717
export default [
1818
includeIgnoreFile(gitignorePath),
19+
{
20+
ignores: ['src/template/**'],
21+
},
1922
...tseslint.configs.recommended,
2023
prettierPlugin,
2124
{

packages/b2c-vs-extension/scripts/esbuild-bundle.mjs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
* Bundles the extension with esbuild. Injects a shim for import.meta.url so
88
* SDK code that uses createRequire(import.meta.url) works in CJS output.
99
*/
10-
import esbuild from "esbuild";
11-
import fs from "node:fs";
12-
import path from "path";
13-
import { fileURLToPath } from "url";
10+
import esbuild from 'esbuild';
11+
import fs from 'node:fs';
12+
import path from 'path';
13+
import {fileURLToPath} from 'url';
1414

1515
const __filename = fileURLToPath(import.meta.url);
1616
const __dirname = path.dirname(__filename);
1717

1818
// scripts/ -> package root
19-
const pkgRoot = path.resolve(__dirname, "..");
19+
const pkgRoot = path.resolve(__dirname, '..');
2020

2121
// In CJS there is no import.meta; SDK's version.js uses createRequire(import.meta.url). Shim it.
2222
// Use globalThis so the value is visible inside all module wrappers in the bundle.
@@ -25,19 +25,19 @@ const IMPORT_META_URL_SHIM =
2525

2626
function loaderFor(filePath) {
2727
const ext = path.extname(filePath);
28-
if (ext === ".ts" || filePath.endsWith(".tsx")) return "ts";
29-
return "js";
28+
if (ext === '.ts' || filePath.endsWith('.tsx')) return 'ts';
29+
return 'js';
3030
}
3131

3232
const importMetaUrlPlugin = {
33-
name: "import-meta-url-shim",
33+
name: 'import-meta-url-shim',
3434
setup(build) {
35-
build.onLoad({ filter: /\.(ts|tsx|js|mjs|cjs)$/ }, (args) => {
36-
const contents = fs.readFileSync(args.path, "utf-8");
37-
const replaced = contents.includes("import.meta.url")
38-
? contents.replace(/import\.meta\.url/g, "globalThis.__import_meta_url")
35+
build.onLoad({filter: /\.(ts|tsx|js|mjs|cjs)$/}, (args) => {
36+
const contents = fs.readFileSync(args.path, 'utf-8');
37+
const replaced = contents.includes('import.meta.url')
38+
? contents.replace(/import\.meta\.url/g, 'globalThis.__import_meta_url')
3939
: contents;
40-
return { contents: replaced, loader: loaderFor(args.path) };
40+
return {contents: replaced, loader: loaderFor(args.path)};
4141
});
4242
},
4343
};
@@ -47,69 +47,67 @@ const importMetaUrlPlugin = {
4747
// we replace that require in the bundle output with the actual JSON (post-build).
4848
// Also replace require.resolve('@salesforce/b2c-tooling-sdk/package.json') so it doesn't throw when
4949
// the extension runs from a VSIX (no node_modules). We use __dirname so path.dirname(...) is the extension dist.
50-
const sdkPkgJsonPath = path.join(pkgRoot, "..", "b2c-tooling-sdk", "package.json");
51-
const REQUIRE_RESOLVE_PACKAGE_JSON_RE = /require\d*\.resolve\s*\(\s*["']@salesforce\/b2c-tooling-sdk\/package\.json["']\s*\)/g;
50+
const sdkPkgJsonPath = path.join(pkgRoot, '..', 'b2c-tooling-sdk', 'package.json');
51+
const REQUIRE_RESOLVE_PACKAGE_JSON_RE =
52+
/require\d*\.resolve\s*\(\s*["']@salesforce\/b2c-tooling-sdk\/package\.json["']\s*\)/g;
5253
const REQUIRE_RESOLVE_REPLACEMENT = "require('path').join(__dirname, 'package.json')";
5354

5455
function inlineSdkPackageJson() {
55-
const outPath = path.join(pkgRoot, "dist", "extension.js");
56-
let str = fs.readFileSync(outPath, "utf8");
57-
const sdkPkg = JSON.stringify(JSON.parse(fs.readFileSync(sdkPkgJsonPath, "utf8")));
58-
str = str.replace(
59-
/require\d*\s*\(\s*["']@salesforce\/b2c-tooling-sdk\/package\.json["']\s*\)/g,
60-
sdkPkg
61-
);
56+
const outPath = path.join(pkgRoot, 'dist', 'extension.js');
57+
let str = fs.readFileSync(outPath, 'utf8');
58+
const sdkPkg = JSON.stringify(JSON.parse(fs.readFileSync(sdkPkgJsonPath, 'utf8')));
59+
str = str.replace(/require\d*\s*\(\s*["']@salesforce\/b2c-tooling-sdk\/package\.json["']\s*\)/g, sdkPkg);
6260
str = str.replace(REQUIRE_RESOLVE_PACKAGE_JSON_RE, REQUIRE_RESOLVE_REPLACEMENT);
63-
fs.writeFileSync(outPath, str, "utf8");
61+
fs.writeFileSync(outPath, str, 'utf8');
6462
}
6563

66-
const watchMode = process.argv.includes("--watch");
64+
const watchMode = process.argv.includes('--watch');
6765

6866
const buildOptions = {
69-
entryPoints: [path.join(pkgRoot, "src", "extension.ts")],
67+
entryPoints: [path.join(pkgRoot, 'src', 'extension.ts')],
7068
bundle: true,
71-
platform: "node",
72-
format: "cjs",
73-
target: "node18",
74-
outfile: path.join(pkgRoot, "dist", "extension.js"),
69+
platform: 'node',
70+
format: 'cjs',
71+
target: 'node18',
72+
outfile: path.join(pkgRoot, 'dist', 'extension.js'),
7573
sourcemap: true,
7674
metafile: true,
77-
external: ["vscode"],
75+
external: ['vscode'],
7876
// In watch mode, include "development" so esbuild resolves the SDK's exports to .ts source files
7977
// directly (no SDK rebuild needed). Production builds use the built dist/ artifacts.
80-
conditions: watchMode
81-
? ["development", "require", "node", "default"]
82-
: ["require", "node", "default"],
83-
mainFields: ["main", "module"],
84-
banner: { js: IMPORT_META_URL_SHIM },
78+
conditions: watchMode ? ['development', 'require', 'node', 'default'] : ['require', 'node', 'default'],
79+
mainFields: ['main', 'module'],
80+
banner: {js: IMPORT_META_URL_SHIM},
8581
plugins: [importMetaUrlPlugin],
86-
logLevel: "info",
82+
logLevel: 'info',
8783
};
8884

8985
if (watchMode) {
9086
const ctx = await esbuild.context(buildOptions);
9187
await ctx.watch();
92-
console.log("[esbuild] watching for changes...");
88+
console.log('[esbuild] watching for changes...');
9389
} else {
9490
const result = await esbuild.build(buildOptions);
9591

9692
inlineSdkPackageJson();
9793

9894
if (result.metafile && process.env.ANALYZE_BUNDLE) {
99-
const metaPath = path.join(pkgRoot, "dist", "meta.json");
100-
fs.writeFileSync(metaPath, JSON.stringify(result.metafile, null, 2), "utf-8");
95+
const metaPath = path.join(pkgRoot, 'dist', 'meta.json');
96+
fs.writeFileSync(metaPath, JSON.stringify(result.metafile, null, 2), 'utf-8');
10197
const inputs = Object.entries(result.metafile.inputs).map(([file, info]) => ({
10298
file: path.relative(pkgRoot, file),
10399
bytes: info.bytes,
104100
}));
105101
inputs.sort((a, b) => b.bytes - a.bytes);
106102
const total = inputs.reduce((s, i) => s + i.bytes, 0);
107-
console.log("\n--- Bundle analysis (top 40 by input size) ---");
103+
console.log('\n--- Bundle analysis (top 40 by input size) ---');
108104
console.log(`Total inputs: ${(total / 1024 / 1024).toFixed(2)} MB\n`);
109-
inputs.slice(0, 40).forEach(({ file, bytes }, i) => {
105+
inputs.slice(0, 40).forEach(({file, bytes}, i) => {
110106
const pct = ((bytes / total) * 100).toFixed(1);
111-
console.log(`${String(i + 1).padStart(2)} ${(bytes / 1024).toFixed(1).padStart(8)} KB ${pct.padStart(5)}% ${file}`);
107+
console.log(
108+
`${String(i + 1).padStart(2)} ${(bytes / 1024).toFixed(1).padStart(8)} KB ${pct.padStart(5)}% ${file}`,
109+
);
112110
});
113-
console.log("\nWrote", metaPath);
111+
console.log('\nWrote', metaPath);
114112
}
115113
}

packages/b2c-vs-extension/src/extension.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ function activateInner(context: vscode.ExtensionContext, log: vscode.OutputChann
521521
return folder;
522522
}
523523

524-
function resolveCliScript(context: vscode.ExtensionContext): {node: string; script: string} | null {
524+
function _resolveCliScript(context: vscode.ExtensionContext): {node: string; script: string} | null {
525525
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
526526
if (workspaceRoot) {
527527
const distCli = path.join(workspaceRoot, 'dist', 'cli.js');
@@ -653,9 +653,7 @@ function activateInner(context: vscode.ExtensionContext, log: vscode.OutputChann
653653
const tenantId = (msg.tenantId ?? '').trim();
654654
const apiFamily = (msg.apiFamily ?? '').trim();
655655
const apiName = (msg.apiName ?? '').trim();
656-
log.appendLine(
657-
`[SCAPI] Fetch schema paths: tenantId=${tenantId} apiFamily=${apiFamily} apiName=${apiName}`,
658-
);
656+
log.appendLine(`[SCAPI] Fetch schema paths: tenantId=${tenantId} apiFamily=${apiFamily} apiName=${apiName}`);
659657
if (!tenantId || !apiFamily || !apiName) {
660658
log.appendLine('[SCAPI] Fetch paths failed: Tenant Id, API Family, and API Name are required.');
661659
panel.webview.postMessage({
@@ -727,14 +725,14 @@ function activateInner(context: vscode.ExtensionContext, log: vscode.OutputChann
727725
log.appendLine(
728726
`[SCAPI] Normalized paths (${paths.length}): ${JSON.stringify(paths.slice(0, 10))}${paths.length > 10 ? '...' : ''}`,
729727
);
730-
const schemaInfo = data && typeof data === 'object' && 'info' in data ? (data as {info?: Record<string, unknown>}).info : undefined;
731-
const apiTypeRaw =
732-
schemaInfo?.['x-api-type'] ?? schemaInfo?.['x-apiType'] ?? schemaInfo?.['x_api_type'];
728+
const schemaInfo =
729+
data && typeof data === 'object' && 'info' in data
730+
? (data as {info?: Record<string, unknown>}).info
731+
: undefined;
732+
const apiTypeRaw = schemaInfo?.['x-api-type'] ?? schemaInfo?.['x-apiType'] ?? schemaInfo?.['x_api_type'];
733733
const apiType = typeof apiTypeRaw === 'string' ? apiTypeRaw : undefined;
734734
if (schemaInfo && !apiType) {
735-
log.appendLine(
736-
`[SCAPI] Schema info keys (no x-api-type): ${Object.keys(schemaInfo).join(', ')}`,
737-
);
735+
log.appendLine(`[SCAPI] Schema info keys (no x-api-type): ${Object.keys(schemaInfo).join(', ')}`);
738736
} else if (apiType) {
739737
log.appendLine(`[SCAPI] API type: ${apiType}`);
740738
}
@@ -1036,7 +1034,7 @@ function activateInner(context: vscode.ExtensionContext, log: vscode.OutputChann
10361034
'sfcc.shopper-products',
10371035
'sfcc.shopper-stores',
10381036
];
1039-
const {data, error, response} = await slasClient.PUT('/tenants/{tenantId}/clients/{clientId}', {
1037+
const {error, response} = await slasClient.PUT('/tenants/{tenantId}/clients/{clientId}', {
10401038
params: {path: {tenantId, clientId}},
10411039
body: {
10421040
clientId,

packages/b2c-vs-extension/src/scapi-explorer.html

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@
174174
gap: 0.5rem;
175175
margin-bottom: 0.5rem;
176176
}
177-
.token-heading-row h3 { margin: 0; }
177+
.token-heading-row h3 {
178+
margin: 0;
179+
}
178180
.copy-icon-btn,
179181
.copy-token-btn {
180182
display: inline-flex;
@@ -352,8 +354,13 @@ <h1>SCAPI API Explorer</h1>
352354
</div>
353355
<div id="create-result-section" class="create-slas-result hidden">
354356
<span class="result-label">SLAS client created</span>
355-
<div class="result-row-inline"><span class="result-label">Client ID:</span> <span class="result-value" id="result-client-id"></span></div>
356-
<div class="result-row-inline"><span class="result-label">Client Secret:</span> <span class="result-value" id="result-client-secret"></span></div>
357+
<div class="result-row-inline">
358+
<span class="result-label">Client ID:</span> <span class="result-value" id="result-client-id"></span>
359+
</div>
360+
<div class="result-row-inline">
361+
<span class="result-label">Client Secret:</span>
362+
<span class="result-value" id="result-client-secret"></span>
363+
</div>
357364
</div>
358365
<div id="create-scopes-section" class="create-slas-scopes hidden">
359366
<span class="result-label">Scopes</span>
@@ -376,7 +383,10 @@ <h3 style="margin-top: 0; font-size: 1rem">Generate Bearer Token</h3>
376383
<div class="input-with-copy">
377384
<input type="text" id="slas-client-id" placeholder="SLAS Client Id" />
378385
<button type="button" class="copy-icon-btn" id="copy-client-id-btn" title="Copy">
379-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
386+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
387+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
388+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
389+
</svg>
380390
</button>
381391
</div>
382392
</div>
@@ -385,7 +395,10 @@ <h3 style="margin-top: 0; font-size: 1rem">Generate Bearer Token</h3>
385395
<div class="input-with-copy">
386396
<input type="text" id="slas-client-secret" placeholder="SLAS Client Secret" />
387397
<button type="button" class="copy-icon-btn" id="copy-client-secret-btn" title="Copy">
388-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
398+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
399+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
400+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
401+
</svg>
389402
</button>
390403
</div>
391404
</div>
@@ -394,7 +407,10 @@ <h3 style="margin-top: 0; font-size: 1rem">Generate Bearer Token</h3>
394407
<div class="token-display-with-copy">
395408
<div class="result-value bearer-result-value" id="bearer-result-value"></div>
396409
<button type="button" class="copy-icon-btn" id="copy-token-btn" title="Copy token">
397-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
410+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
411+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
412+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
413+
</svg>
398414
</button>
399415
</div>
400416
</div>
@@ -450,7 +466,10 @@ <h3 style="margin-top: 0; font-size: 1rem">SCAPI Shop API Call</h3>
450466
<div class="panel-heading-with-copy">
451467
<h4>Generated curl</h4>
452468
<button type="button" class="copy-icon-btn" id="copy-curl-btn" title="Copy">
453-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
469+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
470+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
471+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
472+
</svg>
454473
</button>
455474
</div>
456475
<textarea
@@ -465,7 +484,10 @@ <h4>Generated curl</h4>
465484
<div class="panel-heading-with-copy">
466485
<h3>Response</h3>
467486
<button type="button" class="copy-icon-btn" id="copy-response-btn" title="Copy">
468-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
487+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
488+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
489+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
490+
</svg>
469491
</button>
470492
</div>
471493
<textarea id="scapi-result-body" class="result-body" readonly></textarea>
@@ -729,7 +751,9 @@ <h3>Error</h3>
729751
.then(function () {
730752
var t = btn.getAttribute('title') || fallbackTitle;
731753
btn.setAttribute('title', 'Copied!');
732-
setTimeout(function () { btn.setAttribute('title', t); }, 2000);
754+
setTimeout(function () {
755+
btn.setAttribute('title', t);
756+
}, 2000);
733757
})
734758
.catch(function () {});
735759
}

0 commit comments

Comments
 (0)