From df4311bacd55c6b88f7c636935d5d175fe519094 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Sat, 16 Jul 2022 23:00:44 +0200 Subject: [PATCH] nodejs: remove preserveSymlinks hacks --- overrides/nodejs/default.nix | 60 +------------------ .../npm-preserve-symlinks-v4.patch | 14 ----- .../npm-preserve-symlinks-v5.patch | 13 ---- .../nodejs/builders/granular/default.nix | 29 +++++++-- .../builders/granular/tsconfig-to-json.js | 21 ------- 5 files changed, 24 insertions(+), 113 deletions(-) delete mode 100644 overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v4.patch delete mode 100644 overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v5.patch delete mode 100644 src/subsystems/nodejs/builders/granular/tsconfig-to-json.js diff --git a/overrides/nodejs/default.nix b/overrides/nodejs/default.nix index 1a37cf2f4c..7f51653d56 100644 --- a/overrides/nodejs/default.nix +++ b/overrides/nodejs/default.nix @@ -104,6 +104,7 @@ in }; }; + # TODO not sure if this works edex-ui = { build = { electronAppDir = "src"; @@ -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 = '' @@ -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"; @@ -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: @@ -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 = '' diff --git a/overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v4.patch b/overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v4.patch deleted file mode 100644 index 262a7ed055..0000000000 --- a/overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v4.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/lib/ResolverFactory.js b/lib/ResolverFactory.js -index 2649915..93dbc96 100644 ---- a/lib/ResolverFactory.js -+++ b/lib/ResolverFactory.js -@@ -73,8 +73,7 @@ exports.createResolver = function(options) { - let alias = options.alias || []; - - // Resolve symlinks to their symlinked location -- const symlinks = -- typeof options.symlinks !== "undefined" ? options.symlinks : true; -+ const symlinks = false; - - // Resolve to a context instead of a file - const resolveToContext = options.resolveToContext || false; diff --git a/overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v5.patch b/overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v5.patch deleted file mode 100644 index f591ad2642..0000000000 --- a/overrides/nodejs/enhanced-resolve/npm-preserve-symlinks-v5.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/lib/ResolverFactory.js b/lib/ResolverFactory.js -index 21ac9b0..49bca68 100644 ---- a/lib/ResolverFactory.js -+++ b/lib/ResolverFactory.js -@@ -208,7 +208,7 @@ function createOptions(options) { - options.unsafeCache && typeof options.unsafeCache !== "object" - ? {} - : options.unsafeCache || false, -- symlinks: typeof options.symlinks !== "undefined" ? options.symlinks : true, -+ symlinks: false, - resolver: options.resolver, - modules: mergeFilteredToArray( - Array.isArray(options.modules) diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular/default.nix index c9d061a4c0..b237fe9465 100644 --- a/src/subsystems/nodejs/builders/granular/default.nix +++ b/src/subsystems/nodejs/builders/granular/default.nix @@ -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"; @@ -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..." @@ -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 @@ -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"; + }; + }; } diff --git a/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js b/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js deleted file mode 100644 index c67956b245..0000000000 --- a/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js +++ /dev/null @@ -1,21 +0,0 @@ -try { - require.resolve("typescript"); -} catch (e) { - process.exit(0); -} - -const ts = require("typescript"); -const fs = require("fs"); - -try { - const data = fs.readFileSync("tsconfig.json", "utf8"); -} catch (err) { - console.error(err); -} - -config = ts.parseConfigFileTextToJson(data); - -// https://www.typescriptlang.org/tsconfig#preserveSymlinks -config.compilerOptions.preserveSymlinks = true; - -fs.writeFileSync("tsconfig.json", JSON.stringify(config));