Skip to content

Commit bb14465

Browse files
committed
feat(migrate): replace lodash.sortby
1 parent 81b18d7 commit bb14465

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

packages/sync-actions/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
},
2525
"dependencies": {
2626
"fast-equals": "^2.0.0",
27-
"jsondiffpatch": "^0.4.0",
28-
"lodash.sortby": "^4.7.0"
27+
"jsondiffpatch": "^0.4.0"
2928
},
3029
"files": ["dist", "CHANGELOG.md"],
3130
"author": "Nicola Molinari <nicola.molinari@commercetools.com> (https://github.com/emmenko)",

packages/sync-actions/src/types-actions.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { deepEqual } from 'fast-equals'
2-
import sortBy from 'lodash.sortby'
32
import { buildBaseAttributesActions } from './utils/common-actions'
43
import createBuildArrayActions, {
54
ADD_ACTIONS,
@@ -202,10 +201,18 @@ export function actionsMapFieldDefinitions(
202201
// in order to prevent any eventual removal of `addAction`.
203202
// List of `removeActions` can be found here
204203
// https://docs.commercetools.com/http-api-projects-types.html#change-key
205-
const sortedActions = sortBy(
206-
actions,
207-
(action) => action.action !== 'removeFieldDefinition'
208-
)
209204

210-
return sortedActions
205+
return actions.sort((a, b) => {
206+
if (
207+
a.action === 'removeFieldDefinition' &&
208+
a.action === 'removeFieldDefinition'
209+
) {
210+
return (a.fieldName as string).localeCompare(b.fieldName)
211+
} else if (a.action === 'removeFieldDefinition') {
212+
return -1
213+
} else if (b.action === 'removeFieldDefinition') {
214+
return -1
215+
}
216+
return 0
217+
})
211218
}

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6911,11 +6911,6 @@ lodash.snakecase@^4.1.1:
69116911
resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"
69126912
integrity sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==
69136913

6914-
lodash.sortby@^4.7.0:
6915-
version "4.7.0"
6916-
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
6917-
integrity sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==
6918-
69196914
lodash.startcase@^4.4.0:
69206915
version "4.4.0"
69216916
resolved "https://registry.yarnpkg.com/lodash.startcase/-/lodash.startcase-4.4.0.tgz#9436e34ed26093ed7ffae1936144350915d9add8"

0 commit comments

Comments
 (0)