@cmflow/source-pack 0.0.0-stage → 3.20.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 (37) hide show
  1. package/README.md +183 -2
  2. package/dist/GitRepository-VTAWT6j4.mjs +151 -0
  3. package/dist/GitRepository-VTAWT6j4.mjs.map +1 -0
  4. package/dist/bin/source-pack.d.mts +1 -0
  5. package/dist/bin/source-pack.mjs +3038 -0
  6. package/dist/bin/source-pack.mjs.map +1 -0
  7. package/dist/buildSourcePack-CaaMZ_tw.mjs +11280 -0
  8. package/dist/buildSourcePack-CaaMZ_tw.mjs.map +1 -0
  9. package/dist/buildSourcePack-DIp8G_uL.mjs +3 -0
  10. package/dist/constants-DkiLCuIK.mjs +25 -0
  11. package/dist/constants-DkiLCuIK.mjs.map +1 -0
  12. package/dist/defaults-BJs7a37e.mjs +52 -0
  13. package/dist/defaults-BJs7a37e.mjs.map +1 -0
  14. package/dist/index.d.mts +397 -0
  15. package/dist/index.mjs +73 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/dist/initConfig-ByGsbShR.mjs +185 -0
  18. package/dist/initConfig-ByGsbShR.mjs.map +1 -0
  19. package/dist/loadConfig-CNrL90dq.mjs +224 -0
  20. package/dist/loadConfig-CNrL90dq.mjs.map +1 -0
  21. package/dist/logger-D1XGzzjT.mjs +15 -0
  22. package/dist/logger-D1XGzzjT.mjs.map +1 -0
  23. package/dist/packageVersion-B0749hF6.mjs +4646 -0
  24. package/dist/packageVersion-B0749hF6.mjs.map +1 -0
  25. package/dist/projectIdentity-F97vs1H-.mjs +3331 -0
  26. package/dist/projectIdentity-F97vs1H-.mjs.map +1 -0
  27. package/dist/publishSourcePack-Dj1cdWfT.mjs +3 -0
  28. package/dist/publishSourcePack-xNr9RBgv.mjs +296 -0
  29. package/dist/publishSourcePack-xNr9RBgv.mjs.map +1 -0
  30. package/dist/token-DMtao22Y.mjs +59 -0
  31. package/dist/token-DMtao22Y.mjs.map +1 -0
  32. package/dist/token-util-C3JYrW4-.mjs +498 -0
  33. package/dist/token-util-C3JYrW4-.mjs.map +1 -0
  34. package/dist/token-util-CbjlbIno.mjs +5 -0
  35. package/package.json +45 -3
  36. package/templates/circleci-job.yml +39 -0
  37. package/templates/gitlab-ci.yml +30 -0
