Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sm/tweaks fp #577

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,11 @@ v55 introduces the following new types. Here's their current level of support
|ExternalDataSrcDescriptor|❌|Not supported, but support could be added|
|ExternalDataTranField|❌|Not supported, but support could be added|
|ExternalDataTranObject|❌|Not supported, but support could be added|
|FavoriteTransferDestination|❌|Not supported, but support could be added|
|IndustriesAutomotiveSettings|✅||
|IndustriesMfgServiceSettings|✅||
|InvLatePymntRiskCalcSettings|✅||
|LiveChatObjectAccessDefinition|❌|Not supported, but support could be added|
|PaymentsManagementEnabledSettings|✅||
|RegisteredExternalService|❌|Not supported, but support could be added|
|StreamingAppDataConnector|❌|Not supported, but support could be added|
Expand Down
74 changes: 40 additions & 34 deletions src/convert/transformers/staticResourceMetadataTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,52 @@ export class StaticResourceMetadataTransformer extends BaseMetadataTransformer {

public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise<WriteInfo[]> {
const { xml, content } = component;
const writeInfos: WriteInfo[] = [];

if (content) {
const componentContentType = await this.getContentType(component);
const mergeContentPath = mergeWith?.content;
const baseContentPath = this.getBaseContentPath(component, mergeWith);

// only unzip an archive component if there isn't a merge component, or the merge component is itself expanded
const shouldUnzipArchive =
StaticResourceMetadataTransformer.ARCHIVE_MIME_TYPES.has(componentContentType) &&
(!mergeWith || mergeWith.tree.isDirectory(mergeContentPath));

if (shouldUnzipArchive) {
// for the bulk of static resource writing we'll start writing ASAP
// we'll still defer writing the resource-meta.xml file by pushing it onto the writeInfos
for (const info of (await Open.buffer(await component.tree.readFile(content))).files) {
if (info.type === 'File') {
const path = join(baseContentPath, info.path);

if (!content) {
return [];
}
const componentContentType = await this.getContentType(component);
const mergeContentPath = mergeWith?.content;
const baseContentPath = this.getBaseContentPath(component, mergeWith);

// only unzip an archive component if there isn't a merge component, or the merge component is itself expanded
const shouldUnzipArchive =
StaticResourceMetadataTransformer.ARCHIVE_MIME_TYPES.has(componentContentType) &&
(!mergeWith || mergeWith.tree.isDirectory(mergeContentPath));

if (shouldUnzipArchive) {
// for the bulk of static resource writing we'll start writing ASAP
// we'll still defer writing the resource-meta.xml file by pushing it onto the writeInfos
await Promise.all(
(
await Open.buffer(await component.tree.readFile(content))
).files
.filter((f) => f.type === 'File')
.map(async (f) => {
const path = join(baseContentPath, f.path);
const fullDest = isAbsolute(path)
? path
: join(this.defaultDirectory || component.getPackageRelativePath('', 'source'), path);
// push onto the pipeline and start writing now
await this.pipeline(info.stream(), fullDest);
}
}
} else {
const extension = this.getExtensionFromType(componentContentType);
writeInfos.push({
source: component.tree.stream(content),
output: `${baseContentPath}.${extension}`,
});
}

writeInfos.push({
return this.pipeline(f.stream(), fullDest);
})
);
}
return [
{
source: component.tree.stream(xml),
output: mergeWith?.xml || component.getPackageRelativePath(basename(xml), 'source'),
});
}

return writeInfos;
},
].concat(
shouldUnzipArchive
? []
: [
{
source: component.tree.stream(content),
output: `${baseContentPath}.${this.getExtensionFromType(componentContentType)}`,
},
]
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { basename, join } from 'path';
import deepEqualInAnyOrder = require('deep-equal-in-any-order');

import * as archiver from 'archiver';
import { expect } from 'chai';
import { createSandbox } from 'sinon';
import { CentralDirectory, Entry, Open } from 'unzipper';
import chai = require('chai');
import { registry, SourceComponent, VirtualTreeContainer, WriteInfo } from '../../../src';
import { StaticResourceMetadataTransformer } from '../../../src/convert/transformers/staticResourceMetadataTransformer';
import { LibraryError } from '../../../src/errors';
Expand All @@ -22,6 +25,8 @@ import {
import { TestReadable } from '../../mock/convert/readables';
import { DEFAULT_PACKAGE_ROOT_SFDX } from '../../../src/common';

chai.use(deepEqualInAnyOrder);

const env = createSandbox();

describe('StaticResourceMetadataTransformer', () => {
Expand Down Expand Up @@ -123,7 +128,7 @@ describe('StaticResourceMetadataTransformer', () => {
try {
await transformer.toMetadataFormat(component);
} catch (e) {
expect(e.message).to.equal(
expect(e.message).to.deep.equalInAnyOrder(
nls.localize('error_static_resource_missing_resource_file', [join('staticresources', component.name)])
);
}
Expand Down Expand Up @@ -170,7 +175,7 @@ describe('StaticResourceMetadataTransformer', () => {
},
];

expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos);
expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos);
});

it('should rename extension from .resource for a fallback mime extension', async () => {
Expand All @@ -193,7 +198,7 @@ describe('StaticResourceMetadataTransformer', () => {
},
];

expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos);
expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos);
});

it('should rename extension from .resource for an unsupported mime extension', async () => {
Expand All @@ -216,7 +221,7 @@ describe('StaticResourceMetadataTransformer', () => {
},
];

expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos);
expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos);
});

it('should ignore components without content', async () => {
Expand All @@ -242,7 +247,7 @@ describe('StaticResourceMetadataTransformer', () => {
},
];

expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos);
expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos);
expect(pipelineStub.callCount).to.equal(1);
expect(pipelineStub.firstCall.args[1]).to.equal(
join(
Expand Down Expand Up @@ -275,7 +280,7 @@ describe('StaticResourceMetadataTransformer', () => {
},
];

expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos);
expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos);
});

it('should merge output with merge component when content is archive', async () => {
Expand Down Expand Up @@ -356,7 +361,7 @@ describe('StaticResourceMetadataTransformer', () => {
},
];

expect(await transformer.toSourceFormat(component, mergeComponent)).to.deep.equal(expectedInfos);
expect(await transformer.toSourceFormat(component, mergeComponent)).to.deep.equalInAnyOrder(expectedInfos);
});
});
});