Skip to content

Commit

Permalink
Refactor code, implement new features and fix minor issues
Browse files Browse the repository at this point in the history
- Implement merge requests from the original "license-checker" repository
- Upgrade some node modules
- Update documentation
- Add sublime project files to .gitignore
- Update version number
- Add yarn.lock file, update contributors and fix error in pretest
  • Loading branch information
Roman Seidelsohn committed Feb 24, 2020
0 parents commit 1ebe5e5
Show file tree
Hide file tree
Showing 37 changed files with 5,919 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifacts
build
coverage
31 changes: 31 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"root": true,
"extends": "eslint:recommended",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script"
},
"globals": {
"YUI_config": true
},
"rules": {
"no-unused-vars": ["error", { "args": "after-used" }],
"semi": 2,
"eqeqeq": [2, "allow-null"],
"no-console": 0,
"no-irregular-whitespace": 2,
"no-useless-escape": 0,
"indent": ["error", 4],
"space-before-function-paren": ["error", "never"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"arrow-body-style": [2, "always"],
"array-bracket-spacing": [2, "never"],
"object-curly-spacing": [2, "always"],
"key-spacing": ["error", { "beforeColon": false }]
},
"env": {
"node": true,
"browser": true
}
}
45 changes: 45 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

publish-gpr:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
scope: '@RSeidelsohn'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**/node_modules/
**/npm-debug.log
*.sublime-*
*~
.*.swp
.com.apple.timemachine.supported
.DS_Store
.idea/
.nyc_output
.svn
artifacts
coverage/
CVS/
node_modules/
package-lock.json
tmp/
11 changes: 11 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
reporting:
reports:
- lcov
- text
- text-summary
check:
global:
statements: 95
lines: 95
branches: 90
functions: 100
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "6"
- "8"
cache:
directories:
- "node_modules"
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright 2012 Yahoo Inc.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yahoo! Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

186 changes: 186 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# NPM License Checker

