mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-15 14:26:33 +01:00
146 lines
4 KiB
Nix
146 lines
4 KiB
Nix
{
|
|
lib,
|
|
stdenv,
|
|
buildNpmPackage,
|
|
fetchFromGitHub,
|
|
autoconf,
|
|
automake,
|
|
makeWrapper,
|
|
python311,
|
|
runCommand,
|
|
textlint,
|
|
textlint-plugin-latex2e,
|
|
textlint-rule-abbr-within-parentheses,
|
|
textlint-rule-alex,
|
|
textlint-rule-common-misspellings,
|
|
textlint-rule-diacritics,
|
|
textlint-rule-en-max-word-count,
|
|
textlint-rule-max-comma,
|
|
textlint-rule-no-start-duplicated-conjunction,
|
|
textlint-rule-period-in-list-item,
|
|
textlint-rule-preset-ja-technical-writing,
|
|
textlint-rule-prh,
|
|
textlint-rule-stop-words,
|
|
textlint-rule-terminology,
|
|
textlint-rule-unexpanded-acronym,
|
|
textlint-rule-write-good,
|
|
}:
|
|
|
|
buildNpmPackage rec {
|
|
pname = "textlint";
|
|
version = "14.2.0";
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "textlint";
|
|
repo = "textlint";
|
|
rev = "refs/tags/v${version}";
|
|
hash = "sha256-KNOloSc66IX8GApI5JJ7z2DxPthOaZ3xpw0rlmAgIXc=";
|
|
};
|
|
|
|
patches = [
|
|
# this package uses lerna and requires building many workspaces.
|
|
# this patch removes unnecessary workspaces,
|
|
# reducing package size and build time.
|
|
./remove-workspaces.patch
|
|
];
|
|
|
|
npmDepsHash = "sha256-/m37+odnYsegls2JamkQsHT39/APynppQiTMtRh3ycE=";
|
|
|
|
nativeBuildInputs =
|
|
[
|
|
autoconf
|
|
automake
|
|
]
|
|
++ lib.optionals (stdenv.hostPlatform.system == "aarch64-linux") [
|
|
# File "/build/source/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
|
|
# npm error ModuleNotFoundError: No module named 'distutils'
|
|
python311
|
|
];
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/{bin,lib}
|
|
|
|
npm prune --omit=dev --no-save
|
|
rm -r node_modules/.cache
|
|
rm -r packages/textlint-{scripts,tester}
|
|
rm -r packages/@textlint/*/test
|
|
|
|
cp -r node_modules $out/lib
|
|
cp -r packages $out/lib
|
|
ln -s $out/lib/node_modules/textlint/bin/textlint.js $out/bin/textlint
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
passthru = {
|
|
withPackages =
|
|
ps:
|
|
runCommand "textlint-with-packages" { nativeBuildInputs = [ makeWrapper ]; } ''
|
|
makeWrapper ${textlint}/bin/textlint $out/bin/textlint \
|
|
--set NODE_PATH ${lib.makeSearchPath "lib/node_modules" ps}
|
|
'';
|
|
|
|
testPackages =
|
|
{
|
|
rule,
|
|
testFile,
|
|
pname ? rule.pname,
|
|
plugin ? null,
|
|
}:
|
|
let
|
|
ruleName = lib.removePrefix "textlint-rule-" rule.pname;
|
|
isPreset = lib.hasPrefix "preset-" ruleName;
|
|
ruleName' = lib.removePrefix "preset-" ruleName;
|
|
pluginName = lib.removePrefix "textlint-plugin-" plugin.pname;
|
|
args =
|
|
"${testFile} ${if isPreset then "--preset" else "--rule"} ${ruleName'}"
|
|
+ lib.optionalString (plugin != null) " --plugin ${pluginName}";
|
|
in
|
|
{
|
|
"${pname}-test" =
|
|
runCommand "${pname}-test"
|
|
{
|
|
nativeBuildInputs = [
|
|
(textlint.withPackages [
|
|
rule
|
|
plugin
|
|
])
|
|
];
|
|
}
|
|
''
|
|
grep ${ruleName'} <(textlint ${args}) > $out
|
|
'';
|
|
};
|
|
|
|
tests = lib.mergeAttrsList (
|
|
map (package: package.tests) [
|
|
textlint-plugin-latex2e
|
|
textlint-rule-abbr-within-parentheses
|
|
textlint-rule-alex
|
|
textlint-rule-common-misspellings
|
|
textlint-rule-diacritics
|
|
textlint-rule-en-max-word-count
|
|
textlint-rule-max-comma
|
|
textlint-rule-no-start-duplicated-conjunction
|
|
textlint-rule-period-in-list-item
|
|
textlint-rule-preset-ja-technical-writing
|
|
textlint-rule-prh
|
|
textlint-rule-stop-words
|
|
textlint-rule-terminology
|
|
textlint-rule-unexpanded-acronym
|
|
textlint-rule-write-good
|
|
]
|
|
);
|
|
};
|
|
|
|
meta = {
|
|
description = "Pluggable natural language linter for text and markdown";
|
|
homepage = "https://github.com/textlint/textlint";
|
|
changelog = "https://github.com/textlint/textlint/blob/${src.rev}/CHANGELOG.md";
|
|
license = lib.licenses.mit;
|
|
maintainers = with lib.maintainers; [ natsukium ];
|
|
mainProgram = "textlint";
|
|
};
|
|
}
|