@astra-kit/rp 0.0.0-stage → 0.10.0

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.
Files changed (125) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +352 -2
  4. package/bin/astra-rp.js +51 -0
  5. package/package.json +93 -4
  6. package/src/build-gate.js +157 -0
  7. package/src/changelog-blocks.js +53 -0
  8. package/src/changelog.js +108 -0
  9. package/src/constants/build-gate.js +30 -0
  10. package/src/constants/changelog-draft.js +180 -0
  11. package/src/constants/changelog.js +74 -0
  12. package/src/constants/ci-release.js +346 -0
  13. package/src/constants/cli.js +12 -0
  14. package/src/constants/create-version.js +523 -0
  15. package/src/constants/guard-publish.js +29 -0
  16. package/src/constants/index.js +18 -0
  17. package/src/constants/monorepo.js +57 -0
  18. package/src/constants/package-manager.js +56 -0
  19. package/src/constants/registry.js +72 -0
  20. package/src/constants/terminal-ui.js +93 -0
  21. package/src/constants/version-files.js +63 -0
  22. package/src/constants/versions.js +60 -0
  23. package/src/create-version/artifact.js +343 -0
  24. package/src/create-version/changelog-draft-workspace.js +124 -0
  25. package/src/create-version/changelog-draft.js +380 -0
  26. package/src/create-version/changelog.js +264 -0
  27. package/src/create-version/ci-config.js +54 -0
  28. package/src/create-version/ci-publication-history.js +113 -0
  29. package/src/create-version/ci-release-identity-step.js +58 -0
  30. package/src/create-version/ci-setup.js +794 -0
  31. package/src/create-version/ci.js +555 -0
  32. package/src/create-version/committed-tree.js +75 -0
  33. package/src/create-version/config.js +489 -0
  34. package/src/create-version/errors.js +46 -0
  35. package/src/create-version/github-workflow.js +199 -0
  36. package/src/create-version/index.js +54 -0
  37. package/src/create-version/json.js +32 -0
  38. package/src/create-version/jsonc.js +76 -0
  39. package/src/create-version/jsr.js +96 -0
  40. package/src/create-version/local-changes.js +178 -0
  41. package/src/create-version/npm-auth.js +142 -0
  42. package/src/create-version/npm.js +812 -0
  43. package/src/create-version/plan.js +1200 -0
  44. package/src/create-version/process.js +334 -0
  45. package/src/create-version/registry-config.js +121 -0
  46. package/src/create-version/registry-http.js +62 -0
  47. package/src/create-version/registry.js +220 -0
  48. package/src/create-version/release-execution.js +45 -0
  49. package/src/create-version/release-tag-config.js +76 -0
  50. package/src/create-version/run.js +2087 -0
  51. package/src/create-version/state.js +461 -0
  52. package/src/create-version/strict-utf8.js +11 -0
  53. package/src/create-version/templates/release.yml +52 -0
  54. package/src/create-version/templates/vercel-ignore-build.mjs +66 -0
  55. package/src/guard-publish.js +77 -0
  56. package/src/index.js +42 -0
  57. package/src/monorepo/plan.js +475 -0
  58. package/src/monorepo/release-commit.js +46 -0
  59. package/src/monorepo/run.js +927 -0
  60. package/src/monorepo/state.js +206 -0
  61. package/src/monorepo/workspaces.js +327 -0
  62. package/src/package-manager.js +107 -0
  63. package/src/terminal-ui.js +548 -0
  64. package/src/testing.js +70 -0
  65. package/src/version-files.js +142 -0
  66. package/src/versions.js +303 -0
  67. package/types/build-gate.d.ts +43 -0
  68. package/types/changelog-blocks.d.ts +33 -0
  69. package/types/changelog.d.ts +61 -0
  70. package/types/constants/build-gate.d.ts +23 -0
  71. package/types/constants/changelog-draft.d.ts +138 -0
  72. package/types/constants/changelog.d.ts +56 -0
  73. package/types/constants/ci-release.d.ts +284 -0
  74. package/types/constants/cli.d.ts +11 -0
  75. package/types/constants/create-version.d.ts +397 -0
  76. package/types/constants/guard-publish.d.ts +25 -0
  77. package/types/constants/index.d.ts +17 -0
  78. package/types/constants/monorepo.d.ts +45 -0
  79. package/types/constants/package-manager.d.ts +40 -0
  80. package/types/constants/registry.d.ts +79 -0
  81. package/types/constants/terminal-ui.d.ts +73 -0
  82. package/types/constants/version-files.d.ts +51 -0
  83. package/types/constants/versions.d.ts +47 -0
  84. package/types/create-version/artifact.d.ts +113 -0
  85. package/types/create-version/changelog-draft-workspace.d.ts +33 -0
  86. package/types/create-version/changelog-draft.d.ts +127 -0
  87. package/types/create-version/changelog.d.ts +141 -0
  88. package/types/create-version/ci-config.d.ts +33 -0
  89. package/types/create-version/ci-publication-history.d.ts +51 -0
  90. package/types/create-version/ci-release-identity-step.d.ts +12 -0
  91. package/types/create-version/ci-setup.d.ts +148 -0
  92. package/types/create-version/ci.d.ts +145 -0
  93. package/types/create-version/committed-tree.d.ts +55 -0
  94. package/types/create-version/config.d.ts +128 -0
  95. package/types/create-version/errors.d.ts +39 -0
  96. package/types/create-version/github-workflow.d.ts +41 -0
  97. package/types/create-version/index.d.ts +28 -0
  98. package/types/create-version/json.d.ts +21 -0
  99. package/types/create-version/jsonc.d.ts +21 -0
  100. package/types/create-version/jsr.d.ts +52 -0
  101. package/types/create-version/local-changes.d.ts +52 -0
  102. package/types/create-version/npm-auth.d.ts +60 -0
  103. package/types/create-version/npm.d.ts +331 -0
  104. package/types/create-version/plan.d.ts +369 -0
  105. package/types/create-version/process.d.ts +151 -0
  106. package/types/create-version/registry-config.d.ts +56 -0
  107. package/types/create-version/registry-http.d.ts +22 -0
  108. package/types/create-version/registry.d.ts +86 -0
  109. package/types/create-version/release-execution.d.ts +22 -0
  110. package/types/create-version/release-tag-config.d.ts +18 -0
  111. package/types/create-version/run.d.ts +407 -0
  112. package/types/create-version/state.d.ts +204 -0
  113. package/types/create-version/strict-utf8.d.ts +10 -0
  114. package/types/guard-publish.d.ts +49 -0
  115. package/types/index.d.ts +23 -0
  116. package/types/monorepo/plan.d.ts +68 -0
  117. package/types/monorepo/release-commit.d.ts +29 -0
  118. package/types/monorepo/run.d.ts +68 -0
  119. package/types/monorepo/state.d.ts +96 -0
  120. package/types/monorepo/workspaces.d.ts +86 -0
  121. package/types/package-manager.d.ts +58 -0
  122. package/types/terminal-ui.d.ts +196 -0
  123. package/types/testing.d.ts +31 -0
  124. package/types/version-files.d.ts +59 -0
  125. package/types/versions.d.ts +158 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * JSON helpers shared by the release modes: plain-object checks and manifest reads.
