Skip to content

Commit 834aea1

Browse files
committed
feat!: migrate processors to standard postcss config; add postcss-reporter
1 parent ee1d7f0 commit 834aea1

File tree

317 files changed

+2710
-5509
lines changed

Some content is hidden

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

317 files changed

+2710
-5509
lines changed

.storybook/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"lodash-es": "^4.17.21",
4848
"postcss": "^8.4.33",
4949
"postcss-class-prefix": "^0.3.0",
50+
"postcss-load-config": "^5.0.2",
5051
"postcss-loader": "^4.0.0",
5152
"postcss-prefix-selector": "^1.16.0",
5253
"postcss-selector-replace": "^1.0.2",

.storybook/postcss.config.js

Lines changed: 101 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,77 @@
1-
const { resolve, basename } = require("path");
1+
/*!
2+
Copyright 2023 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
const { resolve, basename, dirname } = require("path");
214
const { existsSync } = require("fs");
15+
316
const warnCleaner = require("postcss-warn-cleaner");
417

5-
const simpleBuilder = require("@spectrum-css/component-builder-simple/css/processors.js");
6-
const legacyBuilder = require("@spectrum-css/component-builder/css/processors.js");
18+
const simpleBuilder = dirname(
19+
require.resolve("@spectrum-css/component-builder-simple", {
20+
paths: [__dirname, resolve(__dirname, "../")],
21+
})
22+
) ?? resolve(__dirname, "../tools/component-builder-simple");
723

8-
/**
9-
* Determines the package name from a file path
10-
* @param {string} filePath
11-
* @returns {string}
12-
*/
13-
function getPackageFromPath(filePath) {
14-
return filePath.match(`(components|@spectrum-css)\/(.*?)\/`)?.[2];
15-
}
24+
const legacyBuilder = dirname(
25+
require.resolve("@spectrum-css/component-builder", {
26+
paths: [__dirname, resolve(__dirname, "../")],
27+
})
28+
) ?? resolve(__dirname, "../tools/component-builder");
29+
30+
const postcssrc = require("postcss-load-config");
31+
32+
module.exports = async (ctx) => {
33+
const file = ctx && Object.keys(ctx) ? ctx.file ?? ctx.to ?? ctx.from : undefined;
34+
35+
/**
36+
* Determines the package name from a file path
37+
* @param {string} filePath
38+
* @returns {string}
39+
*/
40+
function getPackageFromPath(filePath) {
41+
if (!filePath) return;
42+
43+
// Capture component name from a local or node_modules syntax
44+
const componentCheck = filePath.match(/(?:components|@spectrum-css)\/(\w+)/);
45+
if (componentCheck && componentCheck?.[1]) return componentCheck[1];
46+
47+
// Check local root-level packages such as ui-icons & tokens
48+
const pkgCheck = filePath.match(/\/(ui-icons|tokens)\//);
49+
if (pkgCheck && pkgCheck?.[1]) return pkgCheck[1];
50+
51+
return;
52+
}
53+
54+
const plugins = [];
1655

17-
module.exports = (ctx) => {
18-
let plugins = [];
19-
const componentPath = resolve(__dirname, "../components");
2056
/** @todo put together a more robust fallback determination */
21-
const folderName = getPackageFromPath(ctx.file) ?? "tokens";
22-
const pkgPath = resolve(componentPath, folderName, "package.json");
57+
const folderName = file && getPackageFromPath(file);
58+
59+
const componentPath = resolve(__dirname, "../components");
60+
const pkgPath = folderName && resolve(componentPath, folderName, "package.json");
2361

2462
/**
2563
* For our token libraries, include a little extra parsing to allow duplicate
2664
* token values to exist in parallel and be toggled using args in storybook.
2765
*/
28-
if (["expressvars", "vars", "tokens"].includes(folderName)) {
66+
if (folderName && ["expressvars", "vars"].includes(folderName)) {
2967
const isExpress = folderName === "expressvars";
30-
const modifier = basename(ctx.file, ".css").startsWith("spectrum")
31-
? basename(ctx.file, ".css")
68+
const modifier = basename(file, ".css").startsWith("spectrum")
69+
? basename(file, ".css")
3270
.replace("spectrum-", "")
3371
.replace("global", "")
3472
: "";
3573

36-
plugins = [
74+
plugins.push(
3775
require("postcss-import")(),
3876
require("postcss-selector-replace")({
3977
before: [":root"],
@@ -55,8 +93,18 @@ module.exports = (ctx) => {
5593
}),
5694
]
5795
: []),
58-
];
59-
} else if (existsSync(pkgPath)) {
96+
);
97+
} else if (folderName && folderName === "tokens") {
98+
await postcssrc({
99+
cwd: resolve(componentPath, folderName),
100+
env: process.env.NODE_ENV ?? "development",
101+
from: ctx.from ?? file,
102+
to: ctx.to ?? file,
103+
}).then((result) => {
104+
if (!result?.plugins) return;
105+
plugins.push(...result.plugins);
106+
});
107+
} else if (pkgPath && existsSync(pkgPath)) {
60108
/**
61109
* If a path has a package.json, we can assume it's a component and
62110
* we want to leverage the correct plugins for it.
@@ -76,13 +124,38 @@ module.exports = (ctx) => {
76124
if (
77125
deps.includes("@spectrum-css/vars")
78126
) {
79-
plugins.push(...legacyBuilder.processors);
127+
await postcssrc({
128+
cwd: resolve(componentPath, folderName),
129+
env: process.env.NODE_ENV ?? "development",
130+
from: ctx.from ?? file,
131+
to: ctx.to ?? file,
132+
}, legacyBuilder).then((result) => {
133+
if (!result?.plugins) return;
134+
plugins.push(...result.plugins);
135+
});
136+
} else if (ctx.file.split("/").includes("themes")) {
137+
await postcssrc({
138+
cwd: resolve(componentPath, folderName),
139+
env: process.env.NODE_ENV ?? "development",
140+
from: ctx.from ?? file,
141+
to: ctx.to ?? file,
142+
splitinatorOptions: {
143+
noSelectors: false,
144+
},
145+
}, simpleBuilder).then((result) => {
146+
if (!result?.plugins) return;
147+
plugins.push(...result.plugins);
148+
});
80149
} else {
81-
if (ctx.file.split("/").includes("themes")) {
82-
plugins.push(...simpleBuilder.getProcessors({ noSelectors: false }));
83-
} else {
84-
plugins.push(...simpleBuilder.getProcessors());
85-
}
150+
await postcssrc({
151+
cwd: resolve(componentPath, folderName),
152+
env: process.env.NODE_ENV ?? "development",
153+
from: ctx.from ?? file,
154+
to: ctx.to ?? file,
155+
}, simpleBuilder).then((result) => {
156+
if (!result?.plugins) return;
157+
plugins.push(...result.plugins);
158+
});
86159
}
87160
}
88161

.storybook/project.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@
77
"{projectRoot}/*.{js,html}"
88
]
99
},
10-
"implicitDependencies": [
11-
"@spectrum-css/*",
12-
"!@spectrum-css/generator",
13-
"!@spectrum-css/bundle-builder",
14-
"!@spectrum-css/component-builder",
15-
"!@spectrum-css/component-builder-simple"
16-
],
1710
"targets": {
1811
"clean": {
19-
"cache": true,
2012
"inputs": [
2113
"{projectRoot}/storybook-static",
2214
{ "externalDependencies": ["rimraf"] }
@@ -31,8 +23,13 @@
3123
}
3224
},
3325
"build": {
34-
"cache": true,
35-
"dependsOn": ["^build"],
26+
"dependsOn": [
27+
"^build",
28+
{
29+
"target": "build",
30+
"projects": "ui-icons"
31+
}
32+
],
3633
"inputs": [
3734
"{projectRoot}/assets",
3835
"{projectRoot}/decorators",
@@ -58,7 +55,13 @@
5855
},
5956
"start": {
6057
"cache": true,
61-
"dependsOn": ["^build"],
58+
"dependsOn": [
59+
"^build",
60+
{
61+
"target": "build",
62+
"projects": "ui-icons"
63+
}
64+
],
6265
"inputs": [
6366
"{projectRoot}/assets",
6467
"{projectRoot}/decorators",

components/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Each component has the following files:
1313
- `themes/*.css` - The theme-specific styles for the component.
1414
- `stories/*.stories.js` and `stories/template.js` - The storybook assets for rendering components in the Storybook tool and eventually to be used for visual regression testing.
1515

16-
See [documentation generation](/tools/bundle-builder/docs/README.md) documentation for more information on the properties available within the `.yml` files.
17-
1816
## Editing an existing component
1917

2018
1. Run `gulp dev` in the root of the project to begin developing.

components/accordion/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/accordion/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/accordion/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"@spectrum-css/icon": ">=4",
1919
"@spectrum-css/tokens": ">=13"
2020
},
21+
"devDependencies": {
22+
"@spectrum-css/component-builder-simple": "^5.0.0"
23+
},
2124
"publishConfig": {
2225
"access": "public"
2326
}

components/actionbar/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/actionbar/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/actionbar/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"@spectrum-css/popover": ">=6",
2222
"@spectrum-css/tokens": ">=13"
2323
},
24+
"devDependencies": {
25+
"@spectrum-css/component-builder-simple": "^5.0.0"
26+
},
2427
"publishConfig": {
2528
"access": "public"
2629
}

components/actionbutton/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/actionbutton/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/actionbutton/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
}
2525
},
2626
"devDependencies": {
27-
"@spectrum-css/commons": "^9.1.0"
27+
"@spectrum-css/commons": "^9.1.0",
28+
"@spectrum-css/component-builder-simple": "^5.0.0"
2829
},
2930
"publishConfig": {
3031
"access": "public"

components/actiongroup/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/actiongroup/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/actiongroup/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"optional": true
2424
}
2525
},
26+
"devDependencies": {
27+
"@spectrum-css/component-builder-simple": "^5.0.0"
28+
},
2629
"publishConfig": {
2730
"access": "public"
2831
}

components/actionmenu/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/actionmenu/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/actionmenu/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"@spectrum-css/popover": ">=6",
2222
"@spectrum-css/tokens": ">=13"
2323
},
24+
"devDependencies": {
25+
"@spectrum-css/component-builder-simple": "^5.0.0"
26+
},
2427
"publishConfig": {
2528
"access": "public"
2629
}

components/alertbanner/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/alertbanner/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/alertbanner/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"optional": true
2727
}
2828
},
29+
"devDependencies": {
30+
"@spectrum-css/component-builder-simple": "^5.0.0"
31+
},
2932
"publishConfig": {
3033
"access": "public"
3134
}

components/alertdialog/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/alertdialog/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/alertdialog/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"optional": true
3131
}
3232
},
33+
"devDependencies": {
34+
"@spectrum-css/component-builder-simple": "^5.0.0"
35+
},
3336
"publishConfig": {
3437
"access": "public"
3538
}

components/asset/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/asset/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder");
2+
3+
builder.default({ cwd: __dirname });

components/asset/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"peerDependencies": {
1818
"@spectrum-css/vars": ">=9"
1919
},
20+
"devDependencies": {
21+
"@spectrum-css/component-builder": "^6.0.0"
22+
},
2023
"publishConfig": {
2124
"access": "public"
2225
}

components/assetcard/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/assetcard/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/assetcard/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"optional": true
2424
}
2525
},
26+
"devDependencies": {
27+
"@spectrum-css/component-builder-simple": "^5.0.0"
28+
},
2629
"publishConfig": {
2730
"access": "public"
2831
}

components/assetlist/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/assetlist/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

components/assetlist/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"optional": true
2828
}
2929
},
30+
"devDependencies": {
31+
"@spectrum-css/component-builder-simple": "^5.0.0"
32+
},
3033
"publishConfig": {
3134
"access": "public"
3235
}

components/avatar/gulpfile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/avatar/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const builder = require("@spectrum-css/component-builder-simple");
2+
3+
builder.default({ cwd: __dirname });

0 commit comments

Comments
 (0)