@git.zone/cli 6.17.1 → 7.0.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/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/helpers.workflow.d.ts +3 -3
- package/dist_ts/helpers.workflow.js +23 -13
- package/dist_ts/mod_config/index.js +8 -9
- package/dist_ts/mod_release/classes.releasejournal.d.ts +9 -3
- package/dist_ts/mod_release/classes.releasejournal.js +75 -112
- package/dist_ts/mod_release/helpers.npmartifact.d.ts +7 -0
- package/dist_ts/mod_release/helpers.npmartifact.js +50 -1
- package/dist_ts/mod_release/helpers.npmpackages.d.ts +39 -0
- package/dist_ts/mod_release/helpers.npmpackages.js +78 -0
- package/dist_ts/mod_release/helpers.releasepreparation.d.ts +8 -2
- package/dist_ts/mod_release/helpers.releasepreparation.js +15 -8
- package/dist_ts/mod_release/index.d.ts +5 -1
- package/dist_ts/mod_release/index.js +78 -53
- package/dist_ts/mod_services/classes.servicemanager.d.ts +1 -1
- package/dist_ts/mod_services/classes.servicemanager.js +2 -2
- package/dist_ts/plugins.d.ts +2 -2
- package/dist_ts/plugins.js +4 -3
- package/package.json +4 -4
- package/readme.md +80 -46
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.workflow.ts +31 -15
- package/ts/mod_config/index.ts +7 -10
- package/ts/mod_release/classes.releasejournal.ts +95 -158
- package/ts/mod_release/helpers.npmartifact.ts +69 -0
- package/ts/mod_release/helpers.npmpackages.ts +140 -0
- package/ts/mod_release/helpers.releasepreparation.ts +25 -11
- package/ts/mod_release/index.ts +113 -75
- package/ts/mod_services/classes.servicemanager.ts +2 -2
- package/ts/plugins.ts +5 -2
|
@@ -145,6 +145,8 @@ export interface IReleaseJournalV2 {
|
|
|
145
145
|
revision: number;
|
|
146
146
|
release: IReleaseIdentity;
|
|
147
147
|
artifact: IReleaseArtifact | null;
|
|
148
|
+
/** Present only when tspublish modules publish, before the root artifact. */
|
|
149
|
+
packages?: IReleasePackage[];
|
|
148
150
|
git: IReleaseGitJournal;
|
|
149
151
|
npm: {
|
|
150
152
|
access: "public";
|
|
@@ -164,12 +166,12 @@ export interface IReleasePackage {
|
|
|
164
166
|
artifact: IReleaseArtifact;
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
/** Modules without Docker; a public root package publishes after them. */
|
|
167
170
|
export interface IReleaseJournalV3 extends Omit<
|
|
168
171
|
IReleaseJournalV1,
|
|
169
|
-
"schemaVersion"
|
|
172
|
+
"schemaVersion"
|
|
170
173
|
> {
|
|
171
174
|
schemaVersion: 3;
|
|
172
|
-
artifact: null;
|
|
173
175
|
packages: IReleasePackage[];
|
|
174
176
|
}
|
|
175
177
|
|
|
@@ -197,32 +199,39 @@ export interface IReleaseJournalV4 extends Omit<
|
|
|
197
199
|
export type TReleaseJournal =
|
|
198
200
|
IReleaseJournalV1 | IReleaseJournalV2 | IReleaseJournalV3 | IReleaseJournalV4;
|
|
199
201
|
|
|
202
|
+
export type TReleaseJournalWithPackages =
|
|
203
|
+
| IReleaseJournalV3
|
|
204
|
+
| IReleaseJournalV4
|
|
205
|
+
| (IReleaseJournalV2 & { packages: IReleasePackage[] });
|
|
206
|
+
|
|
200
207
|
export const hasReleasePackages = (
|
|
201
208
|
journalArg: TReleaseJournal,
|
|
202
|
-
): journalArg is
|
|
209
|
+
): journalArg is TReleaseJournalWithPackages =>
|
|
203
210
|
journalArg.schemaVersion === 3 ||
|
|
204
|
-
(journalArg.schemaVersion === 4 && journalArg.packages.length > 0)
|
|
211
|
+
(journalArg.schemaVersion === 4 && journalArg.packages.length > 0) ||
|
|
212
|
+
(journalArg.schemaVersion === 2 && journalArg.packages !== undefined);
|
|
205
213
|
|
|
206
214
|
export const releasePackageArtifactFile = (packageNameArg: string): string =>
|
|
207
215
|
`package.${plugins.crypto.createHash("sha256").update(packageNameArg).digest("hex")}.tgz`;
|
|
208
216
|
|
|
217
|
+
/** Every stored npm artifact in publication order: the modules, then the root package. */
|
|
209
218
|
export const getReleaseArtifacts = (
|
|
210
219
|
journalArg: TReleaseJournal,
|
|
211
|
-
): IReleaseArtifact[] =>
|
|
212
|
-
hasReleasePackages(journalArg)
|
|
220
|
+
): IReleaseArtifact[] => [
|
|
221
|
+
...(hasReleasePackages(journalArg)
|
|
213
222
|
? journalArg.packages.map((entryArg) => entryArg.artifact)
|
|
214
|
-
:
|
|
215
|
-
|
|
216
|
-
|
|
223
|
+
: []),
|
|
224
|
+
...(journalArg.artifact ? [journalArg.artifact] : []),
|
|
225
|
+
];
|
|
217
226
|
|
|
218
227
|
export const getReleaseNpmArtifact = (
|
|
219
228
|
journalArg: TReleaseJournal,
|
|
220
229
|
packageNameArg?: string,
|
|
221
230
|
): IReleaseArtifact => {
|
|
222
231
|
const artifact = hasReleasePackages(journalArg)
|
|
223
|
-
? journalArg.
|
|
224
|
-
(
|
|
225
|
-
)
|
|
232
|
+
? getReleaseArtifacts(journalArg).find(
|
|
233
|
+
(artifactArg) => artifactArg.packageName === packageNameArg,
|
|
234
|
+
)
|
|
226
235
|
: journalArg.artifact;
|
|
227
236
|
if (!artifact) throw new Error("npm release target has no exact artifact.");
|
|
228
237
|
return artifact;
|
|
@@ -444,6 +453,10 @@ const assertArtifact = (valueArg: unknown): IReleaseArtifact | null => {
|
|
|
444
453
|
return valueArg as unknown as IReleaseArtifact;
|
|
445
454
|
};
|
|
446
455
|
|
|
456
|
+
/** Publication is finished for a target that verified or that was never selected. */
|
|
457
|
+
const isTerminalTargetState = (stateArg: unknown): boolean =>
|
|
458
|
+
stateArg === "verified" || stateArg === "skipped";
|
|
459
|
+
|
|
447
460
|
const isComplete = (journalArg: TReleaseJournal): boolean => {
|
|
448
461
|
const commonComplete = [
|
|
449
462
|
journalArg.git.state,
|
|
@@ -454,7 +467,7 @@ const isComplete = (journalArg: TReleaseJournal): boolean => {
|
|
|
454
467
|
...journalArg.giteaAssets.assets.map((entry) => entry.state),
|
|
455
468
|
]
|
|
456
469
|
: []),
|
|
457
|
-
].every(
|
|
470
|
+
].every(isTerminalTargetState);
|
|
458
471
|
if (
|
|
459
472
|
!commonComplete ||
|
|
460
473
|
journalArg.schemaVersion !== releaseJournalSchemaVersion
|
|
@@ -1003,6 +1016,7 @@ const assertReleaseJournalV2 = (valueArg: unknown): IReleaseJournalV2 => {
|
|
|
1003
1016
|
if (!isPlainObject(valueArg)) {
|
|
1004
1017
|
throw new Error("Release journal root must be a JSON object.");
|
|
1005
1018
|
}
|
|
1019
|
+
const hasPackages = Object.hasOwn(valueArg, "packages");
|
|
1006
1020
|
assertExactKeys(
|
|
1007
1021
|
valueArg,
|
|
1008
1022
|
[
|
|
@@ -1011,6 +1025,7 @@ const assertReleaseJournalV2 = (valueArg: unknown): IReleaseJournalV2 => {
|
|
|
1011
1025
|
"revision",
|
|
1012
1026
|
"release",
|
|
1013
1027
|
"artifact",
|
|
1028
|
+
...(hasPackages ? ["packages"] : []),
|
|
1014
1029
|
"git",
|
|
1015
1030
|
"npm",
|
|
1016
1031
|
"docker",
|
|
@@ -1028,102 +1043,29 @@ const assertReleaseJournalV2 = (valueArg: unknown): IReleaseJournalV2 => {
|
|
|
1028
1043
|
) {
|
|
1029
1044
|
throw new Error("Release journal header is invalid or unsupported.");
|
|
1030
1045
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
)
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
throw new Error("Release journal Git target is missing.");
|
|
1040
|
-
}
|
|
1041
|
-
assertExactKeys(
|
|
1042
|
-
valueArg.git,
|
|
1043
|
-
[
|
|
1044
|
-
"state",
|
|
1045
|
-
"attempts",
|
|
1046
|
-
"attempt",
|
|
1047
|
-
"error",
|
|
1048
|
-
"remote",
|
|
1049
|
-
"destinationHash",
|
|
1050
|
-
"expectedRemoteMainOid",
|
|
1051
|
-
],
|
|
1052
|
-
"Release journal Git target",
|
|
1053
|
-
);
|
|
1054
|
-
assertTargetStatus(valueArg.git, "Release journal Git target");
|
|
1055
|
-
if (valueArg.git.state === "skipped") {
|
|
1056
|
-
if (
|
|
1057
|
-
valueArg.git.remote !== null ||
|
|
1058
|
-
valueArg.git.destinationHash !== null ||
|
|
1059
|
-
valueArg.git.expectedRemoteMainOid !== null
|
|
1060
|
-
) {
|
|
1061
|
-
throw new Error(
|
|
1062
|
-
"Skipped Git journal targets must not retain destination data.",
|
|
1063
|
-
);
|
|
1064
|
-
}
|
|
1065
|
-
} else if (
|
|
1066
|
-
typeof valueArg.git.remote !== "string" ||
|
|
1067
|
-
normalizeReleaseGitRemoteName(valueArg.git.remote) !==
|
|
1068
|
-
valueArg.git.remote ||
|
|
1069
|
-
typeof valueArg.git.destinationHash !== "string" ||
|
|
1070
|
-
!sha256Regex.test(valueArg.git.destinationHash) ||
|
|
1071
|
-
typeof valueArg.git.expectedRemoteMainOid !== "string" ||
|
|
1072
|
-
!gitOidRegex.test(valueArg.git.expectedRemoteMainOid)
|
|
1073
|
-
) {
|
|
1074
|
-
throw new Error("Active Git journal target destination data is invalid.");
|
|
1075
|
-
}
|
|
1076
|
-
if (!isPlainObject(valueArg.npm)) {
|
|
1077
|
-
throw new Error("Release journal npm target is missing.");
|
|
1078
|
-
}
|
|
1079
|
-
assertExactKeys(
|
|
1080
|
-
valueArg.npm,
|
|
1081
|
-
["access", "tag", "alreadyPublished", "registries"],
|
|
1082
|
-
"Release journal npm target",
|
|
1083
|
-
);
|
|
1084
|
-
if (
|
|
1085
|
-
valueArg.npm.access !== "public" ||
|
|
1086
|
-
valueArg.npm.tag !== "latest" ||
|
|
1087
|
-
(valueArg.npm.alreadyPublished !== "success" &&
|
|
1088
|
-
valueArg.npm.alreadyPublished !== "error") ||
|
|
1089
|
-
!Array.isArray(valueArg.npm.registries)
|
|
1090
|
-
) {
|
|
1091
|
-
throw new Error("Release journal npm settings are invalid.");
|
|
1092
|
-
}
|
|
1093
|
-
const registryUrls: string[] = [];
|
|
1094
|
-
for (const [index, rawRegistry] of valueArg.npm.registries.entries()) {
|
|
1095
|
-
if (!isPlainObject(rawRegistry)) {
|
|
1096
|
-
throw new Error(
|
|
1097
|
-
`Release journal npm registry ${index} must be an object.`,
|
|
1098
|
-
);
|
|
1099
|
-
}
|
|
1100
|
-
assertExactKeys(
|
|
1101
|
-
rawRegistry,
|
|
1102
|
-
["state", "attempts", "attempt", "error", "registry"],
|
|
1103
|
-
`Release journal npm registry ${index}`,
|
|
1104
|
-
);
|
|
1105
|
-
assertTargetStatus(rawRegistry, `Release journal npm registry ${index}`);
|
|
1106
|
-
if (
|
|
1107
|
-
typeof rawRegistry.registry !== "string" ||
|
|
1108
|
-
!isCanonicalRegistryUrl(rawRegistry.registry) ||
|
|
1109
|
-
rawRegistry.state === "skipped"
|
|
1110
|
-
) {
|
|
1111
|
-
throw new Error(`Release journal npm registry ${index} URL is invalid.`);
|
|
1112
|
-
}
|
|
1113
|
-
registryUrls.push(rawRegistry.registry);
|
|
1114
|
-
}
|
|
1115
|
-
if (new Set(registryUrls).size !== registryUrls.length) {
|
|
1116
|
-
throw new Error("Release journal npm registries must be unique.");
|
|
1117
|
-
}
|
|
1118
|
-
if (valueArg.npm.registries.length > 0 !== Boolean(artifact)) {
|
|
1119
|
-
throw new Error(
|
|
1120
|
-
"Release journal npm targets and artifact must exist together.",
|
|
1046
|
+
// Identity, Git and npm follow the schema 1 rules, or the schema 3 package
|
|
1047
|
+
// matrix when modules accompany the Docker images; only Docker is added here.
|
|
1048
|
+
const { docker: rawDocker, ...common } = valueArg;
|
|
1049
|
+
const commonComplete =
|
|
1050
|
+
isPlainObject(valueArg.npm) &&
|
|
1051
|
+
Array.isArray(valueArg.npm.registries) &&
|
|
1052
|
+
[valueArg.git, ...valueArg.npm.registries].every(
|
|
1053
|
+
(entry) => isPlainObject(entry) && isTerminalTargetState(entry.state),
|
|
1121
1054
|
);
|
|
1055
|
+
const commonProjection = {
|
|
1056
|
+
...common,
|
|
1057
|
+
completedAt: commonComplete ? valueArg.updatedAt : null,
|
|
1058
|
+
};
|
|
1059
|
+
if (hasPackages) {
|
|
1060
|
+
assertReleaseJournalV3({ ...commonProjection, schemaVersion: 3 });
|
|
1061
|
+
} else {
|
|
1062
|
+
assertReleaseJournalV1({ ...commonProjection, schemaVersion: 1 });
|
|
1122
1063
|
}
|
|
1123
|
-
const
|
|
1064
|
+
const journal = valueArg as unknown as IReleaseJournalV2;
|
|
1065
|
+
const docker = assertDockerJournal(rawDocker, journal.release);
|
|
1124
1066
|
const activePublishers = [
|
|
1125
|
-
|
|
1126
|
-
...
|
|
1067
|
+
journal.git,
|
|
1068
|
+
...journal.npm.registries,
|
|
1127
1069
|
docker.qualification,
|
|
1128
1070
|
...docker.promotions,
|
|
1129
1071
|
docker.cleanup,
|
|
@@ -1133,35 +1075,21 @@ const assertReleaseJournalV2 = (valueArg: unknown): IReleaseJournalV2 => {
|
|
|
1133
1075
|
"Schema 2 release journals permit at most one active publication owner.",
|
|
1134
1076
|
);
|
|
1135
1077
|
}
|
|
1136
|
-
|
|
1137
|
-
valueArg.createdAt,
|
|
1138
|
-
"Release journal createdAt",
|
|
1139
|
-
);
|
|
1140
|
-
const updatedAt = assertIsoTimestamp(
|
|
1141
|
-
valueArg.updatedAt,
|
|
1142
|
-
"Release journal updatedAt",
|
|
1143
|
-
);
|
|
1144
|
-
if (updatedAt < createdAt) {
|
|
1145
|
-
throw new Error("Release journal updatedAt predates createdAt.");
|
|
1146
|
-
}
|
|
1147
|
-
if (valueArg.completedAt !== null) {
|
|
1078
|
+
if (journal.completedAt !== null) {
|
|
1148
1079
|
const completedAt = assertIsoTimestamp(
|
|
1149
|
-
|
|
1080
|
+
journal.completedAt,
|
|
1150
1081
|
"Release journal completedAt",
|
|
1151
1082
|
);
|
|
1152
|
-
if (
|
|
1153
|
-
completedAt < createdAt ||
|
|
1154
|
-
!isComplete(valueArg as unknown as IReleaseJournalV2)
|
|
1155
|
-
) {
|
|
1083
|
+
if (completedAt < journal.createdAt || !isComplete(journal)) {
|
|
1156
1084
|
throw new Error("Release journal completion state is inconsistent.");
|
|
1157
1085
|
}
|
|
1158
|
-
if (completedAt > updatedAt) {
|
|
1086
|
+
if (completedAt > journal.updatedAt) {
|
|
1159
1087
|
throw new Error("Release journal completedAt exceeds updatedAt.");
|
|
1160
1088
|
}
|
|
1161
|
-
} else if (isComplete(
|
|
1089
|
+
} else if (isComplete(journal)) {
|
|
1162
1090
|
throw new Error("Complete release journal must record completedAt.");
|
|
1163
1091
|
}
|
|
1164
|
-
return
|
|
1092
|
+
return journal;
|
|
1165
1093
|
};
|
|
1166
1094
|
|
|
1167
1095
|
const assertReleaseJournalV3 = (
|
|
@@ -1185,7 +1113,6 @@ const assertReleaseJournalV3 = (
|
|
|
1185
1113
|
"Release journal",
|
|
1186
1114
|
);
|
|
1187
1115
|
if (
|
|
1188
|
-
valueArg.artifact !== null ||
|
|
1189
1116
|
!Array.isArray(valueArg.packages) ||
|
|
1190
1117
|
!valueArg.packages.length ||
|
|
1191
1118
|
valueArg.packages.length > 1000 ||
|
|
@@ -1196,33 +1123,18 @@ const assertReleaseJournalV3 = (
|
|
|
1196
1123
|
}
|
|
1197
1124
|
const names = new Set<string>();
|
|
1198
1125
|
const folders = new Set<string>();
|
|
1126
|
+
const npm = valueArg.npm;
|
|
1199
1127
|
const targets = valueArg.npm.registries;
|
|
1200
1128
|
let expectedRegistries: string[] | undefined;
|
|
1201
1129
|
let targetOffset = 0;
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
!/^ts(?:_[a-z0-9_]+)?$/.test(entry.folder) ||
|
|
1209
|
-
folders.has(entry.folder)
|
|
1210
|
-
) {
|
|
1130
|
+
const { packages, ...common } = valueArg;
|
|
1131
|
+
// Each package owns the next run of targets. Reuse the established identity,
|
|
1132
|
+
// destination, state and timestamp validators through a schema 1 projection
|
|
1133
|
+
// per package; the projection is validation-only and never rewrites data.
|
|
1134
|
+
const assertPackageTargets = (artifact: IReleaseArtifact): void => {
|
|
1135
|
+
if (names.has(artifact.packageName)) {
|
|
1211
1136
|
throw new Error(
|
|
1212
|
-
"Release package
|
|
1213
|
-
);
|
|
1214
|
-
}
|
|
1215
|
-
folders.add(entry.folder);
|
|
1216
|
-
const artifact = assertArtifact({
|
|
1217
|
-
...entry.artifact,
|
|
1218
|
-
file: releaseArtifactFileName,
|
|
1219
|
-
})!;
|
|
1220
|
-
if (
|
|
1221
|
-
names.has(artifact.packageName) ||
|
|
1222
|
-
entry.artifact.file !== releasePackageArtifactFile(artifact.packageName)
|
|
1223
|
-
) {
|
|
1224
|
-
throw new Error(
|
|
1225
|
-
"Release packages require unique names and canonical artifact filenames.",
|
|
1137
|
+
"Release package names must be unique across modules and the root package.",
|
|
1226
1138
|
);
|
|
1227
1139
|
}
|
|
1228
1140
|
names.add(artifact.packageName);
|
|
@@ -1252,23 +1164,48 @@ const assertReleaseJournalV3 = (
|
|
|
1252
1164
|
);
|
|
1253
1165
|
}
|
|
1254
1166
|
expectedRegistries = registryUrls;
|
|
1255
|
-
// Reuse the established identity, destination, state and timestamp validators.
|
|
1256
|
-
// Each projection is validation-only; schema 1/2 data is never rewritten.
|
|
1257
|
-
const { packages, ...common } = valueArg;
|
|
1258
1167
|
const complete = [
|
|
1259
1168
|
valueArg.git as IReleaseTargetStatus,
|
|
1260
1169
|
...registries,
|
|
1261
|
-
].every(
|
|
1262
|
-
(target) => target?.state === "verified" || target?.state === "skipped",
|
|
1263
|
-
);
|
|
1170
|
+
].every((target) => isTerminalTargetState(target?.state));
|
|
1264
1171
|
assertReleaseJournalV1({
|
|
1265
1172
|
...common,
|
|
1266
1173
|
schemaVersion: 1,
|
|
1267
1174
|
artifact,
|
|
1268
|
-
npm: { ...
|
|
1175
|
+
npm: { ...npm, registries },
|
|
1269
1176
|
completedAt: complete ? valueArg.updatedAt : null,
|
|
1270
1177
|
});
|
|
1178
|
+
};
|
|
1179
|
+
for (const entry of valueArg.packages) {
|
|
1180
|
+
if (!isPlainObject(entry) || !isPlainObject(entry.artifact))
|
|
1181
|
+
throw new Error("Invalid release package.");
|
|
1182
|
+
assertExactKeys(entry, ["folder", "artifact"], "Release package");
|
|
1183
|
+
if (
|
|
1184
|
+
typeof entry.folder !== "string" ||
|
|
1185
|
+
!/^ts(?:_[a-z0-9_]+)?$/.test(entry.folder) ||
|
|
1186
|
+
folders.has(entry.folder)
|
|
1187
|
+
) {
|
|
1188
|
+
throw new Error(
|
|
1189
|
+
"Release package folders must be unique canonical source folders.",
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
folders.add(entry.folder);
|
|
1193
|
+
const artifact = assertArtifact({
|
|
1194
|
+
...entry.artifact,
|
|
1195
|
+
file: releaseArtifactFileName,
|
|
1196
|
+
})!;
|
|
1197
|
+
if (
|
|
1198
|
+
entry.artifact.file !== releasePackageArtifactFile(artifact.packageName)
|
|
1199
|
+
) {
|
|
1200
|
+
throw new Error(
|
|
1201
|
+
"Release package artifacts must use the canonical filename derived from their package name.",
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
assertPackageTargets(artifact);
|
|
1271
1205
|
}
|
|
1206
|
+
// The root package publishes after its modules and keeps the root filename.
|
|
1207
|
+
const rootArtifact = assertArtifact(valueArg.artifact);
|
|
1208
|
+
if (rootArtifact) assertPackageTargets(rootArtifact);
|
|
1272
1209
|
if (targetOffset !== targets.length)
|
|
1273
1210
|
throw new Error("Unexpected or out-of-order release package target.");
|
|
1274
1211
|
const statuses = [
|
|
@@ -1382,7 +1319,7 @@ const assertReleaseJournalV4 = (
|
|
|
1382
1319
|
(valueArg.release as IReleaseJournalV1["release"])?.tag,
|
|
1383
1320
|
);
|
|
1384
1321
|
const commonComplete = [valueArg.git, ...valueArg.npm.registries].every(
|
|
1385
|
-
(entry) => entry?.state
|
|
1322
|
+
(entry) => isTerminalTargetState(entry?.state),
|
|
1386
1323
|
);
|
|
1387
1324
|
const common = {
|
|
1388
1325
|
kind: valueArg.kind,
|
|
@@ -453,6 +453,75 @@ export const assertNoLegacyNpmPublisher = async (
|
|
|
453
453
|
}
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
+
const scriptTokenStart = String.raw`(?:^|[\s;&|()'"])`;
|
|
457
|
+
const scriptTokenEnd = String.raw`(?=$|[\s;&|()'"])`;
|
|
458
|
+
const scriptToken = String.raw`[^\s;&|()'"]`;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Every way a script starts the standalone publisher: the bare or quoted
|
|
462
|
+
* binary, a filesystem path to it (a scoped package name is not a path), its
|
|
463
|
+
* CLI entry run through node, or the package run through a one-off runner.
|
|
464
|
+
* `tspublish plan` and `tspublish prepare` publish nothing.
|
|
465
|
+
*/
|
|
466
|
+
const standaloneTspublishPublisher = new RegExp(
|
|
467
|
+
scriptTokenStart +
|
|
468
|
+
"(?:" +
|
|
469
|
+
[
|
|
470
|
+
String.raw`(?:[^\s;&|()'"@]*\/)?tspublish`,
|
|
471
|
+
String.raw`(?:${scriptToken}*\/)?tspublish\/cli\.js`,
|
|
472
|
+
String.raw`(?:npx|pnpx|bunx|(?:pnpm|yarn)\s+dlx)(?:\s+-${scriptToken}*)*\s+@git\.zone\/tspublish(?:@${scriptToken}+)?`,
|
|
473
|
+
].join("|") +
|
|
474
|
+
")" +
|
|
475
|
+
scriptTokenEnd +
|
|
476
|
+
String.raw`(?!\s+(?:plan|prepare)\b)`,
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* The standalone tspublish publisher builds and uploads every named module
|
|
481
|
+
* outside any release journal. Next to a release that publishes the same
|
|
482
|
+
* modules it would upload different bytes for the same version, which the
|
|
483
|
+
* journal can only record as a conflict.
|
|
484
|
+
*/
|
|
485
|
+
export const assertNoStandaloneTspublishPublisher = async (
|
|
486
|
+
cwdArg: string,
|
|
487
|
+
): Promise<void> => {
|
|
488
|
+
let manifest: unknown;
|
|
489
|
+
try {
|
|
490
|
+
manifest = JSON.parse(
|
|
491
|
+
await plugins.fs.readFile(
|
|
492
|
+
plugins.path.join(cwdArg, "package.json"),
|
|
493
|
+
"utf8",
|
|
494
|
+
),
|
|
495
|
+
);
|
|
496
|
+
} catch (error) {
|
|
497
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
throw new Error(
|
|
501
|
+
"Unable to inspect package.json scripts for the standalone tspublish publisher.",
|
|
502
|
+
{ cause: error },
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
const scripts = (manifest as { scripts?: unknown } | null)?.scripts;
|
|
506
|
+
if (typeof scripts !== "object" || scripts === null) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
for (const [name, command] of Object.entries(
|
|
510
|
+
scripts as Record<string, unknown>,
|
|
511
|
+
)) {
|
|
512
|
+
if (
|
|
513
|
+
typeof command === "string" &&
|
|
514
|
+
standaloneTspublishPublisher.test(command)
|
|
515
|
+
) {
|
|
516
|
+
throw new Error(
|
|
517
|
+
`package.json script "${name}" runs the standalone tspublish publisher (${command}). ` +
|
|
518
|
+
"gitzone release publishes every named tspublish module inside its release journal. " +
|
|
519
|
+
`Remove the "${name}" script; \`tspublish plan\` and \`tspublish prepare\` remain available.`,
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
456
525
|
export const normalizeNpmRegistryUrl = (valueArg: string): string => {
|
|
457
526
|
if (typeof valueArg !== "string" || !valueArg.trim()) {
|
|
458
527
|
throw new Error("npm registry URLs must be non-empty strings.");
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as plugins from "./mod.plugins.js";
|
|
2
|
+
import { assertNpmPackageName } from "./helpers.npmartifact.js";
|
|
3
|
+
|
|
4
|
+
/** A module a tspublish descriptor names, which the npm target publishes. */
|
|
5
|
+
export interface IReleaseNpmModule {
|
|
6
|
+
name: string;
|
|
7
|
+
/** Source folders the module owns, its descriptor folder first. */
|
|
8
|
+
folders: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IReleaseNpmRoot {
|
|
12
|
+
name: string;
|
|
13
|
+
/** npm never publishes a private manifest, so neither does the release. */
|
|
14
|
+
private: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Everything the npm target publishes: the named tspublish modules in
|
|
19
|
+
* tspublish order, then the root package unless its manifest is private.
|
|
20
|
+
* Both are read from the project, so there is nothing to configure.
|
|
21
|
+
*/
|
|
22
|
+
export interface IReleaseNpmPackageSet {
|
|
23
|
+
root: IReleaseNpmRoot;
|
|
24
|
+
modules: IReleaseNpmModule[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IReleaseNpmPackagePlan {
|
|
28
|
+
packageSet: IReleaseNpmPackageSet;
|
|
29
|
+
/** The tspublish plan the module set was taken from. */
|
|
30
|
+
plan: plugins.tspublish.ITsPublishPlan;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Modules can only depend on sibling modules and on the root's dependencies,
|
|
35
|
+
* never on the root package, while the root may depend on its own modules.
|
|
36
|
+
* Publishing the modules first therefore never exposes an unresolvable version.
|
|
37
|
+
*/
|
|
38
|
+
export const getReleaseNpmPublicationOrder = (
|
|
39
|
+
packageSetArg: IReleaseNpmPackageSet,
|
|
40
|
+
): string[] => [
|
|
41
|
+
...packageSetArg.modules.map((moduleArg) => moduleArg.name),
|
|
42
|
+
...(packageSetArg.root.private ? [] : [packageSetArg.root.name]),
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** Plan output lines, in publication order. */
|
|
46
|
+
export const describeReleaseNpmPackages = (
|
|
47
|
+
packageSetArg: IReleaseNpmPackageSet,
|
|
48
|
+
): string[] => [
|
|
49
|
+
"npm packages (publication order):",
|
|
50
|
+
...packageSetArg.modules.map(
|
|
51
|
+
(moduleArg) => ` ${moduleArg.name} (${moduleArg.folders.join(", ")})`,
|
|
52
|
+
),
|
|
53
|
+
packageSetArg.root.private
|
|
54
|
+
? ` root ${packageSetArg.root.name}: private, not published`
|
|
55
|
+
: ` ${packageSetArg.root.name} (root)`,
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const readReleaseNpmRoot = async (cwdArg: string): Promise<IReleaseNpmRoot> => {
|
|
59
|
+
let manifest: unknown;
|
|
60
|
+
try {
|
|
61
|
+
manifest = JSON.parse(
|
|
62
|
+
await plugins.fs.readFile(
|
|
63
|
+
plugins.path.join(cwdArg, "package.json"),
|
|
64
|
+
"utf8",
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"The npm release target requires a readable package.json.",
|
|
70
|
+
{
|
|
71
|
+
cause: error,
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
typeof manifest !== "object" ||
|
|
77
|
+
manifest === null ||
|
|
78
|
+
Array.isArray(manifest)
|
|
79
|
+
) {
|
|
80
|
+
throw new Error("package.json must contain a JSON object.");
|
|
81
|
+
}
|
|
82
|
+
const { name, private: isPrivate } = manifest as {
|
|
83
|
+
name?: unknown;
|
|
84
|
+
private?: unknown;
|
|
85
|
+
};
|
|
86
|
+
if (typeof name !== "string") {
|
|
87
|
+
throw new Error('The npm release target requires a package.json "name".');
|
|
88
|
+
}
|
|
89
|
+
assertNpmPackageName(name);
|
|
90
|
+
if (isPrivate !== undefined && typeof isPrivate !== "boolean") {
|
|
91
|
+
throw new Error(
|
|
92
|
+
'package.json "private" must be true or false: it decides whether the npm target publishes the root package.',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return { name, private: isPrivate === true };
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Reads what the npm target publishes and rejects every ambiguous project
|
|
100
|
+
* before a release creates anything.
|
|
101
|
+
*/
|
|
102
|
+
export const planReleaseNpmPackages = async (
|
|
103
|
+
cwdArg: string,
|
|
104
|
+
): Promise<IReleaseNpmPackagePlan> => {
|
|
105
|
+
const root = await readReleaseNpmRoot(cwdArg);
|
|
106
|
+
const plan = await new plugins.tspublish.TsPublish().plan(cwdArg);
|
|
107
|
+
for (const moduleArg of plan.modules) {
|
|
108
|
+
const descriptor = `${moduleArg.folder}/tspublish.json`;
|
|
109
|
+
if (
|
|
110
|
+
moduleArg.registries.length !== 1 ||
|
|
111
|
+
moduleArg.registries[0] !== "useBase"
|
|
112
|
+
) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`${descriptor} names ${moduleArg.name} with registries ${JSON.stringify(moduleArg.registries)}. ` +
|
|
115
|
+
`gitzone publishes every named module to release.targets.npm: declare "registries": ["useBase"], ` +
|
|
116
|
+
`or remove "name" to keep ${moduleArg.folder} a build-order-only folder.`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (!root.private && moduleArg.name === root.name) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`${descriptor} names ${moduleArg.name}, which is also the root package. ` +
|
|
122
|
+
`Set "private": true in package.json to publish ${moduleArg.name} from ${moduleArg.folder} only, ` +
|
|
123
|
+
`or remove "name" from the descriptor.`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (root.private && plan.modules.length === 0) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
"The npm release target has nothing to publish: package.json is private and no ts*/tspublish.json names a package. " +
|
|
130
|
+
'Name a module, remove "private" to publish the root package, or disable release.targets.npm.',
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
packageSet: {
|
|
135
|
+
root,
|
|
136
|
+
modules: plan.modules.map(({ name, folders }) => ({ name, folders })),
|
|
137
|
+
},
|
|
138
|
+
plan,
|
|
139
|
+
};
|
|
140
|
+
};
|