Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-green-licenses

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-green-licenses - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

24

build/src/checker.js

@@ -15,7 +15,19 @@ "use strict";

// limitations under the License.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;

@@ -27,2 +39,3 @@ };

Object.defineProperty(exports, "__esModule", { value: true });
exports.LicenseChecker = void 0;
const events_1 = require("events");

@@ -40,3 +53,3 @@ const fs = __importStar(require("fs"));

var github_2 = require("./github");
exports.GitHubRepository = github_2.GitHubRepository;
Object.defineProperty(exports, "GitHubRepository", { enumerable: true, get: function () { return github_2.GitHubRepository; } });
const fsAccess = util_1.promisify(fs.access);

@@ -158,2 +171,7 @@ const fsReadDir = util_1.promisify(fs.readdir);

correctLicenseName(license) {
// NPM specific value.
if (license === 'UNLICENSED' || license === 'UNLICENCED') {
console.warn(`Unlicensed package, specified license: ${license}`);
return 'UNLICENSED';
}
const corrected = spdx_correct_1.default(license);

@@ -160,0 +178,0 @@ if (this.opts.verbose && corrected && corrected !== license) {

@@ -15,7 +15,19 @@ "use strict";

// limitations under the License.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;

@@ -27,2 +39,3 @@ };

Object.defineProperty(exports, "__esModule", { value: true });
exports.getGitHubConfig = exports.getLocalConfig = void 0;
const fs = __importStar(require("fs"));

@@ -29,0 +42,0 @@ const path = __importStar(require("path"));

238

build/src/github.js

@@ -16,2 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.GitHubRepository = void 0;
// Abstractions over GitHub REST API v3 and related features. For GitHub API,

@@ -31,136 +32,139 @@ // see https://developer.github.com/v3/.

}
class GitHubRepository {
constructor(owner, repo) {
this.pathPrefix = path_1.posix.join('/repos', owner, repo);
}
getAxiosConfig(authToken) {
return authToken ? { headers: { Authorization: `token ${authToken}` } } : {};
}
async apiGet(path, params) {
const url = new url_1.URL('https://api.github.com');
url.pathname = path_1.posix.join(this.pathPrefix, path);
if (params) {
Object.keys(params).forEach(key => {
url.searchParams.set(key, params[key]);
});
let GitHubRepository = /** @class */ (() => {
class GitHubRepository {
constructor(owner, repo) {
this.pathPrefix = path_1.posix.join('/repos', owner, repo);
}
const resp = await gaxios_1.request({
method: 'GET',
url: url.href,
...this.getAxiosConfig(),
});
return resp.data;
}
async apiPost(path, body) {
const url = new url_1.URL('https://api.github.com');
url.pathname = path_1.posix.join(this.pathPrefix, path);
const resp = await gaxios_1.request({
method: 'POST',
url: url.href,
data: body,
...this.getAxiosConfig(),
});
return resp.data;
}
async getPRCommits(prId, attemptCount = 1) {
let answer = await this.apiGet(path_1.posix.join('pulls', prId.toString()));
answer = ensureSingleResponseData(answer);
if (answer.mergeable === null) {
if (attemptCount > GitHubRepository.MAX_PR_COMMIT_RETRIES) {
throw new Error(`Tried ${attemptCount} times but the mergeable field is not set. Giving up`);
getAxiosConfig(authToken) {
return authToken ? { headers: { Authorization: `token ${authToken}` } } : {};
}
async apiGet(path, params) {
const url = new url_1.URL('https://api.github.com');
url.pathname = path_1.posix.join(this.pathPrefix, path);
if (params) {
Object.keys(params).forEach(key => {
url.searchParams.set(key, params[key]);
});
}
console.log('The `mergeable` field is not set yet. Will retry later.');
return new Promise(resolve => {
setTimeout(async () => {
resolve(await this.getPRCommits(prId, attemptCount + 1));
}, 1000);
const resp = await gaxios_1.request({
method: 'GET',
url: url.href,
...this.getAxiosConfig(),
});
return resp.data;
}
else if (!answer.mergeable) {
throw new Error('PR is not mergeable');
async apiPost(path, body) {
const url = new url_1.URL('https://api.github.com');
url.pathname = path_1.posix.join(this.pathPrefix, path);
const resp = await gaxios_1.request({
method: 'POST',
url: url.href,
data: body,
...this.getAxiosConfig(),
});
return resp.data;
}
const mergeCommitSha = answer.merge_commit_sha;
if (!mergeCommitSha) {
throw new Error('Merge commit SHA is not found');
async getPRCommits(prId, attemptCount = 1) {
let answer = await this.apiGet(path_1.posix.join('pulls', prId.toString()));
answer = ensureSingleResponseData(answer);
if (answer.mergeable === null) {
if (attemptCount > GitHubRepository.MAX_PR_COMMIT_RETRIES) {
throw new Error(`Tried ${attemptCount} times but the mergeable field is not set. Giving up`);
}
console.log('The `mergeable` field is not set yet. Will retry later.');
return new Promise(resolve => {
setTimeout(async () => {
resolve(await this.getPRCommits(prId, attemptCount + 1));
}, 1000);
});
}
else if (!answer.mergeable) {
throw new Error('PR is not mergeable');
}
const mergeCommitSha = answer.merge_commit_sha;
if (!mergeCommitSha) {
throw new Error('Merge commit SHA is not found');
}
const headCommitSha = answer.head && answer.head.sha;
if (!headCommitSha) {
throw new Error('HEAD commit SHA is not found');
}
return { mergeCommitSha, headCommitSha };
}
const headCommitSha = answer.head && answer.head.sha;
if (!headCommitSha) {
throw new Error('HEAD commit SHA is not found');
async createPRReview(prId, commitSha, body) {
await this.apiPost(path_1.posix.join('pulls', prId.toString(), 'reviews'), {
commit_id: commitSha,
body,
event: 'COMMENT',
});
}
return { mergeCommitSha, headCommitSha };
}
async createPRReview(prId, commitSha, body) {
await this.apiPost(path_1.posix.join('pulls', prId.toString(), 'reviews'), {
commit_id: commitSha,
body,
event: 'COMMENT',
});
}
async setCommitStatus(commitSha, status, description, context) {
await this.apiPost(path_1.posix.join('statuses', commitSha), {
state: status,
description,
context,
});
}
async getFileContent(commitSha, path) {
let answer;
try {
answer = await this.apiGet(path_1.posix.join('contents', path), {
ref: commitSha,
async setCommitStatus(commitSha, status, description, context) {
await this.apiPost(path_1.posix.join('statuses', commitSha), {
state: status,
description,
context,
});
}
catch (_a) {
return null;
async getFileContent(commitSha, path) {
let answer;
try {
answer = await this.apiGet(path_1.posix.join('contents', path), {
ref: commitSha,
});
}
catch (_a) {
return null;
}
answer = ensureSingleResponseData(answer);
if (answer.content === undefined) {
throw new Error(`Content of ${path} not found`);
}
const content = Buffer.from(answer.content, 'base64').toString();
return content;
}
answer = ensureSingleResponseData(answer);
if (answer.content === undefined) {
throw new Error(`Content of ${path} not found`);
async getSinglePackageJson(dir, commitSha) {
const content = await this.getFileContent(commitSha, path_1.posix.join(dir, 'package.json'));
if (!content) {
return null;
}
const filePath = path_1.posix.join('/', dir, 'package.json');
return { filePath, content };
}
const content = Buffer.from(answer.content, 'base64').toString();
return content;
}
async getSinglePackageJson(dir, commitSha) {
const content = await this.getFileContent(commitSha, path_1.posix.join(dir, 'package.json'));
if (!content) {
return null;
}
const filePath = path_1.posix.join('/', dir, 'package.json');
return { filePath, content };
}
async getPackageJsonFiles(commitSha) {
const packageJsons = [];
// Find the top-level package.json first.
const pj = await this.getSinglePackageJson('', commitSha);
if (pj !== null) {
packageJsons.push(pj);
}
// Find `packages/<name>/package.json` files in case this is a monorepo.
let answer;
try {
answer = await this.apiGet('contents/packages', { ref: commitSha });
}
catch (_a) {
// Not a monorepo. Return just the top-level package.json.
return packageJsons;
}
if (!isSingleResponseData(answer)) {
// Response is an array, which means there's the `packages` directory and
// this is a monorepo. Find package.json from each directory under
// `packages`.
for (const entry of answer) {
if (entry.type === 'dir' && entry.name) {
const pj = await this.getSinglePackageJson(path_1.posix.join('packages', entry.name), commitSha);
if (pj !== null) {
packageJsons.push(pj);
async getPackageJsonFiles(commitSha) {
const packageJsons = [];
// Find the top-level package.json first.
const pj = await this.getSinglePackageJson('', commitSha);
if (pj !== null) {
packageJsons.push(pj);
}
// Find `packages/<name>/package.json` files in case this is a monorepo.
let answer;
try {
answer = await this.apiGet('contents/packages', { ref: commitSha });
}
catch (_a) {
// Not a monorepo. Return just the top-level package.json.
return packageJsons;
}
if (!isSingleResponseData(answer)) {
// Response is an array, which means there's the `packages` directory and
// this is a monorepo. Find package.json from each directory under
// `packages`.
for (const entry of answer) {
if (entry.type === 'dir' && entry.name) {
const pj = await this.getSinglePackageJson(path_1.posix.join('packages', entry.name), commitSha);
if (pj !== null) {
packageJsons.push(pj);
}
}
}
}
return packageJsons;
}
return packageJsons;
}
}
// How many times to retry PR commit retrieval until giving up.
GitHubRepository.MAX_PR_COMMIT_RETRIES = 10;
return GitHubRepository;
})();
exports.GitHubRepository = GitHubRepository;
// How many times to retry PR commit retrieval until giving up.
GitHubRepository.MAX_PR_COMMIT_RETRIES = 10;
//# sourceMappingURL=github.js.map

@@ -16,2 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ensurePackageJson = void 0;
const util_1 = require("util");

@@ -18,0 +19,0 @@ function isOldLicenseField(obj) {

@@ -7,2 +7,9 @@ # Changelog

### [2.0.1](https://www.github.com/google/js-green-licenses/compare/v2.0.0...v2.0.1) (2020-05-18)
### Bug Fixes
* Added support for the UNLICENSED NPM magic value (fixes [#113](https://www.github.com/google/js-green-licenses/issues/113)) ([#134](https://www.github.com/google/js-green-licenses/issues/134)) ([c7966eb](https://www.github.com/google/js-green-licenses/commit/c7966eb39a95c3376f3845f7797bb3d72f2c5904))
## [2.0.0](https://www.github.com/google/js-green-licenses/compare/v1.1.0...v2.0.0) (2020-05-07)

@@ -9,0 +16,0 @@

{
"name": "js-green-licenses",
"version": "2.0.0",
"version": "2.0.1",
"description": "JavaScript package.json license checker",

@@ -67,4 +67,4 @@ "main": "build/src/checker.js",

"proxyquire": "^2.0.1",
"typescript": "~3.8.0"
"typescript": "~3.9.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc