forked from lerna/lerna
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publish): Add a "from-git" argument
Publish un-published releases by reading versions from the package.json files and publishing any that are not already available in the registry. Fixes lerna#1648
- Loading branch information
1 parent
159a0b0
commit 257823c
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
|
||
const fetch = require("npm-registry-fetch"); | ||
const log = require("npmlog"); | ||
const pReduce = require("p-reduce"); | ||
|
||
module.exports = getUnpublishedPackages; | ||
|
||
// Only the abbreviated package metadata is needed to | ||
// determine which versions have been published. This | ||
// saves transfer time for packages with a lot of | ||
// history. | ||
const registryOptions = { | ||
Accept: "application/vnd.npm.install-v1+json", | ||
}; | ||
|
||
function getUnpublishedPackages(project, opts) { | ||
log.silly("getPackageVersions"); | ||
|
||
let chain = Promise.resolve(); | ||
|
||
const mapper = (unpublished, pkg) => | ||
fetch(`-/${pkg.name}`, Object.assign({}, opts, registryOptions)).then( | ||
packument => { | ||
if (packument.versions[pkg.version] === undefined) { | ||
unpublished.push(pkg); | ||
} | ||
|
||
return unpublished; | ||
}, | ||
() => { | ||
log.warn("", "Unable to determine published versions, assuming unpublished."); | ||
return unpublished.concat([pkg]); | ||
} | ||
); | ||
|
||
chain = chain.then(() => project.getPackages()); | ||
chain = chain.then(packages => pReduce(packages, mapper, [])); | ||
|
||
return chain; | ||
} |