Skip to content

Commit cafbb7a

Browse files
authored
Use nodejs path list (#19)
1 parent d071dae commit cafbb7a

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

.github/workflows/Test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
paths-ignore:
1212
- "**.md"
1313

14+
env:
15+
NPM_CONFIG_LOGLEVEL: verbose
16+
1417
jobs:
1518
test:
1619
runs-on: ${{ matrix.os }}

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "PlutoPDF"
22
uuid = "6eb38059-8c05-41f7-8871-5e7e2697ace6"
33
license = "MIT"
44
authors = ["Fons van der Plas", "Connor Burns"]
5-
version = "1.1.0"
5+
version = "1.2.0"
66

77
[deps]
88
DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"

src/setup_build.jl

+30-18
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,46 @@ const node_root_files = (
99
@path(joinpath(dirname(@__DIR__), "node", "package.json")),
1010
)
1111

12-
const npm = !Sys.iswindows() ? NodeJS_20_jll.npm : let
13-
new = "$(NodeJS_20_jll.npm).cmd"
14-
isfile(new) ? new : NodeJS_20_jll.npm
12+
13+
function npm_cmd()
14+
npm = !Sys.iswindows() ? NodeJS_20_jll.npm : let
15+
new = "$(NodeJS_20_jll.npm).cmd"
16+
isfile(new) ? new : NodeJS_20_jll.npm
17+
end
18+
19+
# Add NodeJS PATH to the existing PATH environment variable
20+
path_sep = Sys.iswindows() ? ';' : ':'
21+
path_list = prepend!(split(get(ENV, "PATH", ""), path_sep), NodeJS_20_jll.PATH_list)
22+
path = join(path_list, path_sep)
23+
addenv(`$(npm)`, "PATH" => path)
1524
end
1625

1726
function get_build_dir()
1827
build_node(@get_scratch!("build_dir4"))
1928
end
2029

21-
ci() = get(ENV, "CI", "neetjes") != "neetjes"
30+
const node_build_lock = ReentrantLock()
2231

2332
function build_node(dir)
24-
@info "PlutoPDF: Running npm install in scratch space..."
25-
26-
if dir !== dirname(node_root_files[1])
27-
for f in node_root_files
28-
readwrite(f, joinpath(dir, basename(f)))
33+
lock(node_build_lock) do
34+
npm_cache_dir = @get_scratch!("npm_cache")
35+
cmd = addenv(npm_cmd(), "NPM_CONFIG_CACHE" => npm_cache_dir)
36+
37+
@info "PlutoPDF: Running npm install in scratch space..." npm_version=Text(read(`$(cmd) --version`, String))
38+
39+
if dir != dirname(node_root_files[1])
40+
for f in node_root_files
41+
readwrite(f, joinpath(dir, basename(f)))
42+
end
2943
end
44+
45+
cd(dir) do
46+
run(`$(cmd) install --audit-level=none --no-fund --no-audit`)
47+
end
48+
49+
@info "PlutoPDF: Finished npm install."
50+
dir
3051
end
31-
32-
cd(dir) do
33-
run(`$npm --version`)
34-
run(ci() ? `$npm install --verbose` : `$npm install`)
35-
end
36-
37-
@info "PlutoPDF: Finished npm install."
38-
39-
dir
4052
end
4153

4254
"Like `cp` except we create the file manually (to fix permission issues). (It's not plagiarism if you use this function to copy homework.)"

0 commit comments

Comments
 (0)