From 97f70820fbebb289490c8febc2e93ee1079328f3 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Thu, 21 Apr 2022 17:41:38 -0700 Subject: [PATCH] fix: Fix https failures on macOS (#3716) The issue was traced upstream to needle, and resolved in: - https://github.com/tomas/needle/pull/392 - https://github.com/tomas/needle/pull/394 - https://github.com/tomas/needle/pull/396 - https://github.com/tomas/needle/pull/398 Closes #3693 --- packages/less/package-lock.json | 20 +++++++++--- packages/less/package.json | 2 +- packages/less/src/less/tree/ruleset.js | 31 ++++++++++++++----- packages/test-data/css/_main/import.css | 12 +++++++ packages/test-data/less/_main/import.less | 14 +++++++++ .../less/_main/import/import-style.less | 7 +++++ 6 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 packages/test-data/less/_main/import/import-style.less diff --git a/packages/less/package-lock.json b/packages/less/package-lock.json index 7dd121000..6c8e42fe6 100644 --- a/packages/less/package-lock.json +++ b/packages/less/package-lock.json @@ -1,6 +1,6 @@ { "name": "less", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3373,6 +3373,7 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } @@ -4436,13 +4437,13 @@ "dev": true }, "needle": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/needle/-/needle-2.5.2.tgz", - "integrity": "sha512-LbRIwS9BfkPvNwNHlsA41Q29kL2L/6VaOJ0qisM5lLWsTV3nP15abO5ITL6L81zqFhzjRKDAYjpcBcwM0AVvLQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/needle/-/needle-3.1.0.tgz", + "integrity": "sha512-gCE9weDhjVGCRqS8dwDR/D3GTAeyXLXuqp7I8EzH6DllZGXSUyxuqqLh+YX9rMAWaaTFyVAg6rHGL25dqvczKw==", "optional": true, "requires": { "debug": "^3.2.6", - "iconv-lite": "^0.4.4", + "iconv-lite": "^0.6.3", "sax": "^1.2.4" }, "dependencies": { @@ -4454,6 +4455,15 @@ "requires": { "ms": "^2.1.1" } + }, + "iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "optional": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } } } }, diff --git a/packages/less/package.json b/packages/less/package.json index 5976af2f0..2265157a5 100644 --- a/packages/less/package.json +++ b/packages/less/package.json @@ -50,7 +50,7 @@ "image-size": "~0.5.0", "make-dir": "^2.1.0", "mime": "^1.4.1", - "needle": "^2.5.2", + "needle": "^3.1.0", "source-map": "~0.6.0" }, "devDependencies": { diff --git a/packages/less/src/less/tree/ruleset.js b/packages/less/src/less/tree/ruleset.js index 22f68b75c..08b4dcc65 100644 --- a/packages/less/src/less/tree/ruleset.js +++ b/packages/less/src/less/tree/ruleset.js @@ -81,9 +81,9 @@ Ruleset.prototype = Object.assign(new Node(), { } this.parse.parseNode( toParseSelectors.join(','), - ["selectors"], - selectors[0].getIndex(), - selectors[0].fileInfo(), + ["selectors"], + selectors[0].getIndex(), + selectors[0].fileInfo(), function(err, result) { if (result) { selectors = utils.flattenArray(result); @@ -230,17 +230,34 @@ Ruleset.prototype = Object.assign(new Node(), { let i; let importRules; if (!rules) { return; } - + const importDecl = {}; for (i = 0; i < rules.length; i++) { if (rules[i].type === 'Import') { importRules = rules[i].eval(context); if (importRules && (importRules.length || importRules.length === 0)) { + // fix: #3563 + importRules.forEach((node, index) => { + if (node instanceof Declaration) { + if (!importDecl[node.name]) { + importDecl[node.name] = [i + index] + } else { + importDecl[node.name].push(i + index) + } + } + }) rules.splice.apply(rules, [i, 1].concat(importRules)); i += importRules.length - 1; } else { rules.splice(i, 1, importRules); } this.resetCache(); + } else if (rules[i] instanceof Declaration && importDecl[rules[i].name]) { + const name = rules[i].name + importDecl[name].forEach(e => { + if (rules[e].name === name) { + rules[e].value = rules[i].value + } + }) } } }, @@ -356,9 +373,9 @@ Ruleset.prototype = Object.assign(new Node(), { if (typeof decl.value.value === 'string') { this.parse.parseNode( decl.value.value, - ['value', 'important'], - decl.value.getIndex(), - decl.fileInfo(), + ['value', 'important'], + decl.value.getIndex(), + decl.fileInfo(), function(err, result) { if (err) { decl.parsed = true; diff --git a/packages/test-data/css/_main/import.css b/packages/test-data/css/_main/import.css index 4590222ea..6b69ec78f 100644 --- a/packages/test-data/css/_main/import.css +++ b/packages/test-data/css/_main/import.css @@ -47,3 +47,15 @@ width: 100%; } } +.some-class { + color: var(--primary-color); + backgroundColor: var(--bg-color); +} +:root { + --primary-color: #fff; + --bg-color: #000; +} +html[data-theme="dark"] { + --primary-color: #000; + --bg-color: #fff; +} diff --git a/packages/test-data/less/_main/import.less b/packages/test-data/less/_main/import.less index e7d175692..346eaa19a 100644 --- a/packages/test-data/less/_main/import.less +++ b/packages/test-data/less/_main/import.less @@ -30,3 +30,17 @@ @charset "UTF-8"; // climb on top #2126 +// #3563 +@import "import/import-style.less"; +@base-color: var(--primary-color); +@dark-color: var(--bg-color); + +:root { + --primary-color: #fff; + --bg-color: #000; +} + +html[data-theme="dark"] { + --primary-color: #000; + --bg-color: #fff; +} diff --git a/packages/test-data/less/_main/import/import-style.less b/packages/test-data/less/_main/import/import-style.less new file mode 100644 index 000000000..76e7fa4fa --- /dev/null +++ b/packages/test-data/less/_main/import/import-style.less @@ -0,0 +1,7 @@ +@base-color: green; +@dark-color: darken(@base-color, 50%); + +.some-class { + color: @base-color; + backgroundColor: @dark-color; +}