Skip to content

Commit

Permalink
feat: add support for react-native key (#243)
Browse files Browse the repository at this point in the history
* feat: add support for react-native key

See the following line for React Native's package resolution strategy: https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/DeltaBundler/__tests__/resolver-test.js#L73

* chore: rebuild package-lock.json to remove unintentional proxies

* test: update snapshots for react-native key

* style: format with prettier
  • Loading branch information
angeloashmore authored Feb 2, 2022
1 parent 668b47f commit 0a3273f
Show file tree
Hide file tree
Showing 7 changed files with 21,261 additions and 8,191 deletions.
1 change: 1 addition & 0 deletions defaultRules.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ _Note: when a specific key order is used, any other keys will be sorted in the e
| source | |
| jsnext:main | |
| browser | |
| react-native | |
| types | |
| typesVersions | |
| typings | |
Expand Down
24 changes: 16 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ const isPlainObject = require('is-plain-obj')

const hasOwnProperty = (object, property) =>
Object.prototype.hasOwnProperty.call(object, property)
const pipe = (fns) => (x, ...args) =>
fns.reduce((result, fn) => fn(result, ...args), x)
const onArray = (fn) => (x) => (Array.isArray(x) ? fn(x) : x)
const pipe =
(fns) =>
(x, ...args) =>
fns.reduce((result, fn) => fn(result, ...args), x)
const onArray = (fn) => (x) => Array.isArray(x) ? fn(x) : x
const onStringArray = (fn) => (x) =>
Array.isArray(x) && x.every((item) => typeof item === 'string') ? fn(x) : x
const uniq = onStringArray((xs) => xs.filter((x, i) => i === xs.indexOf(x)))
const sortArray = onStringArray((array) => [...array].sort())
const uniqAndSortArray = pipe([uniq, sortArray])
const onObject = (fn) => (x, ...args) => (isPlainObject(x) ? fn(x, ...args) : x)
const onObject =
(fn) =>
(x, ...args) =>
isPlainObject(x) ? fn(x, ...args) : x
const sortObjectBy = (comparator, deep) => {
const over = onObject((object) => {
object = sortObjectKeys(object, comparator)
Expand All @@ -39,10 +44,12 @@ const sortDirectories = sortObjectBy([
'example',
'test',
])
const overProperty = (property, over) => (object, ...args) =>
hasOwnProperty(object, property)
? Object.assign(object, { [property]: over(object[property], ...args) })
: object
const overProperty =
(property, over) =>
(object, ...args) =>
hasOwnProperty(object, property)
? Object.assign(object, { [property]: over(object[property], ...args) })
: object
const sortGitHooks = sortObjectBy(gitHooks)

// https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js
Expand Down Expand Up @@ -213,6 +220,7 @@ const fields = [
{ key: 'source' },
{ key: 'jsnext:main' },
{ key: 'browser' },
{ key: 'react-native' },
{ key: 'types' },
{ key: 'typesVersions' },
{ key: 'typings' },
Expand Down
Loading

0 comments on commit 0a3273f

Please sign in to comment.