Upgrading SharePoint Framework (SPFx) Projects with the Office 365 CLI

Office 365 CLI

The Office 365 CLI is a great set of capabilities you can use to interact with Office 365 – which is platform independent. Because it’s written to run under Node.js®, it can run on any operating system. Since PowerShell requires Windows, it’s a handy-dandy toolkit for people on a Mac, for example.

Using the Office 365 CLI, you can manage your Microsoft Office 365 tenant and SharePoint Framework projects on any platform. No matter if you are on Windows, macOS or Linux, using Bash, Cmder or PowerShell, using the Office 365 CLI you can configure Office 365, manage SharePoint Framework projects and build automation scripts.

While the capabilities in the Office 365 CLI are extensive, my favorite capability is spfx project upgrade. Its purpose is simple: to help you upgrade a SharePoint Framework (SPFx) project to the specified version.

The usage is simple, but the work it does for you is not. Basically, it analyses the files in your SPFx project and tells you what you need to do to upgrade to the version you specify.

Today, I wanted to upgrade a project from version 1.7.0 to 1.8.2. I simply typed this in the terminal window…

spfx project upgrade --toVersion 1.8.2 --output md > upgrade-report.md

…and after a few seconds, I had everything I needed to do in the upgrade-report.md file.

I tend to jump down to the Summary section, run whatever is in the Execute script section, which will look something like this:

npm i -SE @microsoft/sp-core-library@1.8.2 @microsoft/sp-lodash-subset@1.8.2 @microsoft/sp-office-ui-fabric-core@1.8.2 @microsoft/sp-webpart-base@1.8.2 @types/react@16.7.22 @types/react-dom@16.8.0 office-ui-fabric-react@6.143.0 npm i -DE @microsoft/sp-build-web@1.8.2 @microsoft/sp-module-interfaces@1.8.2 @microsoft/sp-webpart-workbench@1.8.2 @microsoft/sp-tslint-rules@1.8.2 @microsoft/rush-stack-compiler-2.9@0.7.7

…and then make whatever files edits are required. If you start at the top of the output file, you’ll have a lot more work ahead of you, though if you are interested in all the details it’s a worthwhile learning exercise the first few times.

I’ve found that whenever I upgrade an SPFx project from one version to another, it’s a good idea to delete node_modules and package_lock.json, restart my editor (VS Code these days), and run npm install afresh. You may not always have to do these steps, but if you do, you’re far less likely to have any issues after the upgrade. Far better than having to run npm install more than once, as it takes a while.

Thanks to all the great people who work on this PnP project, including waldekmastykarz, VelinGeorgiev, and many more.

Sharing is caring…

Parker the PnP Porcupine
Parker the PnP Porcupine

from Marc D Anderson’s Blog https://ift.tt/2YMQ1Wc