-
-
Notifications
You must be signed in to change notification settings - Fork 17.4k
prettier: Add official plugins #442943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
prettier: Add official plugins #442943
Conversation
Main intent is to provide Prettier plugins for PR NixOS#442463 to consume. Prettier provides, at time of this commit, four [official](https://prettier.io/docs/plugins/#official-plugins) plugins. And there are about two dozen [community](https://prettier.io/docs/plugins/#community-plugins) plugins available too. So it seems wise to leverage existing code, where possible, and follow examples provided by similar NPM projects that have been packaged with plugins. Much of these changes are based on examples found from; - `./pkgs/by-name/le/lessc/plugins/` - `./pkgs/development/node-packages/` ... as well as documentation provided in; - `./doc/languages-frameworks/javascript.section.md`
This _should_ be the final, for now, officially supported plugin from Prettier to be added via this patch-set.
⚠️ this will be a source of future maintenance friction.
| inherit system; | ||
| }, | ||
| system ? builtins.currentSystem, | ||
| nodejs ? pkgs."nodejs_22", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This shouldn't need quotes, because underscore is not a special character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top of that file says;
# This file has been generated by node2nix 1.11.1. Do not edit!
... I'll remove the quotes, but expect 'em to resurrect next time node2nix gets ideas ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed that. I'd just leave it in that case.
| @@ -0,0 +1,73 @@ | |||
| #!/usr/bin/env nix-shell | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file supposed to be included?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly node2nix blessed us with it, and doing a bit of vimgrep /remove-attr/ pkgs/by-name/pr/prettier/plugins/* exposes a note;
pkgs/by-name/pr/prettier/plugins/aliases.nix
### Deprecated aliases - for backward compatibility
###
### !!! NOTE !!!
### Use `./remove-attr.py [attrname]` in this directory to remove your alias
### from the `nodePackages` set without regenerating the entire file.... I'm not sure if it needs to be included at this point 🤷
| @@ -0,0 +1,23 @@ | |||
| # Do not use overrides in this file to add `meta.mainProgram` to packages. Use `./main-programs.nix` | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a no-op right now? If so, can we exclude it until it's needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is loaded by pkgs/by-name/pr/prettier/plugins/default.nix;
extensions = composeManyExtensions [
aliases
mainProgramOverrides
(import ./overrides.nix { inherit pkgs nodejs; })
];... which I think was also generated by node2nix so, similar to removing other files it generates, it is likely to resurrect itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, looks like all the extra code is node2nix's, let's just keep it if other reviewers agree. I'm not sure what the norm is.
|
I would much rather this use the npm/yarn/pnpm tooling built into nixpkgs, as node2nix-generated files are generally more difficult to maintain. Can this PR use that instead? |
... Perhaps?... if ya can point me to the instructions, and it ain't too much trouble, I may be able to convert and after it looks good squash the Git-commit-churn ;-) |
https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#buildnpmpackage-javascript-buildnpmpackage has the instructions for packages that rely on npm, and if you scroll down you'll see instructions for pnpm- and yarn-based packages. |
Thanks!!! Seems the Prettier main package provides a Edit; I've got issues, skill issues x-)
Tried copy/pastying the examples provided by let
gitpkgs = import /home/s0ands0/git/hub/NixOS/nixpkgs/wt/prettier-plugins-official { };
in
{
lib ? gitpkgs.lib,
stdenv ? gitpkgs.stdenv,
fetchFromGitHub ? gitpkgs.fetchFromGitHub,
fetchYarnDeps ? gitpkgs.fetchYarnDeps,
yarnConfigHook ? gitpkgs.yarnConfigHook,
yarnBuildHook ? gitpkgs.yarnBuildHook,
yarnInstallHook ? gitpkgs.yarnInstallHook,
nodejs ? gitpkgs.nodejs,
plugins ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
pname = "prettier";
version = "3.6.2";
src = fetchFromGitHub {
owner = "prettier";
repo = "prettier";
tag = finalAttrs.version;
hash = "sha256-uMLRFBZP7/42R6nReONcb9/kVGCn3yGHLcLFajMZLmQ=";
};
yarnOfflineCache = fetchYarnDeps {
yarnLock = finalAttrs.src + "/yarn.lock";
hash = "";
};
nativeBuildInputs = [
yarnConfigHook
yarnBuildHook
yarnInstallHook
nodejs
];
meta = {
changelog = "https://github.com/prettier/prettier/blob/${finalAttrs.version}/CHANGELOG.md";
description = "Code formatter";
homepage = "https://prettier.io/";
license = lib.licenses.mit;
mainProgram = "prettier";
maintainers = with lib.maintainers; [
l0b0
S0AndS0
];
};
})... but, running And checking the "Full logs" didn't illuminate why I like the idea of yarn, especially if it acktually reduces the grossness needed to inject plugins, but at this point I kinda prefer something that works; even if it lurches x-) |
Prettier uses yarn berry, so you want to scroll down to the Yarn Berry section below that and use that instead. You'll have to provide your own buildPhase and installPhase but otherwise should be similar. |
Main intent is to provide Prettier plugins for PR #442463 to consume.
Prettier provides, at time of this commit, four official plugins. And there are about two dozen community plugins available too.
So it seems wise to leverage existing code, where possible, and follow examples provided by similar NPM projects that have been packaged with plugins.
Much of these changes are based on examples found from;
./pkgs/by-name/le/lessc/plugins/./pkgs/development/node-packages/... as well as documentation provided in;
./doc/languages-frameworks/javascript.section.mdMost of the changes from above references are under;
./pkgs/by-name/pr/prettier/plugins/aliases.nix, within themapAliasescall near end of file./pkgs/by-name/pr/prettier/plugins/node-packages.json, which lists NPM package names./pkgs/by-name/pr/prettier/package.nix, which updates doc-comment and addspassthru.plugins... Other files were either copy/pasted, and slightly modified, or generated via the
./pkgs/by-name/pr/prettier/plugins/generate.shscript.Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.
Edit 2025-09-14 16:41 UTC
Not sure what should be done about the linter error;
... because the
plugins/composition.nixfile's first line clearly states# This file has been generated by node2nix 1.11.1. Do not edit!, so manually fixing things are likely to be undone by next person (or myself) who updates plugins via thegenerate.shscript.The
plugins/default.nixis passing/forwarding the attrs in, so manually removing the? ...stuff shouldn't break anything.