3
+ *
4
+ * @module create-version/json
5
+ */
6
+ /**
7
+ * Tells whether a value is a plain JSON object.
8
+ *
9
+ * @param {unknown} value - Any value.
10
+ * @returns {value is Record<string, unknown>} Whether it is a non-array object.
11
+ */
12
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
13
+ /**
14
+ * Reads and parses a JSON manifest from the working tree; read and parse errors propagate as they are.
15
+ *
16
+ * @param {string} directory - Directory the manifest path is relative to.
17
+ * @param {string} [manifestPath] - Manifest path; the `package.json` of the directory by default.
18
+ * @returns {any} Parsed manifest.
19
+ * @throws {Error} When the file cannot be read or is not valid JSON.
20
+ */
21
+ export declare function readJsonManifest(directory: string, manifestPath?: string): any;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Parses native registry JSONC manifests while preserving character offsets for version-only edits.
3
+ *
4
+ * @module create-version/jsonc
5
+ */
6
+ /**
7
+ * Replaces comments and trailing commas with whitespace, without touching string values or offsets.
8
+ *
9
+ * @param {string} content - JSON or JSONC text.
10
+ * @returns {string} JSON text with the same length and line breaks.
11
+ * @throws {Error} When a block comment is unterminated.
12
+ */
13
+ export declare function normalizeJsonc(content: string): string;
14
+ /**
15
+ * Reads a native JSONC manifest as JSON, preserving comments in the caller's source text.
16
+ *
17
+ * @param {string} content - JSONC manifest text.
18
+ * @returns {Record<string, unknown>} Parsed manifest.
19
+ * @throws {Error} When the manifest is not an object or is malformed.
20
+ */
21
+ export declare function parseJsoncManifest(content: string): Record<string, unknown>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Reads and versions native JSR manifests, then publishes with the official JSR or Deno client.
3
+ *
4
+ * @module create-version/jsr
5
+ */
6
+ /**
7
+ * Finds the native JSR manifest inside a package and reads only its publication metadata.
8
+ *
9
+ * @param {string} packageRoot - Package directory.
10
+ * @param {string | null} configFile - Explicit package-relative path, or auto-detection.
11
+ * @returns {{ filePath: string, originalBytes: Buffer, text: string, manifest: Record<string, unknown>, packageName: string }} Native manifest.
12
+ * @throws {Error} When the file is absent, linked outside the package, malformed or unscoped.
13
+ */
14
+ export declare function readJsrManifest(packageRoot: string, configFile?: string | null): {
15
+ filePath: string;
16
+ originalBytes: Buffer;
17
+ text: string;
18
+ manifest: Record<string, unknown>;
19
+ packageName: string;
20
+ };
21
+ /**
22
+ * Prepares a native manifest version edit for the same transaction as package.json; never writes it.
23
+ *
24
+ * @param {{ repositoryRoot: string, reader: import("./process.js").GitReader, commands: import("../package-manager.js").ProjectCommands, config?: { versionFiles: string[] } }} context - Release context.
25
+ * @param {string} packageRoot - Package checkout directory.
26
+ * @param {import("./registry-config.js").ResolvedPublicationOptions} options - Native publication options.
27
+ * @param {string} version - New stable version.
28
+ * @returns {Promise<import("./run.js").ReleaseFileUpdate[]>} Transactional native manifest update.
29
+ * @throws {ReleaseStepError} When the manifest is dirty, untracked or lacks a usable top-level version.
30
+ */
31
+ export declare function prepareJsrVersionUpdates(context: {
32
+ repositoryRoot: string;
33
+ reader: import("./process.js").GitReader;
34
+ commands: import("../package-manager.js").ProjectCommands;
35
+ config?: {
36
+ versionFiles: string[];
37
+ };
38
+ }, packageRoot: string, options: import("./registry-config.js").ResolvedPublicationOptions, version: string): Promise<import("./run.js").ReleaseFileUpdate[]>;
39
+ /**
40
+ * Publishes with a pinned official client and a selected config; the token is never printed by astra-rp.
41
+ *
42
+ * @param {string} packageRoot - Release checkout.
43
+ * @param {{ registryUrl: string, options: import("./registry-config.js").ResolvedPublicationOptions }} registry - Selected native registry.
44
+ * @param {string | null} token - Personal token, or `null` for browser/OIDC authentication.
45
+ * @param {ReturnType<typeof readJsrManifest>} [native] - Native manifest of the package, when the caller already read it.
46
+ * @returns {Promise<number>} Official client exit code.
47
+ * @throws {Error} When a shell operand or token cannot be passed safely.
48
+ */
49
+ export declare function publishToJsr(packageRoot: string, registry: {
50
+ registryUrl: string;
51
+ options: import("./registry-config.js").ResolvedPublicationOptions;
52
+ }, token: string | null, native?: ReturnType<typeof readJsrManifest>): Promise<number>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Local changes of `astra-rp create-version --ignore-local-changes`: the
3
+ * uncommitted changes (staged, unstaged and untracked) are set aside in a
4
+ * `git stash` entry while the release runs, so checks, preparation and
5
+ * publication only see the release commit, and are restored at the end.
6
+ *
7
+ * The restore is exact or nothing: staged changes go back to the index only,
8
+ * unstaged changes to the working tree only and untracked files stay
9
+ * untracked. Every layer is checked before anything is written; when one does
10
+ * not apply cleanly on top of the release, nothing is touched and the stash
11
+ * entry is kept.
12
+ *
13
+ * @module create-version/local-changes
14
+ */
15
+ export type GitReader = import("./process.js").GitReader;
16
+ export type SetAsideChanges = {
17
+ sha: string;
18
+ keptPaths: string[];
19
+ };
20
+ export type LocalChangesRestore = {
21
+ restored: true;
22
+ } | {
23
+ restored: false;
24
+ reason: string;
25
+ };
26
+ /**
27
+ * Sets the uncommitted changes aside in a new stash entry.
28
+ *
29
+ * @param {GitReader} reader - Git reader of the repository root.
30
+ * @param {{ keepChangelog?: boolean, keptPaths?: readonly string[], createVersionCommand?: string }} options - Files
31
+ * that stay in the working tree because a new release commits them (`keepChangelog` keeps the root
32
+ * `CHANGELOG.md`; a monorepo passes every released package's `keptPaths`), and how the project
33
+ * runs create-version (for the hints).
34
+ * @returns {Promise<SetAsideChanges>} Stash entry holding the changes.
35
+ * @throws {ReleaseStepError} When Git cannot create the stash entry; nothing was changed then.
36
+ */
37
+ export declare function setAsideLocalChanges(reader: GitReader, { keepChangelog, keptPaths: configuredKeptPaths, createVersionCommand }: {
38
+ keepChangelog?: boolean;
39
+ keptPaths?: readonly string[];
40
+ createVersionCommand?: string;
41
+ }): Promise<SetAsideChanges>;
42
+ /**
43
+ * Restores the changes set aside by {@link setAsideLocalChanges} exactly as they were: staged
44
+ * changes staged, unstaged changes unstaged and untracked files untracked. Nothing is written
45
+ * unless every layer applies cleanly; the stash entry is dropped only after a full restore.
46
+ *
47
+ * @param {GitReader} reader - Git reader of the repository root.
48
+ * @param {string} repositoryRoot - Repository root.
49
+ * @param {SetAsideChanges} setAside - Stash entry returned by {@link setAsideLocalChanges}.
50
+ * @returns {Promise<LocalChangesRestore>} Whether the changes are back, and why not otherwise.
51
+ */
52
+ export declare function restoreLocalChanges(reader: GitReader, repositoryRoot: string, setAside: SetAsideChanges): Promise<LocalChangesRestore>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Pure explanations of the npm credential check of `astra-rp create-version`:
3
+ * the blocker the planner shows before anything is touched, and the error of a
4
+ * failed `npm publish`, whose output cannot be parsed because npm inherits the
5
+ * terminal (2FA). They name where `NPM_TOKEN` came from, never the token.
6
+ *
7
+ * @module create-version/npm-auth
8
+ */
9
+ export type NpmAuthCheck = import("./npm.js").NpmAuthCheck;
10
+ export type ProjectCommands = import("../package-manager.js").ProjectCommands;
11
+ export type NpmAuthProblem = {
12
+ title: string;
13
+ details: string[];
14
+ };
15
+ /**
16
+ * @typedef {import("./npm.js").NpmAuthCheck} NpmAuthCheck
17
+ * @typedef {import("../package-manager.js").ProjectCommands} ProjectCommands
18
+ * @typedef {{ title: string, details: string[] }} NpmAuthProblem
19
+ */
20
+ /**
21
+ * Names the source of the token for messages.
22
+ *
23
+ * @param {NpmAuthCheck} npmAuth - Check result.
24
+ * @returns {string} Source label, or a generic name when it is unknown.
25
+ */
26
+ export declare function describeNpmTokenSource(npmAuth: NpmAuthCheck): string;
27
+ /**
28
+ * Explains an npm credential check that must stop the release before anything is touched.
29
+ *
30
+ * @param {NpmAuthCheck} npmAuth - Result of `checkNpmPublishAccess`.
31
+ * @param {ProjectCommands} [commands] - Project commands quoted by the fix (pnpm when omitted).
32
+ * @returns {NpmAuthProblem | null} Blocker, or `null` when the check passed or could not decide (`unknown`).
33
+ */
34
+ export declare function describeNpmAuthProblem(npmAuth: NpmAuthCheck, commands?: ProjectCommands): NpmAuthProblem | null;
35
+ /**
36
+ * Warns about a first publication that cannot be told apart from a hidden package: `npm view` and
37
+ * `npm owner ls` answered E404, which is what a registry answers both for a new package and for a
38
+ * private package the token has no access to.
39
+ *
40
+ * @param {NpmAuthCheck} npmAuth - Result of `checkNpmPublishAccess`, confirmed against `npm view`.
41
+ * @returns {string | null} Warning, or `null` when the check is not a first publication.
42
+ */
43
+ export declare function describeNpmFirstPublicationWarning(npmAuth: NpmAuthCheck): string | null;
44
+ /**
45
+ * Explains a failed `npm publish` from the credential check re-run after it: an invalid token, a
46
+ * user without permission on the package or, when the user can publish, the generic failure, which
47
+ * still names a read-only or granular token without write permission as a possible cause.
48
+ *
49
+ * @param {NpmAuthCheck} npmAuth - Result of `checkNpmPublishAccess` after the failure.
50
+ * @param {{ exitCode: number, version: string }} publication - npm exit code and version being published.
51
+ * @param {ProjectCommands} [commands] - Project commands quoted by the hint (pnpm when omitted).
52
+ * @returns {{ message: string, hint: string }} Spanish message and next action for `ReleaseStepError`.
53
+ */
54
+ export declare function describeNpmPublishFailure(npmAuth: NpmAuthCheck, { exitCode, version }: {
55
+ exitCode: number;
56
+ version: string;
57
+ }, commands?: ProjectCommands): {
58
+ message: string;
59
+ hint: string;
60
+ };
@@ -0,0 +1,331 @@
1
+ /**
2
+ * npm adapter of `astra-rp create-version`: resolves the registry a package is
3
+ * published to (`publishConfig`, else npm's own config), resolves `NPM_TOKEN`
4
+ * with a single ordered lookup (environment, repository `.env`, shared
5
+ * `~/.config/astra-rp/.env`), checks that the token can publish the package
6
+ * (`npm whoami` + `npm owner ls`), lists the versions published there
7
+ * (authenticated with `NPM_TOKEN` when available), reads the integrity npm
8
+ * would pack from the release checkout, and publishes the working tree or a
9
+ * prepared archive with `NPM_TOKEN` bound to the publish registry.
10
+ *
11
+ * @module create-version/npm
12
+ */
13
+ import { runCaptured } from "./process.js";
14
+ export type NpmLookup = {
15
+ status: string;
16
+ publishedVersions: string[];
17
+ latestVersion?: string | null;
18
+ reason: string | null;
19
+ registryLabel?: string;
20
+ tag?: string | null;
21
+ };
22
+ export type NpmPackDescription = {
23
+ name: unknown;
24
+ version: unknown;
25
+ integrity: string;
26
+ };
27
+ export type NpmPackResult = {
28
+ pack: NpmPackDescription | null;
29
+ problem: string | null;
30
+ };
31
+ export type NpmTokenResolution = {
32
+ token: string | null;
33
+ source: string | null;
34
+ };
35
+ export type NpmTokenLookup = {
36
+ environment?: NodeJS.ProcessEnv;
37
+ homeDirectory?: string;
38
+ tokenVariable?: string;
39
+ pinScope?: boolean;
40
+ };
41
+ export type NpmAuthCheck = {
42
+ status: string;
43
+ user: string | null;
44
+ source: string | null;
45
+ registryUrl: string;
46
+ packageName: string;
47
+ owners: string[];
48
+ firstPublication: boolean;
49
+ reason: string | null;
50
+ tokenVariable?: string;
51
+ registryLabel?: string;
52
+ };
53
+ /**
54
+ * @typedef {{ status: string, publishedVersions: string[], latestVersion?: string | null, reason: string | null, registryLabel?: string, tag?: string | null }} NpmLookup
55
+ * `latestVersion` is the version the `latest` dist-tag points at, which may be a prerelease.
56
+ * @typedef {{ name: unknown, version: unknown, integrity: string }} NpmPackDescription
57
+ * What `npm pack --dry-run --json` reports for the release checkout: package name, version and `sha512-<base64>` integrity.
58
+ * @typedef {{ pack: NpmPackDescription | null, problem: string | null }} NpmPackResult
59
+ * @typedef {{ token: string | null, source: string | null }} NpmTokenResolution
60
+ * `NPM_TOKEN` and the `NPM_TOKEN_SOURCE` it came from; both `null` when no source defines it.
61
+ * @typedef {{ environment?: NodeJS.ProcessEnv, homeDirectory?: string, tokenVariable?: string, pinScope?: boolean }} NpmTokenLookup
62
+ * Environment and home directory {@link resolveNpmToken} reads; the current process and `os.homedir()` by default.
63
+ * @typedef {{
64
+ * status: string,
65
+ * user: string | null,
66
+ * source: string | null,
67
+ * registryUrl: string,
68
+ * packageName: string,
69
+ * owners: string[],
70
+ * firstPublication: boolean,
71
+ * reason: string | null,
72
+ * tokenVariable?: string,
73
+ * registryLabel?: string,
74
+ * }} NpmAuthCheck
75
+ * Result of {@link checkNpmPublishAccess}: one of `NPM_AUTH_STATUS`, the user the token
76
+ * authenticates as, where the token came from (never the token itself), the owners npm reports
77
+ * and why the check did not pass.
78
+ */
79
+ /**
80
+ * Runs npm with captured output. On Windows npm only resolves through the shell, so every argument
81
+ * is double-quoted there; callers pass validated names, registries and temporary paths only.
82
+ *
83
+ * @param {string[]} npmArguments - Arguments that follow `npm`.
84
+ * @param {string} repositoryRoot - Working directory, whose `.npmrc` npm reads.
85
+ * @param {NodeJS.ProcessEnv} [environment] - Environment of npm; the current process by default.
86
+ * @returns {ReturnType<typeof runCaptured>} Exit status and output.
87
+ * @throws {Error} When an argument could break out of its quotes on the Windows shell.
88
+ */
89
+ export declare function runNpmCaptured(npmArguments: string[], repositoryRoot: string, environment?: NodeJS.ProcessEnv): ReturnType<typeof runCaptured>;
90
+ /**
91
+ * Builds the `npm view` arguments that list the published versions and dist-tags of a package on a registry.
92
+ * `npm view` ignores the manifest `publishConfig`, so the registry is always passed explicitly.
93
+ *
94
+ * @param {string} packageName - npm package name, already checked with `NPM_PACKAGE_NAME_PATTERN`.
95
+ * @param {string} registryUrl - Registry resolved by {@link resolvePublishRegistry}.
96
+ * @param {string | null} [userConfigPath] - Temporary npm config from {@link withNpmAuthConfig} that
97
+ * authenticates the query; `null` queries with npm's usual config.
98
+ * @param {boolean} [pinScope] - Whether to override inherited scope routing with this operation's registry.
99
+ * @returns {string[]} Arguments that follow `npm`.
100
+ * @throws {Error} When the registry is not a valid http(s) URL or has characters unsafe on the Windows shell.
101
+ */
102
+ export declare function buildNpmViewArguments(packageName: string, registryUrl: string, userConfigPath?: string | null, pinScope?: boolean): string[];
103
+ /**
104
+ * Builds the `npm whoami` arguments that ask a registry which user the temporary config authenticates as.
105
+ *
106
+ * @param {string} registryUrl - Registry the package is published to.
107
+ * @param {string} userConfigPath - Temporary npm config from {@link withNpmAuthConfig}.
108
+ * @param {string | null} [packageName] - Package whose scope must use this registry.
109
+ * @returns {string[]} Arguments that follow `npm`.
110
+ * @throws {Error} When the registry is invalid or unsafe on the Windows shell.
111
+ */
112
+ export declare function buildNpmWhoamiArguments(registryUrl: string, userConfigPath: string, packageName?: string | null): string[];
113
+ /**
114
+ * Builds the `npm owner ls` arguments that list the owners of a package on a registry.
115
+ *
116
+ * @param {string} packageName - npm package name, already checked with `NPM_PACKAGE_NAME_PATTERN`.
117
+ * @param {string} registryUrl - Registry the package is published to.
118
+ * @param {string} userConfigPath - Temporary npm config from {@link withNpmAuthConfig}.
119
+ * @returns {string[]} Arguments that follow `npm`.
120
+ * @throws {Error} When the registry is invalid or unsafe on the Windows shell.
121
+ */
122
+ export declare function buildNpmOwnerListArguments(packageName: string, registryUrl: string, userConfigPath: string, pinScope?: boolean): string[];
123
+ /**
124
+ * Resolves `NPM_TOKEN` with the single lookup shared by the diagnosis, `npm view` and the
125
+ * publication: the `NPM_TOKEN` environment variable, else the repository `.env` (ignored by Git),
126
+ * else the file shared by every project, `~/.config/astra-rp/.env`. The token is only returned:
127
+ * it is never written to disk nor loaded into `process.env`.
128
+ *
129
+ * @param {string} repositoryRoot - Repository root holding the optional `.env`.
130
+ * @param {NpmTokenLookup} [lookup] - Environment and home directory to read.
131
+ * @returns {NpmTokenResolution} Token and its source.
132
+ * @throws {Error} When a `.env` that has to be read exists but cannot be read.
133
+ */
134
+ export declare function resolveNpmToken(repositoryRoot: string, { environment, homeDirectory, tokenVariable }?: NpmTokenLookup): NpmTokenResolution;
135
+ /**
136
+ * Builds the environment of an npm command that authenticates with the temporary config: the
137
+ * publish environment ({@link buildNpmPublishEnvironment}) without inherited npm credential
138
+ * variables, plus `NPM_TOKEN`, which npm expands from `${NPM_TOKEN}` in that config. Only the child
139
+ * process receives the token, and it is the only credential npm can use.
140
+ *
141
+ * @param {string} token - Token from {@link resolveNpmToken}.
142
+ * @param {NodeJS.ProcessEnv} [environment] - Environment to copy; the current process by default.
143
+ * @returns {NodeJS.ProcessEnv} Environment for npm.
144
+ */
145
+ export declare function buildNpmTokenEnvironment(token: string, environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
146
+ /**
147
+ * Parses the output of `npm owner ls`: one `<user> <<email>>` line per owner.
148
+ *
149
+ * @param {string} output - Standard output of npm.
150
+ * @returns {string[]} npm user names.
151
+ */
152
+ export declare function parseNpmOwnerList(output: string): string[];
153
+ /**
154
+ * Builds the result of a lookup that could not list the published versions.
155
+ *
156
+ * @param {string | null} reason - Why the lookup failed.
157
+ * @returns {NpmLookup} Failed lookup without versions.
158
+ */
159
+ export declare function failedLookup(reason: string | null): NpmLookup;
160
+ /**
161
+ * Checks, before anything is touched, the credential `npm publish` will use: resolves the token
162
+ * ({@link resolveNpmToken}), asks the registry who it authenticates as (`npm whoami`) and whether
163
+ * that user owns the package (`npm owner ls`). A package the registry does not show (E404) passes as
164
+ * `firstPublication`; registries also hide private packages from users without access, so the
165
+ * snapshot confirms it against the versions `npm view` lists (see `state.js`). Both commands use the same temporary config and registry as
166
+ * `npm publish`. A passing check proves that the token authenticates as an owner, not that it can
167
+ * write: a read-only or granular token without write permission passes too, and npm offers no
168
+ * side-effect-free way to tell before publishing.
169
+ *
170
+ * @param {string} packageName - npm package name.
171
+ * @param {string} repositoryRoot - Repository root, where npm reads its project config.
172
+ * @param {string} registryUrl - Registry from {@link resolvePublishRegistry}.
173
+ * A project `.npmrc` with credentials for the registry blocks as `projectCredentials` without
174
+ * querying it, because npm would authenticate with them instead of `NPM_TOKEN`; an unreadable
175
+ * `.env` or `.npmrc` leaves the check `unknown` with the file it could not read.
176
+ *
177
+ * @param {NpmTokenLookup} [lookup] - Token lookup of {@link resolveNpmToken}.
178
+ * @returns {Promise<NpmAuthCheck>} Check result; never rejects.
179
+ */
180
+ export declare function checkNpmPublishAccess(packageName: string, repositoryRoot: string, registryUrl: string, lookup?: NpmTokenLookup): Promise<NpmAuthCheck>;
181
+ /**
182
+ * Lists the versions of a package published on a registry. With `NPM_TOKEN` ({@link resolveNpmToken})
183
+ * the query authenticates through the same temporary config the publication uses, so a private
184
+ * package can be diagnosed; without it the registry is queried with npm's usual config.
185
+ *
186
+ * @param {string} packageName - npm package name.
187
+ * @param {string} repositoryRoot - Directory whose `.npmrc` npm reads.
188
+ * @param {string} [registryUrl] - Registry the package is published to, from {@link resolvePublishRegistry};
189
+ * defaults to npm's default registry.
190
+ * @returns {Promise<NpmLookup>} Published versions; a never-published package has none. An unreadable
191
+ * `.env` fails the lookup with the file it could not read instead of rejecting.
192
+ */
193
+ export declare function lookupPublishedVersions(packageName: string, repositoryRoot: string, registryUrl?: string, { tokenVariable, tag, pinScope }?: {
194
+ pinScope?: boolean | undefined;
195
+ tag?: string | undefined;
196
+ tokenVariable?: string | undefined;
197
+ }): Promise<NpmLookup>;
198
+ /**
199
+ * Parses the output of `npm pack --dry-run --json`: an array with one package and its `integrity`.
200
+ *
201
+ * @param {string} output - Standard output of npm.
202
+ * @returns {NpmPackResult} Package name, version and integrity, or why the output is unusable.
203
+ */
204
+ export declare function parseNpmPackDryRunOutput(output: string): NpmPackResult;
205
+ /**
206
+ * Asks npm for the integrity of the archive it would pack from the release checkout, without
207
+ * writing anything nor running lifecycle scripts. The command line is constant, so it is safe
208
+ * on the Windows shell.
209
+ *
210
+ * @param {string} repositoryRoot - Package root, as `prepare` left it.
211
+ * @returns {Promise<NpmPackResult>} npm description, or why npm failed or its output is unusable.
212
+ */
213
+ export declare function readNpmPackIntegrity(repositoryRoot: string): Promise<NpmPackResult>;
214
+ /**
215
+ * Returns the registry `npm publish` sends the package to: `publishConfig["@scope:registry"]` for a
216
+ * scoped package that declares it, else `publishConfig.registry`, else the registry npm's own config
217
+ * resolves (project `.npmrc`, environment, global config; see {@link readNpmConfigRegistry}).
218
+ *
219
+ * @param {Record<string, unknown>} manifest - `package.json` being published.
220
+ * @param {string} repositoryRoot - Package root, where npm reads its project config.
221
+ * @returns {Promise<string>} Registry URL, already checked to be a plain http(s) URL.
222
+ * @throws {Error} When the resolved registry is not a plain http(s) URL or npm cannot report its config.
223
+ */
224
+ export declare function resolvePublishRegistry(manifest: Record<string, unknown>, repositoryRoot: string): Promise<string>;
225
+ /**
226
+ * Describes where a published release can be seen: its npmjs.com page when the registry is the
227
+ * public npm registry, else the registry URL with the package and version.
228
+ *
229
+ * @param {{ registryUrl: string, packageName: string, version: string }} release - Published release.
230
+ * @returns {string} Summary text.
231
+ */
232
+ export declare function describePublishedRelease({ registryUrl, packageName, version }: {
233
+ registryUrl: string;
234
+ packageName: string;
235
+ version: string;
236
+ }): string;
237
+ /**
238
+ * Builds the npm config line that binds `${NPM_TOKEN}` to a registry, in the form npm matches
239
+ * credentials with: `//<host>[:port]<path>/:_authToken=${NPM_TOKEN}` (no protocol, trailing `/`).
240
+ *
241
+ * @param {string} registryUrl - Registry `npm publish` uses.
242
+ * @returns {string} Config line ending with a newline; the token itself is never written.
243
+ * @throws {Error} When the registry is not a plain http(s) URL (credentials, query and fragment are rejected).
244
+ */
245
+ export declare function buildNpmAuthConfigLine(registryUrl: string): string;
246
+ /**
247
+ * Finds a credential for the registry in the project `.npmrc` (repository root). npm prefers the
248
+ * project config over the temporary `--userconfig` that binds `NPM_TOKEN`, so such a credential
249
+ * would authenticate every command instead of the token. Only keys are read, never values.
250
+ *
251
+ * @param {string} repositoryRoot - Repository root holding the optional `.npmrc`.
252
+ * @param {string} registryUrl - Registry the package is published to.
253
+ * @returns {string | null} First credential key for the registry, or `null` when there is none.
254
+ * @throws {Error} When the `.npmrc` exists but cannot be read, or the registry is not a plain http(s) URL.
255
+ */
256
+ export declare function findProjectNpmCredentialKey(repositoryRoot: string, registryUrl: string): string | null;
257
+ /**
258
+ * Runs an operation with a temporary npm user config outside the repository
259
+ * that only references `${NPM_TOKEN}` for the publish registry: npm expands it
260
+ * from the environment, so the token never reaches the disk or a command line,
261
+ * and no repository needs an `.npmrc` (which pnpm refuses to expand and warns
262
+ * about). The config is always removed afterwards.
263
+ *
264
+ * @template T
265
+ * @param {string} authConfigLine - Line built by {@link buildNpmAuthConfigLine}; an empty line
266
+ * gives npm a user config without credentials, which only replaces `~/.npmrc`.
267
+ * @param {(userConfigPath: string) => Promise<T>} operation - Receives the path for `npm --userconfig`.
268
+ * @param {string} [parentDirectory] - Where the temporary directory is created; defaults to the OS temp directory.
269
+ * @returns {Promise<T>} The operation result.
270
+ */
271
+ export declare function withNpmAuthConfig<T>(authConfigLine: string, operation: (userConfigPath: string) => Promise<T>, parentDirectory?: string): Promise<T>;
272
+ /**
273
+ * Builds the `npm publish` arguments, without the user config. A prepared
274
+ * archive is prefixed with `./` because npm parses a bare relative operand
275
+ * such as `releases/1.9.0-abc/pkg-1.9.0.tgz` as a package spec instead of a file.
276
+ *
277
+ * @param {string | null} [artifactPath] - Archive relative to the root, already checked with `isSafeArtifactPath`; `null` publishes the working tree.
278
+ * @param {string | null} [registryUrl] - Registry from {@link resolvePublishRegistry} passed as `--registry`, so npm
279
+ * publishes where it was resolved even from a checkout without the project `.npmrc`; `null` leaves it to npm's config.
280
+ * @param {{ access?: "public" | "restricted" | null, tag?: string | null, provenance?: boolean, packageName?: string | null }} [options] - Publication flags; `null` omits a registry-owned setting.
281
+ * @returns {string[]} Arguments that follow `npm`.
282
+ * @throws {Error} When the registry is not a valid http(s) URL or has characters unsafe on the Windows shell.
283
+ */
284
+ export declare function buildNpmPublishArguments(artifactPath?: string | null, registryUrl?: string | null, { access, tag, provenance, packageName }?: {
285
+ access?: "public" | "restricted" | null;
286
+ tag?: string | null;
287
+ provenance?: boolean;
288
+ packageName?: string | null;
289
+ }): string[];
290
+ /**
291
+ * Builds the environment of `npm publish` without the inherited package
292
+ * manager user agent. npm reads `npm_config_user_agent` as its `user-agent`
293
+ * config, so under `pnpm create-version` its lifecycle scripts would report
294
+ * pnpm and `astra-rp guard-publish` would block its own npm publication.
295
+ * Without it npm reports its own user agent (`npm/…`). npm reads its config
296
+ * variables in any case (`NPM_CONFIG_USER_AGENT` too), so every casing is dropped.
297
+ *
298
+ * @param {NodeJS.ProcessEnv} [environment] - Environment to copy; the current process by default.
299
+ * @returns {NodeJS.ProcessEnv} Copy without `npm_config_user_agent` in any casing.
300
+ */
301
+ export declare function buildNpmPublishEnvironment(environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
302
+ /**
303
+ * Publishes the working tree, or a prepared archive, to npm. `NPM_TOKEN` comes
304
+ * from {@link resolveNpmToken} and only reaches npm through the child
305
+ * environment and a temporary user config. npm inherits the terminal, so its
306
+ * interactive browser or one-time-password (2FA) confirmation works; that is
307
+ * also why its output cannot be parsed, and a failure is explained afterwards
308
+ * with {@link checkNpmPublishAccess}.
309
+ *
310
+ * @param {string} repositoryRoot - Repository root, where `NPM_TOKEN` is looked up; also the package root unless `packageRoot` is given.
311
+ * @param {{ authConfigLine: string, artifactPath?: string | null, packageRoot?: string, registryUrl?: string | null, tokenVariable?: string, authentication?: "token" | "oidc", access?: "public" | "restricted" | null, tag?: string | null, packageName?: string | null }} publication - Registry credential
312
+ * line from {@link buildNpmAuthConfigLine}, the archive relative to the package root (already checked with
313
+ * `isSafeArtifactPath`; without it the working tree is published), the directory of a workspace package and the
314
+ * registry to pass explicitly (see {@link buildNpmPublishArguments}).
315
+ * @returns {Promise<{ exitCode: number, missingToken: boolean }>} npm exit code, or a missing-token result without running npm.
316
+ * @throws {Error} When the temporary config path could break out of its shell quotes.
317
+ */
318
+ export declare function publishToNpm(repositoryRoot: string, { authConfigLine, artifactPath, packageRoot, registryUrl, tokenVariable, authentication, access, tag, packageName }: {
319
+ authConfigLine: string;
320
+ artifactPath?: string | null;
321
+ packageRoot?: string;
322
+ registryUrl?: string | null;
323
+ tokenVariable?: string;
324
+ authentication?: "token" | "oidc";
325
+ access?: "public" | "restricted" | null;
326
+ tag?: string | null;
327
+ packageName?: string | null;
328
+ }): Promise<{
329
+ exitCode: number;
330
+ missingToken: boolean;
331
+ }>;