Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace unmaintained package css by @adobe/css-tools #258

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
"sass": ">=1.45.0"
},
"dependencies": {
"@types/css": "^0.0.33",
"css": "^3.0.0",
"@adobe/css-tools": "^4.3.0-rc.1",
"jest-diff": "^29.4.3",
"lodash": "^4.17.21"
},
Expand Down
22 changes: 16 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-use-before-define */

import {
CssAtRuleAST,
CssCommentAST,
CssRuleAST,
CssTypes,
parse as cssParse,
stringify as cssStringify,
} from '@adobe/css-tools';
import * as assert from 'assert';
import * as css from 'css';
import { diffStringsUnified } from 'jest-diff';
import { find, forEach, last, startsWith } from 'lodash';
import * as path from 'path';
Expand Down Expand Up @@ -55,7 +62,7 @@ export type Context = {
currentExpectedRules?: Rule[];
};

export type Rule = css.Comment | css.Rule | css.AtRule;
export type Rule = CssCommentAST | CssRuleAST | CssAtRuleAST;

export type Parser = (rule: Rule, ctx: Context) => Parser;

Expand Down Expand Up @@ -253,7 +260,7 @@ export const parse = function (
const lines = rawCss.split(/\r?\n/);

const parseCss = function () {
const ast = css.parse(rawCss);
const ast = cssParse(rawCss);
const ctx: Context = { modules: [] };
let handler = parseModule;

Expand Down Expand Up @@ -459,7 +466,8 @@ export const parse = function (
if (rule.comment?.trim() === constants.OUTPUT_END_TOKEN) {
/* istanbul ignore else */
if (ctx.currentAssertion) {
ctx.currentAssertion.output = css.stringify({
ctx.currentAssertion.output = cssStringify({
type: CssTypes.stylesheet,
stylesheet: { rules: ctx.currentOutputRules || [] },
});
}
Expand Down Expand Up @@ -504,7 +512,8 @@ export const parse = function (
if (rule.comment?.trim() === constants.EXPECTED_END_TOKEN) {
/* istanbul ignore else */
if (ctx.currentAssertion) {
ctx.currentAssertion.expected = css.stringify({
ctx.currentAssertion.expected = cssStringify({
type: CssTypes.stylesheet,
stylesheet: { rules: ctx.currentExpectedRules || [] },
});
ctx.currentAssertion.passed =
Expand Down Expand Up @@ -546,7 +555,8 @@ export const parse = function (
if (rule.comment?.trim() === constants.CONTAINED_END_TOKEN) {
/* istanbul ignore else */
if (ctx.currentAssertion) {
ctx.currentAssertion.expected = css.stringify({
ctx.currentAssertion.expected = cssStringify({
type: CssTypes.stylesheet,
stylesheet: { rules: ctx.currentExpectedRules || [] },
});
ctx.currentAssertion.passed = contains(
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Comment, Node } from 'css';
import { CssAllNodesAST, CssCommentAST } from '@adobe/css-tools';

export const truthyValues = (item?: any) => Boolean(item);

export const isCommentNode = (node: Node): node is Comment =>
export const isCommentNode = (node: CssAllNodesAST): node is CssCommentAST =>
node.type === 'comment';

export const removeNewLines = (cssString: string) =>
Expand Down
37 changes: 5 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@adobe/css-tools@^4.3.0-rc.1":
version "4.3.0-rc.1"
resolved "https://artifactory.corp.adobe.com/artifactory/api/npm/npm-adobe-platform-release/@adobe/css-tools/-/css-tools-4.3.0-rc.1.tgz#20885a8bfe608512a9a191267b1df0017745e3fe"
integrity sha512-9QU7yHfQvQ++yc2zQlpu2eUcYgl7lIcAWPqLQ7X3mbKGK4ivMMuKQLRPQoKdbAdluDltb8Q49jGAVYcfsND0yA==

"@ampproject/remapping@^2.1.0", "@ampproject/remapping@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.2.0.tgz#56c133824780de3174aed5ab6834f3026790154d"
Expand Down Expand Up @@ -1565,11 +1570,6 @@
dependencies:
"@babel/types" "^7.3.0"

"@types/css@^0.0.33":
version "0.0.33"
resolved "https://registry.yarnpkg.com/@types/css/-/css-0.0.33.tgz#d0b49c4090c09c8e5dc01364560627e5ebb770f2"
integrity sha512-qjeDgh86R0LIeEM588q65yatc8Yyo/VvSIYFqq8JOIHDolhGNX0rz7k/OuxqDpnpqlefoHj8X4Ai/6hT9IWtKQ==

"@types/graceful-fs@^4.1.3":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
Expand Down Expand Up @@ -1958,11 +1958,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"
integrity sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==

atob@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

babel-jest@^29.4.3:
version "29.4.3"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-29.4.3.tgz#478b84d430972b277ad67dd631be94abea676792"
Expand Down Expand Up @@ -2619,15 +2614,6 @@ css-what@^6.1.0:
resolved "https://registry.yarnpkg.com/css-what/-/css-what-6.1.0.tgz#fb5effcf76f1ddea2c81bdfaa4de44e79bac70f4"
integrity sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==

css@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/css/-/css-3.0.0.tgz#4447a4d58fdd03367c516ca9f64ae365cee4aa5d"
integrity sha512-DG9pFfwOrzc+hawpmqX/dHYHJG+Bsdb0klhyi1sDneOgGOXy9wQIC8hzyVp1e4NRYDBdxcylvywPkkXCHAzTyQ==
dependencies:
inherits "^2.0.4"
source-map "^0.6.1"
source-map-resolve "^0.6.0"

cssesc@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
Expand Down Expand Up @@ -2677,11 +2663,6 @@ decamelize@^5.0.0:
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-5.0.1.tgz#db11a92e58c741ef339fb0a2868d8a06a9a7b1e9"
integrity sha512-VfxadyCECXgQlkoEAjeghAr5gY3Hf+IKjKb+X8tGVDtveCjN+USwprd2q3QXBR9T1+x2DG0XZF5/w+7HAtSaXA==

decode-uri-component@^0.2.0:
version "0.2.2"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9"
integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==

decompress-response@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-3.3.0.tgz#80a4dd323748384bfa248083622aedec982adff3"
Expand Down Expand Up @@ -6310,14 +6291,6 @@ slice-ansi@^4.0.0:
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==

source-map-resolve@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2"
integrity sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w==
dependencies:
atob "^2.1.2"
decode-uri-component "^0.2.0"

[email protected]:
version "0.5.13"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
Expand Down