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