postcss-mixins
Advanced tools
Comparing version 8.1.0 to 9.0.0
52
index.js
let { join, basename, extname, relative } = require('path') | ||
let { promisify } = require('util') | ||
let { readFileSync } = require('fs') | ||
let { platform } = require('os') | ||
let { parse } = require('postcss-js') | ||
let sugarss = require('sugarss') | ||
let globby = require('globby') | ||
let vars = require('postcss-simple-vars') | ||
let fs = require('fs') | ||
let glob = require('fast-glob') | ||
let readFile = promisify(fs.readFile) | ||
let MIXINS_GLOB = '*.{js,json,css,sss,pcss}' | ||
@@ -39,27 +36,25 @@ let IS_WIN = platform().includes('win32') | ||
async function loadGlobalMixin(helpers, globs) { | ||
function loadGlobalMixin(helpers, globs) { | ||
let cwd = process.cwd() | ||
let files = await globby(globs, { caseSensitiveMatch: IS_WIN }) | ||
let files = glob.sync(globs, { caseSensitiveMatch: IS_WIN }) | ||
let mixins = {} | ||
await Promise.all( | ||
files.map(async i => { | ||
let ext = extname(i).toLowerCase() | ||
let name = basename(i, extname(i)) | ||
let path = join(cwd, relative(cwd, i)) | ||
if (ext === '.css' || ext === '.pcss' || ext === '.sss') { | ||
let content = await readFile(path) | ||
let root | ||
if (ext === '.sss') { | ||
root = sugarss.parse(content, { from: path }) | ||
} else { | ||
root = helpers.parse(content, { from: path }) | ||
} | ||
root.walkAtRules('define-mixin', atrule => { | ||
addMixin(helpers, mixins, atrule, path) | ||
}) | ||
files.forEach(i => { | ||
let ext = extname(i).toLowerCase() | ||
let name = basename(i, extname(i)) | ||
let path = join(cwd, relative(cwd, i)) | ||
if (ext === '.css' || ext === '.pcss' || ext === '.sss') { | ||
let content = readFileSync(path) | ||
let root | ||
if (ext === '.sss') { | ||
root = sugarss.parse(content, { from: path }) | ||
} else { | ||
mixins[name] = { mixin: require(path), file: path } | ||
root = helpers.parse(content, { from: path }) | ||
} | ||
}) | ||
) | ||
root.walkAtRules('define-mixin', atrule => { | ||
addMixin(helpers, mixins, atrule, path) | ||
}) | ||
} else { | ||
mixins[name] = { mixin: require(path), file: path } | ||
} | ||
}) | ||
return mixins | ||
@@ -200,5 +195,6 @@ } | ||
if (loadFrom.length > 0) { | ||
return loadGlobalMixin(helpers, loadFrom).then(global => { | ||
try { | ||
let global = loadGlobalMixin(helpers, loadFrom) | ||
addGlobalMixins(helpers, mixins, global, opts.parent) | ||
}) | ||
} catch {} | ||
} | ||
@@ -205,0 +201,0 @@ }, |
{ | ||
"name": "postcss-mixins", | ||
"version": "8.1.0", | ||
"version": "9.0.0", | ||
"description": "PostCSS plugin for mixins", | ||
@@ -26,7 +26,7 @@ "keywords": [ | ||
"dependencies": { | ||
"globby": "^11.0.3", | ||
"fast-glob": "^3.2.7", | ||
"postcss-js": "^3.0.3", | ||
"postcss-simple-vars": "^6.0.3", | ||
"sugarss": "^3.0.3" | ||
"sugarss": "^4.0.1" | ||
} | ||
} |
@@ -171,3 +171,3 @@ # PostCSS Mixins | ||
mixins: { | ||
image: function (mixin, path) { | ||
image: function (mixin, path, dpi) { | ||
return { | ||
@@ -177,3 +177,3 @@ '&': { | ||
}, | ||
'@media (min-resolution: 120dpi)': { | ||
['@media (min-resolution: '+ dpi +'dpi)']: { | ||
'&': { | ||
@@ -180,0 +180,0 @@ background: 'url(' + path + '@2x)' |
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
14536
196
+ Addedfast-glob@^3.2.7
+ Addedsugarss@4.0.1(transitive)
- Removedglobby@^11.0.3
- Removedarray-union@2.1.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedglobby@11.1.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedslash@3.0.0(transitive)
- Removedsugarss@3.0.3(transitive)
Updatedsugarss@^4.0.1