Skip to content

Commit 9ddd974

Browse files
lesya7cursoragent
andcommitted
fix: address PR feedback - clearer error messages, path.sep for separators
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7621647 commit 9ddd974

2 files changed

Lines changed: 23 additions & 32 deletions

File tree

src/resolve/adapters/webApplicationsSourceAdapter.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { join } from 'node:path';
16+
import { join, sep } from 'node:path';
1717
import { Messages } from '@salesforce/core/messages';
1818
import { SfError } from '@salesforce/core/sfError';
1919
import { SourcePath } from '../../common/types';
@@ -92,14 +92,17 @@ export class WebApplicationsSourceAdapter extends BundleSourceAdapter {
9292
const distPath = join(contentPath, 'dist');
9393
const indexPath = join(distPath, 'index.html');
9494

95+
const missingDistIndexMessage =
96+
"If a webapplication.json file does not exist, you are required to include a 'dist/index.html' file. This will be the entry point for your web application.";
97+
9598
if (!this.tree.exists(distPath) || !this.tree.isDirectory(distPath)) {
96-
this.expectedSourceError(distPath);
99+
throw new SfError(missingDistIndexMessage, 'ExpectedSourceFilesError');
97100
}
98101
if (!this.tree.exists(indexPath)) {
99-
this.expectedSourceError(indexPath);
102+
throw new SfError(missingDistIndexMessage, 'ExpectedSourceFilesError');
100103
}
101104
if (this.tree.readFileSync(indexPath).length === 0) {
102-
this.expectedSourceError(indexPath);
105+
throw new SfError(missingDistIndexMessage, 'ExpectedSourceFilesError');
103106
}
104107
}
105108

@@ -141,16 +144,22 @@ export class WebApplicationsSourceAdapter extends BundleSourceAdapter {
141144
);
142145
}
143146

144-
const fallbackPath = join(outputDirPath, config.routing.fallback.replace(/^\//, ''));
147+
// Strip leading path separator (path.sep and / for URL-style paths)
148+
const sepChar = sep.replace(/\\/g, '\\\\');
149+
const stripLeadingSep = (p: string) => p.replace(new RegExp(`^[${sepChar}/]`), '');
150+
const fallbackPath = join(outputDirPath, stripLeadingSep(config.routing.fallback));
145151
if (!this.tree.exists(fallbackPath)) {
146-
this.expectedSourceError(fallbackPath);
152+
throw new SfError(
153+
"The filepath defined in the webapplication.json -> routing.fallback was not found. Ensure this file exists at the location defined.",
154+
'ExpectedSourceFilesError'
155+
);
147156
}
148157

149158
// rewrites are optional, but every target must resolve
150159
if (Array.isArray(config.routing.rewrites)) {
151160
for (const { rewrite } of config.routing.rewrites) {
152161
if (rewrite) {
153-
const rewritePath = join(outputDirPath, rewrite.replace(/^\//, ''));
162+
const rewritePath = join(outputDirPath, stripLeadingSep(rewrite));
154163
if (!this.tree.exists(rewritePath)) {
155164
this.expectedSourceError(rewritePath);
156165
}

test/resolve/adapters/webApplicationsSourceAdapter.test.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,14 @@ describe('WebApplicationsSourceAdapter', () => {
113113
expect(metadataAdapter.getComponent(META_FILE, false)).to.deep.equal(expected);
114114
});
115115

116+
const DIST_INDEX_MESSAGE =
117+
"If a webapplication.json file does not exist, you are required to include a 'dist/index.html' file. This will be the entry point for your web application.";
118+
116119
describe('without webapplication.json (dist fallback)', () => {
117120
it('should throw when the dist folder does not exist', () => {
118121
const t = VirtualTreeContainer.fromFilePaths([META_FILE, CONTENT_FILE]);
119122
const a = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t);
120-
assert.throws(
121-
() => a.getComponent(APP_PATH),
122-
SfError,
123-
messages.getMessage('error_expected_source_files', [DIST_PATH, registry.types.webapplication.name])
124-
);
123+
assert.throws(() => a.getComponent(APP_PATH), SfError, DIST_INDEX_MESSAGE);
125124
});
126125

127126
it('should throw when dist exists but index.html is missing', () => {
@@ -131,14 +130,7 @@ describe('WebApplicationsSourceAdapter', () => {
131130
];
132131
const t = new VirtualTreeContainer(vfs);
133132
const a = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t);
134-
assert.throws(
135-
() => a.getComponent(APP_PATH),
136-
SfError,
137-
messages.getMessage('error_expected_source_files', [
138-
join(DIST_PATH, 'index.html'),
139-
registry.types.webapplication.name,
140-
])
141-
);
133+
assert.throws(() => a.getComponent(APP_PATH), SfError, DIST_INDEX_MESSAGE);
142134
});
143135

144136
it('should throw when dist/index.html is empty', () => {
@@ -148,14 +140,7 @@ describe('WebApplicationsSourceAdapter', () => {
148140
];
149141
const t = new VirtualTreeContainer(vfs);
150142
const a = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t);
151-
assert.throws(
152-
() => a.getComponent(APP_PATH),
153-
SfError,
154-
messages.getMessage('error_expected_source_files', [
155-
join(DIST_PATH, 'index.html'),
156-
registry.types.webapplication.name,
157-
])
158-
);
143+
assert.throws(() => a.getComponent(APP_PATH), SfError, DIST_INDEX_MESSAGE);
159144
});
160145

161146
it('should succeed when dist/index.html exists and is non-empty', () => {
@@ -296,10 +281,7 @@ describe('WebApplicationsSourceAdapter', () => {
296281
assert.throws(
297282
() => a.getComponent(APP_PATH),
298283
SfError,
299-
messages.getMessage('error_expected_source_files', [
300-
join(DIST_PATH, 'missing.html'),
301-
registry.types.webapplication.name,
302-
])
284+
"The filepath defined in the webapplication.json -> routing.fallback was not found. Ensure this file exists at the location defined."
303285
);
304286
});
305287

0 commit comments

Comments
 (0)