less 4.9.1 → 5.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/V5-STATUS.md +71 -0
- package/bin/lessc +302 -626
- package/dist/less-browser-dev.js +2550 -0
- package/dist/less-node.cjs +480 -14561
- package/index.cjs +5 -2
- package/lib/browser-dev.js +86 -0
- package/lib/index.js +164 -0
- package/lib/lessc-helper.js +64 -0
- package/lib/logger.js +76 -0
- package/lib/options.d.ts +82 -0
- package/lib/options.js +227 -0
- package/lib/types.js +20 -0
- package/lib/version.js +19 -0
- package/package.json +36 -40
- package/dist/less.cjs +0 -15218
- package/dist/less.js +0 -15218
- package/dist/less.min.js +0 -11
- package/dist/less.min.js.map +0 -1
- package/lib/less/constants.js +0 -13
- package/lib/less/contexts.js +0 -165
- package/lib/less/data/colors.js +0 -150
- package/lib/less/data/index.js +0 -4
- package/lib/less/data/unit-conversions.js +0 -21
- package/lib/less/default-options.js +0 -89
- package/lib/less/deprecation.js +0 -82
- package/lib/less/environment/abstract-file-manager.js +0 -140
- package/lib/less/environment/abstract-plugin-loader.js +0 -185
- package/lib/less/environment/environment-api.ts +0 -21
- package/lib/less/environment/environment.js +0 -59
- package/lib/less/environment/file-manager-api.ts +0 -77
- package/lib/less/functions/boolean.js +0 -29
- package/lib/less/functions/color-blending.js +0 -85
- package/lib/less/functions/color.js +0 -452
- package/lib/less/functions/data-uri.js +0 -74
- package/lib/less/functions/default.js +0 -26
- package/lib/less/functions/function-caller.js +0 -55
- package/lib/less/functions/function-registry.js +0 -36
- package/lib/less/functions/index.js +0 -35
- package/lib/less/functions/list.js +0 -158
- package/lib/less/functions/math-helper.js +0 -22
- package/lib/less/functions/math.js +0 -30
- package/lib/less/functions/number.js +0 -95
- package/lib/less/functions/string.js +0 -39
- package/lib/less/functions/style.js +0 -29
- package/lib/less/functions/svg.js +0 -87
- package/lib/less/functions/types.js +0 -70
- package/lib/less/import-manager.js +0 -183
- package/lib/less/index.js +0 -95
- package/lib/less/less-error.js +0 -166
- package/lib/less/logger.js +0 -34
- package/lib/less/parse-tree.js +0 -124
- package/lib/less/parse.js +0 -87
- package/lib/less/parser/lookup-pattern.js +0 -26
- package/lib/less/parser/parser-input.js +0 -400
- package/lib/less/parser/parser.js +0 -2998
- package/lib/less/plugin-manager.js +0 -168
- package/lib/less/render.js +0 -41
- package/lib/less/source-map-builder.js +0 -82
- package/lib/less/source-map-output.js +0 -151
- package/lib/less/transform-tree.js +0 -102
- package/lib/less/tree/anonymous.js +0 -61
- package/lib/less/tree/assignment.js +0 -48
- package/lib/less/tree/atrule-syntax.js +0 -8
- package/lib/less/tree/atrule.js +0 -340
- package/lib/less/tree/attribute.js +0 -63
- package/lib/less/tree/call.js +0 -132
- package/lib/less/tree/color.js +0 -285
- package/lib/less/tree/combinator.js +0 -38
- package/lib/less/tree/comment.js +0 -48
- package/lib/less/tree/condition.js +0 -65
- package/lib/less/tree/container.js +0 -104
- package/lib/less/tree/debug-info.js +0 -80
- package/lib/less/tree/declaration.js +0 -142
- package/lib/less/tree/detached-ruleset.js +0 -45
- package/lib/less/tree/dimension.js +0 -215
- package/lib/less/tree/element.js +0 -93
- package/lib/less/tree/expression.js +0 -100
- package/lib/less/tree/extend.js +0 -88
- package/lib/less/tree/import.js +0 -299
- package/lib/less/tree/index.js +0 -56
- package/lib/less/tree/interpolated-variable.js +0 -106
- package/lib/less/tree/javascript.js +0 -45
- package/lib/less/tree/js-eval-node.js +0 -80
- package/lib/less/tree/keyword.js +0 -28
- package/lib/less/tree/media.js +0 -90
- package/lib/less/tree/merge-rules.js +0 -47
- package/lib/less/tree/mixin-call.js +0 -283
- package/lib/less/tree/mixin-definition.js +0 -319
- package/lib/less/tree/namespace-value.js +0 -95
- package/lib/less/tree/negative.js +0 -37
- package/lib/less/tree/nested-at-rule.js +0 -239
- package/lib/less/tree/node.js +0 -310
- package/lib/less/tree/operation.js +0 -81
- package/lib/less/tree/paren.js +0 -41
- package/lib/less/tree/property.js +0 -96
- package/lib/less/tree/query-in-parens.js +0 -64
- package/lib/less/tree/quoted.js +0 -131
- package/lib/less/tree/ruleset.js +0 -1068
- package/lib/less/tree/selector.js +0 -201
- package/lib/less/tree/unicode-descriptor.js +0 -14
- package/lib/less/tree/unit.js +0 -170
- package/lib/less/tree/url.js +0 -83
- package/lib/less/tree/value.js +0 -60
- package/lib/less/tree/variable-call.js +0 -60
- package/lib/less/tree/variable.js +0 -85
- package/lib/less/utils.js +0 -126
- package/lib/less/visitors/extend-visitor.js +0 -505
- package/lib/less/visitors/import-sequencer.js +0 -56
- package/lib/less/visitors/import-visitor.js +0 -203
- package/lib/less/visitors/index.js +0 -15
- package/lib/less/visitors/join-selector-visitor.js +0 -65
- package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
- package/lib/less/visitors/to-css-visitor.js +0 -332
- package/lib/less/visitors/visitor.js +0 -165
- package/lib/less-browser/add-default-options.js +0 -53
- package/lib/less-browser/bootstrap.js +0 -67
- package/lib/less-browser/browser.js +0 -65
- package/lib/less-browser/cache.js +0 -43
- package/lib/less-browser/error-reporting.js +0 -170
- package/lib/less-browser/file-manager.js +0 -112
- package/lib/less-browser/image-size.js +0 -28
- package/lib/less-browser/index.js +0 -284
- package/lib/less-browser/log-listener.js +0 -42
- package/lib/less-browser/plugin-loader.js +0 -24
- package/lib/less-browser/utils.js +0 -30
- package/lib/less-node/environment.js +0 -43
- package/lib/less-node/file-manager.js +0 -156
- package/lib/less-node/fs.js +0 -14
- package/lib/less-node/image-size.js +0 -78
- package/lib/less-node/index.js +0 -31
- package/lib/less-node/lessc-helper.js +0 -95
- package/lib/less-node/plugin-loader.js +0 -62
- package/lib/less-node/url-file-manager.js +0 -60
package/index.cjs
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
// CJS entry
|
|
2
|
-
|
|
1
|
+
// CJS entry: unwrap the Rollup namespace so require('less') returns the Less API object.
|
|
2
|
+
const bundle = require('./dist/less-node.cjs');
|
|
3
|
+
|
|
4
|
+
module.exports = bundle.default || bundle;
|
|
5
|
+
Object.assign(module.exports, bundle);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Less.js v5 — browser build (powered by Jess).
|
|
3
|
+
*
|
|
4
|
+
* A single-file, in-browser Less→CSS compiler. It drives `@jesscss/compiler`'s
|
|
5
|
+
* `renderToResult` with an inline `source` and NO `filePath`, so the Node-only
|
|
6
|
+
* config-discovery layer (cosmiconfig/env-paths/fs) is never reached. `@import`
|
|
7
|
+
* / file access is unsupported here (see build/browser-stubs/fs.js).
|
|
8
|
+
*
|
|
9
|
+
* Bundled to an IIFE that defines `window.less` with the same public shape as
|
|
10
|
+
* the Less 4.x browser build: `less.render(input, options?, callback?)` returns
|
|
11
|
+
* a Promise and also invokes the err-first callback when one is given.
|
|
12
|
+
*
|
|
13
|
+
* @module less/browser-dev
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Compiler } from '@jesscss/compiler';
|
|
17
|
+
import { createLessOptions, mapRenderResult } from './options.js';
|
|
18
|
+
|
|
19
|
+
/* Injected at build time from packages/less/package.json. */
|
|
20
|
+
/* global __LESS_VERSION__ */
|
|
21
|
+
const semver = typeof __LESS_VERSION__ === 'string' ? __LESS_VERSION__ : '5.0.0-alpha.0';
|
|
22
|
+
const versionArray = semver.split('.').map((n) => parseInt(n, 10) || 0).slice(0, 3);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build a Less-4.x-shaped error from the first Jess diagnostic. No fs fallback:
|
|
26
|
+
* in the browser there is no file to re-read for the source extract.
|
|
27
|
+
* @param {import('./options.js').JessRenderResult} result
|
|
28
|
+
*/
|
|
29
|
+
function createRenderError(result) {
|
|
30
|
+
const diagnostic = (result?.errors || [])[0];
|
|
31
|
+
const error = new Error(diagnostic?.message || 'Less render failed');
|
|
32
|
+
error.type = diagnostic?.phase || 'Syntax';
|
|
33
|
+
error.filename = diagnostic?.filePath || 'input';
|
|
34
|
+
error.line = diagnostic?.line || 1;
|
|
35
|
+
error.column = diagnostic?.column || 1;
|
|
36
|
+
const lines = diagnostic?.lines;
|
|
37
|
+
error.extract = Array.isArray(lines) ? lines.map(String) : undefined;
|
|
38
|
+
error.jessErrors = result?.errors || [];
|
|
39
|
+
error.jessWarnings = result?.warnings || [];
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Render Less source to CSS. Mirrors the Less 4.x API: `options` and `callback`
|
|
45
|
+
* are both optional, `callback` may be passed as the second argument, and the
|
|
46
|
+
* returned Promise resolves to a `{ css, warnings }` result. When a callback is
|
|
47
|
+
* given it is invoked err-first and the Promise is still returned.
|
|
48
|
+
* @param {string} input Less source
|
|
49
|
+
* @param {object|Function} [options] Less-style options (math, collapseNesting, plugins) — or the callback
|
|
50
|
+
* @param {Function} [callback] err-first `(error, result)` callback
|
|
51
|
+
* @returns {Promise<{ css: string, warnings?: unknown[] }>}
|
|
52
|
+
*/
|
|
53
|
+
function render(input, options, callback) {
|
|
54
|
+
if (typeof options === 'function') {
|
|
55
|
+
callback = options;
|
|
56
|
+
options = {};
|
|
57
|
+
}
|
|
58
|
+
options = options || {};
|
|
59
|
+
const promise = (async () => {
|
|
60
|
+
const { configOptions } = createLessOptions(options);
|
|
61
|
+
// ponytail: fresh Compiler per call — no defaultPlugins hook, so no
|
|
62
|
+
// node-modules import plugin and no @jesscss/plugin-js. Single-file preview
|
|
63
|
+
// rarely re-renders in a hot loop; a cache map is not worth the surface.
|
|
64
|
+
const compiler = new Compiler(configOptions);
|
|
65
|
+
const result = await compiler.renderToResult(
|
|
66
|
+
{ source: input, language: 'less', extension: '.less' },
|
|
67
|
+
{ ...configOptions, suppressWarnings: true }
|
|
68
|
+
);
|
|
69
|
+
if (result.errors?.length) {
|
|
70
|
+
throw createRenderError(result);
|
|
71
|
+
}
|
|
72
|
+
return mapRenderResult(result, options);
|
|
73
|
+
})();
|
|
74
|
+
if (typeof callback === 'function') {
|
|
75
|
+
promise.then((result) => callback(null, result), (error) => callback(error));
|
|
76
|
+
}
|
|
77
|
+
return promise;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const less = {
|
|
81
|
+
version: versionArray,
|
|
82
|
+
render,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default less;
|
|
86
|
+
export { render, versionArray as version };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Less.js v5 — powered by Jess
|
|
3
|
+
*
|
|
4
|
+
* This module provides a Less-compatible API backed by the Jess compiler.
|
|
5
|
+
* It supports the same `less.render()` interface that Less 4.x users expect,
|
|
6
|
+
* while delegating all parsing, evaluation, and output to Jess with the
|
|
7
|
+
* `@jesscss/plugin-less` and `@jesscss/plugin-less-compat` plugins.
|
|
8
|
+
*
|
|
9
|
+
* @module less
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import { readFile } from 'node:fs/promises';
|
|
14
|
+
import { Compiler } from '@jesscss/compiler';
|
|
15
|
+
import nodeModulesPlugin from '@jesscss/plugin-node-modules';
|
|
16
|
+
import { createLessOptions, getCompilerCacheKey, mapRenderResult } from './options.js';
|
|
17
|
+
import { version } from './version.js';
|
|
18
|
+
import { logger } from './logger.js';
|
|
19
|
+
import { lesscHelper } from './lessc-helper.js';
|
|
20
|
+
|
|
21
|
+
const compilerCache = new Map();
|
|
22
|
+
const lessVersion = version.array;
|
|
23
|
+
|
|
24
|
+
function normalizeDiagnosticLines(lines, lineNumber, filePath) {
|
|
25
|
+
if (Array.isArray(lines)) {
|
|
26
|
+
return lines.map((line) => typeof line === 'string' ? line : String(line));
|
|
27
|
+
}
|
|
28
|
+
if (lines && typeof lines === 'object') {
|
|
29
|
+
const current = Number(lineNumber) || 1;
|
|
30
|
+
return [current - 1, current, current + 1]
|
|
31
|
+
.filter((line) => line > 0 && Object.prototype.hasOwnProperty.call(lines, line))
|
|
32
|
+
.map((line) => {
|
|
33
|
+
const value = lines[line];
|
|
34
|
+
return typeof value === 'string' ? value : String(value);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (typeof filePath === 'string') {
|
|
38
|
+
try {
|
|
39
|
+
const sourceLines = readFileSync(filePath, 'utf8').split(/\r?\n/);
|
|
40
|
+
const current = Number(lineNumber) || 1;
|
|
41
|
+
return [current - 1, current, current + 1]
|
|
42
|
+
.filter((line) => line > 0 && line <= sourceLines.length)
|
|
43
|
+
.map((line) => sourceLines[line - 1]);
|
|
44
|
+
} catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createRenderErrorFromJessDiagnostic(result, filePath) {
|
|
52
|
+
const errors = result?.errors || [];
|
|
53
|
+
const diagnostic = errors[0];
|
|
54
|
+
const error = new Error(diagnostic?.message || 'Less render failed');
|
|
55
|
+
|
|
56
|
+
error.type = diagnostic?.phase || 'Syntax';
|
|
57
|
+
error.filename = diagnostic?.filePath || filePath;
|
|
58
|
+
error.line = diagnostic?.line || 1;
|
|
59
|
+
error.column = diagnostic?.column || 1;
|
|
60
|
+
error.extract = normalizeDiagnosticLines(diagnostic?.lines, error.line, error.filename);
|
|
61
|
+
error.jessErrors = errors;
|
|
62
|
+
error.jessWarnings = result?.warnings || [];
|
|
63
|
+
|
|
64
|
+
return error;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {object} configOptions
|
|
69
|
+
*/
|
|
70
|
+
function getCompiler(configOptions) {
|
|
71
|
+
const cacheKey = getCompilerCacheKey(configOptions);
|
|
72
|
+
let compiler = compilerCache.get(cacheKey);
|
|
73
|
+
if (!compiler) {
|
|
74
|
+
compiler = new Compiler(configOptions, {
|
|
75
|
+
defaultPlugins: context => [nodeModulesPlugin({ basePath: context.resolutionBaseDir })],
|
|
76
|
+
scriptPluginSpecifier: '@jesscss/plugin-js',
|
|
77
|
+
scriptPluginResolveFrom: import.meta.url
|
|
78
|
+
});
|
|
79
|
+
compilerCache.set(cacheKey, compiler);
|
|
80
|
+
}
|
|
81
|
+
return compiler;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Render Less source to CSS.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} input - Less source string
|
|
88
|
+
* @param {import('./options.js').LessRenderOptions} [options={}]
|
|
89
|
+
* @param {Function} [callback] - Optional Node-style callback(err, result)
|
|
90
|
+
* @returns {Promise<import('./options.js').LessRenderResult>}
|
|
91
|
+
*/
|
|
92
|
+
function render(input, options = {}, callback) {
|
|
93
|
+
if (typeof options === 'function') {
|
|
94
|
+
callback = options;
|
|
95
|
+
options = {};
|
|
96
|
+
}
|
|
97
|
+
const promise = (async () => {
|
|
98
|
+
const { configOptions, filePath } = createLessOptions(options, { source: input });
|
|
99
|
+
const compiler = getCompiler(configOptions);
|
|
100
|
+
|
|
101
|
+
const result = await compiler.renderToResult(
|
|
102
|
+
{ source: input, filePath, language: 'less', extension: '.less' },
|
|
103
|
+
{ ...configOptions, suppressWarnings: true }
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (result.errors?.length) {
|
|
107
|
+
throw createRenderErrorFromJessDiagnostic(result, filePath);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return mapRenderResult(result, options);
|
|
111
|
+
})();
|
|
112
|
+
|
|
113
|
+
if (callback) {
|
|
114
|
+
promise.then(
|
|
115
|
+
result => callback(null, result),
|
|
116
|
+
err => callback(err)
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return promise;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Render a Less file to CSS.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} filePath - Absolute or relative path to .less file
|
|
126
|
+
* @param {import('./options.js').LessRenderOptions} [options={}]
|
|
127
|
+
* @returns {Promise<import('./options.js').LessRenderResult>}
|
|
128
|
+
*/
|
|
129
|
+
async function renderFile(filePath, options = {}) {
|
|
130
|
+
const source = await readFile(filePath, 'utf8');
|
|
131
|
+
const { configOptions } = createLessOptions(options, { source });
|
|
132
|
+
const compiler = getCompiler(configOptions);
|
|
133
|
+
|
|
134
|
+
const result = await compiler.renderToResult(filePath, { ...configOptions, suppressWarnings: true });
|
|
135
|
+
if (result.errors?.length) {
|
|
136
|
+
throw createRenderErrorFromJessDiagnostic(result, filePath);
|
|
137
|
+
}
|
|
138
|
+
return mapRenderResult(result, options);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* COMPAT GAP (v5): the Less 4.x `less.functions` (custom-function registry via
|
|
143
|
+
* `less.functions.functionRegistry.add/addMultiple`) and `less.tree` (node
|
|
144
|
+
* constructors) are intentionally NOT present on the Jess-backed build. Jess
|
|
145
|
+
* registers custom functions with `defineFunction(name, fn, opts)` supplied
|
|
146
|
+
* through the compiler config/plugins, and its values are Jess nodes, not
|
|
147
|
+
* `less.tree.*`. Providing these as throwing stubs would break feature-detection
|
|
148
|
+
* (`if (less.functions)`), so they are left absent until a real compat surface
|
|
149
|
+
* (registry -> defineFunction bridge + tree-node shims) is built. Tracked for
|
|
150
|
+
* the broader Less-runner/API-parity work; see also test/less-test.js guards.
|
|
151
|
+
*
|
|
152
|
+
* @type {import('./types.js').LessStatic}
|
|
153
|
+
*/
|
|
154
|
+
const less = {
|
|
155
|
+
version: lessVersion,
|
|
156
|
+
render,
|
|
157
|
+
renderFile,
|
|
158
|
+
logger,
|
|
159
|
+
lesscHelper,
|
|
160
|
+
Compiler,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export default less;
|
|
164
|
+
export { render, renderFile, logger, lesscHelper, Compiler, lessVersion as version };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for lessc CLI.
|
|
3
|
+
* Adapted from lib.bak/less-node/lessc-helper.js.
|
|
4
|
+
* @module less/lib/lessc-helper
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** @type {Record<string, [number, number]>} */
|
|
8
|
+
const STYLES = {
|
|
9
|
+
reset: [0, 0],
|
|
10
|
+
bold: [1, 22],
|
|
11
|
+
inverse: [7, 27],
|
|
12
|
+
underline: [4, 24],
|
|
13
|
+
yellow: [33, 39],
|
|
14
|
+
green: [32, 39],
|
|
15
|
+
red: [31, 39],
|
|
16
|
+
grey: [90, 39],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const lesscHelper = {
|
|
20
|
+
/** @param {string} str @param {string} style */
|
|
21
|
+
stylize(str, style) {
|
|
22
|
+
const s = STYLES[style] ?? STYLES.reset;
|
|
23
|
+
return `\x1b[${s[0]}m${str}\x1b[${s[1]}m`;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
printUsage() {
|
|
27
|
+
console.log('usage: lessc [option option=parameter ...] <source> [destination]');
|
|
28
|
+
console.log('');
|
|
29
|
+
console.log('If source is set to `-\' (dash or hyphen-minus), input is read from stdin.');
|
|
30
|
+
console.log('');
|
|
31
|
+
console.log('options:');
|
|
32
|
+
console.log(' -h, --help Prints help (this message) and exit.');
|
|
33
|
+
console.log(' -I PATH, -IPATH Adds an import search path.');
|
|
34
|
+
console.log(' --include-path=PATHS Sets include paths. Separated by `:\'. `;\' also supported on windows.');
|
|
35
|
+
console.log(' --no-color Disables colorized output.');
|
|
36
|
+
console.log(' -s, --silent Suppresses output of error messages.');
|
|
37
|
+
console.log(' --quiet Suppresses output of warnings.');
|
|
38
|
+
console.log(' -v, --version Prints version number and exit.');
|
|
39
|
+
console.log(' --verbose Be verbose.');
|
|
40
|
+
console.log(' --collapse-nesting[=MODE] Flatten nested rules: native (default), or compact.');
|
|
41
|
+
console.log(' -x, --compress Compress output by removing whitespace.');
|
|
42
|
+
console.log(' --math=MODE Math mode: parens-division (default), always, or parens.');
|
|
43
|
+
console.log(' --unit-mode=MODE Unit handling in math: preserve (default), strict, or loose (Less 4.x guessing).');
|
|
44
|
+
console.log(' --strict-units[=on|off] Deprecated: on is --unit-mode=strict, off is the default (preserve).');
|
|
45
|
+
console.log(' --source-map[=FILE] Emit a source map (FILE, or <destination>.map by default).');
|
|
46
|
+
console.log(' --source-map-inline Embed the source map as a data URI instead of a file.');
|
|
47
|
+
console.log(' --source-map-include-source Embed the source files in the map (sourcesContent).');
|
|
48
|
+
console.log(' --source-map-rootpath=PATH Prepend PATH to every source in the map.');
|
|
49
|
+
console.log(' --source-map-basepath=PATH Strip PATH from the front of every source in the map.');
|
|
50
|
+
console.log(' --source-map-url=URL Override the sourceMappingURL annotation.');
|
|
51
|
+
console.log(' --rewrite-urls[=all|local|off] Rewrite url(...) references in imported files.');
|
|
52
|
+
console.log(' --rootpath=PATH Prepend PATH to url(...) and import references.');
|
|
53
|
+
console.log(' --url-args=ARGS Append ARGS (e.g. cache-buster) to every url(...).');
|
|
54
|
+
console.log('');
|
|
55
|
+
console.log('This release intentionally supports a smaller CLI surface.');
|
|
56
|
+
console.log('Browser compilation, legacy plugin flags, and lint-only mode are not supported.');
|
|
57
|
+
console.log('');
|
|
58
|
+
console.log('Report bugs to: http://github.com/less/less.js/issues');
|
|
59
|
+
console.log('Home page: <http://lesscss.org/>');
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { lesscHelper };
|
|
64
|
+
export default lesscHelper;
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Less logger wired to Jess's logger singleton.
|
|
3
|
+
* Forwards to Jess and maintains Less-style addListener/removeListener for compatibility.
|
|
4
|
+
* @module less/lib/logger
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { logger as jessLogger } from '@jesscss/core';
|
|
8
|
+
|
|
9
|
+
/** @typedef {{ error?: (msg: string) => void, warn?: (msg: string) => void, info?: (msg: string) => void, debug?: (msg: string) => void }} LogListener */
|
|
10
|
+
|
|
11
|
+
/** @type {LogListener[]} */
|
|
12
|
+
const _listeners = [];
|
|
13
|
+
|
|
14
|
+
/** @param {'error'|'warn'|'info'|'debug'} type @param {string} msg */
|
|
15
|
+
function _fireEvent(type, msg) {
|
|
16
|
+
for (const listener of _listeners) {
|
|
17
|
+
const fn = listener[type];
|
|
18
|
+
if (fn) fn(msg);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Wrap Jess's logger so Less listeners receive Jess's log output without
|
|
23
|
+
// writing directly to stderr/stdout. Library consumers should be able to catch
|
|
24
|
+
// `less.render()` rejections without surprise terminal output; the CLI owns
|
|
25
|
+
// deciding whether/how to print diagnostics.
|
|
26
|
+
jessLogger.configure?.({
|
|
27
|
+
log(...args) {
|
|
28
|
+
_fireEvent('debug', args.map(String).join(' '));
|
|
29
|
+
},
|
|
30
|
+
info(...args) {
|
|
31
|
+
_fireEvent('info', args.map(String).join(' '));
|
|
32
|
+
},
|
|
33
|
+
warn(...args) {
|
|
34
|
+
_fireEvent('warn', args.map(String).join(' '));
|
|
35
|
+
},
|
|
36
|
+
error(...args) {
|
|
37
|
+
_fireEvent('error', args.map(String).join(' '));
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** Less-compatible logger backed by Jess's singleton */
|
|
42
|
+
const logger = {
|
|
43
|
+
/** @param {string} msg */
|
|
44
|
+
error(msg) {
|
|
45
|
+
_fireEvent('error', msg);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/** @param {string} msg */
|
|
49
|
+
warn(msg) {
|
|
50
|
+
_fireEvent('warn', msg);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/** @param {string} msg */
|
|
54
|
+
info(msg) {
|
|
55
|
+
_fireEvent('info', msg);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
/** @param {string} msg */
|
|
59
|
+
debug(msg) {
|
|
60
|
+
_fireEvent('debug', msg);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/** @param {LogListener} listener */
|
|
64
|
+
addListener(listener) {
|
|
65
|
+
_listeners.push(listener);
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/** @param {LogListener} listener */
|
|
69
|
+
removeListener(listener) {
|
|
70
|
+
const i = _listeners.indexOf(listener);
|
|
71
|
+
if (i >= 0) _listeners.splice(i, 1);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export { logger };
|
|
76
|
+
export default logger;
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options mapping between Less render options and Jess compiler config.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface LessRenderOptions {
|
|
6
|
+
filename?: string;
|
|
7
|
+
paths?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Legacy Less render plugins are routed through the alpha compatibility
|
|
10
|
+
* layer. File-manager, pre/post-processor, and @plugin execution are not
|
|
11
|
+
* alpha.1-supported surfaces yet.
|
|
12
|
+
*/
|
|
13
|
+
plugins?: unknown[];
|
|
14
|
+
math?: number | 'always' | 'parens-division' | 'parens' | 'strict';
|
|
15
|
+
/**
|
|
16
|
+
* How to flatten authored nesting. Less v5 preserves authored nesting by
|
|
17
|
+
* default (`false`). `'native'` applies the CSS Nesting desugaring (parent
|
|
18
|
+
* wrapped in `:is()`, child selector lists distributed — specificity-faithful,
|
|
19
|
+
* matching the browser and Less 4.x); `'compact'` additionally folds
|
|
20
|
+
* same-combinator descendant runs into a single `:is()`. `true` is a
|
|
21
|
+
* deprecated alias for `'native'`.
|
|
22
|
+
*/
|
|
23
|
+
collapseNesting?: boolean | 'native' | 'compact';
|
|
24
|
+
/** Minified output. */
|
|
25
|
+
compress?: boolean;
|
|
26
|
+
/** Prepend a path to every rewritten `url(...)` and imported reference. */
|
|
27
|
+
rootpath?: string;
|
|
28
|
+
/** Rewrite relative `url(...)` against the importing file: `'all'` | `'local'` | `'off'` (or boolean). */
|
|
29
|
+
rewriteUrls?: boolean | 'all' | 'local' | 'off';
|
|
30
|
+
/** Append a query string to every non-data `url(...)`. */
|
|
31
|
+
urlArgs?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Emit a source map. `true` turns it on with defaults; the object form (or the
|
|
34
|
+
* flat legacy `sourceMap*` options) configures it. Returned as `result.map`.
|
|
35
|
+
*/
|
|
36
|
+
sourceMap?: boolean | {
|
|
37
|
+
sourceMapURL?: string;
|
|
38
|
+
sourceMapFilename?: string;
|
|
39
|
+
sourceMapFullFilename?: string;
|
|
40
|
+
sourceMapRootpath?: string;
|
|
41
|
+
sourceMapBasepath?: string;
|
|
42
|
+
sourceMapFileInline?: boolean;
|
|
43
|
+
sourceMapOutputFilename?: string;
|
|
44
|
+
outputSourceFiles?: boolean;
|
|
45
|
+
disableSourcemapAnnotation?: boolean;
|
|
46
|
+
};
|
|
47
|
+
sourceMapURL?: string;
|
|
48
|
+
sourceMapFilename?: string;
|
|
49
|
+
sourceMapFullFilename?: string;
|
|
50
|
+
sourceMapRootpath?: string;
|
|
51
|
+
sourceMapBasepath?: string;
|
|
52
|
+
sourceMapFileInline?: boolean;
|
|
53
|
+
sourceMapOutputFilename?: string;
|
|
54
|
+
outputSourceFiles?: boolean;
|
|
55
|
+
disableSourcemapAnnotation?: boolean;
|
|
56
|
+
/** @internal Jess alpha benchmark-only flag for source graphs already proven @plugin-free. */
|
|
57
|
+
__jessSkipLessCompatWhenPluginFree?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LessRenderResult {
|
|
61
|
+
css: string;
|
|
62
|
+
map?: string;
|
|
63
|
+
imports?: string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface JessRenderResult {
|
|
67
|
+
css?: string;
|
|
68
|
+
map?: string | object;
|
|
69
|
+
imports?: string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createLessOptions(options?: LessRenderOptions): {
|
|
73
|
+
configOptions: object;
|
|
74
|
+
filePath?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function getCompilerCacheKey(configOptions: object): string;
|
|
78
|
+
|
|
79
|
+
export function mapRenderResult(
|
|
80
|
+
result: JessRenderResult,
|
|
81
|
+
options?: LessRenderOptions
|
|
82
|
+
): LessRenderResult;
|