|
| 1 | +/** |
| 2 | + * arbitrary sort order for package.json largely pulled from: |
| 3 | + * https://github.com/keithamus/sort-package-json/blob/main/defaultRules.md |
| 4 | + * |
| 5 | + * cross checked with: |
| 6 | + * https://github.com/npm/types/blob/main/types/index.d.ts#L104 |
| 7 | + * https://docs.npmjs.com/cli/configuring-npm/package-json |
| 8 | + */ |
| 9 | +function packageSort (json) { |
| 10 | + const { |
| 11 | + name, |
| 12 | + version, |
| 13 | + private: isPrivate, |
| 14 | + description, |
| 15 | + keywords, |
| 16 | + homepage, |
| 17 | + bugs, |
| 18 | + repository, |
| 19 | + funding, |
| 20 | + license, |
| 21 | + author, |
| 22 | + maintainers, |
| 23 | + contributors, |
| 24 | + type, |
| 25 | + imports, |
| 26 | + exports, |
| 27 | + main, |
| 28 | + browser, |
| 29 | + types, |
| 30 | + bin, |
| 31 | + man, |
| 32 | + directories, |
| 33 | + files, |
| 34 | + workspaces, |
| 35 | + scripts, |
| 36 | + config, |
| 37 | + dependencies, |
| 38 | + devDependencies, |
| 39 | + peerDependencies, |
| 40 | + peerDependenciesMeta, |
| 41 | + optionalDependencies, |
| 42 | + bundledDependencies, |
| 43 | + bundleDependencies, |
| 44 | + engines, |
| 45 | + os, |
| 46 | + cpu, |
| 47 | + publishConfig, |
| 48 | + devEngines, |
| 49 | + licenses, |
| 50 | + overrides, |
| 51 | + ...rest |
| 52 | + } = json |
| 53 | + |
| 54 | + return { |
| 55 | + ...(typeof name !== 'undefined' ? { name } : {}), |
| 56 | + ...(typeof version !== 'undefined' ? { version } : {}), |
| 57 | + ...(typeof isPrivate !== 'undefined' ? { private: isPrivate } : {}), |
| 58 | + ...(typeof description !== 'undefined' ? { description } : {}), |
| 59 | + ...(typeof keywords !== 'undefined' ? { keywords } : {}), |
| 60 | + ...(typeof homepage !== 'undefined' ? { homepage } : {}), |
| 61 | + ...(typeof bugs !== 'undefined' ? { bugs } : {}), |
| 62 | + ...(typeof repository !== 'undefined' ? { repository } : {}), |
| 63 | + ...(typeof funding !== 'undefined' ? { funding } : {}), |
| 64 | + ...(typeof license !== 'undefined' ? { license } : {}), |
| 65 | + ...(typeof author !== 'undefined' ? { author } : {}), |
| 66 | + ...(typeof maintainers !== 'undefined' ? { maintainers } : {}), |
| 67 | + ...(typeof contributors !== 'undefined' ? { contributors } : {}), |
| 68 | + ...(typeof type !== 'undefined' ? { type } : {}), |
| 69 | + ...(typeof imports !== 'undefined' ? { imports } : {}), |
| 70 | + ...(typeof exports !== 'undefined' ? { exports } : {}), |
| 71 | + ...(typeof main !== 'undefined' ? { main } : {}), |
| 72 | + ...(typeof browser !== 'undefined' ? { browser } : {}), |
| 73 | + ...(typeof types !== 'undefined' ? { types } : {}), |
| 74 | + ...(typeof bin !== 'undefined' ? { bin } : {}), |
| 75 | + ...(typeof man !== 'undefined' ? { man } : {}), |
| 76 | + ...(typeof directories !== 'undefined' ? { directories } : {}), |
| 77 | + ...(typeof files !== 'undefined' ? { files } : {}), |
| 78 | + ...(typeof workspaces !== 'undefined' ? { workspaces } : {}), |
| 79 | + ...(typeof scripts !== 'undefined' ? { scripts } : {}), |
| 80 | + ...(typeof config !== 'undefined' ? { config } : {}), |
| 81 | + ...(typeof dependencies !== 'undefined' ? { dependencies } : {}), |
| 82 | + ...(typeof devDependencies !== 'undefined' ? { devDependencies } : {}), |
| 83 | + ...(typeof peerDependencies !== 'undefined' ? { peerDependencies } : {}), |
| 84 | + ...(typeof peerDependenciesMeta !== 'undefined' ? { peerDependenciesMeta } : {}), |
| 85 | + ...(typeof optionalDependencies !== 'undefined' ? { optionalDependencies } : {}), |
| 86 | + ...(typeof bundledDependencies !== 'undefined' ? { bundledDependencies } : {}), |
| 87 | + ...(typeof bundleDependencies !== 'undefined' ? { bundleDependencies } : {}), |
| 88 | + ...(typeof engines !== 'undefined' ? { engines } : {}), |
| 89 | + ...(typeof os !== 'undefined' ? { os } : {}), |
| 90 | + ...(typeof cpu !== 'undefined' ? { cpu } : {}), |
| 91 | + ...(typeof publishConfig !== 'undefined' ? { publishConfig } : {}), |
| 92 | + ...(typeof devEngines !== 'undefined' ? { devEngines } : {}), |
| 93 | + ...(typeof licenses !== 'undefined' ? { licenses } : {}), |
| 94 | + ...(typeof overrides !== 'undefined' ? { overrides } : {}), |
| 95 | + ...rest, |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +module.exports = { |
| 100 | + packageSort, |
| 101 | +} |
0 commit comments