From 6fdac877b7006892f01a7be61f54f3369afaebd2 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Thu, 14 Jul 2022 02:38:21 +0200 Subject: [PATCH] nodejs builder: process package.json in-place no need for package-json.bak, just put the original data aside in the JSON. --- src/subsystems/nodejs/builders/granular/default.nix | 1 - .../nodejs/builders/granular/fix-package.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular/default.nix index 00bb1ec3a9..81a501841e 100644 --- a/src/subsystems/nodejs/builders/granular/default.nix +++ b/src/subsystems/nodejs/builders/granular/default.nix @@ -394,7 +394,6 @@ rm $nodeModules/$packageName/package.json.old # run python script (see comment above): - cp package.json package.json.bak python $fixPackage \ || \ # exit code 3 -> the package is incompatible to the current platform diff --git a/src/subsystems/nodejs/builders/granular/fix-package.py b/src/subsystems/nodejs/builders/granular/fix-package.py index df745ee9bd..19a0d94400 100644 --- a/src/subsystems/nodejs/builders/granular/fix-package.py +++ b/src/subsystems/nodejs/builders/granular/fix-package.py @@ -14,7 +14,7 @@ changed = False -# fail if platform incompatible +# fail if platform incompatible - should not happen due to filters if 'os' in package_json: platform = sys.platform if platform not in package_json['os']\ @@ -39,7 +39,7 @@ f"{package_json.get('version')} -> {version}", file=sys.stderr ) - changed = True + package_json['origVersion'] = package_json['version'] package_json['version'] = version @@ -48,6 +48,7 @@ # as NPM install will otherwise re-fetch these if 'dependencies' in package_json: dependencies = package_json['dependencies'] + depsChanged = False # dependencies can be a list or dict for pname in dependencies: if 'bundledDependencies' in package_json\ @@ -58,17 +59,21 @@ f"WARNING: Dependency {pname} wanted but not available. Ignoring.", file=sys.stderr ) + depsChanged = True continue version =\ 'unknown' if isinstance(dependencies, list) else dependencies[pname] if available_deps[pname] != version: - version = available_deps[pname] - changed = True + depsChanged = True print( f"package.json: Pinning version '{version}' to '{available_deps[pname]}'" f" for dependency '{pname}'", file=sys.stderr ) + if depsChanged: + changed = True + package_json['dependencies'] = available_deps + package_json['origDependencies'] = dependencies # create symlinks for executables (bin entries from package.json) def symlink_bin(bin_dir, package_json):