fix(upgrade-packages): detect framework & run without ignite-ui-cli.json#1690
Conversation
…ework from package.json Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/836f72b0-5436-41af-a5f3-4dba187bbe1a Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/836f72b0-5436-41af-a5f3-4dba187bbe1a Co-authored-by: kdinev <1472513+kdinev@users.noreply.github.com>
| if (!framework) { | ||
| const detected = detectFrameworkFromPackageJson(); | ||
| if (!detected) { | ||
| Util.log("Unable to determine the project framework. " + |
There was a problem hiding this comment.
@copilot Can use Util.warn then to put this in the right standard io (can keep the explicit color) and you will need to spy that for the message test
There was a problem hiding this comment.
Switched to Util.warn and updated the test to spy on it. Done in a637180.
Agent-Logs-Url: https://github.com/IgniteUI/igniteui-cli/sessions/39a81310-9882-4de1-94db-8318a994b9d0 Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. 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:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent ig upgrade-packages from crashing when a project has no local ignite-ui-cli.json by safely reading config.project and falling back to framework detection from package.json.
Changes:
- Add optional chaining for
config.projectaccess and fall back todetectFrameworkFromPackageJson()when framework is missing. - Derive a default
projectTypefrom the detected framework via a simple mapping. - Add unit tests covering the “no config” detection path and the “cannot detect framework” warning path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/cli/lib/commands/upgrade.ts |
Adds framework/package.json fallback and derives projectType when config is missing. |
spec/unit/upgrade-spec.ts |
Adds unit tests for framework auto-detection and the warning when detection fails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const config = ProjectConfig.getConfig(); | ||
| const framework = config.project.framework; | ||
| const projectType = config.project.projectType; | ||
| let framework = config.project?.framework; | ||
| let projectType = config.project?.projectType; | ||
|
|
||
| if (!framework) { | ||
| const detected = detectFrameworkFromPackageJson(); | ||
| if (!detected) { | ||
| Util.warn("Unable to determine the project framework. " + | ||
| "Please ensure you are running this command in a project directory with a package.json file, " + | ||
| "or create an ignite-ui-cli.json configuration file.", "yellow"); | ||
| return; |
| const projectLibrary = templateManager.getProjectLibrary(framework, projectType); | ||
| let project: ProjectTemplate; | ||
| if (!config.project.projectTemplate || !projectLibrary.hasProject(config.project.projectTemplate)) { | ||
| if (!config.project?.projectTemplate || !projectLibrary.hasProject(config.project.projectTemplate)) { | ||
| // in case project template is missing from the config we provide backward. | ||
| project = projectLibrary.getProject(projectLibrary.projectIds[0]); | ||
| } else { |
| it("Should auto-detect framework from package.json when config has no project", async () => { | ||
| const config = {} as Config; | ||
| spyOn(ProjectConfig, "getConfig").and.returnValue(config); | ||
| spyOn(detectFrameworkModule, "detectFrameworkFromPackageJson").and.returnValue("react"); | ||
|
|
| angular: "igx-ts", | ||
| react: "igr-ts", | ||
| webcomponents: "igc-ts" | ||
| }; |
There was a problem hiding this comment.
Might be worth to add default project type per framework (bit out of scope), even though those are currently singular IIRC and templateManager.getProjectLibrary will return the first if type is not supplied, so this can possibly even be dropped. Need to check tho.
ig upgrade-packagesthrowsCannot read properties of undefined (reading 'framework')when run in a project withoutignite-ui-cli.json, sinceconfig.projectis undefined when no local config exists.Changes
config.project.frameworkis absent, fall back to the existingdetectFrameworkFromPackageJson()utility to infer the framework frompackage.jsondependenciesconfig.project?.framework,config.project?.projectType, andconfig.project?.projectTemplateangular→igx-ts,react→igr-ts,webcomponents→igc-ts) when not specified in configpackage.jsoncan determine the frameworkWarning
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/usr/local/bin/node node packages/cli/bin/execute.js new --help(dns block)/usr/local/bin/node node packages/cli/bin/execute.js config --help(dns block)/usr/local/bin/node node packages/cli/bin/execute.js generate --help(dns block)If you need me to access, download, or install something from one of these locations, you can either: