Skip to content

Commit

Permalink
Merge pull request #49 from jasonsanjose/jasonsanjose/node-sass-1.1.4
Browse files Browse the repository at this point in the history
node-sass 1.1.4
  • Loading branch information
jasonsanjose committed Nov 5, 2014
2 parents 6fdd079 + 7798945 commit abe5736
Show file tree
Hide file tree
Showing 2,360 changed files with 6,378 additions and 20,113 deletions.
28 changes: 24 additions & 4 deletions Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ define(function (require, exports, module) {
NodeDomain = brackets.getModule("utils/NodeDomain");

// Boilerplate to load NodeDomain
var _domainPath = ExtensionUtils.getModulePath(module, "node/SASSDomain"),
var _domainPath = ExtensionUtils.getModulePath(module, "node/1.1.4/SASSDomain"),
_nodeDomain = new NodeDomain("sass", _domainPath);

// Initialize temp folder on windows only
// This is to normalize windows paths instead of using Node's os.tmpdir()
// which usually resolves to C:\Users\name~1\..., getApplicationSupportDirectory
// will resolve to C:\Users\name_000 instead which is more compatible
// with Brackets' FileSystem paths
if (brackets.platform === "win") {
_nodeDomain.exec("setTempDir", brackets.app.getApplicationSupportDirectory()).fail(function (err) {
console.error("Failed creating brackets-sass temporary directory: " + err);
});
}

var RE_FILE_EXT = /\.(sass|scss)$/,
PREF_ENABLED = "enabled",
PREF_OPTIONS = "options";
Expand Down Expand Up @@ -163,7 +174,9 @@ define(function (require, exports, module) {
var map = {};

_.each(docs, function (doc) {
map[doc.file.fullPath] = doc.getText();
if (doc.isDirty) {
map[doc.file.fullPath] = doc.getText();
}
});

return map;
Expand All @@ -186,8 +199,15 @@ define(function (require, exports, module) {
errors = Array.isArray(errors) ? errors : [errors];

_.each(errors, function (err) {
// Can't report errors on files other than the current document, see CodeInspection
if (path !== err.path) {
if (typeof err === "string") {
err = {
message: "Runtime error: " + err,
pos: {
line: -1
}
};
} else if (path !== err.path) {
// Can't report errors on files other than the current document, see CodeInspection
// Clone error
var clonedError = _.clone(err);
clonedError.pos = _.clone(err.pos);
Expand Down
File renamed without changes.
147 changes: 107 additions & 40 deletions node/SASSDomain.js → node/1.1.4/SASSDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,31 @@ var cp = require("child_process"),
sass = require("node-sass");

var _domainManager,
_tmpdir,
tmpFolders = [];

// [path]:[line]:[error string]
var RE_ERROR = /(.*)(:([0-9]+):)(.*)/;

/**
* Normalize path separator, drop drive letter on windows, and
* return new string starting with first path separator.
* e.g. C:/Users/me/file.txt -> \Users\me\file.txt
*/
function normalize(fullPath) {
// Convert path separator for windows
var result = path.resolve(path.normalize(fullPath));

// Drop drive letter
var firstSep = result.indexOf(path.sep);
return (firstSep >= 0) ? result.slice(firstSep) : result;
}

function tmpdir() {
if (_tmpdir) {
return _tmpdir;
}

var baseTmpDir = os.tmpdir();

if (baseTmpDir.charAt(baseTmpDir.length - 1) !== path.sep) {
Expand Down Expand Up @@ -78,6 +97,8 @@ function _toRelativePaths(file, pathsArray) {
relative;

if (pathsArray) {
pathsArray = Array.isArray(pathsArray) ? pathsArray : [pathsArray];

pathsArray.forEach(function (p) {
absolute = path.resolve(file, p);
relative = path.relative(file, absolute);
Expand All @@ -88,9 +109,25 @@ function _toRelativePaths(file, pathsArray) {
return retval;
}

function _toAbsolutePaths(file, pathsArray) {
var retval = [],
absolute;

if (pathsArray) {
pathsArray = Array.isArray(pathsArray) ? pathsArray : [pathsArray];

pathsArray.forEach(function (p) {
absolute = path.resolve(file, p);
retval.push(absolute);
});
}

return retval;
}

function render(file, includePaths, imagePaths, outputStyle, sourceComments, sourceMap, callback) {
var renderScript = __dirname + "/render",
cwd = path.dirname(file) + "/",
var renderScript = __dirname + path.sep + "render",
cwd = path.resolve(path.dirname(file)) + path.sep,
options = { cwd: cwd },
child = cp.fork(renderScript, [], options);

Expand Down Expand Up @@ -125,9 +162,9 @@ function render(file, includePaths, imagePaths, outputStyle, sourceComments, sou

// Ensure relative paths so that absolute paths don't sneak into generated
// CSS and source maps
includePaths = _toRelativePaths(file, includePaths);
imagePaths = _toRelativePaths(file, imagePaths);

includePaths = _toAbsolutePaths(cwd, includePaths);
imagePaths = _toAbsolutePaths(cwd, imagePaths);
// Paths are relative to current working directory (file parent folder)
var renderMsg = {
cwd: cwd,
Expand All @@ -142,27 +179,13 @@ function render(file, includePaths, imagePaths, outputStyle, sourceComments, sou
child.send(renderMsg);
}

/**
* Normalize path separator, drop drive letter on windows, and
* return new string starting with first path separator.
* e.g. C:/Users/me/file.txt -> \Users\me\file.txt
*/
function normalize(fullPath) {
// Convert path separator for windows
var result = path.normalize(fullPath);

// Drop drive letter
var firstSep = result.indexOf(path.sep);
return (firstSep >= 0) ? result.slice(firstSep) : result;
}

function preview(file, inMemoryFiles, includePaths, imagePaths, outputStyle, sourceComments, sourceMap, callback) {
// Convert path separator for windows
file = normalize(file);
var normalizedFile = normalize(file);

var originalParent = path.dirname(file),
var originalParent = path.dirname(normalizedFile),
tmpDirPath = tmpdir(),
tmpFolder = tmpDirPath + originalParent,
tmpFolder = path.join(tmpDirPath, originalParent),
tmpFile = tmpFolder + path.sep + path.basename(file);

// Delete existing files if they exist
Expand All @@ -172,15 +195,15 @@ function preview(file, inMemoryFiles, includePaths, imagePaths, outputStyle, sou
tmpFolders.push(tmpFolder);

// Copy files to temp folder
fsextra.copySync(originalParent, tmpFolder);
//fsextra.copySync(originalParent, tmpFolder);
fsextra.copySync(file, tmpFile);

// includePath is resolved based on temp location (not original folder)
var tmpIncludePath;

// Ensure relative paths so that absolute paths don't sneak into generated
// CSS and source maps
includePaths = _toRelativePaths(tmpFile, includePaths);
imagePaths = _toRelativePaths(tmpFile, imagePaths);

// Convert include and image paths to absolute paths
includePaths = _toAbsolutePaths(originalParent, includePaths);
imagePaths = _toAbsolutePaths(originalParent, imagePaths);

// Add original file dir as includePath to handle "../" relative imports
includePaths.unshift(originalParent);
Expand All @@ -191,26 +214,53 @@ function preview(file, inMemoryFiles, includePaths, imagePaths, outputStyle, sou

absPaths.forEach(function (absPath) {
inMemoryText = inMemoryFiles[absPath];
fs.writeFileSync(tmpDirPath + normalize(absPath), inMemoryText);
fsextra.outputFileSync(tmpDirPath + normalize(absPath), inMemoryText);
});

render(tmpFile, includePaths, imagePaths, outputStyle, sourceComments, sourceMap, function (errors, result) {
// Remove tmpdir path prefix from error paths
if (errors) {
var indexOfTemp;

var indexOfTemp,
normalizedTempFilePath = path.normalize(tmpFile),
normalizedErrorPath;

errors.forEach(function (error) {
// FIXME why does path start with /private on mac sometimes?
indexOfTemp = error.path.indexOf(tmpDirPath);

if (indexOfTemp >= 0) {
error.path = error.path.slice(indexOfTemp + tmpDirPath.length);
normalizedErrorPath = path.normalize(error.path);

if (normalizedErrorPath === normalizedTempFilePath) {
error.path = file;
} else {
error.path = error.path.replace(tmpDirPath, "");
error.path = path.resolve(tmpFolder, error.path);
}
});
} else {
// Convert relative paths to tmpFile in source map
var map = JSON.parse(result.map);

if (Array.isArray(map.sources)) {
var newSources = [],
absPath;

map.sources.forEach(function (source) {
// Resolve to absolute path, then resolve relative to input file parent folder
absPath = path.resolve(tmpFolder, source);

if (path.normalize(absPath) === tmpFile) {
// Special case for input file
newSources.push(path.basename(file));
} else {
newSources.push(path.relative(path.dirname(file), absPath));
}
});

// Replaces sources with updated relative paths
map.sources = newSources;

// Send updated JSON string
result.map = JSON.stringify(map);
}
}

callback(errors, result);
});
}
Expand All @@ -223,8 +273,14 @@ function deleteTempFiles() {
tmpFolders = [];
}

function mkdirp(path, callback) {
fsextra.mkdirp(path, callback);
function mkdirp(pathToDir, callback) {
fsextra.mkdirp(pathToDir, callback);
}


function setTempDir(pathToDir, callback) {
_tmpdir = path.join(pathToDir, "brackets-sass");
fsextra.mkdirp(_tmpdir, callback);
}

/**
Expand Down Expand Up @@ -289,6 +345,17 @@ function init(domainManager) {
]
);

domainManager.registerCommand(
"sass",
"setTempDir",
setTempDir,
true,
"Set the temporary directory used for in-memory compiling",
[
{name: "path", type: "string"}
]
);

_domainManager = domainManager;
}

Expand Down
15 changes: 15 additions & 0 deletions node/1.1.4/node_modules/.bin/node-sass

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node/1.1.4/node_modules/.bin/node-sass.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit abe5736

Please sign in to comment.