@@ -5,12 +5,26 @@ const warnCleaner = require("postcss-warn-cleaner");
5
5
const simpleBuilder = require ( "@spectrum-css/component-builder-simple/css/processors.js" ) ;
6
6
const legacyBuilder = require ( "@spectrum-css/component-builder/css/processors.js" ) ;
7
7
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
+ }
16
+
8
17
module . exports = ( ctx ) => {
9
18
let plugins = [ ] ;
10
19
const componentPath = resolve ( __dirname , "../components" ) ;
11
- const folderName = ctx . file . includes ( 'node_modules' ) ? relative ( resolve ( __dirname , "../../node_modules/@spectrum-css" ) , ctx . file ) ?. split ( sep ) ?. shift ( ) : relative ( componentPath , ctx . file ) . split ( "/" ) [ 0 ] ;
20
+ /** @todo put together a more robust fallback determination */
21
+ const folderName = getPackageFromPath ( ctx . file ) ?? "tokens" ;
12
22
const pkgPath = resolve ( componentPath , folderName , "package.json" ) ;
13
23
24
+ /**
25
+ * For our token libraries, include a little extra parsing to allow duplicate
26
+ * token values to exist in parallel and be toggled using args in storybook.
27
+ */
14
28
if ( [ "expressvars" , "vars" , "tokens" ] . includes ( folderName ) ) {
15
29
const isExpress = folderName === "expressvars" ;
16
30
const modifier = basename ( ctx . file , ".css" ) . startsWith ( "spectrum" )
@@ -43,6 +57,10 @@ module.exports = (ctx) => {
43
57
: [ ] ) ,
44
58
] ;
45
59
} else if ( existsSync ( pkgPath ) ) {
60
+ /**
61
+ * If a path has a package.json, we can assume it's a component and
62
+ * we want to leverage the correct plugins for it.
63
+ */
46
64
const { devDependencies } = require ( pkgPath ) ;
47
65
if (
48
66
Object . keys ( devDependencies ) . includes ( "@spectrum-css/component-builder" )
@@ -57,7 +75,9 @@ module.exports = (ctx) => {
57
75
}
58
76
}
59
77
60
- // For storybook, add a tool to suppress autoprefixer warnings
78
+ /**
79
+ * For storybook, add a tool to suppress unnecessary warnings
80
+ */
61
81
plugins . push (
62
82
warnCleaner ( {
63
83
ignoreFiles : "**/*.css" ,
0 commit comments