Skip to content

Commit a8460da

Browse files
committed
detect pwa kit extensible project
1 parent 7b6b0d0 commit a8460da

8 files changed

Lines changed: 40 additions & 29 deletions

File tree

packages/b2c-dx-mcp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ When neither `--toolsets` nor `--tools` are provided, the MCP server automatical
6868

6969
| Project Type | Detection | Toolsets Enabled |
7070
|--------------|-----------|------------------|
71-
| **PWA Kit v3** | `@salesforce/pwa-kit-*` packages in package.json | PWAV3, MRT, SCAPI |
71+
| **PWA Kit v3** | `@salesforce/pwa-kit-*`, `@salesforce/retail-react-app`, or `ccExtensibility` | PWAV3, MRT, SCAPI |
7272
| **Storefront Next** | `@salesforce/storefront-next-*` packages in package.json | STOREFRONTNEXT, MRT, SCAPI |
7373
| **SFRA** | `cartridges/` folder with controllers or templates | CARTRIDGES, SCAPI |
7474
| **Custom API** | `rest-apis/*/api.json` or `rest-apis/*/schema.yaml` files | CARTRIDGES, SCAPI |

packages/b2c-dx-mcp/src/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function getToolsetsForProjectType(projectType: ProjectType): Toolset[] {
3737
return ['STOREFRONTNEXT', 'MRT', 'SCAPI'];
3838
}
3939
default: {
40-
// Fallback: provide basic SCAPI tools for unknown projects
40+
// Fallback: provide basic SCAPI tools
4141
return ['SCAPI'];
4242
}
4343
}

packages/b2c-tooling-sdk/src/discovery/detector.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @module discovery/detector
1010
*/
11-
import type {DetectionResult, DetectionPattern, DetectOptions, ProjectType, ConfigFileInfo} from './types.js';
11+
import type {DetectionResult, DetectionPattern, DetectOptions, ProjectType} from './types.js';
1212
import {DEFAULT_PATTERNS} from './patterns/index.js';
1313

1414
/**
@@ -63,7 +63,6 @@ export class WorkspaceTypeDetector {
6363
async detect(): Promise<DetectionResult> {
6464
const matchedPatterns: string[] = [];
6565
const projectTypes: ProjectType[] = [];
66-
const configFiles: ConfigFileInfo[] = [];
6766

6867
for (const pattern of this.patterns) {
6968
try {
@@ -83,7 +82,6 @@ export class WorkspaceTypeDetector {
8382
projectTypes,
8483
matchedPatterns,
8584
autoDiscovered: true,
86-
configFiles,
8785
};
8886
}
8987

packages/b2c-tooling-sdk/src/discovery/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
*
2626
* The detector recognizes the following project types:
2727
*
28-
* - `pwa-kit-v3` - PWA Kit v3 storefront (has @salesforce/pwa-kit-* dependencies)
28+
* - `pwa-kit-v3` - PWA Kit v3 storefront (template copy or extensible flavor)
2929
* - `storefront-next` - Storefront Next/Odyssey project
3030
* - `sfra` - SFRA/cartridge-based storefront (has cartridges/ directory)
3131
* - `custom-api` - Custom SCAPI project (has api.json files)
3232
* - `headless` - Generic headless project (has dw.json but no specific framework)
33-
* - `unknown` - Could not determine project type
3433
*
3534
* ## Custom Patterns
3635
*
@@ -42,7 +41,6 @@
4241
* const myPattern: DetectionPattern = {
4342
* name: 'my-framework',
4443
* projectType: 'custom-api',
45-
* priority: 100,
4644
* detect: async (path) => {
4745
* // Custom detection logic
4846
* return false;
@@ -63,7 +61,7 @@
6361
export {WorkspaceTypeDetector, detectWorkspaceType} from './detector.js';
6462

6563
// Types
66-
export type {ProjectType, DetectionPattern, DetectionResult, DetectOptions, ConfigFileInfo} from './types.js';
64+
export type {ProjectType, DetectionPattern, DetectionResult, DetectOptions} from './types.js';
6765

6866
// Patterns (for customization)
6967
export {

packages/b2c-tooling-sdk/src/discovery/patterns/pwa-kit.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import {readPackageJson} from '../utils.js';
1515
* Detection pattern for PWA Kit v3 storefronts.
1616
*
1717
* Detects projects that have PWA Kit v3 SDK dependencies in package.json.
18-
* Matches packages starting with @salesforce/pwa-kit (v3+).
18+
* Supports two flavors:
19+
* - Template copy: Has @salesforce/pwa-kit-* packages
20+
* - Extensible: Has @salesforce/retail-react-app or ccExtensibility field
1921
*/
2022
export const pwaKitV3Pattern: DetectionPattern = {
2123
name: 'pwa-kit-v3',
@@ -24,7 +26,15 @@ export const pwaKitV3Pattern: DetectionPattern = {
2426
const pkg = await readPackageJson(workspacePath);
2527
if (!pkg) return false;
2628

29+
// Check for ccExtensibility field (extensible flavor marker)
30+
if (pkg.ccExtensibility) return true;
31+
2732
const deps = Object.keys({...pkg.dependencies, ...pkg.devDependencies});
28-
return deps.some((dep) => dep.startsWith('@salesforce/pwa-kit'));
33+
34+
// Template copy flavor: @salesforce/pwa-kit-* packages
35+
// Extensible flavor: @salesforce/retail-react-app package
36+
return deps.some(
37+
(dep) => dep.startsWith('@salesforce/pwa-kit') || dep === '@salesforce/retail-react-app'
38+
);
2939
},
3040
};

