2024-05-15 15:35:15 +00:00
{ lib
, buildNpmPackage
2024-07-27 06:49:29 +00:00
, stdenv
2024-05-15 15:35:15 +00:00
, fetchYarnDeps
2024-07-27 06:49:29 +00:00
, yarnConfigHook
2024-05-15 15:35:15 +00:00
, fetchFromGitHub
, typescript
, jq
, fetchpatch
} :
let
# Instead of the build script that spectral-language-server provides (ref: https://github.com/luizcorreia/spectral-language-server/blob/master/script/vscode-spectral-build.sh), we build vscode-spectral manually.
# This is because the script must go through the network and will not work under the Nix sandbox environment.
2024-07-27 06:49:29 +00:00
vscodeSpectral = stdenv . mkDerivation ( finalAttrs : {
2024-05-15 15:35:15 +00:00
pname = " v s c o d e - s p e c t r a l " ;
version = " 1 . 1 . 2 " ;
src = fetchFromGitHub {
owner = " s t o p l i g h t i o " ;
repo = " v s c o d e - s p e c t r a l " ;
2024-07-27 06:49:29 +00:00
rev = " v ${ finalAttrs . version } " ;
2024-05-15 15:35:15 +00:00
hash = " s h a 2 5 6 - T W y + b C 6 q h T K D Y 8 7 4 O R T B b v C I H 8 y c p m B i U 8 G L Y x B I i A s = " ;
} ;
offlineCache = fetchYarnDeps {
2024-07-27 06:49:29 +00:00
yarnLock = finalAttrs . src + " / y a r n . l o c k " ;
2024-05-15 15:35:15 +00:00
hash = " s h a 2 5 6 - a m 2 7 A 9 V y F o X u O l g G 9 m n v N q V 3 Q 7 B i 7 G J z D q q V F G D V W I A = " ;
} ;
2024-07-27 06:49:29 +00:00
nativeBuildInputs = [ typescript jq yarnConfigHook ] ;
2024-05-15 15:35:15 +00:00
postPatch = ''
cp server/tsconfig.json server/tsconfig.json.bak
jq ' . compilerOptions + = { " m o d u l e " : " N o d e N e x t " , " m o d u l e R e s o l u t i o n " : " N o d e N e x t " } ' server/tsconfig.json.bak > server/tsconfig.json
'' ;
buildPhase = ''
runHook preBuild
# FIXME: vscode-spactral depends on @rollup/pluginutils, but it may have a bug that doesn't provide the type definitions for NodeNext module resolution. (ref: https://github.com/rollup/plugins/issues/1192)
# tsc detects some type errors in the code. However we ignore this because it's not a problem for the final build if server/dist is generated.
tsc - p server || true
test - d server/dist
runHook postBuild
'' ;
installPhase = ''
runHook preInstall
mkdir - p $ out
cp - R server/dist $ out
runHook postInstall
'' ;
meta = with lib ; {
homepage = " h t t p s : / / g i t h u b . c o m / s t o p l i g h t i o / v s c o d e - s p e c t r a l " ;
description = " V S C o d e e x t e n s i o n b r i n g i n g t h e a w e s o m e S p e c t r a l J S O N / Y A M L l i n t e r w i t h O p e n A P I / A s y n c A P I s u p p o r t " ;
license = licenses . asl20 ;
} ;
2024-07-27 06:49:29 +00:00
} ) ;
2024-05-15 15:35:15 +00:00
in
buildNpmPackage rec {
pname = " s p e c t r a l - l a n g u a g e - s e r v e r " ;
version = " 1 . 0 . 8 - u n s t a b l e - 2 0 2 3 - 0 6 - 0 6 " ;
src = fetchFromGitHub {
owner = " l u i z c o r r e i a " ;
repo = " s p e c t r a l - l a n g u a g e - s e r v e r " ;
rev = " c 9 a 7 7 5 2 b 0 8 e 6 b b a 9 3 7 e f 4 f 5 4 3 5 9 0 2 a f d 4 1 b 6 9 5 7 f " ;
hash = " s h a 2 5 6 - V D 2 a A z l C n J 6 m x P U S b N R f M O l s l M 8 k L P q r A I 2 a h 6 s X 9 c U = " ;
} ;
npmDepsHash = " s h a 2 5 6 - i x A X y / r R k y W L 3 j d A k r X J h 1 q h W c K I k r 5 n H / B h u 2 J V 6 k 8 = " ;
patches = [
# https://github.com/luizcorreia/spectral-language-server/pull/15
( fetchpatch {
name = " f i x - p a c k a g e - l o c k . p a t c h " ;
url = " h t t p s : / / g i t h u b . c o m / l u i z c o r r e i a / s p e c t r a l - l a n g u a g e - s e r v e r / c o m m i t / 9 0 9 7 0 4 8 5 0 d d 1 0 e 7 b 3 2 8 f c 7 d 1 5 f 8 b 0 7 c d e f 8 8 8 9 9 d . p a t c h " ;
hash = " s h a 2 5 6 - + m N 9 3 x P 4 H C l l 4 d T c n h 2 W / m 9 k 3 X o v v g n B 6 A O m u J p Z U Z 0 = " ;
} )
] ;
dontNpmBuild = true ;
npmFlags = [ " - - i g n o r e - s c r i p t s " ] ;
installPhase = ''
runHook preInstall
mkdir - p $ out/bin
mkdir - p $ out/node_modules
mkdir - p $ out/dist/spectral-language-server
cp - R $ { vscodeSpectral } /dist /* $ o u t / d i s t / s p e c t r a l - l a n g u a g e - s e r v e r /
cp ./bin /* $ o u t / b i n
cp - R ./node_modules /* $ o u t / n o d e _ m o d u l e s
runHook postInstall
'' ;
meta = with lib ; {
homepage = " h t t p s : / / g i t h u b . c o m / l u i z c o r r e i a / s p e c t r a l - l a n g u a g e - s e r v e r " ;
description = " A w e s o m e S p e c t r a l J S O N / Y A M L l i n t e r w i t h O p e n A P I / A s y n c A P I s u p p o r t " ;
maintainers = with maintainers ; [ momeemt ] ;
license = licenses . mit ;
mainProgram = " s p e c t r a l - l a n g u a g e - s e r v e r " ;
} ;
}