···
+
Prettier with plugins and Vim Home Manager configuration
+
pkgs.prettier.override {
+
plugins = with pkgs.nodePackages; [
···
+
exportRelativePathOf (builtins.fromJSON "./package.json")
+
lib/node_modules/prettier-plugin-toml/./lib/index.cjs
+
exportRelativePathOf :: AttrSet => String
+
: Attribute set with shape similar to `package.json` file
+
nodeExportAttrAddresses = [
+
addresses: default: attrs:
+
if builtins.length addresses == 0 then
+
addressNext = builtins.head addresses;
+
addressesRemaning = lib.lists.drop 1 addresses;
+
lib.attrByPath addressNext (recAttrByPath addressesRemaning default attrs) attrs;
+
recAttrByPath nodeExportAttrAddresses (builtins.head (
+
lib.attrByPath [ "prettier" "plugins" ] [ "null" ] packageJsonAttrs
+
nodeEntryPointOf pkgs.nodePackages.prettier-plugin-toml
+
/nix/store/<NAR_HASH>-prettier-plugin-toml-<VERSION>/lib/node_modules/prettier-plugin-toml/./lib/index.cjs
+
nodeEntryPointOf :: AttrSet => String
+
: Attribute set with `.packageName` and `.outPath` defined
+
pluginDir = "${plugin.outPath}/lib/node_modules/${plugin.packageName}";
+
packageJsonAttrs = builtins.fromJSON (builtins.readFile "${pluginDir}/package.json");
+
exportPath = exportRelativePathOf packageJsonAttrs;
+
pathAbsoluteNaive = "${pluginDir}/${exportPath}";
+
pathAbsoluteFallback = "${pluginDir}/${exportPath}.js";
+
if builtins.pathExists pathAbsoluteNaive then
+
else if builtins.pathExists pathAbsoluteFallback then
+
${plugin.packageName}: error context, tried finding entry point under;
+
pathAbsoluteNaive -> ${pathAbsoluteNaive}
+
pathAbsoluteFallback -> ${pathAbsoluteFallback}
+
'' throw ''${plugin.packageName}: does not provide parse-able entry point'';
stdenv.mkDerivation (finalAttrs: {
···
makeBinaryWrapper "${lib.getExe nodejs}" "$out/bin/prettier" \
--add-flags "$out/bin/prettier.cjs"
+
+ lib.optionalString (builtins.length plugins > 0) ''
+
wrapProgram $out/bin/prettier --add-flags "${
+
builtins.concatStringsSep " " (lib.map (plugin: "--plugin=${nodeEntryPointOf plugin}") plugins)
···
homepage = "https://prettier.io/";
license = lib.licenses.mit;
mainProgram = "prettier";
+
maintainers = with lib.maintainers; [