mirror of
https://github.com/nix-community/dream2nix.git
synced 2025-01-02 03:16:09 +03:00
nodejs builder+translator improvements
This commit is contained in:
parent
792deb6a6b
commit
e69cb52ab0
@ -363,7 +363,9 @@ let
|
||||
python $installDeps
|
||||
|
||||
# add bin path entries collected by python script
|
||||
export PATH="$PATH:$(cat $TMP/ADD_BIN_PATH)"
|
||||
if [ -e $TMP/ADD_BIN_PATH ]; then
|
||||
export PATH="$PATH:$(cat $TMP/ADD_BIN_PATH)"
|
||||
fi
|
||||
|
||||
# add dependencies to NODE_PATH
|
||||
export NODE_PATH="$NODE_PATH:$nodeModules/$packageName/node_modules"
|
||||
@ -407,6 +409,7 @@ let
|
||||
|
||||
# Symlinks executables and manual pages to correct directories
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
echo "Symlinking exectuables to /bin"
|
||||
if [ -d "$nodeModules/.bin" ]
|
||||
@ -434,6 +437,8 @@ let
|
||||
if [ -n "$electronHeaders" ]; then
|
||||
${electron-wrap}
|
||||
fi
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
});
|
||||
in
|
||||
|
@ -31,12 +31,12 @@ if 'os' in package_json:
|
||||
# In case of an 'unknown' version coming from the dream lock,
|
||||
# do not override the version from package.json
|
||||
version = os.environ.get("version")
|
||||
if version not in ["unknown", package_json['version']]:
|
||||
if version not in ["unknown", package_json.get('version')]:
|
||||
print(
|
||||
"WARNING: The version of this package defined by its package.json "
|
||||
"doesn't match the version expected by dream2nix."
|
||||
"\n -> Replacing version in package.json: "
|
||||
f"{package_json['version']} -> {version}",
|
||||
f"{package_json.get('version')} -> {version}",
|
||||
file=sys.stderr
|
||||
)
|
||||
changed = True
|
||||
@ -78,7 +78,7 @@ if 'bin' in package_json and package_json['bin']:
|
||||
sourceDir = os.path.dirname(source)
|
||||
# create parent dir
|
||||
pathlib.Path(sourceDir).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
dest = os.path.relpath(bin, sourceDir)
|
||||
print(f"dest: {dest}; source: {source}")
|
||||
os.symlink(dest, source)
|
||||
|
@ -11,7 +11,6 @@ pname = os.environ.get('packageName')
|
||||
version = os.environ.get('version')
|
||||
root = f"{os.path.abspath('.')}/node_modules"
|
||||
package_json_cache = {}
|
||||
satisfaction_cache = {}
|
||||
|
||||
|
||||
with open(os.environ.get("nodeDepsPath")) as f:
|
||||
@ -19,6 +18,8 @@ with open(os.environ.get("nodeDepsPath")) as f:
|
||||
|
||||
def get_package_json(path):
|
||||
if path not in package_json_cache:
|
||||
if not os.path.isfile(f"{path}/package.json"):
|
||||
return None
|
||||
with open(f"{path}/package.json") as f:
|
||||
package_json_cache[path] = json.load(f)
|
||||
return package_json_cache[path]
|
||||
@ -48,7 +49,10 @@ def install_direct_dependencies():
|
||||
else:
|
||||
print(f"installing: {module}")
|
||||
origin = os.path.realpath(f"{dep}/lib/node_modules/{module}")
|
||||
os.symlink(origin, f"{root}/{module}")
|
||||
if not os.path.isdir(f"{root}/{module}"):
|
||||
os.symlink(origin, f"{root}/{module}")
|
||||
else:
|
||||
print(f"already exists: {root}/{module}")
|
||||
|
||||
return add_to_bin_path
|
||||
|
||||
@ -102,9 +106,6 @@ def symlink_sub_dependencies():
|
||||
|
||||
# checks if dependency is already installed in the current or parent dir.
|
||||
def dependency_satisfied(root, pname, version):
|
||||
if (root, pname, version) in satisfaction_cache:
|
||||
return satisfaction_cache[(root, pname, version)]
|
||||
|
||||
if root == "/nix/store":
|
||||
return False
|
||||
|
||||
@ -113,14 +114,10 @@ def dependency_satisfied(root, pname, version):
|
||||
if os.path.isdir(f"{root}/{pname}"):
|
||||
package_json_file = f"{root}/{pname}/package.json"
|
||||
if os.path.isfile(package_json_file):
|
||||
if version == get_package_json(f"{root}/{pname}")['version']:
|
||||
satisfaction_cache[(root, pname, version)] = True
|
||||
if version == get_package_json(f"{root}/{pname}").get('version'):
|
||||
return True
|
||||
|
||||
satisfaction_cache[(root, pname, version)] =\
|
||||
dependency_satisfied(parent, pname, version)
|
||||
|
||||
return satisfaction_cache[(root, pname, version)]
|
||||
return dependency_satisfied(parent, pname, version)
|
||||
|
||||
|
||||
# transforms symlinked dependencies into real copies
|
||||
@ -132,7 +129,6 @@ def symlinks_to_copies(root):
|
||||
if not os.path.islink(dep) or os.path.isfile(dep):
|
||||
continue
|
||||
|
||||
version = get_package_json(dep)['version']
|
||||
d1, d2 = dep.split('/')[-2:]
|
||||
if d1[0] == '@':
|
||||
pname = f"{d1}/{d2}"
|
||||
@ -140,9 +136,12 @@ def symlinks_to_copies(root):
|
||||
else:
|
||||
pname = d2
|
||||
|
||||
if dependency_satisfied(os.path.dirname(root), pname, version):
|
||||
os.remove(dep)
|
||||
continue
|
||||
package_json = get_package_json(dep)
|
||||
if package_json is not None:
|
||||
version = get_package_json(dep)['version']
|
||||
if dependency_satisfied(os.path.dirname(root), pname, version):
|
||||
os.remove(dep)
|
||||
continue
|
||||
|
||||
print(f"copying {dep}")
|
||||
os.rename(dep, f"{dep}.bac")
|
||||
|
@ -64,7 +64,6 @@ let
|
||||
git = dependencyObject:
|
||||
{
|
||||
type = "git";
|
||||
version = getVersion dependencyObject;
|
||||
hash = dependencyObject.fetch.sha256;
|
||||
url = dependencyObject.fetch.url;
|
||||
rev = dependencyObject.fetch.rev;
|
||||
|
@ -93,6 +93,8 @@
|
||||
(
|
||||
packageJSON.dependencies or {}
|
||||
//
|
||||
packageJSON.optionalDependencies or {}
|
||||
//
|
||||
(lib.optionalAttrs dev (packageJSON.devDependencies or {}))
|
||||
//
|
||||
(lib.optionalAttrs peer (packageJSON.peerDependencies or {}))
|
||||
@ -115,9 +117,13 @@
|
||||
lib.head (lib.splitString "@https://" dependencyObject.yarnName)
|
||||
else
|
||||
let
|
||||
version = lib.last (lib.splitString "@" dependencyObject.yarnName);
|
||||
split = lib.splitString "@" dependencyObject.yarnName;
|
||||
version = lib.last split;
|
||||
in
|
||||
lib.removeSuffix "@${version}" dependencyObject.yarnName;
|
||||
if lib.hasPrefix "@" dependencyObject.yarnName then
|
||||
lib.removeSuffix "@${version}" dependencyObject.yarnName
|
||||
else
|
||||
lib.head split;
|
||||
|
||||
getVersion = dependencyObject:
|
||||
dependencyObject.version;
|
||||
@ -234,7 +240,7 @@
|
||||
else if lib.hasInfix "@file:" dependencyObject.yarnName then
|
||||
{
|
||||
path =
|
||||
lib.last (lib.splitString "@file:" dependencyObject.yarnName);
|
||||
lib.last (lib.splitString "@file:" dependencyObject.yarnName);
|
||||
}
|
||||
else
|
||||
throw "unknown path format ${b.toJSON dependencyObject}";
|
||||
|
@ -61,7 +61,8 @@ let
|
||||
getVersion,
|
||||
getSourceType,
|
||||
sourceConstructors,
|
||||
createMissingSource ? (name: version: { type = "unknown"; }),
|
||||
createMissingSource ?
|
||||
(name: version: throw "Cannot find source for ${name}:${version}"),
|
||||
getDependencies ? null,
|
||||
getOriginalID ? null,
|
||||
mainPackageSource ? { type = "unknown"; },
|
||||
|
Loading…
Reference in New Issue
Block a user