@git.zone/cli 8.5.1 → 8.7.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/asset_tspack_release_gitea/.gitea/workflows/release.yml +12 -18
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.d.mts +22 -0
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs +48 -0
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-release-api.mjs +244 -74
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-sealed-release.mjs +103 -38
- package/assets/templates/vscode/.vscode/settings.json +57 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.gitzoneconfig.d.ts +3 -0
- package/dist_ts/classes.gitzoneconfig.js +1 -1
- package/dist_ts/helpers.objects.d.ts +2 -0
- package/dist_ts/helpers.objects.js +3 -0
- package/dist_ts/helpers.packagefiles.d.ts +74 -0
- package/dist_ts/helpers.packagefiles.js +177 -0
- package/dist_ts/helpers.workflow.d.ts +18 -0
- package/dist_ts/helpers.workflow.js +45 -2
- package/dist_ts/mod_config/index.js +69 -2
- package/dist_ts/mod_format/formatters/assets.formatter.js +2 -1
- package/dist_ts/mod_format/formatters/packagejson.formatter.js +8 -27
- package/dist_ts/mod_release/helpers.giteaassets.d.ts +4 -14
- package/dist_ts/mod_release/helpers.giteaassets.js +20 -35
- package/dist_ts/mod_release/helpers.npmartifactcheck.d.ts +93 -0
- package/dist_ts/mod_release/helpers.npmartifactcheck.js +279 -0
- package/dist_ts/mod_release/index.d.ts +15 -0
- package/dist_ts/mod_release/index.js +82 -17
- package/dist_ts/plugins.d.ts +2 -1
- package/dist_ts/plugins.js +3 -2
- package/package.json +2 -1
- package/readme.md +147 -33
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.gitzoneconfig.ts +3 -0
- package/ts/helpers.objects.ts +5 -0
- package/ts/helpers.packagefiles.ts +273 -0
- package/ts/helpers.workflow.ts +70 -1
- package/ts/mod_config/index.ts +78 -0
- package/ts/mod_format/formatters/assets.formatter.ts +1 -0
- package/ts/mod_format/formatters/packagejson.formatter.ts +7 -27
- package/ts/mod_release/helpers.giteaassets.ts +28 -44
- package/ts/mod_release/helpers.npmartifactcheck.ts +397 -0
- package/ts/mod_release/index.ts +115 -26
- package/ts/plugins.ts +2 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import * as plugins from "./mod.plugins.js";
|
|
2
|
+
import type {
|
|
3
|
+
IReleaseArtifact,
|
|
4
|
+
TReleaseNpmAccess,
|
|
5
|
+
} from "./classes.releasejournal.js";
|
|
6
|
+
import { normalizeNpmRegistryUrl } from "./helpers.npmartifact.js";
|
|
7
|
+
import type { IResolvedReleaseWorkflow } from "../helpers.workflow.js";
|
|
8
|
+
import { isPlainObject } from "../helpers.objects.js";
|
|
9
|
+
|
|
10
|
+
/** The packed-artifact check that refused a release. */
|
|
11
|
+
export type TNpmArtifactCheck = "contents" | "entryPoints" | "publishSize";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A packed tarball failed `core.packNpmArtifact.entryPoints` or
|
|
15
|
+
* `core.packNpmArtifact.publishSize`. The release commit itself causes the
|
|
16
|
+
* failure, so preparing the same commit again fails the same way.
|
|
17
|
+
*/
|
|
18
|
+
export class NpmArtifactCheckError extends Error {
|
|
19
|
+
public readonly check: TNpmArtifactCheck;
|
|
20
|
+
|
|
21
|
+
constructor(checkArg: TNpmArtifactCheck, messageArg: string) {
|
|
22
|
+
super(messageArg);
|
|
23
|
+
this.name = "NpmArtifactCheckError";
|
|
24
|
+
this.check = checkArg;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The artifact check error in an error's cause chain, if there is one. */
|
|
29
|
+
export const findNpmArtifactCheckError = (
|
|
30
|
+
errorArg: unknown,
|
|
31
|
+
): NpmArtifactCheckError | undefined => {
|
|
32
|
+
let current: unknown = errorArg;
|
|
33
|
+
for (let depth = 0; depth < 16 && current instanceof Error; depth++) {
|
|
34
|
+
if (current instanceof NpmArtifactCheckError) return current;
|
|
35
|
+
current = current.cause;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** What a packed npm tarball holds, read from the tarball itself. */
|
|
41
|
+
export interface INpmArtifactContents {
|
|
42
|
+
/** Every regular file, relative to the package root. */
|
|
43
|
+
files: string[];
|
|
44
|
+
/** The packed package.json, as pnpm wrote it into the tarball. */
|
|
45
|
+
manifest: Record<string, unknown>;
|
|
46
|
+
/** The root readme.md the publish document carries, when there is one. */
|
|
47
|
+
readme?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const packagePrefix = "package/";
|
|
51
|
+
|
|
52
|
+
/** How much of a packed tarball the checks read before they refuse it. */
|
|
53
|
+
export interface INpmArtifactReadLimits {
|
|
54
|
+
maxUncompressedArchiveBytes: number;
|
|
55
|
+
maxEntries: number;
|
|
56
|
+
/** For the selected package.json and readme, each. */
|
|
57
|
+
maxUncompressedEntryBytes: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const defaultNpmArtifactReadLimits: INpmArtifactReadLimits = {
|
|
61
|
+
maxUncompressedArchiveBytes: 2 * 1024 ** 3,
|
|
62
|
+
maxEntries: 1_000_000,
|
|
63
|
+
maxUncompressedEntryBytes: 64 * 1024 ** 2,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** The limits a tarball itself can exceed; they refuse it like a failed check. */
|
|
67
|
+
const artifactLimitCodes = new Set<string>([
|
|
68
|
+
plugins.smartarchive.GZIP_ERROR_CODES.UNCOMPRESSED_SIZE_LIMIT,
|
|
69
|
+
plugins.smartarchive.TAR_ERROR_CODES.ENTRY_COUNT_LIMIT,
|
|
70
|
+
plugins.smartarchive.TAR_ERROR_CODES.UNCOMPRESSED_SIZE_LIMIT,
|
|
71
|
+
plugins.smartarchive.TAR_ERROR_CODES.TOTAL_UNCOMPRESSED_SIZE_LIMIT,
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Reads the packed file list, manifest and readme from the tarball. pnpm 12
|
|
76
|
+
* puts a root `readme.md` (any case) into the publish document and prefers
|
|
77
|
+
* `README.md` when there are several. A tarball beyond the read limits comes
|
|
78
|
+
* from the release commit, so it fails as an `NpmArtifactCheckError`.
|
|
79
|
+
*/
|
|
80
|
+
export const readNpmArtifactContents = async (
|
|
81
|
+
artifactPathArg: string,
|
|
82
|
+
limitsArg: INpmArtifactReadLimits = defaultNpmArtifactReadLimits,
|
|
83
|
+
): Promise<INpmArtifactContents> => {
|
|
84
|
+
const bytes = await plugins.fs.readFile(artifactPathArg);
|
|
85
|
+
const files: string[] = [];
|
|
86
|
+
let entries: Awaited<
|
|
87
|
+
ReturnType<plugins.smartarchive.TarTools["extractSelectedTarGzEntries"]>
|
|
88
|
+
>;
|
|
89
|
+
try {
|
|
90
|
+
entries = await new plugins.smartarchive.TarTools().extractSelectedTarGzEntries(
|
|
91
|
+
bytes,
|
|
92
|
+
{
|
|
93
|
+
filter: (entryArg) => {
|
|
94
|
+
if (entryArg.entryType !== "file" || !entryArg.path.startsWith(packagePrefix))
|
|
95
|
+
return false;
|
|
96
|
+
const path = entryArg.path.slice(packagePrefix.length);
|
|
97
|
+
files.push(path);
|
|
98
|
+
return path === "package.json" || path.toLowerCase() === "readme.md";
|
|
99
|
+
},
|
|
100
|
+
maxArchiveBytes: bytes.byteLength,
|
|
101
|
+
maxUncompressedArchiveBytes: limitsArg.maxUncompressedArchiveBytes,
|
|
102
|
+
maxEntries: limitsArg.maxEntries,
|
|
103
|
+
maxSelectedEntries: 64,
|
|
104
|
+
maxUncompressedEntryBytes: limitsArg.maxUncompressedEntryBytes,
|
|
105
|
+
maxTotalUncompressedBytes: 4 * limitsArg.maxUncompressedEntryBytes,
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (
|
|
110
|
+
error instanceof plugins.smartarchive.SmartArchiveError &&
|
|
111
|
+
artifactLimitCodes.has(error.code)
|
|
112
|
+
) {
|
|
113
|
+
throw new NpmArtifactCheckError(
|
|
114
|
+
"contents",
|
|
115
|
+
`The packed tarball ${plugins.path.basename(artifactPathArg)} exceeds what the release reads to check it (${error.code}: ${error.message}; at most ${limitsArg.maxUncompressedArchiveBytes} bytes unpacked, ${limitsArg.maxEntries} entries). Leave files out through @git.zone/cli.packageFiles, then \`gitzone format\`.`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
const decoder = new TextDecoder();
|
|
121
|
+
const manifestEntry = entries.find(
|
|
122
|
+
(entryArg) => entryArg.path === `${packagePrefix}package.json`,
|
|
123
|
+
);
|
|
124
|
+
if (!manifestEntry)
|
|
125
|
+
throw new Error("The packed npm artifact carries no package/package.json.");
|
|
126
|
+
const manifest: unknown = JSON.parse(decoder.decode(manifestEntry.content));
|
|
127
|
+
if (!isPlainObject(manifest))
|
|
128
|
+
throw new Error("The packed package.json is not a JSON object.");
|
|
129
|
+
const readmes = entries.filter(
|
|
130
|
+
(entryArg) => entryArg.path !== `${packagePrefix}package.json`,
|
|
131
|
+
);
|
|
132
|
+
const readme =
|
|
133
|
+
readmes.find((entryArg) => entryArg.path === `${packagePrefix}README.md`) ??
|
|
134
|
+
readmes[0];
|
|
135
|
+
return {
|
|
136
|
+
files,
|
|
137
|
+
manifest,
|
|
138
|
+
...(readme ? { readme: decoder.decode(readme.content) } : {}),
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const normalizeTarget = (targetArg: string): string =>
|
|
143
|
+
targetArg.replace(/^(\.\/)+/, "");
|
|
144
|
+
|
|
145
|
+
/** Node's resolution of a `main` without its extension or as a folder. */
|
|
146
|
+
const mainCandidates = (mainArg: string): string[] => {
|
|
147
|
+
const main = normalizeTarget(mainArg).replace(/\/+$/, "");
|
|
148
|
+
return [
|
|
149
|
+
main,
|
|
150
|
+
`${main}.js`,
|
|
151
|
+
`${main}.json`,
|
|
152
|
+
`${main}.node`,
|
|
153
|
+
`${main}/index.js`,
|
|
154
|
+
`${main}/index.json`,
|
|
155
|
+
`${main}/index.node`,
|
|
156
|
+
];
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
interface IEntryPoint {
|
|
160
|
+
/** Where the manifest names it, e.g. `exports["./x"].import`. */
|
|
161
|
+
field: string;
|
|
162
|
+
target: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const collectExportTargets = (
|
|
166
|
+
valueArg: unknown,
|
|
167
|
+
fieldArg: string,
|
|
168
|
+
targetsArg: IEntryPoint[],
|
|
169
|
+
): void => {
|
|
170
|
+
if (typeof valueArg === "string") {
|
|
171
|
+
targetsArg.push({ field: fieldArg, target: valueArg });
|
|
172
|
+
} else if (Array.isArray(valueArg)) {
|
|
173
|
+
valueArg.forEach((itemArg, indexArg) =>
|
|
174
|
+
collectExportTargets(itemArg, `${fieldArg}[${indexArg}]`, targetsArg),
|
|
175
|
+
);
|
|
176
|
+
} else if (isPlainObject(valueArg)) {
|
|
177
|
+
for (const [keyArg, itemArg] of Object.entries(valueArg))
|
|
178
|
+
collectExportTargets(itemArg, `${fieldArg}[${JSON.stringify(keyArg)}]`, targetsArg);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const escapeRegExp = (valueArg: string): string =>
|
|
183
|
+
valueArg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Every `main`, `module`, `types`/`typings`, `bin` and `exports` target the
|
|
187
|
+
* packed manifest names, with the reason each missing one is missing. An
|
|
188
|
+
* `exports` target with `*` must match at least one packed file, and a
|
|
189
|
+
* folder target (trailing `/`) must contain one.
|
|
190
|
+
*/
|
|
191
|
+
export const findMissingNpmEntryPoints = (
|
|
192
|
+
contentsArg: Pick<INpmArtifactContents, "files" | "manifest">,
|
|
193
|
+
): string[] => {
|
|
194
|
+
const files = new Set(contentsArg.files);
|
|
195
|
+
const manifest = contentsArg.manifest;
|
|
196
|
+
const missing: string[] = [];
|
|
197
|
+
if (typeof manifest.main === "string") {
|
|
198
|
+
if (!mainCandidates(manifest.main).some((candidateArg) => files.has(candidateArg)))
|
|
199
|
+
missing.push(`main -> ${manifest.main}`);
|
|
200
|
+
}
|
|
201
|
+
const plain: IEntryPoint[] = [];
|
|
202
|
+
for (const field of ["module", "types", "typings"] as const) {
|
|
203
|
+
const value = manifest[field];
|
|
204
|
+
if (typeof value === "string") plain.push({ field, target: value });
|
|
205
|
+
}
|
|
206
|
+
if (typeof manifest.bin === "string") {
|
|
207
|
+
plain.push({ field: "bin", target: manifest.bin });
|
|
208
|
+
} else if (isPlainObject(manifest.bin)) {
|
|
209
|
+
for (const [name, target] of Object.entries(manifest.bin))
|
|
210
|
+
if (typeof target === "string")
|
|
211
|
+
plain.push({ field: `bin[${JSON.stringify(name)}]`, target });
|
|
212
|
+
}
|
|
213
|
+
for (const entry of plain)
|
|
214
|
+
if (!files.has(normalizeTarget(entry.target)))
|
|
215
|
+
missing.push(`${entry.field} -> ${entry.target}`);
|
|
216
|
+
const exportTargets: IEntryPoint[] = [];
|
|
217
|
+
collectExportTargets(manifest.exports, "exports", exportTargets);
|
|
218
|
+
for (const entry of exportTargets) {
|
|
219
|
+
// Only package-relative targets name files; anything else is not ours to check.
|
|
220
|
+
if (!entry.target.startsWith("./")) continue;
|
|
221
|
+
const target = normalizeTarget(entry.target);
|
|
222
|
+
let present: boolean;
|
|
223
|
+
if (target.includes("*")) {
|
|
224
|
+
const pattern = new RegExp(
|
|
225
|
+
`^${target.split("*").map(escapeRegExp).join(".+")}$`,
|
|
226
|
+
);
|
|
227
|
+
present = contentsArg.files.some((fileArg) => pattern.test(fileArg));
|
|
228
|
+
} else if (target.endsWith("/")) {
|
|
229
|
+
present = contentsArg.files.some((fileArg) => fileArg.startsWith(target));
|
|
230
|
+
} else {
|
|
231
|
+
present = files.has(target);
|
|
232
|
+
}
|
|
233
|
+
if (!present) missing.push(`${entry.field} -> ${entry.target}`);
|
|
234
|
+
}
|
|
235
|
+
return missing;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export const assertNpmEntryPointsPacked = (
|
|
239
|
+
contentsArg: Pick<INpmArtifactContents, "files" | "manifest">,
|
|
240
|
+
packageNameArg: string,
|
|
241
|
+
): void => {
|
|
242
|
+
const missing = findMissingNpmEntryPoints(contentsArg);
|
|
243
|
+
if (missing.length === 0) return;
|
|
244
|
+
throw new NpmArtifactCheckError(
|
|
245
|
+
"entryPoints",
|
|
246
|
+
`The packed ${packageNameArg} tarball lacks entry points its package.json names: ${missing.join("; ")}. ` +
|
|
247
|
+
"Ship them through package.json files (@git.zone/cli.packageFiles, then `gitzone format`) or fix the build.",
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export interface INpmPublishBodyOptions {
|
|
252
|
+
contents: Pick<INpmArtifactContents, "manifest" | "readme">;
|
|
253
|
+
artifact: Pick<IReleaseArtifact, "packageName" | "version" | "size" | "sha1" | "integrity">;
|
|
254
|
+
registry: string;
|
|
255
|
+
distTag: string;
|
|
256
|
+
access: TReleaseNpmAccess;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The byte length of the document `pnpm publish <tarball>` PUTs to a
|
|
261
|
+
* registry: the packed manifest with its readme and `dist` record, the
|
|
262
|
+
* dist-tag, the access level, and the tarball as base64. Measured against
|
|
263
|
+
* pnpm 12's actual upload; it is an estimate for other publishers.
|
|
264
|
+
*/
|
|
265
|
+
export const estimateNpmPublishBodyBytes = (
|
|
266
|
+
optionsArg: INpmPublishBodyOptions,
|
|
267
|
+
): number => {
|
|
268
|
+
const { artifact, contents } = optionsArg;
|
|
269
|
+
const name = artifact.packageName;
|
|
270
|
+
const registry = normalizeNpmRegistryUrl(optionsArg.registry);
|
|
271
|
+
const description = contents.manifest.description;
|
|
272
|
+
const placeholder = "\u0000";
|
|
273
|
+
const document = {
|
|
274
|
+
_id: name,
|
|
275
|
+
name,
|
|
276
|
+
...(description !== undefined ? { description } : {}),
|
|
277
|
+
"dist-tags": { [optionsArg.distTag]: artifact.version },
|
|
278
|
+
versions: {
|
|
279
|
+
[artifact.version]: {
|
|
280
|
+
...contents.manifest,
|
|
281
|
+
...(contents.readme !== undefined ? { readme: contents.readme } : {}),
|
|
282
|
+
_id: `${name}@${artifact.version}`,
|
|
283
|
+
dist: {
|
|
284
|
+
integrity: artifact.integrity,
|
|
285
|
+
shasum: artifact.sha1,
|
|
286
|
+
tarball: `${registry}/${name}/-/${name}-${artifact.version}.tgz`,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
access: optionsArg.access === "private" ? "restricted" : "public",
|
|
291
|
+
_attachments: {
|
|
292
|
+
[`${name}-${artifact.version}.tgz`]: {
|
|
293
|
+
content_type: "application/octet-stream",
|
|
294
|
+
data: placeholder,
|
|
295
|
+
length: artifact.size,
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
const metadataBytes =
|
|
300
|
+
Buffer.byteLength(JSON.stringify(document), "utf8") -
|
|
301
|
+
Buffer.byteLength(JSON.stringify(placeholder), "utf8") +
|
|
302
|
+
2;
|
|
303
|
+
return metadataBytes + 4 * Math.ceil(artifact.size / 3);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const formatBytes = (bytesArg: number): string =>
|
|
307
|
+
`${bytesArg.toLocaleString("en-US")} bytes (${(bytesArg / 1024 ** 2).toFixed(1)} MiB)`;
|
|
308
|
+
|
|
309
|
+
export interface INpmPublishSizeCheck {
|
|
310
|
+
registry: string;
|
|
311
|
+
bodyBytes: number;
|
|
312
|
+
limit?: number;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The packed size and the estimated publish body per registry, checked
|
|
317
|
+
* against the registry's configured `maxPublishBytes`. Prints both and fails
|
|
318
|
+
* when a body exceeds its registry's limit. Without limits it only reports.
|
|
319
|
+
*/
|
|
320
|
+
export const assertNpmPublishSize = (optionsArg: {
|
|
321
|
+
contents: Pick<INpmArtifactContents, "manifest" | "readme">;
|
|
322
|
+
artifact: Pick<IReleaseArtifact, "packageName" | "version" | "size" | "sha1" | "integrity">;
|
|
323
|
+
registries: string[];
|
|
324
|
+
distTag: string;
|
|
325
|
+
access: TReleaseNpmAccess;
|
|
326
|
+
maxPublishBytes: Record<string, number>;
|
|
327
|
+
log?: (lineArg: string) => void;
|
|
328
|
+
}): INpmPublishSizeCheck[] => {
|
|
329
|
+
const log = optionsArg.log ?? ((lineArg: string) => console.log(lineArg));
|
|
330
|
+
log(`${optionsArg.artifact.packageName}: packed ${formatBytes(optionsArg.artifact.size)}`);
|
|
331
|
+
// Registries and limit keys are both in the resolved release form.
|
|
332
|
+
const checks = optionsArg.registries.map((registry) => {
|
|
333
|
+
const limit = optionsArg.maxPublishBytes[registry];
|
|
334
|
+
return {
|
|
335
|
+
registry,
|
|
336
|
+
bodyBytes: estimateNpmPublishBodyBytes({
|
|
337
|
+
contents: optionsArg.contents,
|
|
338
|
+
artifact: optionsArg.artifact,
|
|
339
|
+
registry,
|
|
340
|
+
distTag: optionsArg.distTag,
|
|
341
|
+
access: optionsArg.access,
|
|
342
|
+
}),
|
|
343
|
+
...(limit !== undefined ? { limit } : {}),
|
|
344
|
+
};
|
|
345
|
+
});
|
|
346
|
+
for (const check of checks)
|
|
347
|
+
log(
|
|
348
|
+
` publish body to ${check.registry}: ${formatBytes(check.bodyBytes)}${check.limit !== undefined ? `, limit ${formatBytes(check.limit)}` : ", no limit configured"}`,
|
|
349
|
+
);
|
|
350
|
+
const exceeded = checks.filter(
|
|
351
|
+
(checkArg) => checkArg.limit !== undefined && checkArg.bodyBytes > checkArg.limit,
|
|
352
|
+
);
|
|
353
|
+
if (exceeded.length > 0)
|
|
354
|
+
throw new NpmArtifactCheckError(
|
|
355
|
+
"publishSize",
|
|
356
|
+
`The ${optionsArg.artifact.packageName} publish body exceeds release.targets.npm.maxPublishBytes: ${exceeded
|
|
357
|
+
.map((checkArg) => `${checkArg.registry} ${checkArg.bodyBytes} > ${checkArg.limit} bytes`)
|
|
358
|
+
.join("; ")}. Leave large files out through @git.zone/cli.packageFiles, then \`gitzone format\`.`,
|
|
359
|
+
);
|
|
360
|
+
return checks;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The checks between packing and the journal: every packed tarball must
|
|
365
|
+
* carry its entry points (`core.packNpmArtifact.entryPoints`), and its
|
|
366
|
+
* publish body must fit every registry limit (`core.packNpmArtifact.publishSize`).
|
|
367
|
+
* The size of each tarball and body is printed either way. A failure here
|
|
368
|
+
* leaves the release where a failed pack leaves it.
|
|
369
|
+
*/
|
|
370
|
+
export const verifyPackedNpmArtifacts = async (optionsArg: {
|
|
371
|
+
workflow: Pick<
|
|
372
|
+
IResolvedReleaseWorkflow,
|
|
373
|
+
"npmRegistries" | "npmDistTag" | "npmAccessLevel" | "npmMaxPublishBytes"
|
|
374
|
+
>;
|
|
375
|
+
artifactDirectory: string;
|
|
376
|
+
artifacts: IReleaseArtifact[];
|
|
377
|
+
log?: (lineArg: string) => void;
|
|
378
|
+
}): Promise<void> => {
|
|
379
|
+
const packed: Array<{ artifact: IReleaseArtifact; contents: INpmArtifactContents }> = [];
|
|
380
|
+
for (const artifact of optionsArg.artifacts) {
|
|
381
|
+
const contents = await readNpmArtifactContents(
|
|
382
|
+
plugins.path.join(optionsArg.artifactDirectory, artifact.file),
|
|
383
|
+
);
|
|
384
|
+
assertNpmEntryPointsPacked(contents, artifact.packageName);
|
|
385
|
+
packed.push({ artifact, contents });
|
|
386
|
+
}
|
|
387
|
+
for (const { artifact, contents } of packed)
|
|
388
|
+
assertNpmPublishSize({
|
|
389
|
+
contents,
|
|
390
|
+
artifact,
|
|
391
|
+
registries: optionsArg.workflow.npmRegistries,
|
|
392
|
+
distTag: optionsArg.workflow.npmDistTag,
|
|
393
|
+
access: optionsArg.workflow.npmAccessLevel,
|
|
394
|
+
maxPublishBytes: optionsArg.workflow.npmMaxPublishBytes,
|
|
395
|
+
...(optionsArg.log ? { log: optionsArg.log } : {}),
|
|
396
|
+
});
|
|
397
|
+
};
|
package/ts/mod_release/index.ts
CHANGED
|
@@ -84,6 +84,11 @@ import {
|
|
|
84
84
|
type IReleaseLine,
|
|
85
85
|
} from "./helpers.releaseline.js";
|
|
86
86
|
import { executeReleasePublication } from "./helpers.releasepublication.js";
|
|
87
|
+
import {
|
|
88
|
+
findNpmArtifactCheckError,
|
|
89
|
+
verifyPackedNpmArtifacts,
|
|
90
|
+
} from "./helpers.npmartifactcheck.js";
|
|
91
|
+
import { assertPackageJsonFilesCurrent } from "../helpers.packagefiles.js";
|
|
87
92
|
import { formatCommandFailure } from "./helpers.commandfailure.js";
|
|
88
93
|
import {
|
|
89
94
|
formatReleaseDuration,
|
|
@@ -249,6 +254,9 @@ const runInternal = async (argvArg: any): Promise<void> => {
|
|
|
249
254
|
return;
|
|
250
255
|
}
|
|
251
256
|
|
|
257
|
+
if (workflow.packageFilesConfigured) {
|
|
258
|
+
await assertPackageJsonFilesCurrent(branchContext.sourceCwd);
|
|
259
|
+
}
|
|
252
260
|
const preflightTsdocker = workflow.targets.includes("docker")
|
|
253
261
|
? new TsdockerReleaseClient(smartshellInstance, branchContext.sourceCwd)
|
|
254
262
|
: undefined;
|
|
@@ -427,7 +435,14 @@ const runInternal = async (argvArg: any): Promise<void> => {
|
|
|
427
435
|
});
|
|
428
436
|
} catch (error) {
|
|
429
437
|
throw new Error(
|
|
430
|
-
|
|
438
|
+
describeTaggedReleaseFailure(error, {
|
|
439
|
+
version: newVersion,
|
|
440
|
+
releaseBranch: branchContext.releaseBranch,
|
|
441
|
+
releaseCwd,
|
|
442
|
+
intentPath: new ReleaseJournalStore(
|
|
443
|
+
await resolveGitCommonDirectory(smartshellInstance, releaseCwd),
|
|
444
|
+
).getIntentPath(newVersion),
|
|
445
|
+
}),
|
|
431
446
|
{ cause: error },
|
|
432
447
|
);
|
|
433
448
|
}
|
|
@@ -454,6 +469,45 @@ const runInternal = async (argvArg: any): Promise<void> => {
|
|
|
454
469
|
printReleaseJournalSummary(finalJournal);
|
|
455
470
|
};
|
|
456
471
|
|
|
472
|
+
/**
|
|
473
|
+
* What an operator does after the release failed between its tag and its
|
|
474
|
+
* journal. Most such failures are environmental, and resuming the recorded
|
|
475
|
+
* release prepares it again. A failed packed-artifact check comes from the
|
|
476
|
+
* release commit itself and would fail again, so its way out is to abandon the
|
|
477
|
+
* local release, fix the package and release again; gitzone has no command
|
|
478
|
+
* for that, so the steps are spelled out.
|
|
479
|
+
*/
|
|
480
|
+
export const describeTaggedReleaseFailure = (
|
|
481
|
+
errorArg: unknown,
|
|
482
|
+
optionsArg: {
|
|
483
|
+
version: string;
|
|
484
|
+
releaseBranch: string;
|
|
485
|
+
/** The checkout that holds the release commit and tag. */
|
|
486
|
+
releaseCwd: string;
|
|
487
|
+
intentPath: string;
|
|
488
|
+
},
|
|
489
|
+
): string => {
|
|
490
|
+
const message = errorArg instanceof Error ? errorArg.message : String(errorArg);
|
|
491
|
+
const { version, releaseBranch, releaseCwd, intentPath } = optionsArg;
|
|
492
|
+
const artifactCheck = findNpmArtifactCheckError(errorArg);
|
|
493
|
+
if (!artifactCheck) {
|
|
494
|
+
return `${message} The release commit and tag v${version} are recorded locally; \`gitzone release resume ${version} -y\` prepares and publishes them.`;
|
|
495
|
+
}
|
|
496
|
+
const what = {
|
|
497
|
+
contents: "a packed tarball is larger than the release reads to check it",
|
|
498
|
+
entryPoints: "a packed tarball lacks entry points its package.json names",
|
|
499
|
+
publishSize: "a publish body exceeds its registry's maxPublishBytes limit",
|
|
500
|
+
}[artifactCheck.check];
|
|
501
|
+
const git = `git -C ${shellQuote(releaseCwd)}`;
|
|
502
|
+
return (
|
|
503
|
+
`${artifactCheck.message} The release v${version} stopped because ${what}. This comes from the release commit itself, ` +
|
|
504
|
+
`so preparing that commit again fails the same way; nothing was pushed. Abandon the local release: ` +
|
|
505
|
+
`confirm \`${git} log -1 --format=%s\` prints v${version} and \`${git} branch --show-current\` prints ${releaseBranch}, ` +
|
|
506
|
+
`then run \`${git} tag -d v${version}\` and \`${git} reset --hard HEAD^\`, and delete ${shellQuote(intentPath)}. ` +
|
|
507
|
+
`Fix the package, commit, and release again.`
|
|
508
|
+
);
|
|
509
|
+
};
|
|
510
|
+
|
|
457
511
|
/**
|
|
458
512
|
* Test logs are release diagnostics, so only a journal that reached completion
|
|
459
513
|
* may drop them. A failure keeps them for the investigation, and a journal left
|
|
@@ -857,32 +911,49 @@ const prepareRecordedRelease = async (
|
|
|
857
911
|
printReleasePhase(
|
|
858
912
|
`Preparing the journal of recorded release v${version} from ${refs.mainOid}`,
|
|
859
913
|
);
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
914
|
+
try {
|
|
915
|
+
await prepareTaggedRelease({
|
|
916
|
+
pnpmCapability,
|
|
917
|
+
smartshell: smartshellArg,
|
|
918
|
+
workflow,
|
|
919
|
+
releaseCwd: paths.cwd,
|
|
920
|
+
releasePushUrl: branch.pushUrl,
|
|
921
|
+
expectedRemoteMainOid,
|
|
922
|
+
version,
|
|
923
|
+
versionFloor: intentArg.release.versionFloor,
|
|
924
|
+
refs,
|
|
925
|
+
ensurePublicationState: async () => {
|
|
926
|
+
await verifyReleaseRefs(
|
|
927
|
+
smartshellArg,
|
|
928
|
+
paths.cwd,
|
|
929
|
+
branch.releaseBranch,
|
|
930
|
+
version,
|
|
931
|
+
refs,
|
|
932
|
+
);
|
|
933
|
+
await revalidateReleasePublicationState(
|
|
934
|
+
smartshellArg,
|
|
935
|
+
branch,
|
|
936
|
+
refs.mainOid,
|
|
937
|
+
expectedRemoteMainOid,
|
|
938
|
+
);
|
|
939
|
+
},
|
|
940
|
+
});
|
|
941
|
+
} catch (error) {
|
|
942
|
+
// An environmental failure keeps its own message: a later resume can
|
|
943
|
+
// still succeed. A failed artifact check cannot.
|
|
944
|
+
if (!findNpmArtifactCheckError(error)) throw error;
|
|
945
|
+
throw new Error(
|
|
946
|
+
describeTaggedReleaseFailure(error, {
|
|
875
947
|
version,
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
});
|
|
948
|
+
releaseBranch: branch.releaseBranch,
|
|
949
|
+
releaseCwd: paths.cwd,
|
|
950
|
+
intentPath: new ReleaseJournalStore(
|
|
951
|
+
await resolveGitCommonDirectory(smartshellArg, paths.cwd),
|
|
952
|
+
).getIntentPath(version),
|
|
953
|
+
}),
|
|
954
|
+
{ cause: error },
|
|
955
|
+
);
|
|
956
|
+
}
|
|
886
957
|
};
|
|
887
958
|
|
|
888
959
|
/**
|
|
@@ -1005,6 +1076,15 @@ export const createReleaseJournal = async (
|
|
|
1005
1076
|
optionsArg.pnpmCapability,
|
|
1006
1077
|
);
|
|
1007
1078
|
}
|
|
1079
|
+
printReleasePhase("Checking the packed npm artifacts");
|
|
1080
|
+
await verifyPackedNpmArtifacts({
|
|
1081
|
+
workflow: optionsArg.workflow,
|
|
1082
|
+
artifactDirectory: temporaryDirectory,
|
|
1083
|
+
artifacts: [
|
|
1084
|
+
...packages.map((entryArg) => entryArg.artifact),
|
|
1085
|
+
...(artifact ? [artifact] : []),
|
|
1086
|
+
],
|
|
1087
|
+
});
|
|
1008
1088
|
await verifyCleanTree(
|
|
1009
1089
|
optionsArg.smartshell,
|
|
1010
1090
|
npmSourceCwd,
|
|
@@ -2329,6 +2409,11 @@ async function printReleasePlan(
|
|
|
2329
2409
|
console.log(
|
|
2330
2410
|
`changelog: ${workflow.changelogFile}#${workflow.changelogPendingSection}`,
|
|
2331
2411
|
);
|
|
2412
|
+
if (workflow.packageFilesConfigured) {
|
|
2413
|
+
console.log(
|
|
2414
|
+
"package files: package.json files must equal what @git.zone/cli.packageFiles generates",
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2332
2417
|
for (const line of describeReleaseVersion(versionResolutionArg)) {
|
|
2333
2418
|
console.log(line);
|
|
2334
2419
|
}
|
|
@@ -2337,6 +2422,10 @@ async function printReleasePlan(
|
|
|
2337
2422
|
`npm registries: ${workflow.npmRegistries.length > 0 ? workflow.npmRegistries.join(", ") : "none"}`,
|
|
2338
2423
|
);
|
|
2339
2424
|
console.log(`npm dist-tag: ${workflow.npmDistTag}`);
|
|
2425
|
+
const limits = Object.entries(workflow.npmMaxPublishBytes);
|
|
2426
|
+
console.log(
|
|
2427
|
+
`npm publish body limits: ${limits.length > 0 ? limits.map(([registry, limit]) => `${registry} ${limit} bytes`).join(", ") : "none configured"}`,
|
|
2428
|
+
);
|
|
2340
2429
|
for (const line of await describeReleaseLineDistTags(
|
|
2341
2430
|
workflow,
|
|
2342
2431
|
versionResolutionArg.version,
|
package/ts/plugins.ts
CHANGED
|
@@ -17,6 +17,7 @@ import * as smartupdate from '@push.rocks/smartupdate';
|
|
|
17
17
|
import * as smartshell from '@push.rocks/smartshell';
|
|
18
18
|
import * as smartnetwork from '@push.rocks/smartnetwork';
|
|
19
19
|
import * as smartfile from '@push.rocks/smartfile';
|
|
20
|
+
import * as smartarchive from '@push.rocks/smartarchive';
|
|
20
21
|
import { SmartFs, SmartFsProviderNode } from '@push.rocks/smartfs';
|
|
21
22
|
|
|
22
23
|
// @lossless.org scope
|
|
@@ -67,6 +68,7 @@ export {
|
|
|
67
68
|
smartshell,
|
|
68
69
|
smartnetwork,
|
|
69
70
|
smartfile,
|
|
71
|
+
smartarchive,
|
|
70
72
|
objectstorage,
|
|
71
73
|
s3,
|
|
72
74
|
tsdockerReleaseProtocol,
|