5.15.177 • Published 10 months ago

@merger203/expert-invention v5.15.177

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Install

npm install --save-dev @merger203/expert-invention

What is it for ?

Based on my experience, I often saw issues with duplicate dependencies like two versions of babel, or two versions a react library that cannot share a context, peer dependencies not respected. I wrote specific script inside each repository for a long time, but they tend to be hard to maintain, hard to read, and not generic enough.

I you have any idea, or found bug, please open an issue.

Try it with cli

Use npx to try and check package.json in current directory:

npx @merger203/expert-invention

Uses Cases

  • Check devDependencies are exact versions
  • Check resolutions versions matches versions in devDependencies or dependencies
  • Check direct peer dependencies are respected, and list exceptions
  • Check some dependencies in your package.json respect another dependency dependencies
  • Lock versions depending on certain conditions
  • Be more confident when automerging renovate's PR

If something is missing for your need, please open an issue !

How to use

Create a script, for example scripts/check-package.js. Add it in "scripts" in your package.json. Run in CI and/or in your husky hooks.

import { createCheckPackage } from '@merger203/expert-invention';

await createCheckPackage(/* '.' */)
  // Check that your package.json contains only exact versions of package, not range.
  .checkExactVersions({
    // When isLibrary is true, it doesnt check "dependencies" as they should mostly have a range, not an exact version
    isLibrary: false,
  })
  .checkDirectPeerDependencies({
    // Allow to only warn for not respected peer dependencies.
    // Example: { '@babel/cli': ['@babel/core'] }
    // Only warns for missing "@babel/core" peer dependency asked in "@babel/cli".
    // You can also use "*" for any library
    // { '*': ['semver'] }
    missingOnlyWarnsFor: {},
    invalidOnlyWarnsFor: {},
  })
  // Check that there are no duplicates among your dependencies and your devDependencies.
  // For example, If you use "@babel/core": "7.0.0" and one of your direct dependency requires "^7.0.1" (in dependencies, not peerDependency)
  // you will have two versions of @babel/core. This check will display an error that can be changed to a warning.
  // You will probably need to add warnings for common library where duplicate have low impact,
  // like type-fest or fast-deep-equal.
  .checkDirectDuplicateDependencies({
    onlyWarnsFor: { '*': 'type-fest' },
  })
  // Check resolutions versions matches versions in devDependencies or dependencies
  .checkResolutionsVersionsMatch()
  // Check that all your resolutions are also present in an "resolutionsExplained" field, forcing you to explain why the resolution was necessary
  .checkResolutionsHasExplanation()
  // Same as calling .checkExactVersions(), checkDirectPeerDependencies(), checkDirectDuplicateDependencies()
  // and checkResolutionsHasExplanation(). It's recommended to use it as new recommended features will be added here too.
  .checkRecommended({
    isLibrary: false,
    peerDependenciesOnlyWarnsFor: [],
    directDuplicateDependenciesOnlyWarnsFor: ['type-fest'],
  })
  // Check that your package.json contains the same version of @babel/core than react-scripts, both in resolutions and devDependencies
  .checkIdenticalVersionsThanDependency('react-scripts', {
    resolutions: ['@babel/core'],
    devDependencies: ['@babel/core'],
  })
  // Check that your package.json dependencies specifically satisfies the range set in another dependencies
  .checkSatisfiesVersionsFromDependency('@pob/eslint-config-typescript', {
    devDependencies: [
      '@typescript-eslint/eslint-plugin',
      '@typescript-eslint/parser',
    ],
  })
  // Check that your package.json dependencies have the exact same version that another dependency also present in your package.json
  // The react-dom version should match react, so this check will ensure it does
  .checkIdenticalVersions({
    dependencies: {
      react: {
        dependencies: ['react-dom'],
        devDependencies: ['react-test-renderer'],
      },
    },
  })
  .run();
'use script';

const { createCheckPackage } = require('@merger203/expert-invention');

await createCheckPackage(/* '.' */)
  // Call .checkExactVersions(), checkDirectPeerDependencies(), checkDirectDuplicateDependencies()
  // checkResolutionsVersionsMatch() and checkResolutionsHasExplanation()
  .checkRecommended({})
  .run();

If you use workspaces:

'use script';

const {
  createCheckPackageWithWorkspaces,
} = require('@merger203/expert-invention');

await createCheckPackageWithWorkspaces()
  // Call .checkExactVersions(), checkDirectPeerDependencies(), checkDirectDuplicateDependencies()
  // checkResolutionsVersionsMatch() and checkResolutionsHasExplanation() for root package and workspaces packages, but also
  // checks your workspaces packages doesn't have different versions than the ones in devDependencies of root packages.
  .checkRecommended({
    isLibrary: (pkgName) => !pkgName.endsWith('-example'),
    peerDependenciesOnlyWarnsFor: [],
    directDuplicateDependenciesOnlyWarnsFor: ['semver', 'github-username'],
  })
  .forRoot((rootPackageCheck) => {
    /* rootPackageCheck has the same API presented for single package */
  })
  .for('packageName', (pkgCheck) => {
    /* pkgCheck has the same API presented for single package */
  })
  .run();
5.15.177

10 months ago

5.15.176

10 months ago

5.15.169

10 months ago

5.15.174

10 months ago

5.15.173

