From 10fd87a02eb3caf4b377abfcdefd7625f808dd61 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Fri, 2 Aug 2024 13:55:55 +0200 Subject: [PATCH] fix: issue copying resource, meta and folder for resource type (#896) --- .../lib/service/inResourceHandler.test.ts | 30 ++- package.json | 6 +- src/service/inResourceHandler.ts | 39 ++-- yarn.lock | 214 ++++++------------ 4 files changed, 101 insertions(+), 188 deletions(-) diff --git a/__tests__/unit/lib/service/inResourceHandler.test.ts b/__tests__/unit/lib/service/inResourceHandler.test.ts index 3a5dfa44..20264b03 100644 --- a/__tests__/unit/lib/service/inResourceHandler.test.ts +++ b/__tests__/unit/lib/service/inResourceHandler.test.ts @@ -80,30 +80,20 @@ describe('InResourceHandler', () => { work.config.generateDelta = true }) describe('when matching resource exist', () => { - beforeEach(() => { - mockedReadDir.mockResolvedValue([ - 'other.resource-meta.xml', - 'other/', - 'image.resource-meta.xml', - 'my_experience_bundle.site-meta.xml', - 'my_experience_bundle/', - 'other_experience_bundle.resource-meta.xml', - ]) - }) it.each([ ['imageFile.png', staticResourceType, 'imageFile', 2], - ['imageFolder/logo.png', staticResourceType, 'imageFolder', 3], + ['imageFolder/logo.png', staticResourceType, 'imageFolder', 2], [ 'my_experience_bundle/config/myexperiencebundle.json', experienceBundleType, 'my_experience_bundle', - 3, + 5, ], [ 'CustomerSupport/permissionSetFieldPermissions/Account.Test__c.permissionSetFieldPermission-meta.xml', permissionSetType, 'CustomerSupport', - 3, + 2, ], ])( 'should copy the matching folder resource, matching meta file and subject file %s', @@ -111,6 +101,15 @@ describe('InResourceHandler', () => { // Arrange const base = 'force-app/main/default/' const line = `A ${base}${type.directoryName}/${path}` + mockedReadDir.mockResolvedValue([ + `${base}${type.directoryName}/other.resource-meta.xml`, + `${base}${type.directoryName}/other/`, + `${base}${type.directoryName}/image.resource-meta.xml`, + `${base}${type.directoryName}/my_experience_bundle.site-meta.xml`, + `${base}${type.directoryName}/my_experience_bundle/`, + `${base}${type.directoryName}/my_experience_bundle/config/myexperiencebundle.json`, + `${base}${type.directoryName}/other_experience_bundle.resource-meta.xml`, + ]) const sut = new InResourceHandler(line, type, work, globalMetadata) // Act @@ -153,7 +152,7 @@ describe('InResourceHandler', () => { expect(work.diffs.package.get(type.xmlName)).toEqual( new Set([entity]) ) - expect(copyFiles).toBeCalledTimes(3) + expect(copyFiles).toBeCalledTimes(2) expect(copyFiles).toHaveBeenCalledWith( work.config, `${base}${type.directoryName}/${path}` @@ -211,8 +210,7 @@ describe('InResourceHandler', () => { expect( Array.from(work.diffs.package.get(permissionSetType.xmlName)!) ).toEqual([metadataElement]) - expect(copyFiles).toBeCalledTimes(3) - expect(copyFiles).toHaveBeenCalledWith(work.config, path) + expect(copyFiles).toBeCalledTimes(2) expect(copyFiles).toHaveBeenCalledWith(work.config, path) }) }) diff --git a/package.json b/package.json index bb48dfdd..79c754bf 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "author": "Sebastien Colladon ", "dependencies": { "@salesforce/command": "^5.3.9", - "@salesforce/core": "^8.2.6", + "@salesforce/core": "^8.2.7", "async": "^3.2.5", "fast-xml-parser": "^4.4.1", "fs-extra": "^11.2.0", @@ -234,8 +234,8 @@ "@types/jest": "^29.5.12", "@types/mocha": "^10.0.7", "@types/node": "^22.0.0", - "@typescript-eslint/eslint-plugin": "^7.17.0", - "@typescript-eslint/parser": "^7.17.0", + "@typescript-eslint/eslint-plugin": "^7.18.0", + "@typescript-eslint/parser": "^7.18.0", "benchmark": "^2.1.4", "chai": "^4.3.10", "eslint": "^8.57.0", diff --git a/src/service/inResourceHandler.ts b/src/service/inResourceHandler.ts index 4e6cf04d..2c57e29a 100644 --- a/src/service/inResourceHandler.ts +++ b/src/service/inResourceHandler.ts @@ -3,33 +3,19 @@ import { join, parse } from 'path' import { DOT, PATH_SEP } from '../constant/fsConstants' import { METAFILE_SUFFIX, META_REGEX } from '../constant/metadataConstants' -import { MetadataRepository } from '../metadata/MetadataRepository' -import { Metadata } from '../types/metadata' -import type { Work } from '../types/work' -import { pathExists } from '../utils/fsHelper' +import { pathExists, readDir } from '../utils/fsHelper' import StandardHandler from './standardHandler' export default class ResourceHandler extends StandardHandler { - protected readonly metadataName: string - - constructor( - line: string, - metadataDef: Metadata, - work: Work, - metadata: MetadataRepository - ) { - super(line, metadataDef, work, metadata) - this.metadataName = this._getMetadataName() - } + protected metadataName: string | undefined public override async handleAddition() { + this.metadataName = this._getMetadataName() await super.handleAddition() if (!this.config.generateDelta) return - if (this.line !== this.metadataName && this._parentFolderIsNotTheType()) { - await this._copy(this.metadataName) - } + await this._copyResourceFiles() } public override async handleDeletion() { @@ -42,6 +28,23 @@ export default class ResourceHandler extends StandardHandler { } } + protected async _copyResourceFiles() { + const staticResourcePath = this.metadataName!.substring( + 0, + this.metadataName!.lastIndexOf(PATH_SEP) + ) + const allStaticResources = await readDir( + staticResourcePath, + this.work.config + ) + const resourceFiles = allStaticResources.filter((file: string) => + file.startsWith(this.metadataName!) + ) + for (const resourceFile of resourceFiles) { + await this._copy(resourceFile) + } + } + protected override _getElementName() { const parsedPath = this._getParsedPath() return parsedPath.name diff --git a/yarn.lock b/yarn.lock index 1ba7eacb..31f92626 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1202,12 +1202,11 @@ __metadata: languageName: node linkType: hard -"@jsforce/jsforce-node@npm:^3.2.4": - version: 3.3.1 - resolution: "@jsforce/jsforce-node@npm:3.3.1" +"@jsforce/jsforce-node@npm:^3.3.2": + version: 3.3.3 + resolution: "@jsforce/jsforce-node@npm:3.3.3" dependencies: "@sindresorhus/is": ^4 - "@types/node": ^18.15.3 abort-controller: ^3.0.0 base64url: ^3.0.1 csv-parse: ^5.5.2 @@ -1219,7 +1218,7 @@ __metadata: node-fetch: ^2.6.1 strip-ansi: ^6.0.0 xml2js: ^0.6.2 - checksum: e1ab52d934e0cd22dc65c6d7cdf88fd26bfc99843ddbdeaf1121f10bcc1bfb68405654605fdfbf71cbb8727a5cb9ce31b81b02603c1a23cc441663f545f9d4ad + checksum: cbc5829596273c1ed603d1725355233ee0c3378dbb1937db9abbe1c1dfdcda4d8083b32f14193e9cfff3e438af8cc21c917f9c9997f466d066a673abe225ff05 languageName: node linkType: hard @@ -1693,37 +1692,11 @@ __metadata: languageName: node linkType: hard -"@salesforce/core@npm:^8.2.3": - version: 8.2.3 - resolution: "@salesforce/core@npm:8.2.3" - dependencies: - "@jsforce/jsforce-node": ^3.2.4 - "@salesforce/kit": ^3.1.6 - "@salesforce/schemas": ^1.9.0 - "@salesforce/ts-types": ^2.0.10 - ajv: ^8.17.1 - change-case: ^4.1.2 - fast-levenshtein: ^3.0.0 - faye: ^1.4.0 - form-data: ^4.0.0 - js2xmlparser: ^4.0.1 - jsonwebtoken: 9.0.2 - jszip: 3.10.1 - pino: ^9.2.0 - pino-abstract-transport: ^1.2.0 - pino-pretty: ^11.2.1 - proper-lockfile: ^4.1.2 - semver: ^7.6.2 - ts-retry-promise: ^0.8.1 - checksum: 855e56f37f47052c4ac7951f96a1d7b1ade33f33fdcaf27c15f25f859ba84ee735a2ce8ff5bd9b359dc7b78b30457c46c31ee7d104c29463cfb9e5bd95b038f2 - languageName: node - linkType: hard - -"@salesforce/core@npm:^8.2.6": - version: 8.2.6 - resolution: "@salesforce/core@npm:8.2.6" +"@salesforce/core@npm:^8.2.3, @salesforce/core@npm:^8.2.7": + version: 8.2.7 + resolution: "@salesforce/core@npm:8.2.7" dependencies: - "@jsforce/jsforce-node": ^3.2.4 + "@jsforce/jsforce-node": ^3.3.2 "@salesforce/kit": ^3.1.6 "@salesforce/schemas": ^1.9.0 "@salesforce/ts-types": ^2.0.10 @@ -1741,7 +1714,7 @@ __metadata: proper-lockfile: ^4.1.2 semver: ^7.6.3 ts-retry-promise: ^0.8.1 - checksum: bf6f64f0af50c8069a23a71bf2c2a5e4eb06efa4b89b89f6e022164ebfaf6bbf00beea98d5cbd9d2cf459310ed921e2ae1c64d50baa2691a593c8b3584a8ff5c + checksum: 0075812ad9048ebc643067adf2951c28e6e7e166bbb76f8870bd5b17a01e9f02ff220d99c83bef42afbbdaa1fdd1a3cf16268b1b99d61c35b261490dd99b7f39 languageName: node linkType: hard @@ -2374,15 +2347,6 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^18.15.3": - version: 18.19.34 - resolution: "@types/node@npm:18.19.34" - dependencies: - undici-types: ~5.26.4 - checksum: ae6369baa1529ec3564da29611ec7eb8ccb219080d717292151b6b899820d25290243d01c9240f11a63d1a42e47198cd6310fab67b6d17bea723221fea07b644 - languageName: node - linkType: hard - "@types/node@npm:^22.0.0": version: 22.0.0 resolution: "@types/node@npm:22.0.0" @@ -2455,15 +2419,15 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:^7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/eslint-plugin@npm:7.17.0" +"@typescript-eslint/eslint-plugin@npm:^7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/eslint-plugin@npm:7.18.0" dependencies: "@eslint-community/regexpp": ^4.10.0 - "@typescript-eslint/scope-manager": 7.17.0 - "@typescript-eslint/type-utils": 7.17.0 - "@typescript-eslint/utils": 7.17.0 - "@typescript-eslint/visitor-keys": 7.17.0 + "@typescript-eslint/scope-manager": 7.18.0 + "@typescript-eslint/type-utils": 7.18.0 + "@typescript-eslint/utils": 7.18.0 + "@typescript-eslint/visitor-keys": 7.18.0 graphemer: ^1.4.0 ignore: ^5.3.1 natural-compare: ^1.4.0 @@ -2474,44 +2438,44 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: edb0abd0113020e47f6fb0833c1b0fe3dcd45420b6ecbdd141331ead05f69cfa09e790ed469e4ecfb70c05e0fb882c61d409b639edc82cf9046a7fe3c986f544 + checksum: dfcf150628ca2d4ccdfc20b46b0eae075c2f16ef5e70d9d2f0d746acf4c69a09f962b93befee01a529f14bbeb3e817b5aba287d7dd0edc23396bc5ed1f448c3d languageName: node linkType: hard -"@typescript-eslint/parser@npm:^7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/parser@npm:7.17.0" +"@typescript-eslint/parser@npm:^7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/parser@npm:7.18.0" dependencies: - "@typescript-eslint/scope-manager": 7.17.0 - "@typescript-eslint/types": 7.17.0 - "@typescript-eslint/typescript-estree": 7.17.0 - "@typescript-eslint/visitor-keys": 7.17.0 + "@typescript-eslint/scope-manager": 7.18.0 + "@typescript-eslint/types": 7.18.0 + "@typescript-eslint/typescript-estree": 7.18.0 + "@typescript-eslint/visitor-keys": 7.18.0 debug: ^4.3.4 peerDependencies: eslint: ^8.56.0 peerDependenciesMeta: typescript: optional: true - checksum: f0525317af174b5547d0a7ed8eadbbb7bbc1da9e9ab86882ed616b0ffb053170818a48cab2aaa627001ee991ee559630fbe5ad632b3df7cdf4a2b1b07a571907 + checksum: 132b56ac3b2d90b588d61d005a70f6af322860974225b60201cbf45abf7304d67b7d8a6f0ade1c188ac4e339884e78d6dcd450417f1481998f9ddd155bab0801 languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/scope-manager@npm:7.17.0" +"@typescript-eslint/scope-manager@npm:7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/scope-manager@npm:7.18.0" dependencies: - "@typescript-eslint/types": 7.17.0 - "@typescript-eslint/visitor-keys": 7.17.0 - checksum: 0cb77db6243455b47947df693d9b16f8e2b07e14994d755918dcc98693dba97036806d8f80a12bbd5c82f61883d134dd42d25880f20448c1e2376a9d873f9ef8 + "@typescript-eslint/types": 7.18.0 + "@typescript-eslint/visitor-keys": 7.18.0 + checksum: b982c6ac13d8c86bb3b949c6b4e465f3f60557c2ccf4cc229799827d462df56b9e4d3eaed7711d79b875422fc3d71ec1ebcb5195db72134d07c619e3c5506b57 languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/type-utils@npm:7.17.0" +"@typescript-eslint/type-utils@npm:7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/type-utils@npm:7.18.0" dependencies: - "@typescript-eslint/typescript-estree": 7.17.0 - "@typescript-eslint/utils": 7.17.0 + "@typescript-eslint/typescript-estree": 7.18.0 + "@typescript-eslint/utils": 7.18.0 debug: ^4.3.4 ts-api-utils: ^1.3.0 peerDependencies: @@ -2519,23 +2483,23 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 357a32d75f449cb9112ee9a23644b79c3eada8b023bd2508489cdc97e0a834ab2937712fb95a2aedd3cfb801d9b973280899ab696938908c480af240a22a36ba + checksum: 68fd5df5146c1a08cde20d59b4b919acab06a1b06194fe4f7ba1b928674880249890785fbbc97394142f2ef5cff5a7fba9b8a940449e7d5605306505348e38bc languageName: node linkType: hard -"@typescript-eslint/types@npm:7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/types@npm:7.17.0" - checksum: efd4fadf8f3f2496d813338f873564b903fbaaff53f3ce496159c76d49e01f6e2dbbf037f5e7318d0292cca7b6191c8f8462fa31cba1b5c50a11676bbb5df9ba +"@typescript-eslint/types@npm:7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/types@npm:7.18.0" + checksum: 7df2750cd146a0acd2d843208d69f153b458e024bbe12aab9e441ad2c56f47de3ddfeb329c4d1ea0079e2577fea4b8c1c1ce15315a8d49044586b04fedfe7a4d languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/typescript-estree@npm:7.17.0" +"@typescript-eslint/typescript-estree@npm:7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/typescript-estree@npm:7.18.0" dependencies: - "@typescript-eslint/types": 7.17.0 - "@typescript-eslint/visitor-keys": 7.17.0 + "@typescript-eslint/types": 7.18.0 + "@typescript-eslint/visitor-keys": 7.18.0 debug: ^4.3.4 globby: ^11.1.0 is-glob: ^4.0.3 @@ -2545,31 +2509,31 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 0f7a7618431c94603c742d1bcb1cb3a5aa646a6ebb3adff89b35db1fe014f9a060d550e6ca5f0ab152615ae129e8a0f84020dda56cd2d2c73386f657dccf7e34 + checksum: c82d22ec9654973944f779eb4eb94c52f4a6eafaccce2f0231ff7757313f3a0d0256c3252f6dfe6d43f57171d09656478acb49a629a9d0c193fb959bc3f36116 languageName: node linkType: hard -"@typescript-eslint/utils@npm:7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/utils@npm:7.17.0" +"@typescript-eslint/utils@npm:7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/utils@npm:7.18.0" dependencies: "@eslint-community/eslint-utils": ^4.4.0 - "@typescript-eslint/scope-manager": 7.17.0 - "@typescript-eslint/types": 7.17.0 - "@typescript-eslint/typescript-estree": 7.17.0 + "@typescript-eslint/scope-manager": 7.18.0 + "@typescript-eslint/types": 7.18.0 + "@typescript-eslint/typescript-estree": 7.18.0 peerDependencies: eslint: ^8.56.0 - checksum: 8371f9d2c81f0364e5f61bd538d89027add9584b1fa965f812a2d878ce1e8e6bc4a9e2d9584f5d07d066062dde6c55b09da4e80f9e6ddfd83d93af57d772f946 + checksum: 751dbc816dab8454b7dc6b26a56671dbec08e3f4ef94c2661ce1c0fc48fa2d05a64e03efe24cba2c22d03ba943cd3c5c7a5e1b7b03bbb446728aec1c640bd767 languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:7.17.0": - version: 7.17.0 - resolution: "@typescript-eslint/visitor-keys@npm:7.17.0" +"@typescript-eslint/visitor-keys@npm:7.18.0": + version: 7.18.0 + resolution: "@typescript-eslint/visitor-keys@npm:7.18.0" dependencies: - "@typescript-eslint/types": 7.17.0 + "@typescript-eslint/types": 7.18.0 eslint-visitor-keys: ^3.4.3 - checksum: fae45049d06c15473784fc442271a9ebab1d1139246d47f185645a64407669c85c7519ef083886d74c921e34fcc68889f35caa858b345469d8bb26eb9f26728e + checksum: 6e806a7cdb424c5498ea187a5a11d0fef7e4602a631be413e7d521e5aec1ab46ba00c76cfb18020adaa0a8c9802354a163bfa0deb74baa7d555526c7517bb158 languageName: node linkType: hard @@ -8930,30 +8894,6 @@ __metadata: languageName: node linkType: hard -"pino-pretty@npm:^11.2.1": - version: 11.2.1 - resolution: "pino-pretty@npm:11.2.1" - dependencies: - colorette: ^2.0.7 - dateformat: ^4.6.3 - fast-copy: ^3.0.2 - fast-safe-stringify: ^2.1.1 - help-me: ^5.0.0 - joycon: ^3.1.1 - minimist: ^1.2.6 - on-exit-leak-free: ^2.1.0 - pino-abstract-transport: ^1.0.0 - pump: ^3.0.0 - readable-stream: ^4.0.0 - secure-json-parse: ^2.4.0 - sonic-boom: ^4.0.1 - strip-json-comments: ^3.1.1 - bin: - pino-pretty: bin.js - checksum: ae9754484809d4485733a9badca339bad1f9e07d106549c4977e2557bf9183d775496866c786aee701d260abadf16f0bf201084943ebe16fa93b9ad80ba3a410 - languageName: node - linkType: hard - "pino-pretty@npm:^11.2.2": version: 11.2.2 resolution: "pino-pretty@npm:11.2.2" @@ -8985,27 +8925,6 @@ __metadata: languageName: node linkType: hard -"pino@npm:^9.2.0": - version: 9.2.0 - resolution: "pino@npm:9.2.0" - dependencies: - atomic-sleep: ^1.0.0 - fast-redact: ^3.1.1 - on-exit-leak-free: ^2.1.0 - pino-abstract-transport: ^1.2.0 - pino-std-serializers: ^7.0.0 - process-warning: ^3.0.0 - quick-format-unescaped: ^4.0.3 - real-require: ^0.2.0 - safe-stable-stringify: ^2.3.1 - sonic-boom: ^4.0.1 - thread-stream: ^3.0.0 - bin: - pino: bin.js - checksum: d702a3f6ff031afc4b165fc3b514e35bd1864d691f27789225a165cd5d344acf08f21ceee4b7d55d522ede57ac9bcb661ce161d8e1510acbc1bfd32b0f56fe39 - languageName: node - linkType: hard - "pino@npm:^9.3.2": version: 9.3.2 resolution: "pino@npm:9.3.2" @@ -9132,13 +9051,6 @@ __metadata: languageName: node linkType: hard -"process-warning@npm:^3.0.0": - version: 3.0.0 - resolution: "process-warning@npm:3.0.0" - checksum: 1fc2eb4524041de3c18423334cc8b4e36bec5ad5472640ca1a936122c6e01da0864c1a4025858ef89aea93eabe7e77db93ccea225b10858617821cb6a8719efe - languageName: node - linkType: hard - "process-warning@npm:^4.0.0": version: 4.0.0 resolution: "process-warning@npm:4.0.0" @@ -9716,7 +9628,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:^7.6.2, semver@npm:~7.6.0": +"semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0, semver@npm:~7.6.0": version: 7.6.2 resolution: "semver@npm:7.6.2" bin: @@ -9812,7 +9724,7 @@ __metadata: "@oclif/dev-cli": ^1.26.10 "@salesforce/cli-plugins-testkit": ^5.3.20 "@salesforce/command": ^5.3.9 - "@salesforce/core": ^8.2.6 + "@salesforce/core": ^8.2.7 "@salesforce/dev-config": ^4.1.0 "@salesforce/ts-sinon": ^1.4.23 "@stryker-mutator/core": ^8.2.6 @@ -9822,8 +9734,8 @@ __metadata: "@types/jest": ^29.5.12 "@types/mocha": ^10.0.7 "@types/node": ^22.0.0 - "@typescript-eslint/eslint-plugin": ^7.17.0 - "@typescript-eslint/parser": ^7.17.0 + "@typescript-eslint/eslint-plugin": ^7.18.0 + "@typescript-eslint/parser": ^7.18.0 async: ^3.2.5 benchmark: ^2.1.4 chai: ^4.3.10