diff --git a/.stylelintrc.js b/.stylelintrc.js index 942c2b8ea47..d093b3fb8d9 100644 --- a/.stylelintrc.js +++ b/.stylelintrc.js @@ -1,6 +1,25 @@ +const fs = require('fs'); const path = require('path'); -const {tokenList} = require('./build/cjs/token-list'); +const tokenGroupsDir = path.join(__dirname, './src/tokens/token-groups'); + +/** + * Allowed Polaris token custom properties. + * + * Result: ['--p-background', '--p-text', etc...] + */ +const polarisTokenCustomProperties = Array.from( + new Set( + fs + .readdirSync(tokenGroupsDir) + .map((file) => { + const tokenGroup = require(path.join(tokenGroupsDir, file)); + + return Object.keys(tokenGroup).map((token) => `--p-${token}`); + }) + .flat(), + ), +); /** * Allowed custom property names in Polaris component styles. @@ -19,7 +38,10 @@ module.exports = { polarisComponentCustomProperties, ], allowedValues: { - '/.+/': [polarisComponentCustomProperties, ...tokenList], + '/.+/': [ + polarisComponentCustomProperties, + ...polarisTokenCustomProperties, + ], }, }, }, diff --git a/loom.config.ts b/loom.config.ts index 7dddb0b1a02..b4a4bfff0df 100644 --- a/loom.config.ts +++ b/loom.config.ts @@ -27,7 +27,6 @@ import type {} from '@shopify/loom-plugin-jest'; // eslint-disable-next-line import/no-default-export export default createPackage((pkg) => { pkg.entry({root: './src/index.ts'}); - pkg.entry({name: 'token-list', root: './src/token-list.ts'}); pkg.use( buildLibrary({ rootEntrypoints: false, diff --git a/src/components/Frame/README.md b/src/components/Frame/README.md index 7f20a6d1b43..19103632fca 100644 --- a/src/components/Frame/README.md +++ b/src/components/Frame/README.md @@ -693,7 +693,7 @@ function FrameExample() { > Global ribbon diff --git a/src/token-list.ts b/src/token-list.ts deleted file mode 100644 index e3418437c99..00000000000 --- a/src/token-list.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {tokens, TokenGroup, ColorSchemes} from './tokens'; - -function getPolarisCustomProperties(tokens: TokenGroup) { - return Object.keys(tokens).map((token) => `--p-${token}`); -} - -/** - * Allowed Polaris token custom properties. - * - * Result: ['--p-background', '--p-text', etc...] - */ -export const tokenList = Array.from( - new Set( - Object.entries(tokens) - .map((entry) => { - const [tokenGroupName, tokenGroupOrColorSchemes] = entry as [ - keyof typeof tokens, - typeof tokens[keyof typeof tokens], - ]; - - if (tokenGroupName === 'colorSchemes') { - const colorSchemes = tokenGroupOrColorSchemes as ColorSchemes; - - return Object.values(colorSchemes).map((tokenGroup) => - getPolarisCustomProperties(tokenGroup), - ); - } else { - const tokenGroup = tokenGroupOrColorSchemes as TokenGroup; - - return getPolarisCustomProperties(tokenGroup); - } - }) - .flat(Infinity), - ), -);