Skip to content

Commit

Permalink
Using a single tag to publish new package
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioszabo committed Jul 4, 2024
1 parent 8f5f7aa commit e9ef304
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions src/models/constructNewPackagePublishData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function constructNewPackagePublishData(opts = {}) {
// ownerRepo = OWNER/REPO (string)
// provider = Provider object from VCS
// packageJson = The full `package.json` from the latest version
// tags = The GitHub API return of tag information
// tag = The GitHub API return of tag information
// readme = The full text readme

let out = {};
Expand All @@ -39,15 +39,15 @@ module.exports = function constructNewPackagePublishData(opts = {}) {

// Now lets setup some constants that we will use over and over
let PACK_NAME = findPackName(opts);
let LATEST_VER = findLatestVer(opts);
let PACKAGE_VER = findLatestVer(opts);

out.name = PACK_NAME;
out.owner = findOwner(opts);
out.readme = typeof opts.readme === "string" ? opts.readme : "";
out.repository = opts.provider;
out.metadata = buildMeta(opts);
out.releases = {
latest: LATEST_VER,
latest: PACKAGE_VER,
};

// From here we want to build or version objects, except we don't have the
Expand All @@ -59,15 +59,8 @@ module.exports = function constructNewPackagePublishData(opts = {}) {
out.versions = {};
// So lets loop through all versions, we will use the same meta object for the
// latest, while getting mandatory only fields for the rest
out.versions[LATEST_VER] = buildMeta(opts);

for (let i = 0; i < opts.tags.length; i++) {
let curVer = semver.clean(opts.tags[i].name);
if (curVer && curVer !== LATEST_VER) {
out.versions[curVer] = buildAbsentVer(curVer, opts);
}
}

out.versions[PACKAGE_VER] = buildMeta(opts);
buildAbsentVer(PACKAGE_VER, opts)
// Now we should be good to go

return out;
Expand Down Expand Up @@ -155,7 +148,7 @@ function buildMeta(opts) {
out.engines = { atom: "*" };
}

let tag = findTagForVer(ver, opts);
let tag = opts.tag;

sha = tag.commit.sha ?? false;
tarball = tag.tarball_url ?? false;
Expand All @@ -180,7 +173,7 @@ function buildAbsentVer(ver, opts) {
// Here we will build an "absent" version object. Since we don't have the
// `package.json` of this version, it's considered absent, and will only receive
// the mandatory fields we can discover via the current version, and it's tag
let tag = findTagForVer(ver, opts);
let tag = opts.tag;

let sha = false;
let tarball = false;
Expand Down Expand Up @@ -213,21 +206,3 @@ function buildAbsentVer(ver, opts) {

return out;
}

function findTagForVer(wantedTag, opts) {
let tag = semver.clean(wantedTag);
let tagFound = false;

for (let i = 0; i < opts.tags.length; i++) {
if (semver.clean(opts.tags[i].name) === tag) {
tagFound = opts.tags[i];
}
}

throwIfFalse(tagFound, "", () => {
throw new Error(
`Unable to locate the tag for 'package.json' version '${tag}'. Are you sure you published a matching tag?`
);
});
return tagFound;
}

0 comments on commit e9ef304

Please sign in to comment.