Skip to content

Commit

Permalink
Remove stable package in favor of native stable sort (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr authored Oct 1, 2022
1 parent fdc9ceb commit 2ea6586
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
3 changes: 1 addition & 2 deletions lib/css-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var csstree = require('css-tree'),
List = csstree.List,
stable = require('stable'),
specificity = require('csso/lib/restructure/prepare/specificity');

/**
Expand Down Expand Up @@ -162,7 +161,7 @@ function _bySelectorSpecificity(selectorA, selectorB) {
* @return {Array} Stable sorted selectors
*/
function sortSelectors(selectors) {
return stable(selectors, _bySelectorSpecificity);
return [...selectors].sort(_bySelectorSpecificity);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions lib/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @typedef {import('./types').XastChild} XastChild
*/

const stable = require('stable');
const csstree = require('css-tree');
// @ts-ignore not defined in @types/csso
const specificity = require('csso/lib/restructure/prepare/specificity');
Expand Down Expand Up @@ -249,9 +248,7 @@ const collectStylesheet = (root) => {
},
});
// sort by selectors specificity
stable.inplace(rules, (a, b) =>
compareSpecificity(a.specificity, b.specificity)
);
rules.sort((a, b) => compareSpecificity(a.specificity, b.specificity));
return { rules, parents };
};
exports.collectStylesheet = collectStylesheet;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@
"css-select": "^5.1.0",
"css-tree": "^1.1.3",
"csso": "^4.2.0",
"picocolors": "^1.0.0",
"stable": "^0.1.8"
"picocolors": "^1.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.2",
Expand Down
13 changes: 7 additions & 6 deletions plugins/inlineStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
const csstree = require('css-tree');
// @ts-ignore not defined in @types/csso
const specificity = require('csso/lib/restructure/prepare/specificity');
const stable = require('stable');
const {
visitSkip,
querySelectorAll,
Expand Down Expand Up @@ -200,11 +199,13 @@ exports.fn = (root, params) => {
return;
}
// stable sort selectors
const sortedSelectors = stable(selectors, (a, b) => {
const aSpecificity = specificity(a.item.data);
const bSpecificity = specificity(b.item.data);
return compareSpecificity(aSpecificity, bSpecificity);
}).reverse();
const sortedSelectors = [...selectors]
.sort((a, b) => {
const aSpecificity = specificity(a.item.data);
const bSpecificity = specificity(b.item.data);
return compareSpecificity(aSpecificity, bSpecificity);
})
.reverse();

for (const selector of sortedSelectors) {
// match selectors
Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4396,13 +4396,6 @@ __metadata:
languageName: node
linkType: hard

"stable@npm:^0.1.8":
version: 0.1.8
resolution: "stable@npm:0.1.8"
checksum: 2ff482bb100285d16dd75cd8f7c60ab652570e8952c0bfa91828a2b5f646a0ff533f14596ea4eabd48bb7f4aeea408dce8f8515812b975d958a4cc4fa6b9dfeb
languageName: node
linkType: hard

"stack-utils@npm:^2.0.3":
version: 2.0.3
resolution: "stack-utils@npm:2.0.3"
Expand Down Expand Up @@ -4583,7 +4576,6 @@ __metadata:
prettier: ^2.7.1
rollup: ^2.79.1
rollup-plugin-terser: ^7.0.2
stable: ^0.1.8
tar-stream: ^2.2.0
typescript: ^4.8.4
bin:
Expand Down

0 comments on commit 2ea6586

Please sign in to comment.