Change Less to Sass
authorNick Downing <nick@ndcode.org>
Mon, 10 Jan 2022 23:13:43 +0000 (10:13 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 10 Jan 2022 23:13:43 +0000 (10:13 +1100)
SassCSSCache.js [moved from LessCSSCache.js with 75% similarity]
package.json

similarity index 75%
rename from LessCSSCache.js
rename to SassCSSCache.js
index 54b1619..43ceb0d 100644 (file)
 let BuildCache = require('@ndcode/build_cache')
 let disk_build = require('@ndcode/disk_build')
 let fs = require('fs')
-let less = require('less')
+let sass = require('sass')
 let path = require('path')
 let util = require('util')
 
 let fs_readFile = util.promisify(fs.readFile)
 let fs_writeFile = util.promisify(fs.writeFile)
 
-let LessCSSCache = function(root, diag1, diag) {
-  if (!this instanceof LessCSSCache)
-    throw new Error('LessCSSCache is a constructor')
+let SassCSSCache = function(root, diag1, diag) {
+  if (!this instanceof SassCSSCache)
+    throw new Error('SassCSSCache is a constructor')
   BuildCache.call(this, diag)
   this.diag1 = diag1
   this.root = root || '.'
 }
 
-LessCSSCache.prototype = Object.create(BuildCache.prototype)
+SassCSSCache.prototype = Object.create(BuildCache.prototype)
 
-LessCSSCache.prototype.build = async function(key, result) {
+SassCSSCache.prototype.build = async function(key, result) {
   let render = await disk_build(
     key,
     async temp_pathname => {
-      let render = await less.render(
-        await fs_readFile(key, {encoding: 'utf-8'}),
-        {
-          compress: true,
-          filename: key,
-          pathnames: [path.posix.dirname(key)],
-          rootkey: this.root
-        }
+      let render = await sass.compileAsync(
+        key,
+        {loadPaths: [path.posix.dirname(key)]}
       )
       await fs_writeFile(
         temp_pathname,
         render.css,
         {encoding: 'utf-8'}
       )
-      return render.imports
+      return render.loadedUrls
     },
     this.diag1
   )
@@ -67,4 +62,4 @@ LessCSSCache.prototype.build = async function(key, result) {
   result.value = await fs_readFile(render.pathname)
 }
 
-module.exports = LessCSSCache
+module.exports = SassCSSCache
index 018cd5c..5590d0a 100644 (file)
@@ -1,9 +1,9 @@
 {
-  "name": "@ndcode/less_css_cache",
+  "name": "@ndcode/sass_css_cache",
   "version": "0.1.0",
-  "description": "Less CSS compiler, caching front-end with live recompilation",
+  "description": "Sass CSS compiler, caching front-end with live recompilation",
   "keywords": [
-    "Less",
+    "Sass",
     "CSS",
     "server-side",
     "render",
   "license": "MIT",
   "repository": {
     "type": "git",
-    "url": "https://git.ndcode.org/public/less_css_cache.git"
+    "url": "https://git.ndcode.org/public/sass_css_cache.git"
   },
   "bugs": {
     "email": "nick@ndcode.org"
   },
-  "main": "LessCSSCache.js",
+  "main": "SassCSSCache.js",
   "engines": {
     "node": ">=0.4.0"
   },
@@ -29,7 +29,6 @@
   "dependencies": {
     "@ndcode/build_cache": "^0.1.0",
     "@ndcode/disk_build": "^0.1.1",
-    "less": "^3.8.1"
-  },
-  "devDependencies": {}
+    "sass": "^1.47.0"
+  }
 }