package.dist.createIssue.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of patch-package Show documentation
Show all versions of patch-package Show documentation
Fix broken node modules with no fuss
The newest version!
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.openIssueCreationLink = exports.maybePrintIssueCreationPrompt = exports.shouldRecommendIssue = exports.getPackageVCSDetails = void 0;
const chalk_1 = __importDefault(require("chalk"));
const open_1 = __importDefault(require("open"));
const querystring_1 = require("querystring");
const path_1 = require("./path");
const repoSpecifier = /^([\w.-]+)\/([\w.-]+)$/;
const githubURL = /github.com(:|\/)([\w.-]+\/[\w.-]+?)(.git|\/.*)?$/;
function parseRepoString(repository) {
if (repository.startsWith("github:")) {
repository = repository.replace(/^github:/, "");
}
const urlMatch = repository.match(githubURL);
if (urlMatch) {
repository = urlMatch[2];
}
const specMatch = repository.match(repoSpecifier);
if (!specMatch) {
return null;
}
const [, org, repo] = specMatch;
return { org, repo, provider: "GitHub" };
}
function getPackageVCSDetails(packageDetails) {
const repository = require(path_1.resolve(path_1.join(packageDetails.path, "package.json")))
.repository;
if (!repository) {
return null;
}
if (typeof repository === "string") {
return parseRepoString(repository);
}
else if (typeof repository === "object" &&
typeof repository.url === "string") {
return parseRepoString(repository.url);
}
}
exports.getPackageVCSDetails = getPackageVCSDetails;
function shouldRecommendIssue(vcsDetails) {
if (!vcsDetails) {
return true;
}
const { repo, org } = vcsDetails;
if (repo === "DefinitelyTyped" && org === "DefinitelyTyped") {
return false;
}
return true;
}
exports.shouldRecommendIssue = shouldRecommendIssue;
function maybePrintIssueCreationPrompt(vcs, packageDetails, packageManager) {
if (vcs) {
console.log(`💡 ${chalk_1.default.bold(packageDetails.name)} is on ${vcs.provider}! To draft an issue based on your patch run
${packageManager === "yarn" ? "yarn" : "npx"} patch-package ${packageDetails.pathSpecifier} --create-issue
`);
}
}
exports.maybePrintIssueCreationPrompt = maybePrintIssueCreationPrompt;
function openIssueCreationLink({ packageDetails, patchFileContents, packageVersion, }) {
const vcs = getPackageVCSDetails(packageDetails);
if (!vcs) {
console.log(`Error: Couldn't find VCS details for ${packageDetails.pathSpecifier}`);
process.exit(1);
}
// trim off trailing newline since we add an extra one in the markdown block
if (patchFileContents.endsWith("\n")) {
patchFileContents = patchFileContents.slice(0, -1);
}
open_1.default(`https://github.com/${vcs.org}/${vcs.repo}/issues/new?${querystring_1.stringify({
title: "",
body: `Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used [patch-package](https://github.com/ds300/patch-package) to patch \`${packageDetails.name}@${packageVersion}\` for the project I'm working on.
Here is the diff that solved my problem:
\`\`\`diff
${patchFileContents}
\`\`\`
This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).
`,
})}`);
}
exports.openIssueCreationLink = openIssueCreationLink;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlSXNzdWUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY3JlYXRlSXNzdWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsa0RBQXlCO0FBQ3pCLGdEQUF1QjtBQUN2Qiw2Q0FBdUM7QUFHdkMsaUNBQXNDO0FBRXRDLE1BQU0sYUFBYSxHQUFHLHdCQUF3QixDQUFBO0FBQzlDLE1BQU0sU0FBUyxHQUFHLGtEQUFrRCxDQUFBO0FBRXBFLFNBQVMsZUFBZSxDQUN0QixVQUFrQjtJQUVsQixJQUFJLFVBQVUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLEVBQUU7UUFDcEMsVUFBVSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUMsVUFBVSxFQUFFLEVBQUUsQ0FBQyxDQUFBO0tBQ2hEO0lBQ0QsTUFBTSxRQUFRLEdBQUcsVUFBVSxDQUFDLEtBQUssQ0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