chore: Remove Node.js runtime dependencies from docfx tools
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
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
wherecommand (Windows) - it's possible to search
nodecommand on current directory by where command. -
node isprefix string appended bytypecommand (Linux/mac)
So I've reverted code to PATH based search logics.
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?
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.
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?
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).
I've created PR(#10406) to fix a reported problem with the default docfx command.
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!