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

Add Jest to stable 21.11 #25

Merged
merged 3 commits into from
Jan 4, 2022
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
7 changes: 4 additions & 3 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ self: super:
with super.lib;

let
nodePackages = self.callPackage ./pkgs/node-packages { };

override = {
# These packages will hide packages in the top level nixpkgs
swift = self.callPackage ./pkgs/swift { };

# Add our additional node packages
nodePackages = super.nodePackages // self.callPackage ./pkgs/node-packages { };
};
in {
replitPackages = rec {
# Any other packages should go in the replitPackages namespace
jdt-language-server = self.callPackage ./pkgs/jdt-language-server { };
replbox = self.callPackage ./pkgs/replbox { };
jest = nodePackages."jest-cli-23.6.0";
coffeescript = nodePackages.coffeescript;

# The override packages are injected into the replitPackages namespace as
# well so they can all be built together
Expand Down
2 changes: 1 addition & 1 deletion pkgs/node-packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv lib python2 runCommand writeTextFile;
inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
Expand Down
93 changes: 57 additions & 36 deletions pkgs/node-packages/node-env.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file originates from node2nix

{ lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile }:
{ lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript }:

let
# Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
Expand Down Expand Up @@ -40,38 +40,22 @@ let
'';
};

includeDependencies = { dependencies }:
lib.optionalString (dependencies != [ ])
(lib.concatMapStrings
(dependency:
''
# Bundle the dependencies of the package
mkdir -p node_modules
cd node_modules
# Common shell logic
installPackage = writeShellScript "install-package" ''
installPackage() {
local packageName=$1 src=$2

# Only include dependencies if they don't exist. They may also be bundled in the package.
if [ ! -e "${dependency.name}" ]
then
${composePackage dependency}
fi

cd ..
''
)
dependencies);
local strippedName

# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [ ], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
DIR=$(pwd)
local DIR=$PWD
cd $TMPDIR

unpackFile ${src}
unpackFile $src

# Make the base dir in which the target dependency resides first
mkdir -p "$(dirname "$DIR/${packageName}")"
mkdir -p "$(dirname "$DIR/$packageName")"

if [ -f "${src}" ]
if [ -f "$src" ]
then
# Figure out what directory has been unpacked
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
Expand All @@ -81,28 +65,55 @@ let
chmod -R u+w "$packageDir"

# Move the extracted tarball into the output folder
mv "$packageDir" "$DIR/${packageName}"
elif [ -d "${src}" ]
mv "$packageDir" "$DIR/$packageName"
elif [ -d "$src" ]
then
# Get a stripped name (without hash) of the source directory.
# On old nixpkgs it's already set internally.
if [ -z "$strippedName" ]
then
strippedName="$(stripHash ${src})"
strippedName="$(stripHash $src)"
fi

# Restore write permissions to make building work
chmod -R u+w "$strippedName"

# Move the extracted directory into the output folder
mv "$strippedName" "$DIR/${packageName}"
mv "$strippedName" "$DIR/$packageName"
fi

# Unset the stripped name to not confuse the next unpack step
unset strippedName
# Change to the package directory to install dependencies
cd "$DIR/$packageName"
}
'';

# Include the dependencies of the package
cd "$DIR/${packageName}"
# Bundle the dependencies of the package
#
# Only include dependencies if they don't exist. They may also be bundled in the package.
includeDependencies = { dependencies }:
lib.optionalString (dependencies != [ ]) (
''
mkdir -p node_modules
cd node_modules
''
+ (lib.concatMapStrings
(dependency:
''
if [ ! -e "${dependency.name}" ]; then
${composePackage dependency}
fi
''
)
dependencies)
+ ''
cd ..
''
);

# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [ ], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
installPackage "${packageName}" "${src}"
${includeDependencies { inherit dependencies; }}
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
Expand Down Expand Up @@ -393,14 +404,15 @@ let
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, meta ? { }
, ...
}@args:

let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" ];
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ];
in
stdenv.mkDerivation ({
name = "node_${name}-${version}";
name = "${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ lib.optional (stdenv.isLinux) utillinux
++ lib.optional (stdenv.isDarwin) libtool
Expand All @@ -417,6 +429,8 @@ let
passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];

installPhase = ''
source ${installPackage}

# Create and enter a root node_modules/ folder
mkdir -p $out/lib/node_modules
cd $out/lib/node_modules
Expand Down Expand Up @@ -449,6 +463,11 @@ let
# Run post install hook, if provided
runHook postInstall
'';

meta = {
# default to Node.js' platforms
platforms = nodejs.meta.platforms;
} // meta;
} // extraArgs);

# Builds a node environment (a node_modules folder and a set of binaries)
Expand Down Expand Up @@ -490,6 +509,8 @@ let
passAsFile = [ "includeScript" "pinpointDependenciesScript" ];

installPhase = ''
source ${installPackage}

mkdir -p $out/${packageName}
cd $out/${packageName}

Expand Down
3 changes: 2 additions & 1 deletion pkgs/node-packages/node-packages.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[
"coffeescript"
"coffeescript",
{ "jest-cli": "23.6.0" }
]
Loading