gulp-dart-scss
Advanced tools
Comparing version 1.0.5 to 1.1.0
93
index.js
@@ -1,57 +0,66 @@ | ||
const through2 = require("through2"); | ||
const pluginError = require("plugin-error"); | ||
const PluginError = require("plugin-error"); | ||
const Transform = require("stream").Transform; | ||
const path = require("path"); | ||
const applySourceMap = require("vinyl-sourcemaps-apply"); | ||
const dartSass = require("sass"); | ||
const applySourceMap = require("vinyl-sourcemaps-apply"); | ||
const path = require("path"); | ||
const PLUGIN_NAME = "gulp-dart-scss"; | ||
module.exports = (options = {}) => { | ||
return through2.obj((file, encoding, callback) => { | ||
if (file.isNull()) { | ||
return callback(null, file); | ||
} | ||
return new Transform({ | ||
objectMode: true, | ||
transform(chunk, encoding, callback) { | ||
// Return chunk if not scss extension | ||
if (path.extname(chunk.path) !== ".scss") { | ||
return callback(null, chunk); | ||
} | ||
if (file.isStream()) { | ||
return callback( | ||
new pluginError("gulp-dart-scss", "Streaming not supported") | ||
); | ||
} | ||
// Ignore if empty or null | ||
if (chunk._contents.length === 0 || chunk.isNull()) { | ||
return callback(null); | ||
} | ||
// Ignore _name.scss files | ||
if (path.basename(file.path).indexOf("_") === 0) { | ||
return callback(); | ||
} | ||
// Ignore _name.scss files | ||
if (path.basename(chunk.path).indexOf("_") === 0) { | ||
return callback(null); | ||
} | ||
(async () => { | ||
try { | ||
options.sourceMap = file.sourceMap ? file.path : false; | ||
options.file = file.path || options.file; | ||
if (chunk.isBuffer()) { | ||
options.sourceMap = chunk.sourceMap ? chunk.path : false; | ||
options.file = chunk.path || options.file; | ||
const result = await dartSass.renderSync(options); | ||
file.contents = Buffer.from(result.css); | ||
// Replace .scss with .css | ||
file.path = path.join( | ||
path.dirname(file.path), | ||
path.basename(file.path, path.extname(file.path)) + ".css" | ||
// Rename extension | ||
chunk.path = path.join( | ||
path.dirname(chunk.path), | ||
path.basename(chunk.path, path.extname(chunk.path)) + ".css" | ||
); | ||
// Apply sourcemap if gulp-sourcemap is present | ||
if (result.map && file.sourceMap) { | ||
const map = JSON.parse(result.map); | ||
map.file = file.relative; | ||
map.sources = map.sources.map(source => | ||
path.relative(file.base, source) | ||
try { | ||
const renderResult = dartSass.renderSync(options); | ||
chunk._contents = Buffer.from(renderResult.css); | ||
if (renderResult.map && chunk.sourceMap) { | ||
const map = JSON.parse(renderResult.map); | ||
map.file = chunk.relative; | ||
map.sources = map.sources.map((source) => | ||
path.relative(chunk.base, source) | ||
); | ||
applySourceMap(chunk, map); | ||
} | ||
return callback(null, chunk); | ||
} catch (error) { | ||
return callback( | ||
new PluginError(PLUGIN_NAME, error.message, { | ||
fileName: chunk.relative, | ||
}) | ||
); | ||
applySourceMap(file, map); | ||
} | ||
setImmediate(callback, null, file); | ||
} catch (error) { | ||
process.stderr.write( | ||
`${new pluginError("gulp-dart-scss", error.message).toString()} \r\n` | ||
} else if (chunk.isStream()) { | ||
return callback( | ||
new PluginError(PLUGIN_NAME, "Streaming is not supported.") | ||
); | ||
return callback(); | ||
} | ||
})(); | ||
}, | ||
}); | ||
}; |
{ | ||
"name": "gulp-dart-scss", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Gulp plugin to compile Sass (.scss) to CSS using the Dart Sass compiler.", | ||
@@ -22,4 +22,3 @@ "author": "Kasper Hesthaven", | ||
"plugin-error": "^1.0.1", | ||
"vinyl-sourcemaps-apply": "^0.2.1", | ||
"through2": "4.0.2" | ||
"vinyl-sourcemaps-apply": "^0.2.1" | ||
}, | ||
@@ -26,0 +25,0 @@ "files": [ |
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
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
12817
3
57
- Removedthrough2@4.0.2
- Removedinherits@2.0.4(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedthrough2@4.0.2(transitive)
- Removedutil-deprecate@1.0.2(transitive)