packages/b2c-tooling-sdk/src/discovery/types.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* Identifies the type of B2C Commerce project.
1414
*/
1515
export type ProjectType =
16-
| 'pwa-kit-v3' // PWA Kit v3 storefront (@salesforce/pwa-kit-* packages)
16+
| 'pwa-kit-v3' // PWA Kit v3 storefront (template copy or extensible flavor)
1717
| 'storefront-next' // Storefront Next (Odyssey)
1818
| 'sfra' // SFRA/cartridge-based storefront
1919
| 'custom-api' // Custom SCAPI project
20-
| 'headless' // Generic headless (uses SCAPI/dw.json but no specific framework)
21-
| 'unknown'; // Could not determine
20+
| 'headless'; // Generic headless (uses SCAPI/dw.json but no specific framework)
2221

2322
/**
2423
* Detection pattern definition.
@@ -32,18 +31,6 @@ export interface DetectionPattern {
3231
detect: (workspacePath: string) => Promise<boolean>;
3332
}
3433

35-
/**
36-
* Information about detected config files.
37-
*/
38-
export interface ConfigFileInfo {
39-
/** Type of configuration file */
40-
type: 'dw.json' | 'package.json' | 'mobify.json' | 'api.json';
41-
/** Path to the file */
42-
path: string;
43-
/** Relevant extracted info */
44-
metadata?: Record<string, unknown>;
45-
}
46-
4734
/**
4835
* Result of workspace detection.
4936
*/
@@ -54,8 +41,6 @@ export interface DetectionResult {
5441
matchedPatterns: string[];
5542
/** Whether auto-discovery was performed */
5643
autoDiscovered: boolean;
57-
/** Detected configuration files */
58-
configFiles: ConfigFileInfo[];
5944
}
6045

6146
/**

packages/b2c-tooling-sdk/test/discovery/detector.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ describe('discovery/detector', () => {
166166
expect(result.projectTypes).to.deep.equal(['pwa-kit']);
167167
expect(result.matchedPatterns).to.deep.equal(['test']);
168168
expect(result.autoDiscovered).to.equal(true);
169-
expect(result.configFiles).to.deep.equal([]);
170169
});
171170

172171
it('works without options', async () => {

packages/b2c-tooling-sdk/test/discovery/patterns/pwa-kit.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ describe('discovery/patterns/pwa-kit', () => {
5353
expect(result).to.be.false;
5454
});
5555

56+
it('detects @salesforce/retail-react-app dependency (extensible flavor)', async () => {
57+
const pkg = {devDependencies: {'@salesforce/retail-react-app': '^8.0.0'}};
58+
await fs.writeFile(path.join(tempDir, 'package.json'), JSON.stringify(pkg));
59+
60+
const result = await pwaKitV3Pattern.detect(tempDir);
61+
62+
expect(result).to.be.true;
63+
});
64+
65+
it('detects ccExtensibility field (extensible flavor)', async () => {
66+
const pkg = {
67+
ccExtensibility: {extends: '@salesforce/retail-react-app', overridesDir: 'overrides'},
68+
devDependencies: {},
69+
};
70+
await fs.writeFile(path.join(tempDir, 'package.json'), JSON.stringify(pkg));
71+
72+
const result = await pwaKitV3Pattern.detect(tempDir);
73+
74+
expect(result).to.be.true;
75+
});
76+
5677
it('returns false without PWA Kit dependencies', async () => {
5778
const pkg = {dependencies: {react: '^18.0.0'}};
5879
await fs.writeFile(path.join(tempDir, 'package.json'), JSON.stringify(pkg));

0 commit comments

Comments
 (0)