Skip to content

Commit

Permalink
Sm/file-responses-windows-paths-bug (#579)
Browse files Browse the repository at this point in the history
* fix: message keys should use posix paths

* test: handle windows separators in Fullname for folder types

* chore: adding types for SDR
  • Loading branch information
mshanemc authored Feb 17, 2022
1 parent e25dd95 commit 67b5775
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { basename, dirname, extname, join } from 'path';
import { basename, dirname, extname, join, posix, sep } from 'path';
import { isString } from '@salesforce/ts-types';
import { create as createArchive } from 'archiver';
import * as fs from 'graceful-fs';
Expand All @@ -30,6 +30,7 @@ export class DeployResult implements MetadataTransferResult {
public readonly response: MetadataApiDeployStatus;
public readonly components: ComponentSet;
private readonly diagnosticUtil = new DiagnosticUtil('metadata');
private readonly shouldConvertPaths = sep !== posix.sep;

public constructor(response: MetadataApiDeployStatus, components: ComponentSet) {
this.response = response;
Expand Down Expand Up @@ -215,7 +216,7 @@ export class DeployResult implements MetadataTransferResult {

private key(component: ComponentLike): string {
const type = typeof component.type === 'string' ? component.type : component.type.name;
return `${type}#${component.fullName}`;
return `${type}#${this.shouldConvertPaths ? component.fullName.split(sep).join(posix.sep) : component.fullName}`;
}
}

Expand Down
9 changes: 6 additions & 3 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,16 @@ describe('MetadataApiDeploy', () => {
expect(responses).to.deep.equal(expected);
});

// folder types have a name like TestFolder/TestImageDoc
// which may include a platform-specific separator TestFolder\\TestImageDoc
it('should fix deploy message issue for "Document" type', () => {
const type = registry.types.document;
const name = 'test';
const foldername = 'A_Folder';
const contentName = `${name}.xyz`;
const basePath = join('path', 'to', type.directoryName, 'A_Folder');
const basePath = join('path', 'to', type.directoryName, foldername);
const props = {
name: 'test',
name: join(foldername, name),
type,
xml: join(basePath, `${name}.document${META_XML_SUFFIX}`),
content: join(basePath, contentName),
Expand All @@ -393,7 +396,7 @@ describe('MetadataApiDeploy', () => {
deleted: 'false',
success: 'true',
// fullname contains file extension that must be stripped
fullName: contentName,
fullName: join(foldername, name),
componentType: type.name,
} as DeployMessage,
},
Expand Down

0 comments on commit 67b5775

Please sign in to comment.