Skip to content

refactor: use TemplateManager from App container#1669

Merged
kdinev merged 8 commits into
masterfrom
copilot/refactor-template-manager-usage
May 12, 2026
Merged

refactor: use TemplateManager from App container#1669
kdinev merged 8 commits into
masterfrom
copilot/refactor-template-manager-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

  • Explore codebase and understand all usages of TemplateManager being passed around
  • Update BasePromptSession to get templateManager from App container instead of constructor param
  • Update PromptSession (CLI) to remove constructor param, get from container
  • Update SchematicsPromptSession to remove constructor param, get from container
  • Remove templateManager property from CommandType interface and all command objects (add, build, start, generate, list, upgrade, new, mcp)
  • Update all commands to get templateManager from App.container.get(TEMPLATE_MANAGER) where they use it
  • Update PackageManager.ensureIgniteUISource to accept BaseTemplateManager and remove circular dependency on TemplateManager
  • Clean up cli.ts: remove all xyz.templateManager = templateManager assignments and TODO comment
  • Update ng-schematics entry points (component/index.ts, ng-new/index.ts) to set container before use
  • Update all unit tests to set templateManager in App container instead of assigning to command properties
  • Build and verify: npm run build
  • Run tests: npm run jasmine ✅ (424 specs, 9 pre-existing failures, 0 new failures)
  • Run validation ✅ (CodeQL clean, code review pass)
Original prompt

Context

In packages/cli/lib/cli.ts (line 35-36), there's a TODO comment:

// TODO: Refactor all code to use TemplateManager from the App container:
App.container.set(TEMPLATE_MANAGER, templateManager);

Currently, after setting the template manager in the App container, the code still manually passes it to every command:

newCommand.addChoices(templateManager.getFrameworkIds());
newCommand.templateManager = templateManager;
add.templateManager = templateManager;
build.templateManager = templateManager;
start.templateManager = templateManager;
generate.templateManager = templateManager;
list.templateManager = templateManager;
upgrade.templateManager = templateManager;

And also passes it to PromptSession:

const prompts = new PromptSession(templateManager);

Task

  1. Find all places where a TemplateManager (or its base type/interface) is passed around — as constructor parameters, method parameters, or assigned as properties on commands. This includes:

    • All command objects in packages/cli/lib/commands/
    • PromptSession in packages/cli/lib/PromptSession.ts
    • Any code in packages/igx-templates/ and packages/ng-schematics/ that receives or uses a template manager
    • The schematics collection entry point(s) in packages/ng-schematics/
  2. Replace the pattern of passing/receiving template manager with retrieving it from the App container using App.container.get(TEMPLATE_MANAGER). The TEMPLATE_MANAGER token is exported from @igniteui/cli-core.

  3. Remove the templateManager properties from command objects and constructor parameters where they're no longer needed.

  4. Clean up cli.ts: Remove all the xyz.templateManager = templateManager assignments. Remove the TODO comment. Keep App.container.set(TEMPLATE_MANAGER, templateManager) and newCommand.addChoices(templateManager.getFrameworkIds()) (or refactor addChoices similarly).

  5. Ensure all entry points that need template manager have it initialized correctly:

    • The CLI entry point (cli.ts) already calls App.container.set(TEMPLATE_MANAGER, templateManager) — keep this
    • The ng-schematics collection entry point(s) — ensure they also initialize the container properly before any code tries to get from it
  6. Adjust all tests that mock or pass template manager to commands/sessions — update them to set it in the App container instead.

  7. Build and test: Ensure npm run build and npm run jasmine pass. The monorepo uses tsc for compilation and Jasmine for tests.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: I added the template manager to the App container so all uses can now extract it from there instead of passing it around to each command and/or sub-code. Check all places where a TemplateManager is passed around (could be the base type too) and asses if it should be kept or replaced by a get from the container. Ensure all entry points (including in the igx-schematics collection) that need to use template manager have it initialized correctly and all tests are adjusted. Open a new PR with the changes

Assistant: I've kicked off the coding agent to create a PR for this refactoring. It will trace all usages of TemplateManager being passed around, replace them with App.container.get(TEMPLATE_MANAGER), clean up cli.ts, ensure schematics entry points initialize the container, and adjust tests accordingly. I'll share the PR link once it's ready.

This pull request was created from Copilot chat.

Copilot AI and others added 2 commits April 27, 2026 17:59
…tainer get

Remove templateManager from CommandType interface, BasePromptSession constructor,
PromptSession constructor, SchematicsPromptSession constructor.
All commands and sessions now get templateManager from App.container.get(TEMPLATE_MANAGER).
Clean up cli.ts by removing all manual templateManager assignments and TODO comment.
Ensure ng-schematics entry points set TEMPLATE_MANAGER in container.

Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/34deef7a-062f-44fe-86f9-7eac03eabc8f

Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
Replace all command.templateManager assignments and PromptSession(templateManager)
constructor calls in tests with App.container.set(TEMPLATE_MANAGER, ...) and
App.container.get(TEMPLATE_MANAGER) patterns. Fix container spy interactions
where spyOn(App.container, 'get') needs to handle both TEMPLATE_MANAGER and
other tokens via callFake.

Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/34deef7a-062f-44fe-86f9-7eac03eabc8f

Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
@damyanpetev
Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

