jslicense / licensee.js

check dependency licenses against rules
https://www.npmjs.com/package/licensee
Apache License 2.0
185 stars 23 forks source link

Allow ".licensee.js" configuration file #75

Closed luckyf closed 1 year ago

luckyf commented 2 years ago

For sharing configuration files between projects as NPM modules it is useful to use dynamic JavaScript files as configuration, in addition to JSON files.

ESLint Config Docs or Commitlint Config Docs can be used as reference.

The .licensee.js configuration file could look like this:

module.exports = {
  licenses: {
    spdx: ['CC-BY-3.0'],
    blueOak: 'bronze',
  },
  packages: {
    'deep-is': '0.1.3',
    diff: '1.4.0',
    doctrine: '1.5.0',
    esutils: '2.0.2',
    'json-schema': '0.2.3',
    wordwrap: '0.0.2',
    longest: '1.0.1',
    'repeat-element': '1.1.2',
  },
  corrections: true,
};
ljharb commented 2 years ago

Why is it useful? All of this data is static (as should be all configuration, ideally)

luckyf commented 2 years ago

I use it for sharing the configuration between projects by creating an "@project/licensee-config" NPM package, which I then export in the .licensee.js file. It's also possible to override single keys in specific projects.

const config = require("@project/licensee-config");

module.exports = {
  ...config,
  somekey: "override",
};

For keeping the configuration up to date, I just need to update my dependencies and skip copying JSON files to all projects, which makes it also easy to automate with Dependabot or Renovate.

ljharb commented 2 years ago

That's interesting. I wonder tho if eslint-style extension would be better, like this:

{
  "extends": "@project/licensee-config",
  "somekey": "override"
}
kemitchell commented 1 year ago

I'm loathe to make munging or managing fundamentally static configuration data direct features of this tool. The tool checks npm package licenses against a configuration. It doesn't know or care how that configuration gets written.

@luckyf, you might try symlinking node_modules/@project/licensee-config/whatever to .licensee.json. Or writing .licensee.json before calling licensee in an npm script like node -e "console.log(JSON.stringify(require('@project/licensee-config')))" > .licensee.json && licensee.