-
Notifications
You must be signed in to change notification settings - Fork 21
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
Link transitive dependencies into node_modules #54
Comments
Do you have a minimal reproduction of this problem? |
A bit messy, but this is an use case we want to support (running stuff at build time) which doesn't work nicely yet with let
pkgs = import <nixpkgs> { };
yarn2nix = import (pkgs.fetchFromGitHub {
owner = "Profpatsch";
repo = "yarn2nix";
rev = "2eb5647049bde3301a005e6bc9f9ea330ed0e13d";
sha256 = "0g875g4mhpw9vga1fq89sfwdd0gvnzfnn8y8nkbkcrw059k970rj";
}) { };
nixLib = yarn2nix.nixLib;
packageJson = pkgs.writeText "package.json" ''
{
"name": "test",
"version": "0.1.0",
"devDependencies": {
"parcel-bundler": "^1.12.4"
}
}
'';
yarnLock = pkgs.fetchurl {
url = "https://gist.githubusercontent.com/sternenseemann/a6d2b9a30dd8c4602529459134a7a9b1/raw/147a9a3a88375147fc38bbfeee3ec4206fb35bc9/yarn.lock";
sha256 = "1nsjg0rwm7b785l03wxdi7anhwwlw58l0i3whsvb015aihi35ksr";
};
pkgSrc = pkgs.runCommandLocal "frontend" {} ''
mkdir $out
ln -s ${packageJson} $out/package.json
ln -s ${yarnLock} $out/yarn.lock
cat > $out/index.html <<EOF
<!doctype html>
<html><head><meta charset="utf-8"><title>test</title></head>
<body>
nope
<script src="main.js"></script>
</body>
</html>
EOF
cat > $out/main.js <<EOF
console.log("lol")
EOF
'';
template = nixLib.callPackageJson packageJson {};
lock = nixLib.callYarnLock yarnLock {};
in {
yarn2nixBuild =
let
tpl = template (nixLib.buildNodeDeps lock);
linked = nixLib.linkNodeDeps {
name = tpl.key.name;
dependencies = tpl.nodeBuildInputs;
};
in pkgs.stdenv.mkDerivation {
inherit (tpl) version;
pname = tpl.key.name;
src = pkgSrc;
buildPhase = ''
export PATH="${linked}/.bin:$PATH"
parcel build index.html --out-dir=dist
'';
installPhase = ''
cp dist $out
'';
};
inherit pkgSrc;
} If you run
This is because of a weird traversal
Below are a directory listing of the yarn2nix
yarn
Note that yarn doesn't even use symlinks. I was told that they used to do that, but even symlinking everything into one directory breaks some packages. |
Okay, hm, seems like we might want two flags, then, or just bite the bullet and always copy the complete transitive closure, which makes the whole thing slow. On btrfs the Do you know if yarn links the combined transitive closure of dev and runtime dependencies? Hmm, okay, so I’d propose having two flags
since the symlinking the transitive closure at every stage shouldn’t be too much overhead, whereas actually copying it leads to considerable duplication and makes the build slower than necessary. |
I think so:
Yeah that was roughly my idea, too. |
It seems to me that this function implements the building of |
It seems like we need to link transitive dependencies into the top-level
node_modules
directory because JavaScript's import routines are all kinds of broken.The solution is to implement a simple “link transitive dependencies” subcommand for
node-package-tool
which optionally can copy the dependencies (in case symlinks are a problem for a particular package).What remains to be found out is the precise algorithm yarn uses for building
node_modules
, mainly how we can solve different versions of packages being present at the same level of the dependency tree.The text was updated successfully, but these errors were encountered: