@git.zone/cli 7.3.0 → 7.4.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.
- package/assets/templates/npm/.package.json +1 -1
- package/assets/templates/service/.package.json +1 -1
- package/assets/templates/wcc/.package.json +1 -1
- package/assets/templates/website/.package.json +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/mod_release/classes.releasejournal.d.ts +8 -2
- package/dist_ts/mod_release/classes.releasejournal.js +2 -2
- package/dist_ts/mod_release/helpers.npmartifact.d.ts +57 -4
- package/dist_ts/mod_release/helpers.npmartifact.js +228 -9
- package/dist_ts/mod_release/helpers.releasepreparation.d.ts +7 -2
- package/dist_ts/mod_release/helpers.releasepreparation.js +20 -6
- package/dist_ts/mod_release/helpers.releasepublication.js +38 -8
- package/dist_ts/mod_release/index.js +27 -11
- package/package.json +2 -2
- package/readme.md +48 -5
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/mod_release/classes.releasejournal.ts +10 -3
- package/ts/mod_release/helpers.npmartifact.ts +379 -16
- package/ts/mod_release/helpers.releasepreparation.ts +25 -3
- package/ts/mod_release/helpers.releasepublication.ts +60 -0
- package/ts/mod_release/index.ts +54 -8
|
@@ -2,6 +2,7 @@ import * as plugins from "./mod.plugins.js";
|
|
|
2
2
|
import {
|
|
3
3
|
releaseArtifactFileName,
|
|
4
4
|
type IReleaseArtifact,
|
|
5
|
+
type TReleaseNpmAccess,
|
|
5
6
|
} from "./classes.releasejournal.js";
|
|
6
7
|
import { assertCredentialFreeGitPushDestination } from "./helpers.releasebranch.js";
|
|
7
8
|
import {
|
|
@@ -87,7 +88,13 @@ export interface INpmArtifactProbeResult {
|
|
|
87
88
|
| "tarball-conflict"
|
|
88
89
|
| "tag-conflict"
|
|
89
90
|
| "registry-response"
|
|
90
|
-
| "network-error"
|
|
91
|
+
| "network-error"
|
|
92
|
+
| "authentication-required";
|
|
93
|
+
/**
|
|
94
|
+
* Why the registry did not confirm the configured authentication, as a
|
|
95
|
+
* redacted command diagnostic. Only authenticated probes set it.
|
|
96
|
+
*/
|
|
97
|
+
failure?: string;
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
export interface INpmArtifactProbeOptions {
|
|
@@ -732,14 +739,59 @@ export const verifyStoredNpmArtifact = async (
|
|
|
732
739
|
}
|
|
733
740
|
};
|
|
734
741
|
|
|
742
|
+
/**
|
|
743
|
+
* Binds a registry command to one destination. A scope registry configured in
|
|
744
|
+
* an .npmrc takes precedence over `--registry` for that scope's packages, so a
|
|
745
|
+
* scoped package also gets its scope bound to the destination; otherwise the
|
|
746
|
+
* command could read from or publish to a different registry than the journal
|
|
747
|
+
* names.
|
|
748
|
+
*/
|
|
749
|
+
export const buildNpmDestinationArgs = (
|
|
750
|
+
registryArg: string,
|
|
751
|
+
packageNameArg: string,
|
|
752
|
+
): string[] => {
|
|
753
|
+
assertNpmPackageName(packageNameArg);
|
|
754
|
+
const registry = normalizeNpmRegistryUrl(registryArg);
|
|
755
|
+
const scope = packageNameArg.startsWith("@")
|
|
756
|
+
? packageNameArg.slice(0, packageNameArg.indexOf("/"))
|
|
757
|
+
: undefined;
|
|
758
|
+
return [
|
|
759
|
+
`--registry=${registry}`,
|
|
760
|
+
...(scope ? [`--config.${scope}:registry=${registry}`] : []),
|
|
761
|
+
];
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
const buildPrivateDestinationArgs = (
|
|
765
|
+
registryArg: string,
|
|
766
|
+
packageNameArg: string | undefined,
|
|
767
|
+
): string[] => {
|
|
768
|
+
if (packageNameArg === undefined) {
|
|
769
|
+
throw new Error(
|
|
770
|
+
"Private npm publication requires the package name its scope binds.",
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
return buildNpmDestinationArgs(registryArg, packageNameArg);
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Public packages publish exactly as they always have. Private packages
|
|
778
|
+
* publish with restricted access, bound to the destination for their scope as
|
|
779
|
+
* well, because their verification reads through the same binding.
|
|
780
|
+
*/
|
|
735
781
|
export const buildPnpmPublishArgs = (
|
|
736
782
|
artifactPathArg: string,
|
|
737
783
|
registryArg: string,
|
|
784
|
+
accessArg: TReleaseNpmAccess = "public",
|
|
785
|
+
packageNameArg?: string,
|
|
738
786
|
): string[] => [
|
|
739
787
|
"publish",
|
|
740
788
|
artifactPathArg,
|
|
741
|
-
|
|
742
|
-
|
|
789
|
+
...(accessArg === "public"
|
|
790
|
+
? [`--registry=${normalizeNpmRegistryUrl(registryArg)}`, "--access=public"]
|
|
791
|
+
: [
|
|
792
|
+
...buildPrivateDestinationArgs(registryArg, packageNameArg),
|
|
793
|
+
"--access=restricted",
|
|
794
|
+
]),
|
|
743
795
|
"--tag=latest",
|
|
744
796
|
"--no-git-checks",
|
|
745
797
|
"--ignore-scripts",
|
|
@@ -752,12 +804,19 @@ export const publishNpmArtifact = async (
|
|
|
752
804
|
artifactPathArg: string,
|
|
753
805
|
registryArg: string,
|
|
754
806
|
capabilityArg: IPnpmReleaseCapability | undefined,
|
|
807
|
+
accessArg: TReleaseNpmAccess = "public",
|
|
808
|
+
packageNameArg?: string,
|
|
755
809
|
): Promise<{ exitCode: number; output: string; failure?: string }> => {
|
|
756
810
|
const result = await smartshellArg.execSpawn(
|
|
757
811
|
"pnpm",
|
|
758
812
|
buildQualifiedPnpmArgs(
|
|
759
813
|
capabilityArg,
|
|
760
|
-
buildPnpmPublishArgs(
|
|
814
|
+
buildPnpmPublishArgs(
|
|
815
|
+
artifactPathArg,
|
|
816
|
+
registryArg,
|
|
817
|
+
accessArg,
|
|
818
|
+
packageNameArg,
|
|
819
|
+
),
|
|
761
820
|
),
|
|
762
821
|
{
|
|
763
822
|
cwd: cwdArg,
|
|
@@ -1043,11 +1102,14 @@ export const probeAnonymousNpmArtifact = async (
|
|
|
1043
1102
|
}
|
|
1044
1103
|
};
|
|
1045
1104
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1105
|
+
/**
|
|
1106
|
+
* Repeats one probe until it proves the artifact or a conflict, or until its
|
|
1107
|
+
* schedule ends. An unconfirmed authentication ends the wait as well: waiting
|
|
1108
|
+
* cannot repair a credential.
|
|
1109
|
+
*/
|
|
1110
|
+
const waitForNpmProbe = async (
|
|
1111
|
+
probeArg: () => Promise<INpmArtifactProbeResult>,
|
|
1112
|
+
optionsArg: INpmArtifactProbeOptions,
|
|
1051
1113
|
): Promise<INpmArtifactProbeResult> => {
|
|
1052
1114
|
const attempts = optionsArg.attempts ?? 10;
|
|
1053
1115
|
const delayMs = optionsArg.delayMs ?? 1_000;
|
|
@@ -1065,13 +1127,12 @@ export const waitForAnonymousNpmArtifact = async (
|
|
|
1065
1127
|
code: "network-error",
|
|
1066
1128
|
};
|
|
1067
1129
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
1068
|
-
lastResult = await
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
)
|
|
1074
|
-
if (lastResult.status === "exact" || lastResult.status === "conflict") {
|
|
1130
|
+
lastResult = await probeArg();
|
|
1131
|
+
if (
|
|
1132
|
+
lastResult.status === "exact" ||
|
|
1133
|
+
lastResult.status === "conflict" ||
|
|
1134
|
+
lastResult.code === "authentication-required"
|
|
1135
|
+
) {
|
|
1075
1136
|
return lastResult;
|
|
1076
1137
|
}
|
|
1077
1138
|
if (attempt + 1 < attempts) {
|
|
@@ -1082,3 +1143,305 @@ export const waitForAnonymousNpmArtifact = async (
|
|
|
1082
1143
|
}
|
|
1083
1144
|
return lastResult;
|
|
1084
1145
|
};
|
|
1146
|
+
|
|
1147
|
+
export const waitForAnonymousNpmArtifact = async (
|
|
1148
|
+
registryArg: string,
|
|
1149
|
+
artifactArg: IReleaseArtifact,
|
|
1150
|
+
tagArg = "latest",
|
|
1151
|
+
optionsArg: INpmArtifactProbeOptions = {},
|
|
1152
|
+
): Promise<INpmArtifactProbeResult> =>
|
|
1153
|
+
waitForNpmProbe(
|
|
1154
|
+
() =>
|
|
1155
|
+
probeAnonymousNpmArtifact(registryArg, artifactArg, tagArg, optionsArg),
|
|
1156
|
+
optionsArg,
|
|
1157
|
+
);
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* The package manager an authenticated registry read runs through. GitZone
|
|
1161
|
+
* never reads, parses, logs or journals a credential: the qualified pnpm reads
|
|
1162
|
+
* its own configuration, exactly as it does when it publishes.
|
|
1163
|
+
*/
|
|
1164
|
+
export interface IAuthenticatedNpmRegistryReader {
|
|
1165
|
+
smartshell: plugins.smartshell.Smartshell;
|
|
1166
|
+
cwd: string;
|
|
1167
|
+
capability: IPnpmReleaseCapability | undefined;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/** The registry did not confirm the configured authentication. */
|
|
1171
|
+
export class NpmRegistryAuthenticationError extends Error {
|
|
1172
|
+
constructor(
|
|
1173
|
+
public readonly registry: string,
|
|
1174
|
+
nextStepArg: string,
|
|
1175
|
+
failureArg?: string,
|
|
1176
|
+
) {
|
|
1177
|
+
super(
|
|
1178
|
+
`npm registry ${registry} did not confirm the configured authentication, so a private package cannot be published or verified there. ` +
|
|
1179
|
+
`Authenticate with \`pnpm login --registry=${registry}\`, then ${nextStepArg}.` +
|
|
1180
|
+
(failureArg ? ` ${failureArg}` : ""),
|
|
1181
|
+
);
|
|
1182
|
+
this.name = "NpmRegistryAuthenticationError";
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
const registryReadTimeoutMs = 30_000;
|
|
1187
|
+
/** Reports that prove the requested package or version does not exist. */
|
|
1188
|
+
const npmNotFoundErrorCodes = new Set([
|
|
1189
|
+
"ERR_PNPM_PACKAGE_NOT_FOUND",
|
|
1190
|
+
"ERR_PNPM_FETCH_404",
|
|
1191
|
+
"E404",
|
|
1192
|
+
]);
|
|
1193
|
+
|
|
1194
|
+
const runRegistryRead = (
|
|
1195
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1196
|
+
argsArg: string[],
|
|
1197
|
+
): Promise<plugins.smartshell.IExecResult> =>
|
|
1198
|
+
readerArg.smartshell.execSpawn(
|
|
1199
|
+
"pnpm",
|
|
1200
|
+
buildQualifiedPnpmArgs(readerArg.capability, argsArg),
|
|
1201
|
+
{
|
|
1202
|
+
cwd: readerArg.cwd,
|
|
1203
|
+
silent: true,
|
|
1204
|
+
timeout: registryReadTimeoutMs,
|
|
1205
|
+
timeoutKillGraceMs: 5_000,
|
|
1206
|
+
maxBuffer: maximumMetadataResponseBytes,
|
|
1207
|
+
},
|
|
1208
|
+
);
|
|
1209
|
+
|
|
1210
|
+
/** A launcher can print warnings before the report, as `pnpm pack` does. */
|
|
1211
|
+
const parseTrailingJsonReport = (stdoutArg: string): unknown => {
|
|
1212
|
+
const stdout = stdoutArg.trim();
|
|
1213
|
+
const reportStart = stdout.lastIndexOf("\n{");
|
|
1214
|
+
return JSON.parse(
|
|
1215
|
+
reportStart === -1 ? stdout : stdout.slice(reportStart + 1),
|
|
1216
|
+
);
|
|
1217
|
+
};
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Asks the registry who the configured authentication belongs to. Success
|
|
1221
|
+
* proves the registry accepts the credential; the answer itself is never
|
|
1222
|
+
* read or printed.
|
|
1223
|
+
*/
|
|
1224
|
+
const readNpmRegistryAuthentication = async (
|
|
1225
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1226
|
+
registryArg: string,
|
|
1227
|
+
): Promise<{ authenticated: true } | { authenticated: false; failure: string }> => {
|
|
1228
|
+
const result = await runRegistryRead(readerArg, [
|
|
1229
|
+
"whoami",
|
|
1230
|
+
`--registry=${normalizeNpmRegistryUrl(registryArg)}`,
|
|
1231
|
+
]);
|
|
1232
|
+
if (result.exitCode === 0 && !result.timedOut && result.stdout.trim()) {
|
|
1233
|
+
return { authenticated: true };
|
|
1234
|
+
}
|
|
1235
|
+
return {
|
|
1236
|
+
authenticated: false,
|
|
1237
|
+
failure: describeCommandFailure(result, {
|
|
1238
|
+
command: "pnpm whoami",
|
|
1239
|
+
timeoutMs: registryReadTimeoutMs,
|
|
1240
|
+
output: "combined",
|
|
1241
|
+
}),
|
|
1242
|
+
};
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Refuses a private npm destination whose configured authentication the
|
|
1247
|
+
* registry does not confirm, before anything is published.
|
|
1248
|
+
*/
|
|
1249
|
+
export const assertNpmRegistryAuthentication = async (
|
|
1250
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1251
|
+
registryArg: string,
|
|
1252
|
+
nextStepArg: string,
|
|
1253
|
+
): Promise<void> => {
|
|
1254
|
+
const registry = normalizeNpmRegistryUrl(registryArg);
|
|
1255
|
+
const authentication = await readNpmRegistryAuthentication(
|
|
1256
|
+
readerArg,
|
|
1257
|
+
registry,
|
|
1258
|
+
);
|
|
1259
|
+
if (!authentication.authenticated) {
|
|
1260
|
+
throw new NpmRegistryAuthenticationError(
|
|
1261
|
+
registry,
|
|
1262
|
+
nextStepArg,
|
|
1263
|
+
authentication.failure,
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
type TAuthenticatedNpmVersionRead =
|
|
1269
|
+
| { status: "present"; metadata: unknown }
|
|
1270
|
+
| { status: "absent" }
|
|
1271
|
+
| {
|
|
1272
|
+
status: "inconclusive";
|
|
1273
|
+
code: "registry-response" | "network-error" | "authentication-required";
|
|
1274
|
+
failure?: string;
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Reads one version's metadata with the registry's configured authentication.
|
|
1279
|
+
* A not-found answer proves absence only when the registry also confirms that
|
|
1280
|
+
* authentication: registries answer an unauthenticated read of a private
|
|
1281
|
+
* package with 401, 403 or 404 alike.
|
|
1282
|
+
*/
|
|
1283
|
+
const readAuthenticatedNpmVersion = async (
|
|
1284
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1285
|
+
registryArg: string,
|
|
1286
|
+
packageNameArg: string,
|
|
1287
|
+
versionArg: string,
|
|
1288
|
+
): Promise<TAuthenticatedNpmVersionRead> => {
|
|
1289
|
+
const destinationArgs = buildNpmDestinationArgs(registryArg, packageNameArg);
|
|
1290
|
+
const result = await runRegistryRead(readerArg, [
|
|
1291
|
+
"view",
|
|
1292
|
+
`${packageNameArg}@${versionArg}`,
|
|
1293
|
+
"--json",
|
|
1294
|
+
...destinationArgs,
|
|
1295
|
+
]);
|
|
1296
|
+
if (result.timedOut) {
|
|
1297
|
+
return { status: "inconclusive", code: "network-error" };
|
|
1298
|
+
}
|
|
1299
|
+
let report: unknown;
|
|
1300
|
+
try {
|
|
1301
|
+
report = parseTrailingJsonReport(result.stdout);
|
|
1302
|
+
} catch {
|
|
1303
|
+
report = undefined;
|
|
1304
|
+
}
|
|
1305
|
+
if (result.exitCode === 0) {
|
|
1306
|
+
return report === undefined
|
|
1307
|
+
? { status: "inconclusive", code: "registry-response" }
|
|
1308
|
+
: { status: "present", metadata: report };
|
|
1309
|
+
}
|
|
1310
|
+
const authentication = await readNpmRegistryAuthentication(
|
|
1311
|
+
readerArg,
|
|
1312
|
+
registryArg,
|
|
1313
|
+
);
|
|
1314
|
+
if (!authentication.authenticated) {
|
|
1315
|
+
return {
|
|
1316
|
+
status: "inconclusive",
|
|
1317
|
+
code: "authentication-required",
|
|
1318
|
+
failure: authentication.failure,
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
const errorCode = (report as { error?: { code?: unknown } } | undefined)
|
|
1322
|
+
?.error?.code;
|
|
1323
|
+
return typeof errorCode === "string" && npmNotFoundErrorCodes.has(errorCode)
|
|
1324
|
+
? { status: "absent" }
|
|
1325
|
+
: { status: "inconclusive", code: "registry-response" };
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* Verifies a private destination through an authenticated metadata read: the
|
|
1330
|
+
* version must exist with the packed artifact's integrity and SHA-1, a
|
|
1331
|
+
* tarball URL on the registry's origin, and the dist-tag rules of the
|
|
1332
|
+
* anonymous probe. pnpm has no command that downloads a tarball with the
|
|
1333
|
+
* registry's authentication, so the bytes are proven by the registry's
|
|
1334
|
+
* integrity record rather than downloaded.
|
|
1335
|
+
*/
|
|
1336
|
+
export const probeAuthenticatedNpmArtifact = async (
|
|
1337
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1338
|
+
registryArg: string,
|
|
1339
|
+
artifactArg: IReleaseArtifact,
|
|
1340
|
+
tagArg = "latest",
|
|
1341
|
+
): Promise<INpmArtifactProbeResult> => {
|
|
1342
|
+
const registry = normalizeNpmRegistryUrl(registryArg);
|
|
1343
|
+
const read = await readAuthenticatedNpmVersion(
|
|
1344
|
+
readerArg,
|
|
1345
|
+
registry,
|
|
1346
|
+
artifactArg.packageName,
|
|
1347
|
+
artifactArg.version,
|
|
1348
|
+
);
|
|
1349
|
+
if (read.status === "absent") return { status: "absent", code: "absent" };
|
|
1350
|
+
if (read.status === "inconclusive") {
|
|
1351
|
+
return {
|
|
1352
|
+
status: "inconclusive",
|
|
1353
|
+
code: read.code,
|
|
1354
|
+
...(read.failure ? { failure: read.failure } : {}),
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
const metadata = read.metadata as {
|
|
1358
|
+
name?: unknown;
|
|
1359
|
+
version?: unknown;
|
|
1360
|
+
dist?: { integrity?: unknown; shasum?: unknown; tarball?: unknown };
|
|
1361
|
+
["dist-tags"]?: Record<string, unknown>;
|
|
1362
|
+
} | null;
|
|
1363
|
+
if (
|
|
1364
|
+
typeof metadata !== "object" ||
|
|
1365
|
+
metadata === null ||
|
|
1366
|
+
Array.isArray(metadata) ||
|
|
1367
|
+
metadata.name !== artifactArg.packageName ||
|
|
1368
|
+
metadata.version !== artifactArg.version ||
|
|
1369
|
+
metadata.dist?.integrity !== artifactArg.integrity ||
|
|
1370
|
+
metadata.dist?.shasum !== artifactArg.sha1 ||
|
|
1371
|
+
typeof metadata.dist?.tarball !== "string"
|
|
1372
|
+
) {
|
|
1373
|
+
return { status: "conflict", code: "metadata-conflict" };
|
|
1374
|
+
}
|
|
1375
|
+
let tarballUrl: URL;
|
|
1376
|
+
try {
|
|
1377
|
+
tarballUrl = new URL(metadata.dist.tarball);
|
|
1378
|
+
} catch {
|
|
1379
|
+
return { status: "conflict", code: "metadata-conflict" };
|
|
1380
|
+
}
|
|
1381
|
+
if (
|
|
1382
|
+
tarballUrl.origin !== new URL(registry).origin ||
|
|
1383
|
+
(tarballUrl.protocol !== "https:" && tarballUrl.protocol !== "http:") ||
|
|
1384
|
+
tarballUrl.username ||
|
|
1385
|
+
tarballUrl.password ||
|
|
1386
|
+
tarballUrl.search ||
|
|
1387
|
+
tarballUrl.hash
|
|
1388
|
+
) {
|
|
1389
|
+
return { status: "conflict", code: "metadata-conflict" };
|
|
1390
|
+
}
|
|
1391
|
+
const taggedVersion = metadata["dist-tags"]?.[tagArg];
|
|
1392
|
+
if (taggedVersion === artifactArg.version) {
|
|
1393
|
+
return { status: "exact", code: "exact" };
|
|
1394
|
+
}
|
|
1395
|
+
if (tagSupersedesVersion(taggedVersion, artifactArg.version)) {
|
|
1396
|
+
return { status: "exact", code: "superseded-tag" };
|
|
1397
|
+
}
|
|
1398
|
+
return { status: "inconclusive", code: "tag-conflict" };
|
|
1399
|
+
};
|
|
1400
|
+
|
|
1401
|
+
export const waitForAuthenticatedNpmArtifact = async (
|
|
1402
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1403
|
+
registryArg: string,
|
|
1404
|
+
artifactArg: IReleaseArtifact,
|
|
1405
|
+
tagArg = "latest",
|
|
1406
|
+
optionsArg: INpmArtifactProbeOptions = {},
|
|
1407
|
+
): Promise<INpmArtifactProbeResult> =>
|
|
1408
|
+
waitForNpmProbe(
|
|
1409
|
+
() =>
|
|
1410
|
+
probeAuthenticatedNpmArtifact(
|
|
1411
|
+
readerArg,
|
|
1412
|
+
registryArg,
|
|
1413
|
+
artifactArg,
|
|
1414
|
+
tagArg,
|
|
1415
|
+
),
|
|
1416
|
+
optionsArg,
|
|
1417
|
+
);
|
|
1418
|
+
|
|
1419
|
+
/**
|
|
1420
|
+
* Recovery without an original artifact must never adopt a published
|
|
1421
|
+
* version; a private version's absence needs a confirmed authentication.
|
|
1422
|
+
*/
|
|
1423
|
+
export const assertAuthenticatedNpmVersionAbsent = async (
|
|
1424
|
+
readerArg: IAuthenticatedNpmRegistryReader,
|
|
1425
|
+
registryArg: string,
|
|
1426
|
+
packageNameArg: string,
|
|
1427
|
+
versionArg: string,
|
|
1428
|
+
nextStepArg: string,
|
|
1429
|
+
): Promise<void> => {
|
|
1430
|
+
const registry = normalizeNpmRegistryUrl(registryArg);
|
|
1431
|
+
assertNpmPackageName(packageNameArg);
|
|
1432
|
+
const read = await readAuthenticatedNpmVersion(
|
|
1433
|
+
readerArg,
|
|
1434
|
+
registry,
|
|
1435
|
+
packageNameArg,
|
|
1436
|
+
versionArg,
|
|
1437
|
+
);
|
|
1438
|
+
if (read.status === "absent") return;
|
|
1439
|
+
if (read.status === "inconclusive" && read.code === "authentication-required") {
|
|
1440
|
+
throw new NpmRegistryAuthenticationError(registry, nextStepArg, read.failure);
|
|
1441
|
+
}
|
|
1442
|
+
throw new Error(
|
|
1443
|
+
`Cannot prove ${packageNameArg}@${versionArg} is unpublished at ${registry} (${
|
|
1444
|
+
read.status === "present" ? "the version exists" : read.code
|
|
1445
|
+
}).`,
|
|
1446
|
+
);
|
|
1447
|
+
};
|
|
@@ -14,9 +14,11 @@ import {
|
|
|
14
14
|
type IReleaseBranchContext,
|
|
15
15
|
} from "./helpers.releasebranch.js";
|
|
16
16
|
import {
|
|
17
|
+
assertAuthenticatedNpmVersionAbsent,
|
|
17
18
|
assertNpmVersionAbsent,
|
|
18
19
|
assertNpmPackageName,
|
|
19
20
|
hashReleaseDestination,
|
|
21
|
+
type IPnpmReleaseCapability,
|
|
20
22
|
} from "./helpers.npmartifact.js";
|
|
21
23
|
import { getReleaseNpmPublicationOrder } from "./helpers.npmpackages.js";
|
|
22
24
|
import { formatCommandFailure } from "./helpers.commandfailure.js";
|
|
@@ -167,9 +169,14 @@ export const assertPackageReleaseRecovery = async (
|
|
|
167
169
|
return manifest.name;
|
|
168
170
|
};
|
|
169
171
|
|
|
170
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* Every package the recovered release publishes must be absent from every
|
|
174
|
+
* registry. A private package's absence is read through the qualified pnpm
|
|
175
|
+
* with the registry's configured authentication.
|
|
176
|
+
*/
|
|
171
177
|
export const assertRecoveryUnpublished = async (
|
|
172
178
|
options: IReleasePreparationRecovery,
|
|
179
|
+
pnpmCapabilityArg?: IPnpmReleaseCapability,
|
|
173
180
|
): Promise<void> => {
|
|
174
181
|
const policy = options.branch.gitRemotePolicy;
|
|
175
182
|
const remoteTags = await runGitRemoteInspection({
|
|
@@ -204,8 +211,23 @@ export const assertRecoveryUnpublished = async (
|
|
|
204
211
|
for (const packageName of getReleaseNpmPublicationOrder(
|
|
205
212
|
options.workflow.npmPackages,
|
|
206
213
|
)) {
|
|
207
|
-
for (const registry of options.workflow.npmRegistries)
|
|
208
|
-
|
|
214
|
+
for (const registry of options.workflow.npmRegistries) {
|
|
215
|
+
if (options.workflow.npmAccessLevel === "private") {
|
|
216
|
+
await assertAuthenticatedNpmVersionAbsent(
|
|
217
|
+
{
|
|
218
|
+
smartshell: options.smartshell,
|
|
219
|
+
cwd: options.branch.sourceCwd,
|
|
220
|
+
capability: pnpmCapabilityArg,
|
|
221
|
+
},
|
|
222
|
+
registry,
|
|
223
|
+
packageName,
|
|
224
|
+
options.version,
|
|
225
|
+
`run \`gitzone release recover ${options.version} -y\``,
|
|
226
|
+
);
|
|
227
|
+
} else {
|
|
228
|
+
await assertNpmVersionAbsent(registry, packageName, options.version);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
209
231
|
}
|
|
210
232
|
};
|
|
211
233
|
|
|
@@ -27,10 +27,13 @@ import {
|
|
|
27
27
|
npmPublishWasAccepted,
|
|
28
28
|
planNpmAvailabilityProbes,
|
|
29
29
|
probeAnonymousNpmArtifact,
|
|
30
|
+
probeAuthenticatedNpmArtifact,
|
|
30
31
|
publishNpmArtifact,
|
|
31
32
|
verifyStoredNpmArtifact,
|
|
32
33
|
waitForAnonymousNpmArtifact,
|
|
34
|
+
waitForAuthenticatedNpmArtifact,
|
|
33
35
|
buildQualifiedPnpmArgs,
|
|
36
|
+
NpmRegistryAuthenticationError,
|
|
34
37
|
type IPnpmReleaseCapability,
|
|
35
38
|
type INpmArtifactProbeOptions,
|
|
36
39
|
type INpmArtifactProbeResult,
|
|
@@ -563,7 +566,12 @@ const executeGitTarget = async (
|
|
|
563
566
|
);
|
|
564
567
|
};
|
|
565
568
|
|
|
569
|
+
/**
|
|
570
|
+
* Public destinations verify anonymously. Private destinations verify through
|
|
571
|
+
* the qualified pnpm with the registry's configured authentication.
|
|
572
|
+
*/
|
|
566
573
|
const probeNpm = async (
|
|
574
|
+
optionsArg: IReleasePublicationOptions,
|
|
567
575
|
journalArg: TReleaseJournal,
|
|
568
576
|
registryArg: string,
|
|
569
577
|
probeOptionsArg: INpmArtifactProbeOptions | undefined,
|
|
@@ -571,6 +579,27 @@ const probeNpm = async (
|
|
|
571
579
|
packageNameArg?: string,
|
|
572
580
|
): Promise<INpmArtifactProbeResult> => {
|
|
573
581
|
const artifact = getReleaseNpmArtifact(journalArg, packageNameArg);
|
|
582
|
+
if (journalArg.npm.access === "private") {
|
|
583
|
+
const reader = {
|
|
584
|
+
smartshell: optionsArg.smartshell,
|
|
585
|
+
cwd: optionsArg.cwd,
|
|
586
|
+
capability: optionsArg.pnpmCapability,
|
|
587
|
+
};
|
|
588
|
+
return waitArg
|
|
589
|
+
? waitForAuthenticatedNpmArtifact(
|
|
590
|
+
reader,
|
|
591
|
+
registryArg,
|
|
592
|
+
artifact,
|
|
593
|
+
journalArg.npm.tag,
|
|
594
|
+
probeOptionsArg,
|
|
595
|
+
)
|
|
596
|
+
: probeAuthenticatedNpmArtifact(
|
|
597
|
+
reader,
|
|
598
|
+
registryArg,
|
|
599
|
+
artifact,
|
|
600
|
+
journalArg.npm.tag,
|
|
601
|
+
);
|
|
602
|
+
}
|
|
574
603
|
return waitArg
|
|
575
604
|
? waitForAnonymousNpmArtifact(
|
|
576
605
|
registryArg,
|
|
@@ -620,6 +649,25 @@ const reportAcceptedNpmTarget = (
|
|
|
620
649
|
);
|
|
621
650
|
};
|
|
622
651
|
|
|
652
|
+
/**
|
|
653
|
+
* A private destination whose registry does not confirm the configured
|
|
654
|
+
* authentication can neither be proven published nor proven absent. The run
|
|
655
|
+
* stops with the journal unchanged, and resume verifies again.
|
|
656
|
+
*/
|
|
657
|
+
const assertNpmProbeAuthenticated = (
|
|
658
|
+
journalArg: TReleaseJournal,
|
|
659
|
+
registryArg: string,
|
|
660
|
+
probeArg: INpmArtifactProbeResult,
|
|
661
|
+
): void => {
|
|
662
|
+
if (probeArg.code === "authentication-required") {
|
|
663
|
+
throw new NpmRegistryAuthenticationError(
|
|
664
|
+
registryArg,
|
|
665
|
+
`run \`gitzone release resume ${journalArg.release.version} -y\``,
|
|
666
|
+
probeArg.failure,
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
623
671
|
const markNpmProbeFailure = async (
|
|
624
672
|
optionsArg: IReleasePublicationOptions,
|
|
625
673
|
journalArg: TReleaseJournal,
|
|
@@ -653,12 +701,14 @@ const executeNpmRegistry = async (
|
|
|
653
701
|
let journal = journalArg;
|
|
654
702
|
let status = getTargetStatus(journal, selector);
|
|
655
703
|
let probe = await probeNpm(
|
|
704
|
+
optionsArg,
|
|
656
705
|
journal,
|
|
657
706
|
registryArg,
|
|
658
707
|
optionsArg.npmProbeOptions,
|
|
659
708
|
false,
|
|
660
709
|
packageNameArg,
|
|
661
710
|
);
|
|
711
|
+
assertNpmProbeAuthenticated(journal, registryArg, probe);
|
|
662
712
|
|
|
663
713
|
if (status.state === "verified") {
|
|
664
714
|
if (probe.status === "exact") {
|
|
@@ -755,6 +805,7 @@ const executeNpmRegistry = async (
|
|
|
755
805
|
`Waiting for npm availability: ${describeNpmTarget(registryArg, packageNameArg)}`,
|
|
756
806
|
);
|
|
757
807
|
probe = await probeNpm(
|
|
808
|
+
optionsArg,
|
|
758
809
|
journal,
|
|
759
810
|
registryArg,
|
|
760
811
|
availabilityProbeOptions(optionsArg),
|
|
@@ -766,6 +817,7 @@ const executeNpmRegistry = async (
|
|
|
766
817
|
? journal.release.mainOid
|
|
767
818
|
: journal.git.expectedRemoteMainOid || undefined,
|
|
768
819
|
);
|
|
820
|
+
assertNpmProbeAuthenticated(journal, registryArg, probe);
|
|
769
821
|
const becameReadable = await settleAccepted(probe);
|
|
770
822
|
if (becameReadable) return becameReadable;
|
|
771
823
|
reportAcceptedNpmTarget(journal, registryArg, packageNameArg);
|
|
@@ -773,12 +825,14 @@ const executeNpmRegistry = async (
|
|
|
773
825
|
}
|
|
774
826
|
|
|
775
827
|
probe = await probeNpm(
|
|
828
|
+
optionsArg,
|
|
776
829
|
journal,
|
|
777
830
|
registryArg,
|
|
778
831
|
optionsArg.npmProbeOptions,
|
|
779
832
|
false,
|
|
780
833
|
packageNameArg,
|
|
781
834
|
);
|
|
835
|
+
assertNpmProbeAuthenticated(journal, registryArg, probe);
|
|
782
836
|
if (probe.status === "exact") {
|
|
783
837
|
if (status.attempts === 0 && journal.npm.alreadyPublished === "error") {
|
|
784
838
|
await markUnclaimedTarget(
|
|
@@ -831,8 +885,11 @@ const executeNpmRegistry = async (
|
|
|
831
885
|
artifactPath,
|
|
832
886
|
registryArg,
|
|
833
887
|
optionsArg.pnpmCapability,
|
|
888
|
+
journal.npm.access,
|
|
889
|
+
artifact.packageName,
|
|
834
890
|
);
|
|
835
891
|
probe = await probeNpm(
|
|
892
|
+
optionsArg,
|
|
836
893
|
journal,
|
|
837
894
|
registryArg,
|
|
838
895
|
availabilityProbeOptions(optionsArg),
|
|
@@ -866,6 +923,9 @@ const executeNpmRegistry = async (
|
|
|
866
923
|
"accepted",
|
|
867
924
|
null,
|
|
868
925
|
);
|
|
926
|
+
// The upload stays accepted and is never sent again; resume verifies it
|
|
927
|
+
// once the registry confirms the authentication.
|
|
928
|
+
assertNpmProbeAuthenticated(journal, registryArg, probe);
|
|
869
929
|
if (!deferVerificationArg)
|
|
870
930
|
reportAcceptedNpmTarget(journal, registryArg, packageNameArg);
|
|
871
931
|
return journal;
|