Skip to content

Commit 593260e

Browse files
committed
Convert processLitCSSPlugin to ESM everywhere + use the new module in Storybook + cleanup old CommonJS custom properties
1 parent c49322f commit 593260e

File tree

6 files changed

+11
-87
lines changed

6 files changed

+11
-87
lines changed

.storybook/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const tsconfigPaths = require('vite-tsconfig-paths').default;
2-
const processLitCSSPlugin =
3-
require('../scripts/vite.processLitCSSPlugin').default;
42

53
module.exports = {
64
stories: ['../packages/**/*.story.ts'],
@@ -13,6 +11,9 @@ module.exports = {
1311
async viteFinal(config, { configType }) {
1412
// customize the Vite config here
1513

14+
const processLitCSSPlugin = (
15+
await import('../scripts/processLitCSSPlugin.mjs')
16+
).default;
1617
config.plugins.push(processLitCSSPlugin());
1718

1819
if (configType === 'DEVELOPMENT') {

packages/rollup-package.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { readPackageJson } from '../scripts/modify-pkgjson.mjs';
55
import rollupPostcss from 'rollup-plugin-postcss';
66
import postcssCustomPropertiesFallback from '../scripts/postcss-custom-properties-fallback/plugin.mjs';
77
import path from 'path';
8-
import processLitCSSPlugin from '../scripts/rollup.processLitCSSPlugin.mjs';
8+
import processLitCSSPlugin from '../scripts/processLitCSSPlugin.mjs';
99
import importCss from 'rollup-plugin-import-css';
1010

1111
// @ts-ignore-start

packages/uui-css/scripts/cache-custom-properties.mjs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ export const CacheCustomProperties = async masterCSSPath => {
3535

3636
let json = JSON.stringify(fileData);
3737

38-
try {
39-
await fs.writeFile(
40-
'./custom-properties.cjs',
41-
`module.exports = ${json};`,
42-
'utf8'
43-
);
44-
} catch (err) {
45-
console.error(err);
46-
}
47-
48-
// Second file for ESM, TODO: fix so we can use the same file in both cases.
4938
try {
5039
await fs.writeFile(
5140
'./custom-properties.module.js',

scripts/postcss-custom-properties-fallback/plugin.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const customPropertiesRegExp = /(^|[^\w-])var\([\W\w]+\)/; // var\([\W\w]+,[\W\w
88

99
const isTransformableDecl = decl => customPropertiesRegExp.test(decl.value);
1010

11-
import { nodeToString } from 'postcss-values-parser'; // eslint-disable-next-line no-empty-pattern
11+
import * as postcssValuesParser from 'postcss-values-parser'; // eslint-disable-next-line no-empty-pattern
1212

1313
export default opts => ({
1414
postcssPlugin: 'postcss-custom-properties-fallback',
@@ -53,7 +53,9 @@ export default opts => ({
5353
{
5454
type: 'word',
5555
value: fallback
56-
.map(fallbackNode => nodeToString(fallbackNode))
56+
.map(fallbackNode =>
57+
postcssValuesParser.nodeToString(fallbackNode)
58+
)
5759
.join(' '),
5860
}
5961
);

scripts/rollup.processLitCSSPlugin.mjs renamed to scripts/processLitCSSPlugin.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
import { createFilter } from '@rollup/pluginutils';
12
import postcss from 'postcss';
23
import syntax from 'postcss-jsx';
3-
import postcssCustomPropertiesFallback from './postcss-custom-properties-fallback/plugin.mjs';
4-
import { createFilter } from '@rollup/pluginutils';
54
import postcssConfig from 'postcss-load-config';
65

7-
// @ts-ignore-start
8-
// eslint-disable-next-line -- // @typescript-eslint/ban-ts-comment // @ts-ignore
9-
import customProperties from '../packages/uui-css/custom-properties.module'; // eslint-disable-line
10-
// @ts-ignore-end
6+
import customProperties from '../packages/uui-css/custom-properties.module.js';
7+
import postcssCustomPropertiesFallback from './postcss-custom-properties-fallback/plugin.mjs';
118

129
const options = {
1310
include: ['**/index.ts', '**/uui-*.ts', '**/*Mixin.ts', '**/*.styles.ts'],

scripts/vite.processLitCSSPlugin.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)