-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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-package" positional argument (#1708)
Publish un-published releases by reading versions from the package.json files and publishing any that are not already available in the registry. Fixes #1648
- Loading branch information
1 parent
6107c9a
commit 16611be
Showing
9 changed files
with
188 additions
and
9 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
34 changes: 34 additions & 0 deletions
34
commands/publish/__tests__/get-unpublished-packages.test.js
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,34 @@ | ||
"use strict"; | ||
|
||
jest.mock("pacote"); | ||
|
||
const pacote = require("pacote"); | ||
const Project = require("@lerna/project"); | ||
const initFixture = require("@lerna-test/init-fixture")(__dirname); | ||
const getUnpublishedPackages = require("../lib/get-unpublished-packages"); | ||
|
||
pacote.packument.mockImplementation(async pkg => { | ||
if (pkg === "package-1") { | ||
return { | ||
versions: {}, | ||
}; | ||
} | ||
|
||
if (pkg === "package-2") { | ||
return { | ||
versions: { | ||
"1.0.0": {}, | ||
}, | ||
}; | ||
} | ||
|
||
throw new Error("package does not exist"); | ||
}); | ||
|
||
test("getUnpublishedPackages", async () => { | ||
const cwd = await initFixture("licenses-names"); | ||
const project = new Project(cwd); | ||
|
||
const pkgs = await getUnpublishedPackages(project, {}); | ||
expect(pkgs.map(p => p.name)).toEqual(["package-1", "package-3", "package-4", "package-5"]); | ||
}); |
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
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,3 @@ | ||
"use strict"; | ||
|
||
module.exports = jest.fn(() => Promise.resolve([])); |
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,33 @@ | ||
"use strict"; | ||
|
||
const log = require("npmlog"); | ||
const pReduce = require("p-reduce"); | ||
const pacote = require("pacote"); | ||
|
||
module.exports = getUnpublishedPackages; | ||
|
||
function getUnpublishedPackages(project, opts) { | ||
log.silly("getPackageVersions"); | ||
|
||
let chain = Promise.resolve(); | ||
|
||
const mapper = (unpublished, pkg) => | ||
pacote.packument(pkg.name, opts.snapshot).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; | ||
} |
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 |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
"p-map": "^1.2.0", | ||
"p-pipe": "^1.2.0", | ||
"p-reduce": "^1.0.0", | ||
"pacote": "^9.1.0", | ||
"semver": "^5.5.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.