node-sass-middleware
Advanced tools
Comparing version 0.11.0 to 1.0.0
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -8,3 +8,2 @@ var sass = require('node-sass'), | ||
dirname = require('path').dirname, | ||
mkdirp = require('mkdirp'), | ||
join = require('path').join; | ||
@@ -19,17 +18,21 @@ | ||
* | ||
* all supportend options from node-sass project plus following: | ||
* all supported options from node-sass project plus following: | ||
* | ||
* `src` Source directory used to find .scss files | ||
* `dest` Destination directory used to output .css files when undefined defaults to `src` | ||
* `root` A base path for both source and destination directories | ||
* `prefix` It will tell the sass compiler that any request file will always be prefixed | ||
* with <prefix> and this prefix should be ignored. | ||
* `force` Always re-compile | ||
* `debug` Output debugging information | ||
* `response` True (default) to write output directly to response instead of to a file | ||
* `error` A function to be called when something goes wrong | ||
* `maxAge` MaxAge to be passed in Cache-Control header | ||
* `log` function(severity, key, val), used to log data instead of the default `console.error` | ||
* `src` - (String) Source directory used to find `.scss` or `.sass` files. | ||
* | ||
* optional configurations: | ||
* | ||
* `beepOnError` - Enable beep on error, false by default. | ||
* `debug` - `[true | false]`, false by default. Output debugging information. | ||
* `dest` - (String) Destination directory used to output `.css` files (when undefined defaults to `src`). | ||
* `error` - A function to be called when something goes wrong. | ||
* `force` - `[true | false]`, false by default. Always re-compile. | ||
* `indentedSyntax` - `[true | false]`, false by default. Compiles files with the `.sass` extension instead of `.scss` in the `src` directory. | ||
* `log` - `function(severity, key, val)`, used to log data instead of the default `console.error` | ||
* `maxAge` - MaxAge to be passed in Cache-Control header. | ||
* `prefix` - (String) It will tell the sass middleware that any request file will always be prefixed with `<prefix>` and this prefix should be ignored. | ||
* `response` - `[true | false]`, true by default. To write output directly to response instead of to a file. | ||
* `root` - (String) A base path for both source and destination directories. | ||
* | ||
* | ||
* Examples: | ||
@@ -62,3 +65,3 @@ * | ||
// Accept single src/dest dir | ||
if (typeof options == 'string') { | ||
if (typeof options === 'string') { | ||
options = { src: options }; | ||
@@ -68,5 +71,5 @@ } | ||
// Source directory (required) | ||
var src = options.src || function() { | ||
var src = options.src || (function() { | ||
throw new Error('sass.middleware() requires "src" directory.'); | ||
}(); | ||
}()); | ||
// Destination directory (source by default) | ||
@@ -81,2 +84,4 @@ var dest = options.dest || src; | ||
var debug = options.debug; | ||
// Enable beep on error | ||
var beep = options.beepOnError || false; | ||
@@ -97,6 +102,6 @@ var sassExtension = (options.indentedSyntax === true) ? '.sass' : '.scss'; | ||
if (typeof (console[severity]) === 'function') { | ||
console[severity]('[sass] \x1B[90m%s:\x1B[0m \x1B[36m%s %s\x1B[0m', key, val, text); | ||
if (severity === 'error') { | ||
console.error('[sass] \x1B[90m%s:\x1B[0m \x1B[36m%s %s\x1B[0m', key, val, text); | ||
} else { | ||
console.error('[sass] \x1B[90m%s:\x1B[0m \x1B[36m%s %s\x1B[0m', key, val, text); | ||
console.log('[sass] \x1B[90m%s:\x1B[0m \x1B[36m%s %s\x1B[0m', key, val, text); | ||
} | ||
@@ -125,3 +130,3 @@ }; | ||
if (req.method != 'GET' && req.method != 'HEAD') { | ||
if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
return next(); | ||
@@ -138,3 +143,3 @@ } | ||
if (options.prefix) { | ||
if (0 === path.indexOf(options.prefix)) { | ||
if (path.indexOf(options.prefix) === 0) { | ||
path = path.substring(options.prefix.length); | ||
@@ -154,4 +159,4 @@ } else { | ||
sassPath = join(root, src, path | ||
.replace(new RegExp('^' + dest), '') | ||
.replace(/\.css$/, sassExtension)); | ||
.replace(new RegExp('^' + dest), '') | ||
.replace(/\.css$/, sassExtension)); | ||
sassDir = dirname(sassPath); | ||
@@ -167,3 +172,3 @@ } | ||
var file = sassPath; | ||
if (err.file && err.file != 'stdin') { | ||
if (err.file && err.file !== 'stdin') { | ||
file = err.file; | ||
@@ -173,3 +178,3 @@ } | ||
var fileLineColumn = file + ':' + err.line + ':' + err.column; | ||
var errorMessage = '\x07\x1B[31m' + err.message.replace(/^ +/, '') + '\n\nin ' + fileLineColumn + '\x1B[91m'; | ||
var errorMessage = (beep ? '\x07' : '') + '\x1B[31m' + err.message.replace(/^ +/, '') + '\n\nin ' + fileLineColumn + '\x1B[91m'; | ||
@@ -216,3 +221,3 @@ error(err, errorMessage); | ||
mkdirp(dirname(cssPath), '0700', function(err) { | ||
fs.mkdir(dirname(cssPath), { mode: '0700', recursive: true}, function(err) { | ||
if (err) { | ||
@@ -238,3 +243,3 @@ error(err); | ||
var sourceMapPath = this.options.sourceMap; | ||
mkdirp(dirname(sourceMapPath), '0700', function(err) { | ||
fs.mkdir(dirname(sourceMapPath), { mode: '0700', recursive: true}, function(err) { | ||
if (err) { | ||
@@ -258,3 +263,3 @@ error(err); | ||
} | ||
} | ||
}; | ||
@@ -305,3 +310,3 @@ // Compile to cssPath | ||
if (err) { | ||
if ('ENOENT' === err.code) { // CSS has not been compiled, compile it! | ||
if (err.code === 'ENOENT') { // CSS has not been compiled, compile it! | ||
log('debug', 'compile', cssPath, 'was not found'); | ||
@@ -331,3 +336,3 @@ return compile(); | ||
}); | ||
} | ||
}; | ||
}; | ||
@@ -334,0 +339,0 @@ |
@@ -5,5 +5,6 @@ { | ||
"description": "Connect middleware for node-sass", | ||
"version": "0.11.0", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
"lint": "eslint .", | ||
"test": "mocha" | ||
}, | ||
@@ -31,15 +32,15 @@ "homepage": "https://github.com/sass/node-sass-middleware", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=12.0.0" | ||
}, | ||
"dependencies": { | ||
"mkdirp": "^0.5.1", | ||
"node-sass": "^4.3.0" | ||
"node-sass": "^7.0.1" | ||
}, | ||
"devDependencies": { | ||
"connect": "^3.5.0", | ||
"express": "^4.14.0", | ||
"mocha": "^3.2.0", | ||
"should": "^11.1.2", | ||
"supertest": "^2.0.1" | ||
"connect": "^3.7.0", | ||
"eslint": "^7.32.0", | ||
"express": "^4.17.1", | ||
"mocha": "^7.2.0", | ||
"should": "^13.2.3", | ||
"supertest": "^6.1.6" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
#node-sass-middleware | ||
# node-sass-middleware | ||
@@ -22,5 +22,5 @@ Connect/Express middleware for [node-sass](https://github.com/sass/node-sass). | ||
```javascript | ||
var connect = require('connect') | ||
var sassMiddleware = require('node-sass-middleware') | ||
var server = connect.createServer( | ||
const connect = require('connect') | ||
const sassMiddleware = require('node-sass-middleware') | ||
const server = connect.createServer( | ||
sassMiddleware({ | ||
@@ -45,6 +45,6 @@ /* Options */ | ||
```javascript | ||
var express = require('express'); | ||
var sassMiddleware = require('node-sass-middleware'); | ||
var path = require('path'); | ||
var app = express(); | ||
const express = require('express'); | ||
const sassMiddleware = require('node-sass-middleware'); | ||
const path = require('path'); | ||
const app = express(); | ||
app.use(sassMiddleware({ | ||
@@ -66,10 +66,10 @@ /* Options */ | ||
```javascript | ||
var connect = require('connect'); | ||
var sassMiddleware = require('node-sass-middleware'); | ||
var postcssMiddleware = require('postcss-middleware'); | ||
var autoprefixer = require('autoprefixer'); | ||
var path = require('path'); | ||
var http = require('http'); | ||
var app = connect(); | ||
var destPath = __dirname + '/public'; | ||
const connect = require('connect'); | ||
const sassMiddleware = require('node-sass-middleware'); | ||
const postcssMiddleware = require('postcss-middleware'); | ||
const autoprefixer = require('autoprefixer'); | ||
const path = require('path'); | ||
const http = require('http'); | ||
const app = connect(); | ||
const destPath = __dirname + '/public'; | ||
app.use(sassMiddleware({ | ||
@@ -100,25 +100,28 @@ /* Options */ | ||
* `src` - (String) Source directory used to find `.scss` or `.sass` files. | ||
* optional configurations: | ||
* `dest` - (String) Destination directory used to output `.css` files (when undefined defaults to `src`). | ||
* `root` - (String) A base path for both source and destination directories. | ||
* `prefix` - (String) It will tell the sass middleware that any request file will always be prefixed with `<prefix>` and this prefix should be ignored. | ||
* `force` - `[true | false]`, false by default. Always re-compile. | ||
* `debug` - `[true | false]`, false by default. Output debugging information. | ||
* `indentedSyntax` - `[true | false]`, false by default. Compiles files with the `.sass` extension instead of `.scss` in the `src` directory. | ||
* `response` - `[true | false]`, true by default. To write output directly to response instead of to a file. | ||
* `error` - A function to be called when something goes wrong. | ||
* `maxAge` - MaxAge to be passed in Cache-Control header. | ||
* `log` - `function(severity, key, val)`, used to log data instead of the default `console.error` | ||
#### Optional configurations: | ||
* `beepOnError` - Enable beep on error, false by default. | ||
* `debug` - `[true | false]`, false by default. Output debugging information. | ||
* `dest` - (String) Destination directory used to output `.css` files (when undefined defaults to `src`). | ||
* `error` - A function to be called when something goes wrong. | ||
* `force` - `[true | false]`, false by default. Always re-compile. | ||
* `indentedSyntax` - `[true | false]`, false by default. If true compiles files with the `.sass` extension instead of `.scss` in the `src` directory. | ||
* `log` - `function(severity, key, val, message)`, used to log data instead of the default `console.error`. "severity" matches [Winston](https://www.npmjs.com/package/winston) severity levels. | ||
* `maxAge` - MaxAge to be passed in Cache-Control header. | ||
* `prefix` - (String) It will tell the sass middleware that any request file will always be prefixed with `<prefix>` and this prefix should be ignored. | ||
* `response` - `[true | false]`, true by default. To write output directly to response instead of to a file. | ||
* `root` - (String) A base path for both source and destination directories. | ||
For full list of options from original node-sass project go [here](https://github.com/sass/node-sass). | ||
### Express example with custom log function | ||
```javascript | ||
var express = require('express'); | ||
var sassMiddleware = require('node-sass-middleware'); | ||
var path = require('path'); | ||
var winston = require('winston'); | ||
var app = express(); | ||
const express = require('express'); | ||
const sassMiddleware = require('node-sass-middleware'); | ||
const path = require('path'); | ||
const winston = require('winston'); | ||
const app = express(); | ||
winston.level = 'debug'; | ||
@@ -130,3 +133,3 @@ app.use(sassMiddleware({ | ||
debug: true, | ||
log: function (severity, key, value) { winston.log(severity, 'node-saas-middleware %s : %s', key, value); } | ||
log: function (severity, key, value) { winston.log(severity, 'node-sass-middleware %s : %s', key, value); } | ||
})); | ||
@@ -133,0 +136,0 @@ // Note: you must place sass-middleware *before* `express.static` or else it will |
@@ -0,6 +1,6 @@ | ||
/*global describe it*/ | ||
'use strict'; | ||
var fs = require('fs'), | ||
path = require('path'), | ||
should = require('should'), | ||
sass = require('node-sass'), | ||
request = require('supertest'), | ||
@@ -10,9 +10,5 @@ connect = require('connect'), | ||
fixture = path.join.bind(null, __dirname, 'fixtures'), | ||
test_cssFile = fixture('test.css'), | ||
test_sassFile = fixture('test.sass'), | ||
test_scssFile = fixture('test.scss'), | ||
index_cssFile = fixture('index.css'), | ||
index_sassFile = fixture('index.sass'), | ||
index_scssFile = fixture('index.scss'), | ||
index_sourceMap = fixture('index.css.map'), | ||
testCssFile = fixture('test.css'), | ||
indexCssFile = fixture('index.css'), | ||
indexScssFile = fixture('index.scss'), | ||
spawn = require('child_process').spawn, | ||
@@ -22,3 +18,2 @@ http = require('http'); | ||
describe('Creating middleware', function() { | ||
it('throws an error when omitting src', function() { | ||
@@ -35,3 +30,2 @@ middleware.should.throw(/requires "src"/); | ||
}); | ||
}); | ||
@@ -41,6 +35,6 @@ | ||
describe('Spawning example server', function() { | ||
describe('Spawning test server', function() { | ||
it('starts the server', function(done) { | ||
var serverStartupTimeout = 950; | ||
spawnedServer = spawn('node', [fixture('example-server.js')]); | ||
spawnedServer = spawn('node', [fixture('test-server.js')]); | ||
@@ -61,8 +55,8 @@ // exclude serverStartupTimeout from timeout and slow counters of test runs | ||
it('should use the default logger when none provided', function(done) { | ||
var expected = '[sass] \u001b[90msource:\u001b[0m \u001b[36m' + index_scssFile + ' \u001b[0m'; | ||
var expected = '[sass] \u001b[90msource:\u001b[0m \u001b[36m' + indexScssFile + ' \u001b[0m'; | ||
http.request({ method: 'GET', host: 'localhost', port: process.env.PORT || '8000', path: '/index.css' }) | ||
.end(); | ||
.end(); | ||
spawnedServer.stderr.once('data', function(data) { | ||
spawnedServer.stdout.once('data', function(data) { | ||
data.toString().should.startWith(expected); | ||
@@ -89,3 +83,3 @@ done(); | ||
.expect(200, function() { | ||
fs.unlink(index_cssFile); | ||
fs.unlinkSync(indexCssFile); | ||
loggerArguments[0].should.equal('debug'); | ||
@@ -150,474 +144,28 @@ done(); | ||
}); | ||
it('should produce beep ', function(done) { | ||
this.timeout(this.timeout() + 55500); | ||
// setup | ||
var testScssFile = fixture('test2.scss'); | ||
var content = fs.readFileSync(fixture('test.scss')) + '\nbody { background;: red; }'; | ||
fs.writeFileSync(testScssFile, content, { flag: 'w' }); | ||
function setupBeforeEach() { | ||
beforeEach(function(done) { | ||
fs.exists(test_cssFile, function(exists) { | ||
if (exists) { | ||
fs.unlink(test_cssFile); | ||
} | ||
}); | ||
var expectedKey = '\x07\x1B'; | ||
fs.exists(index_cssFile, function(exists) { | ||
if (exists) { | ||
fs.unlink(index_cssFile); | ||
} | ||
}); | ||
http.request({ method: 'GET', host: 'localhost', port: process.env.PORT || '8000', path: '/test2.css' }) | ||
.end(); | ||
fs.exists(index_sourceMap, function(exists) { | ||
if (exists) { | ||
fs.unlink(index_sourceMap); | ||
spawnedServer.stderr.on('data', function(data) { | ||
// skip until we get the error | ||
if (data.indexOf('[sass] \x1B[90merror:') !== 0) { | ||
return; | ||
} | ||
}); | ||
done(); | ||
}); | ||
} | ||
data.toString().should.containEql(expectedKey); | ||
describe('Using middleware to compile .scss', function() { | ||
var server = connect() | ||
.use(middleware({ | ||
src: fixture(), | ||
dest: fixture() | ||
})) | ||
.use(function(err, req, res, next) { | ||
res.statusCode = 500; | ||
res.end(err.message); | ||
fs.unlinkSync(testScssFile); | ||
done(); | ||
}); | ||
setupBeforeEach(); | ||
describe('successful file request', function() { | ||
it('serves a file with 200 Content-Type css', function(done) { | ||
request(server) | ||
.get('/test.css') | ||
.set('Accept', 'text/css') | ||
.expect('Content-Type', /css/) | ||
.expect(200, done); | ||
}); | ||
it('serves the compiled contents of the relative scss file', function(done) { | ||
var filesrc = fs.readFileSync(test_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }); | ||
request(server) | ||
.get('/test.css') | ||
.expect(result.css.toString()) | ||
.expect(200, done); | ||
}); | ||
it('writes the compiled contents out to the expected file', function(done) { | ||
var filesrc = fs.readFileSync(test_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }); | ||
request(server) | ||
.get('/test.css') | ||
.expect(result.css.toString()) | ||
.expect(200, function(err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
if (fs.existsSync(test_cssFile)) { | ||
fs.readFileSync(test_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} else { | ||
done(new Error('file was not written before request ends')); | ||
} | ||
} | ||
}); | ||
}); | ||
it('only writes the compiled contents out to the expected file without serving them', function(done) { | ||
var filesrc = fs.readFileSync(test_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }), | ||
anotherResponse = 'something else', | ||
server = connect() | ||
.use(middleware({ | ||
response: false, | ||
src: fixture(), | ||
dest: fixture() | ||
})); | ||
server.use(function(req, res) { | ||
res.end(anotherResponse); | ||
}); | ||
request(server) | ||
.get('/test.css') | ||
.expect(anotherResponse) | ||
.expect(200, function(err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
fs.readFileSync(test_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
describe('unsucessful file request', function() { | ||
it('moves to next middleware', function(done) { | ||
request(server) | ||
.get('/does-not-exist.css') | ||
.expect('Cannot GET /does-not-exist.css\n') | ||
.expect(404, done); | ||
}); | ||
}); | ||
describe('compiling files with dependencies (source file contains includes)', function() { | ||
it('serves the compiled contents of the relative scss file', function(done) { | ||
var filesrc = fs.readFileSync(index_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }); | ||
request(server) | ||
.get('/index.css') | ||
.expect(result.css.toString()) | ||
.expect(200, done); | ||
}); | ||
it('writes the compiled contents out to the expected file', function(done) { | ||
var filesrc = fs.readFileSync(index_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }); | ||
request(server) | ||
.get('/index.css') | ||
.expect(result.css.toString()) | ||
.expect(200, function(err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
(function checkFile() { | ||
if (fs.existsSync(index_cssFile)) { | ||
fs.readFileSync(index_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} else { | ||
setTimeout(checkFile, 25); | ||
} | ||
}()); | ||
} | ||
}); | ||
}); | ||
it('any change in a dependent file, force recompiling', function(done) { | ||
request(server) | ||
.get('/index.css') | ||
.expect(200, function() { | ||
(function checkInitialFile() { | ||
fs.stat(index_cssFile, function(err, initialDate) { | ||
if (initialDate != undefined) { | ||
fs.appendFile(test_scssFile, '\nbody { background: red; }', function(err, data) { | ||
if (err) throw err; | ||
var filesrc = fs.readFileSync(index_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }); | ||
request(server) | ||
.get('/index.css') | ||
.expect(200, function() { | ||
(function checkRecompiledFile() { | ||
var cont = fs.readFileSync(index_cssFile).toString(); | ||
if (cont === result.css.toString()) { | ||
done(); | ||
} else { | ||
setTimeout(checkRecompiledFile, 10); | ||
} | ||
}()); | ||
}); | ||
}); | ||
} else { | ||
setTimeout(checkInitialFile, 10); | ||
} | ||
}); | ||
}()); | ||
}); | ||
// clean | ||
after(function() { | ||
var reset = fs.readFileSync(test_scssFile).toString().replace('\nbody { background: red; }', ''); | ||
fs.writeFileSync(test_scssFile, reset, { flag: 'w' }); | ||
}); | ||
}); | ||
}); | ||
describe('generating source-map for compiled css', function() { | ||
var server = connect() | ||
.use(middleware({ | ||
src: fixture(), | ||
dest: fixture(), | ||
sourceMap: true | ||
})) | ||
.use(function(err, req, res, next) { | ||
res.statusCode = 500; | ||
res.end(err.message); | ||
}); | ||
it('generates source-map with correct contents', function(done) { | ||
request(server) | ||
.get('/index.css') | ||
.expect(200, function() { | ||
var filesrc = fs.readFileSync(index_scssFile), | ||
result = sass.renderSync({ file: index_scssFile, outFile: index_cssFile, sourceMap: true }); | ||
(function checkFile() { | ||
fs.exists(index_sourceMap, function(exists) { | ||
if (exists) { | ||
var cont = fs.readFileSync(index_sourceMap).toString(); | ||
if (cont === result.map.toString()) { | ||
done(); | ||
} | ||
} else { | ||
setTimeout(checkFile, 10); | ||
} | ||
}); | ||
}()); | ||
}); | ||
}); | ||
}); | ||
describe('compiling files with errors moves to next middleware with err', function() { | ||
// alter | ||
before(function() { | ||
fs.appendFileSync(test_scssFile, '\nbody { background;: red; }'); | ||
}); | ||
it('if error is in the main file', function(done) { | ||
request(server) | ||
.get('/test.css') | ||
.expect('property "background" must be followed by a \':\'') | ||
.expect(500, done); | ||
}); | ||
it('if error is in imported file', function(done) { | ||
request(server) | ||
.get('/index.css') | ||
.expect('property "background" must be followed by a \':\'') | ||
.expect(500, done); | ||
}); | ||
// clean | ||
after(function() { | ||
var reset = fs.readFileSync(test_scssFile).toString().replace('\nbody { background;: red; }', ''); | ||
fs.writeFileSync(test_scssFile, reset, { flag: 'w' }); | ||
}); | ||
}); | ||
}); | ||
describe('Using middleware to compile .sass', function() { | ||
var server = connect() | ||
.use(middleware({ | ||
src: fixture(), | ||
dest: fixture(), | ||
indentedSyntax: true | ||
})) | ||
.use(function(err, req, res, next) { | ||
res.statusCode = 500; | ||
res.end(err.message); | ||
}); | ||
setupBeforeEach(); | ||
describe('successful file request', function() { | ||
it('serves a file with 200 Content-Type css', function(done) { | ||
request(server) | ||
.get('/test.css') | ||
.set('Accept', 'text/css') | ||
.expect('Content-Type', /css/) | ||
.expect(200, done); | ||
}); | ||
it('serves the compiled contents of the relative sass file', function(done) { | ||
var filesrc = fs.readFileSync(test_sassFile), | ||
result = sass.renderSync({ data: filesrc.toString(), indentedSyntax: true }); | ||
request(server) | ||
.get('/test.css') | ||
.expect(result.css.toString()) | ||
.expect(200, done); | ||
}); | ||
it('writes the compiled contents out to the expected file', function(done) { | ||
var filesrc = fs.readFileSync(test_sassFile), | ||
result = sass.renderSync({ data: filesrc.toString(), indentedSyntax: true }); | ||
request(server) | ||
.get('/test.css') | ||
.expect(result.css.toString()) | ||
.expect(200, function(err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
(function checkFile() { | ||
if (fs.existsSync(test_cssFile)) { | ||
fs.readFileSync(test_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} else { | ||
setTimeout(checkFile, 25); | ||
} | ||
}()); | ||
} | ||
}); | ||
}); | ||
}); | ||
describe('unsucessful file request', function() { | ||
it('moves to next middleware', function(done) { | ||
request(server) | ||
.get('/does-not-exist.css') | ||
.expect('Cannot GET /does-not-exist.css\n') | ||
.expect(404, done); | ||
}); | ||
}); | ||
describe('compiling files with dependencies (source file contains includes)', function() { | ||
it('serves the compiled contents of the relative sass file', function(done) { | ||
var filesrc = fs.readFileSync(index_sassFile), | ||
result = sass.renderSync({ data: filesrc.toString(), indentedSyntax: true }); | ||
request(server) | ||
.get('/index.css') | ||
.expect(result.css.toString()) | ||
.expect(200, done); | ||
}); | ||
it('writes the compiled contents out to the expected file', function(done) { | ||
var filesrc = fs.readFileSync(index_sassFile), | ||
result = sass.renderSync({ data: filesrc.toString(), indentedSyntax: true }); | ||
request(server) | ||
.get('/index.css') | ||
.expect(result.css.toString()) | ||
.expect(200, function(err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
(function checkFile() { | ||
if (fs.existsSync(index_cssFile)) { | ||
fs.readFileSync(index_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} else { | ||
setTimeout(checkFile, 25); | ||
} | ||
}()); | ||
} | ||
}); | ||
}); | ||
it('any change in a dependent file, force recompiling', function(done) { | ||
request(server) | ||
.get('/index.css') | ||
.expect(200, function() { | ||
(function checkInitialFile() { | ||
fs.stat(index_cssFile, function(err, initialDate) { | ||
if (initialDate != undefined) { | ||
fs.appendFile(test_sassFile, '\nbody\n\tbackground: red', function(err, data) { | ||
if (err) throw err; | ||
var filesrc = fs.readFileSync(index_sassFile), | ||
result = sass.renderSync({ data: filesrc.toString(), indentedSyntax: true }); | ||
request(server) | ||
.get('/index.css') | ||
.expect(200, function() { | ||
(function checkRecompiledFile() { | ||
var cont = fs.readFileSync(index_cssFile).toString(); | ||
if (cont === result.css.toString()) { | ||
done(); | ||
} else { | ||
setTimeout(checkRecompiledFile, 10); | ||
} | ||
}()); | ||
}); | ||
}); | ||
} else { | ||
setTimeout(checkInitialFile, 10); | ||
} | ||
}); | ||
}()); | ||
}); | ||
// clean | ||
after(function() { | ||
var reset = fs.readFileSync(test_sassFile).toString().replace('\nbody\n\tbackground: red', ''); | ||
fs.writeFileSync(test_sassFile, reset, { flag: 'w' }); | ||
}); | ||
}); | ||
}); | ||
describe('generating source-map for compiled css', function() { | ||
var server = connect() | ||
.use(middleware({ | ||
src: fixture(), | ||
dest: fixture(), | ||
indentedSyntax: true, | ||
sourceMap: true | ||
})) | ||
.use(function(err, req, res, next) { | ||
res.statusCode = 500; | ||
res.end(err.message); | ||
}); | ||
it('generates source-map with correct contents', function(done) { | ||
request(server) | ||
.get('/index.css') | ||
.expect(200, function() { | ||
var filesrc = fs.readFileSync(index_scssFile), | ||
result = sass.renderSync({ file: index_sassFile, indentedSyntax: true, outFile: index_cssFile, sourceMap: true }); | ||
(function checkFile() { | ||
fs.exists(index_sourceMap, function(exists) { | ||
if (exists) { | ||
var cont = fs.readFileSync(index_sourceMap).toString(); | ||
if (cont === result.map.toString()) { | ||
return done(); | ||
} | ||
} | ||
setTimeout(checkFile, 10); | ||
}); | ||
}()); | ||
}); | ||
}); | ||
}); | ||
describe('compiling files with errors moves to next middleware with err', function() { | ||
// alter | ||
before(function() { | ||
fs.appendFileSync(test_sassFile, '\nbody\n\tbackground;: red'); | ||
}); | ||
it('if error is in the main file', function(done) { | ||
request(server) | ||
.get('/test.css') | ||
.expect('property "background" must be followed by a \':\'') | ||
.expect(500, done); | ||
}); | ||
it('if error is in imported file', function(done) { | ||
request(server) | ||
.get('/index.css') | ||
.expect('property "background" must be followed by a \':\'') | ||
.expect(500, done); | ||
}); | ||
// clean | ||
after(function() { | ||
var reset = fs.readFileSync(test_sassFile).toString().replace('\nbody\n\tbackground;: red', ''); | ||
fs.writeFileSync(test_sassFile, reset, { flag: 'w' }); | ||
}); | ||
}); | ||
}); | ||
describe('Checking for http headers', function() { | ||
@@ -631,3 +179,3 @@ var oneDay = 60 * 60 * 24; // one day | ||
})) | ||
.use(function(err, req, res, next) { | ||
.use(function(err, req, res) { | ||
res.statusCode = 500; | ||
@@ -639,19 +187,18 @@ res.end(err.message); | ||
request(server) | ||
.get('/test.css') | ||
.set('Accept', 'text/css') | ||
.expect('Cache-Control', 'max-age=' + oneDay) | ||
.expect(200, function() { | ||
// delete file | ||
fs.exists(test_cssFile, function(exists) { | ||
if (exists) { | ||
fs.unlink(test_cssFile); | ||
} | ||
.get('/test.css') | ||
.set('Accept', 'text/css') | ||
.expect('Cache-Control', 'max-age=' + oneDay) | ||
.expect(200, function() { | ||
// delete file | ||
fs.exists(testCssFile, function(exists) { | ||
if (exists) { | ||
fs.unlinkSync(testCssFile); | ||
} | ||
}); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('Killing example server', function() { | ||
describe('Killing test server', function() { | ||
it('stops the server', function(done) { | ||
@@ -658,0 +205,0 @@ spawnedServer.kill(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
46075
1
19
1023
0
161
6
10
4
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@gar/promisify@1.1.3(transitive)
+ Added@npmcli/fs@1.1.1(transitive)
+ Added@npmcli/move-file@1.1.2(transitive)
+ Added@tootallnate/once@1.1.2(transitive)
+ Added@types/minimist@1.2.5(transitive)
+ Added@types/normalize-package-data@2.4.4(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedagentkeepalive@4.5.0(transitive)
+ Addedaggregate-error@3.1.0(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.03.0.1(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedcacache@15.3.0(transitive)
+ Addedcamelcase-keys@6.2.2(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcross-spawn@7.0.5(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedenv-paths@2.2.1(transitive)
+ Addederr-code@2.0.3(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedgauge@3.0.24.0.4(transitive)
+ Addedhard-rejection@2.1.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedhttp-proxy-agent@4.0.1(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedhumanize-ms@1.2.1(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedinfer-owner@1.0.4(transitive)
+ Addedip-address@9.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-lambda@1.0.1(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsbn@1.1.0(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmake-fetch-happen@9.1.0(transitive)
+ Addedmap-obj@4.3.0(transitive)
+ Addedmeow@9.0.0(transitive)
+ Addedmin-indent@1.0.1(transitive)
+ Addedminimist-options@4.1.0(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminipass-collect@1.0.2(transitive)
+ Addedminipass-fetch@1.4.1(transitive)
+ Addedminipass-flush@1.0.5(transitive)
+ Addedminipass-pipeline@1.2.4(transitive)
+ Addedminipass-sized@1.0.3(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedms@2.1.3(transitive)
+ Addednegotiator@0.6.4(transitive)
+ Addednode-gyp@8.4.1(transitive)
+ Addednode-sass@7.0.3(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednormalize-package-data@3.0.3(transitive)
+ Addednpmlog@5.0.16.0.2(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-map@4.0.0(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpromise-inflight@1.0.1(transitive)
+ Addedpromise-retry@2.0.1(transitive)
+ Addedquick-lru@4.0.1(transitive)
+ Addedread-pkg@5.2.0(transitive)
+ Addedread-pkg-up@7.0.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedredent@3.0.0(transitive)
+ Addedretry@0.12.0(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsass-graph@4.0.1(transitive)
+ Addedscss-tokenizer@0.4.3(transitive)
+ Addedsemver@5.7.27.6.3(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsmart-buffer@4.2.0(transitive)
+ Addedsocks@2.8.3(transitive)
+ Addedsocks-proxy-agent@6.2.1(transitive)
+ Addedsource-map@0.7.4(transitive)
+ Addedsprintf-js@1.1.3(transitive)
+ Addedssri@8.0.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedstrip-indent@3.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtrim-newlines@3.0.1(transitive)
+ Addedtype-fest@0.18.10.6.00.8.1(transitive)
+ Addedunique-filename@1.1.1(transitive)
+ Addedunique-slug@2.0.2(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@20.2.921.1.1(transitive)
- Removedmkdirp@^0.5.1
- Removedamdefine@1.0.1(transitive)
- Removedansi-regex@2.1.14.1.1(transitive)
- Removedansi-styles@2.2.13.2.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedblock-stream@0.0.9(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcliui@5.0.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcross-spawn@3.0.1(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfind-up@1.1.23.0.0(transitive)
- Removedfstream@1.0.12(transitive)
- Removedgauge@2.7.4(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedin-publish@2.0.1(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-fullwidth-code-point@1.0.02.0.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednode-gyp@3.8.0(transitive)
- Removednode-sass@4.14.1(transitive)
- Removednopt@3.0.6(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.03.0.0(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsass-graph@2.2.5(transitive)
- Removedscss-tokenizer@0.2.3(transitive)
- Removedsemver@5.3.0(transitive)
- Removedsource-map@0.4.4(transitive)
- Removedstring-width@1.0.23.1.0(transitive)
- Removedstrip-ansi@3.0.15.2.0(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtar@2.2.2(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@5.1.0(transitive)
- Removedy18n@4.0.3(transitive)
- Removedyallist@2.1.2(transitive)
- Removedyargs@13.3.2(transitive)
- Removedyargs-parser@13.1.2(transitive)
Updatednode-sass@^7.0.1