-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80fa58b
commit 5f8a788
Showing
9 changed files
with
776 additions
and
38 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
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,29 @@ | ||
import pc from "picocolors"; | ||
import { findUnpublishedPackages } from "../../unpublished-packages/find-unpublished-packages.js"; | ||
import { NodeChronusHost } from "../../utils/node-host.js"; | ||
import { loadChronusWorkspace } from "../../workspace/index.js"; | ||
|
||
export interface ListPendingPublishOptions { | ||
readonly json?: boolean; | ||
} | ||
|
||
export async function listPendingPublish(dir: string, options?: ListPendingPublishOptions) { | ||
const host = NodeChronusHost; | ||
const workspace = await loadChronusWorkspace(host, dir); | ||
|
||
const packages = await findUnpublishedPackages(workspace); | ||
if (options?.json) { | ||
log(JSON.stringify(packages, null, 2)); | ||
} else { | ||
log("Packages with unpublished versions:"); | ||
for (const pkg of packages) { | ||
log(`- ${pkg.name} ${pc.cyan(pkg.version)}`); | ||
} | ||
log(); | ||
} | ||
} | ||
|
||
function log(...args: any[]) { | ||
// eslint-disable-next-line no-console | ||
console.log(...args); | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/chronus/src/unpublished-packages/find-unpublished-packages.ts
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,39 @@ | ||
import pacote from "pacote"; | ||
import type { ChronusWorkspace } from "../index.js"; | ||
import type { Package } from "../workspace-manager/types.js"; | ||
|
||
export async function findUnpublishedPackages(workspace: ChronusWorkspace): Promise<Package[]> { | ||
const data = await Promise.all( | ||
workspace.packages.map(async (pkg) => [pkg, await isPackageVersionPublished(pkg)] as const), | ||
); | ||
return data.filter(([, published]) => !published).map(([pkg]) => pkg); | ||
} | ||
|
||
async function isPackageVersionPublished(pkg: Package): Promise<boolean> { | ||
try { | ||
const manifest = await pacote.manifest(`${pkg.name}@${pkg.version}`); | ||
return manifest.version === pkg.version; | ||
} catch (e: unknown) { | ||
if (isPacoteError(e) && ((e.code === "ETARGET" && e.type === "version") || e.code === "E404")) { | ||
return false; | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
function isPacoteError(e: unknown): e is PacoteError | HttpError { | ||
return typeof e === "object" && e !== null && "code" in e; | ||
} | ||
|
||
interface HttpError { | ||
readonly code: "E404"; | ||
} | ||
interface PacoteError { | ||
readonly code: "ETARGET"; | ||
readonly type: "version"; | ||
readonly wanted: string; | ||
readonly versions: string[]; | ||
readonly name: string; | ||
readonly distTags: Record<string, string>; | ||
readonly defaultTag: string; | ||
} |
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 @@ | ||
export { findUnpublishedPackages } from "./find-unpublished-packages.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
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
Oops, something went wrong.