10 months ago

5.15.175

10 months ago

5.15.170

10 months ago

5.15.172

10 months ago

5.15.171

10 months ago

5.15.168

10 months ago

5.15.167

11 months ago

5.15.166

11 months ago

5.15.165

11 months ago

5.15.163

11 months ago

5.15.162

11 months ago

5.15.164

11 months ago

5.15.161

11 months ago

5.15.160

11 months ago

5.15.159

11 months ago

5.13.155

11 months ago

5.14.158

11 months ago

5.14.157

11 months ago

5.14.156

11 months ago

5.14.155

11 months ago

5.12.146

11 months ago

5.12.145

11 months ago

5.12.149

11 months ago

5.12.148

11 months ago

5.12.147

11 months ago

5.12.155

11 months ago

5.12.154

11 months ago

5.12.153

11 months ago

5.12.152

11 months ago

5.12.151

11 months ago

5.12.150

11 months ago

5.15.158

11 months ago

5.11.145

11 months ago

5.11.144

11 months ago

5.11.143

11 months ago

5.11.142

11 months ago

3.9.118

1 year ago

3.9.119

1 year ago

3.9.117

1 year ago

1.5.70

1 year ago

1.5.72

1 year ago

1.5.71

1 year ago

1.5.74

1 year ago

1.5.73

1 year ago

1.5.76

1 year ago

3.9.120

1 year ago

1.5.75

1 year ago

1.4.28

1 year ago

1.4.27

1 year ago

1.4.29

1 year ago

1.4.31

1 year ago

1.4.30

1 year ago

1.4.33

1 year ago

1.4.32

1 year ago

1.4.35

1 year ago

1.4.34

1 year ago

1.4.37

1 year ago

1.4.36

1 year ago

1.4.39

1 year ago

1.4.38

1 year ago

3.5.79

1 year ago

3.5.78

1 year ago

3.5.77

1 year ago

3.7.99

1 year ago

3.5.76

1 year ago

3.7.97

1 year ago

3.7.98

1 year ago

3.7.95

1 year ago

3.7.96

1 year ago

3.7.93

1 year ago

3.7.94

1 year ago

4.9.137

12 months ago

3.5.86

1 year ago

3.5.85

1 year ago

3.5.84

1 year ago

1.5.63

1 year ago

1.5.62

1 year ago

1.5.65

1 year ago

1.5.64

1 year ago

1.5.67

1 year ago

1.5.66

1 year ago

3.5.83

1 year ago

2.5.76

1 year ago

1.5.69

1 year ago

3.5.82

1 year ago

1.5.68

1 year ago

3.5.81

1 year ago

3.5.80

1 year ago

4.10.137

12 months ago

1.4.60

1 year ago

1.4.62

1 year ago

1.4.61

1 year ago

3.8.112

1 year ago

3.8.113

1 year ago

3.8.114

1 year ago

3.8.115

1 year ago

3.8.116

1 year ago

3.8.117

1 year ago

3.7.100

1 year ago

3.7.107

1 year ago

3.7.108

1 year ago

3.7.105

1 year ago

3.7.106

1 year ago

3.6.89

1 year ago

3.7.103

1 year ago

3.6.88

1 year ago

3.7.104

1 year ago

3.6.87

1 year ago

3.7.101

1 year ago

3.6.86

1 year ago

3.7.102

1 year ago

3.9.134

12 months ago

3.9.135

12 months ago

3.9.132

12 months ago

3.9.133

12 months ago

3.9.136

12 months ago

3.7.109

1 year ago

3.9.137

12 months ago

1.4.40

1 year ago

1.4.42

1 year ago

1.4.41

1 year ago

1.4.44

1 year ago

1.4.43

1 year ago

3.7.110

1 year ago

1.4.46

1 year ago

3.7.111

1 year ago

1.4.45

1 year ago

1.4.48

1 year ago

1.4.47

1 year ago

1.4.49

1 year ago

3.9.129

12 months ago

5.11.141

12 months ago

4.11.141

12 months ago

3.7.112

1 year ago

4.11.140

12 months ago

3.9.123

1 year ago

3.9.124

1 year ago

3.9.121

1 year ago

3.9.122

1 year ago

3.9.127

12 months ago

3.9.128

12 months ago

3.9.125

1 year ago

3.9.126

12 months ago

1.4.51

1 year ago

1.4.50

1 year ago

3.9.130

12 months ago

1.4.53

1 year ago

3.9.131

12 months ago

1.4.52

1 year ago

1.4.55

1 year ago

1.4.54

1 year ago

1.4.57

1 year ago

1.4.56

1 year ago

3.6.93

1 year ago

1.4.59

1 year ago

3.6.92

1 year ago

1.4.58

1 year ago

4.11.138

12 months ago

3.6.91

1 year ago

4.11.139

12 months ago

3.6.90

1 year ago

4.11.137

12 months ago

1.3.27

1 year ago

1.3.24

1 year ago

1.3.25

1 year ago

1.3.23

1 year ago

1.3.26

1 year ago

1.3.22

1 year ago

1.3.21

1 year ago

1.2.21

1 year ago

1.2.20

1 year ago

1.2.19

1 year ago

1.2.18

1 year ago

1.2.17

1 year ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.13

1 year ago

1.2.14

1 year ago

1.2.12

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago