@reelout/yarn 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -4
- package/dist/index.js +24 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/yarn.ts +46 -20
package/README.md
CHANGED
|
@@ -43,10 +43,12 @@ run it without side effects. When it activates, the npm plugin stays inactive
|
|
|
43
43
|
instead, so packages publish through Yarn. The plugin accepts `workspace`,
|
|
44
44
|
`access`, `provenance`, and `stage` options.
|
|
45
45
|
|
|
46
|
-
Yarn releases authenticate with registry credentials
|
|
46
|
+
Yarn releases authenticate with registry credentials: an `NPM_TOKEN`
|
|
47
47
|
environment variable, ambient `.npmrc` authentication (Yarn Classic), or
|
|
48
|
-
`.yarnrc.yml` credentials (Yarn Berry).
|
|
49
|
-
|
|
48
|
+
`.yarnrc.yml` credentials (Yarn Berry). Yarn Berry 4.3.0 and newer can also
|
|
49
|
+
publish through OIDC trusted publishing on supported CI platforms, exchanging
|
|
50
|
+
an identity token with the same registry endpoint as the npm CLI; Yarn
|
|
51
|
+
Classic cannot.
|
|
50
52
|
|
|
51
53
|
The `stage` option controls staged publishing: `true` stages every package
|
|
52
54
|
for later approval instead of publishing it immediately, `false` publishes
|
|
@@ -69,7 +71,9 @@ publish permission for each scheduled package. It checks existing packages
|
|
|
69
71
|
against their maintainers, new scoped packages against the user or
|
|
70
72
|
organization owning the scope, and remaining scoped packages through npm
|
|
71
73
|
collaborator and team permissions. A missing permission fails the release
|
|
72
|
-
before anything is published; inconclusive checks only warn.
|
|
74
|
+
before anything is published; inconclusive checks only warn. Releases
|
|
75
|
+
publishing through OIDC trusted publishing carry no static registry
|
|
76
|
+
credentials, so their access checks stay inconclusive and only warn.
|
|
73
77
|
|
|
74
78
|
## API
|
|
75
79
|
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { filterPackages, formatError, normalizeWorkspace, sortPackages } from "@reelout/core";
|
|
2
|
-
import { bumpPackageDependencies, hasPackageManifest,
|
|
2
|
+
import { bumpPackageDependencies, describeYarnOidcVersionBlocker, hasPackageManifest, inspectVersionedPackageManager, isCompleteReleasePlan, loadPackages, probeReleasePlan, publishPlans, resolveGitRepositoryFromPackage, resolveProvenance, resolveWorkspaceMembers, verifyAuth, verifyPublishAccess, verifyTrustedPublishing } from "@reelout/npm";
|
|
3
3
|
import { colors } from "consola/utils";
|
|
4
4
|
// src/PLUGIN_NAME.ts
|
|
5
5
|
var PLUGIN_NAME = "@reelout/yarn";
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.
|
|
7
|
+
var version = "0.2.1";
|
|
8
8
|
// src/yarn.ts
|
|
9
9
|
/**
|
|
10
10
|
* Built-in plugin that discovers Yarn workspace packages, updates package manifests, and publishes packages with Yarn Classic or Yarn Berry.
|
|
@@ -15,16 +15,22 @@ var version = "0.1.1";
|
|
|
15
15
|
* no root `package.json` or the workspace is not managed by Yarn.
|
|
16
16
|
* Otherwise resolves and attaches Git repository metadata from root
|
|
17
17
|
* package configuration, then verifies registry authentication,
|
|
18
|
-
* failing
|
|
19
|
-
*
|
|
18
|
+
* failing with a version diagnosis in strict mode and warning
|
|
19
|
+
* otherwise when OIDC environment tokens exist but the Yarn release
|
|
20
|
+
* predates the trusted-publishing exchange, and failing in strict
|
|
21
|
+
* mode or skipping the publish phase when no credentials exist.
|
|
20
22
|
* - `discover`: Skips discovery when the plugin is inactive. Discovers
|
|
21
23
|
* workspace member packages, filters them against the `filter` patterns,
|
|
22
24
|
* and loads package metadata into context.
|
|
23
25
|
* - `write`: Skips manifest updates when the plugin is inactive. Bumps
|
|
24
26
|
* internal workspace dependency versions in `package.json` files (skipped
|
|
25
27
|
* in dry-run).
|
|
26
|
-
* - `publish`:
|
|
27
|
-
*
|
|
28
|
+
* - `publish`: For OIDC-authenticated Yarn Berry releases — Yarn 4.3.0 or
|
|
29
|
+
* newer on a supported CI platform targeting the public npm registry —
|
|
30
|
+
* verifies trusted publishing through the registry's token exchange
|
|
31
|
+
* before anything is published, failing when the registry rejects it.
|
|
32
|
+
* Verifies each publishable package's publish permission against its
|
|
33
|
+
* resolved registry, failing when access is definitively
|
|
28
34
|
* missing and warning when it cannot be confirmed. Then authenticates
|
|
29
35
|
* and probes each publishable package version before publishing,
|
|
30
36
|
* skipping versions the registry already holds with identical content
|
|
@@ -52,7 +58,7 @@ var yarn = (options = {}) => {
|
|
|
52
58
|
context.logger.debug(`Yarn workspace could not be found at "${context.cwd}".`);
|
|
53
59
|
return next(context);
|
|
54
60
|
}
|
|
55
|
-
const packageManager = await
|
|
61
|
+
const packageManager = await inspectVersionedPackageManager(context);
|
|
56
62
|
if (!packageManager.isYarn) {
|
|
57
63
|
inactive = true;
|
|
58
64
|
context.logger.debug(`Yarn plugin is inactive: "${packageManager.name}" is the active package manager.`);
|
|
@@ -60,9 +66,15 @@ var yarn = (options = {}) => {
|
|
|
60
66
|
}
|
|
61
67
|
context.repository = await resolveGitRepositoryFromPackage(context.cwd) ?? context.repository;
|
|
62
68
|
if (await verifyAuth(context, packageManager) === "none") {
|
|
63
|
-
|
|
69
|
+
const oidcVersionDiagnosis = describeYarnOidcVersionBlocker(packageManager, context.env);
|
|
70
|
+
if (oidcVersionDiagnosis) {
|
|
71
|
+
if (context.strict) throw new Error(oidcVersionDiagnosis);
|
|
72
|
+
context.logger.warn(colors.yellow(oidcVersionDiagnosis));
|
|
73
|
+
}
|
|
74
|
+
const ambientCredentialFile = packageManager.isYarnBerry ? "(\".yarnrc.yml\")" : "(\".npmrc\")";
|
|
75
|
+
if (context.strict) throw new Error(`NPM_TOKEN or ambient registry credentials ${ambientCredentialFile} are required for Yarn authentication in strict mode.`);
|
|
64
76
|
publishSkipped = true;
|
|
65
|
-
context.logger.warn(colors.yellow(
|
|
77
|
+
context.logger.warn(colors.yellow(`Packages will not be published: NPM_TOKEN or ambient registry credentials ${ambientCredentialFile} are required for Yarn authentication.`));
|
|
66
78
|
}
|
|
67
79
|
return next(context);
|
|
68
80
|
},
|
|
@@ -100,10 +112,11 @@ var yarn = (options = {}) => {
|
|
|
100
112
|
}
|
|
101
113
|
const provenance = await resolveProvenance(context, options.provenance);
|
|
102
114
|
const publishable = context.plans.filter((plan) => isCompleteReleasePlan(plan, PLUGIN_NAME));
|
|
103
|
-
const packageManager = publishable.length > 0 ? await
|
|
115
|
+
const packageManager = publishable.length > 0 ? await inspectVersionedPackageManager(context) : void 0;
|
|
104
116
|
const skipped = /* @__PURE__ */ new Set();
|
|
105
117
|
if (packageManager) {
|
|
106
|
-
await
|
|
118
|
+
const trustedPublishing = await verifyTrustedPublishing(context, publishable, packageManager, PLUGIN_NAME);
|
|
119
|
+
await verifyPublishAccess(context, publishable, packageManager, PLUGIN_NAME, trustedPublishing);
|
|
107
120
|
for (const plan of publishable) await probeReleasePlan(context, plan, packageManager, skipped);
|
|
108
121
|
}
|
|
109
122
|
const publishOptions = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/PLUGIN_NAME.ts","../src/yarn.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nexport const PLUGIN_NAME = '@reelout/yarn'\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport {\n filterPackages,\n formatError,\n normalizeWorkspace,\n sortPackages,\n type Package,\n type ReleasePlan,\n type ReleasePlugin,\n type Workspace,\n} from '@reelout/core'\nimport {\n bumpPackageDependencies,\n hasPackageManifest,\n inspectPackageManager,\n isCompleteReleasePlan,\n loadPackages,\n probeReleasePlan,\n publishPlans,\n resolveGitRepositoryFromPackage,\n resolveProvenance,\n resolveWorkspaceMembers,\n verifyAuth,\n verifyPublishAccess,\n type PublishAccess,\n type PublishPackageOptions,\n} from '@reelout/npm'\nimport { colors } from 'consola/utils'\nimport { version } from '../package.json'\nimport { PLUGIN_NAME } from './PLUGIN_NAME'\n\nexport interface PluginOptions {\n workspace?: Partial<Workspace>\n access?: PublishAccess | null | undefined\n provenance?: boolean | undefined\n stage?: boolean | undefined\n}\n\n/**\n * Built-in plugin that discovers Yarn workspace packages, updates package manifests, and publishes packages with Yarn Classic or Yarn Berry.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `configure`: Leaves the plugin inactive when the working directory holds\n * no root `package.json` or the workspace is not managed by Yarn.\n * Otherwise resolves and attaches Git repository metadata from root\n * package configuration, then verifies registry authentication,\n * failing in strict mode or skipping the publish phase when no\n * credentials exist.\n * - `discover`: Skips discovery when the plugin is inactive. Discovers\n * workspace member packages, filters them against the `filter` patterns,\n * and loads package metadata into context.\n * - `write`: Skips manifest updates when the plugin is inactive. Bumps\n * internal workspace dependency versions in `package.json` files (skipped\n * in dry-run).\n * - `publish`: Verifies each publishable package's publish permission\n * against its resolved registry, failing when access is definitively\n * missing and warning when it cannot be confirmed. Then authenticates\n * and probes each publishable package version before publishing,\n * skipping versions the registry already holds with identical content\n * (syncing their dist-tags) and failing on different or unverifiable\n * content. Publishes non-private packages with Yarn, enabling provenance\n * when the manifest repository is valid, matches the context repository,\n * and is public. Falls back to staged publishing when the registry\n * rejects a direct publish with a staged-publishing requirement and the\n * `stage` option does not disable the fallback, summarizing the staged\n * publications at the end. Skips entirely when no Yarn workspace was\n * found, another package manager is active, or configure-stage\n * verification found no registry authentication.\n *\n * @param options Configuration options for Yarn workspace discovery and publishing behavior.\n * @returns A release plugin configured for Yarn workspace management and package publication.\n */\nconst yarn = (options: PluginOptions = {}): ReleasePlugin => {\n let inactive = false\n\n let publishSkipped = false\n\n return {\n name: PLUGIN_NAME,\n version,\n configure: async (context, next) => {\n if (!(await hasPackageManifest(context.cwd))) {\n context.logger.debug(\n `Yarn workspace could not be found at \"${context.cwd}\".`\n )\n\n return next(context)\n }\n\n const packageManager = await inspectPackageManager(\n context.cwd,\n {\n env: context.env,\n },\n context.logger\n )\n\n if (!packageManager.isYarn) {\n inactive = true\n\n context.logger.debug(\n `Yarn plugin is inactive: \"${packageManager.name}\" is the active package manager.`\n )\n\n return next(context)\n }\n\n const repo = await resolveGitRepositoryFromPackage(context.cwd)\n context.repository = repo ?? context.repository\n\n const authKind = await verifyAuth(context, packageManager)\n\n if (authKind === 'none') {\n if (context.strict) {\n throw new Error(\n 'NPM_TOKEN is required for Yarn authentication in strict mode.'\n )\n }\n\n publishSkipped = true\n\n context.logger.warn(\n colors.yellow(\n 'Packages will not be published: NPM_TOKEN is required for Yarn authentication.'\n )\n )\n }\n\n return next(context)\n },\n discover: async (context, next) => {\n if (inactive || !(await hasPackageManifest(context.cwd))) {\n return next(context)\n }\n\n const packages: Package[] = []\n\n const workspace = normalizeWorkspace(context.cwd, options.workspace)\n\n workspace.members ??= await resolveWorkspaceMembers(context.cwd)\n\n for (const result of await loadPackages(context.cwd, workspace)) {\n if (result.status === 'fulfilled') {\n packages.push({\n ...result.value,\n provider: PLUGIN_NAME,\n })\n } else {\n context.logger.warn(\n colors.yellow(\n `Package could not be loaded: ${formatError(result.reason)}`\n )\n )\n }\n }\n\n context.packages = sortPackages(\n filterPackages(context.packages.concat(packages), context.filter)\n )\n\n return next(context)\n },\n write: async (context, next) => {\n if (inactive || !(await hasPackageManifest(context.cwd))) {\n return next(context)\n }\n\n if (context.dryRun) {\n context.logger.debug('[DRY RUN] Package files will not be updated.')\n } else {\n await bumpPackageDependencies(\n context.cwd,\n context.plans.filter((plan) => plan.package.provider === PLUGIN_NAME)\n )\n }\n\n return next(context)\n },\n publish: async (context, next) => {\n if (inactive) {\n context.logger.debug(\n 'Yarn plugin is inactive: another package manager is active.'\n )\n\n return next(context)\n }\n\n if (!(await hasPackageManifest(context.cwd))) {\n context.logger.debug(\n 'Yarn publishing was skipped: no Yarn workspace was found.'\n )\n\n return next(context)\n }\n\n if (publishSkipped) {\n context.logger.debug(\n 'Yarn publishing was skipped: no registry authentication was found.'\n )\n\n return next(context)\n }\n\n const provenance = await resolveProvenance(context, options.provenance)\n\n const publishable = context.plans.filter((plan) =>\n isCompleteReleasePlan(plan, PLUGIN_NAME)\n )\n\n const packageManager =\n publishable.length > 0\n ? await inspectPackageManager(\n context.cwd,\n { env: context.env },\n context.logger\n )\n : undefined\n\n const skipped = new Set<ReleasePlan>()\n\n if (packageManager) {\n await verifyPublishAccess(\n context,\n publishable,\n packageManager,\n PLUGIN_NAME\n )\n\n for (const plan of publishable) {\n await probeReleasePlan(context, plan, packageManager, skipped)\n }\n }\n\n const publishOptions: PublishPackageOptions = {\n dryRun: context.dryRun,\n tag: context.releaseChannel,\n access: options.access,\n provenance,\n stage: options.stage,\n }\n\n const staged = await publishPlans(\n context,\n PLUGIN_NAME,\n packageManager,\n publishOptions,\n skipped\n )\n\n if (packageManager !== undefined && staged.length > 0) {\n const targets = staged\n .map((plan) => `\"${plan.package.name}@${plan.release.version}\"`)\n .join(', ')\n\n context.logger.warn(\n colors.yellow(\n `Packages were staged instead of published: ${targets}. Review the staged publications with \"yarn npm stage list\" and finish the release with \"yarn npm stage approve <stage-id>\".`\n )\n )\n }\n\n return next(context)\n },\n }\n}\n\nexport default yarn\n"],"mappings":";;;;AAGA,IAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACwE3B,IAAM,QAAQ,UAAyB,CAAC,MAAqB;CAC3D,IAAI,WAAW;CAEf,IAAI,iBAAiB;CAErB,OAAO;EACL,MAAM;EACN;EACA,WAAW,OAAO,SAAS,SAAS;GAClC,IAAI,CAAE,MAAM,mBAAmB,QAAQ,GAAG,GAAI;IAC5C,QAAQ,OAAO,MACb,yCAAyC,QAAQ,IAAI,GACvD;IAEA,OAAO,KAAK,OAAO;GACrB;GAEA,MAAM,iBAAiB,MAAM,sBAC3B,QAAQ,KACR,EACE,KAAK,QAAQ,IACf,GACA,QAAQ,MACV;GAEA,IAAI,CAAC,eAAe,QAAQ;IAC1B,WAAW;IAEX,QAAQ,OAAO,MACb,6BAA6B,eAAe,KAAK,iCACnD;IAEA,OAAO,KAAK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AAM,mBAAmB,QAAQ,GAAG,GAAI;IAC5C,QAAQ,OAAO,MACb,2DACF;IAEA,OAAO,KAAK,OAAO;GACrB;GAEA,IAAI,gBAAgB;IAClB,QAAQ,OAAO,MACb,oEACF;IAEA,OAAO,KAAK,OAAO;GACrB;GAEA,MAAM,aAAa,MAAM,kBAAkB,SAAS,QAAQ,UAAU;GAEtE,MAAM,cAAc,QAAQ,MAAM,QAAQ,SACxC,sBAAsB,MAAM,WAAW,CACzC;GAEA,MAAM,iBACJ,YAAY,SAAS,IACjB,MAAM,sBACJ,QAAQ,KACR,EAAE,KAAK,QAAQ,IAAI,GACnB,QAAQ,MACV,IACA,KAAA;GAEN,MAAM,0BAAU,IAAI,IAAiB;GAErC,IAAI,gBAAgB;IAClB,MAAM,oBACJ,SACA,aACA,gBACA,WACF;IAEA,KAAK,MAAM,QAAQ,aACjB,MAAM,iBAAiB,SAAS,MAAM,gBAAgB,OAAO;GAEjE;GAEA,MAAM,iBAAwC;IAC5C,QAAQ,QAAQ;IAChB,KAAK,QAAQ;IACb,QAAQ,QAAQ;IAChB;IACA,OAAO,QAAQ;GACjB;GAEA,MAAM,SAAS,MAAM,aACnB,SACA,aACA,gBACA,gBACA,OACF;GAEA,IAAI,mBAAmB,KAAA,KAAa,OAAO,SAAS,GAAG;IACrD,MAAM,UAAU,OACb,KAAK,SAAS,IAAI,KAAK,QAAQ,KAAK,GAAG,KAAK,QAAQ,QAAQ,EAAE,CAAC,CAC/D,KAAK,IAAI;IAEZ,QAAQ,OAAO,KACb,OAAO,OACL,8CAA8C,QAAQ,6HACxD,CACF;GACF;GAEA,OAAO,KAAK,OAAO;EACrB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/PLUGIN_NAME.ts","../src/yarn.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nexport const PLUGIN_NAME = '@reelout/yarn'\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport {\n filterPackages,\n formatError,\n normalizeWorkspace,\n sortPackages,\n type Package,\n type ReleasePlan,\n type ReleasePlugin,\n type Workspace,\n} from '@reelout/core'\nimport {\n bumpPackageDependencies,\n describeYarnOidcVersionBlocker,\n hasPackageManifest,\n inspectVersionedPackageManager,\n isCompleteReleasePlan,\n loadPackages,\n probeReleasePlan,\n publishPlans,\n resolveGitRepositoryFromPackage,\n resolveProvenance,\n resolveWorkspaceMembers,\n verifyAuth,\n verifyPublishAccess,\n verifyTrustedPublishing,\n type PublishAccess,\n type PublishPackageOptions,\n} from '@reelout/npm'\nimport { colors } from 'consola/utils'\nimport { version } from '../package.json'\nimport { PLUGIN_NAME } from './PLUGIN_NAME'\n\nexport interface PluginOptions {\n workspace?: Partial<Workspace>\n access?: PublishAccess | null | undefined\n provenance?: boolean | undefined\n stage?: boolean | undefined\n}\n\n/**\n * Built-in plugin that discovers Yarn workspace packages, updates package manifests, and publishes packages with Yarn Classic or Yarn Berry.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `configure`: Leaves the plugin inactive when the working directory holds\n * no root `package.json` or the workspace is not managed by Yarn.\n * Otherwise resolves and attaches Git repository metadata from root\n * package configuration, then verifies registry authentication,\n * failing with a version diagnosis in strict mode and warning\n * otherwise when OIDC environment tokens exist but the Yarn release\n * predates the trusted-publishing exchange, and failing in strict\n * mode or skipping the publish phase when no credentials exist.\n * - `discover`: Skips discovery when the plugin is inactive. Discovers\n * workspace member packages, filters them against the `filter` patterns,\n * and loads package metadata into context.\n * - `write`: Skips manifest updates when the plugin is inactive. Bumps\n * internal workspace dependency versions in `package.json` files (skipped\n * in dry-run).\n * - `publish`: For OIDC-authenticated Yarn Berry releases — Yarn 4.3.0 or\n * newer on a supported CI platform targeting the public npm registry —\n * verifies trusted publishing through the registry's token exchange\n * before anything is published, failing when the registry rejects it.\n * Verifies each publishable package's publish permission against its\n * resolved registry, failing when access is definitively\n * missing and warning when it cannot be confirmed. Then authenticates\n * and probes each publishable package version before publishing,\n * skipping versions the registry already holds with identical content\n * (syncing their dist-tags) and failing on different or unverifiable\n * content. Publishes non-private packages with Yarn, enabling provenance\n * when the manifest repository is valid, matches the context repository,\n * and is public. Falls back to staged publishing when the registry\n * rejects a direct publish with a staged-publishing requirement and the\n * `stage` option does not disable the fallback, summarizing the staged\n * publications at the end. Skips entirely when no Yarn workspace was\n * found, another package manager is active, or configure-stage\n * verification found no registry authentication.\n *\n * @param options Configuration options for Yarn workspace discovery and publishing behavior.\n * @returns A release plugin configured for Yarn workspace management and package publication.\n */\nconst yarn = (options: PluginOptions = {}): ReleasePlugin => {\n let inactive = false\n\n let publishSkipped = false\n\n return {\n name: PLUGIN_NAME,\n version,\n configure: async (context, next) => {\n if (!(await hasPackageManifest(context.cwd))) {\n context.logger.debug(\n `Yarn workspace could not be found at \"${context.cwd}\".`\n )\n\n return next(context)\n }\n\n const packageManager = await inspectVersionedPackageManager(context)\n\n if (!packageManager.isYarn) {\n inactive = true\n\n context.logger.debug(\n `Yarn plugin is inactive: \"${packageManager.name}\" is the active package manager.`\n )\n\n return next(context)\n }\n\n const repo = await resolveGitRepositoryFromPackage(context.cwd)\n context.repository = repo ?? context.repository\n\n const authKind = await verifyAuth(context, packageManager)\n\n if (authKind === 'none') {\n const oidcVersionDiagnosis = describeYarnOidcVersionBlocker(\n packageManager,\n context.env\n )\n\n if (oidcVersionDiagnosis) {\n if (context.strict) {\n throw new Error(oidcVersionDiagnosis)\n }\n\n context.logger.warn(colors.yellow(oidcVersionDiagnosis))\n }\n\n // Yarn Berry reads registry credentials from \".yarnrc.yml\" and\n // Yarn Classic from \".npmrc\", so the message names the file the\n // active release family reads.\n const ambientCredentialFile = packageManager.isYarnBerry\n ? '(\".yarnrc.yml\")'\n : '(\".npmrc\")'\n\n if (context.strict) {\n throw new Error(\n `NPM_TOKEN or ambient registry credentials ${ambientCredentialFile} are required for Yarn authentication in strict mode.`\n )\n }\n\n publishSkipped = true\n\n context.logger.warn(\n colors.yellow(\n `Packages will not be published: NPM_TOKEN or ambient registry credentials ${ambientCredentialFile} are required for Yarn authentication.`\n )\n )\n }\n\n return next(context)\n },\n discover: async (context, next) => {\n if (inactive || !(await hasPackageManifest(context.cwd))) {\n return next(context)\n }\n\n const packages: Package[] = []\n\n const workspace = normalizeWorkspace(context.cwd, options.workspace)\n\n workspace.members ??= await resolveWorkspaceMembers(context.cwd)\n\n for (const result of await loadPackages(context.cwd, workspace)) {\n if (result.status === 'fulfilled') {\n packages.push({\n ...result.value,\n provider: PLUGIN_NAME,\n })\n } else {\n context.logger.warn(\n colors.yellow(\n `Package could not be loaded: ${formatError(result.reason)}`\n )\n )\n }\n }\n\n context.packages = sortPackages(\n filterPackages(context.packages.concat(packages), context.filter)\n )\n\n return next(context)\n },\n write: async (context, next) => {\n if (inactive || !(await hasPackageManifest(context.cwd))) {\n return next(context)\n }\n\n if (context.dryRun) {\n context.logger.debug('[DRY RUN] Package files will not be updated.')\n } else {\n await bumpPackageDependencies(\n context.cwd,\n context.plans.filter((plan) => plan.package.provider === PLUGIN_NAME)\n )\n }\n\n return next(context)\n },\n publish: async (context, next) => {\n if (inactive) {\n context.logger.debug(\n 'Yarn plugin is inactive: another package manager is active.'\n )\n\n return next(context)\n }\n\n if (!(await hasPackageManifest(context.cwd))) {\n context.logger.debug(\n 'Yarn publishing was skipped: no Yarn workspace was found.'\n )\n\n return next(context)\n }\n\n if (publishSkipped) {\n context.logger.debug(\n 'Yarn publishing was skipped: no registry authentication was found.'\n )\n\n return next(context)\n }\n\n const provenance = await resolveProvenance(context, options.provenance)\n\n const publishable = context.plans.filter((plan) =>\n isCompleteReleasePlan(plan, PLUGIN_NAME)\n )\n\n const packageManager =\n publishable.length > 0\n ? await inspectVersionedPackageManager(context)\n : undefined\n\n const skipped = new Set<ReleasePlan>()\n\n if (packageManager) {\n const trustedPublishing = await verifyTrustedPublishing(\n context,\n publishable,\n packageManager,\n PLUGIN_NAME\n )\n\n await verifyPublishAccess(\n context,\n publishable,\n packageManager,\n PLUGIN_NAME,\n trustedPublishing\n )\n\n for (const plan of publishable) {\n await probeReleasePlan(context, plan, packageManager, skipped)\n }\n }\n\n const publishOptions: PublishPackageOptions = {\n dryRun: context.dryRun,\n tag: context.releaseChannel,\n access: options.access,\n provenance,\n stage: options.stage,\n }\n\n const staged = await publishPlans(\n context,\n PLUGIN_NAME,\n packageManager,\n publishOptions,\n skipped\n )\n\n if (packageManager !== undefined && staged.length > 0) {\n const targets = staged\n .map((plan) => `\"${plan.package.name}@${plan.release.version}\"`)\n .join(', ')\n\n context.logger.warn(\n colors.yellow(\n `Packages were staged instead of published: ${targets}. Review the staged publications with \"yarn npm stage list\" and finish the release with \"yarn npm stage approve <stage-id>\".`\n )\n )\n }\n\n return next(context)\n },\n }\n}\n\nexport default yarn\n"],"mappings":";;;;AAGA,IAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgF3B,IAAM,QAAQ,UAAyB,CAAC,MAAqB;CAC3D,IAAI,WAAW;CAEf,IAAI,iBAAiB;CAErB,OAAO;EACL,MAAM;EACN;EACA,WAAW,OAAO,SAAS,SAAS;GAClC,IAAI,CAAE,MAAM,mBAAmB,QAAQ,GAAG,GAAI;IAC5C,QAAQ,OAAO,MACb,yCAAyC,QAAQ,IAAI,GACvD;IAEA,OAAO,KAAK,OAAO;GACrB;GAEA,MAAM,iBAAiB,MAAM,+BAA+B,OAAO;GAEnE,IAAI,CAAC,eAAe,QAAQ;IAC1B,WAAW;IAEX,QAAQ,OAAO,MACb,6BAA6B,eAAe,KAAK,iCACnD;IAEA,OAAO,KAAK,OAAO;GACrB;GAGA,QAAQ,aAAa,MADF,gCAAgC,QAAQ,GAAG,KACjC,QAAQ;GAIrC,IAAI,MAFmB,WAAW,SAAS,cAAc,MAExC,QAAQ;IACvB,MAAM,uBAAuB,+BAC3B,gBACA,QAAQ,GACV;IAEA,IAAI,sBAAsB;KACxB,IAAI,QAAQ,QACV,MAAM,IAAI,MAAM,o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aces, updating manifests and dependency ranges, and publishing packages with Yarn Classic and Yarn Berry.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"release",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"./src"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@reelout/core": "^0.14.
|
|
43
|
-
"@reelout/github": "^0.9.
|
|
44
|
-
"@reelout/npm": "^0.15.
|
|
42
|
+
"@reelout/core": "^0.14.2",
|
|
43
|
+
"@reelout/github": "^0.9.2",
|
|
44
|
+
"@reelout/npm": "^0.15.2",
|
|
45
45
|
"consola": "^3.4.2"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
package/src/yarn.ts
CHANGED
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
} from '@reelout/core'
|
|
14
14
|
import {
|
|
15
15
|
bumpPackageDependencies,
|
|
16
|
+
describeYarnOidcVersionBlocker,
|
|
16
17
|
hasPackageManifest,
|
|
17
|
-
|
|
18
|
+
inspectVersionedPackageManager,
|
|
18
19
|
isCompleteReleasePlan,
|
|
19
20
|
loadPackages,
|
|
20
21
|
probeReleasePlan,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
resolveWorkspaceMembers,
|
|
25
26
|
verifyAuth,
|
|
26
27
|
verifyPublishAccess,
|
|
28
|
+
verifyTrustedPublishing,
|
|
27
29
|
type PublishAccess,
|
|
28
30
|
type PublishPackageOptions,
|
|
29
31
|
} from '@reelout/npm'
|
|
@@ -47,16 +49,22 @@ export interface PluginOptions {
|
|
|
47
49
|
* no root `package.json` or the workspace is not managed by Yarn.
|
|
48
50
|
* Otherwise resolves and attaches Git repository metadata from root
|
|
49
51
|
* package configuration, then verifies registry authentication,
|
|
50
|
-
* failing
|
|
51
|
-
*
|
|
52
|
+
* failing with a version diagnosis in strict mode and warning
|
|
53
|
+
* otherwise when OIDC environment tokens exist but the Yarn release
|
|
54
|
+
* predates the trusted-publishing exchange, and failing in strict
|
|
55
|
+
* mode or skipping the publish phase when no credentials exist.
|
|
52
56
|
* - `discover`: Skips discovery when the plugin is inactive. Discovers
|
|
53
57
|
* workspace member packages, filters them against the `filter` patterns,
|
|
54
58
|
* and loads package metadata into context.
|
|
55
59
|
* - `write`: Skips manifest updates when the plugin is inactive. Bumps
|
|
56
60
|
* internal workspace dependency versions in `package.json` files (skipped
|
|
57
61
|
* in dry-run).
|
|
58
|
-
* - `publish`:
|
|
59
|
-
*
|
|
62
|
+
* - `publish`: For OIDC-authenticated Yarn Berry releases — Yarn 4.3.0 or
|
|
63
|
+
* newer on a supported CI platform targeting the public npm registry —
|
|
64
|
+
* verifies trusted publishing through the registry's token exchange
|
|
65
|
+
* before anything is published, failing when the registry rejects it.
|
|
66
|
+
* Verifies each publishable package's publish permission against its
|
|
67
|
+
* resolved registry, failing when access is definitively
|
|
60
68
|
* missing and warning when it cannot be confirmed. Then authenticates
|
|
61
69
|
* and probes each publishable package version before publishing,
|
|
62
70
|
* skipping versions the registry already holds with identical content
|
|
@@ -90,13 +98,7 @@ const yarn = (options: PluginOptions = {}): ReleasePlugin => {
|
|
|
90
98
|
return next(context)
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
const packageManager = await
|
|
94
|
-
context.cwd,
|
|
95
|
-
{
|
|
96
|
-
env: context.env,
|
|
97
|
-
},
|
|
98
|
-
context.logger
|
|
99
|
-
)
|
|
101
|
+
const packageManager = await inspectVersionedPackageManager(context)
|
|
100
102
|
|
|
101
103
|
if (!packageManager.isYarn) {
|
|
102
104
|
inactive = true
|
|
@@ -114,9 +116,29 @@ const yarn = (options: PluginOptions = {}): ReleasePlugin => {
|
|
|
114
116
|
const authKind = await verifyAuth(context, packageManager)
|
|
115
117
|
|
|
116
118
|
if (authKind === 'none') {
|
|
119
|
+
const oidcVersionDiagnosis = describeYarnOidcVersionBlocker(
|
|
120
|
+
packageManager,
|
|
121
|
+
context.env
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
if (oidcVersionDiagnosis) {
|
|
125
|
+
if (context.strict) {
|
|
126
|
+
throw new Error(oidcVersionDiagnosis)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
context.logger.warn(colors.yellow(oidcVersionDiagnosis))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Yarn Berry reads registry credentials from ".yarnrc.yml" and
|
|
133
|
+
// Yarn Classic from ".npmrc", so the message names the file the
|
|
134
|
+
// active release family reads.
|
|
135
|
+
const ambientCredentialFile = packageManager.isYarnBerry
|
|
136
|
+
? '(".yarnrc.yml")'
|
|
137
|
+
: '(".npmrc")'
|
|
138
|
+
|
|
117
139
|
if (context.strict) {
|
|
118
140
|
throw new Error(
|
|
119
|
-
|
|
141
|
+
`NPM_TOKEN or ambient registry credentials ${ambientCredentialFile} are required for Yarn authentication in strict mode.`
|
|
120
142
|
)
|
|
121
143
|
}
|
|
122
144
|
|
|
@@ -124,7 +146,7 @@ const yarn = (options: PluginOptions = {}): ReleasePlugin => {
|
|
|
124
146
|
|
|
125
147
|
context.logger.warn(
|
|
126
148
|
colors.yellow(
|
|
127
|
-
|
|
149
|
+
`Packages will not be published: NPM_TOKEN or ambient registry credentials ${ambientCredentialFile} are required for Yarn authentication.`
|
|
128
150
|
)
|
|
129
151
|
)
|
|
130
152
|
}
|
|
@@ -212,23 +234,27 @@ const yarn = (options: PluginOptions = {}): ReleasePlugin => {
|
|
|
212
234
|
|
|
213
235
|
const packageManager =
|
|
214
236
|
publishable.length > 0
|
|
215
|
-
? await
|
|
216
|
-
context.cwd,
|
|
217
|
-
{ env: context.env },
|
|
218
|
-
context.logger
|
|
219
|
-
)
|
|
237
|
+
? await inspectVersionedPackageManager(context)
|
|
220
238
|
: undefined
|
|
221
239
|
|
|
222
240
|
const skipped = new Set<ReleasePlan>()
|
|
223
241
|
|
|
224
242
|
if (packageManager) {
|
|
225
|
-
await
|
|
243
|
+
const trustedPublishing = await verifyTrustedPublishing(
|
|
226
244
|
context,
|
|
227
245
|
publishable,
|
|
228
246
|
packageManager,
|
|
229
247
|
PLUGIN_NAME
|
|
230
248
|
)
|
|
231
249
|
|
|
250
|
+
await verifyPublishAccess(
|
|
251
|
+
context,
|
|
252
|
+
publishable,
|
|
253
|
+
packageManager,
|
|
254
|
+
PLUGIN_NAME,
|
|
255
|
+
trustedPublishing
|
|
256
|
+
)
|
|
257
|
+
|
|
232
258
|
for (const plan of publishable) {
|
|
233
259
|
await probeReleasePlan(context, plan, packageManager, skipped)
|
|
234
260
|
}
|