@earendil-works/chord 1.1.0 → 1.3.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 (190) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +79 -195
  3. package/dist/cell.d.ts +122 -0
  4. package/dist/cell.d.ts.map +1 -0
  5. package/dist/cell.js +356 -0
  6. package/dist/cell.js.map +1 -0
  7. package/dist/cluster.d.ts +27 -0
  8. package/dist/cluster.d.ts.map +1 -0
  9. package/dist/cluster.js +230 -0
  10. package/dist/cluster.js.map +1 -0
  11. package/dist/connection.d.ts +270 -0
  12. package/dist/connection.d.ts.map +1 -0
  13. package/dist/connection.js +1216 -0
  14. package/dist/connection.js.map +1 -0
  15. package/dist/context/index.d.ts +12 -1
  16. package/dist/context/index.d.ts.map +1 -1
  17. package/dist/context/index.js.map +1 -1
  18. package/dist/contract.d.ts +208 -0
  19. package/dist/contract.d.ts.map +1 -0
  20. package/dist/contract.js +246 -0
  21. package/dist/contract.js.map +1 -0
  22. package/dist/declare.d.ts +33 -0
  23. package/dist/declare.d.ts.map +1 -0
  24. package/dist/declare.js +2 -0
  25. package/dist/declare.js.map +1 -0
  26. package/dist/delta/apply-immutable-trusted.js.map +1 -1
  27. package/dist/delta/diff.d.ts +1 -1
  28. package/dist/delta/diff.d.ts.map +1 -1
  29. package/dist/delta/diff.js.map +1 -1
  30. package/dist/delta/index.d.ts +4 -3
  31. package/dist/delta/index.d.ts.map +1 -1
  32. package/dist/delta/index.js +45 -0
  33. package/dist/delta/index.js.map +1 -1
  34. package/dist/delta/revision-validator.d.ts +1 -1
  35. package/dist/delta/revision-validator.d.ts.map +1 -1
  36. package/dist/delta/revision-validator.js.map +1 -1
  37. package/dist/delta/tracker.d.ts +1 -1
  38. package/dist/delta/tracker.d.ts.map +1 -1
  39. package/dist/delta/tracker.js +40 -4
  40. package/dist/delta/tracker.js.map +1 -1
  41. package/dist/errors.d.ts +28 -0
  42. package/dist/errors.d.ts.map +1 -0
  43. package/dist/errors.js +59 -0
  44. package/dist/errors.js.map +1 -0
  45. package/dist/host.d.ts +348 -0
  46. package/dist/host.d.ts.map +1 -0
  47. package/dist/host.js +1000 -0
  48. package/dist/host.js.map +1 -0
  49. package/dist/index.d.ts +17 -10
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +8 -8
  52. package/dist/index.js.map +1 -1
  53. package/dist/json.d.ts +9 -1
  54. package/dist/json.d.ts.map +1 -1
  55. package/dist/json.js.map +1 -1
  56. package/dist/link.d.ts +107 -0
  57. package/dist/link.d.ts.map +1 -0
  58. package/dist/link.js +355 -0
  59. package/dist/link.js.map +1 -0
  60. package/dist/loader.d.ts +4 -0
  61. package/dist/loader.d.ts.map +1 -0
  62. package/dist/loader.js +73 -0
  63. package/dist/loader.js.map +1 -0
  64. package/dist/manager.d.ts +115 -0
  65. package/dist/manager.d.ts.map +1 -0
  66. package/dist/manager.js +345 -0
  67. package/dist/manager.js.map +1 -0
  68. package/dist/node.d.ts +3 -4
  69. package/dist/node.d.ts.map +1 -1
  70. package/dist/node.js +3 -2
  71. package/dist/node.js.map +1 -1
  72. package/dist/object.d.ts +438 -0
  73. package/dist/object.d.ts.map +1 -0
  74. package/dist/object.js +1571 -0
  75. package/dist/object.js.map +1 -0
  76. package/dist/output.d.ts +85 -0
  77. package/dist/output.d.ts.map +1 -0
  78. package/dist/output.js +350 -0
  79. package/dist/output.js.map +1 -0
  80. package/dist/publish.d.ts +5 -0
  81. package/dist/publish.d.ts.map +1 -0
  82. package/dist/publish.js +40 -0
  83. package/dist/publish.js.map +1 -0
  84. package/dist/registry.d.ts +25 -0
  85. package/dist/registry.d.ts.map +1 -0
  86. package/dist/registry.js +6 -0
  87. package/dist/registry.js.map +1 -0
  88. package/dist/reload.d.ts +126 -0
  89. package/dist/reload.d.ts.map +1 -0
  90. package/dist/reload.js +653 -0
  91. package/dist/reload.js.map +1 -0
  92. package/dist/remote.d.ts +165 -0
  93. package/dist/remote.d.ts.map +1 -0
  94. package/dist/remote.js +612 -0
  95. package/dist/remote.js.map +1 -0
  96. package/dist/schema.d.ts +21 -0
  97. package/dist/schema.d.ts.map +1 -0
  98. package/dist/schema.js +228 -0
  99. package/dist/schema.js.map +1 -0
  100. package/dist/state.d.ts +92 -0
  101. package/dist/state.d.ts.map +1 -0
  102. package/dist/{services/state.js → state.js} +28 -138
  103. package/dist/state.js.map +1 -0
  104. package/dist/types.d.ts +69 -258
  105. package/dist/types.d.ts.map +1 -1
  106. package/dist/types.js.map +1 -1
  107. package/dist/websocket.d.ts +15 -0
  108. package/dist/websocket.d.ts.map +1 -0
  109. package/dist/websocket.js +16 -0
  110. package/dist/websocket.js.map +1 -0
  111. package/dist/wire.d.ts +216 -0
  112. package/dist/wire.d.ts.map +1 -0
  113. package/dist/wire.js +165 -0
  114. package/dist/wire.js.map +1 -0
  115. package/docs/guide.md +814 -0
  116. package/docs/spec.md +288 -0
  117. package/docs/tutorial.md +931 -0
  118. package/package.json +14 -10
  119. package/src/delta/README.md +5 -3
  120. package/dist/api.d.ts +0 -20
  121. package/dist/api.d.ts.map +0 -1
  122. package/dist/api.js +0 -77
  123. package/dist/api.js.map +0 -1
  124. package/dist/bundler.d.ts +0 -6
  125. package/dist/bundler.d.ts.map +0 -1
  126. package/dist/bundler.js +0 -3
  127. package/dist/bundler.js.map +0 -1
  128. package/dist/facets/host.d.ts +0 -12
  129. package/dist/facets/host.d.ts.map +0 -1
  130. package/dist/facets/host.js +0 -763
  131. package/dist/facets/host.js.map +0 -1
  132. package/dist/facets/loader.d.ts +0 -3
  133. package/dist/facets/loader.d.ts.map +0 -1
  134. package/dist/facets/loader.js +0 -5
  135. package/dist/facets/loader.js.map +0 -1
  136. package/dist/node/bundle-loader.d.ts +0 -30
  137. package/dist/node/bundle-loader.d.ts.map +0 -1
  138. package/dist/node/bundle-loader.js +0 -377
  139. package/dist/node/bundle-loader.js.map +0 -1
  140. package/dist/node/bundle.d.ts +0 -26
  141. package/dist/node/bundle.d.ts.map +0 -1
  142. package/dist/node/bundle.js +0 -183
  143. package/dist/node/bundle.js.map +0 -1
  144. package/dist/node/manifest.d.ts +0 -36
  145. package/dist/node/manifest.d.ts.map +0 -1
  146. package/dist/node/manifest.js +0 -6
  147. package/dist/node/manifest.js.map +0 -1
  148. package/dist/node/package.d.ts +0 -15
  149. package/dist/node/package.d.ts.map +0 -1
  150. package/dist/node/package.js +0 -199
  151. package/dist/node/package.js.map +0 -1
  152. package/dist/services/consumer.d.ts +0 -11
  153. package/dist/services/consumer.d.ts.map +0 -1
  154. package/dist/services/consumer.js +0 -585
  155. package/dist/services/consumer.js.map +0 -1
  156. package/dist/services/errors.d.ts +0 -8
  157. package/dist/services/errors.d.ts.map +0 -1
  158. package/dist/services/errors.js +0 -22
  159. package/dist/services/errors.js.map +0 -1
  160. package/dist/services/handle.d.ts +0 -15
  161. package/dist/services/handle.d.ts.map +0 -1
  162. package/dist/services/handle.js +0 -101
  163. package/dist/services/handle.js.map +0 -1
  164. package/dist/services/instances.d.ts +0 -26
  165. package/dist/services/instances.d.ts.map +0 -1
  166. package/dist/services/instances.js +0 -140
  167. package/dist/services/instances.js.map +0 -1
  168. package/dist/services/loopback.d.ts +0 -5
  169. package/dist/services/loopback.d.ts.map +0 -1
  170. package/dist/services/loopback.js +0 -15
  171. package/dist/services/loopback.js.map +0 -1
  172. package/dist/services/provider.d.ts +0 -37
  173. package/dist/services/provider.d.ts.map +0 -1
  174. package/dist/services/provider.js +0 -521
  175. package/dist/services/provider.js.map +0 -1
  176. package/dist/services/state-codec.d.ts +0 -15
  177. package/dist/services/state-codec.d.ts.map +0 -1
  178. package/dist/services/state-codec.js +0 -133
  179. package/dist/services/state-codec.js.map +0 -1
  180. package/dist/services/state-internals.d.ts +0 -13
  181. package/dist/services/state-internals.d.ts.map +0 -1
  182. package/dist/services/state-internals.js +0 -10
  183. package/dist/services/state-internals.js.map +0 -1
  184. package/dist/services/state.d.ts +0 -28
  185. package/dist/services/state.d.ts.map +0 -1
  186. package/dist/services/state.js.map +0 -1
  187. package/dist/services/wire.d.ts +0 -63
  188. package/dist/services/wire.d.ts.map +0 -1
  189. package/dist/services/wire.js +0 -186
  190. package/dist/services/wire.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle-loader.js","sourceRoot":"","sources":["../../src/node/bundle-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EACN,4BAA4B,EAC5B,oCAAoC,EACpC,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,GAI1B,MAAM,eAAe,CAAC;AAyBvB,2DAA2D;AAC3D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAkB;IAC/D,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACJ,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,gBA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,CAAC;YACvC,IAAI,OAAO,SAAS,CAAC,SAAS,KAAK,QAAQ;gBAC1C,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,4BAA4B,CAAC,CAAC;YACzE,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,IAAI,aAAa,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7B,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,eAAe;YACf,GAAG,CAAC,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC;SAChF,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,mBAAmB;QAC3B,aAAa,EAAE,2BAA2B;QAC1C,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACrB,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE;YACnB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAChF,CAAC;QACF,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;KAC/B,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { compileFunction } from \"node:vm\";\nimport type { Facet, FacetLoader, LoadedFacets } from \"../types.ts\";\nimport {\n\tFACET_BUNDLE_ARTIFACT_FORMAT,\n\tFACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\tFACET_BUNDLE_FORMAT,\n\tFACET_BUNDLE_FORMAT_VERSION,\n\tFACET_BUNDLE_MANIFEST_FILE,\n\ttype FacetBundleArtifact,\n\ttype FacetBundleEntry,\n\ttype FacetBundleManifest,\n} from \"./manifest.ts\";\n\nexport type FacetBundleExternalResolver = (specifier: string) => string | URL | undefined;\n\nexport interface FacetBundleLoaderOptions {\n\treadonly manifestPath: string | URL;\n\treadonly entry: string;\n\t/** Verify the entry's SHA-256 integrity before evaluating it. Defaults to true. */\n\treadonly verifyIntegrity?: boolean;\n\t/** Resolve host-provided external imports when the bundle is outside the host's package tree. */\n\treadonly resolveExternal?: FacetBundleExternalResolver;\n}\n\nexport interface FacetBundleArtifactLoaderOptions {\n\treadonly artifact: unknown;\n\t/** Resolve host-provided external imports against the receiving application. */\n\treadonly resolveExternal?: FacetBundleExternalResolver;\n\t/** Parent directory for materialized module generations. Defaults to the operating system temp directory. */\n\treadonly temporaryDirectory?: string;\n}\n\ninterface CommonJsModule {\n\texports: unknown;\n}\n\n/** Read and validate a versioned facet bundle manifest. */\nexport async function readFacetBundleManifest(path: string | URL): Promise<FacetBundleManifest> {\n\tconst manifestPath = toFilePath(path);\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\t} catch (error) {\n\t\tthrow new Error(`Could not read facet bundle manifest ${manifestPath}`, { cause: error });\n\t}\n\treturn validateManifest(parsed, manifestPath);\n}\n\n/** Read and verify one transportable entry from a facet bundle on disk. */\nexport async function readFacetBundleArtifact(options: {\n\treadonly manifestPath: string | URL;\n\treadonly entry: string;\n}): Promise<FacetBundleArtifact> {\n\tif (options.entry.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\tconst manifestPath = toFilePath(options.manifestPath);\n\tconst manifest = await readFacetBundleManifest(manifestPath);\n\tconst entry = manifest.entries[options.entry];\n\tif (entry === undefined) throw new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);\n\tconst modulePath = resolveBundleFile(manifestPath, entry.file, \"entry\");\n\tconst source = await readFile(modulePath, \"utf8\");\n\tverifySource(source, entry);\n\tconst sourceMapContents =\n\t\tentry.sourceMap === undefined\n\t\t\t? undefined\n\t\t\t: await readFile(resolveBundleFile(manifestPath, entry.sourceMap, \"source map\"), \"utf8\");\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_ARTIFACT_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\t\tplugin: manifest.plugin,\n\t\tentryName: options.entry,\n\t\tentry,\n\t\tsource,\n\t\t...(sourceMapContents === undefined ? {} : { sourceMapContents }),\n\t});\n}\n\n/** Materialize a transported artifact and create a fresh VM-compiled CommonJS generation for each load. */\nexport function createFacetBundleArtifactLoader(options: FacetBundleArtifactLoaderOptions): FacetLoader {\n\tconst artifact = validateArtifact(options.artifact);\n\tconst temporaryParent = resolve(options.temporaryDirectory ?? tmpdir());\n\treturn {\n\t\tasync load(): Promise<LoadedFacets> {\n\t\t\tawait mkdir(temporaryParent, { recursive: true });\n\t\t\tconst directory = await mkdtemp(join(temporaryParent, \"chord-facet-\"));\n\t\t\ttry {\n\t\t\t\tawait materializeArtifact(directory, artifact);\n\t\t\t\tconst loaded = await createFacetBundleLoader({\n\t\t\t\t\tmanifestPath: join(directory, FACET_BUNDLE_MANIFEST_FILE),\n\t\t\t\t\tentry: artifact.entryName,\n\t\t\t\t\tresolveExternal: options.resolveExternal,\n\t\t\t\t}).load();\n\t\t\t\tlet disposed = false;\n\t\t\t\treturn {\n\t\t\t\t\tget facets() {\n\t\t\t\t\t\treturn loaded.facets;\n\t\t\t\t\t},\n\t\t\t\t\tasync dispose() {\n\t\t\t\t\t\tif (disposed) return;\n\t\t\t\t\t\tdisposed = true;\n\t\t\t\t\t\tconst errors: unknown[] = [];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait loaded.dispose();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait rm(directory, { force: true, recursive: true });\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (errors.length === 1) throw errors[0];\n\t\t\t\t\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose facet bundle artifact\");\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait rm(directory, { force: true, recursive: true });\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tthrow new AggregateError([error, cleanupError], \"Facet bundle artifact loading and cleanup failed\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n\n/** Create a reusable loader for one opaque entry in a facet bundle manifest. */\nexport function createFacetBundleLoader(options: FacetBundleLoaderOptions): FacetLoader {\n\tif (options.entry.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\tconst manifestPath = toFilePath(options.manifestPath);\n\treturn {\n\t\tasync load(): Promise<LoadedFacets> {\n\t\t\tconst manifest = await readFacetBundleManifest(manifestPath);\n\t\t\tconst entry = manifest.entries[options.entry];\n\t\t\tif (entry === undefined) {\n\t\t\t\tthrow new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);\n\t\t\t}\n\t\t\tconst modulePath = resolveBundleFile(manifestPath, entry.file, \"entry\");\n\t\t\ttry {\n\t\t\t\tconst source = await readFile(modulePath, \"utf8\");\n\t\t\t\tif (options.verifyIntegrity !== false) verifySource(source, entry);\n\t\t\t\tconst exported = executeCommonJsModule(source, modulePath, entry.externalImports, options.resolveExternal);\n\t\t\t\tlet facets = facetsFromModule(exported, manifest.plugin.id, options.entry);\n\t\t\t\tlet disposed = false;\n\t\t\t\treturn {\n\t\t\t\t\tget facets() {\n\t\t\t\t\t\treturn facets;\n\t\t\t\t\t},\n\t\t\t\t\tasync dispose() {\n\t\t\t\t\t\tif (disposed) return;\n\t\t\t\t\t\tdisposed = true;\n\t\t\t\t\t\tfacets = Object.freeze([]);\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst detail = error instanceof Error ? `: ${error.message}` : \"\";\n\t\t\t\tthrow new Error(`Could not load facet bundle entry ${manifest.plugin.id}/${options.entry}${detail}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n\nfunction executeCommonJsModule(\n\tsource: string,\n\tmodulePath: string,\n\texternalImports: readonly string[],\n\tresolver?: FacetBundleExternalResolver,\n): unknown {\n\tconst requireFromModule = createRequire(modulePath);\n\tconst externalTargets = new Map<string, string>();\n\tfor (const specifier of externalImports) {\n\t\tif (!isBuiltin(specifier)) validatePackageSpecifier(specifier);\n\t\texternalTargets.set(specifier, toRequireSpecifier(resolveExternalTarget(specifier, resolver)));\n\t}\n\tconst targetFor = (specifier: string): string => {\n\t\tconst target = externalTargets.get(specifier);\n\t\tif (target === undefined) throw new Error(`Facet bundle required undeclared external import: ${specifier}`);\n\t\treturn target;\n\t};\n\tconst requireExternal = Object.assign((specifier: string): unknown => requireFromModule(targetFor(specifier)), {\n\t\tresolve: (specifier: string): string => requireFromModule.resolve(targetFor(specifier)),\n\t});\n\tconst commonJsModule: CommonJsModule = { exports: Object.create(null) };\n\tconst compiled = compileFunction(source, [\"exports\", \"require\", \"module\", \"__filename\", \"__dirname\"], {\n\t\tfilename: modulePath,\n\t});\n\tReflect.apply(compiled, commonJsModule.exports, [\n\t\tcommonJsModule.exports,\n\t\trequireExternal,\n\t\tcommonJsModule,\n\t\tmodulePath,\n\t\tdirname(modulePath),\n\t]);\n\treturn commonJsModule.exports;\n}\n\nfunction toRequireSpecifier(target: string): string {\n\tif (isAbsolute(target) || isBuiltin(target)) return target;\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(target);\n\t} catch {\n\t\treturn target;\n\t}\n\tif (url.protocol === \"file:\") return fileURLToPath(url);\n\tif (url.protocol === \"node:\") return url.href;\n\tthrow new Error(`Facet bundle external target must be a file, package, or built-in module: ${target}`);\n}\n\nfunction toFilePath(path: string | URL): string {\n\tif (typeof path === \"string\") return resolve(path);\n\tif (path.protocol !== \"file:\") throw new TypeError(`Facet bundle manifest must be a file URL, not ${path.protocol}`);\n\treturn fileURLToPath(path);\n}\n\nfunction resolveBundleFile(manifestPath: string, file: string, label: string): string {\n\tif (file.length === 0 || isAbsolute(file) || basename(file) !== file || file === \".\" || file === \"..\") {\n\t\tthrow new Error(`Facet bundle ${label} must be a filename relative to its manifest`);\n\t}\n\treturn resolve(dirname(manifestPath), file);\n}\n\nfunction verifySource(source: string, entry: FacetBundleEntry): void {\n\tconst expected = parseIntegrity(entry.integrity);\n\tconst actual = createHash(\"sha256\").update(source, \"utf8\").digest(\"base64\");\n\tif (actual !== expected) throw new Error(`Facet bundle integrity check failed for ${entry.file}`);\n}\n\nfunction parseIntegrity(integrity: string): string {\n\tconst prefix = \"sha256-\";\n\tif (!integrity.startsWith(prefix) || integrity.length === prefix.length) {\n\t\tthrow new Error(\"Facet bundle entry has an invalid SHA-256 integrity value\");\n\t}\n\treturn integrity.slice(prefix.length);\n}\n\nfunction facetsFromModule(imported: unknown, pluginId: string, entryName: string): readonly Facet[] {\n\tif (!isRecord(imported)) throw new Error(`Facet bundle entry ${pluginId}/${entryName} did not export a module`);\n\tconst exported = imported.default;\n\tconst candidates: readonly unknown[] = Array.isArray(exported) ? (exported as readonly unknown[]) : [exported];\n\tif (candidates.length === 0) {\n\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} exported no facets`);\n\t}\n\tconst facets: Facet[] = [];\n\tfor (const candidate of candidates) {\n\t\tif (!isRecord(candidate) || typeof candidate.id !== \"string\" || candidate.id.length === 0) {\n\t\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} has a facet with an invalid ID`);\n\t\t}\n\t\tif (typeof candidate.setup !== \"function\") {\n\t\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} facet ${candidate.id} has no setup function`);\n\t\t}\n\t\tfacets.push(candidate as unknown as Facet);\n\t}\n\tconst ids = facets.map(({ id }) => id);\n\tif (new Set(ids).size !== ids.length) {\n\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} exports duplicate facet IDs`);\n\t}\n\treturn Object.freeze(facets);\n}\n\nfunction validateArtifact(value: unknown): FacetBundleArtifact {\n\tif (\n\t\t!isRecord(value) ||\n\t\tvalue.format !== FACET_BUNDLE_ARTIFACT_FORMAT ||\n\t\tvalue.formatVersion !== FACET_BUNDLE_ARTIFACT_FORMAT_VERSION ||\n\t\ttypeof value.entryName !== \"string\" ||\n\t\tvalue.entryName.length === 0 ||\n\t\ttypeof value.source !== \"string\"\n\t) {\n\t\tthrow new Error(\"Invalid facet bundle artifact\");\n\t}\n\tconst manifest = validateManifest(\n\t\t{\n\t\t\tformat: FACET_BUNDLE_FORMAT,\n\t\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\t\tplugin: value.plugin,\n\t\t\tentries: { [value.entryName]: value.entry },\n\t\t},\n\t\t\"facet bundle artifact\",\n\t);\n\tconst entry = manifest.entries[value.entryName]!;\n\tif (entry.sourceMap === undefined) {\n\t\tif (value.sourceMapContents !== undefined) {\n\t\t\tthrow new Error(\"Facet bundle artifact has source map contents without a source map\");\n\t\t}\n\t} else if (typeof value.sourceMapContents !== \"string\") {\n\t\tthrow new Error(\"Facet bundle artifact is missing its source map contents\");\n\t}\n\tverifySource(value.source, entry);\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_ARTIFACT_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\t\tplugin: manifest.plugin,\n\t\tentryName: value.entryName,\n\t\tentry,\n\t\tsource: value.source,\n\t\t...(value.sourceMapContents === undefined ? {} : { sourceMapContents: value.sourceMapContents }),\n\t});\n}\n\nasync function materializeArtifact(directory: string, artifact: FacetBundleArtifact): Promise<void> {\n\tconst manifest: FacetBundleManifest = {\n\t\tformat: FACET_BUNDLE_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\tplugin: artifact.plugin,\n\t\tentries: { [artifact.entryName]: artifact.entry },\n\t};\n\tawait Promise.all([\n\t\twriteFile(join(directory, artifact.entry.file), artifact.source, \"utf8\"),\n\t\twriteFile(join(directory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`, \"utf8\"),\n\t\t...(artifact.entry.sourceMap === undefined\n\t\t\t? []\n\t\t\t: [writeFile(join(directory, artifact.entry.sourceMap), artifact.sourceMapContents!, \"utf8\")]),\n\t]);\n}\n\nfunction resolveExternalTarget(specifier: string, resolver?: FacetBundleExternalResolver): string {\n\tconst resolved = resolver?.(specifier);\n\tif (resolved !== undefined) return typeof resolved === \"string\" ? resolved : resolved.href;\n\tconst extension = import.meta.url.endsWith(\".ts\") ? \"ts\" : \"js\";\n\tif (specifier === \"@earendil-works/chord\") return new URL(`../index.${extension}`, import.meta.url).href;\n\tif (specifier === \"@earendil-works/chord/context\") {\n\t\treturn new URL(`../context/index.${extension}`, import.meta.url).href;\n\t}\n\tif (specifier === \"@earendil-works/chord/node\") return new URL(`../node.${extension}`, import.meta.url).href;\n\treturn import.meta.resolve(specifier);\n}\n\nfunction validatePackageSpecifier(specifier: string): void {\n\tconst segments = specifier.split(\"/\");\n\tconst packageParts = specifier.startsWith(\"@\") ? 2 : 1;\n\tif (\n\t\tspecifier.startsWith(\".\") ||\n\t\tspecifier.startsWith(\"/\") ||\n\t\tspecifier.startsWith(\"#\") ||\n\t\tspecifier.includes(\":\") ||\n\t\tspecifier.includes(\"\\\\\") ||\n\t\tsegments.length < packageParts ||\n\t\tsegments.some((part) => part.length === 0 || part === \".\" || part === \"..\")\n\t) {\n\t\tthrow new Error(`Facet bundle artifact has an unsupported external import: ${specifier}`);\n\t}\n}\n\nfunction validateManifest(value: unknown, path: string): FacetBundleManifest {\n\tif (!isRecord(value) || value.format !== FACET_BUNDLE_FORMAT) {\n\t\tthrow new Error(`Invalid facet bundle manifest format in ${path}`);\n\t}\n\tif (value.formatVersion !== FACET_BUNDLE_FORMAT_VERSION) {\n\t\tthrow new Error(`Unsupported facet bundle manifest version in ${path}: ${String(value.formatVersion)}`);\n\t}\n\tif (!isRecord(value.plugin) || typeof value.plugin.id !== \"string\" || value.plugin.id.length === 0) {\n\t\tthrow new Error(`Facet bundle manifest has an invalid plugin identity in ${path}`);\n\t}\n\tif (\n\t\tvalue.plugin.version !== undefined &&\n\t\t(typeof value.plugin.version !== \"string\" || value.plugin.version.length === 0)\n\t) {\n\t\tthrow new Error(`Facet bundle manifest has an invalid plugin version in ${path}`);\n\t}\n\tif (!isRecord(value.entries) || Object.keys(value.entries).length === 0) {\n\t\tthrow new Error(`Facet bundle manifest has no entries in ${path}`);\n\t}\n\tconst entries: Record<string, FacetBundleEntry> = {};\n\tfor (const [name, candidate] of Object.entries(value.entries)) {\n\t\tif (name.length === 0 || !isRecord(candidate)) {\n\t\t\tthrow new Error(`Facet bundle manifest has an invalid entry in ${path}`);\n\t\t}\n\t\tif (typeof candidate.file !== \"string\") throw new Error(`Facet bundle entry ${name} has no file`);\n\t\tresolveBundleFile(path, candidate.file, `entry ${name}`);\n\t\tif (typeof candidate.integrity !== \"string\") throw new Error(`Facet bundle entry ${name} has no integrity`);\n\t\tparseIntegrity(candidate.integrity);\n\t\tif (\n\t\t\t!Array.isArray(candidate.externalImports) ||\n\t\t\tcandidate.externalImports.some((item) => typeof item !== \"string\")\n\t\t) {\n\t\t\tthrow new Error(`Facet bundle entry ${name} has invalid external imports`);\n\t\t}\n\t\tconst externalImports = Object.freeze([...(candidate.externalImports as readonly string[])]);\n\t\tif (new Set(externalImports).size !== externalImports.length) {\n\t\t\tthrow new Error(`Facet bundle entry ${name} has duplicate external imports`);\n\t\t}\n\t\tif (candidate.sourceMap !== undefined) {\n\t\t\tif (typeof candidate.sourceMap !== \"string\")\n\t\t\t\tthrow new Error(`Facet bundle entry ${name} has an invalid source map`);\n\t\t\tresolveBundleFile(path, candidate.sourceMap, `entry ${name} source map`);\n\t\t}\n\t\tentries[name] = Object.freeze({\n\t\t\tfile: candidate.file,\n\t\t\tintegrity: candidate.integrity,\n\t\t\texternalImports,\n\t\t\t...(candidate.sourceMap === undefined ? {} : { sourceMap: candidate.sourceMap }),\n\t\t});\n\t}\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\tplugin: Object.freeze({\n\t\t\tid: value.plugin.id,\n\t\t\t...(value.plugin.version === undefined ? {} : { version: value.plugin.version }),\n\t\t}),\n\t\tentries: Object.freeze(entries),\n\t});\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
