postcss-atroot
Advanced tools
Comparing version 0.1.3 to 0.2.3
29
index.js
@@ -1,14 +0,19 @@ | ||
var postcss = require('postcss') | ||
module.exports = () => { | ||
return { | ||
postcssPlugin: 'postcss-atroot', | ||
AtRule: { | ||
'at-root': function (rule) { | ||
// Find first node from root to move child nodes after it | ||
let p = rule | ||
while (p && p.parent && p.parent.type !== 'root') { | ||
p = p.parent | ||
} | ||
module.exports = postcss.plugin('postcss-atroot', function (opts) { | ||
opts = opts || {} | ||
return function (root, opts) { | ||
root.walkAtRules('at-root', function (rule) { | ||
var p = rule | ||
// Find first node from root to move child nodes after it | ||
while (p && p.parent !== root) p = p.parent | ||
root.insertBefore(p, rule.nodes) | ||
rule.remove() | ||
}) | ||
rule.root().insertBefore(p, rule.nodes) | ||
rule.remove() | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
module.exports.postcss = true |
{ | ||
"name": "postcss-atroot", | ||
"version": "0.1.3", | ||
"version": "0.2.3", | ||
"description": "PostCSS plugin to place rules directly at the root", | ||
@@ -11,4 +11,4 @@ "main": "index.js", | ||
"scripts": { | ||
"start": "gulp", | ||
"test": "gulp" | ||
"pretest": "eslint index.js test", | ||
"test": "mocha test/*.js" | ||
}, | ||
@@ -25,12 +25,14 @@ "keywords": [ | ||
"license": "MIT", | ||
"dependencies": { | ||
"postcss": "^5.0.5" | ||
"engines": { | ||
"node": ">= 10" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.2.0", | ||
"gulp": "^3.9.0", | ||
"gulp-eslint": "^1.0.0", | ||
"gulp-mocha": "^2.1.3", | ||
"mocha": "^2.3.2" | ||
"chai": "^4.3.4", | ||
"eslint": "^7.26.0", | ||
"mocha": "^8.4.0", | ||
"postcss": "^8.2.15" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.2.15" | ||
} | ||
} |
@@ -5,3 +5,3 @@ var postcss = require('postcss') | ||
var test = function (input, output, opts) { | ||
function test (input, output, opts) { | ||
var result = postcss(atroot(opts)).process(input) | ||
@@ -14,13 +14,29 @@ expect(result.css).to.eql(output) | ||
describe('postcss-atroot', function () { | ||
it('places nodes before parent rule', function () { | ||
test('.test {@at-root {.root {color: black}}}', | ||
'.root {\n color: black\n}\n.test {}') | ||
test( | ||
'.test {@at-root {.root {color: black}}}', | ||
'.root {color: black}.test {}' | ||
) | ||
}) | ||
it('places nodes before parent rule, recursively', function () { | ||
test( | ||
'.test { .innertest { @at-root {.root {color: black}}}}', | ||
'.root {color: black}.test { .innertest {}}' | ||
) | ||
}) | ||
it('places nodes before parent rule, keeps nested media', function () { | ||
test( | ||
'.test { .innertest { @at-root { @media(print) {.root {color: black}}}}}', | ||
' @media(print) {.root {color: black}} .test { .innertest {}}' | ||
) | ||
}) | ||
it('saves nodes order', function () { | ||
test('.test {@at-root {color: white;color: black;color: green}}', | ||
'color: white;\ncolor: black;\ncolor: green;\n.test {}') | ||
test( | ||
'.test {@at-root {color: white;color: black;color: green}}', | ||
'color: white;color: black;color: green;\n.test {}' | ||
) | ||
}) | ||
}) |
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
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
4
52
9288
7
+ Addednanoid@3.3.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedsource-map-js@1.2.1(transitive)
- Removedpostcss@^5.0.5
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedpostcss@5.2.18(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.03.2.3(transitive)