Giter Club home page Giter Club logo

license-webpack-plugin's Introduction

License Webpack Plugin

Build Status

Manage third-party license compliance in your webpack build.

Installation

npm install license-webpack-plugin --save-dev

Usage

To use the plugin, simply add it to the plugins section in the webpack config.

Example:

const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;

module.exports = {
  plugins: [
    new LicenseWebpackPlugin()
  ]
};

The default behavior will add a license notice file to each chunk of the webpack build. In addition, it will add a banner indicating the path to the license notice file in any Javascript assets. Third party libraries imported via external tools like SASS @import may not appear in the output (since webpack does not process @import). If this issue happens, please specify additional modules that the plugin should scan.

To configure the plugin, check the documentation.

Build Instructions

yarn
yarn build

Migration Guides

Migration guides for breaking changes are documented here.

Changelog

The changelog can be found here.

License

ISC

license-webpack-plugin's People

Contributors

alan-agius4 avatar arcanis avatar beenotung avatar cakeinpanic avatar dvdckl avatar emmilco avatar filipesilva avatar jackfruit2 avatar joostk avatar markjm avatar taion avatar tobiasweibel avatar vikashkumar29 avatar wictorwilen avatar wszgrcy avatar xz64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

license-webpack-plugin's Issues

How to whitelist license or package

I want to fail my build when package with GPL license only is found. This works with the config below.
But i have one package "normalize-scss" with license "MIT or GPL-2.0".

Could we have a overridePattern that explicit allows licenses. (eg. overridepattern /MIT/).

Or maybe allow a function for accept license checks which could replace regex option, this would allow custom code for special use cases.

new LicenseWebpackPlugin({
pattern: /.*/,
unacceptablePattern: /GPL/,
abortOnUnacceptableLicense: true
});

webpack@5: Error: Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)

When using [email protected] with the new [email protected], the following error occurs:

Error: Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)

callstack:

