mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-08-25 08:08:00 +00:00
207 lines
23 KiB
JavaScript
207 lines
23 KiB
JavaScript
'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path);
|
|
var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs);
|
|
var _readPkgUp = require('read-pkg-up');var _readPkgUp2 = _interopRequireDefault(_readPkgUp);
|
|
var _minimatch = require('minimatch');var _minimatch2 = _interopRequireDefault(_minimatch);
|
|
var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
|
|
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
|
|
var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);
|
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
|
|
|
|
function hasKeys() {let obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
return Object.keys(obj).length > 0;
|
|
}
|
|
|
|
function arrayOrKeys(arrayOrObject) {
|
|
return Array.isArray(arrayOrObject) ? arrayOrObject : Object.keys(arrayOrObject);
|
|
}
|
|
|
|
function extractDepFields(pkg) {
|
|
return {
|
|
dependencies: pkg.dependencies || {},
|
|
devDependencies: pkg.devDependencies || {},
|
|
optionalDependencies: pkg.optionalDependencies || {},
|
|
peerDependencies: pkg.peerDependencies || {},
|
|
// BundledDeps should be in the form of an array, but object notation is also supported by
|
|
// `npm`, so we convert it to an array if it is an object
|
|
bundledDependencies: arrayOrKeys(pkg.bundleDependencies || pkg.bundledDependencies || []) };
|
|
|
|
}
|
|
|
|
function getDependencies(context, packageDir) {
|
|
let paths = [];
|
|
try {
|
|
const packageContent = {
|
|
dependencies: {},
|
|
devDependencies: {},
|
|
optionalDependencies: {},
|
|
peerDependencies: {},
|
|
bundledDependencies: [] };
|
|
|
|
|
|
if (packageDir && packageDir.length > 0) {
|
|
if (!Array.isArray(packageDir)) {
|
|
paths = [_path2.default.resolve(packageDir)];
|
|
} else {
|
|
paths = packageDir.map(dir => _path2.default.resolve(dir));
|
|
}
|
|
}
|
|
|
|
if (paths.length > 0) {
|
|
// use rule config to find package.json
|
|
paths.forEach(dir => {
|
|
const _packageContent = extractDepFields(
|
|
JSON.parse(_fs2.default.readFileSync(_path2.default.join(dir, 'package.json'), 'utf8')));
|
|
|
|
Object.keys(packageContent).forEach(depsKey =>
|
|
Object.assign(packageContent[depsKey], _packageContent[depsKey]));
|
|
|
|
});
|
|
} else {
|
|
// use closest package.json
|
|
Object.assign(
|
|
packageContent,
|
|
extractDepFields(
|
|
_readPkgUp2.default.sync({ cwd: context.getFilename(), normalize: false }).pkg));
|
|
|
|
|
|
}
|
|
|
|
if (![
|
|
packageContent.dependencies,
|
|
packageContent.devDependencies,
|
|
packageContent.optionalDependencies,
|
|
packageContent.peerDependencies,
|
|
packageContent.bundledDependencies].
|
|
some(hasKeys)) {
|
|
return null;
|
|
}
|
|
|
|
return packageContent;
|
|
} catch (e) {
|
|
if (paths.length > 0 && e.code === 'ENOENT') {
|
|
context.report({
|
|
message: 'The package.json file could not be found.',
|
|
loc: { line: 0, column: 0 } });
|
|
|
|
}
|
|
if (e.name === 'JSONError' || e instanceof SyntaxError) {
|
|
context.report({
|
|
message: 'The package.json file could not be parsed: ' + e.message,
|
|
loc: { line: 0, column: 0 } });
|
|
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function missingErrorMessage(packageName) {
|
|
return `'${packageName}' should be listed in the project's dependencies. ` +
|
|
`Run 'npm i -S ${packageName}' to add it`;
|
|
}
|
|
|
|
function devDepErrorMessage(packageName) {
|
|
return `'${packageName}' should be listed in the project's dependencies, not devDependencies.`;
|
|
}
|
|
|
|
function optDepErrorMessage(packageName) {
|
|
return `'${packageName}' should be listed in the project's dependencies, ` +
|
|
`not optionalDependencies.`;
|
|
}
|
|
|
|
function reportIfMissing(context, deps, depsOptions, node, name) {
|
|
// Do not report when importing types
|
|
if (node.importKind === 'type' || node.parent && node.parent.importKind === 'type') {
|
|
return;
|
|
}
|
|
|
|
if ((0, _importType2.default)(name, context) !== 'external') {
|
|
return;
|
|
}
|
|
|
|
const resolved = (0, _resolve2.default)(name, context);
|
|
if (!resolved) {return;}
|
|
|
|
const splitName = name.split('/');
|
|
const packageName = splitName[0][0] === '@' ?
|
|
splitName.slice(0, 2).join('/') :
|
|
splitName[0];
|
|
const isInDeps = deps.dependencies[packageName] !== undefined;
|
|
const isInDevDeps = deps.devDependencies[packageName] !== undefined;
|
|
const isInOptDeps = deps.optionalDependencies[packageName] !== undefined;
|
|
const isInPeerDeps = deps.peerDependencies[packageName] !== undefined;
|
|
const isInBundledDeps = deps.bundledDependencies.indexOf(packageName) !== -1;
|
|
|
|
if (isInDeps ||
|
|
depsOptions.allowDevDeps && isInDevDeps ||
|
|
depsOptions.allowPeerDeps && isInPeerDeps ||
|
|
depsOptions.allowOptDeps && isInOptDeps ||
|
|
depsOptions.allowBundledDeps && isInBundledDeps)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (isInDevDeps && !depsOptions.allowDevDeps) {
|
|
context.report(node, devDepErrorMessage(packageName));
|
|
return;
|
|
}
|
|
|
|
if (isInOptDeps && !depsOptions.allowOptDeps) {
|
|
context.report(node, optDepErrorMessage(packageName));
|
|
return;
|
|
}
|
|
|
|
context.report(node, missingErrorMessage(packageName));
|
|
}
|
|
|
|
function testConfig(config, filename) {
|
|
// Simplest configuration first, either a boolean or nothing.
|
|
if (typeof config === 'boolean' || typeof config === 'undefined') {
|
|
return config;
|
|
}
|
|
// Array of globs.
|
|
return config.some(c =>
|
|
(0, _minimatch2.default)(filename, c) ||
|
|
(0, _minimatch2.default)(filename, _path2.default.join(process.cwd(), c)));
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'problem',
|
|
docs: {
|
|
url: (0, _docsUrl2.default)('no-extraneous-dependencies') },
|
|
|
|
|
|
schema: [
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'devDependencies': { 'type': ['boolean', 'array'] },
|
|
'optionalDependencies': { 'type': ['boolean', 'array'] },
|
|
'peerDependencies': { 'type': ['boolean', 'array'] },
|
|
'bundledDependencies': { 'type': ['boolean', 'array'] },
|
|
'packageDir': { 'type': ['string', 'array'] } },
|
|
|
|
'additionalProperties': false }] },
|
|
|
|
|
|
|
|
|
|
create: function (context) {
|
|
const options = context.options[0] || {};
|
|
const filename = context.getFilename();
|
|
const deps = getDependencies(context, options.packageDir) || extractDepFields({});
|
|
|
|
const depsOptions = {
|
|
allowDevDeps: testConfig(options.devDependencies, filename) !== false,
|
|
allowOptDeps: testConfig(options.optionalDependencies, filename) !== false,
|
|
allowPeerDeps: testConfig(options.peerDependencies, filename) !== false,
|
|
allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false };
|
|
|
|
|
|
return (0, _moduleVisitor2.default)(node => {
|
|
reportIfMissing(context, deps, depsOptions, node, node.value);
|
|
}, { commonjs: true });
|
|
} };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1leHRyYW5lb3VzLWRlcGVuZGVuY2llcy5qcyJdLCJuYW1lcyI6WyJoYXNLZXlzIiwib2JqIiwiT2JqZWN0Iiwia2V5cyIsImxlbmd0aCIsImFycmF5T3JLZXlzIiwiYXJyYXlPck9iamVjdCIsIkFycmF5IiwiaXNBcnJheSIsImV4dHJhY3REZXBGaWVsZHMiLCJwa2ciLCJkZXBlbmRlbmNpZXMiLCJkZXZEZXBlbmRlbmNpZXMiLCJvcHRpb25hbERlcGVuZGVuY2llcyIsInBlZXJEZXBlbmRlbmNpZXMiLCJidW5kbGVkRGVwZW5kZW5jaWVzIiwiYnVuZGxlRGVwZW5kZW5jaWVzIiwiZ2V0RGVwZW5kZW5jaWVzIiwiY29udGV4dCIsIn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FtdLFxuICAgIH1cblxuICAgIGlmIChwYWNrYWdlRGlyICYmIHBhY2thZ2VEaXIubGVuZ3RoID4gMCkge1xuICAgICAgaWYgKCFBcnJheS5pc0FycmF5KHBhY2thZ2VEaXIpKSB7XG4gICAgICAgIHBhdGhzID0gW3BhdGgucmVzb2x2ZShwYWNrYWdlRGlyKV1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHBhdGhzID0gcGFja2FnZURpci5tYXAoZGlyID0+IHBhdGgucmVzb2x2ZShkaXIpKVxuICAgICAgfVxuICAgIH1cblxuICAgIGlmIChwYXRocy5sZW5ndGggPiAwKSB7XG4gICAgICAvLyB1c2UgcnVsZSBjb25maWcgdG8gZmluZCBwYWNrYWdlLmpzb25cbiAgICAgIHBhdGhzLmZvckVhY2goZGlyID0+IHtcbiAgICAgICAgY29uc3QgX3BhY2thZ2VDb250ZW50ID0gZXh0cmFjdERlcEZpZWxkcyhcbiAgICAgICAgICBKU09OLnBhcnNlKGZzLnJlYWRGaWxlU3luYyhwYXRoLmpvaW4oZGlyLCAncGFja2FnZS5qc29uJyksICd1dGY4JykpXG4gICAgICAgIClcbiAgICAgICAgT2JqZWN0LmtleXMocGFja2FnZUNvbnRlbnQpLmZvckVhY2goZGVwc0tleSA9PlxuICAgICAgICAgIE9iamVjdC5hc3NpZ24ocGFja2FnZUNvbnRlbnRbZGVwc0tleV0sIF9wYWNrYWdlQ29udGVudFtkZXBzS2V5XSlcbiAgICAgICAgKVxuICAgICAgfSlcbiAgICB9IGVsc2Uge1xuICAgICAgLy8gdXNlIGNsb3Nlc3QgcGFja2FnZS5qc29uXG4gICAgICBPYmplY3QuYXNzaWduKFxuICAgICAgICBwYWNrYWdlQ29udGVudCxcbiAgICAgICAgZXh0cmFjdERlcEZpZWxkcyhcbiAgICAgICAgICByZWFkUGtnVXAuc3luYyh7Y3dkOiBjb250ZXh0LmdldEZpbGVuYW1lKCksIG5vcm1hbGl6ZTogZmFsc2V9KS5wa2dcbiAgICAgICAg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