From c991447b05e637a3f9456d42eb5ab57eae696fca Mon Sep 17 00:00:00 2001 From: hsjobeki Date: Wed, 16 Nov 2022 10:53:00 +0100 Subject: [PATCH] wrap typescript in overrides --- overrides/nodejs/default.nix | 75 ++++++++++--------- .../builders/granular-nodejs/default.nix | 8 -- .../granular-nodejs/tsconfig-to-json.js | 19 ----- 3 files changed, 41 insertions(+), 61 deletions(-) delete mode 100644 src/subsystems/nodejs/builders/granular-nodejs/tsconfig-to-json.js diff --git a/overrides/nodejs/default.nix b/overrides/nodejs/default.nix index 14234141..59ef63a8 100644 --- a/overrides/nodejs/default.nix +++ b/overrides/nodejs/default.nix @@ -109,17 +109,38 @@ in electronAppDir = "src"; preBuild = {outputs, ...}: '' - # link dependencies of subpackage - ln -s \ - ${outputs.subPackages.edex-ui-subpackage.packages.edex-ui-subpackage}/lib/node_modules/edex-ui-subpackage/node_modules \ - ./src/node_modules + # function to resolve symlinks to copies + symlinksToCopies() { + local dir="$1" - # transform symlinked subpackage 'node-pty' to copies, - # in order to allow re-building - mv src/node_modules src/node_modules.bac - mkdir src/node_modules - cp -r src/node_modules.bac/* src/node_modules/ - symlinksToCopies ./src/node_modules/node-pty + echo "transforming symlinks to copies..." + for f in $(find -L "$dir" -xtype l); do + if [ -f $f ]; then + continue + fi + echo "copying $f" + chmod +wx $(dirname "$f") + mv "$f" "$f.bak" + mkdir "$f" + if [ -n "$(ls -A "$f.bak/")" ]; then + cp -r "$f.bak"/* "$f/" + chmod -R +w $f + fi + rm "$f.bak" + done + } + + # link dependencies of subpackage + ln -s \ + ${outputs.subPackages.edex-ui-subpackage.packages.edex-ui-subpackage}/lib/node_modules/edex-ui-subpackage/node_modules \ + ./src/node_modules + + # transform symlinked subpackage 'node-pty' to copies, + # in order to allow re-building + mv src/node_modules src/node_modules.bac + mkdir src/node_modules + cp -r src/node_modules.bac/* src/node_modules/ + symlinksToCopies ./src/node_modules/node-pty ''; }; }; @@ -738,26 +759,6 @@ in in "${pkg}/lib/node_modules/${pname}/node_modules") outputs.subPackages))} - symlinksToCopies() { - local dir="$1" - - echo "transforming symlinks to copies..." - for f in $(find -L "$dir" -xtype l); do - if [ -f $f ]; then - continue - fi - echo "copying $f" - chmod +wx $(dirname "$f") - mv "$f" "$f.bak" - mkdir "$f" - if [ -n "$(ls -A "$f.bak/")" ]; then - cp -r "$f.bak"/* "$f/" - chmod -R +w $f - fi - rm "$f.bak" - done - } - for dir in $(ls -d */); do if [ -f $dir/package.json ]; then echo "installing sub-package $dir" @@ -774,12 +775,18 @@ in }; }; - # TODO: confirm this is actually working + # Allways call tsc --preserveSymlinks + # This overrides the argument of tsconfig.json + # Is required for installMethod != "copy" typescript = { preserve-symlinks = { - postPatch = '' - find -name '*.js' -exec \ - ${ensureFileModified} {} sed -i "s/options.preserveSymlinks/true/g; s/compilerOptions.preserveSymlinks/true/g" {} \; + postInstall = '' + realTsc=$(realpath $out/bin/tsc) + rm $out/bin/tsc + makeWrapper \ + $realTsc \ + $out/bin/tsc \ + --add-flags " --preserveSymlinks" ''; }; }; diff --git a/src/subsystems/nodejs/builders/granular-nodejs/default.nix b/src/subsystems/nodejs/builders/granular-nodejs/default.nix index 570ff492..bbcf1c7c 100644 --- a/src/subsystems/nodejs/builders/granular-nodejs/default.nix +++ b/src/subsystems/nodejs/builders/granular-nodejs/default.nix @@ -390,14 +390,6 @@ else exit 1 fi - - # configure typescript - if [ -f ./tsconfig.json ] \ - && node -e 'require("typescript")' &>/dev/null; then - node ${./tsconfig-to-json.js} - ${pkgs.jq}/bin/jq ".compilerOptions.preserveSymlinks = true" tsconfig.json \ - | ${pkgs.moreutils}/bin/sponge tsconfig.json - fi ''; # - installs dependencies into the node_modules directory diff --git a/src/subsystems/nodejs/builders/granular-nodejs/tsconfig-to-json.js b/src/subsystems/nodejs/builders/granular-nodejs/tsconfig-to-json.js deleted file mode 100644 index 1ccd3db0..00000000 --- a/src/subsystems/nodejs/builders/granular-nodejs/tsconfig-to-json.js +++ /dev/null @@ -1,19 +0,0 @@ -try { - console.log(require.resolve("typescript")); -} catch(e) { - console.error("typescript is not found"); - process.exit(e.code); -} - -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) -newdata = JSON.stringify(config) -fs.writeFileSync('tsconfig.json', newdata);