svelte-preprocess
Advanced tools
Comparing version 2.0.2 to 2.0.3
{ | ||
"name": "svelte-preprocess", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -36,3 +36,3 @@ # Svelte Preprocess | ||
/** Transform the whole markup before preprocessing */ | ||
onBefore(content, filename) { | ||
onBefore({ content, filename }) { | ||
return content.replace('something', 'someotherthing') | ||
@@ -57,3 +57,3 @@ }, | ||
/** Use a custom preprocess method by passing a function. */ | ||
pug(content, filename) { | ||
pug({ content, filename }) { | ||
const code = pug.render(content) | ||
@@ -65,3 +65,3 @@ | ||
/** Add a custom language preprocessor */ | ||
customLanguage(content, filename) { | ||
customLanguage({ content, filename }) { | ||
const { code, map } = require('custom-language-compiler')(content) | ||
@@ -68,0 +68,0 @@ return { code, map } |
@@ -13,3 +13,3 @@ type SveltePreprocessObject = { | ||
type SveltePreprocessOptions = { | ||
onBefore?(content: string, filename: string): string; | ||
onBefore?({ content, filename } = { content: string, filename: string }): string; | ||
transformers?: { | ||
@@ -16,0 +16,0 @@ [languageName: string]: boolean | object | (({ content, filename }: { content: string, filename?: string }) => |
@@ -50,8 +50,6 @@ const stripIndent = require('strip-indent') | ||
return runTransformer( | ||
lang, | ||
transformers[lang], | ||
stripIndent(content), | ||
return runTransformer(lang, transformers[lang], { | ||
content: stripIndent(content), | ||
filename, | ||
) | ||
}) | ||
} | ||
@@ -61,3 +59,3 @@ | ||
if (isFn(onBefore)) { | ||
content = onBefore(content, filename) | ||
content = onBefore({ content, filename }) | ||
} | ||
@@ -90,8 +88,6 @@ | ||
const preProcessedContent = runTransformer( | ||
lang, | ||
transformers[lang], | ||
stripIndent(templateCode), | ||
const preProcessedContent = runTransformer(lang, transformers[lang], { | ||
content: stripIndent(templateCode), | ||
filename, | ||
) | ||
}) | ||
@@ -111,9 +107,8 @@ return Promise.resolve(preProcessedContent).then(({ code }) => { | ||
if (transformers.postcss) { | ||
return Promise.resolve(transformedCSS).then(({ code }) => { | ||
return runTransformer( | ||
'postcss', | ||
transformers.postcss, | ||
code, | ||
assetInfo.filename, | ||
) | ||
return Promise.resolve(transformedCSS).then(({ code, map }) => { | ||
return runTransformer('postcss', transformers.postcss, { | ||
content: code, | ||
filename: assetInfo.filename, | ||
map, | ||
}) | ||
}) | ||
@@ -120,0 +115,0 @@ } |
const coffeescript = require('coffeescript') | ||
module.exports = function(content, filename, opts) { | ||
module.exports = function({ content, filename, opts }) { | ||
const { js: code, sourceMap: map } = coffeescript.compile(content, { | ||
@@ -5,0 +5,0 @@ filename, |
const less = require('less/lib/less-node') | ||
module.exports = function(content, filename, opts) { | ||
module.exports = function({ content, filename, opts }) { | ||
return less | ||
@@ -5,0 +5,0 @@ .render(content, { |
const postcss = require('postcss') | ||
module.exports = (content, filename, opts = { plugins: [] }) => { | ||
return postcss(opts.plugins) | ||
.process(content, { from: filename }) | ||
module.exports = ({ | ||
content, | ||
filename, | ||
options: { plugins = [] }, | ||
map = false, | ||
}) => { | ||
return postcss(plugins) | ||
.process(content, { | ||
from: filename, | ||
prev: map, | ||
}) | ||
.then(({ css, map }) => ({ | ||
@@ -7,0 +15,0 @@ code: css, |
const pug = require('pug') | ||
module.exports = function(content, filename, opts) { | ||
const code = pug.render(content, opts) | ||
module.exports = function({ content, filename, options }) { | ||
const code = pug.render(content, options) | ||
return { code } | ||
} |
@@ -5,9 +5,9 @@ const sass = require('node-sass') | ||
module.exports = function( | ||
module.exports = function({ | ||
content, | ||
filename, | ||
opts = { | ||
options = { | ||
includePaths: getIncludePaths(filename), | ||
}, | ||
) { | ||
}) { | ||
return new Promise((resolve, reject) => { | ||
@@ -19,3 +19,3 @@ sass.render( | ||
outFile: filename + '.css', | ||
...opts, | ||
...options, | ||
}, | ||
@@ -22,0 +22,0 @@ (err, result) => { |
@@ -5,9 +5,9 @@ const stylus = require('stylus') | ||
module.exports = function( | ||
module.exports = function({ | ||
content, | ||
filename, | ||
opts = { | ||
options = { | ||
paths: getIncludePaths(filename), | ||
}, | ||
) { | ||
}) { | ||
return new Promise((resolve, reject) => { | ||
@@ -17,3 +17,3 @@ const style = stylus(content, { | ||
sourcemap: true, | ||
...opts, | ||
...options, | ||
}) | ||
@@ -20,0 +20,0 @@ |
@@ -62,5 +62,5 @@ const { readFileSync } = require('fs') | ||
exports.runTransformer = (name, maybeFn, content, filename) => { | ||
exports.runTransformer = (name, maybeFn, { content, filename }) => { | ||
if (exports.isFn(maybeFn)) { | ||
return maybeFn(content, filename) | ||
return maybeFn({ content, filename }) | ||
} | ||
@@ -73,6 +73,6 @@ | ||
const transformOpts = | ||
const options = | ||
maybeFn && maybeFn.constructor === Object ? maybeFn : undefined | ||
return transformers[name](content, filename, transformOpts) | ||
return transformers[name]({ content, filename, options }) | ||
} catch (e) { | ||
@@ -79,0 +79,0 @@ throw new Error( |
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
12485
280