Skip to content

[WIP] Refactor code to use TemplateManager from App container#1669

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/refactor-template-manager-usage
Draft

[WIP] Refactor code to use TemplateManager from App container#1669
Copilot wants to merge 4 commits intomasterfrom
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:

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.

2 participants