Skip to content

Commit b81d434

Browse files
slorberclaude
andauthored
chore(infima): add the @docusaurus/infima package, compiled from the Infima sources (#13082)
* chore(infima): add the @docusaurus/infima package, compiled from the Infima sources Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(infima): link the PR in the postcss-preset-env-v7 catalog comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(infima): override the vulnerable postcss versions of the Infima build plugins Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: apply lint autofix * docs(infima): only link the upstream Infima repository as the origin of the sources Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(infima): also build the RTL Infima file, as infima-rtl.css Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(argos): diff the Infima LTR and RTL CSS files on Argos Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: slorber <749374+slorber@users.noreply.github.com>
1 parent cb96836 commit b81d434

50 files changed

Lines changed: 3575 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/argos.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ jobs:
6868
run: pnpm argos:format:text-snapshots
6969
- name: Upload Argos text snapshots
7070
run: pnpm argos:upload:text-snapshots
71+
72+
# pnpm install builds the Infima CSS files
73+
- name: Upload Argos Infima CSS snapshots
74+
run: pnpm argos:upload:infima

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ packages/docusaurus/lib/
2727
packages/docusaurus-*/lib/*
2828
packages/eslint-plugin/lib/
2929
packages/stylelint-copyright/lib/
30+
packages/docusaurus-infima/dist/
3031

3132
website/changelog
3233

‎.oxfmtrc.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"!packages/docusaurus-*/lib/theme/",
2626

2727
"packages/create-docusaurus/templates/*/docusaurus.config.js",
28+
"packages/docusaurus-infima/styles",
2829
"packages/eslint-plugin/lib/",
2930
"packages/stylelint-copyright/lib/",
3031
"__fixtures__",

‎.stylelintignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ packages/lqip-loader/lib/
1313
packages/docusaurus/lib/
1414
packages/docusaurus-*/lib/*
1515
packages/create-docusaurus/lib/*
16+
packages/docusaurus-infima/dist/
1617
packages/create-docusaurus/templates/
1718
website/static/katex/katex.min.css
1819
website/_dogfooding/_asset-tests/badSyntax.css

‎argos/README.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This workspace can be run manually, but is generally run through the [Argos GitH
88

99
This workflow runs for `main` and PR branches, and add a commit status to each PR with a visual diff that we can easily inspect.
1010

11-
The workflow execute the 2 main steps below:
11+
The workflow execute the 3 main steps below:
1212

1313
### Screenshots
1414

@@ -22,6 +22,10 @@ The workflow execute the 2 main steps below:
2222
- Rebuild - this time with HTML unminified/formatted.
2323
- Upload [HTML/CSS/JS files, blog feeds (RSS/Atom/JSON) and the sitemap to also diff them on Argos](https://argos-ci.com/docs/learn/how-to-guides/visual-coverage/compare-non-image-files) using `pnpm argos:upload:text-snapshots`
2424

25+
### Infima CSS
26+
27+
- Upload the CSS files compiled by [`@docusaurus/infima`](../packages/docusaurus-infima) (LTR and RTL) to diff them on Argos, in a separate `infima` build, using `pnpm argos:upload:infima`
28+
2529
## Run manually
2630

2731
Install the Playwright browser once:
@@ -45,6 +49,12 @@ pnpm argos:format:text-snapshots
4549
pnpm argos:upload:text-snapshots
4650
```
4751

52+
To run the Infima CSS step manually (`pnpm install` already builds the files):
53+
54+
```bash
55+
pnpm argos:upload:infima
56+
```
57+
4858
## How to modify
4959

5060
- Use [./tests/screenshot.spec.ts](./tests/screenshot.spec.ts) to customize the screenshots we take, eventually filter out some useless sitemap pages like versioned docs

‎argos/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"screenshot": "playwright test",
99
"upload": "pnpm exec -- argos upload ./screenshots/chromium",
1010
"upload-text-snapshots": "pnpm exec -- argos upload \"../website/build\" --build-name text-snapshots --files styles.css --files \"docs/**/*.html\" --files \"blog/**/*.html\" --files \"**/rss.xml\" --files \"**/atom.xml\" --files \"**/feed.json\" --files sitemap.xml",
11+
"upload-infima": "pnpm exec -- argos upload ../packages/docusaurus-infima/dist --build-name infima --files \"*.css\"",
1112
"report": "playwright show-report"
1213
},
1314
"dependencies": {

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
"crowdin:upload:website": "crowdin upload sources --config ./crowdin-v2.yaml",
3636
"crowdin:download": "crowdin download --config ./crowdin-v2.yaml",
3737
"crowdin:download:website": "pnpm crowdin:download --language fr --language ko --language pt-BR --language zh-CN --language ja",
38-
"argos": "pnpm argos:build && pnpm argos:screenshot && pnpm argos:build:text-snapshots && pnpm argos:format:text-snapshots && pnpm argos:upload:text-snapshots",
38+
"argos": "pnpm argos:build && pnpm argos:screenshot && pnpm argos:build:text-snapshots && pnpm argos:format:text-snapshots && pnpm argos:upload:text-snapshots && pnpm argos:upload:infima",
3939
"argos:build": "cross-env DOCUSAURUS_ARGOS_BUILD=true pnpm build:website:fast --dev",
4040
"argos:screenshot": "pnpm --filter argos screenshot",
4141
"argos:build:text-snapshots": "cross-env DOCUSAURUS_ARGOS_BUILD=true SKIP_HTML_MINIFICATION=true pnpm build:website:fast --dev --no-minify",
4242
"argos:format:text-snapshots": "node argos/normalizeTextSnapshots.mjs && pnpm format:website:build",
4343
"argos:upload:text-snapshots": "pnpm --filter argos upload-text-snapshots",
44+
"argos:upload:infima": "pnpm --filter argos upload-infima",
4445
"canary": "pnpm canary:bumpVersion && pnpm canary:publish",
4546
"canary:getCoreVersion": "node -p \"require('./packages/docusaurus/package.json').version.split('-')[0]\"",
4647
"canary:version": "echo `pnpm --silent canary:getCoreVersion`-canary-`git rev-list --count HEAD`+`git rev-parse --short HEAD`",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `@docusaurus/infima`
2+
3+
The Infima CSS framework, an internal package of `@docusaurus/theme-classic`.
4+
5+
Don't depend on it directly: it has no stability guarantee, except for the `--ifm-*` CSS variables and the documented class names. The Infima documentation moves to [docusaurus.io/infima](https://docusaurus.io/infima).
6+
7+
## Origin
8+
9+
The `styles` sources come from the former upstream repository at commit [`87bc1dbf`](https://github.com/facebookincubator/infima/tree/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab): they are the same as the published `infima@0.2.0-alpha.45` package. `scripts/build.mjs` inlines its [PostCSS preset](https://github.com/facebookincubator/infima/blob/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab/packages/postcss-preset-infima/index.js).
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "@docusaurus/infima",
3+
"version": "4.0.0",
4+
"description": "Infima CSS framework, used by the Docusaurus classic theme.",
5+
"sideEffects": [
6+
"*.css"
7+
],
8+
"exports": {
9+
"./infima.css": "./dist/infima.css",
10+
"./infima-rtl.css": "./dist/infima-rtl.css",
11+
"./package.json": "./package.json"
12+
},
13+
"files": [
14+
"dist"
15+
],
16+
"scripts": {
17+
"build": "node scripts/build.mjs"
18+
},
19+
"publishConfig": {
20+
"access": "public"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/meta/docusaurus.git",
25+
"directory": "packages/docusaurus-infima"
26+
},
27+
"license": "MIT",
28+
"devDependencies": {
29+
"postcss": "catalog:",
30+
"postcss-color-mod-function": "catalog:dev",
31+
"postcss-combine-duplicated-selectors": "catalog:dev",
32+
"postcss-each": "catalog:dev",
33+
"postcss-for": "catalog:dev",
34+
"postcss-import": "catalog:dev",
35+
"postcss-mixins": "catalog:dev",
36+
"postcss-nested": "catalog:dev",
37+
"postcss-nested-ancestors": "catalog:dev",
38+
"postcss-preset-env-v7": "catalog:dev",
39+
"postcss-sort-media-queries": "catalog:dev",
40+
"rtlcss": "catalog:"
41+
},
42+
"engines": {
43+
"node": ">=26.13"
44+
}
45+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// Inlines the upstream postcss-preset-infima and the gulp styles and rtl tasks
9+
// See https://github.com/facebookincubator/infima/blob/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab/packages/postcss-preset-infima/index.js
10+
11+
import fs from 'node:fs/promises';
12+
import path from 'node:path';
13+
import postcss from 'postcss';
14+
import postcssColorModFunction from 'postcss-color-mod-function';
15+
import postcssCombineDuplicatedSelectors from 'postcss-combine-duplicated-selectors';
16+
import postcssEach from 'postcss-each';
17+
import postcssFor from 'postcss-for';
18+
import postcssImport from 'postcss-import';
19+
import postcssMixins from 'postcss-mixins';
20+
import postcssNested from 'postcss-nested';
21+
import postcssNestedAncestors from 'postcss-nested-ancestors';
22+
import postcssPresetEnv from 'postcss-preset-env-v7';
23+
import postcssSortMediaQueries from 'postcss-sort-media-queries';
24+
import rtlcss from 'rtlcss';
25+
26+
const packageDir = path.dirname(import.meta.dirname);
27+
const entryFile = path.join(packageDir, 'styles/themes/default/default.pcss');
28+
const outputFile = path.join(packageDir, 'dist/infima.css');
29+
const rtlOutputFile = path.join(packageDir, 'dist/infima-rtl.css');
30+
31+
async function main() {
32+
const source = await fs.readFile(entryFile, 'utf8');
33+
const css = await compileInfima(source, entryFile);
34+
await fs.mkdir(path.dirname(outputFile), {recursive: true});
35+
await fs.writeFile(outputFile, css);
36+
await fs.writeFile(rtlOutputFile, rtlcss.process(css));
37+
}
38+
39+
async function compileInfima(source, from) {
40+
const result = await postcss(getPlugins()).process(source, {from});
41+
return result.css;
42+
}
43+
44+
// The plugin order matters
45+
function getPlugins() {
46+
return [
47+
postcssImport,
48+
// TODO postcss-each v1 doesn't seem to be compatible due to color-mod.
49+
// Need to upgrade later
50+
postcssEach,
51+
postcssFor,
52+
postcssMixins({mixins: {transition: transitionMixin}}),
53+
postcssNestedAncestors,
54+
postcssNested,
55+
// color-mod has been removed from the spec, so it's not included in
56+
// preset-env. Using a separate plugin instead. We probably would eventually
57+
// get rid of color-mod
58+
postcssColorModFunction({unresolved: 'ignore'}),
59+
postcssPresetEnv({
60+
stage: 1,
61+
features: {
62+
'custom-properties': false,
63+
},
64+
}),
65+
postcssSortMediaQueries,
66+
postcssCombineDuplicatedSelectors,
67+
];
68+
}
69+
70+
// @mixin transition opacity visibility, var(--ifm-transition-fast), linear;
71+
function transitionMixin(
72+
_mixin,
73+
properties,
74+
duration = 'var(--ifm-transition-fast)',
75+
timing = 'var(--ifm-transition-timing-default)',
76+
) {
77+
if (properties.includes(' ')) {
78+
return {
79+
'transition-property': properties.replace(/\s/g, ', '),
80+
'transition-duration': duration,
81+
'transition-timing-function': timing,
82+
};
83+
}
84+
return {transition: [properties, duration, timing].join(' ')};
85+
}
86+
87+
await main();

0 commit comments

Comments
 (0)