diff --git a/.eslintignore b/.eslintignore index 4be6e16..c36bcaf 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -dist/* \ No newline at end of file +dist/* +test/* diff --git a/.eslintrc.json b/.eslintrc.json index 1d1e020..9e547b2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,7 @@ }, "parserOptions": { "sourceType": "module", - "ecmaVersion": 2018 + "ecmaVersion": 2020 }, "extends": "eslint:recommended", "rules": { @@ -158,4 +158,4 @@ "error" ] } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 2d42c3e..2bee426 100644 --- a/README.md +++ b/README.md @@ -17,23 +17,18 @@ npm install less-compile-roots Here is a basic programmatic usage example: ```javascript -let lessCompileRoots = require("less-compile-roots"); +import {compileRoots} from "less-compile-roots"; -lessCompileRoots.compileRoots({ +let rootEntries = await compileRoots({ // Glob pattern matching existing less files pattern: "src/**/*.less", // Pass any Less.js options you need lessOptions: { sourceMap: {sourceMapFileInline: true} } -}) -.then(rootEntries => { - console.log("Compiled root files:"); - console.log(rootEntries.join("\n")); -}) -.catch(reason => { - console.error(reason); }); +console.log("Compiled root files:"); +console.log(rootEntries.join("\n")); ``` If you prefer using the tool through the command line, please refer the [Command line usage](#command-line-usage) section. @@ -50,7 +45,7 @@ The supported options are: * `pattern` _(required)_: a glob pattern (or a list of patterns) matching your source Less files. Please refer the [fast-glob docs](https://github.com/mrmlnc/fast-glob#patterns) for details; * `lessOptions` _(optional)_: the options object to pass to the [`less.render` method](http://lesscss.org/usage/#programmatic-usage). The [available options](http://lesscss.org/usage/#less-options) are listed in the official Less documentation; -* `globOptions` _(optional)_: the options object to pass to the fast-glob function. See their [docs](https://github.com/mrmlnc/fast-glob#options-1) for details. +* `globOptions` _(optional)_: the options object to pass to the fast-glob function. See their [docs](https://github.com/mrmlnc/fast-glob#options-3) for details. ### `getRoots(options)` @@ -65,7 +60,7 @@ You may also use `less-compile-roots` through the command line interface: less-compile-roots --pattern=src/**/*.less # or use custom config from a specified file -less-compile-roots --config=less-compile-config.js +less-compile-roots --config=less-compile-config.cjs ``` Available options: @@ -78,6 +73,7 @@ Available options: Note that you cannot use the options `--pattern` and `--config` together. Specifying the `--pattern` option makes the module compile Less files using all default parameters. If you need to customize the parameters, create a config file and specify the path to it through the `--config` option (or just use the module [programmatically](#api) rather than in command line). Here is an example of such config file: ```javascript +// less-compile-config.cjs let LessPlugin = require('less-plugin-myplugin'); module.exports = { pattern: ["project-1/css/**/*.less", "project-2/css/**/*.less"], @@ -93,7 +89,7 @@ In fact, the config module just exports an object which is then used as the `opt ## Requirements -* NodeJS engine v9.11.2+ +* NodeJS engine v10.0.0+ * Less pre-processor v2.0.0+ ## Caveats diff --git a/bin/less-compile-roots.js b/bin/less-compile-roots.cjs similarity index 100% rename from bin/less-compile-roots.js rename to bin/less-compile-roots.cjs diff --git a/dist/index.js b/dist/index.cjs similarity index 73% rename from dist/index.js rename to dist/index.cjs index 9bf5675..17ba500 100644 --- a/dist/index.js +++ b/dist/index.cjs @@ -2,13 +2,14 @@ Object.defineProperty(exports, '__esModule', { value: true }); -let fs = require("fs"); -let util = require("util"); -let path = require("path"); -let fastGlob = require("fast-glob"); +var fs = require('fs'); +var path = require('path'); +var fastGlob = require('fast-glob'); + +function _interopNamespaceDefaultOnly(e) { + return Object.freeze({__proto__: null, 'default': e}); +} -let readFile = util.promisify(fs.readFile); -let writeFile = util.promisify(fs.writeFile); let setExt = (path, ext, oldExtRE = /\.less$/) => path.replace(oldExtRE, "") + ext; let flat = Array.prototype.flat ? list => list.flat() : list => [].concat(...list); @@ -17,7 +18,7 @@ async function getImports(entries) { let commentRE = /\/\*[\s\S]*?\*\/|\/\/\s*@import[^;]+;/g; let importRE = /(?<=@import\s[^"']*["']).+?(?=['"]\s*;)/g; let promises = entries.map(async entry => { - let data = await readFile(entry, "utf8"); + let data = await fs.promises.readFile(entry, "utf8"); data = data.replace(commentRE, ""); let dir = path.dirname(entry); return (data.match(importRE) || []).map(importPath => { @@ -32,20 +33,20 @@ async function getImports(entries) { return new Set(flat(importLists)); } -function compile(entries, lessOptions) { - let less = require("less"); +async function compile(entries, lessOptions) { + let less = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('less')); })).default; let inlineMap = lessOptions.sourceMap && lessOptions.sourceMap.sourceMapFileInline; let promises = entries.map(async entry => { - let data = await readFile(entry, "utf8"); + let data = await fs.promises.readFile(entry, "utf8"); let {css, map} = await less.render(data, { ...lessOptions, filename: entry }); - let writeCSS = writeFile(setExt(entry, ".css"), css); + let writeCSS = fs.promises.writeFile(setExt(entry, ".css"), css); if (!map || inlineMap) { return writeCSS; } - let writeMap = writeFile(setExt(entry, ".css.map"), map); + let writeMap = fs.promises.writeFile(setExt(entry, ".css.map"), map); return Promise.all([writeCSS, writeMap]); }); return Promise.all(promises); diff --git a/package-lock.json b/package-lock.json index 47dbfff..779ba04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "less-compile-roots", - "version": "1.0.0", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -939,9 +939,9 @@ } }, "rollup": { - "version": "2.45.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.45.1.tgz", - "integrity": "sha512-vPD+JoDj3CY8k6m1bLcAFttXMe78P4CMxoau0iLVS60+S9kLsv2379xaGy4NgYWu+h2WTlucpoLPAoUoixFBag==", + "version": "2.45.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.45.2.tgz", + "integrity": "sha512-kRRU7wXzFHUzBIv0GfoFFIN3m9oteY4uAsKllIpQDId5cfnkWF2J130l+27dzDju0E6MScKiV0ZM5Bw8m4blYQ==", "dev": true, "requires": { "fsevents": "~2.3.1" diff --git a/package.json b/package.json index 09bad20..edb164d 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,16 @@ { "name": "less-compile-roots", - "version": "1.0.0", + "version": "2.0.0", "description": "Tool for extracting and compiling root Less files", - "main": "dist/index.js", - "module": "src/index.mjs", + "type": "module", + "main": "./dist/index.cjs", + "module": "./src/index.mjs", + "exports": { + "import": "./src/index.mjs", + "require": "./dist/index.cjs" + }, "bin": { - "less-compile-roots": "./bin/less-compile-roots.js" + "less-compile-roots": "./bin/less-compile-roots.cjs" }, "files": [ "bin", @@ -35,12 +40,12 @@ }, "devDependencies": { "eslint": "^7.24.0", - "rollup": "^2.45.1" + "rollup": "^2.45.2" }, "peerDependencies": { "less": ">=2.0.0" }, "engines": { - "node": ">=9.11.2" + "node": ">=10.0.0" } } diff --git a/rollup.config.js b/rollup.config.js index f765258..65afadd 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,9 @@ export default { input: "src/index.mjs", output: { - file: "dist/index.js", - format: "cjs" - } + file: "dist/index.cjs", + format: "cjs", + interop: id => id === "less" ? "defaultOnly" : "default" + }, + external: () => true }; diff --git a/src/index.mjs b/src/index.mjs index d6211e4..3bf27f8 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -1,10 +1,7 @@ -let fs = require("fs"); -let util = require("util"); -let path = require("path"); -let fastGlob = require("fast-glob"); +import {promises as fsPromises} from "fs"; +import path from "path"; +import fastGlob from "fast-glob"; -let readFile = util.promisify(fs.readFile); -let writeFile = util.promisify(fs.writeFile); let setExt = (path, ext, oldExtRE = /\.less$/) => path.replace(oldExtRE, "") + ext; let flat = Array.prototype.flat ? list => list.flat() : list => [].concat(...list); @@ -13,7 +10,7 @@ async function getImports(entries) { let commentRE = /\/\*[\s\S]*?\*\/|\/\/\s*@import[^;]+;/g; let importRE = /(?<=@import\s[^"']*["']).+?(?=['"]\s*;)/g; let promises = entries.map(async entry => { - let data = await readFile(entry, "utf8"); + let data = await fsPromises.readFile(entry, "utf8"); data = data.replace(commentRE, ""); let dir = path.dirname(entry); return (data.match(importRE) || []).map(importPath => { @@ -28,20 +25,20 @@ async function getImports(entries) { return new Set(flat(importLists)); } -function compile(entries, lessOptions) { - let less = require("less"); +async function compile(entries, lessOptions) { + let less = (await import("less")).default; let inlineMap = lessOptions.sourceMap && lessOptions.sourceMap.sourceMapFileInline; let promises = entries.map(async entry => { - let data = await readFile(entry, "utf8"); + let data = await fsPromises.readFile(entry, "utf8"); let {css, map} = await less.render(data, { ...lessOptions, filename: entry }); - let writeCSS = writeFile(setExt(entry, ".css"), css); + let writeCSS = fsPromises.writeFile(setExt(entry, ".css"), css); if (!map || inlineMap) { return writeCSS; } - let writeMap = writeFile(setExt(entry, ".css.map"), map); + let writeMap = fsPromises.writeFile(setExt(entry, ".css.map"), map); return Promise.all([writeCSS, writeMap]); }); return Promise.all(promises); diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index 2318862..0000000 --- a/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.css \ No newline at end of file diff --git a/test/less-compile-config.cjs b/test/less-compile-config.cjs new file mode 100644 index 0000000..06ba324 --- /dev/null +++ b/test/less-compile-config.cjs @@ -0,0 +1,6 @@ +module.exports = { + pattern: "less/*.less", + lessOptions: { + sourceMap: {} + } +}; diff --git a/test/less/root-01.css b/test/less/root-01.css new file mode 100644 index 0000000..e48e92b --- /dev/null +++ b/test/less/root-01.css @@ -0,0 +1,12 @@ +body { + background: #000; +} +/* +a { + color:#0a0; +} +@import "root-04"; +some text +*/ +/*@import "root-05";*/ +/* child-01 */ diff --git a/test/less/root-01.css.map b/test/less/root-01.css.map new file mode 100644 index 0000000..edad92d --- /dev/null +++ b/test/less/root-01.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["less/root-01.less"],"names":[],"mappings":"AAAA;EACI,gBAAA"} \ No newline at end of file diff --git a/test/less/root-02.css b/test/less/root-02.css new file mode 100644 index 0000000..d12b1b4 --- /dev/null +++ b/test/less/root-02.css @@ -0,0 +1,6 @@ +/* child-02 */ +/* child-02-1 */ +/* child-02-2 */ +body { + background: #000; +} diff --git a/test/less/root-02.css.map b/test/less/root-02.css.map new file mode 100644 index 0000000..7c049fc --- /dev/null +++ b/test/less/root-02.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["less/root-02.less"],"names":[],"mappings":";;;AAGA;EACI,gBAAA"} \ No newline at end of file diff --git a/test/less/root-03.css b/test/less/root-03.css new file mode 100644 index 0000000..3e19b69 --- /dev/null +++ b/test/less/root-03.css @@ -0,0 +1,4 @@ +body { + background: #000; +} +/* child-03 */ diff --git a/test/less/root-03.css.map b/test/less/root-03.css.map new file mode 100644 index 0000000..e3dd040 --- /dev/null +++ b/test/less/root-03.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["less/root-03.less"],"names":[],"mappings":"AAAA;EACI,gBAAA"} \ No newline at end of file diff --git a/test/less/root-04.css b/test/less/root-04.css new file mode 100644 index 0000000..78c0719 --- /dev/null +++ b/test/less/root-04.css @@ -0,0 +1,5 @@ +/* child-04 */ +/* child-04-1 */ +body { + background: #000; +} diff --git a/test/less/root-04.css.map b/test/less/root-04.css.map new file mode 100644 index 0000000..55a042a --- /dev/null +++ b/test/less/root-04.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["less/root-04.less"],"names":[],"mappings":";;AAiBA;EACI,gBAAA"} \ No newline at end of file diff --git a/test/less/root-05.css b/test/less/root-05.css new file mode 100644 index 0000000..c6af4d8 --- /dev/null +++ b/test/less/root-05.css @@ -0,0 +1,4 @@ +/* child-05-1 */ +body { + background: #000; +} diff --git a/test/less/root-05.css.map b/test/less/root-05.css.map new file mode 100644 index 0000000..a208e72 --- /dev/null +++ b/test/less/root-05.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["less/root-05.less"],"names":[],"mappings":";AAKA;EACI,gBAAA"} \ No newline at end of file diff --git a/test/package-lock.json b/test/package-lock.json index 6d4650f..603ad9c 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -176,6 +176,23 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, + "copy-anything": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-2.0.3.tgz", + "integrity": "sha512-GK6QUtisv4fNS+XcI7shX0Gx9ORg7QqIznyfho79JTnX1XhLiyZHfftvGiziqzRiEi/Bjhgpi+D2o7HxJFPnDQ==", + "requires": { + "is-what": "^3.12.0" + } + }, + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "optional": true, + "requires": { + "ms": "^2.1.1" + } + }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -230,9 +247,9 @@ } }, "errno": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", - "integrity": "sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg==", + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.8.tgz", + "integrity": "sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==", "optional": true, "requires": { "prr": "~1.0.1" @@ -357,6 +374,15 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==" }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "optional": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, "ignore": { "version": "5.1.8", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", @@ -425,6 +451,11 @@ "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", "integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=" }, + "is-what": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/is-what/-/is-what-3.14.1.tgz", + "integrity": "sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -441,31 +472,33 @@ "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" }, "less": { - "version": "3.12.2", - "resolved": "https://registry.npmjs.org/less/-/less-3.12.2.tgz", - "integrity": "sha512-+1V2PCMFkL+OIj2/HrtrvZw0BC0sYLMICJfbQjuj/K8CEnlrFX6R5cKKgzzttsZDHyxQNL1jqMREjKN3ja/E3Q==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/less/-/less-4.1.1.tgz", + "integrity": "sha512-w09o8tZFPThBscl5d0Ggp3RcrKIouBoQscnOMgFH3n5V3kN/CXGHNfCkRPtxJk6nKryDXaV9aHLK55RXuH4sAw==", "requires": { + "copy-anything": "^2.0.1", "errno": "^0.1.1", "graceful-fs": "^4.1.2", "image-size": "~0.5.0", "make-dir": "^2.1.0", "mime": "^1.4.1", - "native-request": "^1.0.5", + "needle": "^2.5.2", + "parse-node-version": "^1.0.1", "source-map": "~0.6.0", "tslib": "^1.10.0" } }, "less-compile-roots": { - "version": "file:../less-compile-roots-1.0.0.tgz", - "integrity": "sha512-lGBw2tYHY0LfUfr9nlUc7IsptYqQ9CsP1mfl2v5bl9P1NPTMLYZxFo4onG52fxczVZF7tKoydwuX/EMA2N8nLw==", + "version": "file:../less-compile-roots-2.0.0.tgz", + "integrity": "sha512-MXwRT6FymcfnKPHzcM37VNGeQsHoZOrLG1mSSNHv2Fh7mWp4BHc4gx8xFvGWHIfkkpxrDY+ZWmhCuPQT6z31jw==", "requires": { - "fast-glob": "^3.2.2" + "fast-glob": "^3.2.5" }, "dependencies": { "fast-glob": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.2.tgz", - "integrity": "sha512-UDV82o4uQyljznxwMxyVRJgZZt3O5wENYojjzbaGEGZgeOxkLFf+V4cnUD+krzb2F72E18RhamkMZ7AdeggF7A==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.5.tgz", + "integrity": "sha512-2DtFcgT68wiTTiwZ2hNdJfcHNke9XOfnwmBRWXhmeKM8rF0TGwmC/Qto3S7RoZKp5cilZbxzO5iTNTQsJ+EeDg==", "requires": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -476,9 +509,9 @@ } }, "picomatch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.1.tgz", - "integrity": "sha512-ISBaA8xQNmwELC7eOjqFKMESB2VIqt4PPDD0nsS95b/9dZXvVKOlz9keMSnoGGKcOHXfTvDD6WMaRoSc9UuhRA==" + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz", + "integrity": "sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg==" } } }, @@ -571,12 +604,23 @@ "kind-of": "^6.0.3" } }, - "native-request": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/native-request/-/native-request-1.0.7.tgz", - "integrity": "sha512-9nRjinI9bmz+S7dgNtf4A70+/vPhnd+2krGpy4SUlADuOuSa24IDkNaZ+R/QT1wQ6S8jBdi6wE7fLekFZNfUpQ==", + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "optional": true }, + "needle": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/needle/-/needle-2.6.0.tgz", + "integrity": "sha512-KKYdza4heMsEfSWD7VPUIz3zX2XDwOyX2d+geb4vrERZMT5RMU6ujjaD+I5Yr54uZxQ2w6XRTAhHBbSCyovZBg==", + "optional": true, + "requires": { + "debug": "^3.2.6", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" + } + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -636,6 +680,11 @@ "lines-and-columns": "^1.1.6" } }, + "parse-node-version": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz", + "integrity": "sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==" + }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -748,6 +797,18 @@ "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==" }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "optional": true + }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "optional": true + }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -822,9 +883,9 @@ "integrity": "sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA==" }, "tslib": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", - "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==" + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, "type-fest": { "version": "0.13.1", diff --git a/test/package.json b/test/package.json index ed8801a..75bb8fd 100644 --- a/test/package.json +++ b/test/package.json @@ -2,16 +2,22 @@ "name": "less-compile-root-test", "version": "1.0.0", "description": "Simple test package for the less-compile-roots module", - "main": "index.js", + "private": true, + "type": "module", + "main": "./test-api.cjs", + "exports": "./test-api.mjs", "scripts": { - "test": "del 'less/*.css' && less-compile-roots --pattern=less/*.less", - "test-api": "del 'less/*.css' && node ./test-api.js" + "cleanup": "del 'less/*.css' 'less/*.css.map'", + "test-cli": "npm run cleanup && less-compile-roots --pattern=less/*.less", + "test-cli-config": "npm run cleanup && less-compile-roots --config=less-compile-config.cjs", + "test-api-mjs": "npm run cleanup && node ./test-api.mjs", + "test-api-cjs": "npm run cleanup && node ./test-api.cjs" }, "author": "Amphiluke", "license": "MIT", "dependencies": { "del-cli": "^3.0.1", - "less": "^3.12.2", - "less-compile-roots": "file:../less-compile-roots-1.0.0.tgz" + "less": "^4.1.1", + "less-compile-roots": "file:../less-compile-roots-2.0.0.tgz" } } diff --git a/test/test-api.js b/test/test-api.cjs similarity index 69% rename from test/test-api.js rename to test/test-api.cjs index 0f9511c..b3ece3e 100644 --- a/test/test-api.js +++ b/test/test-api.cjs @@ -1,6 +1,6 @@ -let lessCompileRoots = require("less-compile-roots"); +let {compileRoots} = require("less-compile-roots"); -lessCompileRoots.compileRoots({ +compileRoots({ pattern: "less/**/*.less" }) .then(rootEntries => { diff --git a/test/test-api.mjs b/test/test-api.mjs new file mode 100644 index 0000000..d6284d1 --- /dev/null +++ b/test/test-api.mjs @@ -0,0 +1,7 @@ +import {compileRoots} from "less-compile-roots"; + +let rootEntries = await compileRoots({ + pattern: "less/**/*.less" +}); +console.info("Compiled root files:"); +console.info(rootEntries.join("\n"));