Error: Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)
    at Chunk.get entryModule [as entryModule] (/home/node/app/node_modules/webpack/lib/Chunk.js:113:10)
    at WebpackChunkModuleIterator.iterateModules (/home/node/app/node_modules/license-webpack-plugin/dist/WebpackChunkModuleIterator.js:38:19)
    at PluginChunkReadHandler.processChunk (/home/node/app/node_modules/license-webpack-plugin/dist/PluginChunkReadHandler.js:26:29)
    at _loop_1 (/home/node/app/node_modules/license-webpack-plugin/dist/WebpackCompilerHandler.js:48:37)
    at WebpackCompilerHandler.iterateChunks (/home/node/app/node_modules/license-webpack-plugin/dist/WebpackCompilerHandler.js:71:17)
    at /home/node/app/node_modules/license-webpack-plugin/dist/WebpackCompilerHandler.js:29:27
    at Hook.eval [as callAsync] (eval at create (/home/node/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:32:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/node/app/node_modules/tapable/lib/Hook.js:18:14)
    at /home/node/app/node_modules/webpack/lib/Compilation.js:1592:37
    at Hook.eval [as callAsync] (eval at create (/home/node/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/node/app/node_modules/tapable/lib/Hook.js:18:14)
    at cont (/home/node/app/node_modules/webpack/lib/Compilation.js:1586:33)
    at /home/node/app/node_modules/webpack/lib/Compilation.js:1638:6
    at /home/node/app/node_modules/neo-async/async.js:2830:7
    at Object.each (/home/node/app/node_modules/neo-async/async.js:2850:39)
    at Compilation.createChunkAssets (/home/node/app/node_modules/webpack/lib/Compilation.js:2308:12)

my (simplified) webpack config is as follows:

{
  entry: {
    index: [
      'core-js/stable',
      'regenerator-runtime/runtime'
      'index.js'
   ],
   mode: 'production',
   target: 'web',
   plugins: [
     new LicenseWebpackPlugin(),
     ...
    ],
   ...
}

Most of the other plugins we use simply throw deprecation warnings rather than an error.

Do others have similar problems when using webpack@5?
Are there any plans to test / increase compatibility with the upcoming webpack version?

Problems with pnpm

When using the combination of Angular CLI and pnpm I get the following error:

LicenseWebpackPlugin(node:29173) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/myproj/node_modules/.registry.npmjs.org/package.json'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:348:35)
    at LicenseExtractor.readPackageJson (/myproj/node_modules/.registry.npmjs.org/license-webpack-plugin/1.3.1/[email protected]/node_modules/license-webpack-plugin/dist/LicenseExtractor.js:126:23)

The owner of pnpm told me, that this should this library should not preserve symlinks in order for it to work.

It would be great to get this working with pnpm.

not reporting all module licenses

Hello,
I created a new angular project with ng new lic-test.
I copied the following list of dependencies into package.json:

    "@angular/animations": "~5.2.3",
    "@angular/cdk": "~5.1.1",
    "@angular/common": "~5.2.3",
    "@angular/compiler": "~5.2.3",
    "@angular/core": "~5.2.3",
    "@angular/forms": "~5.2.3",
    "@angular/http": "~5.2.3",
    "@angular/material": "~5.1.1",
    "@angular/platform-browser": "~5.2.3",
    "@angular/platform-browser-dynamic": "~5.2.3",
    "@angular/router": "~5.2.3",
    "@auth0/angular-jwt": "^1.0.0-beta.9",
    "classlist.js": "~1.1.20150312",
    "core-js": "~2.5.3",
    "hammerjs": "~2.0.8",
    "intl": "~1.2.5",
    "jsencrypt": "^2.3.1",
    "rxjs": "~5.5.6",
    "underscore": "~1.8.3",
    "web-animations-js": "~2.3.1",
    "zone.js": "~0.8.14"

Then I did npm install, ng build --prod
The resulting 3rdpartylicenses.txt only contains the modules

Why for example @auth0/angular-jwt is missing? It's MIT, it has a LICENSE file...

I'm on Windows 10, node version 8.9.1, npm 5.5.1

Is there anything I'm doing wrong?
Thank you.

Symlinked node_module folder can't be resolved

We basically have a docker container that has a node_modules directory somewhere. This directory will be sym-linked into the source directory. Processing that symlink with license-webpack-plugin doesn't work due to the following problem. At

this.modulePrefixes = options.modulesDirectories.map(dir =>
path.join(this.context, dir)
);

the existing code simply concatenates the context path with the paths in modulesDirectories option. This will work when the modulesDirectories paths are set as relative paths. If they are absolute or symlinked then later on in this file (see findModulePrefix) the paths coming from webpack don't match with this.modulePrefixes.

My proposal to solve that issue would be:

        this.modulePrefixes = options.modulesDirectories.map(dir => {
            if (!path.isAbsolute(dir)) {
                dir = path.join(this.context, dir);
            }
            return fs.realpathSync(dir);
        });

Is that reasonable? It would solve the absolute path problem and also symlinked node_modules.

Produce license file for each entry point/bundle

I'd like to be able to produce a license manifest for each entry point/bundle processed by webpack and output the file alongside the bundle ${filename}.

It'd also be really useful to be able to add a comment to the top of the given bundle pointing towards the generated license manifest for that bundle (without having to rely on other plugins to do this).

Looking at the plugins options I don't seem to see a way to managing this as of now.

Thanks

Some licenses missing when using @angular/cli

Hi there,

we're using the Angular CLI, which builds a 3rdpartylicenses.txt by default using license-webpack-plugin.

However, the licenses of some dependencies are missing in the output. I uploaded a rather minimal Angular CLI-based reproduction repository. In its build/3rdpartylicenses.txt, there is no entry for @ngx-translate/http-loader (or core), despite both being imported from src/app/app.module.ts.

When I debugged the issue (in a larger project where @ngx-translate/core is listed, but @ngx-translate/http-loader isn't) I found out that webpack uses different kinds of modules per compilation chunk. "Regular" dependencies were represented as a NormalModule with a resource from which the plugin uses to determine the package name. The dependencies that weren't included are contained in a ConcatenatedModule, which (in my case) had a reference rootModule to a NormalModule with a resource.

I tried building a minimal repo without Angular CLI, but that did work and included all dependencies. I assume its an interaction with one of the many other plugins (maybe ModuleConcatenationPlugin?) that the Angular CLI uses (ng eject creates a webpack.config.js).

packages don't get detected if webpack context is outside of project root

Currently the plugin relies on appending 'node_modules' to compiler.context from webpack to find the path to node_modules. This works if the webpack config is located in your project root. However if the webpack config is located in node_modules or some other directory, it won't pick up the packages.

Option to still output license of Unknown Licenses

I was thinking there should be an option to still output the output of the license file if it is unknown.

In LicenseExtractor.js:getLicenseText():

if (licenseName === LicenseExtractor.UNKNOWN_LICENSE) {
            return '';
 }

Can be something like:

if (!this.options.outputUnknown && licenseName === LicenseExtractor.UNKNOWN_LICENSE) {
            return '';
}

Add new option

I'd like to have ability to provide my own pattern of output.
For example:
%name%@%version% type: %license% url: %url%

Test files getting picked up by the plugin

We are having another issue where if we run the plugin on a dev build with karma enabled, "object-assign" gets added to the license output, even though this is a dev dependency and should be ignored (?). Output of yarn why:

#object-assign"
=> Found "socket.io#[email protected]"
info This module exists because "karma#socket.io" depends on it.
=> Found "gulp-util#[email protected]"
info This module exists because "karma-remap-istanbul#remap-istanbul#gulp-util" depends on it.

=> Found "[email protected]"
info Has been hoisted to "karma"
info This module exists because it's specified in "devDependencies".

=> Found "[email protected]"
info Has been hoisted to "karma-remap-istanbul"
info This module exists because it's specified in "devDependencies".

Incorrect type for `IncludeExcludeTest`

Based on the implementation, it seems that the include and exclude values in https://github.com/xz64/license-webpack-plugin/blob/d41bf38e94484dd5d848056c91d1ecb764415c9c/src/IncludeExcludeTest.ts, currently typed as single-item tuples containing a string, are in fact supposed to be typed as arrays of strings.

I.e. the type should instead be:

type IncludeExcludeTest =
  | {
      include?: string[];
      exclude?: string[];
    }
  | ((chunkName: string) => boolean);

If I pass these arrays instead of single-item tuples, they seem to work fine with webpack 4.

Mixed line endings

For example webpack itself have CRLF windows line endings in license file. While other packages have unix-like LF line endigns.
So generated 3rdpartylicenses.txt have a mixed line endings.

Such files conflict with git's autocrlf option for example.

Licenses File does not show all the included dependencies

The legal team at my company wants us to list all licenses for all dependencies found in our build (including transitive dependencies). However, the final results has only a few of the total amount existing.

Package.json
"devDependencies": {
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@storybook/addon-a11y": "^4.1.6",
"@storybook/addon-actions": "^4.1.6",
"@storybook/addon-info": "^4.1.6",
"@storybook/addon-knobs": "^4.1.6",
"@storybook/addon-options": "^4.1.6",
"@storybook/preact": "4.2.0-alpha.10",
"eslint": "^5.1.0",
"eslint-config-pogo": "^1.0.1",
"extract-loader": "^3.1.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^24.1.0",
"license-webpack-plugin": "^2.1.1",
"postcss-apply": "^0.12.0",
"postcss-import": "^12.0.1",
"postcss-mixins": "^6.2.0",
"postcss-preset-env": "^5.1.0",
"preact-render-spy": "^1.2.1",
"preact-svg-loader": "^0.2.1",
"preact-transition-group": "^1.1.1",
"rimraf": "^2.6.3",
"stylelint": "^9.4.0",
"workbox-webpack-plugin": "^4.3.1"
},
"dependencies": {
"autobind-decorator": "^2.4.0",
"classnames": "^2.2.5",
"intersection-observer": "^0.6.0",
"preact": "^8.4.2",
"preact-cli": "3.0.0-rc.1",
"preact-router": "^2.6.1",
"smoothscroll-polyfill": "^0.4.4",
"unistore": "^3.4.1"
},

And on my bundle.licenses.txt i only see the following

@preact/async-loader
autobind-decorator
classnames
intersection-observer
preact-cli
preact-router
preact-transition-group
smoothscroll-polyfill
unistore
webpack

Why am i only able to see these ones and not all the included dependencies?

Tests are error'ing

Hi,

I cloned the project and tried to run the tests but I hit an error:

> [email protected] test C:\Users\myusername\Documents\GitHub\license-webpack-plugin
> tape test/*.js | tap-diff

C:\Users\myusername\Documents\GitHub\license-webpack-plugin\test\index.test.js:303
    t.equal(plugin.modules[0].licenseText, 'text: MIT');
                             ^

TypeError: Cannot read property 'licenseText' of undefined
    at C:\Users\myusername\Documents\GitHub\license-webpack-plugin\test\index.test.js:303:30
    at C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\tapes\index.js:82:7
    at C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\async\lib\async.js:52:16
    at iterate (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\async\lib\async.js:260:24)
    at Object.async.forEachOfSeries.async.eachOfSeries (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\async\lib\async.js:281:9)
    at Object.async.forEachSeries.async.eachSeries (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\async\lib\async.js:214:22)
    at runWrapperFns (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\tapes\index.js:90:9)
    at Test.<anonymous> (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\tapes\index.js:81:5)
    at Test.bound [as _cb] (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\tape\lib\test.js:65:32)
    at Test.run (C:\Users\myusername\Documents\GitHub\license-webpack-plugin\node_modules\tape\lib\test.js:84:10)

I ran the following command: npm install && npm run test

I'm on Windows 7 x64 using NodeJS 6.9.1 and NPM 3.8.6.

Unfortunately I'm too busy to look into it myself, otherwise I would try to fix it and do a PR :-)

Cheers,
Raf

Possibility to ignore licenses for dev-dependencies?

The legal team at my company wants us to list all licenses for all dependencies found in our build (including sub dependencies). However, I also noticed that licenses for our internal tools are also included (like webpack, loaders, linters, etc) - is there a way to ignore those?

Suppressing no license file error messages

It would be a nice if it was possible to suppress "no license file" errors because for example many of the Angular 2 packages do not have a license file.

license-webpack-plugin: Could not find a license file for @angular/core, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/compiler, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/common, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/platform-browser, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/forms, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/http, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/router, defaulting to license name found in package.json: MIT
license-webpack-plugin: Could not find a license file for @angular/platform-browser-dynamic, defaulting to license name found in package.json: MIT

Problem with thirdparty package (dragscroller)

Thank you for the great plugin.

I just noticed that I keep getting error when importing this package.
https://www.npmjs.com/package/dragscroll

it throws this error:
"ERROR in WebpackLicensePlugin: Could not find license info for [email protected]"

And here is my config option:

  new LicensePlugin({
      outputFilename: 'thirdPartyNotice.json',
      handleMissingLicenseText: (packageName, licenseType) => {
        console.log(`Cannot find license for ${packageName}`);
        return '';
      },
      handleMissingLicenseType: (packageName) => {
        console.log(packageName);
        return '';
      },
    }),

am I missing something or it is a bug?

@types/webpack-sources

@types/webpack-sources should be a regular dependency, since dist/WebpackCompilation.d.ts depends on it. I understand that it's extra weight for non-TS users, but @types packages are very lean, and are comparable to having <package_name>.d.ts bundled-in weight-wise.

licenseTemplateDir errors on missing license

I get the below error, crashing webpack when I use the licenseTemplateDir option and a license is missing from the directory. It should probably handle this case better and instead fallback to handleMissingLicenseText or simply report missing license text.

.\node_modules\license-webpack-plugin\dist\WebpackCompilerHandler.js:79
          finally { if (e_1) throw e_1.error; }
                             ^

Error: ENOENT: no such file or directory, open '.\buildConfig\licenseTemplates\BSD-3-Clause.txt'
  at Object.openSync (fs.js:436:3)
  at Object.readFileSync (fs.js:341:35)
  at Storage.provideSync (.\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:95:16)
  at CachedInputFileSystem.readFileSync (.\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:254:31)
  at WebpackFileSystem.readFileAsUtf8 (.\node_modules\license-webpack-plugin\dist\WebpackFileSystem.js:52:24)
  at LicenseTextReader.readLicense (.\node_modules\license-webpack-plugin\dist\LicenseTextReader.js:42:18)
  at PluginChunkReadHandler.processModule (.\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:52:62)
  at .\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:29:23
  at WebpackModuleFileIterator.iterateFiles (.\node_modules\license-webpack-plugin\dist\WebpackModuleFileIterator.js:7:9)
  at .\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:27:32
  at Array.forEach (<anonymous>)
  at WebpackChunkModuleIterator.iterateModules (.\node_modules\license-webpack-plugin\dist\WebpackChunkModuleIterator.js:36:27)
  at PluginChunkReadHandler.processChunk (.\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:26:29)
  at _loop_1 (.\node_modules\license-webpack-plugin\dist\WebpackCompilerHandler.js:48:37)
  at WebpackCompilerHandler.iterateChunks (.\node_modules\license-webpack-plugin\dist\WebpackCompilerHandler.js:71:17)
  at Compilation.<anonymous> (.\node_modules\license-webpack-plugin\dist\WebpackCompilerHandler.js:37:31)
  at Compilation.applyPluginsAsyncSeries (.\node_modules\tapable\lib\Tapable.js:206:13)
  at self.applyPluginsAsync.err (.\node_modules\webpack\lib\Compilation.js:635:10)
  at next (.\node_modules\tapable\lib\Tapable.js:202:11)
  at Compilation.compilation.plugin.callback (.\node_modules\webpack\lib\ProgressPlugin.js:113:6)
  at next (.\node_modules\tapable\lib\Tapable.js:204:14)
  at ExtractTextPlugin.<anonymous> (.\node_modules\extract-text-webpack-plugin\index.js:345:4)
  at Compilation.applyPluginsAsyncSeries (.\node_modules\tapable\lib\Tapable.js:206:13)
  at sealPart2 (.\node_modules\webpack\lib\Compilation.js:631:9)
  at next (.\node_modules\tapable\lib\Tapable.js:202:11)
  at Compilation.compilation.plugin (.\node_modules\webpack\lib\ProgressPlugin.js:109:6)
  at next (.\node_modules\tapable\lib\Tapable.js:204:14)
  at ExtractTextPlugin.<anonymous> (.\node_modules\extract-text-webpack-plugin\index.js:317:5)
  at .\node_modules\async\dist\async.js:473:16
  at iteratorCallback (.\node_modules\async\dist\async.js:1064:13)

More modules than dependencies

Method renderLicenses loads all the dependencies modules plus a few more:

is-buffer
process
setimmediate
timers-browserify
vue-loader
vue-style-loader
base64-js
buffer
ieee754
isarray
moment

I am interested to know what is logic behind this? How does it take some of the transitive dependencies and not all?

LicenseWebpackPlugin is incompatible with meteor-client-bundler

angular-cli uses LicenseWebpackPlugin when building for production:

    new LicenseWebpackPlugin({
      "licenseFilenames": [
        "LICENSE",
        "LICENSE.md",
        "LICENSE.txt",
        "license",
        "license.md",
        "license.txt"
      ],
      "perChunkOutput": false,
      "outputTemplate": "/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/output.template.ejs",
      "outputFilename": "3rdpartylicenses.txt",
      "suppressErrors": true,
      "includePackagesWithoutLicense": false,
      "abortOnUnacceptableLicense": false,
      "addBanner": false,
      "bannerTemplate": "/*! 3rd party license information is available at <%- filename %> */",
      "includedChunks": [],
      "excludedChunks": [],
      "additionalPackages": [],
      "pattern": /^(MIT|ISC|BSD.*)$/
    }),

Unfortunately this causes the following error when using meteor-client-bundler:

$ npm run start

> [email protected] start /home/niko/WebstormProjects/angularcli-meteor
> webpack-dev-server --port=4200

 10% building modules 3/3 modules 0 activeProject is running at http://localhost:4200/
webpack output is served from /
404s will fallback to /index.html
 95% emittingUnhandled rejection Error: ENOTDIR: not a directory, open '/home/niko/WebstormProjects/angularcli-meteor/node_modules/meteor-client.js/package.json'
    at Object.fs.openSync (fs.js:652:18)
    at Object.fs.readFileSync (fs.js:553:33)
    at LicenseExtractor.readPackageJson (/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/LicenseExtractor.js:121:23)
    at LicenseExtractor.parsePackage (/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/LicenseExtractor.js:21:32)
    at ModuleProcessor.processPackage (/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/ModuleProcessor.js:24:46)
    at ModuleProcessor.processFile (/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/ModuleProcessor.js:21:21)
    at moduleCallback (/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/LicenseWebpackPlugin.js:80:61)
    at Set.forEach (native)
    at Chunk.forEachModule (/home/niko/WebstormProjects/angularcli-meteor/node_modules/webpack/lib/Chunk.js:159:17)
    at /home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/LicenseWebpackPlugin.js:88:27
    at Array.forEach (<anonymous>)
    at Compiler.<anonymous> (/home/niko/WebstormProjects/angularcli-meteor/node_modules/license-webpack-plugin/dist/LicenseWebpackPlugin.js:65:32)
    at next (/home/niko/WebstormProjects/angularcli-meteor/node_modules/tapable/lib/Tapable.js:204:14)
    at /home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/index.js:204:9
    at PassThroughHandlerContext.finallyHandler (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/finally.js:56:23)
    at PassThroughHandlerContext.tryCatcher (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/home/niko/WebstormProjects/angularcli-meteor/node_modules/html-webpack-plugin/node_modules/bluebird/js/release/async.js:143:10)

Commenting out import 'meteor-client'; from src/main.ts solves the building issue, but obviously the app will not work.

You can easily reproduce the issue checking out my angularcli-meteor tutorial repository.

Feature Request: Use compiler.outputFileSystem

While less common, I was in a scenario where I wanted to run a development server using a production configuration using webpack-dev-middleware. While native webpack outputs went into its MemoryFS, license-webpack-plugin still wrote to the native filesystem.

This is a low priority, but it would be nice if the compiler's outputFileSystem were used for writing if set in the compiler object.

While not applicable to my case, I suspect that supporting inputFileSystem might be appropriate.

References:

Unexpected error on empty pattern

When patter isn't passed into constructor, plugin tries to report an error:
245 this.errors.push(plugin.errorMessages['no-pattern']);
but, at this point this.errors isn't assigned yet, and will be created only at
248 objectAssign(this, composedPlugin, instance(), opts);

as result, not very clear error is shown:

<redacted>\node_modules\license-webpack-plugin\index.js:245
    this.errors.push(plugin.errorMessages['no-pattern']);
               ^

TypeError: Cannot read property 'push' of undefined
    at new licensePlugin (<redacted>\node_modules\license-webpack-plugin\index.js:245:16)```

Support for old package.json license structure

I know that according to the current package.json format specification the license info should always be a string. Unfortunately many packages still use the old notation of license.type shown here. Since I should show these licenses too it would be great if there was support for listing them too.

Type definition files getting picked up by the plugin

I am having an issue where I am importing a third party package which has a type definition file as a regular dependency (@types/graphql), and the plugin is returning this package even though this does not really seem to be used by our bundle. I checked the generated webpack stats json and this module is not referenced there at all. Is there a bug in the plugin? Should we exclude *.d.ts files from the output?

Package name undefined

I have an angular project with a npm module that includes a package.json. This file does not set a name. The plugin picks this up as undefined and then adds a line containing the string »undefined« to the end of the 3rdpartylicenses.txt.

I would expect the plugin to print nothing instead of undefined if there is no license to match the unknown title.

This happens in the context of an angular CLI project and the offending file is https://github.com/angular/angular/blob/master/packages/common/locales/package.json

The problem occurs in this line of the plugin:

name: packageJson.name,

This passes on a name even if there is none

TS2322 when using license-webpack-plugin from typescript based webpack config.

When I have a typescript based webpack config, I get the following typescript error from using license-webpack-plugin:

error TS2322: Type 'LicenseWebpackPlugin' is not assignable to type 'Plugin'.
  Types of property 'apply' are incompatible.
    Type '(compiler: WebpackCompiler) => void' is not assignable to type '(compiler: Compiler) => void'.
      Types of parameters 'compiler' and 'compiler' are incompatible.
        Property 'context' is missing in type 'Compiler' but required in type 'WebpackCompiler'.

Does not work on Windows

This plugin interprets every .js and .ts file path which is outside of the node_modules directory as a module called C: on Windows and crashes with an error:

Error: ENOENT: no such file or directory, open 'C:\dev\site\example\node_modules\C:\package.json'

The problem seems to be in the findPackageName function. What I don't understand is that why does it consider files outside of the node_modules directory in the first place?

Compilation modules and chunk parsing

Hello!

I'm implementing a plugin very much like this for an internal usecase and already have a working version for webpack v3. I'd love to update this to webpack v4, but it seems the way of parsing the included node_modules from the compilation modules that i've used doesn't work anymore.

I've taken a look at your modular approach (mostly WebpackCompilerHandler, WebpackChunkHandler, ModuleIterator and FileIterator) to gain insight into how you get from WebpackCompilation to the included node_modules.

What i've done so far for my webpack v3 plugin is reading the chunks from the compilation by accessing it's .chunks property and then reading the modules of each chunk by either accessing getModules or the modules property: chunk.getModules ? chunk.getModules() : chunk.modules

Then, for every module, i simply read it's context and check if it contains "node_modules" as a string. If it does, it's a file from a node_module so i parse the module from the path (first subdirectory of the deepest node_modules directory in the path).

This seems rather hacky and doesn't work for webpack v4 since a module's context is sometimes null.

Can you elaborate a bit on how you do it - especially where you found the API documentation in regards to what properties/methods a WebpackCompilation, a WebpackChunk and a WebpackModule have? I'm pretty sure there was a documentation like that, but unfortunately i can't find any for v4.

Any help is appreciated!

addBanner and perChunkOutput settings are switched

Hi,

I found the reason for the bug I mentioned in #43

The order here is not the same:

constructor(
private chunkIncludeTester: ChunkIncludeExcludeTester,
private chunkHandler: WebpackChunkHandler,
private assetManager: AssetManager,
private moduleCache: ModuleCache,
private addBanner: boolean,
private perChunkOutput: boolean,
private additionalChunkModules: { [chunkName: string]: Module[] },
private additionalModules: Module[]
) {}

const handler = new WebpackCompilerHandler(
chunkIncludeExcludeTester,
readHandler,
assetManager,
moduleCache,
options.perChunkOutput,
options.addBanner,
options.additionalChunkModules,
options.additionalModules
);

License from LICENSE file

Example:

package.json of (just as example) node_modules/can-ajax have no any key with license.
But node_modules/can-ajax have files LICENSE and README.md:

file LICENSE

MIT License

Copyright (c) 2017 CanJS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

README.md


# can-ajax

[![Join the chat at https://gitter.im/canjs/canjs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/canjs/canjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/canjs/can-ajax/blob/master/LICENSE)
[![npm version](https://badge.fury.io/js/can-ajax.svg)](https://www.npmjs.com/package/can-ajax)
[![Travis build status](https://travis-ci.org/canjs/can-ajax.svg?branch=master)](https://travis-ci.org/canjs/can-ajax)
[![Greenkeeper badge](https://badges.greenkeeper.io/canjs/can-ajax.svg)](https://greenkeeper.io/)

jQuery-inspired AJAX request library.

## Documentation

Read the [can-ajax API docs on CanJS.com](https://canjs.com/doc/can-ajax.html).

## Changelog

See the [latest releases on GitHub](https://github.com/canjs/can-ajax/releases).

## Contributing

The [contribution guide](https://github.com/canjs/can-ajax/blob/master/CONTRIBUTING.md) has information on getting help, reporting bugs, developing locally, and more.

## License

[MIT](https://github.com/canjs/can-ajax/blob/master/LICENSE)

My config is:

        new LicenseWebpackPlugin({
                pattern: /.*/,
                licenseFilenames: [ // list of filenames to search for in each package
                    'LICENSE',
                    'LICENSE.md',
                    'LICENSE.txt',
                    'license',
                    'license.md',
                    'license.txt',
                    'README',
                    'README.md',
                    'README.txt',
                    'readme',
                    'readme.md',
                    'readme.txt'
                ],
                outputTemplate: 'output.template.ejs',
                outputFilename: '[name].licenses.html',
                includePackagesWithoutLicense: true,
                addBanner: true,
                bannerTemplate: '/*! 3rd party license information is available at <%- filename %> */'
            })

as result I have Unknown license on output.

Why?

Output path not being created recursively

Heya,

If the webpack configuration has a deep output path that doesn't currently exist, license-webpack-plugin will fail at mkdirSync (angular/angular-cli#7203).

Webpack itself is ok with creating this path and putting files there though. Perhaps compilation.assets could be used instead of mkdirSync? There's an example at https://github.com/webpack/docs/wiki/how-to-write-a-plugin#a-simple-example where they do that. That way Webpack itself would take care of outputting it.

On webpack4, outputTemplate is broken

In output.template.ejs, sometimes packages[i] is undefined, I had to change to:

<%_ for(var i=0; i < packages.length; i++) { -%>
<%- packages[i] && packages[i].packageJson.name %>
<%- packages[i] && packages[i].license.name %>
<%- packages[i] && packages[i].license.text -%>
<%- (i < (packages.length - 1)) ? '\n\n' : '' -%>
<%_ } -%>

But then there's several blank rows.

LicenseTextReader checks for license template inclusion improperly

Here, the package constructs the filename using the license type and .txt.

this.fileSystem.isFileInDirectory(templateFilename, this.templateDir)

But if we look at isFileInDirectory it's treating that filename as resolvable to a full path, which doesn't work out.

const normalizedFile = this.resolvePath(filename);

The result being that, currently, the licenseTemplateDir option doesn't work.

Problems when running with webpack-dev-server

Hi

Thanks for this plugin. I get an error when running with webpack-dev-server

Here are my dependencies,

webpack: 2.2.0-rc.6
webpack-dev-server: 2.2.0-rc.0
license-webpack-plugin: latest

plugin options -
new LicensesPlugin({
//filename: 'licenses.txt',
pattern: /^(.*)$/,
includeUndefined: true,
addLicenseText: true,
addUrl: true,
}),

I get the following stacktrace -

fs.js:558
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: ENOENT: no such file or directory, open '/Users/ksheth/myproj/web/3rdpartylicenses.txt'
at Object.fs.openSync (fs.js:558:51)
at Object.fs.writeFileSync (fs.js:1223:33)
at licensePlugin.write (/Users/ksheth/myproj/node_modules/license-webpack-plugin/index.js:178:8)
at licensePlugin. (/Users/ksheth/myproj/node_modules/license-webpack-plugin/index.js:198:12)
at Compiler.applyPlugins (/Users/ksheth/myproj/node_modules/webpack/node_modules/tapable/lib/Tapable.js:61:14)
at Watching._done (/Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:91:17)
at /Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:74:18
at Compiler.emitRecords (/Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:348:37)
at /Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:57:19
at /Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:341:11
at next (/Users/ksheth/myproj/node_modules/webpack/node_modules/tapable/lib/Tapable.js:154:11)
at Compiler.compiler.plugin (/Users/ksheth/myproj/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
at Compiler.applyPluginsAsyncSeries1 (/Users/ksheth/myproj/node_modules/webpack/node_modules/tapable/lib/Tapable.js:158:13)
at Compiler.afterEmit (/Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:338:8)
at Compiler. (/Users/ksheth/myproj/node_modules/webpack/lib/Compiler.js:333:14)
at /Users/ksheth/myproj/node_modules/webpack/node_modules/async/dist/async.js:356:16

Thanks,

Add a string or json module

I'd like to add the 3rd Party License information directly into a Help or About page, so that the information is viewable within the app itself.

It would be great if this plugin (or one like it) could add a module to the webpack build returning the text as a string or maybe a more structured JSON file broken down by library name or similar to allow for even better user experience options (table of contents, etc).

module directory should be an option

We should be able to override the moduleDirectory (Default to node_modules). It is possible to have node modules installed elsewhere than in node_modules.

Incompatible types

Hi,

It seems that LicenseWebpackPlugin implements WebpackPlugin interface,
but WebpackPlugin interface is not compatible with Webpack's Plugin abstract class.
Which cause my code to break after i have updated from version 1.5.0 to 2.1.3, is their a way to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.