Commit 94168369 by Adeel Mujahid

Merge pull request #660 from am11/master

Misc. Fixes
parents fe1d59f5 b48d5d6a
...@@ -6,11 +6,12 @@ compiler: ...@@ -6,11 +6,12 @@ compiler:
- gcc - gcc
node_js: node_js:
- "0.10" - "0.10"
- "0.11" - "0.12"
- iojs
matrix: matrix:
fast_finish: true fast_finish: true
allow_failures: allow_failures:
- node_js: "0.11" - node_js: iojs
before_install: before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test;
- sudo apt-get update; - sudo apt-get update;
......
...@@ -6,18 +6,21 @@ init: ...@@ -6,18 +6,21 @@ init:
environment: environment:
SKIP_SASS_BINARY_DOWNLOAD_FOR_CI: true SKIP_SASS_BINARY_DOWNLOAD_FOR_CI: true
matrix: matrix:
# node.js
- nodejs_version: 0.10 - nodejs_version: 0.10
- nodejs_version: 0.11 - nodejs_version: 0.12
# io.js
- nodejs_version: "1.1"
install: install:
- ps: Install-Product node $env:nodejs_version - ps: Install-Product node $env:nodejs_version
- cmd: SET PATH=C:\python27;%PATH% - cmd: SET PATH=C:\python27;%PATH%
- git submodule update --init --recursive - git submodule update --init --recursive
- ps: npm install --msvs_version=2013 - ps: npm install --msvs_version=2013
test_script:
- node --version - node --version
- npm --version - npm --version
test_script:
- npm test - npm test
build: off build: off
...@@ -10,19 +10,22 @@ var semver = require('semver'), ...@@ -10,19 +10,22 @@ var semver = require('semver'),
function getRuntimeName() { function getRuntimeName() {
return process.execPath return process.execPath
.split(/[\\/]+/).pop() .split(/[\\/]+/).pop()
.split('.')[0]; .split('.').shift();
} }
/** /**
* Get unique name of binary for current platform * Get unique name of binary for current platform
* *
* @api public * @api private
*/ */
module.exports.getBinaryIdentifiableName = function() { function getBinaryIdentifiableName() {
return process.platform + '-' + return [process.platform, '-',
process.arch + '-' + process.arch, '-',
getRuntimeName() + '-' + getRuntimeName(), '-',
runtimeVersion.major + '.' + runtimeVersion.major, '.',
runtimeVersion.minor; runtimeVersion.minor].join('');
}; }
process.runtime = getRuntimeName();
process.sassBinaryName = getBinaryIdentifiableName();
var fs = require('fs'), var fs = require('fs'),
path = require('path'), path = require('path');
utils = require('./utils');
require('./extensions');
/** /**
* Get binding * Get binding
...@@ -12,10 +13,10 @@ function getBinding() { ...@@ -12,10 +13,10 @@ function getBinding() {
var candidates = [ var candidates = [
path.join(__dirname, '..', 'build', 'Debug', 'binding.node'), path.join(__dirname, '..', 'build', 'Debug', 'binding.node'),
path.join(__dirname, '..', 'build', 'Release', 'binding.node'), path.join(__dirname, '..', 'build', 'Release', 'binding.node'),
path.join(__dirname, '..', 'vendor', utils.getBinaryIdentifiableName(), 'binding.node') path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node')
]; ];
var candidate = candidates.filter(fs.existsSync)[0]; var candidate = candidates.filter(fs.existsSync).shift();
if (!candidate) { if (!candidate) {
throw new Error('`libsass` bindings not found. Try reinstalling `node-sass`?'); throw new Error('`libsass` bindings not found. Try reinstalling `node-sass`?');
...@@ -146,12 +147,7 @@ function getOptions(options) { ...@@ -146,12 +147,7 @@ function getOptions(options) {
var success = options.success; var success = options.success;
options.error = function(err, code) { options.error = function(err, code) {
try { err = JSON.parse(err);
err = JSON.parse(err);
} catch (e) {
err = { message: err };
}
err.code = code; err.code = code;
if (error) { if (error) {
...@@ -166,7 +162,7 @@ function getOptions(options) { ...@@ -166,7 +162,7 @@ function getOptions(options) {
if (success) { if (success) {
success({ success({
css: result.css, css: result.css,
map: result.sourceMap, map: result.map,
stats: stats stats: stats
}); });
} }
......
...@@ -64,6 +64,6 @@ ...@@ -64,6 +64,6 @@
"jscoverage": "^0.5.9", "jscoverage": "^0.5.9",
"jshint": "^2.6.0", "jshint": "^2.6.0",
"mocha-lcov-reporter": "^0.0.1", "mocha-lcov-reporter": "^0.0.1",
"pangyp": "^2.0.2" "pangyp": "^2.1.0"
} }
} }
...@@ -2,8 +2,9 @@ var fs = require('fs'), ...@@ -2,8 +2,9 @@ var fs = require('fs'),
path = require('path'), path = require('path'),
spawn = require('child_process').spawn, spawn = require('child_process').spawn,
mkdir = require('mkdirp'), mkdir = require('mkdirp'),
Mocha = require('mocha'), Mocha = require('mocha');
utils = require('../lib/utils');
require('../lib/extensions');
/** /**
* After build * After build
...@@ -15,9 +16,9 @@ var fs = require('fs'), ...@@ -15,9 +16,9 @@ var fs = require('fs'),
function afterBuild(options) { function afterBuild(options) {
var folder = options.debug ? 'Debug' : 'Release'; var folder = options.debug ? 'Debug' : 'Release';
var target = path.join(__dirname, '..', 'build', folder, 'binding.node'); var target = path.join(__dirname, '..', 'build', folder, 'binding.node');
var install = path.join(__dirname, '..', 'vendor', options.bin, 'binding.node'); var install = path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node');
mkdir(path.join(__dirname, '..', 'vendor', options.bin), function (err) { mkdir(path.join(__dirname, '..', 'vendor', process.sassBinaryName), function (err) {
if (err && err.code !== 'EEXIST') { if (err && err.code !== 'EEXIST') {
console.error(err.message); console.error(err.message);
return; return;
...@@ -49,9 +50,8 @@ function afterBuild(options) { ...@@ -49,9 +50,8 @@ function afterBuild(options) {
*/ */
function build(options) { function build(options) {
var bin = options.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp'; var proc = spawn(process.execPath, ['node_modules/pangyp/bin/node-gyp', 'rebuild'].concat(options.args), {
var proc = spawn(bin, ['rebuild'].concat(options.args), { stdio: [0, 1, 2]
customFds: [0, 1, 2]
}); });
proc.on('exit', function(code) { proc.on('exit', function(code) {
...@@ -92,7 +92,7 @@ function parseArgs(args) { ...@@ -92,7 +92,7 @@ function parseArgs(args) {
return false; return false;
} else if (arg.substring(0, 13) === '--target_arch') { } else if (arg.substring(0, 13) === '--target_arch') {
options.arch = arg.substring(14); options.arch = arg.substring(14);
} else if (arg === '--debug') { } else if (arg === '-d' || arg === '--debug') {
options.debug = true; options.debug = true;
} }
...@@ -110,18 +110,16 @@ function parseArgs(args) { ...@@ -110,18 +110,16 @@ function parseArgs(args) {
*/ */
function testBinary(options) { function testBinary(options) {
options.bin = utils.getBinaryIdentifiableName();
if (options.force || process.env.SASS_FORCE_BUILD) { if (options.force || process.env.SASS_FORCE_BUILD) {
return build(options); return build(options);
} }
fs.stat(path.join(__dirname, '..', 'vendor', options.bin, 'binding.node'), function (err) { fs.stat(path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node'), function (err) {
if (err) { if (err) {
return build(options); return build(options);
} }
console.log('`' + options.bin + '` exists; testing'); console.log('`' + process.sassBinaryName + '` exists; testing');
var mocha = new Mocha({ var mocha = new Mocha({
ui: 'bdd', ui: 'bdd',
......
...@@ -2,8 +2,9 @@ var fs = require('fs'), ...@@ -2,8 +2,9 @@ var fs = require('fs'),
path = require('path'), path = require('path'),
request = require('request'), request = require('request'),
mkdirp = require('mkdirp'), mkdirp = require('mkdirp'),
exec = require('shelljs').exec, exec = require('shelljs').exec;
utils = require('../lib/utils');
require('../lib/extensions');
/** /**
* Download file, if succeeds save, if not delete * Download file, if succeeds save, if not delete
...@@ -77,31 +78,28 @@ function applyProxy(options, cb) { ...@@ -77,31 +78,28 @@ function applyProxy(options, cb) {
*/ */
function exists() { function exists() {
var name = utils.getBinaryIdentifiableName(); fs.exists(path.join(__dirname, '..', 'vendor', process.sassBinaryName), function (exists) {
fs.exists(path.join(__dirname, '..', 'vendor', name), function (exists) {
if (exists) { if (exists) {
return; return;
} }
fetch(name); fetch();
}); });
} }
/** /**
* Fetch binaries * Fetch binaries
* *
* @param {String} name
* @api private * @api private
*/ */
function fetch(name) { function fetch() {
var url = [ var url = [
'https://raw.githubusercontent.com/sass/node-sass-binaries/v', 'https://raw.githubusercontent.com/sass/node-sass-binaries/v',
require('../package.json').version, '/', name, require('../package.json').version, '/', process.sassBinaryName,
'/binding.node' '/binding.node'
].join(''); ].join('');
var dir = path.join(__dirname, '..', 'vendor', name); var dir = path.join(__dirname, '..', 'vendor', process.sassBinaryName);
var dest = path.join(dir, 'binding.node'); var dest = path.join(dir, 'binding.node');
mkdirp(dir, function(err) { mkdirp(dir, function(err) {
......
...@@ -194,7 +194,7 @@ void GetSourceMap(sass_context_wrapper* ctx_w, Sass_Context* ctx) { ...@@ -194,7 +194,7 @@ void GetSourceMap(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
source_map = NanNew<String>("{}"); source_map = NanNew<String>("{}");
} }
NanNew(ctx_w->result)->Set(NanNew("sourceMap"), source_map); NanNew(ctx_w->result)->Set(NanNew("map"), source_map);
} }
int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx) { int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
......
...@@ -20,6 +20,45 @@ describe('api', function() { ...@@ -20,6 +20,45 @@ describe('api', function() {
}); });
}); });
it('should compile sass to css with outFile set to absolute url', function(done) {
sass.render({
file: fixture('simple/index.scss'),
sourceMap: true,
outFile: fixture('simple/index-test.css'),
success: function(result) {
assert.equal(JSON.parse(result.map).file, 'index-test.css');
done();
}
});
});
it('should compile sass to css with outFile set to relative url', function(done) {
sass.render({
file: fixture('simple/index.scss'),
sourceMap: true,
outFile: './index-test.css',
success: function(result) {
assert.equal(JSON.parse(result.map).file, 'index-test.css');
done();
}
});
});
it('should compile sass to css with outFile and sourceMap set to relative url', function(done) {
sass.render({
file: fixture('simple/index.scss'),
sourceMap: './deep/nested/index.map',
outFile: './index-test.css',
success: function(result) {
assert.equal(JSON.parse(result.map).file, '../../index-test.css');
done();
}
});
});
it('should compile sass to css with data', function(done) { it('should compile sass to css with data', function(done) {
var src = read(fixture('simple/index.scss'), 'utf8'); var src = read(fixture('simple/index.scss'), 'utf8');
var expected = read(fixture('simple/expected.css'), 'utf8').trim(); var expected = read(fixture('simple/expected.css'), 'utf8').trim();
...@@ -331,6 +370,39 @@ describe('api', function() { ...@@ -331,6 +370,39 @@ describe('api', function() {
done(); done();
}); });
it('should compile sass to css with outFile set to absolute url', function(done) {
var result = sass.renderSync({
file: fixture('simple/index.scss'),
sourceMap: true,
outFile: fixture('simple/index-test.css')
});
assert.equal(JSON.parse(result.map).file, 'index-test.css');
done();
});
it('should compile sass to css with outFile set to relative url', function(done) {
var result = sass.renderSync({
file: fixture('simple/index.scss'),
sourceMap: true,
outFile: './index-test.css'
});
assert.equal(JSON.parse(result.map).file, 'index-test.css');
done();
});
it('should compile sass to css with outFile and sourceMap set to relative url', function(done) {
var result = sass.renderSync({
file: fixture('simple/index.scss'),
sourceMap: './deep/nested/index.map',
outFile: './index-test.css'
});
assert.equal(JSON.parse(result.map).file, '../../index-test.css');
done();
});
it('should compile sass to css with data', function(done) { it('should compile sass to css with data', function(done) {
var src = read(fixture('simple/index.scss'), 'utf8'); var src = read(fixture('simple/index.scss'), 'utf8');
var expected = read(fixture('simple/expected.css'), 'utf8').trim(); var expected = read(fixture('simple/expected.css'), 'utf8').trim();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment