wrap typescript in overrides

This commit is contained in:
hsjobeki 2022-11-16 10:53:00 +01:00
parent 48c92cfd39
commit c991447b05
3 changed files with 41 additions and 61 deletions

View File

@ -109,6 +109,27 @@ in
electronAppDir = "src";
preBuild = {outputs, ...}: ''
# function to resolve symlinks to copies
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
}
# link dependencies of subpackage
ln -s \
${outputs.subPackages.edex-ui-subpackage.packages.edex-ui-subpackage}/lib/node_modules/edex-ui-subpackage/node_modules \
@ -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"
'';
};
};

View File

@ -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

View File

@ -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);