Merge origin/master into copilot/refactor-template-manager-usage.
- Take master's updated describe strings, builder functions, and aliases
- Convert new listAllFrameworks() function to use App container pattern
- Convert new list-spec test to use App.container.set(TEMPLATE_MANAGER, ...)
- Fix PromptSession() constructor call in cli.ts fallback handler

Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 28, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 6f8ac64e. Merged master and applied our refactoring pattern to the new code:

  • Updated describe strings, builder functions, and aliases from master
  • Converted the new listAllFrameworks() function in list.ts to use App.container.get(TEMPLATE_MANAGER) instead of command.templateManager
  • Converted the new list-spec test to use App.container.set(TEMPLATE_MANAGER, ...)
  • Fixed PromptSession() constructor call in cli.ts fallback handler (no longer takes args)

Build and tests pass (425 specs, 9 pre-existing failures, 0 new failures).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.google-analytics.com
    • Triggering command: /usr/local/bin/node node packages/cli/bin/execute.js new --help de_modules/.bin/tsx (dns block)
    • Triggering command: /usr/local/bin/node node packages/cli/bin/execute.js config --help (dns block)
    • Triggering command: /usr/local/bin/node node packages/cli/bin/execute.js generate --help sqli�� (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@damyanpetev damyanpetev marked this pull request as ready for review May 11, 2026 12:34
Copilot AI review requested due to automatic review settings May 11, 2026 12:34
Copy link
Copy Markdown
Contributor

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

This PR refactors the CLI and schematics codepaths to stop passing TemplateManager through constructors/properties and instead resolve it from the global App.container via the TEMPLATE_MANAGER token, aligning runtime behavior across CLI commands, prompt sessions, and Angular schematics.

Changes:

  • Updated BasePromptSession, CLI PromptSession, and SchematicsPromptSession to resolve the template manager from App.container rather than constructor injection.
  • Removed templateManager from the CommandType interface and from command objects; updated commands to fetch App.container.get(TEMPLATE_MANAGER) where needed.
  • Updated schematics entry points and unit tests to set TEMPLATE_MANAGER in the container instead of mutating command/session properties.

Reviewed changes

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

Show a summary per file
File Description
spec/unit/upgrade-spec.ts Updates upgrade command unit test to set template manager via App.container.
spec/unit/PromptSession-spec.ts Updates prompt session tests to use container-provided template manager.
spec/unit/new-spec.ts Updates new command tests to use container-resolved template manager.
spec/unit/list-spec.ts Updates list command tests to use container-resolved template manager.
spec/unit/generate-spec.ts Updates generate command tests to use container-resolved template manager.
spec/unit/add-spec.ts Updates add command tests to use container-resolved template manager.
packages/ng-schematics/src/prompt/SchematicsPromptSession.ts Removes constructor injection and relies on BasePromptSession container resolution.
packages/ng-schematics/src/ng-new/index.ts Initializes TEMPLATE_MANAGER in the container before creating the prompt session.
packages/ng-schematics/src/component/index.ts Initializes TEMPLATE_MANAGER in the container before prompt session usage.
packages/core/prompt/BasePromptSession.ts Replaces ctor-injected template manager with a container-backed getter.
packages/core/packages/PackageManager.ts Decouples core from CLI TemplateManager by accepting BaseTemplateManager.
packages/cli/lib/PromptSession.ts Removes template-manager constructor param and stops assigning it into commands.
packages/cli/lib/commands/upgrade.ts Resolves template manager from App.container instead of command.templateManager.
packages/cli/lib/commands/types.ts Removes templateManager from CommandType.
packages/cli/lib/commands/start.ts Drops now-invalid templateManager property from the command literal.
packages/cli/lib/commands/new.ts Resolves template manager from App.container and removes fallback constructor injection into PromptSession.
packages/cli/lib/commands/mcp.ts Drops now-invalid templateManager property from the command literal.
packages/cli/lib/commands/list.ts Resolves template manager from App.container for framework/library access.
packages/cli/lib/commands/generate.ts Resolves template manager from App.container for framework/library access.
packages/cli/lib/commands/build.ts Resolves template manager from App.container for ensureIgniteUISource.
packages/cli/lib/commands/add.ts Resolves template manager from App.container for framework/library access and config updates.
packages/cli/lib/cli.ts Removes per-command template manager assignments; only sets TEMPLATE_MANAGER in the container.

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

Comment thread packages/core/prompt/BasePromptSession.ts
Comment thread spec/unit/PromptSession-spec.ts
Comment thread spec/unit/PromptSession-spec.ts
@damyanpetev damyanpetev requested a review from Copilot May 11, 2026 13:00
@coveralls
Copy link
Copy Markdown

coveralls commented May 11, 2026

Coverage Status

coverage: 86.917% (-0.005%) from 86.922% — copilot/refactor-template-manager-usage into master

Copy link
Copy Markdown
Contributor

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 22 out of 22 changed files in this pull request and generated no new comments.

@damyanpetev damyanpetev requested a review from kdinev May 11, 2026 13:08
@damyanpetev damyanpetev changed the title [WIP] Refactor code to use TemplateManager from App container refactor: use TemplateManager from App container May 11, 2026
@kdinev kdinev merged commit ebdbcb3 into master May 12, 2026
3 checks passed
@kdinev kdinev deleted the copilot/refactor-template-manager-usage branch May 12, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants