Skip to content

Commit 9edc519

Browse files
authored
Merge pull request #16 from mlabs-haskell/jared/postrebuild-package-lock-only-install
Update `package-lock.json` in `postRebuild` phase
2 parents 00b1c7b + 058c0e5 commit 9edc519

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

flake-lang/typescript/flake-typescript.nix

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pkgs.lib.makeExtensible
9898
${pkgs.lib.escapeShellArg dataFolder} \
9999
${pkgs.lib.escapeShellArg dataLinkFarm}
100100
101-
102101
[[ -e ${pkgs.lib.escapeShellArg dataFolder} ]] && \
103102
printf "flake-lang.nix: %s: removing existing \`%s\`\n" \
104103
${pkgs.lib.escapeShellArg name} \
@@ -126,6 +125,7 @@ pkgs.lib.makeExtensible
126125
cd $out
127126
128127
${builtins.concatStringsSep "\n" (builtins.map (dep: ''ln -sf ${pkgs.lib.escapeShellArg dep}/tarballs/* .'') npmExtraDependenciesTransitiveClosure)}
128+
129129
'';
130130

131131
# Shell script to create the dependencies copied in `npmExtraDependenciesTransitiveClosure`.
@@ -272,6 +272,34 @@ pkgs.lib.makeExtensible
272272
# rm package-lock.json
273273
# '';
274274
# ```
275+
# NOTE(jaredponn): Yet another troubling note.. inspection of the
276+
# code generated by `node2nix` makes it call `npm` install (unless
277+
# otherwise specified) just after their `rebuildPhase`.
278+
# Putting this here seems to "tell `npm` the complete picture" of the
279+
# packages it can install, so it won't duplicate the local
280+
# dependencies in the `node_modules` provided by nix multiple times.
281+
# For example, if we have
282+
# - A depends on B
283+
# - B depends on C
284+
# Then, without this, `npm` would create a dependency graph something
285+
# like:
286+
# ```
287+
# A-B-C
288+
# `C
289+
# ```
290+
# instead of the more desirable
291+
# ```
292+
# A-B
293+
# `C
294+
# ```
295+
# Unfortunately, there is no trace of this in the documentation
296+
# anywhere, and we only have some experimental evidence for this.
297+
# Alternatively, we could just set the `dontNpmInstall` flag in
298+
# node2nix, but I'm not sure of the consequences of that...
299+
postRebuild =
300+
''
301+
npm --offline --no-bin-links --ignore-scripts --package-lock-only install
302+
'';
275303
})
276304
;
277305

0 commit comments

Comments
 (0)