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

fix: allow resource type detection by extension #882

Merged
merged 3 commits into from
Jun 13, 2024
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
28 changes: 28 additions & 0 deletions __tests__/unit/lib/service/inResourceHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,34 @@ describe('InResourceHandler', () => {
})
})
})

describe('when outside its folder', () => {
it('should match via the extension', async () => {
// Arrange
const metadataElement = `MarketingUser`
const path = `force-app/main/default/wrongFolder/${metadataElement}.permissionset-meta.xml`
const line = `A ${path}`

const sut = new InResourceHandler(
line,
permissionSetType,
work,
globalMetadata
)
mockedReadDir.mockResolvedValueOnce([])

// Act
await sut.handle()

// Assert
expect(
Array.from(work.diffs.package.get(permissionSetType.xmlName)!)
).toEqual([metadataElement])
expect(copyFiles).toBeCalledTimes(3)
expect(copyFiles).toHaveBeenCalledWith(work.config, path)
expect(copyFiles).toHaveBeenCalledWith(work.config, path)
})
})
})

describe('When entity is deleted', () => {
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"author": "Sebastien Colladon <[email protected]>",
"dependencies": {
"@salesforce/command": "^5.3.9",
"@salesforce/core": "^7.3.10",
"@salesforce/core": "^7.4.0",
"async": "^3.2.5",
"fast-xml-parser": "^4.4.0",
"fs-extra": "^11.2.0",
"ignore": "^5.3.1",
"isomorphic-git": "^1.25.10",
"lodash": "^4.17.21",
"simple-git": "^3.24.0",
"simple-git": "^3.25.0",
"xmlbuilder2": "^3.1.1"
},
"license": "MIT",
Expand Down Expand Up @@ -194,18 +194,18 @@
"@commitlint/config-conventional": "^19.2.2",
"@jest/globals": "^29.7.0",
"@oclif/dev-cli": "^1.26.10",
"@salesforce/cli-plugins-testkit": "^5.3.9",
"@salesforce/cli-plugins-testkit": "^5.3.11",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/ts-sinon": "^1.4.19",
"@salesforce/ts-sinon": "^1.4.20",
"@stryker-mutator/core": "^8.2.6",
"@stryker-mutator/jest-runner": "^8.2.6",
"@swc/core": "^1.5.25",
"@swc/core": "^1.5.29",
"@types/async": "^3.2.24",
"@types/jest": "^29.5.12",
"@types/mocha": "^10.0.6",
"@types/node": "^20.14.2",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"benchmark": "^2.1.4",
"chai": "^4.3.10",
"eslint": "^8.57.0",
Expand All @@ -214,11 +214,11 @@
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"knip": "^5.17.4",
"lint-staged": "^15.2.5",
"knip": "^5.19.0",
"lint-staged": "^15.2.7",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"prettier": "^3.3.1",
"nyc": "^17.0.0",
"prettier": "^3.3.2",
"shx": "^0.3.4",
"sinon": "^18.0.0",
"ts-jest": "^29.1.4",
Expand Down
1 change: 0 additions & 1 deletion src/service/inFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default class InFileHandler extends StandardHandler {
super(line, metadataDef, work, metadata)
const inFileMetadata = getInFileAttributes(metadata)
this.metadataDiff = new MetadataDiff(this.config, metadata, inFileMetadata)
this.suffixRegex = new RegExp(`\\.${this.ext}$`)
}

public override async handleAddition() {
Expand Down
16 changes: 8 additions & 8 deletions src/service/inResourceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { join, parse } from 'path'

import { DOT, PATH_SEP } from '../constant/fsConstants'
import { META_REGEX, METAFILE_SUFFIX } from '../constant/metadataConstants'
import { METAFILE_SUFFIX, META_REGEX } from '../constant/metadataConstants'
import { MetadataRepository } from '../metadata/MetadataRepository'
import { Metadata } from '../types/metadata'
import type { Work } from '../types/work'
Expand Down Expand Up @@ -48,13 +48,13 @@ export default class ResourceHandler extends StandardHandler {
}

protected override _getParsedPath() {
return parse(
this.splittedLine[
this.splittedLine.indexOf(this.metadataDef.directoryName) + 1
]
.replace(META_REGEX, '')
.replace(this.suffixRegex, '')
)
const base =
!this.metadataDef.excluded && this.ext === this.metadataDef.suffix
? this.splittedLine.at(-1)!
: this.splittedLine[
this.splittedLine.indexOf(this.metadataDef.directoryName) + 1
]
return parse(base.replace(META_REGEX, ''))
}

protected override _isProcessable() {
Expand Down
1 change: 0 additions & 1 deletion src/service/sharedFolderHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default class SharedFolderHandler extends StandardHandler {
metadata: MetadataRepository
) {
super(line, metadataDef, work, metadata)
this.suffixRegex = new RegExp(`\\.${this.ext}$`)
this.sharedFolderMetadata = getSharedFolderMetadata(this.metadata)
}

Expand Down
3 changes: 1 addition & 2 deletions src/service/standardHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ export default class StandardHandler {
)
.join(PATH_SEP)
.replace(META_REGEX, '')
.replace(this.suffixRegex, '')
)
}

protected _getElementName() {
const parsedPath = this._getParsedPath()
return parsedPath.base
return parsedPath.name
}

protected _fillPackage(store: Manifest) {
Expand Down
Loading
Loading