Skip to content

Commit

Permalink
nodejs: remove preserveSymlinks hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Jul 28, 2022
1 parent 54cf131 commit df4311b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 113 deletions.
60 changes: 1 addition & 59 deletions overrides/nodejs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ in
};
};

# TODO not sure if this works
edex-ui = {
build = {
electronAppDir = "src";
Expand Down Expand Up @@ -428,31 +429,6 @@ in
};
};

enhanced-resolve = {
fix-resolution-v4 = {
_condition = satisfiesSemver "^4.0.0";

# respect node path
postPatch = ''
${ensureFileModified} lib/ResolverFactory.js \
sed -zi 's/const symlinks =.*options.symlinks : true;/const symlinks = false;/g' lib/ResolverFactory.js
substituteInPlace lib/ResolverFactory.js --replace \
'let modules = options.modules || ["node_modules"];' \
'let modules = (options.modules || ["node_modules"]).concat(process.env.NODE_PATH.split( /[;:]/ ));'
'';
};

fix-resolution-v5 = {
_condition = satisfiesSemver "^5.0.0";

patches = [
./enhanced-resolve/npm-preserve-symlinks-v5.patch
./enhanced-resolve/respect-node-path-v5.patch
];
};
};

gifsicle = {
add-binary = {
buildScript = ''
Expand Down Expand Up @@ -600,15 +576,6 @@ in
};
};

rollup = {
preserve-symlinks = {
postPatch = ''
find -name '*.js' -exec \
${ensureFileModified} {} sed -i "s/preserveSymlinks: .*/preserveSymlinks: true,/g" {} \;
'';
};
};

simple-git-hooks = {
dont-postinstall = {
buildScript = "true";
Expand Down Expand Up @@ -706,16 +673,6 @@ in
};
};

# TODO: confirm this is actually working
typescript = {
preserve-symlinks = {
postPatch = ''
find -name '*.js' -exec \
${ensureFileModified} {} sed -i "s/options.preserveSymlinks/true/g; s/compilerOptions.preserveSymlinks/true/g" {} \;
'';
};
};

usb-detection = {
build = {
nativeBuildInputs = old:
Expand Down Expand Up @@ -842,21 +799,6 @@ in
};
};

# This should not be necessary, as this plugin claims to
# respect the `preserveSymlinks` option of rollup.
# Adding the NODE_PATH to the module directories fixes it for now.
"@rollup/plugin-node-resolve" = {
respect-node-path = {
postPatch = ''
for f in $(find -name '*.js'); do
substituteInPlace $f --replace \
"moduleDirectories: ['node_modules']," \
"moduleDirectories: ['node_modules'].concat(process.env.NODE_PATH.split( /[;:]/ )),"
done
'';
};
};

"@sentry/cli" = {
add-binary = {
buildScript = ''
Expand Down
14 changes: 0 additions & 14 deletions overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v4.patch

This file was deleted.

13 changes: 0 additions & 13 deletions overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v5.patch

This file was deleted.

29 changes: 23 additions & 6 deletions src/subsystems/nodejs/builders/granular/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# implements tree-of-symlinks node_modules
# If there are modules that can't handle that for some reason,
# a copy strategy could be made that copies just the problematic modules
# to the root and keeps symlinks for the rest.
{...}: {
type = "pure";

Expand Down Expand Up @@ -381,6 +385,13 @@
d2nLoadFuncsPhase = ''
# function to resolve symlinks to copies
symlinksToCopies() {
# TODO symlinksToCopies should take a list of names and only copy those to project root
# That might be enough to handle problematic cases
# Bash has associative arrays and node_module cannot have cycles,
# so it can be implemented as a recursive function
echo "ERROR: symlinksToCopies doesn't work right now, make sure you actually still need it"
exit 1
local dir="$1"
echo "transforming symlinks to copies..."
Expand Down Expand Up @@ -484,12 +495,6 @@
else
exit 1
fi
# configure typescript to resolve symlinks locally
# disabled since it should just work
# if [ -f ./tsconfig.json ]; then
# node ${./tsconfig-to-json.js}
# fi
'';

# - links dependencies into the node_modules directory + adds bin to PATH
Expand Down Expand Up @@ -592,4 +597,16 @@
// {sourceInfo = getSourceSpec name version;};
in
outputs;

extraArgs = {
nodejs = {
description = "nodejs version to use for building";
default = "14";
examples = [
"14"
"16"
];
type = "argument";
};
};
}
21 changes: 0 additions & 21 deletions src/subsystems/nodejs/builders/granular/tsconfig-to-json.js

This file was deleted.

0 comments on commit df4311b

Please sign in to comment.