You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

postcss-import

Package Overview
Dependencies
Maintainers
3
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-import - npm Package Compare versions

Comparing version

to
16.1.1

45

lib/apply-conditions.js

@@ -6,11 +6,37 @@ "use strict"

module.exports = function applyConditions(bundle, atRule) {
bundle.forEach(stmt => {
const firstImportStatementIndex = bundle.findIndex(
stmt => stmt.type === "import",
)
const lastImportStatementIndex = bundle.findLastIndex(
stmt => stmt.type === "import",
)
bundle.forEach((stmt, index) => {
if (stmt.type === "charset" || stmt.type === "warning") {
return
}
if (
stmt.type === "charset" ||
stmt.type === "warning" ||
!stmt.conditions?.length
stmt.type === "layer" &&
((index < lastImportStatementIndex && stmt.conditions?.length) ||
(index > firstImportStatementIndex && index < lastImportStatementIndex))
) {
stmt.type = "import"
stmt.node = stmt.node.clone({
name: "import",
params: base64EncodedConditionalImport(
`'data:text/css;base64,${Buffer.from(stmt.node.toString()).toString(
"base64",
)}'`,
stmt.conditions,
),
})
return
}
if (!stmt.conditions?.length) {
return
}
if (stmt.type === "import") {

@@ -24,4 +50,11 @@ stmt.node.params = base64EncodedConditionalImport(

const { nodes } = stmt
const { parent } = nodes[0]
let nodes
let parent
if (stmt.type === "layer") {
nodes = [stmt.node]
parent = stmt.node.parent
} else {
nodes = stmt.nodes
parent = nodes[0].parent
}

@@ -28,0 +61,0 @@ const atRules = []

2

lib/apply-styles.js

@@ -8,3 +8,3 @@ "use strict"

bundle.forEach(stmt => {
if (["charset", "import"].includes(stmt.type)) {
if (["charset", "import", "layer"].includes(stmt.type)) {
stmt.node.parent = undefined

@@ -11,0 +11,0 @@ styles.append(stmt.node)

@@ -11,2 +11,4 @@ "use strict"

module.exports = function base64EncodedConditionalImport(prelude, conditions) {
if (!conditions?.length) return prelude
conditions.reverse()

@@ -13,0 +15,0 @@ const first = conditions.pop()

@@ -12,2 +12,3 @@ "use strict"

let nodes = []
let encounteredNonImportNodes = false

@@ -21,2 +22,10 @@ styles.each(node => {

stmt = parseCharset(result, node, conditions, from)
else if (
node.name === "layer" &&
!encounteredNonImportNodes &&
!node.nodes
)
stmt = parseLayer(result, node, conditions, from)
} else if (node.type !== "comment") {
encounteredNonImportNodes = true
}

@@ -238,1 +247,10 @@

}
function parseLayer(result, atRule, conditions, from) {
return {
type: "layer",
node: atRule,
conditions: [...conditions],
from,
}
}

@@ -36,3 +36,3 @@ "use strict"

let charset
const imports = []
const beforeBundle = []
const bundle = []

@@ -60,3 +60,4 @@

stmt.children.forEach((child, index) => {
if (child.type === "import") imports.push(child)
if (child.type === "import") beforeBundle.push(child)
else if (child.type === "layer") beforeBundle.push(child)
else if (child.type === "charset") handleCharset(child)

@@ -67,3 +68,5 @@ else bundle.push(child)

})
} else imports.push(stmt)
} else beforeBundle.push(stmt)
} else if (stmt.type === "layer") {
beforeBundle.push(stmt)
} else if (stmt.type === "nodes") {

@@ -74,3 +77,5 @@ bundle.push(stmt)

return charset ? [charset, ...imports.concat(bundle)] : imports.concat(bundle)
return charset
? [charset, ...beforeBundle.concat(bundle)]
: beforeBundle.concat(bundle)
}

@@ -77,0 +82,0 @@

{
"name": "postcss-import",
"version": "16.1.0",
"version": "16.1.1",
"description": "PostCSS plugin to import CSS files",

@@ -30,10 +30,11 @@ "keywords": [

"ava": "^6.0.0",
"c8": "^9.0.0",
"eslint": "^8.27.0",
"eslint-config-problems": "^8.0.0",
"c8": "^10.0.0",
"eslint": "^9.28.0",
"eslint-config-problems": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"globals": "^16.2.0",
"postcss": "^8.0.0",
"postcss-scss": "^4.0.0",
"prettier": "~3.2.0",
"sugarss": "^4.0.0"
"prettier": "~3.5.0",
"sugarss": "^5.0.0"
},

@@ -48,21 +49,3 @@ "peerDependencies": {

"test": "c8 ava"
},
"eslintConfig": {
"extends": "eslint-config-problems",
"env": {
"node": true
},
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": [
"error",
{
"semi": false,
"arrowParens": "avoid"
}
]
}
}
}