Skip to content

Commit 6c95b8e

Browse files
committed
resolve issue with bundle deploy ssr patterns
1 parent eac40bc commit 6c95b8e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

docs/guide/storefront-next.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ This is run from your Storefront Next project directory.
152152

153153
```bash
154154
b2c mrt bundle deploy -p <PROJECT> -e <ENVIRONMENT> \
155-
--ssr-only "server/**/*,loader.js,sfnext-server-*.mjs,streamingHandler.{js,mjs,cjs},streamingHandler.{js,mjs,cjs}.map,!static/**/*" \
156-
--ssr-shared "client/**/*,static/**/*,**/*.css,**/*.png,**/*.jpg,**/*.jpeg,**/*.gif,**/*.svg,**/*.ico,**/*.woff,**/*.woff2,**/*.ttf,**/*.eot"
155+
--ssr-only '["server/**/*", "loader.js", "sfnext-server-*.mjs", "streamingHandler.{js,mjs,cjs}", "streamingHandler.{js,mjs,cjs}.map", "!static/**/*", "!**/*.stories.tsx", "!**/*.stories.ts", "!**/*-snapshot.tsx", "!.storybook/**/*", "!storybook-static/**/*", "!**/__mocks__/**/*", "!**/__snapshots__/**/*"]' \
156+
--ssr-shared '["client/**/*", "static/**/*", "**/*.css", "**/*.png", "**/*.jpg", "**/*.jpeg", "**/*.gif", "**/*.svg", "**/*.ico", "**/*.woff", "**/*.woff2", "**/*.ttf", "**/*.eot", "!**/*.stories.tsx", "!**/*.stories.ts", "!**/*-snapshot.tsx", "!.storybook/**/*", "!storybook-static/**/*", "!**/__mocks__/**/*", "!**/__snapshots__/**/*"]'
157157
```
158158

159-
The `--ssr-only` and `--ssr-shared` patterns are required for the Storefront Next bundle structure.
159+
These patterns match the defaults used by `pnpm sfnext push`. The `--ssr-only` and `--ssr-shared` flags accept either a JSON array (for patterns with brace expansion) or a comma-separated string, and can be overridden if your project structure differs.
160160

161161
## Summary
162162

packages/b2c-cli/src/commands/mrt/bundle/deploy.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ import {
1414
} from '@salesforce/b2c-tooling-sdk/operations/mrt';
1515
import {t, withDocs} from '../../../i18n/index.js';
1616

17+
/**
18+
* Parses a glob pattern string into an array of patterns.
19+
* Accepts either a JSON array (e.g. '["server/**\/*", "ssr.{js,mjs}"]')
20+
* or a comma-separated string (e.g. 'server/**\/*,ssr.js').
21+
* JSON array format supports brace expansion in individual patterns.
22+
*/
23+
function parseGlobPatterns(value: string): string[] {
24+
const trimmed = value.trim();
25+
if (trimmed.startsWith('[')) {
26+
const parsed: unknown = JSON.parse(trimmed);
27+
if (!Array.isArray(parsed) || !parsed.every((item) => typeof item === 'string')) {
28+
throw new Error(`Invalid glob pattern array: expected an array of strings`);
29+
}
30+
return parsed.map((s: string) => s.trim()).filter(Boolean);
31+
}
32+
return trimmed
33+
.split(',')
34+
.map((s) => s.trim())
35+
.filter(Boolean);
36+
}
37+
1738
/**
1839
* Parses SSR parameter flags into a key-value object.
1940
* Accepts format: key=value
@@ -79,11 +100,11 @@ export default class MrtBundleDeploy extends MrtCommand<typeof MrtBundleDeploy>
79100
default: 'build',
80101
}),
81102
'ssr-only': Flags.string({
82-
description: 'Glob patterns for server-only files (comma-separated, only for local builds)',
103+
description: 'Glob patterns for server-only files (comma-separated or JSON array, only for local builds)',
83104
default: 'ssr.js,ssr.mjs,server/**/*',
84105
}),
85106
'ssr-shared': Flags.string({
86-
description: 'Glob patterns for shared files (comma-separated, only for local builds)',
107+
description: 'Glob patterns for shared files (comma-separated or JSON array, only for local builds)',
87108
default: 'static/**/*,client/**/*',
88109
}),
89110
'node-version': Flags.string({
@@ -190,8 +211,8 @@ export default class MrtBundleDeploy extends MrtCommand<typeof MrtBundleDeploy>
190211
}
191212

192213
const buildDir = this.flags['build-dir'];
193-
const ssrOnly = this.flags['ssr-only'].split(',').map((s) => s.trim());
194-
const ssrShared = this.flags['ssr-shared'].split(',').map((s) => s.trim());
214+
const ssrOnly = parseGlobPatterns(this.flags['ssr-only']);
215+
const ssrShared = parseGlobPatterns(this.flags['ssr-shared']);
195216

196217
// Build SSR parameters from flags
197218
const ssrParameters: Record<string, unknown> = parseSsrParams(this.flags['ssr-param']);

0 commit comments

Comments
 (0)