From edf31729cc9261a81c309aec2e0b242bd9aad3c4 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 14 Feb 2022 17:18:01 -0600 Subject: [PATCH 1/3] perf: promise.all the pipelining --- .../staticResourceMetadataTransformer.ts | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/src/convert/transformers/staticResourceMetadataTransformer.ts b/src/convert/transformers/staticResourceMetadataTransformer.ts index dadc3f3281..2db82444ec 100644 --- a/src/convert/transformers/staticResourceMetadataTransformer.ts +++ b/src/convert/transformers/staticResourceMetadataTransformer.ts @@ -66,46 +66,52 @@ export class StaticResourceMetadataTransformer extends BaseMetadataTransformer { public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise { 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)}`, + }, + ] + ); } /** From 4b136e95ecd6fb7a678fc01e3c4e1d623533c76c Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 14 Feb 2022 17:29:07 -0600 Subject: [PATCH 2/3] test: equal in any order --- .../staticResourceMetadataTransformer.test.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/convert/transformers/staticResourceMetadataTransformer.test.ts b/test/convert/transformers/staticResourceMetadataTransformer.test.ts index 7ff06c6e69..d25056661e 100644 --- a/test/convert/transformers/staticResourceMetadataTransformer.test.ts +++ b/test/convert/transformers/staticResourceMetadataTransformer.test.ts @@ -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'; @@ -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', () => { @@ -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)]) ); } @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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( @@ -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 () => { @@ -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); }); }); }); From 51cdfd54083a49d439c007ef0801904818b80063 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 14 Feb 2022 17:30:43 -0600 Subject: [PATCH 3/3] chore: adding types for SDR --- METADATA_SUPPORT.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/METADATA_SUPPORT.md b/METADATA_SUPPORT.md index edd21f2e11..1d5eea3226 100644 --- a/METADATA_SUPPORT.md +++ b/METADATA_SUPPORT.md @@ -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|