@@ -12,9 +12,9 @@ import type {CartridgeMapping} from '../code/cartridges.js';
1212 * Resolve a user-provided file path to an SDAPI script_path.
1313 *
1414 * Accepts:
15- * - Server path: `/app_storefront/cartridge/controllers/Cart.js` (passed through)
1615 * - Absolute local path: `/Users/.../app_storefront/cartridge/controllers/Cart.js`
1716 * - Relative local path: `./cartridges/app_storefront/cartridge/controllers/Cart.js`
17+ * - Server path: `/app_storefront/cartridge/controllers/Cart.js` (passed through if not a local match)
1818 * - Cartridge-name-prefixed: `app_storefront/cartridge/controllers/Cart.js` (prefixed with /)
1919 *
2020 * Returns the SDAPI script_path (e.g. `/app_storefront/cartridge/controllers/Cart.js`).
@@ -25,18 +25,21 @@ export function resolveBreakpointPath(
2525 sourceMapper : SourceMapper ,
2626 cartridges : CartridgeMapping [ ] ,
2727) : string {
28- if ( input . startsWith ( '/' ) ) {
29- return input ;
30- }
31-
32- // Try direct source mapper (handles absolute and resolvable relative paths)
28+ // Always try source mapper first — handles both absolute and relative local paths
3329 const mapped = sourceMapper . toServerPath ( input ) ;
3430 if ( mapped ) return mapped ;
3531
36- // Try resolving relative to cwd
32+ // Try resolving relative to cwd (for paths like ./cartridges/app_mysite/...)
3733 const resolved = path . resolve ( input ) ;
38- const mappedResolved = sourceMapper . toServerPath ( resolved ) ;
39- if ( mappedResolved ) return mappedResolved ;
34+ if ( resolved !== input ) {
35+ const mappedResolved = sourceMapper . toServerPath ( resolved ) ;
36+ if ( mappedResolved ) return mappedResolved ;
37+ }
38+
39+ // If it starts with / and the source mapper didn't match, treat as server path
40+ if ( input . startsWith ( '/' ) ) {
41+ return input ;
42+ }
4043
4144 // Check if the input starts with a known cartridge name — treat as server path missing leading /
4245 const normalized = input . split ( path . sep ) . join ( '/' ) ;
@@ -46,14 +49,15 @@ export function resolveBreakpointPath(
4649 }
4750
4851 const cartridgeNames = cartridges . map ( ( c ) => c . name ) . join ( ', ' ) ;
49- const hint = cartridges . length > 0
50- ? `Known cartridges: ${ cartridgeNames } \n` +
51- `Accepted forms:\n` +
52- ` /cartridge_name/cartridge/path/to/file.js (server path)\n` +
53- ` cartridge_name/cartridge/path/to/file.js (server path without leading /)\n` +
54- ` ./path/to/cartridge_name/cartridge/file.js (relative local path)\n` +
55- ` /absolute/path/to/cartridge_name/file.js (absolute local path)`
56- : 'No cartridges discovered. Use a server path: /cartridge_name/cartridge/path/file.js' ;
52+ const hint =
53+ cartridges . length > 0
54+ ? `Known cartridges: ${ cartridgeNames } \n` +
55+ `Accepted forms:\n` +
56+ ` /cartridge_name/cartridge/path/to/file.js (server path)\n` +
57+ ` cartridge_name/cartridge/path/to/file.js (server path without leading /)\n` +
58+ ` ./path/to/cartridge_name/cartridge/file.js (relative local path)\n` +
59+ ` /absolute/path/to/cartridge_name/file.js (absolute local path)`
60+ : 'No cartridges discovered. Use a server path: /cartridge_name/cartridge/path/file.js' ;
5761
5862 throw new Error ( `Cannot resolve "${ input } " to a server script path.\n${ hint } ` ) ;
5963}
0 commit comments