diff --git a/dist/index.js b/dist/index.js index 75214992..629fc59c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -857,17 +857,23 @@ class LicensePlugin { if (exists) { this.debug(`found package.json at: ${pkgPath}, read it`); // Read `package.json` file - pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")); // Read license file, if it exists. + const pkgJson = JSON.parse(fs.readFileSync(pkgPath, "utf-8")); // We are probably in a package.json specifying the type of package (module, cjs). + // Nevertheless, if the package name is not defined, we must not use this `package.json` descriptor. - const licenseFile = glob.sync(path.join(dir, "LICENSE*"))[0]; + if (pkgJson.name) { + // We found it! + pkg = pkgJson; // Read license file, if it exists. - if (licenseFile) { - pkg.licenseText = fs.readFileSync(licenseFile, "utf-8"); - } // Add the new dependency to the set of third-party dependencies. + const licenseFile = glob.sync(path.join(dir, "LICENSE*"))[0]; - this.addDependency(pkg); // We can stop now. + if (licenseFile) { + pkg.licenseText = fs.readFileSync(licenseFile, "utf-8"); + } // Add the new dependency to the set of third-party dependencies. - break; + this.addDependency(pkg); // We can stop now. + + break; + } } // Go up in the directory tree. dir = path.normalize(path.join(dir, "..")); @@ -936,7 +942,9 @@ class LicensePlugin { addDependency(pkg) { const name = pkg.name; - if (!_.has(this._dependencies, name)) { + if (!name) { + this.warn("Trying to add dependency without any name, skipping it."); + } else if (!_.has(this._dependencies, name)) { this._dependencies[name] = new Dependency(pkg); } } diff --git a/package.json b/package.json index cd85fc03..1d682adf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-license", - "version": "1.0.0", + "version": "1.0.1", "description": "Rollup plugin to add license banner to the final bundle and output third party licenses", "main": "dist/index.js", "scripts": {