Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/less/build/browser-dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const result = await esbuild.build({
banner: {
js:
'/*! Less v5 (alpha) browser build. For live styling in the browser, follow the Less browser guide. Compiling Less in the browser is not intended for production — compile ahead of time (Node "less") for production builds. */\n' +
'var process = (typeof globalThis !== "undefined" && globalThis.process) || { env: {}, cwd: function () { return "/"; }, argv: [], platform: "browser" };'
'var process = (typeof globalThis !== "undefined" && globalThis.process) || { env: {}, cwd: function () { return "/"; }, argv: [], platform: "browser", stderr: {}, stdout: {} };'
},
alias: {
fs: join(stubs, 'fs.js'),
Expand Down
8 changes: 2 additions & 6 deletions packages/less/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { readFileSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { Compiler } from '@jesscss/compiler';
import nodeModulesPlugin from '@jesscss/plugin-node-modules';
import { LessCompiler } from './less-compiler.js';
import { createLessOptions, getCompilerCacheKey, mapRenderResult } from './options.js';
import { version } from './version.js';
import { logger } from './logger.js';
Expand Down Expand Up @@ -71,11 +71,7 @@ function getCompiler(configOptions) {
const cacheKey = getCompilerCacheKey(configOptions);
let compiler = compilerCache.get(cacheKey);
if (!compiler) {
compiler = new Compiler(configOptions, {
defaultPlugins: context => [nodeModulesPlugin({ basePath: context.resolutionBaseDir })],
scriptPluginSpecifier: '@jesscss/plugin-js',
scriptPluginResolveFrom: import.meta.url
});
compiler = new LessCompiler(configOptions);
compilerCache.set(cacheKey, compiler);
}
return compiler;
Expand Down
27 changes: 27 additions & 0 deletions packages/less/lib/less-compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Compiler } from '@jesscss/compiler';
import nodeModulesPlugin from '@jesscss/plugin-node-modules';

/**
* The compiler `less.render()` runs: the Jess compiler with Less's default
* plugins. It names its own module, so a render that reaches a `@plugin`
* script runs whole in the `@jesscss/plugin-js` sandbox with this same
* compiler, made there from this module.
*/
export class LessCompiler extends Compiler {
/*
* Spelled relative to `lib/` so it names this file from the ESM entry and
* from the bundled CommonJS build in `dist/` alike.
*/
static moduleIdentity = { module: new URL('../lib/less-compiler.js', import.meta.url).href, exportName: 'LessCompiler' };

/**
* @param {object} configOptions
*/
constructor(configOptions) {
super(configOptions, {
defaultPlugins: context => [nodeModulesPlugin({ basePath: context.resolutionBaseDir })],
scriptPluginSpecifier: '@jesscss/plugin-js',
scriptPluginResolveFrom: import.meta.url
});
}
}
14 changes: 7 additions & 7 deletions packages/less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"scripts": {
"quicktest": "npm run test:legacy-node",
"test:alpha": "npm run typecheck && npm run build && npm run test:lessc && node test/jess-alpha-fast-path.mjs && node test/alpha-support.mjs && node test/alpha-sourcemaps.mjs && node test/alpha-fixtures.mjs",
"test:alpha": "npm run typecheck && npm run build && npm run test:lessc && node test/jess-alpha-fast-path.mjs && node test/alpha-support.mjs && node test/alpha-sourcemaps.mjs && node test/alpha-fixtures.mjs && npm run build:browser && node test/alpha-browser-bundle.mjs",
"test:lessc": "node test/lessc-alpha.mjs",
"test": "npm run test:alpha",
"test:module": "node test/test-es6.js && node test/test-cjs.cjs",
Expand Down Expand Up @@ -142,15 +142,15 @@
"rawcurrent": "https://raw.github.com/less/less.js/v",
"sourcearchive": "https://github.com/less/less.js/archive/v",
"dependencies": {
"@jesscss/compiler": "2.0.0-alpha.31",
"@jesscss/core": "2.0.0-alpha.31",
"@jesscss/plugin-less": "2.0.0-alpha.31",
"@jesscss/plugin-less-compat": "2.0.0-alpha.31",
"@jesscss/plugin-node-modules": "2.0.0-alpha.31",
"@jesscss/compiler": "2.0.0-alpha.32",
"@jesscss/core": "2.0.0-alpha.32",
"@jesscss/plugin-less": "2.0.0-alpha.32",
"@jesscss/plugin-less-compat": "2.0.0-alpha.32",
"@jesscss/plugin-node-modules": "2.0.0-alpha.32",
"parse-node-version": "^1.0.1"
},
"peerDependencies": {
"@jesscss/plugin-js": "2.0.0-alpha.31"
"@jesscss/plugin-js": "2.0.0-alpha.32"
},
"peerDependenciesMeta": {
"@jesscss/plugin-js": {
Expand Down
32 changes: 32 additions & 0 deletions packages/less/test/alpha-browser-bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Loads the built `dist/less-browser-dev.js` in a context with browser globals
* and no Node `process`, then renders through `window.less`. Run `build:browser`
* first.
*/
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import vm from 'node:vm';

const bundle = readFileSync(new URL('../dist/less-browser-dev.js', import.meta.url), 'utf8');

const window = {
location: { href: 'http://localhost/' },
document: {},
console,
setTimeout,
clearTimeout,
URL,
TextEncoder,
TextDecoder,
queueMicrotask,
performance
};
window.window = window;
window.globalThis = window;
window.self = window;

vm.runInContext(bundle, vm.createContext(window));

const { css } = await window.less.render('.m() { x: 1; }\n.a { b: (1 + 1); .m(); &:hover { c: contrast(#f00); } }\n');
assert.equal(css, '.a {\n b: 2;\n x: 1;\n &:hover {\n c: #000000;\n }\n}\n');
console.log('Less browser bundle render passed');
1 change: 0 additions & 1 deletion packages/less/test/alpha-fixtures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ const expectedFailureFixtures = new Map([
['tests-unit/plugin-module/plugin-module.less', 'legacy CommonJS @plugin graph with require() is not supported by the optional JS runtime'],
['tests-unit/plugin-preeval/plugin-preeval.less', 'legacy tree visitor ABI is not supported'],
['tests-unit/plugin/plugin.less', '@plugin scripts execute; the Less 4 golden uses the deprecated registerPlugin/(option) lifecycle and flattened output. v5 intentionally does NOT merge nested @media (nesting is preserved by design), so that is not a gap'],
['tests-unit/parse-interpolation/parse-interpolation.less', 'renders but interpolation formatting differs from Less'],
['tests-unit/parser-slashed-combinator/parser-slashed-combinator.less', 'slashed combinator not yet supported'],
['tests-unit/permissive-parse/permissive-parse.less', 'permissive legacy parser corners are not alpha-supported'],
['tests-unit/media/media.less', 'top-level bare @var at-rule preludes are rejected'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.var-args {
width: 45;
height: 8%;
depth: 18 / 2 - 1%;
depth: 8%;
}
.multi-mix {
width: 10px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
margin-keep: 12;
margin-parts: 12;
margin-all: 12;
border-radius-keep: 8px / 7px;
border-radius-keep: 4px * 2 / 4 + 3px;
border-radius-parts: 8px / 7px;
border-radius-all: 5px;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/test-data/tests-unit/functions/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
saturate-filter: saturate(5%);
contrast-white: #000000;
contrast-black: #ffffff;
contrast-red: #ffffff;
contrast-red: #000000;
contrast-green: #000000;
contrast-blue: #ffffff;
contrast-yellow: #000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
b: cos(var(--a));
c: calc(tan(var(--t)) * 1px);
d: atan2(var(--x), var(--y));
e: percentage(var(--p));
e: calc(var(--p) * 100%);
}
.numeric {
a: 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
result: #ff0a0a;
}
.test-division {
result: calc(10px / 2 * 2);
result: 10px;
}
.test-nested {
result: 30px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ input[type=text], input[type=email], input[type=password], textarea {
}
}
.bar {
.d:is(.a, .b, .c)&:hover, baz-cap {
.d:is(.a, .b, .c)&:hover,
baz-cap {
color: blue;
}
}
Expand All @@ -41,7 +42,7 @@ input[type=text], input[type=email], input[type=password], textarea {
}
.a, .b.c, .d {
+ .e-quoted {
foo: bar;
foo: baz;
}
}
input.cap {
Expand All @@ -66,9 +67,11 @@ input.quoted {
background-color: blue;
}
}
.fruit-cap-apple,
.fruit-cap-satsuma,
.fruit-cap-banana,
.fruit-cap-pear {
content: "Capture";
apple,
satsuma,
banana,
pear {
.fruit-cap-& {
content: "Capture";
}
}
Loading
Loading