Skip to content

Commit

Permalink
nodejs builder: process package.json in-place
Browse files Browse the repository at this point in the history
no need for package-json.bak, just put the original data aside in the JSON.
  • Loading branch information
wmertens committed Aug 11, 2022
1 parent be27b1a commit cc6dafe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/subsystems/nodejs/builders/granular/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/subsystems/nodejs/builders/granular/fix-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']\
Expand All @@ -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


Expand All @@ -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\
Expand All @@ -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):
Expand Down

0 comments on commit cc6dafe

Please sign in to comment.