Skip to content

feat(api): expose resolved asset declarations to post-build hooks - #231

Merged
mgks merged 2 commits into
docmd-io:mainfrom
justinTM:feat/post-build-assets
Sep 16, 2026
Merged

mgks merged 2 commits into
docmd-io:mainfrom
justinTM:feat/post-build-assets

Conversation

@justinTM

@justinTM justinTM commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #230.

Why

Post-build integrations can inspect outputDir, but a directory walk cannot
recover external URLs, page conditions, injection position, load priority, or
which template/plugin declared an asset.

DocMD also resolved plugin assets once for copying and again while rendering.
A stateful or asynchronous getAssets() hook could therefore describe one
file to the copier and another to the generated page.

The first consumer is a Google Apps Script packager, but the same seam is
useful for offline archives, embedded viewers, and other non-directory hosts.

What changed

  • Resolve template and plugin declarations once, after onConfigResolved.
  • Reuse the same frozen readonly ResolvedAsset[] for copying, page tags, and
    PostBuildContext.resolvedAssets.
  • Preserve legacy src/dest/location defaults and precedence while making
    the documented path/url/position form work consistently in both copy
    and render stages.
  • Retain provider, condition, priority, position, and tag attributes.
  • Match the public getAssets() type to its existing async runtime support.

On full builds, the one resolution still happens after core/theme/user asset
preparation—the same boundary as the existing first copy-stage call.

flowchart TB
  subgraph CHANGE["The change"]
    direction TB

    subgraph RESOLUTION["Resolve once"]
      direction LR
      DECL["Template and plugin declarations"]:::context
      BUILD["buildSite()"]:::modified
      RESOLVE(["resolveBuildAssets()"])
      ARRAY(["One frozen declaration catalog — not an output manifest"])
      REPEAT["Repeated per-stage resolution"]:::removed

      DECL --> RESOLVE
      BUILD -->|"once, after onConfigResolved"| RESOLVE
      RESOLVE -->|"returns frozen"| ARRAY
      RESOLVE -. "replaces" .-> REPEAT
    end

    subgraph USES["Reuse the same array"]
      direction LR
      COPY["Copy local files"]:::modified
      TAGS["Emit page tags"]:::modified
      POST["Expose to post-build hooks"]:::modified

      COPY ~~~ TAGS ~~~ POST
      ARRAY -->|"copy files"| COPY
      ARRAY -->|"emit page tags"| TAGS
      ARRAY -->|"same array"| POST
    end

    subgraph API["Public API"]
      direction LR
      TYPES["types.ts"]:::modified
      ENTRY["ResolvedAsset"]
      CONTEXT["PostBuildContext.resolvedAssets"]

      TYPES -->|"defines"| ENTRY
      TYPES -->|"exposes"| CONTEXT
    end

    ENTRY -. "describes each item" .-> ARRAY
  end

  subgraph LEGEND["Change key"]
    direction LR
    L_CONTEXT["= Context"]:::context
    L_MODIFIED["~ Modified"]:::modified
    L_NEW["+ New"]:::new
    L_REMOVED["- Removed"]:::removed
    L_CONTEXT ~~~ L_MODIFIED ~~~ L_NEW ~~~ L_REMOVED
  end

  CHANGE ~~~ LEGEND
  class RESOLVE,ARRAY,ENTRY,CONTEXT new

  classDef context fill:#F1F5F9,stroke:#64748B,color:#172033,stroke-width:2px
  classDef modified fill:#FFF4D6,stroke:#9A6700,color:#3D2B00,stroke-width:2px
  classDef new fill:#E6F4EA,stroke:#1E7A3E,color:#103A20,stroke-width:3px
  classDef removed fill:#FDE8E8,stroke:#B42318,color:#4A1712,stroke-width:2px,stroke-dasharray:6 3
  style CHANGE fill:#F8FAFC,stroke:#94A3B8,stroke-width:1px
  style RESOLUTION fill:#FFFFFF,stroke:#CBD5E1,stroke-width:1px
  style USES fill:#FFFFFF,stroke:#CBD5E1,stroke-width:1px
  style API fill:#FFFFFF,stroke:#CBD5E1,stroke-width:1px
  style LEGEND fill:#FFFFFF,stroke:#CBD5E1,stroke-width:1px
Loading

Contract boundary

resolvedAssets describes the plugin and template declarations the current
asset pipeline understands. File entries identify the source and generated-site
path; URL entries identify an uncopied URL/path reference. Both include
effective rendering metadata and declaration provenance.

It is deliberately not a complete output manifest. Core UI, theme, and user
asset directories are copied separately, and post-build hooks can create more
files after this value is assembled. Existing reserved Asset.inline and
Asset.hash fields remain outside the current pipeline and this new view.
Declaration order and duplicates are preserved; consumers must not infer final
tag order or unique output paths from the array.

Integrations should read emitted bytes from outputDir/outputPath, since DocMD
may transform a source while copying it.

Legacy local-file declarations retain their existing defaults and precedence.
The shared resolver also fixes two inconsistencies in the typed contract:
canonical path/url/position declarations now reach both stages, and
location: "none" suppresses URL-only tags as it already did for local assets.

Verification

  • pnpm -r run build
  • DOCMD_TEST_CACHE_OFF=1 node tests/runner.js --only=plugin-assets-pipeline
    — 27 passed, 0 failed
  • env -u NO_COLOR DOCMD_TEST_CACHE_OFF=1 pnpm verify --skip-setup
  • pnpm lint
  • Supplemental fresh-runner, packed-consumer, and network-isolated evidence:
    non-merge proof at c494325e,
    pinned to feature commit 53dd43f7 — all three jobs passed

@justinTM justinTM changed the title feat(api): expose resolved assets to post-build hooks feat(api): expose resolved asset declarations to post-build hooks Sep 15, 2026
mgks added a commit that referenced this pull request Sep 16, 2026
@mgks
mgks merged commit 0b7fb7f into docmd-io:main Sep 16, 2026
@mgks

mgks commented Sep 19, 2026

Copy link
Copy Markdown
Member

Nice catch on the reading time calculation. Thanks for the fix and contribution!

@mgks

mgks commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Hey @justinTM, your commits landed with an email which isn't linked to your GitHub account, so you're not showing up in the repo contributors list – though we absolutely recognise your contribution. If you'd like your profile to show up on docmd's repo page and website, just add that email under GitHub email settings. No rush!

mgks added a commit that referenced this pull request Sep 22, 2026
mgks added a commit that referenced this pull request Sep 22, 2026
feat(api): expose resolved asset declarations to post-build hooks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Expose resolved asset declarations to build integrations

2 participants