docfx icon indicating copy to clipboard operation
docfx copied to clipboard

chore: Remove Node.js runtime dependencies from docfx tools

Open filzrev opened this issue 1 year ago • 1 comments

This PR intended to resolve #9396.

Background

Playwright 1.41 or later supports following environment variables. (It's not documented though)

  • PLAYWRIGHT_NODEJS_PATH
  • PLAYWRIGHT_DRIVER_SEARCH_PATH

So it can remove Node.js runtime from docfx package. Instead. it can use locally installed Node.js runtime instead.

By this changes. docfx packages size can be reduced from 208MB -> 56 MB

BREAKING CHANGES This PR remove Node.js runtime bundles. So it may introduce breaking changes for some users who using docfx without Node.js installation. (e.g. docker image users)

I'll try to fix official docker image later. https://github.com/dotnet/docfx/blob/main/Dockerfile

filzrev avatar Jul 05 '24 00:07 filzrev

When using CommandUtility.ExistCommand helper methods. It need to handle stdout result parse logics. Because of following reasons.

  • On GitHub runner environment multiple node.js installations found by where command (Windows)
  • it's possible to search node command on current directory by where command.
  • node is prefix string appended by type command (Linux/mac)

So I've reverted code to PATH based search logics.

filzrev avatar Jul 05 '24 03:07 filzrev

Hi @yufeih, is it expected that everyone has to install the node.js locally (and on CI) even if we don't use any PDF related feature?

JanVargovsky avatar Nov 18 '24 15:11 JanVargovsky

Node.js installation is required when running following commands.

  • docfx (Default command)
  • docfx pdf

It might be better to modify Prerequisite section of following document.

  • https://github.com/dotnet/docfx/blob/main/docs/index.md?plain=1#L9-L12

I'll try to create PR later.

filzrev avatar Nov 18 '24 19:11 filzrev

I use the default command with "pdf": false in my docfx.json. I run docfx inside docker, image mcr.microsoft.com/dotnet/sdk:8.0-jammy. With 2.78.x, docfx started breaking my builds with

TypeInitializationException: The type initializer for 'Docfx.Pdf.PdfBuilder' 
threw an exception.
     DocfxException: Node.js executable is not found. Try to install Node.js or 
     set the `PLAYWRIGHT_NODEJS_PATH` environment variable.                     
       at void EnsurePlaywrightNodeJsPath() in PlaywrightHelper.cs:25           
       at cctor() in PdfBuilder.cs:53                                           
  at Task CreatePdf(string outputFolder)                                        
  at void <Execute>b__0() in DefaultCommand.cs:53                               
  at int Run(LogOptions options, Action run) in CommandHelper.cs:48             
  at int Execute(CommandContext context, Options options) in DefaultCommand.cs: 
     31                                                                         
  at Task<int> Execute(CommandContext context, CommandSettings settings) in     
     CommandOfT.cs:40                                                           
  at async Task<int> Execute(CommandTree leaf, CommandTree tree, CommandContext 
     context, ITypeResolver resolver, IConfiguration configuration) in          
     CommandExecutor.cs:166

Could it be a possibility to not require Node.js if PDF output is disabled?

georg-jung avatar Nov 19 '24 11:11 georg-jung

Workaround is simply by setting PLAYWRIGHT_DRIVER_SEARCH_PATH or PLAYWRIGHT_NODEJS_PATH to non empty value. For example in CMD:

set PLAYWRIGHT_NODEJS_PATH=anyvalue && docfx

My build then succeeded as it used to. Or install node.js even if it's not required (unless you are using pdf).

JanVargovsky avatar Nov 19 '24 17:11 JanVargovsky

I've created PR(#10406) to fix a reported problem with the default docfx command.

filzrev avatar Nov 19 '24 20:11 filzrev

FWIW in the meantime,

RUN PLAYWRIGHT_NODEJS_PATH="workaround https://github.com/dotnet/docfx/pull/10066#issuecomment-2486269657" docfx tech/docfx.json --disableGitFeatures=true

works in my Dockerfile. Thanks @JanVargovsky and of course @filzrev for the super fast fix!

georg-jung avatar Nov 20 '24 08:11 georg-jung