build-support/node/import-npm-lock: use structuredAttrs instead of passAsFile
This commit is contained in:
@@ -12,6 +12,7 @@ let
|
||||
match
|
||||
elemAt
|
||||
toJSON
|
||||
toFile
|
||||
removeAttrs
|
||||
;
|
||||
inherit (lib) importJSON mapAttrs;
|
||||
@@ -157,18 +158,15 @@ lib.fix (self: {
|
||||
{
|
||||
inherit pname version;
|
||||
|
||||
passAsFile = [
|
||||
"package"
|
||||
"packageLock"
|
||||
];
|
||||
package = toFile (toJSON packageJSON');
|
||||
packageLock = toFile (toJSON packageLock');
|
||||
|
||||
package = toJSON packageJSON';
|
||||
packageLock = toJSON packageLock';
|
||||
__structuredAttrs = true;
|
||||
}
|
||||
''
|
||||
mkdir $out
|
||||
cp "$packagePath" $out/package.json
|
||||
cp "$packageLockPath" $out/package-lock.json
|
||||
cp "${package}" > $out/package.json
|
||||
cp "${packageLock}" > $out/package-lock.json
|
||||
'';
|
||||
|
||||
# Build node modules from package.json & package-lock.json
|
||||
@@ -180,6 +178,11 @@ lib.fix (self: {
|
||||
nodejs,
|
||||
derivationArgs ? { },
|
||||
}:
|
||||
let
|
||||
# Backwards compatibility: if derivationArgs contains passAsFile,
|
||||
# we can't force structuredAttrs here yet.
|
||||
__structuredAttrs = !(derivationArgs ? passAsFile);
|
||||
in
|
||||
stdenv.mkDerivation (
|
||||
{
|
||||
pname = derivationArgs.pname or "${getName package}-node-modules";
|
||||
@@ -213,17 +216,29 @@ lib.fix (self: {
|
||||
++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]
|
||||
++ derivationArgs.nativeBuildInputs or [ ];
|
||||
|
||||
postPatch =
|
||||
(
|
||||
if __structuredAttrs then
|
||||
''
|
||||
echo -n "$package" > package.json
|
||||
echo -n "$packageLock" > package-lock.json
|
||||
''
|
||||
else
|
||||
''
|
||||
cp --no-preserve=mode "$packagePath" package.json
|
||||
cp --no-preserve=mode "$packageLockPath" package-lock.json
|
||||
''
|
||||
)
|
||||
+ derivationArgs.postPatch or "";
|
||||
|
||||
inherit __structuredAttrs;
|
||||
}
|
||||
// lib.optionalAttrs (!__structuredAttrs) {
|
||||
passAsFile = [
|
||||
"package"
|
||||
"packageLock"
|
||||
]
|
||||
++ derivationArgs.passAsFile or [ ];
|
||||
|
||||
postPatch = ''
|
||||
cp --no-preserve=mode "$packagePath" package.json
|
||||
cp --no-preserve=mode "$packageLockPath" package-lock.json
|
||||
''
|
||||
+ derivationArgs.postPatch or "";
|
||||
++ derivationArgs.passAsFile;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user