Skip to content

feat: inject _.canister.name into recipe template context#567

Open
marc0olo wants to merge 6 commits into
mainfrom
feat/inject-icp-canister-name
Open

feat: inject _.canister.name into recipe template context#567
marc0olo wants to merge 6 commits into
mainfrom
feat/inject-icp-canister-name

Conversation

@marc0olo
Copy link
Copy Markdown
Member

@marc0olo marc0olo commented May 26, 2026

Summary

  • Adds {{_.canister.name}} as a built-in recipe variable, automatically injected into every Handlebars recipe template from the canister name in icp.yaml
  • The _ namespace is reserved and cannot be overridden by user-provided configuration: values
  • Works with all Handlebars helpers, e.g. {{ replace "-" "_" _.canister.name }} for Rust WASM artifact filenames
  • Updates docs/concepts/recipes.md and docs/guides/creating-recipes.md to document built-in recipe variables and use {{_.canister.name}} throughout all examples
  • docs/guides/using-recipes.md will be updated separately once the official recipes (@dfinity/rust, @dfinity/motoko) are updated to use {{_.canister.name}} in icp-cli-recipes

@marc0olo marc0olo requested a review from a team as a code owner May 26, 2026 13:11
Comment thread crates/icp/src/lib.rs
Comment thread docs/concepts/recipes.md Outdated
marc0olo added 4 commits May 26, 2026 16:22
Recipes can now use `{{icp.canister_name}}` to reference the canister
name from icp.yaml without repeating it in the configuration block.
The `icp` namespace is reserved and always overrides any user-supplied
value.

Affects the Rust recipe (`{{package}}`) and Motoko recipe (`{{name}}`),
which can switch to `{{icp.canister_name}}` in a follow-up.
Renames the built-in recipe variable namespace from `{{icp.canister_name}}`
to `{{_.canister.name}}` following review feedback to use a more generic,
non-brand-tied reserved prefix and a nested struct for future extensibility.
@marc0olo marc0olo force-pushed the feat/inject-icp-canister-name branch from 17e9e4f to b18bee7 Compare May 26, 2026 14:22
@marc0olo marc0olo requested review from Copilot and raymondk May 26, 2026 14:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a CLI-injected Handlebars template context value for the current canister name so recipes can reference it without duplicating configuration, and updates docs/tests accordingly.

Changes:

  • Extend the recipe resolver interface to accept canister_name and pass it from manifest consolidation.
  • Inject the reserved _ namespace into the Handlebars render context (including _.canister.name) and add coverage for injection/override behavior.
  • Update recipe documentation and examples to use {{_.canister.name}}, and document built-in recipe variables.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/guides/creating-recipes.md Updates examples to use {{_.canister.name}} and adds a “Built-in Recipe Variables” section (contains a namespace wording inconsistency).
docs/concepts/recipes.md Documents built-in _.* variables and reserved _ namespace.
crates/icp/src/project.rs Passes canister name into recipe resolver during manifest consolidation (formatting issue in changed hunk).
crates/icp/src/lib.rs Updates test mock resolver signature to match new Resolve trait.
crates/icp/src/canister/recipe/mod.rs Updates Resolve trait signature to accept canister_name.
crates/icp/src/canister/recipe/handlebars.rs Injects _.canister.name into Handlebars context and adds tests for injection/replace-helper/override behavior (comment/test naming inconsistencies).
CHANGELOG.md Adds unreleased entry documenting {{_.canister.name}} and reserved _ namespace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/icp/src/project.rs
Comment thread crates/icp/src/canister/recipe/handlebars.rs Outdated
Comment thread docs/guides/creating-recipes.md Outdated
Comment thread docs/guides/creating-recipes.md Outdated
Comment thread crates/icp/src/canister/recipe/handlebars.rs Outdated
Comment thread crates/icp/src/canister/recipe/handlebars.rs Outdated
- Fix stale comments in handlebars.rs still referencing icp.* / icp key
- Rename test functions from icp_canister_name_* / icp_namespace_* to
  match the actual _ reserved namespace
- Fix {{#if optimize}} → {{#if shrink}} inconsistency in recipe docs example
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread docs/guides/creating-recipes.md Outdated
Comment thread crates/icp/src/project.rs
Comment thread CHANGELOG.md
Line 151 still referred to the reserved `icp` namespace; update to `_`.
@marc0olo marc0olo changed the title feat: inject icp.canister_name into recipe template context feat: inject \_.canister.name into recipe template context May 26, 2026
@marc0olo marc0olo changed the title feat: inject \_.canister.name into recipe template context feat: inject _.canister.name into recipe template context May 26, 2026
marc0olo added a commit to dfinity/icp-cli-templates that referenced this pull request May 26, 2026
With _.canister.name now injected automatically by icp-cli (see
dfinity/icp-cli#567), the `name` configuration param is no longer
needed in recipe configs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants