Skip to content

Commit

Permalink
Update dependencies and practies
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Oct 7, 2023
1 parent 8eaab00 commit 3aa595b
Show file tree
Hide file tree
Showing 5 changed files with 638 additions and 359 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/test.yml
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest
version: 8
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 19
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
Expand All @@ -33,15 +33,14 @@ jobs:
node-version:
- 18
- 16
- 14
name: Node.js ${{ matrix.node-version }} Quick
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest
version: 8
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand All @@ -53,22 +52,26 @@ jobs:
run: pnpm unit
old:
runs-on: ubuntu-latest
name: Node.js 12 Quick
strategy:
matrix:
node-version:
- 14
- 12
name: Node.js ${{ matrix.node-version }} Quick
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 6
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Install Node.js 12
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: 12
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
run: pnpm install --no-frozen-lockfile --ignore-scripts
- name: Run unit tests
run: pnpm unit

34 changes: 17 additions & 17 deletions index.js
@@ -1,4 +1,4 @@
const { Rule, AtRule } = require('postcss')
const { AtRule, Rule } = require('postcss')
let parser = require('postcss-selector-parser')

/**
Expand Down Expand Up @@ -118,8 +118,8 @@ function createFnAtruleChilds(bubble) {

function pickDeclarations(selector, declarations, after) {
let parent = new Rule({
selector,
nodes: []
nodes: [],
selector
})
parent.append(declarations)
after.after(parent)
Expand All @@ -143,7 +143,7 @@ function parseRootRuleParams(params) {
params = params.trim()
let braceBlock = params.match(/^\((.*)\)$/)
if (!braceBlock) {
return { type: 'basic', selector: params }
return { selector: params, type: 'basic' }
}
let bits = braceBlock[1].match(/^(with(?:out)?):(.+)$/)
if (bits) {
Expand All @@ -165,8 +165,8 @@ function parseRootRuleParams(params) {
}

return {
type: 'withrules',
escapes
escapes,
type: 'withrules'
}
}
// Unrecognized brace block
Expand Down Expand Up @@ -250,14 +250,14 @@ const rootRuleEscapes = Symbol('rootRuleEscapes')

function normalizeRootRule(rule) {
let { params } = rule
let { type, selector, escapes } = parseRootRuleParams(params)
let { escapes, selector, type } = parseRootRuleParams(params)
if (type === 'unknown') {
throw rule.error(
`Unknown @${rule.name} parameter ${JSON.stringify(params)}`
)
}
if (type === 'basic' && selector) {
let selectorBlock = new Rule({ selector, nodes: rule.nodes })
let selectorBlock = new Rule({ nodes: rule.nodes, selector })
rule.removeAll()
rule.append(selectorBlock)
}
Expand Down Expand Up @@ -287,15 +287,22 @@ module.exports = (opts = {}) => {
let preserveEmpty = opts.preserveEmpty

return {
postcssPlugin: 'postcss-nested',

Once(root) {
root.walkAtRules(rootRuleName, node => {
normalizeRootRule(node)
root[hasRootRule] = true
})
},

postcssPlugin: 'postcss-nested',

RootExit(root) {
if (root[hasRootRule]) {
root.walkAtRules(rootRuleName, unwrapRootRule)
root[hasRootRule] = false
}
},

Rule(rule) {
let unwrapped = false
let after = rule
Expand Down Expand Up @@ -348,13 +355,6 @@ module.exports = (opts = {}) => {
rule.raws.semicolon = true
if (rule.nodes.length === 0) rule.remove()
}
},

RootExit(root) {
if (root[hasRootRule]) {
root.walkAtRules(rootRuleName, unwrapRootRule)
root[hasRootRule] = false
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions index.test.js
Expand Up @@ -676,12 +676,12 @@ test('works with other visitors', () => {
let css = 'a{b{color:red}@mixin;}'
let mixinPlugin = () => {
return {
postcssPlugin: 'mixin',
AtRule: {
mixin(node) {
node.replaceWith('.in{.deep{color:blue}}')
}
}
},
postcssPlugin: 'mixin'
}
}
mixinPlugin.postcss = true
Expand All @@ -695,12 +695,12 @@ test('works with other visitors #2', () => {
let css = 'a { @mixin; b {color:red} }'
let mixinPlugin = () => {
return {
postcssPlugin: 'mixin',
AtRule: {
mixin(node) {
node.replaceWith('.in { .deep {color:blue} }')
}
}
},
postcssPlugin: 'mixin'
}
}
mixinPlugin.postcss = true
Expand Down
24 changes: 14 additions & 10 deletions package.json
Expand Up @@ -11,7 +11,9 @@
],
"scripts": {
"unit": "uvu . '\\.test\\.js$'",
"test": "c8 pnpm unit && eslint ."
"test:coverage": "c8 pnpm unit",
"test:lint": "eslint .",
"test": "pnpm run /^test:/"
},
"author": "Andrey Sitnik <andrey@sitnik.ru>",
"license": "MIT",
Expand All @@ -33,19 +35,21 @@
"postcss": "^8.2.14"
},
"dependencies": {
"postcss-selector-parser": "^6.0.11"
"postcss-selector-parser": "^6.0.13"
},
"devDependencies": {
"@logux/eslint-config": "^49.0.0",
"c8": "^7.13.0",
"clean-publish": "^4.1.1",
"eslint": "^8.36.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"@logux/eslint-config": "^52.0.1",
"c8": "^8.0.1",
"clean-publish": "^4.2.0",
"eslint": "^8.51.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-node-import": "^1.0.4",
"eslint-plugin-perfectionist": "^2.1.0",
"eslint-plugin-prefer-let": "^3.0.1",
"eslint-plugin-promise": "^6.1.1",
"postcss": "^8.4.21",
"postcss": "^8.4.31",
"uvu": "^0.5.6"
},
"prettier": {
Expand Down

0 comments on commit 3aa595b

Please sign in to comment.