mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-02 14:55:25 +03:00
feat: improve nodejs translators/builders
- also execute preinstall script during package installation - disable devDependencies if no instal script present by default
This commit is contained in:
parent
130d71f9d5
commit
1beb1eaab5
@ -473,6 +473,9 @@
|
||||
elif [ -n "$runBuild" ] && [ "$(jq '.scripts.build' ./package.json)" != "null" ]; then
|
||||
npm run build
|
||||
else
|
||||
if [ "$(jq '.scripts.preinstall' ./package.json)" != "null" ]; then
|
||||
npm --production --offline --nodedir=$nodeSources run preinstall
|
||||
fi
|
||||
if [ "$(jq '.scripts.install' ./package.json)" != "null" ]; then
|
||||
npm --production --offline --nodedir=$nodeSources run install
|
||||
fi
|
||||
|
@ -47,11 +47,29 @@
|
||||
cd ./$relPath
|
||||
rm -rf package-lock.json
|
||||
|
||||
if [ "$(jq '.project.subsystemInfo.noDev' -c -r $jsonInput)" == "true" ]; then
|
||||
hasInstallScript=false
|
||||
if [ "$(jq 'has("scripts")' -c -r package.json)" == "false" ]; then
|
||||
:
|
||||
elif [ "$(jq '.scripts | has("preinstall")' -c -r package.json)" == "true" ]; then
|
||||
hasInstallScript=true
|
||||
elif [ "$(jq '.scripts | has("install")' -c -r package.json)" == "true" ]; then
|
||||
hasInstallScript=true
|
||||
elif [ "$(jq '.scripts | has("postinstall")' -c -r package.json)" == "true" ]; then
|
||||
hasInstallScript=true
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
if [ "$hasInstallScript" == "false" ]; then
|
||||
echo "package.json does not define an [pre|post]install script -> omitting dev dependencies"
|
||||
fi
|
||||
|
||||
if [ "$hasInstallScript" == "false" ] \
|
||||
|| [ "$(jq '.project.subsystemInfo.noDev' -c -r $jsonInput)" == "true" ]; then
|
||||
echo "excluding dev dependencies"
|
||||
jq '.devDependencies = {}' ./package.json > package.json.mod
|
||||
mv package.json.mod package.json
|
||||
npm install --package-lock-only --production $npmArgs
|
||||
npm install --package-lock-only --omit=dev $npmArgs
|
||||
else
|
||||
npm install --package-lock-only $npmArgs
|
||||
fi
|
||||
|
@ -25,7 +25,15 @@
|
||||
} @ args: let
|
||||
b = builtins;
|
||||
|
||||
dev = ! noDev;
|
||||
hasInstallScript =
|
||||
(packageJson ? scripts.preinstall)
|
||||
|| (packageJson ? scripts.install)
|
||||
|| (packageJson ? scripts.postinstall);
|
||||
|
||||
noDev =
|
||||
if ! hasInstallScript
|
||||
then true
|
||||
else args.noDev;
|
||||
name = project.name;
|
||||
tree = args.tree.getNodeFromPath project.relPath;
|
||||
relPath = project.relPath;
|
||||
@ -70,11 +78,23 @@
|
||||
then let
|
||||
path = getPath dependencyObject;
|
||||
in
|
||||
(
|
||||
b.fromJSON
|
||||
(b.readFile "${source}/${path}/package.json")
|
||||
)
|
||||
.version
|
||||
if ! (l.pathExists "${source}/${path}/package.json")
|
||||
then
|
||||
throw ''
|
||||
The lock file references a sub-package residing at '${source}/${path}',
|
||||
but that directory doesn't exist or doesn't contain a package.json
|
||||
|
||||
The reason might be that devDependencies are not included in this package release.
|
||||
Possible solutions:
|
||||
- get full package source via git and translate from there
|
||||
- disable devDependencies by passing `noDev` to the translator
|
||||
''
|
||||
else
|
||||
(
|
||||
b.fromJSON
|
||||
(b.readFile "${source}/${path}/package.json")
|
||||
)
|
||||
.version
|
||||
else if lib.hasPrefix "https://" dependencyObject.version
|
||||
then "unknown"
|
||||
else dependencyObject.version;
|
||||
@ -153,7 +173,7 @@
|
||||
version = getVersion pdata;
|
||||
})
|
||||
(lib.filterAttrs
|
||||
(pname: pdata: ! (pdata.dev or false) || dev)
|
||||
(pname: pdata: ! (pdata.dev or false) || ! noDev)
|
||||
parsedDependencies);
|
||||
|
||||
subsystemName = "nodejs";
|
||||
@ -186,7 +206,7 @@
|
||||
in
|
||||
lib.filter
|
||||
(pdata:
|
||||
dev || ! (pdata.dev or false))
|
||||
! noDev || ! (pdata.dev or false))
|
||||
(lib.flatten (serialize inputData));
|
||||
|
||||
getName = dependencyObject: dependencyObject.pname;
|
||||
|
Loading…
Reference in New Issue
Block a user