Skip to content

Commit df4311b

Browse files
committed
nodejs: remove preserveSymlinks hacks
1 parent 54cf131 commit df4311b

File tree

5 files changed

+24
-113
lines changed

5 files changed

+24
-113
lines changed

overrides/nodejs/default.nix

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ in
104104
};
105105
};
106106

107+
# TODO not sure if this works
107108
edex-ui = {
108109
build = {
109110
electronAppDir = "src";
@@ -428,31 +429,6 @@ in
428429
};
429430
};
430431

431-
enhanced-resolve = {
432-
fix-resolution-v4 = {
433-
_condition = satisfiesSemver "^4.0.0";
434-
435-
# respect node path
436-
postPatch = ''
437-
${ensureFileModified} lib/ResolverFactory.js \
438-
sed -zi 's/const symlinks =.*options.symlinks : true;/const symlinks = false;/g' lib/ResolverFactory.js
439-
440-
substituteInPlace lib/ResolverFactory.js --replace \
441-
'let modules = options.modules || ["node_modules"];' \
442-
'let modules = (options.modules || ["node_modules"]).concat(process.env.NODE_PATH.split( /[;:]/ ));'
443-
'';
444-
};
445-
446-
fix-resolution-v5 = {
447-
_condition = satisfiesSemver "^5.0.0";
448-
449-
patches = [
450-
./enhanced-resolve/npm-preserve-symlinks-v5.patch
451-
./enhanced-resolve/respect-node-path-v5.patch
452-
];
453-
};
454-
};
455-
456432
gifsicle = {
457433
add-binary = {
458434
buildScript = ''
@@ -600,15 +576,6 @@ in
600576
};
601577
};
602578

603-
rollup = {
604-
preserve-symlinks = {
605-
postPatch = ''
606-
find -name '*.js' -exec \
607-
${ensureFileModified} {} sed -i "s/preserveSymlinks: .*/preserveSymlinks: true,/g" {} \;
608-
'';
609-
};
610-
};
611-
612579
simple-git-hooks = {
613580
dont-postinstall = {
614581
buildScript = "true";
@@ -706,16 +673,6 @@ in
706673
};
707674
};
708675

709-
# TODO: confirm this is actually working
710-
typescript = {
711-
preserve-symlinks = {
712-
postPatch = ''
713-
find -name '*.js' -exec \
714-
${ensureFileModified} {} sed -i "s/options.preserveSymlinks/true/g; s/compilerOptions.preserveSymlinks/true/g" {} \;
715-
'';
716-
};
717-
};
718-
719676
usb-detection = {
720677
build = {
721678
nativeBuildInputs = old:
@@ -842,21 +799,6 @@ in
842799
};
843800
};
844801

845-
# This should not be necessary, as this plugin claims to
846-
# respect the `preserveSymlinks` option of rollup.
847-
# Adding the NODE_PATH to the module directories fixes it for now.
848-
"@rollup/plugin-node-resolve" = {
849-
respect-node-path = {
850-
postPatch = ''
851-
for f in $(find -name '*.js'); do
852-
substituteInPlace $f --replace \
853-
"moduleDirectories: ['node_modules']," \
854-
"moduleDirectories: ['node_modules'].concat(process.env.NODE_PATH.split( /[;:]/ )),"
855-
done
856-
'';
857-
};
858-
};
859-
860802
"@sentry/cli" = {
861803
add-binary = {
862804
buildScript = ''

overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v4.patch

Lines changed: 0 additions & 14 deletions
This file was deleted.

overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v5.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/subsystems/nodejs/builders/granular/default.nix

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# implements tree-of-symlinks node_modules
2+
# If there are modules that can't handle that for some reason,
3+
# a copy strategy could be made that copies just the problematic modules
4+
# to the root and keeps symlinks for the rest.
15
{...}: {
26
type = "pure";
37

@@ -381,6 +385,13 @@
381385
d2nLoadFuncsPhase = ''
382386
# function to resolve symlinks to copies
383387
symlinksToCopies() {
388+
# TODO symlinksToCopies should take a list of names and only copy those to project root
389+
# That might be enough to handle problematic cases
390+
# Bash has associative arrays and node_module cannot have cycles,
391+
# so it can be implemented as a recursive function
392+
echo "ERROR: symlinksToCopies doesn't work right now, make sure you actually still need it"
393+
exit 1
394+
384395
local dir="$1"
385396
386397
echo "transforming symlinks to copies..."
@@ -484,12 +495,6 @@
484495
else
485496
exit 1
486497
fi
487-
488-
# configure typescript to resolve symlinks locally
489-
# disabled since it should just work
490-
# if [ -f ./tsconfig.json ]; then
491-
# node ${./tsconfig-to-json.js}
492-
# fi
493498
'';
494499

495500
# - links dependencies into the node_modules directory + adds bin to PATH
@@ -592,4 +597,16 @@
592597
// {sourceInfo = getSourceSpec name version;};
593598
in
594599
outputs;
600+
601+
extraArgs = {
602+
nodejs = {
603+
description = "nodejs version to use for building";
604+
default = "14";
605+
examples = [
606+
"14"
607+
"16"
608+
];
609+
type = "argument";
610+
};
611+
};
595612
}

src/subsystems/nodejs/builders/granular/tsconfig-to-json.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)