[![Build Status](https://www.travis-ci.org/davglass/license-checker.svg?branch=master)](https://www.travis-ci.org/davglass/license-checker)

_Due to legal issues I - for now - had to remove the `--relativeModulePath` option again. I hope I can bring it back soon._

_This is a fork of davglass' `license-checker v.25.0.1` - I simply added a new option `--relativeModulePath` for stripping the local absolute path portions from modules (`--relativeLicensePath` already does this for the license file paths). Since that module doesn't seem to be updated regularly, I created this module for use in our workplace. A pull request has also been created for bringing that new option into the original module (see https://github.com/davglass/license-checker/pull/223). Also, I upgraded several node modules for this fork that are not upgraded in the original module. The latter is not part of my pull request._

_As of v26.0.0 the `exclude` argument has been changed into `excludeLicenses` in order to prevent confusion and better align it with the `excludePackages` argument. Also, the argument `includeLicenses` has been added for listing only packages that include the licenses listed._

_As of v17.0.0 the `failOn` and `onlyAllow` arguments take semicolons as delimeters instead of commas. Some license names contain commas and it messed with the parsing._

Ever needed to see all the license info for a module and its dependencies?

It's this easy:

```shell
npm install -g license-checker-rseidelsohn

mkdir foo
cd foo
npm install yui-lint
license-checker-rseidelsohn
```

You should see something like this:

```
├─ cli@0.4.3
│ ├─ repository: http://github.com/chriso/cli
│ └─ licenses: MIT
├─ glob@3.1.14
│ ├─ repository: https://github.com/isaacs/node-glob
│ └─ licenses: UNKNOWN
├─ graceful-fs@1.1.14
│ ├─ repository: https://github.com/isaacs/node-graceful-fs
│ └─ licenses: UNKNOWN
├─ inherits@1.0.0
│ ├─ repository: https://github.com/isaacs/inherits
│ └─ licenses: UNKNOWN
├─ jshint@0.9.1
│ └─ licenses: MIT
├─ lru-cache@1.0.6
│ ├─ repository: https://github.com/isaacs/node-lru-cache
│ └─ licenses: MIT
├─ lru-cache@2.0.4
│ ├─ repository: https://github.com/isaacs/node-lru-cache
│ └─ licenses: MIT
├─ minimatch@0.0.5
│ ├─ repository: https://github.com/isaacs/minimatch
│ └─ licenses: MIT
├─ minimatch@0.2.9
│ ├─ repository: https://github.com/isaacs/minimatch
│ └─ licenses: MIT
├─ sigmund@1.0.0
│ ├─ repository: https://github.com/isaacs/sigmund
│ └─ licenses: UNKNOWN
└─ yui-lint@0.1.1
├─ licenses: BSD
└─ repository: http://github.com/yui/yui-lint
```

An asterisk next to a license name means that it was deduced from
an other file than package.json (README, LICENSE, COPYING, ...)
You could see something like this:

```
└─ debug@2.0.0
├─ repository: https://github.com/visionmedia/debug
└─ licenses: MIT*
```

## Options

- `--production` only show production dependencies.
- `--development` only show development dependencies.
- `--start [filepath]` path of the initial json to look for
- `--unknown` report guessed licenses as unknown licenses.
- `--onlyunknown` only list packages with unknown or guessed licenses.
- `--markdown` output in markdown format.
- `--json` output in json format.
- `--csv` output in csv format.
- `--csvComponentPrefix` prefix column for component in csv format.
- `--out [filepath]` write the data to a specific file.
- `--files [path]` copy all license files to path and rename them to `module-name`@`version`-LICENSE.txt.
- `--customPath` to add a custom Format file in JSON
- `--excludeLicenses [list]` exclude modules which licenses are in the comma-separated list from the output
- `--includeLicenses [list]` include only modules which licenses are in the comma-separated list from the output
- `--relativeLicensePath` output the location of the license files as relative paths
- `--summary` output a summary of the license usage',
- `--failOn [list]` fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list
- `--onlyAllow [list]` fail (exit with code 1) on the first occurrence of the licenses not in the semicolon-seperated list
- `--includePackages [list]` restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") in the semicolon-seperated list
- `--excludePackages [list]` restrict output to the packages (either "package@fullversion" or "package@majorversion" or only "package") not in the semicolon-seperated list
- `--excludePrivatePackages` restrict output to not include any package marked as private
- `--direct` look for direct dependencies only

## Exclusions

A list of licenses is the simplest way to describe what you want to exclude.

You can use valid [SPDX identifiers](https://spdx.org/licenses/).
You can use valid SPDX expressions like `MIT OR X11`.
You can use non-valid SPDX identifiers, like `Public Domain`, since `npm` does
support some license strings that are not SPDX identifiers.

## Examples

```
license-checker-rseidelsohn --json > /path/to/licenses.json
license-checker-rseidelsohn --csv --out /path/to/licenses.csv
license-checker-rseidelsohn --unknown
license-checker-rseidelsohn --customPath customFormatExample.json
license-checker-rseidelsohn --excludeModules 'MIT, MIT OR X11, BSD, ISC'
license-checker-rseidelsohn --includePackages 'react@16.3.0;react-dom@16.3.0;lodash@4.3.1'
license-checker-rseidelsohn --excludePackages 'internal-1;internal-2'
license-checker-rseidelsohn --onlyunknown
```

## Custom format

The `--customPath` option can be used with CSV to specify the columns. Note that
the first column, `module_name`, will always be used.

When used with JSON format, it will add the specified items to the usual ones.

The available items are the following:

- name
- version
- description
- repository
- publisher
- email
- url
- licenses
- licenseFile
- licenseText
- licenseModified

You can also give default values for each item.
See an example in [customFormatExample.json](customFormatExample.json).

## Requiring

```js
var checker = require('license-checker');

checker.init(
{
start: '/path/to/start/looking',
},
function(err, packages) {
if (err) {
//Handle error
} else {
//The sorted package data
//as an Object
}
}
);
```

## Debugging

license-checker uses [debug](https://www.npmjs.com/package/debug) for internal logging. There’s two internal markers:

- `license-checker-rseidelsohn:error` for errors
- `license-checker-rseidelsohn:log` for non-errors

Set the `DEBUG` environment variable to one of these to see debug output:

```shell
$ export DEBUG=license-checker-rseidelsohn*; license-checker-rseidelsohn
scanning ./yui-lint
├─ cli@0.4.3
│ ├─ repository: http://github.com/chriso/cli
│ └─ licenses: MIT
# ...
```

## How Licenses are Found

We walk through the `node_modules` directory with the [`read-installed`](https://www.npmjs.org/package/read-installed) module. Once we gathered a list of modules we walk through them and look at all of their `package.json`'s, We try to identify the license with the [`spdx`](https://www.npmjs.com/package/spdx) module to see if it has a valid SPDX license attached. If that fails, we then look into the module for the following files: `LICENSE`, `LICENCE`, `COPYING`, & `README`.

If one of the those files are found (in that order) we will attempt to parse the license data from it with a list of known license texts. This will be shown with the `*` next to the name of the license to show that we "guessed" at it.
Loading

0 comments on commit 1ebe5e5

Please sign in to comment.