Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap all invocations of npm in node to set the PATH appropriately #123

Merged
merged 2 commits into from
May 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DocumenterVitepress"
uuid = "4710194d-e776-4893-9690-8d956a29c365"
authors = ["Lazaro Alonso <[email protected]>", "Anshul Singhvi <[email protected]>"]
version = "0.0.18"
version = "0.0.19"

[deps]
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
Expand Down
2 changes: 1 addition & 1 deletion src/DocumenterVitepress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module DocumenterVitepress
using Documenter: Documenter, Selectors

using DocStringExtensions
using NodeJS_20_jll: npm
using NodeJS_20_jll: node, npm

const ASSETS = normpath(joinpath(@__DIR__, "..", "assets"))

Expand Down
18 changes: 12 additions & 6 deletions src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,20 @@
end

cd(dirname(builddir)) do
if settings.install_npm || should_remove_package_json
if !isfile(joinpath(dirname(builddir), "package.json"))
cp(joinpath(dirname(@__DIR__), "template", "package.json"), joinpath(dirname(builddir), "package.json"))
should_remove_package_json = true
# NodeJS_20_jll treats `npm` as a `FileProduct`, meaning that it has no associated environment variable
# when interpolating the `npm` command.
# However, `node() do ...` actually uses `withenv` internally, so we can wrap all invocations of `npm` in
# a `node()` block to ensure that the `npm` from the JLL finds the `node` from the JLL.
node(; adjust_PATH = true, adjust_LIBPATH = true) do _
if settings.install_npm || should_remove_package_json
if !isfile(joinpath(dirname(builddir), "package.json"))
cp(joinpath(dirname(@__DIR__), "template", "package.json"), joinpath(dirname(builddir), "package.json"))
should_remove_package_json = true
end
run(`$(npm) install`)
end
run(`$(npm) install`)
run(`$(npm) run docs:build`)
end
run(`$(npm) run docs:build`)
end
catch e
rethrow(e)
Expand Down Expand Up @@ -656,7 +662,7 @@
# Code blocks
function render(io::IO, mime::MIME"text/plain", node::Documenter.MarkdownAST.Node, code::MarkdownAST.CodeBlock, page, doc; kwargs...)
if startswith(code.info, "@")
@warn """

Check warning on line 665 in src/writer.jl

View workflow job for this annotation

GitHub Actions / build

DocumenterVitepress: un-expanded `@doctest` block encountered on page src/code_example.md. The first few lines of code in this node are: ``` julia> 1 + 1 2 ```
DocumenterVitepress: un-expanded `$(code.info)` block encountered on page $(page.source).
The first few lines of code in this node are:
```
Expand Down
Loading