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

chore: introduce CSS Modules #1265

Merged
merged 1 commit into from
Jan 19, 2024
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
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,25 @@ jobs:
run: yarn workspace ${{ matrix.package }} depcheck

- name: Audit dependencies
if: matrix.package != '@slicemachine/e2e'
run: yarn workspace ${{ matrix.package }} audit

- name: Lint
run: yarn workspace ${{ matrix.package }} lint

- name: Stylelint
if: matrix.package == 'slice-machine-ui'
run: yarn workspace ${{ matrix.package }} stylelint

- name: Generate TypeScript definition files from CSS Modules
if: matrix.package == 'slice-machine-ui'
run: yarn workspace ${{ matrix.package }} typed-css-modules

- name: Types
run: yarn workspace ${{ matrix.package }} types

- name: Unit
if: matrix.package != '@slicemachine/e2e'
run: yarn workspace ${{ matrix.package }} unit
env:
EMAIL: ${{ secrets.EMAIL }}
Expand Down Expand Up @@ -125,7 +135,7 @@ jobs:
- "@slicemachine/adapter-nuxt"
- "@slicemachine/adapter-nuxt2"
- "@slicemachine/adapter-sveltekit"
- "@slicemachine/e2e"
# - "@slicemachine/e2e" # Commented as there are no unit tests for `@slicemachine/e2e`.

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Ignore artifacts:
.github/
/.yarn
/packages/*/src/**/*.module.css.d.ts
/packages/*/storybook-static
/.pnp.*
packages/slice-machine/.next
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"packageManager": "[email protected]",
"scripts": {
"clean": "rimraf --glob '{e2e-projects/*/{.next,.svelte-kit},packages/*/{.next,.svelte-kit,build,coverage,dist,out,package.tgz,storybook-static},playwright/{playwright-report,test-results}}'",
"clean": "rimraf --glob '{e2e-projects/*/{.next,.svelte-kit},packages/*/{.next,.svelte-kit,build,coverage,dist,out,package.tgz,src/**/*.module.css.d.ts,storybook-static},playwright/{playwright-report,test-results}}'",
"dev": "concurrently --prefix-colors auto \"yarn:dev:*\"",
"dev:manager": "yarn workspace @slicemachine/manager dev",
"dev:start-slicemachine": "yarn workspace start-slicemachine dev",
Expand All @@ -20,6 +20,7 @@
"build-essential": "yarn workspace @slicemachine/plugin-kit build && yarn workspace @slicemachine/manager build",
"audit": "yarn workspaces foreach --parallel --verbose run audit",
"lint": "yarn workspaces foreach --verbose run lint",
"stylelint": "yarn workspaces foreach --verbose run stylelint",
"lint-staged": "lint-staged",
"prettier:fix": "prettier --write .",
"prettier:check": "prettier --check .",
Expand Down Expand Up @@ -65,6 +66,10 @@
"**/packages/slice-machine/**/*.@(js|jsx|ts|tsx|)": [
"prettier --write --ignore-unknown",
"yarn workspace slice-machine-ui lint:precommit"
],
"**/packages/slice-machine/**/*.module.css": [
"prettier --write --ignore-unknown",
"yarn workspace slice-machine-ui stylelint:precommit"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a discussion a while ago about removing pre-commit hooks considering we do these checks in CI. Is that still planned? If yes, I wonder if we should not add new pre-commit hooks.

(I prefer no pre-commit hooks since it slows the commit process down, but I don't have a full understanding of the history.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most team members, if not all, are okay to remove all our pre-commit hooks. However, I don't think it was listed somewhere so I've just created a Linear issue in our backlog: DT-1906. In the meantime, I think consistency has value and as TypeScript files are linted before committing, I think it's okay to do the same for CSS Modules.

]
},
"resolutions": {
Expand Down
4 changes: 3 additions & 1 deletion packages/slice-machine/.depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ignores:
"monocle-ts",
"newtype-ts",
"semver",
"start-slicemachine"
"start-slicemachine",
"stylelint-config-css-modules",
"stylelint-config-recommended"
]
skip - missing: true
1 change: 1 addition & 0 deletions packages/slice-machine/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/src/**/*.module.css.d.ts
/storybook-static
!/.storybook
build
Expand Down
1 change: 1 addition & 0 deletions packages/slice-machine/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ yarn-error.log*
.vercel

# typescript
/src/**/*.module.css.d.ts
*.tsbuildinfo
next-env.d.ts

