Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 0e8b080

Browse files
committed
Merge pull request #7230 from adobe/zaggino/less-fix
Fix a case when extension less file is importing other less files
2 parents cd86e0f + ec54316 commit 0e8b080

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/utils/ExtensionUtils.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
26-
/*global define, $, brackets, less */
26+
/*global define, $, brackets, less, PathUtils */
2727

2828
/**
2929
* ExtensionUtils defines utility methods for implementing extensions.
@@ -90,6 +90,16 @@ define(function (require, exports, module) {
9090
paths: [dir],
9191
rootpath: dir
9292
};
93+
94+
if (PathUtils.isAbsoluteUrl(url)) {
95+
options.currentFileInfo = {
96+
currentDirectory: dir,
97+
entryPath: dir,
98+
filename: url,
99+
rootFilename: url,
100+
rootpath: dir
101+
};
102+
}
93103
}
94104

95105
var parser = new less.Parser(options);
@@ -151,7 +161,7 @@ define(function (require, exports, module) {
151161
* @return {!$.Promise} A promise object that is resolved with the contents of the requested file
152162
**/
153163
function loadFile(module, path) {
154-
var url = getModuleUrl(module, path),
164+
var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path),
155165
promise = $.get(url);
156166

157167
return promise;

test/spec/ExtensionUtils-test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ define(function (require, exports, module) {
111111
waitsForFail(promise, "loadStyleSheet: " + path);
112112
});
113113
});
114-
115-
// putting everything LESS related in 1 test so it runs faster
114+
116115
it("should attach LESS style sheets", function () {
117116
var promise, result;
118117

@@ -137,6 +136,35 @@ define(function (require, exports, module) {
137136
expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy();
138137
});
139138
});
139+
140+
it("should attach LESS style sheets using absolute url", function () {
141+
var promise, result;
142+
143+
runs(function () {
144+
var indexLocation = testWindow.location.origin + testWindow.location.pathname,
145+
bracketsLocation = indexLocation.substring(0, indexLocation.length - "src/index.html".length),
146+
basicLessLocation = bracketsLocation + "test/spec/ExtensionUtils-test-files/basic.less";
147+
148+
promise = loadStyleSheet(testWindow.document, basicLessLocation);
149+
promise.done(function (style) {
150+
result = style;
151+
});
152+
153+
waitsForDone(promise);
154+
});
155+
156+
runs(function () {
157+
// convert all line endings to platform default
158+
var windowText = FileUtils.translateLineEndings(testWindow.$(result).text()),
159+
lessText = FileUtils.translateLineEndings(LESS_RESULT);
160+
161+
// confirm style sheet contents
162+
expect(windowText).toBe(lessText);
163+
164+
// confirm style is attached to document
165+
expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy();
166+
});
167+
});
140168
});
141169
});
142170
});

0 commit comments

Comments
 (0)