Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions templates/UmbracoPackageRcl/UmbracoPackage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@
<PackageReference Include="Umbraco.Cms.Web.Website" Version="UMBRACO_VERSION_FROM_TEMPLATE" />
<PackageReference Include="Umbraco.Cms.Web.BackOffice" Version="UMBRACO_VERSION_FROM_TEMPLATE" />
</ItemGroup>

<ItemGroup>
<Content Update="package.json" Pack="False" />
<Content Update="package-lock.json" Pack="False" />
<Content Update="tsconfig.json" Pack="False" />
</ItemGroup>

<Target Name="NpmInstall" AfterTargets="Restore;Build" Inputs="package-lock.json" Outputs="node_modules\.package-lock.json">
<Message Text="Installing NPM packages" Importance="High" />
<Exec Command="npm ci --no-fund --no-audit --prefer-offline" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

npm ci performs a clean install of all the packages, i.e. it wipes out and recreates ./node_modules/ - that shouldn't be necessary to run for every build. The ASP.NET example templates add some conditional logic to only run when /node_modules/ doesn't exist.

https://docs.npmjs.com/cli/v10/commands/npm-ci#description

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Jason! Notice the Inputs and Outputs attributes, which will result in incremental builds, so the commands are only executed when the package-lock.json has changed and/or the one in node_modules is different/doesn't exist yet 👍🏻

This also means that if you update your local repo with changes to this file (e.g. if someone or something else - like dependabot - installed/updated a package), the next dotnet restore/build will automatically ensure your local packages are up-to-date. No need to manually run npm ci anymore!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it shouldn't be enough to run npm install which would make the incremental builds even faster. With modern npm, the discrepancies between the lock file and package file are less critical and you won't end up with a completely different version of a sub-sub-dependency anymore, as was the case of older npm, which spawned the need for the ci command in the first place. Also, if someone for some reason forgot to commit the changed lockfile, the ci command actually fails resulting in the entire build failing. This is not the case with npm install. What do you think?

</Target>

<Target Name="NpmBuild" AfterTargets="Build;NpmInstall">
<Message Text="Executing NPM build script" Importance="High" />
<Exec Command="npm run build" />
</Target>

</Project>
Loading