Expand Down
22 changes: 15 additions & 7 deletions packages/slice-machine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
"node": ">=14"
},
"scripts": {
"build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 next build && next export",
"dev": "next dev",
"dev-cypress": "concurrently \"next dev\" \"npm run dev --prefix ../../e2e-projects/cypress-next-app\"",
"build": "yarn typed-css-modules && cross-env NODE_OPTIONS=--max_old_space_size=8192 next build && next export",
"dev": "concurrently \"yarn typed-css-modules:watch\" \"next dev\" --names \"typed-css-modules,next\" --prefix-colors auto",
"dev-cypress": "concurrently \"yarn typed-css-modules:watch\" \"next dev\" \"npm run dev --prefix ../../e2e-projects/cypress-next-app\" --names \"typed-css-modules,next,cypress-next-app\" --prefix-colors auto",
"lint": "eslint --max-warnings 0 --ext .ts,.tsx,.js,.jsx .",
"stylelint": "stylelint --max-warnings 0 \"src/**/*.module.css\"",
"prepack": "$npm_execpath run build",
"storybook": "storybook dev --no-open --port 6006",
"storybook-build": "storybook build",
"test": "yarn lint && yarn types && yarn unit && yarn build",
"test": "yarn lint && yarn stylelint && yarn typed-css-modules && yarn types && yarn unit && yarn build",
"types": "tsc --noEmit",
"typed-css-modules": "tcm --pattern \"src/**/*.module.css\" .",
"typed-css-modules:watch": "yarn typed-css-modules --watch",
"unit": "vitest run --coverage",
"unit:watch": "vitest watch",
"lint:precommit": "eslint --max-warnings 0",
"stylelint:precommit": "stylelint --max-warnings 0",
"depcheck": "depcheck --config=.depcheckrc",
"audit": "yarn npm audit --environment production --severity high"
},
Expand All @@ -38,9 +42,9 @@
"devDependencies": {
"@emotion/react": "11.11.1",
"@extractus/oembed-extractor": "3.1.8",
"@prismicio/editor-fields": "0.4.19",
"@prismicio/editor-support": "0.4.19",
"@prismicio/editor-ui": "0.4.19",
"@prismicio/editor-fields": "0.4.20",
"@prismicio/editor-support": "0.4.20",
"@prismicio/editor-ui": "0.4.20",
"@prismicio/mocks": "2.0.0-alpha.2",
"@prismicio/simulator": "0.1.4",
"@prismicio/types-internal": "2.2.0",
Expand Down Expand Up @@ -123,8 +127,12 @@
"remark-gfm": "3.0.1",
"semver": "7.3.8",
"storybook": "7.0.10",
"stylelint": "16.2.0",
"stylelint-config-css-modules": "4.4.0",
"stylelint-config-recommended": "14.0.0",
"swr": "1.3.0",
"theme-ui": "0.15.5",
"typed-css-modules": "0.8.1",
"typesafe-actions": "5.1.0",
"typescript": "4.9.5",
"vite": "4.3.9",
Expand Down
2 changes: 0 additions & 2 deletions packages/slice-machine/postcss.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions packages/slice-machine/src/components/Kbd/Kbd.css.ts

This file was deleted.

10 changes: 10 additions & 0 deletions packages/slice-machine/src/components/Kbd/Kbd.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.root {
background-color: var(--grey2);
border-color: var(--grey6);
/* stylelint-disable-next-line declaration-property-value-allowed-list -- The component has a border radius of 3 px in Figma. */
border-radius: 3px;
border-style: solid;
border-width: 1px;
color: var(--grey11);
padding-inline: 4px;
}
2 changes: 1 addition & 1 deletion packages/slice-machine/src/components/Kbd/Kbd.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, PropsWithChildren } from "react";

import * as styles from "./Kbd.css";
import styles from "./Kbd.module.css";

export const Kbd: FC<PropsWithChildren> = ({ children }) => (
<kbd className={styles.root}>{children}</kbd>
Expand Down
13 changes: 13 additions & 0 deletions packages/slice-machine/stylelint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { cssTheme } = require("@prismicio/editor-ui");

module.exports = {
defaultSeverity: "warning",
reportNeedlessDisables: true,
reportInvalidScopeDisables: true,
reportDescriptionlessDisables: true,
rules: {
"declaration-property-value-allowed-list": cssTheme,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line ensure we follow the theme tokens? Like colors, spacing, sizing, etc.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly 🙂 It works fine, but I miss the TypeScript auto completion.

},
extends: ["stylelint-config-recommended", "stylelint-config-css-modules"],
};
4 changes: 1 addition & 3 deletions playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
"description": "E2E tests for Slice Machine",
"author": "Prismic <[email protected]> (https://prismic.io)",
"scripts": {
"audit": "echo \"No audit for playwright\" && true",
"depcheck": "depcheck --config=.depcheckrc",
"lint": "eslint --max-warnings 0 --ext .js,.ts .",
"test:e2e:install": "playwright install --with-deps chromium",
"test:e2e:report": "playwright show-report",
"test:e2e": "playwright test",
"types": "tsc --noEmit",
"test:e2e:merge-reports": "playwright merge-reports",
"unit": "echo \"No unit tests for playwright\" && true"
"test:e2e:merge-reports": "playwright merge-reports"
},
"devDependencies": {
"@msgpack/msgpack": "2.8.0",
Expand Down
Loading
Loading