-
Notifications
You must be signed in to change notification settings - Fork 7.6k
fix loading of less imports on win, linux and mac #7522
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
var FileSystem = require("filesystem/FileSystem"); | ||
|
||
/** | ||
* Appends a <style> tag to the document's head. | ||
* | ||
|
@@ -66,6 +68,18 @@ define(function (require, exports, module) { | |
return $link[0]; | ||
} | ||
|
||
/** | ||
* getModuleUrl returns different urls for win platform | ||
* so that's why we need a different check here | ||
* @see getModuleUrl() | ||
* @param {!string} pathOrUrl that should be checked if it's absolute | ||
* @return {!boolean} returns true if pathOrUrl is absolute url on win platform | ||
* or when it's absolute path on other platforms | ||
*/ | ||
function isAbsolutePathOrUrl(pathOrUrl) { | ||
return brackets.platform === "win" ? PathUtils.isAbsoluteUrl(pathOrUrl) : FileSystem.isAbsolutePath(pathOrUrl); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zaggino I don't like the idea of this solution because I think it sets a bad precedent -- pretty soon we'll have to do this everywhere. The What code is failing? Maybe that code should convert the local file path to a url instead. cc @peterflynn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right this is a bad solution ... here's the problematic code (line 140):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @redmunds The Where is the path originating from in this case? It seems like it's part of the Require There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This results in url being different for win vs others so different check is also needed depending on the platform... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, @zaggino sorry, your replies didn't show up until I reloaded the page. So tt seems like our own In the loadFile() case we could just do the absolute check before converting getModulePath() to a URL... but in the loadStyleSheet() -> parseLessCode() case we're going off of the URL fed into $.get() ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wasn't suggesting that API should be changed, just not used here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the check a bit according to |
||
|
||
/** | ||
* Parses LESS code and returns a promise that resolves with plain CSS code. | ||
* | ||
|
@@ -91,7 +105,7 @@ define(function (require, exports, module) { | |
rootpath: dir | ||
}; | ||
|
||
if (PathUtils.isAbsoluteUrl(url)) { | ||
if (isAbsolutePathOrUrl(url)) { | ||
options.currentFileInfo = { | ||
currentDirectory: dir, | ||
entryPath: dir, | ||
|
@@ -161,7 +175,7 @@ define(function (require, exports, module) { | |
* @return {!$.Promise} A promise object that is resolved with the contents of the requested file | ||
**/ | ||
function loadFile(module, path) { | ||
var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path), | ||
var url = isAbsolutePathOrUrl(path) ? path : getModuleUrl(module, path), | ||
promise = $.get(url); | ||
|
||
return promise; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs a reference to hack done in
getModuleUrl()
to help keep these functions in sync.Also needs jsdoc info for
@param
and@return
.