Skip to content

Commit

Permalink
fix: handle lwc in a pkgDir of the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Feb 14, 2022
1 parent 6df02a7 commit 621d8cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/shared/metadataKeys.ts
Expand Up @@ -4,15 +4,21 @@
* 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 * as path from 'path';
import { basename, dirname, join, normalize, sep } from 'path';
import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve';
import { RemoteSyncInput } from './types';
import { getMetadataKey } from './functions';

// LWC can have child folders (ex: dynamic templates like /templates/noDataIllustration.html
// See UT for examples of the complexity this must handle
// keys always use forward slashes, even on Windows
const pathAfterFullName = (fileResponse: RemoteSyncInput): string =>
fileResponse && fileResponse.filePath
? fileResponse.filePath.substr(fileResponse.filePath.lastIndexOf(fileResponse.fullName)).replace(/\\/gi, '/')
? join(
dirname(fileResponse.filePath)
.substring(dirname(fileResponse.filePath).lastIndexOf(fileResponse.fullName))
.replace(/\\/gi, '/'),
basename(fileResponse.filePath)
)
: '';

const registry = new RegistryAccess();
Expand All @@ -29,8 +35,8 @@ const reverseAliasTypes = new Map(aliasTypes.map(([alias, type]) => [type, alias
export const getMetadataKeyFromFileResponse = (fileResponse: RemoteSyncInput): string[] => {
// also create an element for the parent object
if (fileResponse.type === 'CustomField' && fileResponse.filePath) {
const splits = path.normalize(fileResponse.filePath).split(path.sep);
const objectFolderIndex = splits.lastIndexOf('objects');
const splits = normalize(fileResponse.filePath).split(sep);
const objectFolderIndex = splits.indexOf('objects');
return [
getMetadataKey('CustomObject', splits[objectFolderIndex + 1]),
getMetadataKey(fileResponse.type, fileResponse.fullName),
Expand Down
13 changes: 13 additions & 0 deletions test/unit/metadataKeys.test.ts
Expand Up @@ -22,6 +22,19 @@ describe('metadataKeys', () => {
});

describe('lwc', () => {
it('lwc in folder of the same name', () => {
const fileResponse = {
fullName: 'productTileList',
type: 'LightningComponentBundle',
state: ComponentStatus.Created,
filePath: 'force-app/main/productTileList/lwc/productTileList/productTileList.css',
};
expect(getMetadataKeyFromFileResponse(fileResponse)).to.deep.equal([
'LightningComponentResource__productTileList/productTileList.css',
'LightningComponentBundle__productTileList',
]);
});

it('lwc returns the bundle and the resource pointing to the file', () => {
const fileResponse = {
fullName: 'productTileList',
Expand Down

0 comments on commit 621d8cf

Please sign in to comment.