diff mbox series

[bug#67019,v2,03/16] gnu: Add lessc.

Message ID 83a3e16cf7d86bb07f6cf728acf3872dcae604dc.1700161584.git.philip@philipmcgrath.com
State New
Headers show
Series gnu: Add KaTeX, lessc, and flow-remove-types. | expand

Commit Message

Philip McGrath Nov. 16, 2023, 7:15 p.m. UTC
* gnu/packages/web.scm (lessc): New variable.
---
 gnu/packages/web.scm | 183 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 183 insertions(+)
diff mbox series

Patch

diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 389f7d1375..9efc6ebc9d 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -65,6 +65,7 @@ 
 ;;; Copyright © 2023 Christopher Howard <christopher@librehacker.com>
 ;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
 ;;; Copyright © 2023 Evgeny Pisemsky <evgeny@pisemsky.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -99,6 +100,7 @@  (define-module (gnu packages web)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system go)
   #:use-module (guix build-system meson)
+  #:use-module (guix build-system node)
   #:use-module (guix build-system perl)
   #:use-module (guix build-system pyproject)
   #:use-module (guix build-system python)
@@ -169,6 +171,7 @@  (define-module (gnu packages web)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages networking)
   #:use-module (gnu packages node)
+  #:use-module (gnu packages node-xyz)
   #:use-module (gnu packages nss)
   #:use-module (gnu packages openldap)
   #:use-module (gnu packages openstack)
@@ -2344,6 +2347,186 @@  (define-public sassc/libsass-3.5
                                                     "0830pjcvhzxh6yixj82x5k5r1xnadjqzi16kp53213icbly0r9ma")))))))
     (properties '((hidden? . #t)))))
 
+(define-public lessc
+  (package
+    (name "lessc")
+    (version "4.2.0")
+    (source
+     (origin (method git-fetch)
+             (uri (git-reference
+                   (url "https://github.com/less/less.js")
+                   (commit (string-append "v" version))))
+             (sha256
+              (base32 "1b6anlafk7lnayxy3vhsi474jcdah2ffaw2qyac5s2ibxb1wmr54"))
+             (snippet
+              #~(begin
+                  (use-modules (guix build utils))
+                  (delete-file-recursively "packages/less/dist")))
+             (file-name (git-file-name name version))))
+    (build-system node-build-system)
+    (native-inputs (list esbuild))
+    (inputs (list node-copy-anything))
+    (arguments
+     (list
+      #:tests? #f ; many more dependencies
+      #:modules
+      `((guix build node-build-system)
+        (ice-9 match)
+        (guix build utils))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda args
+              (chdir "packages/less")))
+          (add-after 'patch-dependencies 'delete-dependencies
+            (lambda args
+              (delete-dependencies
+               '(;; dependencies
+                 "parse-node-version" ; patched out
+                 "tslib" ; probably not needed w/ esbuild
+                 ;; devDependencies
+                 "@less/test-data"
+                 "@less/test-import-module"
+                 "@rollup/plugin-commonjs"
+                 "@rollup/plugin-json"
+                 "@rollup/plugin-node-resolve"
+                 "@typescript-eslint/eslint-plugin"
+                 "@typescript-eslint/parser"
+                 "benny"
+                 "bootstrap-less-port"
+                 "chai"
+                 "cross-env"
+                 "diff"
+                 "eslint"
+                 "fs-extra"
+                 "git-rev"
+                 "globby"
+                 "grunt"
+                 "grunt-cli"
+                 "grunt-contrib-clean"
+                 "grunt-contrib-connect"
+                 "grunt-eslint"
+                 "grunt-saucelabs"
+                 "grunt-shell"
+                 "html-template-tag"
+                 "jit-grunt"
+                 "less-plugin-autoprefix"
+                 "less-plugin-clean-css"
+                 "minimist"
+                 "mocha"
+                 "mocha-headless-chrome"
+                 "mocha-teamcity-reporter"
+                 "nock"
+                 "npm-run-all"
+                 "performance-now"
+                 "phin"
+                 "promise"
+                 "read-glob"
+                 "resolve"
+                 "rollup"
+                 "rollup-plugin-terser"
+                 "rollup-plugin-typescript2"
+                 "semver"
+                 "shx"
+                 "time-grunt"
+                 "ts-node"
+                 "typescript"
+                 "uikit"
+                 ;; optionalDependencies
+                 "errno"
+                 "graceful-fs"
+                 "image-size"
+                 "make-dir"
+                 "mime"
+                 "needle"
+                 "source-map"))))
+          (add-after 'delete-dependencies 'avoid-parse-node-version
+            (lambda args
+              (define version
+                #$(package-version this-package))
+              (substitute* "src/less/index.js"
+                (("import [{] version [}]" orig)
+                 (string-append "// " orig))
+                (("import parseVersion from 'parse-node-version';" orig)
+                 (string-append "// " orig))
+                (("const v = parseVersion[(]`v\\$[{]version[}]`[)];" orig)
+                 (string-append "// " orig))
+                (("(version: )(\\[v\\.major, v\\.minor, v\\.patch],)" _ lhs rhs)
+                 (string-append
+                  lhs
+                  "["
+                  (string-join
+                   (list-head (string-split
+                               version (char-set-complement char-set:digit))
+                              3)
+                   ", ")
+                  "], // "
+                  rhs)))))
+          (add-after 'avoid-parse-node-version 'do-not-target-es5
+            (lambda args
+              ;; esbuild can't compile all features to ES5
+              (with-atomic-json-file-replacement "tsconfig.json"
+                (match-lambda
+                  (('@ . alist)
+                   (cons '@
+                    (map (match-lambda
+                           (("compilerOptions" '@ . alist)
+                            `("compilerOptions" @ ,@(delete '("target" . "ES5")
+                                                            alist)))
+                           (other
+                            other))
+                         alist)))))))
+          (add-after 'do-not-target-es5 'patch-build-script
+            (lambda args
+              (define new-build-script
+                (string-join
+                 `("esbuild"
+                   "--platform=node"
+                   "--format=cjs"
+                   "--outdir=lib"
+                   ,@(find-files "src/less" "\\.js$")
+                   ,@(find-files "src/less-node" "\\.js$"))))
+              (with-atomic-json-file-replacement "package.json"
+                (match-lambda
+                  (('@ . alist)
+                   (cons '@
+                    (map (match-lambda
+                           (("scripts" @ . alist)
+                            `("scripts" @ ,@(map (match-lambda
+                                                   (("build" . _)
+                                                    (cons "build"
+                                                          new-build-script))
+                                                   (other
+                                                    other))
+                                                 alist)))
+                           (other
+                            other))
+                         alist)))))))
+          (add-after 'build 'build-browser
+            (lambda args
+              (invoke "esbuild"
+                      "--bundle"
+                      "--platform=browser"
+                      "--format=cjs"
+                      "--outfile=dist/less.js"
+                      "src/less-browser/bootstrap.js")
+              (invoke "esbuild"
+                      "--bundle"
+                      "--minify"
+                      "--sourcemap"
+                      "--platform=browser"
+                      "--format=cjs"
+                      "--outfile=dist/less.min.js"
+                      "src/less-browser/bootstrap.js"))))))
+    (home-page "https://lesscss.org")
+    (synopsis "Compiler for @acronym{Less} @acronym{CSS} language extension")
+    ;; XXX: @abbr{} seems better for Less (which is always capitalized that
+    ;; way), but it is rejected as invalid Texinfo markup here.
+    (description "@acronym{Less, Leaner Style Sheets} is a
+backwards-compatible language extension for @acronym{CSS}.  This package
+provides @command{lessc}, which compiles Less files to plain @acronym{CSS}.")
+    (license license:asl2.0)))
+
 
 (define-public perl-apache-logformat-compiler
   (package