Skip to content

Commit 40c1954

Browse files
authored
feat(tokens): remove components from token build (#3488)
1 parent 42f6f0b commit 40c1954

Some content is hidden

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

47 files changed

+4493
-4901
lines changed

.changeset/clean-doors-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spectrum-tools/gh-action-file-diff": minor
3+
---
4+
5+
Update file table to specify if the file is deleted/moved and indicate the file size has decreased without showing percentages. This update also hardens the way in which the main file is highlighted in the table by checking for exact equals for looking for files "ending with" the file name.

.changeset/olive-poets-love.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
"@spectrum-css/tokens": major
3+
---
4+
5+
### Breaking change
6+
7+
This update removes the compiled `components` directory from the token output. Instead, customers are asked to source the theming data from the component's `theme/(express,spectrum,spectrum-two).css` and `index-theme.css`. For example:
8+
9+
```
10+
import "@spectrum-css/actionbutton/dist/index-base.css";
11+
import "@spectrum-css/actionbutton/dist/index-theme.css";
12+
import "@spectrum-css/actionbutton/dist/themes/express.css";
13+
```
14+
15+
In addition, the `custom-*-vars.css` files previously shipped in the `spectrum` and `express` folders will no longer be shipped separately. This data already exists in the `*-vars.css` file with a matching name. For example, `spectrum/custom-large-vars.css` already exists within `spectrum/large-vars.css`, concatenated with the token-generated output.
16+
17+
### Minor
18+
19+
Whitespace has been cleaned up in the exported content for readability.

.github/actions/file-diff/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ async function run() {
175175
const removedOnBranch = isRemoved(headByteSize, baseByteSize);
176176
// @todo should there be any normalization before comparing the file names?
177177
const isMainFile = readableFilename === mainFile;
178-
const size = removedOnBranch ? " - " : bytesToSize(headByteSize);
179-
const delta = `${printChange(headByteSize, baseByteSize)}${difference(baseByteSize, headByteSize) !== 0 ? ` (${printPercentChange(headByteSize , baseByteSize)})` : ""}`;
178+
const size = removedOnBranch ? "🚨 deleted/moved" : bytesToSize(headByteSize);
179+
const change = !removedOnBranch ? printChange(headByteSize, baseByteSize) : `⬇ ${bytesToSize(baseByteSize)}`;
180+
const diff = difference(baseByteSize, headByteSize) !== 0 ? ` (${printPercentChange(headByteSize , baseByteSize)})` : "";
181+
const delta = `${change}${removedOnBranch ? "" : diff}`;
180182

181183
return [
182184
...table,
@@ -323,7 +325,13 @@ const makeTable = function (PACKAGES, filePath, path) {
323325
if (main) mainFile = main.replace(/^.*\/dist\//, "");
324326
}
325327

326-
const mainFileOnly = [...fileMap.keys()].filter((file) => file.endsWith(mainFile));
328+
let mainFileOnly = [...fileMap.keys()].filter((file) => file === mainFile);
329+
330+
// If no main file is found, look for the first file matching the filename only
331+
if (mainFileOnly.length === 0) {
332+
mainFileOnly = [...fileMap.keys()].filter((file) => file.endsWith(mainFile));
333+
}
334+
327335
const headMainSize = mainFileOnly.reduce(
328336
(acc, filename) => {
329337
const { headByteSize = 0 } = fileMap.get(filename);

tasks/component-builder.js

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ require("colors");
2626
const {
2727
dirs,
2828
relativePrint,
29-
bytesToSize,
3029
getPackageFromPath,
3130
cleanFolder,
3231
validateComponentName,
32+
writeAndReport,
3333
fetchContent,
3434
copy,
3535
} = require("./utilities.js");
@@ -55,10 +55,20 @@ async function processCSS(
5555
...postCSSOptions
5656
} = {},
5757
) {
58-
if (!content)
59-
return Promise.reject(
60-
new Error("This function requires content be provided"),
61-
);
58+
if (!content) {
59+
if (!fs.existsSync(input)) {
60+
return Promise.reject(
61+
new Error("This function requires that either content or an input path be provided")
62+
);
63+
}
64+
else {
65+
content = await fsp.readFile(input, "utf-8");
66+
67+
if (!content) {
68+
return Promise.reject(new Error(`No content found for ${relativePrint(input, { cwd })}`));
69+
}
70+
}
71+
}
6272

6373
const ctx = {
6474
cwd,
@@ -107,36 +117,12 @@ async function processCSS(
107117
}
108118

109119
const promises = [
110-
fsp
111-
.writeFile(output, formatted)
112-
.then(() => {
113-
const stats = fs.statSync(output);
114-
return `${"✓".green} ${relativePrint(output, { cwd }).padEnd(20, " ").yellow} ${bytesToSize(stats.size).gray}`;
115-
})
116-
.catch((err) => {
117-
if (!err) return;
118-
console.log(
119-
`${"✗".red} ${relativePrint(output, { cwd }).yellow} not written`,
120-
);
121-
return Promise.reject(err);
122-
}),
120+
writeAndReport(formatted, output, { cwd }),
123121
];
124122

125123
if (result.map) {
126124
promises.push(
127-
fsp
128-
.writeFile(`${output}.map`, result.map.toString().trimStart())
129-
.then(() => {
130-
const stats = fs.statSync(output);
131-
return `${"✓".green} ${relativePrint(`${output}.map`, { cwd }).padEnd(20, " ").yellow} ${bytesToSize(stats.size).gray}`;
132-
})
133-
.catch((err) => {
134-
if (!err) return;
135-
console.log(
136-
`${"✗".red} ${relativePrint(`${output}.map`, { cwd }).yellow} not written`,
137-
);
138-
return Promise.reject(err);
139-
}),
125+
writeAndReport(result.map.toString().trimStart(), `${output}.map`, { cwd }),
140126
);
141127
}
142128

@@ -151,12 +137,10 @@ async function processCSS(
151137
* @returns Promise<void>
152138
*/
153139
async function build({ cwd = process.cwd(), clean = false, componentName } = {}) {
154-
const indexSourceCSS = path.join(cwd, "index.css");
155-
156140
// Nothing to do if there's no input file
157-
if (!fs.existsSync(indexSourceCSS)) return;
141+
if (!fs.existsSync(path.join(cwd, "index.css"))) return;
158142

159-
const content = await fsp.readFile(indexSourceCSS, "utf8");
143+
const content = await fsp.readFile(path.join(cwd, "index.css"), "utf8");
160144

161145
if (!componentName || validateComponentName(componentName) !== true) {
162146
componentName = getPackageFromPath(cwd);
@@ -170,7 +154,7 @@ async function build({ cwd = process.cwd(), clean = false, componentName } = {})
170154
const indexOutputPath = path.join(cwd, "dist", "index.css");
171155

172156
return Promise.all([
173-
processCSS(content, indexSourceCSS, indexOutputPath, {
157+
processCSS(content, path.join(cwd, "index.css"), indexOutputPath, {
174158
cwd,
175159
clean,
176160
skipMapping: true,
@@ -184,7 +168,7 @@ async function build({ cwd = process.cwd(), clean = false, componentName } = {})
184168
}),
185169
processCSS(
186170
content,
187-
indexSourceCSS,
171+
path.join(cwd, "index.css"),
188172
path.join(cwd, "dist", "index-base.css"),
189173
{
190174
cwd,

tasks/component-reporter.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/* eslint-disable no-console */
1515
const fs = require("fs");
16-
const fsp = fs.promises;
1716
const path = require("path");
1817

1918
const postcss = require("postcss");
@@ -169,8 +168,7 @@ async function main({
169168
return Promise.reject(new Error(`No source CSS file found at ${sourceCSS}`));
170169
}
171170

172-
const content = await fsp.readFile(sourceCSS, "utf-8");
173-
const processed = await processCSS(content, sourceCSS, undefined, {
171+
const processed = await processCSS(undefined, sourceCSS, undefined, {
174172
cwd,
175173
skipMapping: true,
176174
referencesOnly: false,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)