@@ -0,0 +1,296 @@
1
+ import { g as MANIFEST_FILE, h as GITLAB_TOKEN_ENV, m as GITHUB_TOKEN_ENV } from "./constants-DkiLCuIK.mjs";
2
+ import { n as silentLogger } from "./logger-D1XGzzjT.mjs";
3
+ import { r as rt, t as projectIdentity } from "./projectIdentity-F97vs1H-.mjs";
4
+ import path from "node:path";
5
+ import { createReadStream } from "node:fs";
6
+ import { access, readFile, stat } from "node:fs/promises";
7
+
8
+ //#region src/pack/readArchiveEntries.ts
9
+ /** Reads the regular files of a (gzipped) tar archive, given as a file path (streamed) or as bytes, in memory. */
10
+ function readArchiveEntries(archive, { until } = {}) {
11
+ const files = /* @__PURE__ */ new Map();
12
+ let done = false;
13
+ let stopInput = () => {};
14
+ return new Promise((resolve, reject) => {
15
+ const parser = new rt({
16
+ strict: true,
17
+ onReadEntry(entry) {
18
+ if (done || entry.type !== "File") {
19
+ entry.resume();
20
+ return;
21
+ }
22
+ const file = entry.path.replace(/^\.\//, "");
23
+ const parts = [];
24
+ entry.on("data", (data) => parts.push(data));
25
+ entry.on("end", () => {
26
+ files.set(file, Buffer.concat(parts));
27
+ if (file === until) {
28
+ done = true;
29
+ stopInput();
30
+ resolve(files);
31
+ }
32
+ });
33
+ }
34
+ });
35
+ parser.on("error", reject);
36
+ parser.on("end", () => resolve(files));
37
+ if (typeof archive === "string") {
38
+ const input = createReadStream(archive);
39
+ stopInput = () => input.destroy();
40
+ input.on("error", reject).pipe(parser);
41
+ } else parser.end(Buffer.from(archive.buffer, archive.byteOffset, archive.byteLength));
42
+ });
43
+ }
44
+
45
+ //#endregion
46
+ //#region src/publish/HttpError.ts
47
+ var HttpError = class extends Error {
48
+ constructor(method, url, status, body) {
49
+ super(`${method} ${url} failed with HTTP ${status}: ${body.slice(0, 300)}`);
50
+ this.method = method;
51
+ this.url = url;
52
+ this.status = status;
53
+ this.body = body;
54
+ this.name = "HttpError";
55
+ }
56
+ };
57
+
58
+ //#endregion
59
+ //#region src/publish/requestJson.ts
60
+ /** fetch + JSON decoding; throws an HttpError (never including request headers) on unexpected statuses. */
61
+ async function requestJson(fetch, url, { method = "GET", headers, body, allow = [] } = {}) {
62
+ const response = await fetch(url, {
63
+ method,
64
+ headers,
65
+ body
66
+ });
67
+ if (allow.includes(response.status)) return;
68
+ const text = await response.text();
69
+ if (!response.ok) throw new HttpError(method, url, response.status, text);
70
+ return text ? JSON.parse(text) : void 0;
71
+ }
72
+
73
+ //#endregion
74
+ //#region src/publish/ensureRelease.ts
75
+ /**
76
+ * Returns the release of `manifest.tag`. When it does not exist, fails unless `publish.createRelease` is set,
77
+ * in which case the release is created (named after the tag).
78
+ */
79
+ async function ensureRelease({ config, manifest, fetch, logger }, { provider, repository, releaseUrl, releasesUrl, headers, jsonHeaders, missing }) {
80
+ const release = await requestJson(fetch, releaseUrl, {
81
+ headers,
82
+ allow: missing
83
+ });
84
+ if (release) return release;
85
+ if (!config.publish.createRelease) throw new Error(`No ${provider} release for tag ${manifest.tag}${repository ? ` in ${repository}` : ""} (set publish.createRelease to create it)`);
86
+ logger.info(`creating ${provider} release ${manifest.tag}`);
87
+ return await requestJson(fetch, releasesUrl, {
88
+ method: "POST",
89
+ headers: jsonHeaders,
90
+ body: JSON.stringify({
91
+ tag_name: manifest.tag,
92
+ name: manifest.tag
93
+ })
94
+ });
95
+ }
96
+
97
+ //#endregion
98
+ //#region src/publish/publishGithubRelease.ts
99
+ /**
100
+ * Uploads the archive as an asset of the GitHub release of `manifest.tag`, replacing an asset with the same name.
101
+ * Requires GITHUB_TOKEN (contents: write).
102
+ */
103
+ async function publishGithubRelease(context) {
104
+ const { config, manifest, archivePath, assetName, dryRun, env, fetch, logger } = context;
105
+ const { owner, name, apiUrl } = config.repository;
106
+ const repoUrl = `${apiUrl}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`;
107
+ const plannedUrl = `https://github.com/${owner}/${name}/releases/download/${encodeURIComponent(manifest.tag)}/${encodeURIComponent(assetName)}`;
108
+ if (dryRun) {
109
+ logger.info(`[dry-run] would upload ${assetName} (${(await stat(archivePath)).size} bytes) to the GitHub release ${manifest.tag} of ${owner}/${name}`);
110
+ logger.info(`[dry-run] ${config.publish.createRelease ? "would create the release if missing" : "requires the release to exist"}; an existing ${assetName} asset would be replaced`);
111
+ return {
112
+ target: "github-release",
113
+ dryRun,
114
+ url: plannedUrl,
115
+ replaced: false
116
+ };
117
+ }
118
+ const token = env[GITHUB_TOKEN_ENV];
119
+ if (!token) throw new Error(`${GITHUB_TOKEN_ENV} is not set (required to publish on a GitHub release)`);
120
+ const headers = {
121
+ Accept: "application/vnd.github+json",
122
+ Authorization: `Bearer ${token}`,
123
+ "X-GitHub-Api-Version": "2022-11-28",
124
+ "User-Agent": "cmflow-source-pack"
125
+ };
126
+ const release = await ensureRelease(context, {
127
+ provider: "GitHub",
128
+ repository: `${owner}/${name}`,
129
+ releaseUrl: `${repoUrl}/releases/tags/${encodeURIComponent(manifest.tag)}`,
130
+ releasesUrl: `${repoUrl}/releases`,
131
+ headers,
132
+ jsonHeaders: {
133
+ ...headers,
134
+ "Content-Type": "application/json"
135
+ },
136
+ missing: [404]
137
+ });
138
+ const existing = release.assets?.find((asset) => asset.name === assetName);
139
+ if (existing) {
140
+ logger.info(`replacing existing asset ${assetName}`);
141
+ await requestJson(fetch, `${repoUrl}/releases/assets/${existing.id}`, {
142
+ method: "DELETE",
143
+ headers
144
+ });
145
+ }
146
+ const archive = await readFile(archivePath);
147
+ const uploadUrl = `${release.upload_url.replace(/\{.*\}$/, "")}?name=${encodeURIComponent(assetName)}`;
148
+ const asset = await requestJson(fetch, uploadUrl, {
149
+ method: "POST",
150
+ headers: {
151
+ ...headers,
152
+ "Content-Type": "application/gzip",
153
+ "Content-Length": String(archive.length)
154
+ },
155
+ body: archive
156
+ });
157
+ logger.info(`published ${asset.browser_download_url}`);
158
+ return {
159
+ target: "github-release",
160
+ dryRun,
161
+ url: asset.browser_download_url,
162
+ replaced: Boolean(existing)
163
+ };
164
+ }
165
+
166
+ //#endregion
167
+ //#region src/publish/publishGitlabRelease.ts
168
+ function gitlabHeaders(env) {
169
+ const token = env[GITLAB_TOKEN_ENV];
170
+ if (token) return { "PRIVATE-TOKEN": token };
171
+ if (env.CI_JOB_TOKEN) return { "JOB-TOKEN": env.CI_JOB_TOKEN };
172
+ throw new Error(`${GITLAB_TOKEN_ENV} is not set (required to publish on a GitLab release; CI_JOB_TOKEN is used as a fallback)`);
173
+ }
174
+ /**
175
+ * Uploads the archive to the project's Generic Package Registry
176
+ * (`/projects/:id/packages/generic/<packageName>/<version>/<assetName>`), removes older files with the same name
177
+ * in that package version, and links it from the GitLab release of `manifest.tag` (link updated when it exists).
178
+ */
179
+ async function publishGitlabRelease(context) {
180
+ const { config, manifest, archivePath, assetName, dryRun, env, fetch, logger } = context;
181
+ const { apiUrl, projectId, owner, name } = config.repository;
182
+ const { packageName } = config.publish;
183
+ const projectUrl = `${apiUrl}/projects/${encodeURIComponent(projectId ?? `${owner}/${name}`)}`;
184
+ const packageUrl = `${projectUrl}/packages/generic/${encodeURIComponent(packageName)}/${encodeURIComponent(manifest.version)}/${encodeURIComponent(assetName)}`;
185
+ const releaseUrl = `${projectUrl}/releases/${encodeURIComponent(manifest.tag)}`;
186
+ if (dryRun) {
187
+ logger.info(`[dry-run] would PUT ${assetName} (${(await stat(archivePath)).size} bytes) to ${packageUrl}`);
188
+ logger.info(`[dry-run] would link it from the GitLab release ${manifest.tag}${config.publish.createRelease ? " (created if missing)" : ""}`);
189
+ return {
190
+ target: "gitlab-release",
191
+ dryRun,
192
+ url: packageUrl,
193
+ replaced: false
194
+ };
195
+ }
196
+ const headers = gitlabHeaders(env);
197
+ const jsonHeaders = {
198
+ ...headers,
199
+ "Content-Type": "application/json"
200
+ };
201
+ const uploaded = await requestJson(fetch, `${packageUrl}?select=package_file`, {
202
+ method: "PUT",
203
+ headers: {
204
+ ...headers,
205
+ "Content-Type": "application/octet-stream"
206
+ },
207
+ body: await readFile(archivePath)
208
+ });
209
+ const duplicates = (await requestJson(fetch, `${projectUrl}/packages/${uploaded.package_id}/package_files?per_page=100`, { headers }) ?? []).filter((file) => file.file_name === assetName && file.id !== uploaded.id);
210
+ for (const duplicate of duplicates) await requestJson(fetch, `${projectUrl}/packages/${uploaded.package_id}/package_files/${duplicate.id}`, {
211
+ method: "DELETE",
212
+ headers
213
+ });
214
+ await ensureRelease(context, {
215
+ provider: "GitLab",
216
+ releaseUrl,
217
+ releasesUrl: `${projectUrl}/releases`,
218
+ headers,
219
+ jsonHeaders,
220
+ missing: [404, 403]
221
+ });
222
+ const existing = (await requestJson(fetch, `${releaseUrl}/assets/links?per_page=100`, { headers }) ?? []).find((link) => link.name === assetName);
223
+ const linkBody = JSON.stringify({
224
+ name: assetName,
225
+ url: packageUrl,
226
+ link_type: "package"
227
+ });
228
+ if (existing) await requestJson(fetch, `${releaseUrl}/assets/links/${existing.id}`, {
229
+ method: "PUT",
230
+ headers: jsonHeaders,
231
+ body: linkBody
232
+ });
233
+ else await requestJson(fetch, `${releaseUrl}/assets/links`, {
234
+ method: "POST",
235
+ headers: jsonHeaders,
236
+ body: linkBody
237
+ });
238
+ logger.info(`published ${packageUrl}`);
239
+ return {
240
+ target: "gitlab-release",
241
+ dryRun,
242
+ url: packageUrl,
243
+ replaced: duplicates.length > 0 || Boolean(existing)
244
+ };
245
+ }
246
+
247
+ //#endregion
248
+ //#region src/publish/publishSourcePack.ts
249
+ async function locateArchive(config, archivePath) {
250
+ if (archivePath) {
251
+ const resolved = path.resolve(config.cwd, archivePath);
252
+ const manifestFile = (await readArchiveEntries(resolved, { until: MANIFEST_FILE })).get(MANIFEST_FILE);
253
+ if (!manifestFile) throw new Error(`${resolved} is not a source pack (no ${MANIFEST_FILE})`);
254
+ return {
255
+ archivePath: resolved,
256
+ manifest: JSON.parse(manifestFile.toString("utf8"))
257
+ };
258
+ }
259
+ const manifestPath = path.join(config.outputDir, MANIFEST_FILE);
260
+ let manifest;
261
+ try {
262
+ manifest = JSON.parse(await readFile(manifestPath, "utf8"));
263
+ } catch {
264
+ throw new Error(`No built source pack in ${config.outputDir}: run "source-pack build" first or pass --archive`);
265
+ }
266
+ const resolved = path.join(config.outputDir, manifest.publish.assetName);
267
+ await access(resolved).catch(() => {
268
+ throw new Error(`Archive ${resolved} declared by ${manifestPath} is missing: run "source-pack build" again`);
269
+ });
270
+ return {
271
+ archivePath: resolved,
272
+ manifest
273
+ };
274
+ }
275
+ /** Publishes a built source pack on the release of its tag, on the provider of `repository`. Idempotent. */
276
+ async function publishSourcePack(options) {
277
+ const { config, env = process.env, fetch = globalThis.fetch, logger = silentLogger } = options;
278
+ const { archivePath, manifest } = await locateArchive(config, options.archivePath);
279
+ const context = {
280
+ config,
281
+ manifest,
282
+ archivePath,
283
+ assetName: path.basename(archivePath),
284
+ dryRun: Boolean(options.dryRun),
285
+ env,
286
+ fetch,
287
+ logger
288
+ };
289
+ const expectedProject = projectIdentity(config.repository).id;
290
+ if (manifest.project.id !== expectedProject) throw new Error(`Archive belongs to ${manifest.project.id}, not to the configured repository ${expectedProject}`);
291
+ return config.repository.provider === "github" ? publishGithubRelease(context) : publishGitlabRelease(context);
292
+ }
293
+
294
+ //#endregion
295
+ export { readArchiveEntries as n, publishSourcePack as t };
296
+ //# sourceMappingURL=publishSourcePack-xNr9RBgv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishSourcePack-xNr9RBgv.mjs","names":["Parser"],"sources":["../src/pack/readArchiveEntries.ts","../src/publish/HttpError.ts","../src/publish/requestJson.ts","../src/publish/ensureRelease.ts","../src/publish/publishGithubRelease.ts","../src/publish/publishGitlabRelease.ts","../src/publish/publishSourcePack.ts"],"sourcesContent":["import { createReadStream } from \"node:fs\";\nimport { Parser, type ReadEntry } from \"tar\";\n\nexport interface ReadArchiveEntriesOptions {\n /** Stop reading the archive as soon as this entry has been read (the rest of the file is not read). */\n until?: string;\n}\n\n/** Reads the regular files of a (gzipped) tar archive, given as a file path (streamed) or as bytes, in memory. */\nexport function readArchiveEntries(archive: string | Uint8Array, { until }: ReadArchiveEntriesOptions = {}): Promise<Map<string, Buffer>> {\n const files = new Map<string, Buffer>();\n let done = false;\n let stopInput = () => {};\n\n return new Promise((resolve, reject) => {\n const parser = new Parser({\n strict: true,\n onReadEntry(entry: ReadEntry) {\n if (done || entry.type !== \"File\") {\n entry.resume();\n return;\n }\n\n const file = entry.path.replace(/^\\.\\//, \"\");\n const parts: Buffer[] = [];\n\n entry.on(\"data\", (data: Buffer) => parts.push(data));\n entry.on(\"end\", () => {\n files.set(file, Buffer.concat(parts));\n\n if (file === until) {\n done = true;\n stopInput();\n resolve(files);\n }\n });\n }\n });\n\n parser.on(\"error\", reject);\n parser.on(\"end\", () => resolve(files));\n\n if (typeof archive === \"string\") {\n const input = createReadStream(archive);\n\n stopInput = () => input.destroy();\n input.on(\"error\", reject).pipe(parser);\n } else {\n parser.end(Buffer.from(archive.buffer, archive.byteOffset, archive.byteLength));\n }\n });\n}\n","export class HttpError extends Error {\n constructor(\n readonly method: string,\n readonly url: string,\n readonly status: number,\n readonly body: string\n ) {\n super(`${method} ${url} failed with HTTP ${status}: ${body.slice(0, 300)}`);\n this.name = \"HttpError\";\n }\n}\n","import { HttpError } from \"./HttpError\";\n\nexport interface RequestJsonOptions {\n method?: string;\n headers?: Record<string, string>;\n body?: string | Uint8Array;\n /** Statuses returned as `undefined` instead of throwing (e.g. 404). */\n allow?: number[];\n}\n\n/** fetch + JSON decoding; throws an HttpError (never including request headers) on unexpected statuses. */\nexport async function requestJson<T>(\n fetch: typeof globalThis.fetch,\n url: string,\n { method = \"GET\", headers, body, allow = [] }: RequestJsonOptions = {}\n): Promise<T | undefined> {\n const response = await fetch(url, { method, headers, body });\n\n if (allow.includes(response.status)) {\n return undefined;\n }\n\n const text = await response.text();\n\n if (!response.ok) {\n throw new HttpError(method, url, response.status, text);\n }\n\n return (text ? JSON.parse(text) : undefined) as T;\n}\n","import type { PublishContext } from \"./interfaces/PublishContext\";\nimport { requestJson } from \"./requestJson\";\n\nexport interface EnsureReleaseOptions {\n /** Provider name used in messages, e.g. `GitHub`. */\n provider: string;\n /** Repository shown in the \"missing release\" error, when the provider message needs it. */\n repository?: string;\n /** Release of `manifest.tag`. */\n releaseUrl: string;\n /** Collection the release is created in when missing. */\n releasesUrl: string;\n headers: Record<string, string>;\n jsonHeaders: Record<string, string>;\n /** Statuses meaning \"no release\" on `releaseUrl`. */\n missing: number[];\n}\n\n/**\n * Returns the release of `manifest.tag`. When it does not exist, fails unless `publish.createRelease` is set,\n * in which case the release is created (named after the tag).\n */\nexport async function ensureRelease<T>(\n { config, manifest, fetch, logger }: Pick<PublishContext, \"config\" | \"manifest\" | \"fetch\" | \"logger\">,\n { provider, repository, releaseUrl, releasesUrl, headers, jsonHeaders, missing }: EnsureReleaseOptions\n): Promise<T> {\n const release = await requestJson<T>(fetch, releaseUrl, { headers, allow: missing });\n\n if (release) {\n return release;\n }\n\n if (!config.publish.createRelease) {\n throw new Error(\n `No ${provider} release for tag ${manifest.tag}${repository ? ` in ${repository}` : \"\"} (set publish.createRelease to create it)`\n );\n }\n\n logger.info(`creating ${provider} release ${manifest.tag}`);\n\n return (await requestJson<T>(fetch, releasesUrl, {\n method: \"POST\",\n headers: jsonHeaders,\n body: JSON.stringify({ tag_name: manifest.tag, name: manifest.tag })\n })) as T;\n}\n","import { readFile, stat } from \"node:fs/promises\";\nimport { GITHUB_TOKEN_ENV } from \"../constants\";\nimport { ensureRelease } from \"./ensureRelease\";\nimport type { PublishContext, PublishResult } from \"./interfaces/PublishContext\";\nimport { requestJson } from \"./requestJson\";\n\ninterface GithubAsset {\n id: number;\n name: string;\n browser_download_url: string;\n}\n\ninterface GithubRelease {\n id: number;\n upload_url: string;\n html_url: string;\n assets?: GithubAsset[];\n}\n\n/**\n * Uploads the archive as an asset of the GitHub release of `manifest.tag`, replacing an asset with the same name.\n * Requires GITHUB_TOKEN (contents: write).\n */\nexport async function publishGithubRelease(context: PublishContext): Promise<PublishResult> {\n const { config, manifest, archivePath, assetName, dryRun, env, fetch, logger } = context;\n const { owner, name, apiUrl } = config.repository;\n const repoUrl = `${apiUrl}/repos/${encodeURIComponent(owner!)}/${encodeURIComponent(name!)}`;\n const plannedUrl = `https://github.com/${owner}/${name}/releases/download/${encodeURIComponent(manifest.tag)}/${encodeURIComponent(assetName)}`;\n\n if (dryRun) {\n logger.info(\n `[dry-run] would upload ${assetName} (${(await stat(archivePath)).size} bytes) to the GitHub release ${manifest.tag} of ${owner}/${name}`\n );\n logger.info(\n `[dry-run] ${config.publish.createRelease ? \"would create the release if missing\" : \"requires the release to exist\"}; an existing ${assetName} asset would be replaced`\n );\n\n return { target: \"github-release\", dryRun, url: plannedUrl, replaced: false };\n }\n\n const token = env[GITHUB_TOKEN_ENV];\n\n if (!token) {\n throw new Error(`${GITHUB_TOKEN_ENV} is not set (required to publish on a GitHub release)`);\n }\n\n const headers = {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${token}`,\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n \"User-Agent\": \"cmflow-source-pack\"\n };\n const release = await ensureRelease<GithubRelease>(context, {\n provider: \"GitHub\",\n repository: `${owner}/${name}`,\n releaseUrl: `${repoUrl}/releases/tags/${encodeURIComponent(manifest.tag)}`,\n releasesUrl: `${repoUrl}/releases`,\n headers,\n jsonHeaders: { ...headers, \"Content-Type\": \"application/json\" },\n missing: [404]\n });\n const existing = release.assets?.find((asset) => asset.name === assetName);\n\n if (existing) {\n logger.info(`replacing existing asset ${assetName}`);\n await requestJson(fetch, `${repoUrl}/releases/assets/${existing.id}`, { method: \"DELETE\", headers });\n }\n\n const archive = await readFile(archivePath);\n const uploadUrl = `${release.upload_url.replace(/\\{.*\\}$/, \"\")}?name=${encodeURIComponent(assetName)}`;\n const asset = (await requestJson<GithubAsset>(fetch, uploadUrl, {\n method: \"POST\",\n headers: { ...headers, \"Content-Type\": \"application/gzip\", \"Content-Length\": String(archive.length) },\n body: archive\n }))!;\n\n logger.info(`published ${asset.browser_download_url}`);\n\n return { target: \"github-release\", dryRun, url: asset.browser_download_url, replaced: Boolean(existing) };\n}\n","import { readFile, stat } from \"node:fs/promises\";\nimport { GITLAB_TOKEN_ENV } from \"../constants\";\nimport { ensureRelease } from \"./ensureRelease\";\nimport type { PublishContext, PublishResult } from \"./interfaces/PublishContext\";\nimport { requestJson } from \"./requestJson\";\n\ninterface GitlabPackageFile {\n id: number;\n package_id: number;\n file_name: string;\n}\n\ninterface GitlabReleaseLink {\n id: number;\n name: string;\n url: string;\n}\n\nfunction gitlabHeaders(env: NodeJS.ProcessEnv): Record<string, string> {\n const token = env[GITLAB_TOKEN_ENV];\n\n if (token) {\n return { \"PRIVATE-TOKEN\": token };\n }\n\n if (env.CI_JOB_TOKEN) {\n return { \"JOB-TOKEN\": env.CI_JOB_TOKEN };\n }\n\n throw new Error(`${GITLAB_TOKEN_ENV} is not set (required to publish on a GitLab release; CI_JOB_TOKEN is used as a fallback)`);\n}\n\n/**\n * Uploads the archive to the project's Generic Package Registry\n * (`/projects/:id/packages/generic/<packageName>/<version>/<assetName>`), removes older files with the same name\n * in that package version, and links it from the GitLab release of `manifest.tag` (link updated when it exists).\n */\nexport async function publishGitlabRelease(context: PublishContext): Promise<PublishResult> {\n const { config, manifest, archivePath, assetName, dryRun, env, fetch, logger } = context;\n const { apiUrl, projectId, owner, name } = config.repository;\n const { packageName } = config.publish;\n const project = encodeURIComponent(projectId ?? `${owner}/${name}`);\n const projectUrl = `${apiUrl}/projects/${project}`;\n const packageUrl = `${projectUrl}/packages/generic/${encodeURIComponent(packageName)}/${encodeURIComponent(manifest.version)}/${encodeURIComponent(assetName)}`;\n const releaseUrl = `${projectUrl}/releases/${encodeURIComponent(manifest.tag)}`;\n\n if (dryRun) {\n logger.info(`[dry-run] would PUT ${assetName} (${(await stat(archivePath)).size} bytes) to ${packageUrl}`);\n logger.info(\n `[dry-run] would link it from the GitLab release ${manifest.tag}${config.publish.createRelease ? \" (created if missing)\" : \"\"}`\n );\n\n return { target: \"gitlab-release\", dryRun, url: packageUrl, replaced: false };\n }\n\n const headers = gitlabHeaders(env);\n const jsonHeaders = { ...headers, \"Content-Type\": \"application/json\" };\n const uploaded = (await requestJson<GitlabPackageFile>(fetch, `${packageUrl}?select=package_file`, {\n method: \"PUT\",\n headers: { ...headers, \"Content-Type\": \"application/octet-stream\" },\n body: await readFile(archivePath)\n }))!;\n const files =\n (await requestJson<GitlabPackageFile[]>(fetch, `${projectUrl}/packages/${uploaded.package_id}/package_files?per_page=100`, {\n headers\n })) ?? [];\n const duplicates = files.filter((file) => file.file_name === assetName && file.id !== uploaded.id);\n\n for (const duplicate of duplicates) {\n await requestJson(fetch, `${projectUrl}/packages/${uploaded.package_id}/package_files/${duplicate.id}`, { method: \"DELETE\", headers });\n }\n\n await ensureRelease(context, {\n provider: \"GitLab\",\n releaseUrl,\n releasesUrl: `${projectUrl}/releases`,\n headers,\n jsonHeaders,\n missing: [404, 403]\n });\n\n const links = (await requestJson<GitlabReleaseLink[]>(fetch, `${releaseUrl}/assets/links?per_page=100`, { headers })) ?? [];\n const existing = links.find((link) => link.name === assetName);\n const linkBody = JSON.stringify({ name: assetName, url: packageUrl, link_type: \"package\" });\n\n if (existing) {\n await requestJson(fetch, `${releaseUrl}/assets/links/${existing.id}`, { method: \"PUT\", headers: jsonHeaders, body: linkBody });\n } else {\n await requestJson(fetch, `${releaseUrl}/assets/links`, { method: \"POST\", headers: jsonHeaders, body: linkBody });\n }\n\n logger.info(`published ${packageUrl}`);\n\n return { target: \"gitlab-release\", dryRun, url: packageUrl, replaced: duplicates.length > 0 || Boolean(existing) };\n}\n","import { access, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { ResolvedConfig } from \"../config/interfaces/ResolvedConfig\";\nimport { MANIFEST_FILE } from \"../constants\";\nimport type { SourcePackManifest } from \"../interfaces/SourcePackManifest\";\nimport { projectIdentity } from \"../pack/projectIdentity\";\nimport { readArchiveEntries } from \"../pack/readArchiveEntries\";\nimport { type Logger, silentLogger } from \"../utils/logger\";\nimport type { PublishResult } from \"./interfaces/PublishContext\";\nimport { publishGithubRelease } from \"./publishGithubRelease\";\nimport { publishGitlabRelease } from \"./publishGitlabRelease\";\n\nexport interface PublishSourcePackOptions {\n config: ResolvedConfig;\n /** Archive to publish. Default: the archive of the last `build` in `outputDir`. */\n archivePath?: string;\n dryRun?: boolean;\n env?: NodeJS.ProcessEnv;\n fetch?: typeof globalThis.fetch;\n logger?: Logger;\n}\n\nasync function locateArchive(config: ResolvedConfig, archivePath?: string): Promise<{ archivePath: string; manifest: SourcePackManifest }> {\n if (archivePath) {\n const resolved = path.resolve(config.cwd, archivePath);\n const manifestFile = (await readArchiveEntries(resolved, { until: MANIFEST_FILE })).get(MANIFEST_FILE);\n\n if (!manifestFile) {\n throw new Error(`${resolved} is not a source pack (no ${MANIFEST_FILE})`);\n }\n\n return { archivePath: resolved, manifest: JSON.parse(manifestFile.toString(\"utf8\")) as SourcePackManifest };\n }\n\n const manifestPath = path.join(config.outputDir, MANIFEST_FILE);\n let manifest: SourcePackManifest;\n\n try {\n manifest = JSON.parse(await readFile(manifestPath, \"utf8\")) as SourcePackManifest;\n } catch {\n throw new Error(`No built source pack in ${config.outputDir}: run \"source-pack build\" first or pass --archive`);\n }\n\n const resolved = path.join(config.outputDir, manifest.publish.assetName);\n\n await access(resolved).catch(() => {\n throw new Error(`Archive ${resolved} declared by ${manifestPath} is missing: run \"source-pack build\" again`);\n });\n\n return { archivePath: resolved, manifest };\n}\n\n/** Publishes a built source pack on the release of its tag, on the provider of `repository`. Idempotent. */\nexport async function publishSourcePack(options: PublishSourcePackOptions): Promise<PublishResult> {\n const { config, env = process.env, fetch = globalThis.fetch, logger = silentLogger } = options;\n const { archivePath, manifest } = await locateArchive(config, options.archivePath);\n const context = {\n config,\n manifest,\n archivePath,\n assetName: path.basename(archivePath),\n dryRun: Boolean(options.dryRun),\n env,\n fetch,\n logger\n };\n\n const expectedProject = projectIdentity(config.repository).id;\n\n if (manifest.project.id !== expectedProject) {\n throw new Error(`Archive belongs to ${manifest.project.id}, not to the configured repository ${expectedProject}`);\n }\n\n return config.repository.provider === \"github\" ? publishGithubRelease(context) : publishGitlabRelease(context);\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,mBAAmB,SAA8B,EAAE,UAAqC,CAAC,GAAiC;CACxI,MAAM,wBAAQ,IAAI,IAAoB;CACtC,IAAI,OAAO;CACX,IAAI,kBAAkB,CAAC;CAEvB,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,SAAS,IAAIA,GAAO;GACxB,QAAQ;GACR,YAAY,OAAkB;IAC5B,IAAI,QAAQ,MAAM,SAAS,QAAQ;KACjC,MAAM,OAAO;KACb;IACF;IAEA,MAAM,OAAO,MAAM,KAAK,QAAQ,SAAS,EAAE;IAC3C,MAAM,QAAkB,CAAC;IAEzB,MAAM,GAAG,SAAS,SAAiB,MAAM,KAAK,IAAI,CAAC;IACnD,MAAM,GAAG,aAAa;KACpB,MAAM,IAAI,MAAM,OAAO,OAAO,KAAK,CAAC;KAEpC,IAAI,SAAS,OAAO;MAClB,OAAO;MACP,UAAU;MACV,QAAQ,KAAK;KACf;IACF,CAAC;GACH;EACF,CAAC;EAED,OAAO,GAAG,SAAS,MAAM;EACzB,OAAO,GAAG,aAAa,QAAQ,KAAK,CAAC;EAErC,IAAI,OAAO,YAAY,UAAU;GAC/B,MAAM,QAAQ,iBAAiB,OAAO;GAEtC,kBAAkB,MAAM,QAAQ;GAChC,MAAM,GAAG,SAAS,MAAM,CAAC,CAAC,KAAK,MAAM;EACvC,OACE,OAAO,IAAI,OAAO,KAAK,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,UAAU,CAAC;C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,OAAO,IAAI,qBAAqB,OAAO;AAC/G"}
@@ -0,0 +1,59 @@
1
+ import { i as __commonJSMin, r as require_token_error, t as require_token_util } from "./token-util-C3JYrW4-.mjs";
2
+
3
+ //#region ../../node_modules/@vercel/oidc/dist/token.js
4
+ var require_token = /* @__PURE__ */ __commonJSMin(((exports, module) => {
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var token_exports = {};
26
+ __export(token_exports, { refreshToken: () => refreshToken });
27
+ module.exports = __toCommonJS(token_exports);
28
+ var import_token_error = require_token_error();
29
+ var import_token_util = require_token_util();
30
+ async function refreshToken(options) {
31
+ let projectId = options?.project;
32
+ let teamId = options?.team;
33
+ if (!projectId && !teamId) {
34
+ const projectInfo = (0, import_token_util.findProjectInfo)();
35
+ projectId = projectInfo.projectId;
36
+ teamId = projectInfo.teamId;
37
+ } else if (!projectId || !teamId) {
38
+ const projectInfo = (0, import_token_util.findProjectInfo)();
39
+ projectId = projectId ?? projectInfo.projectId;
40
+ teamId = teamId ?? projectInfo.teamId;
41
+ }
42
+ if (!projectId) throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token: No project specified. Try re-linking your project with `vc link`");
43
+ let maybeToken = (0, import_token_util.loadToken)(projectId);
44
+ if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options?.expirationBufferMs)) {
45
+ const authToken = await (0, import_token_util.getVercelToken)({ expirationBufferMs: options?.expirationBufferMs });
46
+ maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
47
+ if (!maybeToken) throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token");
48
+ (0, import_token_util.saveToken)(maybeToken, projectId);
49
+ }
50
+ process.env.VERCEL_OIDC_TOKEN = maybeToken.token;
51
+ }
52
+ 0 && (module.exports = { refreshToken });
53
+ }));
54
+
55
+ //#endregion
56
+ export default require_token();
57
+
58
+ export { };
59
+ //# sourceMappingURL=token-DMtao22Y.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-DMtao22Y.mjs","names":[],"sources":["../../../node_modules/@vercel/oidc/dist/token.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar token_exports = {};\n__export(token_exports, {\n refreshToken: () => refreshToken\n});\nmodule.exports = __toCommonJS(token_exports);\nvar import_token_error = require(\"./token-error\");\nvar import_token_util = require(\"./token-util\");\nasync function refreshToken(options) {\n let projectId = options?.project;\n let teamId = options?.team;\n if (!projectId && !teamId) {\n const projectInfo = (0, import_token_util.findProjectInfo)();\n projectId = projectInfo.projectId;\n teamId = projectInfo.teamId;\n } else if (!projectId || !teamId) {\n const projectInfo = (0, import_token_util.findProjectInfo)();\n projectId = projectId ?? projectInfo.projectId;\n teamId = teamId ?? projectInfo.teamId;\n }\n if (!projectId) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: No project specified. Try re-linking your project with `vc link`\"\n );\n }\n let maybeToken = (0, import_token_util.loadToken)(projectId);\n if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token), options?.expirationBufferMs)) {\n const authToken = await (0, import_token_util.getVercelToken)({\n expirationBufferMs: options?.expirationBufferMs\n });\n maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);\n if (!maybeToken) {\n throw new import_token_error.VercelOidcTokenError(\"Failed to refresh OIDC token\");\n }\n (0, import_token_util.saveToken)(maybeToken, projectId);\n }\n process.env.VERCEL_OIDC_TOKEN = maybeToken.token;\n return;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n refreshToken\n});\n"],"x_google_ignoreList":[0],"mappings":";;;;CACA,IAAI,YAAY,OAAO;CACvB,IAAI,mBAAmB,OAAO;CAC9B,IAAI,oBAAoB,OAAO;CAC/B,IAAI,eAAe,OAAO,UAAU;CACpC,IAAI,YAAY,QAAQ,QAAQ;EAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;GAAE,KAAK,IAAI;GAAO,YAAY;EAAK,CAAC;CAChE;CACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;EAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YACtD;QAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;IAAE,WAAW,KAAK;IAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;GAAW,CAAC;EA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