Skip to content

Commit a09e257

Browse files
fix: vs extension lint error (#158)
* fix: vs extension lint error * fix: vs ext test also runs lint * fix: vs ext file lint passes now * fix: vs ext lint runs in CI
1 parent 0d19c48 commit a09e257

File tree

6 files changed

+62
-54
lines changed

6 files changed

+62
-54
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ jobs:
7575
working-directory: packages/b2c-cli
7676
run: pnpm run pretest && pnpm run test:ci && pnpm run lint
7777

78+
- name: Run VS Extension lint
79+
id: vs-extension-test
80+
if: always() && steps.vs-extension-test.conclusion != 'cancelled'
81+
working-directory: packages/b2c-vs-extension
82+
# Testing not currently supported on CI
83+
run: pnpm run lint
84+
7885
- name: Test Report
7986
uses: dorny/test-reporter@fe45e9537387dac839af0d33ba56eed8e24189e8 # v2.3.0
8087
if: always() && steps.sdk-test.conclusion != 'cancelled'
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {includeIgnoreFile} from '@eslint/compat';
77
import headerPlugin from 'eslint-plugin-header';
88
import path from 'node:path';
99
import {fileURLToPath} from 'node:url';
10-
import typescriptEslint from 'typescript-eslint';
10+
import tseslint from 'typescript-eslint';
1111

1212
import {copyrightHeader, sharedRules, prettierPlugin} from '../../eslint.config.mjs';
1313

@@ -16,17 +16,19 @@ headerPlugin.rules.header.meta.schema = false;
1616

1717
export default [
1818
includeIgnoreFile(gitignorePath),
19-
...typescriptEslint.config({
20-
files: ['**/*.ts'],
21-
languageOptions: {
22-
parserOptions: {ecmaVersion: 2022, sourceType: 'module'},
23-
},
24-
}),
19+
{
20+
ignores: ['src/template/**'],
21+
},
22+
...tseslint.configs.recommended,
2523
prettierPlugin,
2624
{
25+
files: ['**/*.ts'],
2726
plugins: {
2827
header: headerPlugin,
2928
},
29+
languageOptions: {
30+
parserOptions: {ecmaVersion: 2022, sourceType: 'module'},
31+
},
3032
rules: {
3133
'header/header': ['error', 'block', copyrightHeader],
3234
...sharedRules,

packages/b2c-vs-extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"format": "prettier --write src",
7474
"format:check": "prettier --check src",
7575
"test": "vscode-test",
76+
"posttest": "pnpm run lint",
7677
"analyze": "ANALYZE_BUNDLE=1 node scripts/esbuild-bundle.mjs"
7778
},
7879
"devDependencies": {

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function activateInner(context: vscode.ExtensionContext, log: vscode.OutputChann
527527
return folder;
528528
}
529529

530-
function resolveCliScript(context: vscode.ExtensionContext): {node: string; script: string} | null {
530+
function _resolveCliScript(context: vscode.ExtensionContext): {node: string; script: string} | null {
531531
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
532532
if (workspaceRoot) {
533533
const distCli = path.join(workspaceRoot, 'dist', 'cli.js');
@@ -1040,7 +1040,7 @@ function activateInner(context: vscode.ExtensionContext, log: vscode.OutputChann
10401040
'sfcc.shopper-products',
10411041
'sfcc.shopper-stores',
10421042
];
1043-
const {data, error, response} = await slasClient.PUT('/tenants/{tenantId}/clients/{clientId}', {
1043+
const {error, response} = await slasClient.PUT('/tenants/{tenantId}/clients/{clientId}', {
10441044
params: {path: {tenantId, clientId}},
10451045
body: {
10461046
clientId,

0 commit comments

Comments
 (0)