Skip to content

Commit 15bb021

Browse files
committed
feat: pull out dev task from bundle-builder
1 parent 6f58292 commit 15bb021

File tree

220 files changed

+4699
-8040
lines changed

Some content is hidden

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

220 files changed

+4699
-8040
lines changed

.storybook/postcss.config.js

Lines changed: 80 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,68 @@ OF ANY KIND, either express or implied. See the License for the specific languag
1010
governing permissions and limitations under the License.
1111
*/
1212

13-
const { resolve, basename } = require("path");
13+
const { resolve, basename, dirname } = require("path");
1414
const { existsSync } = require("fs");
1515

1616
const warnCleaner = require("postcss-warn-cleaner");
1717

18-
const simpleBuilder = path.dirname(
19-
require.resolve("@spectrum-css/component-builder-simple")
20-
);
21-
const legacyBuilder = path.dirname(
22-
require.resolve("@spectrum-css/component-builder")
23-
);
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");
23+
24+
const legacyBuilder = dirname(
25+
require.resolve("@spectrum-css/component-builder", {
26+
paths: [__dirname, resolve(__dirname, "../")],
27+
})
28+
) ?? resolve(__dirname, "../tools/component-builder");
2429

2530
const postcssrc = require("postcss-load-config");
2631

27-
/**
28-
* Determines the package name from a file path
29-
* @param {string} filePath
30-
* @returns {string}
31-
*/
32-
function getPackageFromPath(filePath) {
33-
return filePath.match(`(components|@spectrum-css)\/(.*?)\/`)?.[2];
34-
}
35-
36-
module.exports = (ctx) => {
37-
let plugins = [];
38-
const componentPath = resolve(__dirname, "../components");
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 = [];
55+
3956
/** @todo put together a more robust fallback determination */
40-
const folderName = getPackageFromPath(ctx.file) ?? "tokens";
41-
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");
4261

4362
/**
4463
* For our token libraries, include a little extra parsing to allow duplicate
4564
* token values to exist in parallel and be toggled using args in storybook.
4665
*/
47-
if (["expressvars", "vars", "tokens"].includes(folderName)) {
66+
if (folderName && ["expressvars", "vars"].includes(folderName)) {
4867
const isExpress = folderName === "expressvars";
49-
const modifier = basename(ctx.file, ".css").startsWith("spectrum")
50-
? basename(ctx.file, ".css")
68+
const modifier = basename(file, ".css").startsWith("spectrum")
69+
? basename(file, ".css")
5170
.replace("spectrum-", "")
5271
.replace("global", "")
5372
: "";
5473

55-
plugins = [
74+
plugins.push(
5675
require("postcss-import")(),
5776
require("postcss-selector-replace")({
5877
before: [":root"],
@@ -74,8 +93,18 @@ module.exports = (ctx) => {
7493
}),
7594
]
7695
: []),
77-
];
78-
} 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)) {
79108
/**
80109
* If a path has a package.json, we can assume it's a component and
81110
* we want to leverage the correct plugins for it.
@@ -92,36 +121,42 @@ module.exports = (ctx) => {
92121
...Object.keys(devDependencies),
93122
])];
94123

95-
let processors = [];
96124
if (
97125
deps.includes("@spectrum-css/vars")
98126
) {
99-
processors = postcssrc({
127+
await postcssrc({
100128
cwd: resolve(componentPath, folderName),
101-
env: process.env.NODE_ENV || "development",
102-
from: ctx.file,
103-
to: ctx.file,
104-
}, legacyBuilder).then((result) => result.plugins);
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+
});
105136
} else if (ctx.file.split("/").includes("themes")) {
106-
processors = postcssrc({
137+
await postcssrc({
107138
cwd: resolve(componentPath, folderName),
108-
env: process.env.NODE_ENV || "development",
109-
from: ctx.file,
110-
to: ctx.file,
139+
env: process.env.NODE_ENV ?? "development",
140+
from: ctx.from ?? file,
141+
to: ctx.to ?? file,
111142
splitinatorOptions: {
112143
noSelectors: false,
113144
},
114-
}, simpleBuilder).then((result) => result.plugins);
145+
}, simpleBuilder).then((result) => {
146+
if (!result?.plugins) return;
147+
plugins.push(...result.plugins);
148+
});
115149
} else {
116-
processors = postcssrc({
150+
await postcssrc({
117151
cwd: resolve(componentPath, folderName),
118-
env: process.env.NODE_ENV || "development",
119-
from: ctx.file,
120-
to: ctx.file,
121-
}, simpleBuilder).then((result) => result.plugins);
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+
});
122159
}
123-
124-
plugins.push(...processors);
125160
}
126161

127162
/**

.storybook/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"implicitDependencies": [
1111
"@spectrum-css/*",
1212
"!@spectrum-css/generator",
13-
"!@spectrum-css/bundle-builder",
1413
"!@spectrum-css/component-builder",
1514
"!@spectrum-css/component-builder-simple"
1615
],

components/README.md

Lines changed: 0 additions & 2 deletions
File renamed without changes.

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": "^4.1.0"
23+
},
2124
"publishConfig": {
2225
"access": "public"
2326
}
File renamed without changes.

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": "^4.1.0"
26+
},
2427
"publishConfig": {
2528
"access": "public"
2629
}

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": "^4.1.0"
2829
},
2930
"publishConfig": {
3031
"access": "public"
File renamed without changes.

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": "^4.1.0"
28+
},
2629
"publishConfig": {
2730
"access": "public"
2831
}
File renamed without changes.

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": "^4.1.0"
26+
},
2427
"publishConfig": {
2528
"access": "public"
2629
}
File renamed without changes.

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": "^4.1.0"
31+
},
2932
"publishConfig": {
3033
"access": "public"
3134
}
File renamed without changes.

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": "^4.1.0"
35+
},
3336
"publishConfig": {
3437
"access": "public"
3538
}
File renamed without changes.

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": "^5.1.0"
22+
},
2023
"publishConfig": {
2124
"access": "public"
2225
}
File renamed without changes.

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": "^4.1.0"
28+
},
2629
"publishConfig": {
2730
"access": "public"
2831
}
File renamed without changes.

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": "^4.1.0"
32+
},
3033
"publishConfig": {
3134
"access": "public"
3235
}
File renamed without changes.

components/avatar/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/tokens": ">=13"
1919
},
20+
"devDependencies": {
21+
"@spectrum-css/component-builder-simple": "^4.1.0"
22+
},
2023
"publishConfig": {
2124
"access": "public"
2225
}
File renamed without changes.

components/badge/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": "^4.1.0"
28+
},
2629
"publishConfig": {
2730
"access": "public"
2831
}
File renamed without changes.

components/breadcrumb/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": "^4.1.0"
32+
},
3033
"publishConfig": {
3134
"access": "public"
3235
}
File renamed without changes.

components/button/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": "^4.1.0"
2829
},
2930
"publishConfig": {
3031
"access": "public"
File renamed without changes.

components/buttongroup/package.json

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

components/calendar/package.json

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

components/card/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
"optional": true
4343
}
4444
},
45+
"devDependencies": {
46+
"@spectrum-css/component-builder-simple": "^4.1.0"
47+
},
4548
"publishConfig": {
4649
"access": "public"
4750
}
File renamed without changes.

components/checkbox/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": "^4.1.0"
23+
},
2124
"publishConfig": {
2225
"access": "public"
2326
}
File renamed without changes.

components/clearbutton/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": "^4.1.0"
23+
},
2124
"publishConfig": {
2225
"access": "public"
2326
}
File renamed without changes.

components/closebutton/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"@spectrum-css/tokens": ">=13"
2020
},
2121
"devDependencies": {
22-
"@spectrum-css/commons": "^9.1.0"
22+
"@spectrum-css/commons": "^9.1.0",
23+
"@spectrum-css/component-builder-simple": "^4.1.0"
2324
},
2425
"publishConfig": {
2526
"access": "public"

0 commit comments

Comments
 (0)