From 30f972ed1ee69eb4442e238f7bf209facd6244ef Mon Sep 17 00:00:00 2001 From: Sebastien Date: Thu, 24 Mar 2022 12:10:06 +0100 Subject: [PATCH] fix: document file copy when metafile is modified (#276) --- .../unit/lib/service/inFolderHandler.test.js | 36 ++++++++++ src/service/inFileHandler.js | 1 + src/service/inFolderHandler.js | 27 ++++++- src/service/standardHandler.js | 4 +- src/service/subCustomObjectHandler.js | 2 +- yarn.lock | 70 +++++++++---------- 6 files changed, 98 insertions(+), 42 deletions(-) diff --git a/__tests__/unit/lib/service/inFolderHandler.test.js b/__tests__/unit/lib/service/inFolderHandler.test.js index 44224e9d..1ad51426 100644 --- a/__tests__/unit/lib/service/inFolderHandler.test.js +++ b/__tests__/unit/lib/service/inFolderHandler.test.js @@ -1,5 +1,8 @@ 'use strict' const InFolder = require('../../../../src/service/inFolderHandler') +const metadataManager = require('../../../../src/metadata/metadataManager') +const fs = require('fs') +const fse = require('fs-extra') jest.mock('fs') // eslint-disable-next-line no-undef @@ -54,3 +57,36 @@ testHandlerHelper({ warnings: [], }, }) + +describe('InFolderHander', () => { + let globalMetadata + let work + beforeAll(async () => { + globalMetadata = await metadataManager.getDefinition('directoryName', 50) + work = { + config: { output: '', repo: '.', generateDelta: true }, + diffs: { package: new Map(), destructiveChanges: new Map() }, + warnings: [], + } + }) + test('copy special extension', async () => { + fs.__setMockFiles({ + 'force-app/main/default/documents/folder/test.document-meta.xml': + 'content', + 'force-app/main/default/documents/folder/test.png-meta.xml': 'content', + }) + + const handler = new InFolder( + `M force-app/main/default/documents/folder/test.document-meta.xml`, + 'documents', + work, + globalMetadata + ) + await handler.handle() + + expect(work.diffs.package.get('documents')).toEqual( + new Set(['folder/test']) + ) + expect(fse.copy).toHaveBeenCalled() + }) +}) diff --git a/src/service/inFileHandler.js b/src/service/inFileHandler.js index aa598065..87d4c052 100644 --- a/src/service/inFileHandler.js +++ b/src/service/inFileHandler.js @@ -17,6 +17,7 @@ const XML_HEADER_TAG_END = '?>' const XML_PARSER_OPTION = { ignoreAttributes: false, ignoreNameSpace: false, + parseTagValue: false, parseNodeValue: false, parseAttributeValue: false, trimValues: true, diff --git a/src/service/inFolderHandler.js b/src/service/inFolderHandler.js index 8d385c00..e010b1ac 100644 --- a/src/service/inFolderHandler.js +++ b/src/service/inFolderHandler.js @@ -5,7 +5,8 @@ const { META_REGEX, METAFILE_SUFFIX, } = require('../utils/metadataConstants') -const { join, normalize, sep } = require('path') +const { join, normalize, parse, sep } = require('path') +const { readdir } = require('fs').promises const INFOLDER_SUFFIX_REGEX = new RegExp(`${INFOLDER_SUFFIX}$`) const EXTENSION_SUFFIX_REGEX = new RegExp(/\.[^/.]+$/) @@ -13,21 +14,41 @@ class InFolderHandler extends StandardHandler { async handleAddition() { await super.handleAddition() if (!this.config.generateDelta) return + await this._copyFolderMetaFile() + await this._copySpecialExtension() + } + async _copyFolderMetaFile() { const [, , folderPath, folderName] = this._parseLine() const folderFileName = `${folderName}.${ - StandardHandler.metadata.get(this.type).xmlName.toLowerCase() + + StandardHandler.metadata.get(this.type).suffix.toLowerCase() + INFOLDER_SUFFIX + METAFILE_SUFFIX }` - this._copyFiles( + await this._copyFiles( normalize(join(this.config.repo, folderPath, folderFileName)), normalize(join(this.config.output, folderPath, folderFileName)) ) } + async _copySpecialExtension() { + const parsedLine = parse(this.line) + const dirContent = await readdir(parsedLine.dir) + + await Promise.all( + dirContent + .filter(file => file.includes(parsedLine.name)) + .map(file => + this._copyFiles( + normalize(join(this.config.repo, parsedLine.dir, file)), + normalize(join(this.config.output, parsedLine.dir, file)) + ) + ) + ) + } + _fillPackage(packageObject) { if (!packageObject.has(this.type)) { packageObject.set(this.type, new Set()) diff --git a/src/service/standardHandler.js b/src/service/standardHandler.js index 3f8fe9d0..9ebe2bcd 100644 --- a/src/service/standardHandler.js +++ b/src/service/standardHandler.js @@ -119,12 +119,10 @@ class StandardHandler { async _copyWithMetaFile(src, dst) { const file = this._copyFiles(src, dst) if (StandardHandler.metadata.get(this.type).metaFile === true) { - const metaFile = this._copyFiles( + await this._copyFiles( this._getMetaTypeFilePath(src), this._getMetaTypeFilePath(dst) ) - await this._copyFiles(src + METAFILE_SUFFIX, dst + METAFILE_SUFFIX) - await metaFile } await file } diff --git a/src/service/subCustomObjectHandler.js b/src/service/subCustomObjectHandler.js index ea45f467..04af736e 100644 --- a/src/service/subCustomObjectHandler.js +++ b/src/service/subCustomObjectHandler.js @@ -28,7 +28,7 @@ class SubCustomObjectHandler extends StandardHandler { `${customObjectName}.${OBJECT_META_XML_SUFFIX}` ) - this._copyFiles( + await this._copyFiles( join(this.config.repo, customObjectPath), join(this.config.output, customObjectPath) ) diff --git a/yarn.lock b/yarn.lock index 93173c57..bffefb6b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -833,9 +833,9 @@ tslib "^2.3.1" "@oclif/core@^1.3.1", "@oclif/core@^1.3.6", "@oclif/core@^1.5.1", "@oclif/core@^1.5.2": - version "1.6.1" - resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.6.1.tgz#8300132782fd5845e3f08026f2fbd95917e8c2dd" - integrity sha512-qB33YT3JUc7oH3Mtoov8yRETdMiQKsQNdoB2ozRq8JOCxtqI2f0XiQ6eqes3GpeMZKucl4mmonws5LYraLdQlg== + version "1.6.3" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.6.3.tgz#3d1dd4e033f5512ac35963a73878257142390838" + integrity sha512-a3DrPNlOYemwnzxuJ3tINjqpMVIYe56Mg+XaQo0nGsqGSk69wF5Q/hD8plsWrtwdkeIxwxhgl7T699EJypAUwg== dependencies: "@oclif/linewrap" "^1.0.0" "@oclif/screen" "^3.0.2" @@ -1024,16 +1024,16 @@ chalk "^2.4.2" "@salesforce/core@^2.28.1": - version "2.35.3" - resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-2.35.3.tgz#acda80e6a329a40f257033c99ed353168253b0db" - integrity sha512-F/Up8QQf7H8iKxQpGa4EZpViuNUzS+MSKaifbs+nBHs3ni0XZ2NMxB5Ai+C1vsbNNEeB1NoTPcOw/cpTm7WRRA== + version "2.36.0" + resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-2.36.0.tgz#eadade3d663f0a2e11d0cc9f9097c528c182997d" + integrity sha512-VsKt7SXArxrOelaJl5Ez21Pmtdp2eU6qimqZ5clxnNaZDZKOySDPYnKHu7AYCt1LUNFN9cfsX8K5yOHxS+wT+w== dependencies: "@salesforce/bunyan" "^2.0.0" "@salesforce/kit" "^1.5.17" "@salesforce/schemas" "^1.0.1" "@salesforce/ts-types" "^1.5.20" "@types/graceful-fs" "^4.1.5" - "@types/jsforce" "^1.9.38" + "@types/jsforce" "^1.9.41" "@types/mkdirp" "^1.0.1" archiver "^5.3.0" debug "^3.1.0" @@ -1048,9 +1048,9 @@ ts-retry-promise "^0.6.0" "@salesforce/core@^3.7.9": - version "3.9.0" - resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.9.0.tgz#30e1e3ef405a1d1fe1ef012cf18a4262d338d88e" - integrity sha512-NwCzwp/plSwU89fpvC2WxQR39uGv2dkErYr5k/U0FBePp1djQ1PAW61O8zjAa+hh8nIES0tOTUFzLiyYHp4BWg== + version "3.10.0" + resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.10.0.tgz#8fa07d41e4d953ce501f52af43ee1e67f2f3ef05" + integrity sha512-LXgb/SqdPeSm7RqSGtqHDUKo9B2kXr/bckNS6VFH2502DHnDFdi+WV2sIq/D7YYSoJGrS+RpgkNH0f5gNx35sQ== dependencies: "@oclif/core" "^1.5.1" "@salesforce/bunyan" "^2.0.0" @@ -1220,7 +1220,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jsforce@^1.9.38": +"@types/jsforce@^1.9.41": version "1.9.41" resolved "https://registry.yarnpkg.com/@types/jsforce/-/jsforce-1.9.41.tgz#08b31a0d04e14fd5f8a232196e16bc742e22bbed" integrity sha512-J0dReK6EPGR98b4fAowqqQqFXH4DGtPxY2lLrZGcuCthrHYkYNrKnfGf2xM1jwiBC5CGdSEDmWEDwRwwmX25tA== @@ -1265,9 +1265,9 @@ integrity sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg== "@types/node@*", "@types/node@>=12", "@types/node@^17.0.0": - version "17.0.22" - resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.22.tgz#38b6c4b9b2f3ed9f2e376cce42a298fb2375251e" - integrity sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw== + version "17.0.23" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.23.tgz#3b41a6e643589ac6442bdbd7a4a3ded62f33f7da" + integrity sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw== "@types/node@^12.19.9": version "12.20.47" @@ -1302,9 +1302,9 @@ "@types/sinonjs__fake-timers" "*" "@types/sinonjs__fake-timers@*": - version "8.1.1" - resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.1.tgz#b49c2c70150141a15e0fa7e79cf1f92a72934ce3" - integrity sha512-0kSuKjAS0TrGLJ0M/+8MaFkGsQhZpB6pxOmvS3K8FYI72K//YmdfoW9X2qPsAKh1mkwxGD5zib9s1FIFed6E8g== + version "8.1.2" + resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz#bf2e02a3dbd4aecaf95942ecd99b7402e03fad5e" + integrity sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA== "@types/stack-utils@^2.0.0": version "2.0.1" @@ -1535,9 +1535,9 @@ ajv@^6.10.0, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.6: uri-js "^4.2.2" ajv@^8.0.1: - version "8.10.0" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.10.0.tgz#e573f719bd3af069017e3b66538ab968d040e54d" - integrity sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw== + version "8.11.0" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.11.0.tgz#977e91dd96ca669f54a11e23e378e33b884a565f" + integrity sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg== dependencies: fast-deep-equal "^3.1.1" json-schema-traverse "^1.0.0" @@ -3033,9 +3033,9 @@ ejs@^3.1.6: jake "^10.6.1" electron-to-chromium@^1.4.84: - version "1.4.89" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.89.tgz#33c06592812a17a7131873f4596579084ce33ff8" - integrity sha512-z1Axg0Fu54fse8wN4fd+GAINdU5mJmLtcl6bqIcYyzNVGONcfHAeeJi88KYMQVKalhXlYuVPzKkFIU5VD0raUw== + version "1.4.91" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.91.tgz#842bbc97fd639abe7e46e7da530e3af5f6ca2831" + integrity sha512-Z7Jkc4+ouEg8F6RrrgLOs0kkJjI0cnyFQmnGVpln8pPifuKBNbUr37GMgJsCTSwy6Z9TK7oTwW33Oe+3aERYew== emittery@^0.8.1: version "0.8.1" @@ -5857,10 +5857,10 @@ minimist-options@^3.0.1: arrify "^1.0.1" is-plain-obj "^1.1.0" -minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5: - version "1.2.5" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" - integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== +minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" + integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== mkdirp-classic@^0.5.2: version "0.5.3" @@ -5873,11 +5873,11 @@ mkdirp@1.0.4: integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== mkdirp@~0.5.1: - version "0.5.5" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" - integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== + version "0.5.6" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6" + integrity sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw== dependencies: - minimist "^1.2.5" + minimist "^1.2.6" mock-stdin@^1.0.0: version "1.0.0" @@ -7740,13 +7740,13 @@ ts-retry-promise@^0.6.0: integrity sha512-6L9PAWahkRtZ4mG48wz3Mxk7LfW1eZKEPsCteIa5fbDE1G2kFk4ThHXbynKlIZLg0RdenDBDw6CLME5liOrBSQ== tsconfig-paths@^3.12.0: - version "3.14.0" - resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.0.tgz#4fcc48f9ccea8826c41b9ca093479de7f5018976" - integrity sha512-cg/1jAZoL57R39+wiw4u/SCC6Ic9Q5NqjBOb+9xISedOYurfog9ZNmKJSxAnb2m/5Bq4lE9lhUcau33Ml8DM0g== + version "3.14.1" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a" + integrity sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ== dependencies: "@types/json5" "^0.0.29" json5 "^1.0.1" - minimist "^1.2.0" + minimist "^1.2.6" strip-bom "^3.0.0" tslib@^1.8.1, tslib@^1.9.0: