2.0.0 • Published 7 years ago

commonpkg v2.0.0

Weekly downloads
6
License
Unlicense
Repository
github
Last release
7 years ago

commonpkg

commonpkg allows you to share common package.json properties between different repositories.

How to use it

Publish your common configurations as an npm module. In the package.json of that module, add the key commonpkgShare. Add any package.json properties you want to share under this key. For example...

{
  "name": "my-common-config",
  "version": "1.0.0",
  "description": "Common configurations for MyProject repos",
  "repository": "https://github.com/my-project/common-config",
  "license": "Unlicense",
  "commonpkgShare": {
    "scripts": {
      "lint": "tslint '**/*.t{s,sx}' -e '**/node_modules/**' --fix",
      "precommit": "lint-staged"
    },
    "devDependencies": {
      "lint-staged": "^3.4.0",
      "ts-node": "^3.0.3",
      "tslint": "^5.0.0",
      "tslint-config-standard": "^5.0.2",
      "typescript": "^2.1.6"
    },
    "lint-staged": {
      "*.{ts,tsx}": [
        "yarn lint",
        "git add"
      ]
    },
    "pre-commit": "lint-staged"
  }
}

Now in the package where you want to inherit these configurations, do the following:

Add your common configurations as a dependency:

npm install my-common-config --save-dev

Install commonpkg

npm install commonpkg --save-dev

Configure the package.json

  1. Tell commonpkg the name of the package that has your configurations. You do that by adding the key commonpkg to the root of your package.json.
  2. Add commonpkg to your npm scripts. You will use npm run commonpkg to run the commonpkg script

For example...

{
  "name": "package-where-i-wanna-import-some-configs",
  "version": "1.0.0",
  "main": "dist/index.js",
  "description": "This is My Package",
  "repository": "https://github.com/my-project/my-package.git",
  "license": "Unlicense",
  "scripts": {
    "commonpkg": "commonpkg" // <== add a script like this
  },
  "commonpkg": "my-common-config", // <== add this key to point to the package that has the configs
  "devDependencies": {
    "my-common-config": "^1.0.0",
    "commonpkg": "^2.0.0"
  }
}

✨ Run the magic command ✨

Now run npm run commonpkg and commonpkg will merge the shared properties from my-common-config with your current package.json. After the merge, your package.json will look like this:

The results

{
  "name": "package-where-i-wanna-import-some-configs",
  "version": "1.0.0",
  "main": "dist/index.js",
  "description": "This is My Package",
  "repository": "https://github.com/my-project/my-package.git",
  "license": "Unlicense",
  "scripts": {
    "commonpkg": "commonpkg",
    "lint": "tslint '**/*.t{s,sx}' -e '**/node_modules/**' --fix",
    "precommit": "lint-staged"
  },
  "commonpkg": "my-common-config",
  "devDependencies": {
    "my-common-config": "^1.0.0",
    "commonpkg": "^2.0.0",
    "lint-staged": "^3.4.0",
    "ts-node": "^3.0.3",
    "tslint": "^5.0.0",
    "tslint-config-standard": "^5.0.2",
    "typescript": "^2.1.6"
  },
  "lint-staged": {
    "*.{ts,tsx}": [
      "yarn lint",
      "git add"
    ]
  },
  "pre-commit": "lint-staged"
}

If the dependencies between your old package.json and new package.json are different. commonpkg will remind you to reinstall your node_modules.

You can do npm run commonpkg whenever your common configurations change and commonpkg will pull in the updates.

Bonus tip

You can also use the repo of your common config to check-in files such as tslint.json, .eslintrc, .babelrc, etc and extend those config files from your main package, like so:

For example, your .eslintrc can be:

{
  "extends": "./node_modules/my-common-config/.eslintrc",

  "rules": {
    "eqeqeq": 1
  }
}

You don't even need commonpkg to do this.

Real example

We use commonpkg to share common configurations and files which we keep in our common-config repository with other repositories such as hollowverse.

Contributing

The goal of commonpkg is to serve the requirements of the Hollowverse project. Unfortunately, we don't have the resources to fix bugs or implement features that don't affect us.

However, commonpkg is not super complicated. Check out its source code.

If you need to fix a bug or add a feature, feel free to open an issue to discuss it, and we'll be happy to provide pointers on how to approach it.

2.0.0

7 years ago

1.0.5201

7 years ago

2.0.3-beta

7 years ago

2.0.2-beta

7 years ago

2.0.1-beta

7 years ago

2.0.0-beta

7 years ago

1.5.5

7 years ago

1.0.77

7 years ago

1.0.76

7 years ago

1.0.75

7 years ago

1.0.74

7 years ago

1.0.73

7 years ago

1.0.72

7 years ago

1.0.71

7 years ago

1.0.64

7 years ago

1.0.63

7 years ago

1.0.62

7 years ago

1.0.61

7 years ago

1.0.60

7 years ago

1.0.59

7 years ago

1.0.58

7 years ago

1.0.57

7 years ago

1.0.55

7 years ago

1.5.4

7 years ago

1.0.52

7 years ago

1.5.3

7 years ago

1.0.51

7 years ago

1.0.50

7 years ago

1.5.2

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.38

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.5.1

7 years ago

1.0.25

7 years ago

1.0.23

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1-test

7 years ago

1.0.0-test

7 years ago

1.5.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago