2023-11-14 17:46:16 +01:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchNpmDeps
|
|
|
|
, buildPackages
|
|
|
|
, nodejs
|
|
|
|
, darwin
|
|
|
|
} @ topLevelArgs:
|
2022-09-03 03:52:20 +02:00
|
|
|
|
|
|
|
{ name ? "${args.pname}-${args.version}"
|
|
|
|
, src ? null
|
|
|
|
, srcs ? null
|
|
|
|
, sourceRoot ? null
|
2022-11-19 06:31:18 +01:00
|
|
|
, prePatch ? ""
|
2022-09-03 03:52:20 +02:00
|
|
|
, patches ? [ ]
|
2022-11-19 06:31:18 +01:00
|
|
|
, postPatch ? ""
|
2022-09-03 03:52:20 +02:00
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, buildInputs ? [ ]
|
|
|
|
# The output hash of the dependencies for this project.
|
|
|
|
# Can be calculated in advance with prefetch-npm-deps.
|
|
|
|
, npmDepsHash ? ""
|
2022-12-13 04:33:43 +01:00
|
|
|
# Whether to force the usage of Git dependencies that have install scripts, but not a lockfile.
|
|
|
|
# Use with care.
|
|
|
|
, forceGitDeps ? false
|
2023-07-14 14:03:54 +02:00
|
|
|
# Whether to force allow an empty dependency cache.
|
|
|
|
# This can be enabled if there are truly no remote dependencies, but generally an empty cache indicates something is wrong.
|
|
|
|
, forceEmptyCache ? false
|
2022-09-03 03:52:20 +02:00
|
|
|
# Whether to make the cache writable prior to installing dependencies.
|
|
|
|
# Don't set this unless npm tries to write to the cache directory, as it can slow down the build.
|
|
|
|
, makeCacheWritable ? false
|
|
|
|
# The script to run to build the project.
|
|
|
|
, npmBuildScript ? "build"
|
|
|
|
# Flags to pass to all npm commands.
|
|
|
|
, npmFlags ? [ ]
|
2023-05-24 03:41:57 +02:00
|
|
|
# Flags to pass to `npm ci`.
|
2022-09-03 03:52:20 +02:00
|
|
|
, npmInstallFlags ? [ ]
|
|
|
|
# Flags to pass to `npm rebuild`.
|
|
|
|
, npmRebuildFlags ? [ ]
|
|
|
|
# Flags to pass to `npm run ${npmBuildScript}`.
|
|
|
|
, npmBuildFlags ? [ ]
|
|
|
|
# Flags to pass to `npm pack`.
|
|
|
|
, npmPackFlags ? [ ]
|
2023-05-24 03:41:57 +02:00
|
|
|
# Flags to pass to `npm prune`.
|
|
|
|
, npmPruneFlags ? npmInstallFlags
|
|
|
|
# Value for npm `--workspace` flag and directory in which the files to be installed are found.
|
|
|
|
, npmWorkspace ? null
|
2023-11-09 17:19:24 +01:00
|
|
|
, nodejs ? topLevelArgs.nodejs
|
2023-11-09 18:51:35 +01:00
|
|
|
, npmDeps ? fetchNpmDeps {
|
2023-07-14 14:03:54 +02:00
|
|
|
inherit forceGitDeps forceEmptyCache src srcs sourceRoot prePatch patches postPatch;
|
2023-11-09 18:51:35 +01:00
|
|
|
name = "${name}-npm-deps";
|
|
|
|
hash = npmDepsHash;
|
|
|
|
}
|
2024-02-16 09:04:00 +01:00
|
|
|
# Custom npmConfigHook
|
|
|
|
, npmConfigHook ? null
|
|
|
|
# Custom npmBuildHook
|
|
|
|
, npmBuildHook ? null
|
|
|
|
# Custom npmInstallHook
|
|
|
|
, npmInstallHook ? null
|
2022-09-03 03:52:20 +02:00
|
|
|
, ...
|
|
|
|
} @ args:
|
|
|
|
|
|
|
|
let
|
2023-09-03 23:01:22 +02:00
|
|
|
# .override {} negates splicing, so we need to use buildPackages explicitly
|
|
|
|
npmHooks = buildPackages.npmHooks.override {
|
|
|
|
inherit nodejs;
|
|
|
|
};
|
2022-09-03 03:52:20 +02:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (args // {
|
|
|
|
inherit npmDeps npmBuildScript;
|
|
|
|
|
2023-11-14 17:46:16 +01:00
|
|
|
nativeBuildInputs = nativeBuildInputs
|
2024-02-16 09:04:00 +01:00
|
|
|
++ [
|
|
|
|
nodejs
|
|
|
|
# Prefer passed hooks
|
|
|
|
(if npmConfigHook != null then npmConfigHook else npmHooks.npmConfigHook)
|
|
|
|
(if npmBuildHook != null then npmBuildHook else npmHooks.npmBuildHook)
|
|
|
|
(if npmInstallHook != null then npmInstallHook else npmHooks.npmInstallHook)
|
|
|
|
nodejs.python
|
|
|
|
]
|
2023-11-14 17:46:16 +01:00
|
|
|
++ lib.optionals stdenv.isDarwin [ darwin.cctools ];
|
2022-09-03 03:52:20 +02:00
|
|
|
buildInputs = buildInputs ++ [ nodejs ];
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
# Stripping takes way too long with the amount of files required by a typical Node.js project.
|
|
|
|
dontStrip = args.dontStrip or true;
|
|
|
|
|
|
|
|
meta = (args.meta or { }) // { platforms = args.meta.platforms or nodejs.meta.platforms; };
|
|
|
|
})
|