@@ -1,26 +0,0 @@
1
- import { type FacetBundleManifest } from "./manifest.ts";
2
- export type FacetBundlePlatform = "node" | "browser" | "neutral";
3
- export interface BundleFacetsOptions {
4
- readonly plugin: {
5
- readonly id: string;
6
- readonly version?: string;
7
- };
8
- /** Opaque application-selected entry names mapped to TypeScript or JavaScript source files. */
9
- readonly entries: Readonly<Record<string, string>>;
10
- readonly outdir: string;
11
- readonly workingDirectory?: string;
12
- /** Additional package imports intentionally left for the loading application to resolve. */
13
- readonly external?: readonly string[];
14
- readonly sourceMap?: boolean;
15
- readonly minify?: boolean;
16
- readonly define?: Readonly<Record<string, string>>;
17
- readonly platform?: FacetBundlePlatform;
18
- readonly target?: string | readonly string[];
19
- }
20
- export interface BundleFacetsResult {
21
- readonly manifest: FacetBundleManifest;
22
- readonly manifestPath: string;
23
- }
24
- /** Bundle each opaque facet entry into an independent content-addressed CommonJS file. */
25
- export declare function bundleFacets(options: BundleFacetsOptions): Promise<BundleFacetsResult>;
26
- //# sourceMappingURL=bundle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/node/bundle.ts"],"names":[],"mappings":"AAIA,OAAO,EAKN,KAAK,mBAAmB,EACxB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,MAAM,EAAE;QAChB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,+FAA+F;IAC/F,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IACvC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B;AAED,0FAA0F;AAC1F,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwC5F"}
@@ -1,183 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
3
- import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
4
- import { build } from "esbuild";
5
- import { FACET_BUNDLE_FORMAT, FACET_BUNDLE_FORMAT_VERSION, FACET_BUNDLE_MANIFEST_FILE, } from "./manifest.js";
6
- /** Bundle each opaque facet entry into an independent content-addressed CommonJS file. */
7
- export async function bundleFacets(options) {
8
- validateOptions(options);
9
- const workingDirectory = resolve(options.workingDirectory ?? process.cwd());
10
- const outputDirectory = resolve(workingDirectory, options.outdir);
11
- const outputParent = dirname(outputDirectory);
12
- await mkdir(outputParent, { recursive: true });
13
- const temporaryDirectory = join(outputParent, `.${basename(outputDirectory)}.tmp-${randomUUID()}`);
14
- await mkdir(temporaryDirectory);
15
- try {
16
- const entries = {};
17
- for (const [entryName, source] of Object.entries(options.entries).sort(([left], [right]) => left.localeCompare(right))) {
18
- entries[entryName] = await bundleEntry({
19
- entryName,
20
- source: resolve(workingDirectory, source),
21
- temporaryDirectory,
22
- workingDirectory,
23
- options,
24
- });
25
- }
26
- const manifest = Object.freeze({
27
- format: FACET_BUNDLE_FORMAT,
28
- formatVersion: FACET_BUNDLE_FORMAT_VERSION,
29
- plugin: Object.freeze({
30
- id: options.plugin.id,
31
- ...(options.plugin.version === undefined ? {} : { version: options.plugin.version }),
32
- }),
33
- entries: Object.freeze(entries),
34
- });
35
- await writeFile(join(temporaryDirectory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
36
- await replaceDirectory(temporaryDirectory, outputDirectory);
37
- return Object.freeze({
38
- manifest,
39
- manifestPath: join(outputDirectory, FACET_BUNDLE_MANIFEST_FILE),
40
- });
41
- }
42
- catch (error) {
43
- await rm(temporaryDirectory, { force: true, recursive: true });
44
- throw error;
45
- }
46
- }
47
- async function bundleEntry(input) {
48
- const entryPrefix = `facet-${shortHash(input.entryName)}`;
49
- const requestedPlatform = input.options.platform ?? "node";
50
- const buildOptions = {
51
- absWorkingDir: input.workingDirectory,
52
- banner: { js: '"use strict";' },
53
- bundle: true,
54
- define: input.options.define,
55
- entryNames: `${entryPrefix}-[hash]`,
56
- entryPoints: [input.source],
57
- external: [...new Set(["@earendil-works/chord", "@earendil-works/chord/*", ...(input.options.external ?? [])])],
58
- format: "cjs",
59
- legalComments: "none",
60
- logLevel: "silent",
61
- metafile: true,
62
- minify: input.options.minify ?? false,
63
- outdir: input.temporaryDirectory,
64
- outExtension: { ".js": ".cjs" },
65
- platform: requestedPlatform,
66
- sourcemap: input.options.sourceMap === true ? "external" : false,
67
- supported: { "dynamic-import": false },
68
- target: input.options.target === undefined
69
- ? requestedPlatform === "node"
70
- ? "node22.19"
71
- : "es2022"
72
- : typeof input.options.target === "string"
73
- ? input.options.target
74
- : [...input.options.target],
75
- write: true,
76
- };
77
- let result;
78
- try {
79
- result = await build(buildOptions);
80
- }
81
- catch (error) {
82
- const diagnostics = esbuildMessages(error);
83
- const detail = diagnostics.length === 0 ? "" : `\n${diagnostics.join("\n")}`;
84
- throw new Error(`Could not bundle facet entry ${input.entryName}${detail}`, { cause: error });
85
- }
86
- const metafile = result.metafile;
87
- if (metafile === undefined)
88
- throw new Error(`Facet entry ${input.entryName} produced no build metadata`);
89
- const outputs = Object.entries(metafile.outputs).filter(([path, output]) => output.entryPoint !== undefined && extname(path) === ".cjs");
90
- if (outputs.length !== 1)
91
- throw new Error(`Facet entry ${input.entryName} did not produce exactly one JavaScript file`);
92
- const [outputPath, metadata] = outputs[0];
93
- const absoluteOutputPath = resolve(input.workingDirectory, outputPath);
94
- const file = relative(input.temporaryDirectory, absoluteOutputPath);
95
- if (file.length === 0 || file.startsWith(`..${sep}`) || basename(file) !== file) {
96
- throw new Error(`Facet entry ${input.entryName} produced an invalid output path`);
97
- }
98
- const sourceMap = input.options.sourceMap === true ? `${file}.map` : undefined;
99
- const allowedOutputs = new Set([absoluteOutputPath]);
100
- if (sourceMap !== undefined)
101
- allowedOutputs.add(join(input.temporaryDirectory, sourceMap));
102
- const unexpectedOutputs = Object.keys(metafile.outputs)
103
- .map((path) => resolve(input.workingDirectory, path))
104
- .filter((path) => !allowedOutputs.has(path));
105
- if (unexpectedOutputs.length > 0) {
106
- throw new Error(`Facet entry ${input.entryName} produced files other than its JavaScript bundle and source map`);
107
- }
108
- const contents = await readFile(absoluteOutputPath);
109
- if (sourceMap !== undefined)
110
- await stat(join(input.temporaryDirectory, sourceMap));
111
- return Object.freeze({
112
- file,
113
- integrity: `sha256-${createHash("sha256").update(contents).digest("base64")}`,
114
- externalImports: Object.freeze([...new Set(metadata.imports.filter(({ external }) => external).map(({ path }) => path))].sort()),
115
- ...(sourceMap === undefined ? {} : { sourceMap }),
116
- });
117
- }
118
- function validateOptions(options) {
119
- if (options.plugin.id.length === 0)
120
- throw new TypeError("Facet bundle plugin ID must not be empty");
121
- if (options.plugin.version !== undefined && options.plugin.version.length === 0) {
122
- throw new TypeError("Facet bundle plugin version must not be empty");
123
- }
124
- const entries = Object.entries(options.entries);
125
- if (entries.length === 0)
126
- throw new TypeError("Facet bundle must contain at least one entry");
127
- for (const [name, source] of entries) {
128
- if (name.length === 0)
129
- throw new TypeError("Facet bundle entry name must not be empty");
130
- if (source.length === 0)
131
- throw new TypeError(`Facet bundle entry ${name} must have a source path`);
132
- }
133
- for (const external of options.external ?? []) {
134
- if (external.length === 0)
135
- throw new TypeError("Facet bundle external import must not be empty");
136
- }
137
- }
138
- async function replaceDirectory(temporaryDirectory, outputDirectory) {
139
- const backupDirectory = `${outputDirectory}.old-${randomUUID()}`;
140
- let movedExisting = false;
141
- try {
142
- await rename(outputDirectory, backupDirectory);
143
- movedExisting = true;
144
- }
145
- catch (error) {
146
- if (!isMissingPath(error))
147
- throw error;
148
- }
149
- try {
150
- await rename(temporaryDirectory, outputDirectory);
151
- }
152
- catch (error) {
153
- if (movedExisting)
154
- await rename(backupDirectory, outputDirectory);
155
- throw error;
156
- }
157
- if (movedExisting)
158
- await rm(backupDirectory, { force: true, recursive: true });
159
- }
160
- function shortHash(value) {
161
- return createHash("sha256").update(value).digest("hex").slice(0, 12);
162
- }
163
- function esbuildMessages(error) {
164
- if (!isRecord(error) || !Array.isArray(error.errors))
165
- return [];
166
- return error.errors.flatMap((candidate) => isEsbuildMessage(candidate) ? [formatEsbuildMessage(candidate)] : []);
167
- }
168
- function formatEsbuildMessage(message) {
169
- const location = message.location;
170
- return location === null
171
- ? message.text
172
- : `${location.file}:${location.line}:${location.column + 1}: ${message.text}`;
173
- }
174
- function isEsbuildMessage(value) {
175
- return isRecord(value) && typeof value.text === "string" && (value.location === null || isRecord(value.location));
176
- }
177
- function isMissingPath(error) {
178
- return isRecord(error) && error.code === "ENOENT";
179
- }
180
- function isRecord(value) {
181
- return typeof value === "object" && value !== null && !Array.isArray(value);
182
- }
183
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/node/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAqB,KAAK,EAAgB,MAAM,SAAS,CAAC;AACjE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,CAAC,MAA6B,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CACjE,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CACpE,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAgB;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,OAAO,QAAQ,KAAK,IAAI;QACvB,CAAC,CAAC,OAAO,CAAC,IAAI;QACd,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC;AAChF,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACvC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AACnH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AACnD,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, extname, join, relative, resolve, sep } from \"node:path\";\nimport { type BuildOptions, build, type Message } from \"esbuild\";\nimport {\n\tFACET_BUNDLE_FORMAT,\n\tFACET_BUNDLE_FORMAT_VERSION,\n\tFACET_BUNDLE_MANIFEST_FILE,\n\ttype FacetBundleEntry,\n\ttype FacetBundleManifest,\n} from \"./manifest.ts\";\n\nexport type FacetBundlePlatform = \"node\" | \"browser\" | \"neutral\";\n\nexport interface BundleFacetsOptions {\n\treadonly plugin: {\n\t\treadonly id: string;\n\t\treadonly version?: string;\n\t};\n\t/** Opaque application-selected entry names mapped to TypeScript or JavaScript source files. */\n\treadonly entries: Readonly<Record<string, string>>;\n\treadonly outdir: string;\n\treadonly workingDirectory?: string;\n\t/** Additional package imports intentionally left for the loading application to resolve. */\n\treadonly external?: readonly string[];\n\treadonly sourceMap?: boolean;\n\treadonly minify?: boolean;\n\treadonly define?: Readonly<Record<string, string>>;\n\treadonly platform?: FacetBundlePlatform;\n\treadonly target?: string | readonly string[];\n}\n\nexport interface BundleFacetsResult {\n\treadonly manifest: FacetBundleManifest;\n\treadonly manifestPath: string;\n}\n\n/** Bundle each opaque facet entry into an independent content-addressed CommonJS file. */\nexport async function bundleFacets(options: BundleFacetsOptions): Promise<BundleFacetsResult> {\n\tvalidateOptions(options);\n\tconst workingDirectory = resolve(options.workingDirectory ?? process.cwd());\n\tconst outputDirectory = resolve(workingDirectory, options.outdir);\n\tconst outputParent = dirname(outputDirectory);\n\tawait mkdir(outputParent, { recursive: true });\n\tconst temporaryDirectory = join(outputParent, `.${basename(outputDirectory)}.tmp-${randomUUID()}`);\n\tawait mkdir(temporaryDirectory);\n\ttry {\n\t\tconst entries: Record<string, FacetBundleEntry> = {};\n\t\tfor (const [entryName, source] of Object.entries(options.entries).sort(([left], [right]) =>\n\t\t\tleft.localeCompare(right),\n\t\t)) {\n\t\t\tentries[entryName] = await bundleEntry({\n\t\t\t\tentryName,\n\t\t\t\tsource: resolve(workingDirectory, source),\n\t\t\t\ttemporaryDirectory,\n\t\t\t\tworkingDirectory,\n\t\t\t\toptions,\n\t\t\t});\n\t\t}\n\t\tconst manifest: FacetBundleManifest = Object.freeze({\n\t\t\tformat: FACET_BUNDLE_FORMAT,\n\t\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\t\tplugin: Object.freeze({\n\t\t\t\tid: options.plugin.id,\n\t\t\t\t...(options.plugin.version === undefined ? {} : { version: options.plugin.version }),\n\t\t\t}),\n\t\t\tentries: Object.freeze(entries),\n\t\t});\n\t\tawait writeFile(join(temporaryDirectory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`);\n\t\tawait replaceDirectory(temporaryDirectory, outputDirectory);\n\t\treturn Object.freeze({\n\t\t\tmanifest,\n\t\t\tmanifestPath: join(outputDirectory, FACET_BUNDLE_MANIFEST_FILE),\n\t\t});\n\t} catch (error) {\n\t\tawait rm(temporaryDirectory, { force: true, recursive: true });\n\t\tthrow error;\n\t}\n}\n\nasync function bundleEntry(input: {\n\treadonly entryName: string;\n\treadonly source: string;\n\treadonly temporaryDirectory: string;\n\treadonly workingDirectory: string;\n\treadonly options: BundleFacetsOptions;\n}): Promise<FacetBundleEntry> {\n\tconst entryPrefix = `facet-${shortHash(input.entryName)}`;\n\tconst requestedPlatform = input.options.platform ?? \"node\";\n\tconst buildOptions: BuildOptions = {\n\t\tabsWorkingDir: input.workingDirectory,\n\t\tbanner: { js: '\"use strict\";' },\n\t\tbundle: true,\n\t\tdefine: input.options.define,\n\t\tentryNames: `${entryPrefix}-[hash]`,\n\t\tentryPoints: [input.source],\n\t\texternal: [...new Set([\"@earendil-works/chord\", \"@earendil-works/chord/*\", ...(input.options.external ?? [])])],\n\t\tformat: \"cjs\",\n\t\tlegalComments: \"none\",\n\t\tlogLevel: \"silent\",\n\t\tmetafile: true,\n\t\tminify: input.options.minify ?? false,\n\t\toutdir: input.temporaryDirectory,\n\t\toutExtension: { \".js\": \".cjs\" },\n\t\tplatform: requestedPlatform,\n\t\tsourcemap: input.options.sourceMap === true ? \"external\" : false,\n\t\tsupported: { \"dynamic-import\": false },\n\t\ttarget:\n\t\t\tinput.options.target === undefined\n\t\t\t\t? requestedPlatform === \"node\"\n\t\t\t\t\t? \"node22.19\"\n\t\t\t\t\t: \"es2022\"\n\t\t\t\t: typeof input.options.target === \"string\"\n\t\t\t\t\t? input.options.target\n\t\t\t\t\t: [...input.options.target],\n\t\twrite: true,\n\t};\n\tlet result: Awaited<ReturnType<typeof build>>;\n\ttry {\n\t\tresult = await build(buildOptions);\n\t} catch (error) {\n\t\tconst diagnostics = esbuildMessages(error);\n\t\tconst detail = diagnostics.length === 0 ? \"\" : `\\n${diagnostics.join(\"\\n\")}`;\n\t\tthrow new Error(`Could not bundle facet entry ${input.entryName}${detail}`, { cause: error });\n\t}\n\tconst metafile = result.metafile;\n\tif (metafile === undefined) throw new Error(`Facet entry ${input.entryName} produced no build metadata`);\n\tconst outputs = Object.entries(metafile.outputs).filter(\n\t\t([path, output]) => output.entryPoint !== undefined && extname(path) === \".cjs\",\n\t);\n\tif (outputs.length !== 1)\n\t\tthrow new Error(`Facet entry ${input.entryName} did not produce exactly one JavaScript file`);\n\tconst [outputPath, metadata] = outputs[0]!;\n\tconst absoluteOutputPath = resolve(input.workingDirectory, outputPath);\n\tconst file = relative(input.temporaryDirectory, absoluteOutputPath);\n\tif (file.length === 0 || file.startsWith(`..${sep}`) || basename(file) !== file) {\n\t\tthrow new Error(`Facet entry ${input.entryName} produced an invalid output path`);\n\t}\n\tconst sourceMap = input.options.sourceMap === true ? `${file}.map` : undefined;\n\tconst allowedOutputs = new Set([absoluteOutputPath]);\n\tif (sourceMap !== undefined) allowedOutputs.add(join(input.temporaryDirectory, sourceMap));\n\tconst unexpectedOutputs = Object.keys(metafile.outputs)\n\t\t.map((path) => resolve(input.workingDirectory, path))\n\t\t.filter((path) => !allowedOutputs.has(path));\n\tif (unexpectedOutputs.length > 0) {\n\t\tthrow new Error(`Facet entry ${input.entryName} produced files other than its JavaScript bundle and source map`);\n\t}\n\tconst contents = await readFile(absoluteOutputPath);\n\tif (sourceMap !== undefined) await stat(join(input.temporaryDirectory, sourceMap));\n\treturn Object.freeze({\n\t\tfile,\n\t\tintegrity: `sha256-${createHash(\"sha256\").update(contents).digest(\"base64\")}`,\n\t\texternalImports: Object.freeze(\n\t\t\t[...new Set(metadata.imports.filter(({ external }) => external).map(({ path }) => path))].sort(),\n\t\t),\n\t\t...(sourceMap === undefined ? {} : { sourceMap }),\n\t});\n}\n\nfunction validateOptions(options: BundleFacetsOptions): void {\n\tif (options.plugin.id.length === 0) throw new TypeError(\"Facet bundle plugin ID must not be empty\");\n\tif (options.plugin.version !== undefined && options.plugin.version.length === 0) {\n\t\tthrow new TypeError(\"Facet bundle plugin version must not be empty\");\n\t}\n\tconst entries = Object.entries(options.entries);\n\tif (entries.length === 0) throw new TypeError(\"Facet bundle must contain at least one entry\");\n\tfor (const [name, source] of entries) {\n\t\tif (name.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\t\tif (source.length === 0) throw new TypeError(`Facet bundle entry ${name} must have a source path`);\n\t}\n\tfor (const external of options.external ?? []) {\n\t\tif (external.length === 0) throw new TypeError(\"Facet bundle external import must not be empty\");\n\t}\n}\n\nasync function replaceDirectory(temporaryDirectory: string, outputDirectory: string): Promise<void> {\n\tconst backupDirectory = `${outputDirectory}.old-${randomUUID()}`;\n\tlet movedExisting = false;\n\ttry {\n\t\tawait rename(outputDirectory, backupDirectory);\n\t\tmovedExisting = true;\n\t} catch (error) {\n\t\tif (!isMissingPath(error)) throw error;\n\t}\n\ttry {\n\t\tawait rename(temporaryDirectory, outputDirectory);\n\t} catch (error) {\n\t\tif (movedExisting) await rename(backupDirectory, outputDirectory);\n\t\tthrow error;\n\t}\n\tif (movedExisting) await rm(backupDirectory, { force: true, recursive: true });\n}\n\nfunction shortHash(value: string): string {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\").slice(0, 12);\n}\n\nfunction esbuildMessages(error: unknown): string[] {\n\tif (!isRecord(error) || !Array.isArray(error.errors)) return [];\n\treturn (error.errors as readonly unknown[]).flatMap((candidate) =>\n\t\tisEsbuildMessage(candidate) ? [formatEsbuildMessage(candidate)] : [],\n\t);\n}\n\nfunction formatEsbuildMessage(message: Message): string {\n\tconst location = message.location;\n\treturn location === null\n\t\t? message.text\n\t\t: `${location.file}:${location.line}:${location.column + 1}: ${message.text}`;\n}\n\nfunction isEsbuildMessage(value: unknown): value is Message {\n\treturn isRecord(value) && typeof value.text === \"string\" && (value.location === null || isRecord(value.location));\n}\n\nfunction isMissingPath(error: unknown): boolean {\n\treturn isRecord(error) && error.code === \"ENOENT\";\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
@@ -1,36 +0,0 @@
1
- export declare const FACET_BUNDLE_FORMAT = "chord.facet-bundle";
2
- export declare const FACET_BUNDLE_FORMAT_VERSION = 2;
3
- export declare const FACET_BUNDLE_MANIFEST_FILE = "chord-facets.json";
4
- export declare const FACET_BUNDLE_ARTIFACT_FORMAT = "chord.facet-bundle-artifact";
5
- export declare const FACET_BUNDLE_ARTIFACT_FORMAT_VERSION = 2;
6
- export interface FacetBundleEntry {
7
- /** Content-addressed CommonJS filename relative to the manifest. */
8
- readonly file: string;
9
- /** SHA-256 subresource-integrity value for the JavaScript file. */
10
- readonly integrity: string;
11
- /** Imports intentionally left for the loading application to resolve. */
12
- readonly externalImports: readonly string[];
13
- /** Source map filename relative to the manifest, when emitted. */
14
- readonly sourceMap?: string;
15
- }
16
- export interface FacetBundleManifest {
17
- readonly format: typeof FACET_BUNDLE_FORMAT;
18
- readonly formatVersion: typeof FACET_BUNDLE_FORMAT_VERSION;
19
- readonly plugin: FacetBundlePlugin;
20
- readonly entries: Readonly<Record<string, FacetBundleEntry>>;
21
- }
22
- export interface FacetBundlePlugin {
23
- readonly id: string;
24
- readonly version?: string;
25
- }
26
- /** One self-contained manifest entry suitable for storage or transport to another Node host. */
27
- export interface FacetBundleArtifact {
28
- readonly format: typeof FACET_BUNDLE_ARTIFACT_FORMAT;
29
- readonly formatVersion: typeof FACET_BUNDLE_ARTIFACT_FORMAT_VERSION;
30
- readonly plugin: FacetBundlePlugin;
31
- readonly entryName: string;
32
- readonly entry: FacetBundleEntry;
33
- readonly source: string;
34
- readonly sourceMapContents?: string;
35
- }
36
- //# sourceMappingURL=manifest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/node/manifest.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AACxD,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,eAAO,MAAM,0BAA0B,sBAAsB,CAAC;AAC9D,eAAO,MAAM,4BAA4B,gCAAgC,CAAC;AAC1E,eAAO,MAAM,oCAAoC,IAAI,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC;IAC5C,QAAQ,CAAC,aAAa,EAAE,OAAO,2BAA2B,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,gGAAgG;AAChG,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,4BAA4B,CAAC;IACrD,QAAQ,CAAC,aAAa,EAAE,OAAO,oCAAoC,CAAC;IACpE,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACpC"}
@@ -1,6 +0,0 @@
1
- export const FACET_BUNDLE_FORMAT = "chord.facet-bundle";
2
- export const FACET_BUNDLE_FORMAT_VERSION = 2;
3
- export const FACET_BUNDLE_MANIFEST_FILE = "chord-facets.json";
4
- export const FACET_BUNDLE_ARTIFACT_FORMAT = "chord.facet-bundle-artifact";
5
- export const FACET_BUNDLE_ARTIFACT_FORMAT_VERSION = 2;
6
- //# sourceMappingURL=manifest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/node/manifest.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACxD,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAC9D,MAAM,CAAC,MAAM,4BAA4B,GAAG,6BAA6B,CAAC;AAC1E,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,CAAC","sourcesContent":["export const FACET_BUNDLE_FORMAT = \"chord.facet-bundle\";\nexport const FACET_BUNDLE_FORMAT_VERSION = 2;\nexport const FACET_BUNDLE_MANIFEST_FILE = \"chord-facets.json\";\nexport const FACET_BUNDLE_ARTIFACT_FORMAT = \"chord.facet-bundle-artifact\";\nexport const FACET_BUNDLE_ARTIFACT_FORMAT_VERSION = 2;\n\nexport interface FacetBundleEntry {\n\t/** Content-addressed CommonJS filename relative to the manifest. */\n\treadonly file: string;\n\t/** SHA-256 subresource-integrity value for the JavaScript file. */\n\treadonly integrity: string;\n\t/** Imports intentionally left for the loading application to resolve. */\n\treadonly externalImports: readonly string[];\n\t/** Source map filename relative to the manifest, when emitted. */\n\treadonly sourceMap?: string;\n}\n\nexport interface FacetBundleManifest {\n\treadonly format: typeof FACET_BUNDLE_FORMAT;\n\treadonly formatVersion: typeof FACET_BUNDLE_FORMAT_VERSION;\n\treadonly plugin: FacetBundlePlugin;\n\treadonly entries: Readonly<Record<string, FacetBundleEntry>>;\n}\n\nexport interface FacetBundlePlugin {\n\treadonly id: string;\n\treadonly version?: string;\n}\n\n/** One self-contained manifest entry suitable for storage or transport to another Node host. */\nexport interface FacetBundleArtifact {\n\treadonly format: typeof FACET_BUNDLE_ARTIFACT_FORMAT;\n\treadonly formatVersion: typeof FACET_BUNDLE_ARTIFACT_FORMAT_VERSION;\n\treadonly plugin: FacetBundlePlugin;\n\treadonly entryName: string;\n\treadonly entry: FacetBundleEntry;\n\treadonly source: string;\n\treadonly sourceMapContents?: string;\n}\n"]}
@@ -1,15 +0,0 @@
1
- import { type BundleFacetsResult } from "./bundle.ts";
2
- export interface BundleFacetPackageOptions {
3
- /** Plugin package directory or its package.json path. */
4
- readonly packagePath: string;
5
- readonly outdir: string;
6
- /** Application conventions applied when the corresponding source file exists. */
7
- readonly defaultFacets?: Readonly<Record<string, string>>;
8
- }
9
- export interface BundleFacetPackageResult extends BundleFacetsResult {
10
- readonly packageDirectory: string;
11
- readonly packageJsonPath: string;
12
- }
13
- /** Build a plugin package using package.json metadata and application-provided facet conventions. */
14
- export declare function bundleFacetPackage(options: BundleFacetPackageOptions): Promise<BundleFacetPackageResult>;
15
- //# sourceMappingURL=package.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/node/package.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,kBAAkB,EAAgB,MAAM,aAAa,CAAC;AAEpE,MAAM,WAAW,yBAAyB;IACzC,yDAAyD;IACzD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,wBAAyB,SAAQ,kBAAkB;IACnE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CACjC;AAaD,qGAAqG;AACrG,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAoB9G"}
@@ -1,199 +0,0 @@
1
- import { readFile, realpath, stat } from "node:fs/promises";
2
- import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
- import { bundleFacets } from "./bundle.js";
4
- /** Build a plugin package using package.json metadata and application-provided facet conventions. */
5
- export async function bundleFacetPackage(options) {
6
- const metadata = await readFacetPackageMetadata(options.packagePath);
7
- const entries = await resolveFacetEntries(metadata, options.defaultFacets ?? {});
8
- const external = [...metadata.peerDependencies, ...metadata.external].flatMap((specifier) => [
9
- specifier,
10
- `${specifier}/*`,
11
- ]);
12
- const result = await bundleFacets({
13
- plugin: { id: metadata.name, version: metadata.version },
14
- entries,
15
- outdir: options.outdir,
16
- workingDirectory: metadata.packageDirectory,
17
- external,
18
- sourceMap: metadata.sourceMap,
19
- });
20
- return Object.freeze({
21
- ...result,
22
- packageDirectory: metadata.packageDirectory,
23
- packageJsonPath: metadata.packageJsonPath,
24
- });
25
- }
26
- async function readFacetPackageMetadata(packagePath) {
27
- if (packagePath.length === 0)
28
- throw new TypeError("Facet package path must not be empty");
29
- const candidate = resolve(packagePath);
30
- let packageDirectory;
31
- let packageJsonPath;
32
- let candidateStats;
33
- try {
34
- candidateStats = await stat(candidate);
35
- }
36
- catch (error) {
37
- throw new Error(`Could not access facet package ${candidate}`, { cause: error });
38
- }
39
- if (candidateStats.isDirectory()) {
40
- packageDirectory = await realpath(candidate);
41
- packageJsonPath = join(packageDirectory, "package.json");
42
- }
43
- else if (candidateStats.isFile() && basename(candidate) === "package.json") {
44
- packageJsonPath = await realpath(candidate);
45
- packageDirectory = dirname(packageJsonPath);
46
- }
47
- else {
48
- throw new Error(`Facet package path must name a directory or package.json: ${candidate}`);
49
- }
50
- let parsed;
51
- try {
52
- parsed = JSON.parse(await readFile(packageJsonPath, "utf8"));
53
- }
54
- catch (error) {
55
- throw new Error(`Could not read facet package metadata ${packageJsonPath}`, { cause: error });
56
- }
57
- if (!isRecord(parsed))
58
- throw new Error(`Facet package metadata must be an object: ${packageJsonPath}`);
59
- if (typeof parsed.name !== "string" || parsed.name.length === 0) {
60
- throw new Error(`Facet package must have a non-empty name: ${packageJsonPath}`);
61
- }
62
- if (typeof parsed.version !== "string" || parsed.version.length === 0) {
63
- throw new Error(`Facet package must have a non-empty version: ${packageJsonPath}`);
64
- }
65
- const peerDependencies = parsePeerDependencies(parsed.peerDependencies, packageJsonPath);
66
- const chord = parseChordConfiguration(parsed.chord, packageJsonPath);
67
- return {
68
- packageDirectory,
69
- packageJsonPath,
70
- name: parsed.name,
71
- version: parsed.version,
72
- peerDependencies,
73
- configuredFacets: chord.facets,
74
- external: chord.external,
75
- sourceMap: chord.sourceMap,
76
- };
77
- }
78
- function parsePeerDependencies(value, packageJsonPath) {
79
- if (value === undefined)
80
- return [];
81
- if (!isRecord(value) ||
82
- Object.entries(value).some(([name, version]) => name.length === 0 || typeof version !== "string")) {
83
- throw new Error(`Facet package has invalid peerDependencies: ${packageJsonPath}`);
84
- }
85
- return Object.freeze(Object.keys(value).sort());
86
- }
87
- function parseChordConfiguration(value, packageJsonPath) {
88
- if (value === undefined)
89
- return { facets: Object.freeze({}), external: Object.freeze([]), sourceMap: true };
90
- if (!isRecord(value))
91
- throw new Error(`Facet package chord configuration must be an object: ${packageJsonPath}`);
92
- if (Object.keys(value).some((key) => key !== "facets" && key !== "external" && key !== "sourceMap")) {
93
- throw new Error(`Facet package chord configuration has an unknown field: ${packageJsonPath}`);
94
- }
95
- const facets = {};
96
- if (value.facets !== undefined) {
97
- if (!isRecord(value.facets)) {
98
- throw new Error(`Facet package chord.facets must be an object: ${packageJsonPath}`);
99
- }
100
- for (const [name, source] of Object.entries(value.facets)) {
101
- if (name.length === 0 || (typeof source !== "string" && source !== false) || source === "") {
102
- throw new Error(`Facet package has an invalid chord.facets entry: ${packageJsonPath}`);
103
- }
104
- facets[name] = source;
105
- }
106
- }
107
- let external = [];
108
- if (value.external !== undefined) {
109
- if (!Array.isArray(value.external) ||
110
- value.external.some((specifier) => typeof specifier !== "string" || specifier.length === 0)) {
111
- throw new Error(`Facet package chord.external must contain non-empty strings: ${packageJsonPath}`);
112
- }
113
- external = Object.freeze([...new Set(value.external)].sort());
114
- }
115
- if (value.sourceMap !== undefined && typeof value.sourceMap !== "boolean") {
116
- throw new Error(`Facet package chord.sourceMap must be a boolean: ${packageJsonPath}`);
117
- }
118
- return {
119
- facets: Object.freeze(facets),
120
- external,
121
- sourceMap: value.sourceMap ?? true,
122
- };
123
- }
124
- async function resolveFacetEntries(metadata, defaultFacets) {
125
- const entries = {};
126
- for (const [name, source] of Object.entries(defaultFacets)) {
127
- validateFacetMapping(name, source, "default");
128
- const path = resolvePackageEntry(metadata.packageDirectory, source, name);
129
- try {
130
- const entryStats = await stat(path);
131
- if (!entryStats.isFile())
132
- throw new Error(`Default facet entry ${name} is not a file: ${path}`);
133
- const canonicalPath = await realpath(path);
134
- validateCanonicalPackageEntry(metadata.packageDirectory, canonicalPath, name);
135
- entries[name] = canonicalPath;
136
- }
137
- catch (error) {
138
- if (isMissingPath(error))
139
- continue;
140
- throw error;
141
- }
142
- }
143
- for (const [name, source] of Object.entries(metadata.configuredFacets)) {
144
- if (source === false) {
145
- delete entries[name];
146
- continue;
147
- }
148
- validateFacetMapping(name, source, "configured");
149
- const path = resolvePackageEntry(metadata.packageDirectory, source, name);
150
- let entryStats;
151
- try {
152
- entryStats = await stat(path);
153
- }
154
- catch (error) {
155
- throw new Error(`Could not access configured facet entry ${name}: ${path}`, { cause: error });
156
- }
157
- if (!entryStats.isFile())
158
- throw new Error(`Configured facet entry ${name} is not a file: ${path}`);
159
- const canonicalPath = await realpath(path);
160
- validateCanonicalPackageEntry(metadata.packageDirectory, canonicalPath, name);
161
- entries[name] = canonicalPath;
162
- }
163
- if (Object.keys(entries).length === 0) {
164
- throw new Error(`Facet package ${metadata.name} has no configured or conventional facet entries`);
165
- }
166
- return Object.freeze(entries);
167
- }
168
- function validateFacetMapping(name, source, kind) {
169
- if (name.length === 0)
170
- throw new Error(`Facet package ${kind} entry name must not be empty`);
171
- if (source.length === 0)
172
- throw new Error(`Facet package ${kind} entry ${name} must have a source path`);
173
- }
174
- function resolvePackageEntry(packageDirectory, source, name) {
175
- if (isAbsolute(source))
176
- throw new Error(`Facet package entry ${name} must be relative to the package directory`);
177
- const path = resolve(packageDirectory, source);
178
- const relativePath = relative(packageDirectory, path);
179
- if (relativePath.length === 0 ||
180
- relativePath === ".." ||
181
- relativePath.startsWith(`..${sep}`) ||
182
- isAbsolute(relativePath)) {
183
- throw new Error(`Facet package entry ${name} escapes the package directory`);
184
- }
185
- return path;
186
- }
187
- function validateCanonicalPackageEntry(packageDirectory, path, name) {
188
- const relativePath = relative(packageDirectory, path);
189
- if (relativePath === ".." || relativePath.startsWith(`..${sep}`) || isAbsolute(relativePath)) {
190
- throw new Error(`Facet package entry ${name} resolves outside the package directory`);
191
- }
192
- }
193
- function isMissingPath(error) {
194
- return isRecord(error) && error.code === "ENOENT";
195
- }
196
- function isRecord(value) {
197
- return typeof value === "object" && value !== null && !Array.isArray(value);
198
- }
199
- //# sourceMappingURL=package.js.map