2019-07-13 13:00:43 +00:00
|
|
|
{ pkgs ? import <nixpkgs> {}
|
|
|
|
, nodejs ? pkgs.nodejs
|
|
|
|
, yarn ? pkgs.yarn
|
2022-04-01 09:33:10 +00:00
|
|
|
, allowAliases ? pkgs.config.allowAliases
|
2022-11-13 01:36:51 +00:00
|
|
|
}@inputs:
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
let
|
2022-12-18 22:22:17 +00:00
|
|
|
inherit (pkgs) stdenv lib callPackage git rsync runCommandLocal;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
compose = f: g: x: f (g x);
|
|
|
|
id = x: x;
|
|
|
|
composeAll = builtins.foldl' compose id;
|
2021-10-10 23:08:40 +00:00
|
|
|
|
|
|
|
# https://docs.npmjs.com/files/package.json#license
|
|
|
|
# TODO: support expression syntax (OR, AND, etc)
|
|
|
|
getLicenseFromSpdxId = licstr:
|
|
|
|
if licstr == "UNLICENSED" then
|
|
|
|
lib.licenses.unfree
|
|
|
|
else
|
|
|
|
lib.getLicenseFromSpdxId licstr;
|
2019-07-13 13:00:43 +00:00
|
|
|
in rec {
|
|
|
|
# Export yarn again to make it easier to find out which yarn was used.
|
|
|
|
inherit yarn;
|
|
|
|
|
|
|
|
# Re-export pkgs
|
|
|
|
inherit pkgs;
|
|
|
|
|
|
|
|
unlessNull = item: alt:
|
|
|
|
if item == null then alt else item;
|
|
|
|
|
|
|
|
reformatPackageName = pname:
|
|
|
|
let
|
|
|
|
# regex adapted from `validate-npm-package-name`
|
|
|
|
# will produce 3 parts e.g.
|
|
|
|
# "@someorg/somepackage" -> [ "@someorg/" "someorg" "somepackage" ]
|
|
|
|
# "somepackage" -> [ null null "somepackage" ]
|
|
|
|
parts = builtins.tail (builtins.match "^(@([^/]+)/)?([^/]+)$" pname);
|
|
|
|
# if there is no organisation we need to filter out null values.
|
|
|
|
non-null = builtins.filter (x: x != null) parts;
|
|
|
|
in builtins.concatStringsSep "-" non-null;
|
|
|
|
|
2021-10-10 23:08:40 +00:00
|
|
|
inherit getLicenseFromSpdxId;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
# Generates the yarn.nix from the yarn.lock file
|
|
|
|
mkYarnNix = { yarnLock, flags ? [] }:
|
|
|
|
pkgs.runCommand "yarn.nix" {}
|
|
|
|
"${yarn2nix}/bin/yarn2nix --lockfile ${yarnLock} --no-patch --builtin-fetchgit ${lib.escapeShellArgs flags} > $out";
|
|
|
|
|
|
|
|
# Loads the generated offline cache. This will be used by yarn as
|
|
|
|
# the package source.
|
|
|
|
importOfflineCache = yarnNix:
|
|
|
|
let
|
|
|
|
pkg = callPackage yarnNix { };
|
|
|
|
in
|
|
|
|
pkg.offline_cache;
|
|
|
|
|
|
|
|
defaultYarnFlags = [
|
|
|
|
"--offline"
|
|
|
|
"--frozen-lockfile"
|
|
|
|
"--ignore-engines"
|
|
|
|
];
|
|
|
|
|
|
|
|
mkYarnModules = {
|
2021-05-21 21:10:02 +00:00
|
|
|
name ? "${pname}-${version}", # safe name and version, e.g. testcompany-one-modules-1.0.0
|
2019-07-13 13:00:43 +00:00
|
|
|
pname, # original name, e.g @testcompany/one
|
|
|
|
version,
|
|
|
|
packageJSON,
|
|
|
|
yarnLock,
|
|
|
|
yarnNix ? mkYarnNix { inherit yarnLock; },
|
2021-10-06 16:26:50 +00:00
|
|
|
offlineCache ? importOfflineCache yarnNix,
|
2022-07-24 12:54:33 +00:00
|
|
|
yarnFlags ? [ ],
|
2022-11-01 13:27:02 +00:00
|
|
|
ignoreScripts ? true,
|
2022-11-13 01:36:51 +00:00
|
|
|
nodejs ? inputs.nodejs,
|
2023-07-11 20:11:54 +00:00
|
|
|
yarn ? inputs.yarn.override { inherit nodejs; },
|
2019-07-13 13:00:43 +00:00
|
|
|
pkgConfig ? {},
|
|
|
|
preBuild ? "",
|
|
|
|
postBuild ? "",
|
|
|
|
workspaceDependencies ? [], # List of yarn packages
|
2022-01-05 20:09:34 +00:00
|
|
|
packageResolutions ? {},
|
2019-07-13 13:00:43 +00:00
|
|
|
}:
|
|
|
|
let
|
2022-01-28 16:33:06 +00:00
|
|
|
extraNativeBuildInputs =
|
|
|
|
lib.concatMap
|
|
|
|
(key: pkgConfig.${key}.nativeBuildInputs or [])
|
|
|
|
(builtins.attrNames pkgConfig);
|
|
|
|
extraBuildInputs =
|
|
|
|
lib.concatMap
|
|
|
|
(key: pkgConfig.${key}.buildInputs or [])
|
|
|
|
(builtins.attrNames pkgConfig);
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2023-07-11 20:11:54 +00:00
|
|
|
postInstall = builtins.map (key:
|
2019-07-13 13:00:43 +00:00
|
|
|
if (pkgConfig.${key} ? postInstall) then
|
|
|
|
''
|
|
|
|
for f in $(find -L -path '*/node_modules/${key}' -type d); do
|
|
|
|
(cd "$f" && (${pkgConfig.${key}.postInstall}))
|
|
|
|
done
|
|
|
|
''
|
|
|
|
else
|
|
|
|
""
|
2023-07-11 20:11:54 +00:00
|
|
|
) (builtins.attrNames pkgConfig);
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2023-02-06 15:27:02 +00:00
|
|
|
# build-time JSON generation to avoid IFD
|
|
|
|
# see https://nixos.wiki/wiki/Import_From_Derivation
|
|
|
|
workspaceJSON = pkgs.runCommand "${name}-workspace-package.json"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ pkgs.jq ];
|
|
|
|
inherit packageJSON;
|
|
|
|
passAsFile = [ "baseJSON" ];
|
|
|
|
baseJSON = builtins.toJSON { private = true; workspaces = [ "deps/**" ]; resolutions = packageResolutions; };
|
|
|
|
} ''
|
|
|
|
jq --slurpfile packageJSON "$packageJSON" '.resolutions = $packageJSON[0].resolutions + .resolutions' <"$baseJSONPath" >$out
|
|
|
|
'';
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
workspaceDependencyLinks = lib.concatMapStringsSep "\n"
|
|
|
|
(dep: ''
|
|
|
|
mkdir -p "deps/${dep.pname}"
|
|
|
|
ln -sf ${dep.packageJSON} "deps/${dep.pname}/package.json"
|
|
|
|
'')
|
|
|
|
workspaceDependencies;
|
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
inherit preBuild postBuild name;
|
2021-08-16 20:37:41 +00:00
|
|
|
dontUnpack = true;
|
|
|
|
dontInstall = true;
|
2022-01-28 16:33:06 +00:00
|
|
|
nativeBuildInputs = [ yarn nodejs git ] ++ extraNativeBuildInputs;
|
|
|
|
buildInputs = extraBuildInputs;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2021-10-11 23:56:16 +00:00
|
|
|
configurePhase = lib.optionalString (offlineCache ? outputHash) ''
|
|
|
|
if ! cmp -s ${yarnLock} ${offlineCache}/yarn.lock; then
|
|
|
|
echo "yarn.lock changed, you need to update the fetchYarnDeps hash"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'' + ''
|
2019-07-13 13:00:43 +00:00
|
|
|
# Yarn writes cache directories etc to $HOME.
|
|
|
|
export HOME=$PWD/yarn_home
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
mkdir -p "deps/${pname}"
|
|
|
|
cp ${packageJSON} "deps/${pname}/package.json"
|
|
|
|
cp ${workspaceJSON} ./package.json
|
|
|
|
cp ${yarnLock} ./yarn.lock
|
|
|
|
chmod +w ./yarn.lock
|
|
|
|
|
|
|
|
yarn config --offline set yarn-offline-mirror ${offlineCache}
|
|
|
|
|
|
|
|
# Do not look up in the registry, but in the offline cache.
|
|
|
|
${fixup_yarn_lock}/bin/fixup_yarn_lock yarn.lock
|
|
|
|
|
|
|
|
${workspaceDependencyLinks}
|
|
|
|
|
2022-11-01 13:27:02 +00:00
|
|
|
yarn install ${lib.escapeShellArgs (defaultYarnFlags ++ lib.optional ignoreScripts "--ignore-scripts" ++ yarnFlags)}
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
${lib.concatStringsSep "\n" postInstall}
|
|
|
|
|
|
|
|
mkdir $out
|
|
|
|
mv node_modules $out/
|
|
|
|
mv deps $out/
|
|
|
|
patchShebangs $out
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# This can be used as a shellHook in mkYarnPackage. It brings the built node_modules into
|
|
|
|
# the shell-hook environment.
|
|
|
|
linkNodeModulesHook = ''
|
|
|
|
if [[ -d node_modules || -L node_modules ]]; then
|
|
|
|
echo "./node_modules is present. Replacing."
|
|
|
|
rm -rf node_modules
|
|
|
|
fi
|
|
|
|
|
|
|
|
ln -s "$node_modules" node_modules
|
|
|
|
'';
|
|
|
|
|
|
|
|
mkYarnWorkspace = {
|
|
|
|
src,
|
|
|
|
packageJSON ? src + "/package.json",
|
|
|
|
yarnLock ? src + "/yarn.lock",
|
2022-11-13 01:36:51 +00:00
|
|
|
nodejs ? inputs.nodejs,
|
2023-07-11 20:11:54 +00:00
|
|
|
yarn ? inputs.yarn.override { inherit nodejs; },
|
2019-07-13 13:00:43 +00:00
|
|
|
packageOverrides ? {},
|
|
|
|
...
|
|
|
|
}@attrs:
|
|
|
|
let
|
|
|
|
package = lib.importJSON packageJSON;
|
|
|
|
|
2021-12-23 13:18:10 +00:00
|
|
|
packageGlobs = if lib.isList package.workspaces then package.workspaces else package.workspaces.packages;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2022-01-05 20:09:34 +00:00
|
|
|
packageResolutions = package.resolutions or {};
|
|
|
|
|
2019-07-13 13:00:43 +00:00
|
|
|
globElemToRegex = lib.replaceStrings ["*"] [".*"];
|
|
|
|
|
|
|
|
# PathGlob -> [PathGlobElem]
|
|
|
|
splitGlob = lib.splitString "/";
|
|
|
|
|
|
|
|
# Path -> [PathGlobElem] -> [Path]
|
|
|
|
# Note: Only directories are included, everything else is filtered out
|
|
|
|
expandGlobList = base: globElems:
|
|
|
|
let
|
|
|
|
elemRegex = globElemToRegex (lib.head globElems);
|
|
|
|
rest = lib.tail globElems;
|
|
|
|
children = lib.attrNames (lib.filterAttrs (name: type: type == "directory") (builtins.readDir base));
|
|
|
|
matchingChildren = lib.filter (child: builtins.match elemRegex child != null) children;
|
|
|
|
in if globElems == []
|
|
|
|
then [ base ]
|
|
|
|
else lib.concatMap (child: expandGlobList (base+("/"+child)) rest) matchingChildren;
|
|
|
|
|
|
|
|
# Path -> PathGlob -> [Path]
|
|
|
|
expandGlob = base: glob: expandGlobList base (splitGlob glob);
|
|
|
|
|
|
|
|
packagePaths = lib.concatMap (expandGlob src) packageGlobs;
|
|
|
|
|
|
|
|
packages = lib.listToAttrs (map (src:
|
|
|
|
let
|
|
|
|
packageJSON = src + "/package.json";
|
|
|
|
|
|
|
|
package = lib.importJSON packageJSON;
|
|
|
|
|
|
|
|
allDependencies = lib.foldl (a: b: a // b) {} (map (field: lib.attrByPath [field] {} package) ["dependencies" "devDependencies"]);
|
|
|
|
|
|
|
|
# { [name: String] : { pname : String, packageJSON : String, ... } } -> { [pname: String] : version } -> [{ pname : String, packageJSON : String, ... }]
|
|
|
|
getWorkspaceDependencies = packages: allDependencies:
|
|
|
|
let
|
|
|
|
packageList = lib.attrValues packages;
|
|
|
|
in
|
|
|
|
composeAll [
|
|
|
|
(lib.filter (x: x != null))
|
|
|
|
(lib.mapAttrsToList (pname: _version: lib.findFirst (package: package.pname == pname) null packageList))
|
|
|
|
] allDependencies;
|
|
|
|
|
|
|
|
workspaceDependencies = getWorkspaceDependencies packages allDependencies;
|
|
|
|
|
|
|
|
name = reformatPackageName package.name;
|
|
|
|
in {
|
|
|
|
inherit name;
|
|
|
|
value = mkYarnPackage (
|
|
|
|
builtins.removeAttrs attrs ["packageOverrides"]
|
2022-11-13 01:36:51 +00:00
|
|
|
// { inherit src packageJSON yarnLock nodejs yarn packageResolutions workspaceDependencies; }
|
2019-07-13 13:00:43 +00:00
|
|
|
// lib.attrByPath [name] {} packageOverrides
|
|
|
|
);
|
|
|
|
})
|
|
|
|
packagePaths
|
|
|
|
);
|
|
|
|
in packages;
|
|
|
|
|
|
|
|
mkYarnPackage = {
|
|
|
|
name ? null,
|
|
|
|
src,
|
|
|
|
packageJSON ? src + "/package.json",
|
|
|
|
yarnLock ? src + "/yarn.lock",
|
|
|
|
yarnNix ? mkYarnNix { inherit yarnLock; },
|
2021-10-06 16:26:50 +00:00
|
|
|
offlineCache ? importOfflineCache yarnNix,
|
2022-11-13 01:36:51 +00:00
|
|
|
nodejs ? inputs.nodejs,
|
2023-07-11 20:11:54 +00:00
|
|
|
yarn ? inputs.yarn.override { inherit nodejs; },
|
2022-07-24 12:54:33 +00:00
|
|
|
yarnFlags ? [ ],
|
2019-07-13 13:00:43 +00:00
|
|
|
yarnPreBuild ? "",
|
2020-10-24 01:34:00 +00:00
|
|
|
yarnPostBuild ? "",
|
2019-07-13 13:00:43 +00:00
|
|
|
pkgConfig ? {},
|
|
|
|
extraBuildInputs ? [],
|
|
|
|
publishBinsFor ? null,
|
|
|
|
workspaceDependencies ? [], # List of yarnPackages
|
2022-01-05 20:09:34 +00:00
|
|
|
packageResolutions ? {},
|
2019-07-13 13:00:43 +00:00
|
|
|
...
|
|
|
|
}@attrs:
|
|
|
|
let
|
|
|
|
package = lib.importJSON packageJSON;
|
2023-07-11 20:12:59 +00:00
|
|
|
pname = attrs.pname or package.name;
|
|
|
|
safeName = reformatPackageName package.name;
|
2020-12-13 12:42:56 +00:00
|
|
|
version = attrs.version or package.version;
|
2019-07-13 13:00:43 +00:00
|
|
|
baseName = unlessNull name "${safeName}-${version}";
|
|
|
|
|
|
|
|
workspaceDependenciesTransitive = lib.unique (
|
|
|
|
(lib.flatten (builtins.map (dep: dep.workspaceDependencies) workspaceDependencies))
|
|
|
|
++ workspaceDependencies
|
|
|
|
);
|
|
|
|
|
|
|
|
deps = mkYarnModules {
|
2023-07-11 20:12:59 +00:00
|
|
|
pname = package.name;
|
2019-07-13 13:00:43 +00:00
|
|
|
name = "${safeName}-modules-${version}";
|
|
|
|
preBuild = yarnPreBuild;
|
2020-10-24 01:34:00 +00:00
|
|
|
postBuild = yarnPostBuild;
|
2019-07-13 13:00:43 +00:00
|
|
|
workspaceDependencies = workspaceDependenciesTransitive;
|
2023-07-11 20:12:59 +00:00
|
|
|
inherit packageJSON version yarnLock offlineCache nodejs yarn yarnFlags pkgConfig packageResolutions;
|
2019-07-13 13:00:43 +00:00
|
|
|
};
|
|
|
|
|
2023-07-11 20:12:59 +00:00
|
|
|
publishBinsFor_ = unlessNull publishBinsFor [ package.name ];
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
linkDirFunction = ''
|
|
|
|
linkDirToDirLinks() {
|
|
|
|
target=$1
|
|
|
|
if [ ! -f "$target" ]; then
|
|
|
|
mkdir -p "$target"
|
|
|
|
elif [ -L "$target" ]; then
|
|
|
|
local new=$(mktemp -d)
|
|
|
|
trueSource=$(realpath "$target")
|
|
|
|
if [ "$(ls $trueSource | wc -l)" -gt 0 ]; then
|
|
|
|
ln -s $trueSource/* $new/
|
|
|
|
fi
|
|
|
|
rm -r "$target"
|
|
|
|
mv "$new" "$target"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
workspaceDependencyCopy = lib.concatMapStringsSep "\n"
|
|
|
|
(dep: ''
|
|
|
|
# ensure any existing scope directory is not a symlink
|
2023-07-11 20:12:59 +00:00
|
|
|
linkDirToDirLinks "$(dirname node_modules/${dep.package.name})"
|
|
|
|
mkdir -p "deps/${dep.package.name}"
|
|
|
|
tar -xf "${dep}/tarballs/${dep.name}.tgz" --directory "deps/${dep.package.name}" --strip-components=1
|
|
|
|
if [ ! -e "deps/${dep.package.name}/node_modules" ]; then
|
|
|
|
ln -s "${deps}/deps/${dep.package.name}/node_modules" "deps/${dep.package.name}/node_modules"
|
2019-07-13 13:00:43 +00:00
|
|
|
fi
|
|
|
|
'')
|
|
|
|
workspaceDependenciesTransitive;
|
|
|
|
|
2022-01-05 20:09:34 +00:00
|
|
|
in stdenv.mkDerivation (builtins.removeAttrs attrs ["yarnNix" "pkgConfig" "workspaceDependencies" "packageResolutions"] // {
|
2023-07-11 20:12:59 +00:00
|
|
|
inherit pname version src;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
name = baseName;
|
|
|
|
|
|
|
|
buildInputs = [ yarn nodejs rsync ] ++ extraBuildInputs;
|
|
|
|
|
|
|
|
node_modules = deps + "/node_modules";
|
|
|
|
|
|
|
|
configurePhase = attrs.configurePhase or ''
|
|
|
|
runHook preConfigure
|
|
|
|
|
|
|
|
for localDir in npm-packages-offline-cache node_modules; do
|
|
|
|
if [[ -d $localDir || -L $localDir ]]; then
|
|
|
|
echo "$localDir dir present. Removing."
|
|
|
|
rm -rf $localDir
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-07-11 20:12:59 +00:00
|
|
|
# move convent of . to ./deps/${package.name}
|
2019-07-13 13:00:43 +00:00
|
|
|
mv $PWD $NIX_BUILD_TOP/temp
|
2023-07-11 20:12:59 +00:00
|
|
|
mkdir -p "$PWD/deps/${package.name}"
|
|
|
|
rm -fd "$PWD/deps/${package.name}"
|
|
|
|
mv $NIX_BUILD_TOP/temp "$PWD/deps/${package.name}"
|
2019-07-13 13:00:43 +00:00
|
|
|
cd $PWD
|
|
|
|
|
2023-07-11 20:12:59 +00:00
|
|
|
ln -s ${deps}/deps/${package.name}/node_modules "deps/${package.name}/node_modules"
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
cp -r $node_modules node_modules
|
|
|
|
chmod -R +w node_modules
|
|
|
|
|
|
|
|
${linkDirFunction}
|
|
|
|
|
2023-07-11 20:12:59 +00:00
|
|
|
linkDirToDirLinks "$(dirname node_modules/${package.name})"
|
|
|
|
ln -s "deps/${package.name}" "node_modules/${package.name}"
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
${workspaceDependencyCopy}
|
|
|
|
|
|
|
|
# Help yarn commands run in other phases find the package
|
2023-07-11 20:12:59 +00:00
|
|
|
echo "--cwd deps/${package.name}" > .yarnrc
|
2019-07-13 13:00:43 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Replace this phase on frontend packages where only the generated
|
|
|
|
# files are an interesting output.
|
|
|
|
installPhase = attrs.installPhase or ''
|
|
|
|
runHook preInstall
|
|
|
|
|
2023-07-11 20:12:59 +00:00
|
|
|
mkdir -p $out/{bin,libexec/${package.name}}
|
|
|
|
mv node_modules $out/libexec/${package.name}/node_modules
|
|
|
|
mv deps $out/libexec/${package.name}/deps
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2023-07-11 20:12:59 +00:00
|
|
|
node ${./internal/fixup_bin.js} $out/bin $out/libexec/${package.name}/node_modules ${lib.concatStringsSep " " publishBinsFor_}
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2022-05-31 15:10:16 +00:00
|
|
|
doDist = attrs.doDist or true;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
distPhase = attrs.distPhase or ''
|
|
|
|
# pack command ignores cwd option
|
|
|
|
rm -f .yarnrc
|
2023-07-11 20:12:59 +00:00
|
|
|
cd $out/libexec/${package.name}/deps/${package.name}
|
2019-07-13 13:00:43 +00:00
|
|
|
mkdir -p $out/tarballs/
|
|
|
|
yarn pack --offline --ignore-scripts --filename $out/tarballs/${baseName}.tgz
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
2023-07-11 20:12:59 +00:00
|
|
|
inherit package packageJSON deps;
|
2019-07-13 13:00:43 +00:00
|
|
|
workspaceDependencies = workspaceDependenciesTransitive;
|
|
|
|
} // (attrs.passthru or {});
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
inherit (nodejs.meta) platforms;
|
2022-11-22 10:11:04 +00:00
|
|
|
} // lib.optionalAttrs (package ? description) { inherit (package) description; }
|
|
|
|
// lib.optionalAttrs (package ? homepage) { inherit (package) homepage; }
|
|
|
|
// lib.optionalAttrs (package ? license) { license = getLicenseFromSpdxId package.license; }
|
|
|
|
// (attrs.meta or {});
|
2019-07-13 13:00:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
yarn2nix = mkYarnPackage {
|
|
|
|
src =
|
|
|
|
let
|
|
|
|
src = ./.;
|
|
|
|
|
|
|
|
mkFilter = { dirsToInclude, filesToInclude, root }: path: type:
|
|
|
|
let
|
2023-07-11 20:11:54 +00:00
|
|
|
inherit (lib) elem elemAt splitString;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
|
|
|
subpath = elemAt (splitString "${toString root}/" path) 1;
|
|
|
|
spdir = elemAt (splitString "/" subpath) 0;
|
|
|
|
in elem spdir dirsToInclude ||
|
|
|
|
(type == "regular" && elem subpath filesToInclude);
|
|
|
|
in builtins.filterSource
|
|
|
|
(mkFilter {
|
|
|
|
dirsToInclude = ["bin" "lib"];
|
|
|
|
filesToInclude = ["package.json" "yarn.lock"];
|
|
|
|
root = src;
|
|
|
|
})
|
|
|
|
src;
|
|
|
|
|
|
|
|
# yarn2nix is the only package that requires the yarnNix option.
|
|
|
|
# All the other projects can auto-generate that file.
|
|
|
|
yarnNix = ./yarn.nix;
|
2020-07-10 16:24:03 +00:00
|
|
|
|
2019-11-22 14:27:11 +00:00
|
|
|
# Using the filter above and importing package.json from the filtered
|
|
|
|
# source results in an error in restricted mode. To circumvent this,
|
|
|
|
# we import package.json from the unfiltered source
|
|
|
|
packageJSON = ./package.json;
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2022-11-01 13:27:02 +00:00
|
|
|
yarnFlags = defaultYarnFlags ++ [ "--ignore-scripts" "--production=true" ];
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2021-10-31 08:44:50 +00:00
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
|
2019-07-13 13:00:43 +00:00
|
|
|
buildPhase = ''
|
|
|
|
source ${./nix/expectShFunctions.sh}
|
|
|
|
|
|
|
|
expectFilePresent ./node_modules/.yarn-integrity
|
|
|
|
|
|
|
|
# check dependencies are installed
|
|
|
|
expectFilePresent ./node_modules/@yarnpkg/lockfile/package.json
|
|
|
|
|
|
|
|
# check devDependencies are not installed
|
|
|
|
expectFileOrDirAbsent ./node_modules/.bin/eslint
|
|
|
|
expectFileOrDirAbsent ./node_modules/eslint/package.json
|
|
|
|
'';
|
2021-10-31 08:44:50 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
wrapProgram $out/bin/yarn2nix --prefix PATH : "${pkgs.nix-prefetch-git}/bin"
|
|
|
|
'';
|
2019-07-13 13:00:43 +00:00
|
|
|
};
|
|
|
|
|
2021-08-19 20:49:29 +00:00
|
|
|
fixup_yarn_lock = runCommandLocal "fixup_yarn_lock"
|
|
|
|
{
|
|
|
|
buildInputs = [ nodejs ];
|
|
|
|
} ''
|
|
|
|
mkdir -p $out/lib
|
|
|
|
mkdir -p $out/bin
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2021-08-19 20:49:29 +00:00
|
|
|
cp ${./lib/urlToName.js} $out/lib/urlToName.js
|
|
|
|
cp ${./internal/fixup_yarn_lock.js} $out/bin/fixup_yarn_lock
|
2019-07-13 13:00:43 +00:00
|
|
|
|
2021-08-19 20:49:29 +00:00
|
|
|
patchShebangs $out
|
|
|
|
'';
|
2021-10-10 23:08:40 +00:00
|
|
|
} // lib.optionalAttrs allowAliases {
|
|
|
|
# Aliases
|
|
|
|
spdxLicense = getLicenseFromSpdxId; # added 2021-12-01
|
2019-07-13 13:00:43 +00:00
|
|
|
}
|