From e6920f4ba3e1fbca158787ca3cfa1d359444a5eb Mon Sep 17 00:00:00 2001 From: Jean-Philippe Zolesio Date: Thu, 27 Jul 2023 13:45:34 -0700 Subject: [PATCH] Replace unmaintained package css by @adobe/css-tools --- package.json | 3 +-- src/index.ts | 22 ++++++++++++++++------ src/utils.ts | 4 ++-- yarn.lock | 37 +++++-------------------------------- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 26aef2f..7fd383f 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/index.ts b/src/index.ts index bf503f5..a9dafdd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -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; @@ -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; @@ -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 || [] }, }); } @@ -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 = @@ -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( diff --git a/src/utils.ts b/src/utils.ts index ff4b0e7..cdec938 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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) => diff --git a/yarn.lock b/yarn.lock index c7c831e..df2afb6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -1958,11 +1958,6 @@ async@0.2: 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" @@ -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" @@ -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" @@ -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" - source-map-support@0.5.13: version "0.5.13" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"