@stacksjs/registry 0.10.17 → 0.10.20

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 (2) hide show
  1. package/dist/index.js +244 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -104122,13 +104122,253 @@ async function handleDocs(reqPath) {
104122
104122
  return new Response("Documentation not found", { status: 404 });
104123
104123
  }
104124
104124
  if (false) {}
104125
+ // src/workspace-protocol.ts
104126
+ import { existsSync as existsSync15, readFileSync as readFileSync5 } from "fs";
104127
+ import { dirname as dirname8, join as join10, resolve as resolve16 } from "path";
104128
+ var {Glob } = globalThis.Bun;
104129
+ var WORKSPACE_RANGE_SECTIONS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
104130
+
104131
+ class UnresolvableWorkspaceDependencyError extends Error {
104132
+ dependency;
104133
+ section;
104134
+ constructor(message, dependency, section) {
104135
+ super(message);
104136
+ this.name = "UnresolvableWorkspaceDependencyError";
104137
+ this.dependency = dependency;
104138
+ this.section = section;
104139
+ }
104140
+ }
104141
+
104142
+ class UnresolvableCatalogDependencyError extends Error {
104143
+ dependency;
104144
+ section;
104145
+ constructor(message, dependency, section) {
104146
+ super(message);
104147
+ this.name = "UnresolvableCatalogDependencyError";
104148
+ this.dependency = dependency;
104149
+ this.section = section;
104150
+ }
104151
+ }
104152
+ function resolveWorkspaceSpec(spec, version3) {
104153
+ if (spec === "" || spec === "*")
104154
+ return version3;
104155
+ if (spec === "^")
104156
+ return `^${version3}`;
104157
+ if (spec === "~")
104158
+ return `~${version3}`;
104159
+ return spec;
104160
+ }
104161
+ function readWorkspaceGlobsFromManifest(manifest) {
104162
+ if (!manifest || typeof manifest !== "object")
104163
+ return [];
104164
+ const workspaces = manifest.workspaces;
104165
+ if (Array.isArray(workspaces))
104166
+ return workspaces.filter((p11) => typeof p11 === "string");
104167
+ if (workspaces && typeof workspaces === "object") {
104168
+ const packages = workspaces.packages;
104169
+ if (Array.isArray(packages))
104170
+ return packages.filter((p11) => typeof p11 === "string");
104171
+ }
104172
+ return [];
104173
+ }
104174
+ function readWorkspaceGlobs(rootDir) {
104175
+ const manifestPath = join10(rootDir, "package.json");
104176
+ if (!existsSync15(manifestPath))
104177
+ return [];
104178
+ try {
104179
+ return readWorkspaceGlobsFromManifest(JSON.parse(readFileSync5(manifestPath, "utf-8")));
104180
+ } catch {
104181
+ return [];
104182
+ }
104183
+ }
104184
+ function findWorkspaceRoot(startDir) {
104185
+ let current = resolve16(startDir);
104186
+ for (let depth = 0;depth < 32; depth++) {
104187
+ const manifestPath = join10(current, "package.json");
104188
+ if (existsSync15(manifestPath)) {
104189
+ try {
104190
+ const manifest = JSON.parse(readFileSync5(manifestPath, "utf-8"));
104191
+ if (readWorkspaceGlobsFromManifest(manifest).length > 0) {
104192
+ return current;
104193
+ }
104194
+ } catch {}
104195
+ }
104196
+ const parent = dirname8(current);
104197
+ if (parent === current)
104198
+ return null;
104199
+ current = parent;
104200
+ }
104201
+ return null;
104202
+ }
104203
+ function resolveWorkspacePackages(rootDir, globs = readWorkspaceGlobs(rootDir)) {
104204
+ const packages = new Map;
104205
+ for (const pattern of globs) {
104206
+ let matches;
104207
+ try {
104208
+ matches = [...new Glob(pattern).scanSync({ cwd: rootDir, onlyFiles: false })];
104209
+ } catch {
104210
+ continue;
104211
+ }
104212
+ for (const match of matches) {
104213
+ const dir = join10(rootDir, match);
104214
+ const manifestPath = join10(dir, "package.json");
104215
+ if (!existsSync15(manifestPath))
104216
+ continue;
104217
+ let manifest;
104218
+ try {
104219
+ manifest = JSON.parse(readFileSync5(manifestPath, "utf-8"));
104220
+ } catch {
104221
+ continue;
104222
+ }
104223
+ if (typeof manifest.name !== "string" || manifest.name.length === 0)
104224
+ continue;
104225
+ if (packages.has(manifest.name))
104226
+ continue;
104227
+ packages.set(manifest.name, {
104228
+ name: manifest.name,
104229
+ version: typeof manifest.version === "string" ? manifest.version : undefined,
104230
+ dir
104231
+ });
104232
+ }
104233
+ }
104234
+ return packages;
104235
+ }
104236
+ function firstWorkspaceRange(manifest) {
104237
+ for (const section of WORKSPACE_RANGE_SECTIONS) {
104238
+ const deps = manifest[section];
104239
+ if (!deps || typeof deps !== "object" || Array.isArray(deps))
104240
+ continue;
104241
+ for (const [name, range] of Object.entries(deps)) {
104242
+ if (typeof range === "string" && range.startsWith("workspace:")) {
104243
+ return { name, section, range };
104244
+ }
104245
+ }
104246
+ }
104247
+ return null;
104248
+ }
104249
+ function manifestUsesWorkspaceProtocol(manifest) {
104250
+ return firstWorkspaceRange(manifest) !== null;
104251
+ }
104252
+ function firstCatalogRange(manifest) {
104253
+ for (const section of WORKSPACE_RANGE_SECTIONS) {
104254
+ const deps = manifest[section];
104255
+ if (!deps || typeof deps !== "object" || Array.isArray(deps))
104256
+ continue;
104257
+ for (const [name, range] of Object.entries(deps)) {
104258
+ if (typeof range === "string" && range.startsWith("catalog:"))
104259
+ return { name, section, range };
104260
+ }
104261
+ }
104262
+ return null;
104263
+ }
104264
+ function manifestUsesCatalogProtocol(manifest) {
104265
+ return firstCatalogRange(manifest) !== null;
104266
+ }
104267
+ function catalogMap(root, name) {
104268
+ const source = root[name ? "catalogs" : "catalog"] ?? (root.workspaces && !Array.isArray(root.workspaces) ? root.workspaces[name ? "catalogs" : "catalog"] : undefined);
104269
+ const catalog = name ? source?.[name] : source;
104270
+ return catalog && typeof catalog === "object" && !Array.isArray(catalog) ? catalog : undefined;
104271
+ }
104272
+ function rewriteCatalogRanges(manifest, root) {
104273
+ const resolutions = [];
104274
+ let result = manifest;
104275
+ for (const section of WORKSPACE_RANGE_SECTIONS) {
104276
+ const deps = manifest[section];
104277
+ if (!deps || typeof deps !== "object" || Array.isArray(deps))
104278
+ continue;
104279
+ for (const [dep, range] of Object.entries(deps)) {
104280
+ if (typeof range !== "string" || !range.startsWith("catalog:"))
104281
+ continue;
104282
+ const name = range.slice("catalog:".length);
104283
+ const version3 = catalogMap(root, name)?.[dep];
104284
+ if (typeof version3 !== "string" || !version3) {
104285
+ throw new UnresolvableCatalogDependencyError(`Cannot publish "${String(manifest.name ?? "package")}" - dependency "${dep}" (${section}) uses "${range}" but the workspace root does not define it in that catalog.`, dep, section);
104286
+ }
104287
+ if (result === manifest)
104288
+ result = { ...manifest };
104289
+ if (result[section] === deps)
104290
+ result[section] = { ...deps };
104291
+ result[section][dep] = version3;
104292
+ resolutions.push({ name: dep, section, from: range, to: version3 });
104293
+ }
104294
+ }
104295
+ return { manifest: result, resolutions };
104296
+ }
104297
+ function rewriteWorkspaceRanges(manifest, packages, options = {}) {
104298
+ const resolutions = [];
104299
+ let result = manifest;
104300
+ const owner = options.packageName ? `"${options.packageName}" ` : "";
104301
+ const lookedIn = options.workspaceRoot ? ` (workspace root: ${options.workspaceRoot})` : "";
104302
+ for (const section of WORKSPACE_RANGE_SECTIONS) {
104303
+ const deps = manifest[section];
104304
+ if (!deps || typeof deps !== "object" || Array.isArray(deps))
104305
+ continue;
104306
+ for (const [dep, range] of Object.entries(deps)) {
104307
+ if (typeof range !== "string" || !range.startsWith("workspace:"))
104308
+ continue;
104309
+ const spec = range.slice("workspace:".length);
104310
+ const pkg = packages.get(dep);
104311
+ if (!pkg) {
104312
+ throw new UnresolvableWorkspaceDependencyError(`Cannot publish ${owner}\u2014 dependency "${dep}" (${section}) uses "${range}" but no workspace package named "${dep}" exists${lookedIn}. Refusing to publish an unresolvable workspace: range.`, dep, section);
104313
+ }
104314
+ if (!pkg.version) {
104315
+ throw new UnresolvableWorkspaceDependencyError(`Cannot publish ${owner}\u2014 workspace package "${dep}" (${section}, at ${pkg.dir}) has no "version" field. Refusing to publish an unresolvable "${range}" range.`, dep, section);
104316
+ }
104317
+ const to4 = resolveWorkspaceSpec(spec, pkg.version);
104318
+ if (result === manifest)
104319
+ result = { ...manifest };
104320
+ if (result[section] === deps)
104321
+ result[section] = { ...deps };
104322
+ result[section][dep] = to4;
104323
+ resolutions.push({ name: dep, section, from: range, to: to4 });
104324
+ }
104325
+ }
104326
+ return { manifest: result, resolutions };
104327
+ }
104328
+ function rewriteManifestForPublish(manifest, packageDir) {
104329
+ const usesWorkspace = manifestUsesWorkspaceProtocol(manifest);
104330
+ const usesCatalog = manifestUsesCatalogProtocol(manifest);
104331
+ if (!usesWorkspace && !usesCatalog)
104332
+ return { manifest, resolutions: [] };
104333
+ const packageName = typeof manifest.name === "string" ? manifest.name : undefined;
104334
+ const root = findWorkspaceRoot(packageDir);
104335
+ if (!root) {
104336
+ const ref = firstWorkspaceRange(manifest);
104337
+ throw new UnresolvableWorkspaceDependencyError(`Cannot publish ${packageName ? `"${packageName}" ` : ""}\u2014 dependency "${ref.name}" (${ref.section}) uses "${ref.range}" but no workspace root (a package.json with "workspaces") was found at or above ${packageDir}. Refusing to publish an unresolvable workspace: range.`, ref.name, ref.section);
104338
+ }
104339
+ const workspaceResult = usesWorkspace ? rewriteWorkspaceRanges(manifest, resolveWorkspacePackages(root), { packageName, workspaceRoot: root }) : { manifest, resolutions: [] };
104340
+ if (!usesCatalog)
104341
+ return workspaceResult;
104342
+ const rootManifest = JSON.parse(readFileSync5(join10(root, "package.json"), "utf-8"));
104343
+ const catalogResult = rewriteCatalogRanges(workspaceResult.manifest, rootManifest);
104344
+ return { manifest: catalogResult.manifest, resolutions: [...workspaceResult.resolutions, ...catalogResult.resolutions] };
104345
+ }
104346
+ function rewritePackageJsonContent(content, packageDir) {
104347
+ const manifest = JSON.parse(content);
104348
+ const result = rewriteManifestForPublish(manifest, packageDir);
104349
+ if (result.resolutions.length === 0) {
104350
+ return { content, rewritten: false, resolutions: [] };
104351
+ }
104352
+ return { content: `${JSON.stringify(result.manifest, null, 2)}
104353
+ `, rewritten: true, resolutions: result.resolutions };
104354
+ }
104125
104355
  export {
104126
104356
  verifyPassword,
104127
104357
  validateZigHash,
104128
104358
  searchPackagist,
104129
104359
  searchNpm,
104360
+ rewriteWorkspaceRanges,
104361
+ rewritePackageJsonContent,
104362
+ rewriteManifestForPublish,
104363
+ rewriteCatalogRanges,
104364
+ resolveWorkspaceSpec,
104365
+ resolveWorkspacePackages,
104366
+ readWorkspaceGlobsFromManifest,
104367
+ readWorkspaceGlobs,
104130
104368
  parseZigZon,
104131
104369
  parseComposerJson,
104370
+ manifestUsesWorkspaceProtocol,
104371
+ manifestUsesCatalogProtocol,
104132
104372
  listNpmVersions,
104133
104373
  isUserApiToken,
104134
104374
  hashToken,
@@ -104141,6 +104381,7 @@ export {
104141
104381
  generateComposerRequire,
104142
104382
  generateApiToken,
104143
104383
  formatPrice,
104384
+ findWorkspaceRoot,
104144
104385
  fetchFromPackagist,
104145
104386
  fetchFromNpm,
104146
104387
  downloadNpmTarball,
@@ -104159,6 +104400,9 @@ export {
104159
104400
  computeZigHash,
104160
104401
  computePhpChecksum,
104161
104402
  checkPaywallAccess,
104403
+ WORKSPACE_RANGE_SECTIONS,
104404
+ UnresolvableWorkspaceDependencyError,
104405
+ UnresolvableCatalogDependencyError,
104162
104406
  S3Storage,
104163
104407
  Registry,
104164
104408
  LocalStorage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacksjs/registry",
3
- "version": "0.10.17",
3
+ "version": "0.10.20",
4
4
  "type": "module",
5
5
  "description": "Pantry package registry backend - S3 storage with DynamoDB metadata",
6
6
  "author": "Stacks.js",