Skip to content

Commit 8817545

Browse files
authored
fix: handle namespaces on lwc markup (#669)
* fix: handle namespaces on lwc markup * fix: support capitals in NS * fix: case insensitive version * test: ut for markup/ns/failures
1 parent 50d89b7 commit 8817545

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

contributing/metadata.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,17 @@ You can use an existing org for the metadata describe portion of the script by
193193

194194
### Steps to add your metadata in registry
195195

196-
## prerequisites:
196+
## Prerequisites
197197

198198
1. A sfdx project must exists in local.
199199
`sfdx force:project:create --projectname <projectname> --defaultpackagedir <directory> -x`
200-
2. An authorised devhub org must exists
200+
2. An authorized devhub org must exists
201201
`sfdx force:auth:web:login -a <alias> -r <localhost url> -d`
202202
3. A scratch org must exists with alias `registryBuilder`
203203
1. Update `project-scratch-def.json` as per your requirements.
204204
2. `sfdx force:org:create -f config/project-scratch-def.json -a registryBuilder -t scratch -s`
205205

206-
## Steps:
206+
## Steps
207207

208208
1. Fork SourceDeployRetrieve github repo
209209
(https://github.com/forcedotcom/source-deploy-retrieve)

src/client/metadataApiDeploy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export class DeployResult implements MetadataTransferResult {
231231
}
232232
switch (message.componentType) {
233233
case registry.types.lightningcomponentbundle.name:
234-
// remove the markup scheme from fullName
235-
message.fullName = message.fullName.replace(/markup:\/\/c:/, '');
234+
// remove the markup scheme from fullName, including c: or custom namespaces
235+
message.fullName = message.fullName.replace(/markup:\/\/[a-z|0-9|_]+:/i, '');
236236
break;
237237
case registry.types.document.name:
238238
// strip document extension from fullName

test/client/metadataApiDeploy.test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,91 @@ describe('MetadataApiDeploy', () => {
322322
expect(responses).to.deep.equal(expected);
323323
});
324324

325+
describe('namespaced lwc failures', () => {
326+
const bundlePath = join('path', 'to', 'lwc', 'test');
327+
const props = {
328+
name: 'test',
329+
type: registry.types.lightningcomponentbundle,
330+
xml: join(bundlePath, 'test.js-meta.xml'),
331+
content: bundlePath,
332+
};
333+
const component = SourceComponent.createVirtualComponent(props, [
334+
{
335+
dirPath: bundlePath,
336+
children: [basename(props.xml), 'test.js', 'test.html'],
337+
},
338+
]);
339+
const deployedSet = new ComponentSet([component]);
340+
const { fullName, type } = component;
341+
const problem = 'something went wrong';
342+
const problemType = 'Error';
343+
const componentSuccesses = {
344+
changed: 'true',
345+
created: 'false',
346+
deleted: 'false',
347+
success: 'true',
348+
fullName,
349+
componentType: type.name,
350+
} as DeployMessage;
351+
352+
const componentFailures = {
353+
changed: 'false',
354+
created: 'false',
355+
deleted: 'false',
356+
success: 'false',
357+
problem,
358+
problemType,
359+
fileName: join(bundlePath, `${fullName}.html`),
360+
componentType: type.name,
361+
} as DeployMessage;
362+
363+
it('should handle default namespace failure for "LightningComponentBundle" type', () => {
364+
const apiStatus: Partial<MetadataApiDeployStatus> = {
365+
details: {
366+
componentSuccesses,
367+
componentFailures: { ...componentFailures, fullName: `markup://c:${fullName}` },
368+
},
369+
};
370+
const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet);
371+
372+
const responses = result.getFileResponses();
373+
const expected = [
374+
{
375+
fullName,
376+
type: type.name,
377+
error: problem,
378+
problemType,
379+
state: ComponentStatus.Failed,
380+
filePath: componentFailures.fileName,
381+
},
382+
] as FileResponse[];
383+
expect(responses).to.deep.equal(expected);
384+
});
385+
386+
it('should handle custom namespace failure for "LightningComponentBundle" type', () => {
387+
const apiStatus: Partial<MetadataApiDeployStatus> = {
388+
details: {
389+
componentSuccesses,
390+
componentFailures: { ...componentFailures, fullName: `markup://my_NS:${fullName}` },
391+
},
392+
};
393+
const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet);
394+
395+
const responses = result.getFileResponses();
396+
const expected = [
397+
{
398+
fullName,
399+
type: type.name,
400+
error: problem,
401+
problemType,
402+
state: ComponentStatus.Failed,
403+
filePath: componentFailures.fileName,
404+
},
405+
] as FileResponse[];
406+
expect(responses).to.deep.equal(expected);
407+
});
408+
});
409+
325410
it('should report component as failed if component has success and failure messages', () => {
326411
const component = matchingContentFile.COMPONENT;
327412
const deployedSet = new ComponentSet([component]);

0 commit comments

Comments
 (0)