UNPKG

tsd-check

Version:
27 lines (26 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const fs = require("fs"); const utils_1 = require("../utils"); /** * Rule which enforces the typings file to be present in the `files` list in `package.json`. * * @param context - The context object. * @returns A list of custom diagnostics. */ exports.default = (context) => { const { pkg, typingsFile } = context; if (!Array.isArray(pkg.files)) { return []; } const normalizedTypingsFile = path.normalize(typingsFile); const normalizedFiles = pkg.files.map(path.normalize); if (normalizedFiles.includes(normalizedTypingsFile)) { return []; } const content = fs.readFileSync(path.join(context.cwd, 'package.json'), 'utf8'); return [ Object.assign({ fileName: 'package.json', message: `TypeScript type definition \`${normalizedTypingsFile}\` is not part of the \`files\` list.`, severity: 'error' }, utils_1.getJSONPropertyPosition(content, 'files')) ]; };