Skip to content

Commit

Permalink
fix(packages/vkui): add missed "type": "module"
Browse files Browse the repository at this point in the history
Это повлекло за собой следующие изменения:

- ~`packages/vkui/shared.config.js`~ – переименование в `.mjs` не удалось из-за **react-styleguidist**, который не умеет в **ESM**, поэтому перенёс в корневой `shared.js`, который используется только в папке `/styleguide`
- `stylelint.config.mjs` – заменил импорты из `shared.config.js` на объявление путей прямо в файле
- `packages/vkui/cssm/postcss.config.js` → `packages/vkui/cssm/postcss.config.cjs` – заменил импорты из `shared.config.js` на объявление путей прямо в файле
- `packages/vkui/scripts/postcss.js` → `packages/vkui/scripts/postcss.cjs` – заменил импорты из `shared.config.js` на объявление путей прямо в файле, а также перенёс объявления `VKUI_TOKENS_CSS` и `generateScopedName`
- `packages/vkui/tsconfig.json` – упростил `include`, а то было точечное определение файлов
- `packages/vkui/.eslintrc.js` → `packages/vkui/.eslintrc.cjs`
- `packages/vkui/rspack.styles.config.ts` → `packages/vkui/rspack.styles.config.mjs` – т.к. начал падать с ошибкой `ERR_UNKNOWN_FILE_EXTENSION`
  • Loading branch information
inomdzhon committed Nov 13, 2024
1 parent 933f11e commit 941138e
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 113 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { makePostcssPlugins } = require('../scripts/postcss');
const { makePostcssPlugins } = require('../scripts/postcss.cjs');

module.exports = () => {
const plugins = makePostcssPlugins({ isESNext: true, isVKUIPackageBuild: true });
Expand Down
3 changes: 2 additions & 1 deletion packages/vkui/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"version": "7.0.0-beta.1",
"name": "@vkontakte/vkui",
"description": "VKUI library",
Expand Down Expand Up @@ -54,7 +55,7 @@
"clear": "yarn run -T shx rm -rf dist/* || yarn run -T shx true",
"docker:clear-playwright-cache": "../../scripts/generate_env_docker.sh && docker compose --env-file=./.env.docker rm -f && docker volume rm vkui_package_vkui_playwright_cache",
"postcss": "yarn run -T cross-env NODE_ENV=production concurrently 'yarn:postcss:*'",
"postcss:bundle": "yarn run -T rspack --config rspack.styles.config.ts",
"postcss:bundle": "yarn run -T rspack --config rspack.styles.config.mjs",
"postcss:modules": "yarn run -T postcss './src/**/*.css' --base ./src --dir ./dist/cssm --config ./cssm",
"swc-base": "yarn run -T cross-env NODE_ENV=production swc src/ --config-file package.swcrc --extensions .tsx,.jsx,.ts,.js --strip-leading-paths",
"swc:es6": "yarn swc-base -d dist -s",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// @ts-check

import path from 'node:path';
import rspack, { type Configuration, type RspackPluginInstance } from '@rspack/core';
import rspack from '@rspack/core';
import browserslist from 'browserslist';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import { makePostcssPlugins } from './scripts/postcss';
import { makePostcssPlugins } from './scripts/postcss.cjs';

const rootDirectory = path.join(__dirname, '../../');
const rootDirectory = path.join(import.meta.dirname, '../../');
const browser = browserslist.readConfig(path.join(rootDirectory, '.browserslistrc'));

interface MakeCssRuleUseOptions {
/**
* Флаг для определения сборки css модулей
*/
isCssModulesFile?: boolean;
}

/**
* Конфигурация для css
*
* @param {Object} [options={}]
* @param {boolean} [options.isCssModulesFile=false] Флаг для определения сборки css модулей
*/
function makeCssRuleUse({ isCssModulesFile = false }: MakeCssRuleUseOptions = {}) {
function makeCssRuleUse({ isCssModulesFile = false } = {}) {
return [
{
loader: 'postcss-loader',
Expand All @@ -30,14 +27,15 @@ function makeCssRuleUse({ isCssModulesFile = false }: MakeCssRuleUseOptions = {}
];
}

const config: Configuration = {
/** @type {import('@rspack/cli').Configuration} */
const config = {
mode: 'production',
entry: {
vkui: ['./src/styles/themes.css', './src/index.ts'],
components: './src/index.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
path: path.resolve(import.meta.dirname, 'dist'),
filename: '[name].js.tmp',
cssFilename: '[name].css',
},
Expand Down Expand Up @@ -96,7 +94,7 @@ const config: Configuration = {
protectWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [],
cleanAfterEveryBuildPatterns: ['*.tmp', '*.tmp.*'],
}) as unknown as RspackPluginInstance,
}),
],
stats: {
all: false,
Expand All @@ -106,6 +104,7 @@ const config: Configuration = {
},
experiments: {
css: true,
outputModule: true,
},
};

Expand Down
5 changes: 2 additions & 3 deletions packages/vkui/scripts/generateCSSCustomMedias.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import fs from 'node:fs';
import path from 'path';
import ts from 'typescript';
import { PATHS } from '../shared.config.js';

const inputSourceFilePath = path.resolve(
import.meta.dirname,
PATHS.JS_BREAKPOINTS.replace(PATHS.ROOT_DIR, '../'),
'../src/lib/adaptivity/breakpoints.ts',
);

const outputSourceFilePath = path.resolve(
import.meta.dirname,
PATHS.CSS_CUSTOM_MEDIAS.replace(PATHS.ROOT_DIR, '../'),
'../src/styles/customMedias.generated.css',
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const postcssGapProperties = require('postcss-gap-properties');
const cssImport = require('postcss-import');
const postcssLogical = require('postcss-logical');
const cssModules = require('postcss-modules');
const { VKUI_PACKAGE, VKUI_TOKENS_CSS, generateScopedName } = require('../../../shared');

const rootDirectory = path.join(__dirname, '../../..');

Expand All @@ -33,11 +32,12 @@ function getMinimizerOptions(isVKUIPackageBuild = false) {
/**
* Конфигурация postcss плагинов
* @param {Object} config - Конфигурация.
* @param {boolean | undefined} config.isVKUIPackageBuild - Сборка пакета.
* @param {boolean | undefined} config.isProduction - Продакшн сборка.
* @param {boolean | undefined} config.isCssModulesFile - Сборка module.css файлов.
* @param {boolean | undefined} config.isESNext - Отдельная сборка cssm.
* @param {boolean | undefined} config.disableMinimizer - Отключает cssnano.
* @param {boolean} [config.isVKUIPackageBuild=false] Сборка пакета.
* @param {boolean} [config.isProduction=process.env.NODE_ENV === 'production'] Продакшн сборка.
* @param {boolean} [config.isCssModulesFile=false] Сборка module.css файлов.
* @param {boolean} [config.isESNext=false] Отдельная сборка cssm.
* @param {boolean} [config.isStorybook=process.env.SANDBOX === '.storybook'] Отдельная сборка cssm.
* @param {boolean} [config.disableMinimizer=false] Отключает cssnano.
* @returns {import('postcss').Plugin[]}
*/
function makePostcssPlugins({
Expand All @@ -53,16 +53,24 @@ function makePostcssPlugins({
cssImport(),

restructureVariable(
VKUI_TOKENS_CSS.map((pathSegment) => path.join(rootDirectory, pathSegment)),
[
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariables.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkBaseDark/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkIOS/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkIOSDark/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkCom/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkComDark/cssVars/declarations/onlyVariablesLocal.css',
].map((pathSegment) => path.join(rootDirectory, pathSegment)),
),

// Сбор данных для работы некоторых postcss плагинов
postcssGlobalData({
files: [
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariables.css',
VKUI_PACKAGE.PATHS.CSS_DYNAMIC_TOKENS,
VKUI_PACKAGE.PATHS.CSS_CONSTANTS,
VKUI_PACKAGE.PATHS.CSS_CUSTOM_MEDIAS,
'packages/vkui/src/styles/dynamicTokens.css',
'packages/vkui/src/styles/constants.css',
'packages/vkui/src/styles/customMedias.generated.css',
].map((pathSegment) => path.join(rootDirectory, pathSegment)),
}),

Expand All @@ -84,7 +92,7 @@ function makePostcssPlugins({
if (isVKUIPackageBuild && isCssModulesFile && !isESNext) {
plugins.push(
cssModules({
generateScopedName,
generateScopedName: 'vkui[folder]__[local]',
getJSON: () => void 0,
}),
);
Expand Down
42 changes: 0 additions & 42 deletions packages/vkui/shared.config.js

This file was deleted.

16 changes: 1 addition & 15 deletions packages/vkui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@
}
]
},
"include": [
"src/**/*.ts*",
"src/**/*.js",
".storybook/**/*.ts*",
"**/*.config.js",
"*.config.*.js",
"*.setup.js",
".eslintrc.js",
"playwright-ct.config.ts",
"playwright/index.tsx",
"scripts/*.js",
"scripts/*.mjs",
"./jest.*.ts",
"*.config.ts"
],
"include": ["*.ts*", "**/*.ts*", "*.js", "**/*.js", "*.mjs", "**/*.mjs", "*.cjs", "**/*.cjs"],
"files": ["./global.d.ts", "types/env.d.ts"]
}
43 changes: 26 additions & 17 deletions shared.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
const { VERSION, URLS, PATHS } = require('./packages/vkui/shared.config');
// Используется в папке styleguide/

module.exports = {
VKUI_PACKAGE: {
VERSION,
URLS,
PATHS,
},
const iconPkg = require('./node_modules/@vkontakte/icons/package.json');
const tokensPkg = require('./node_modules/@vkontakte/vkui-tokens/package.json');
const vkuiPgk = require('./packages/vkui/package.json');

const ROOT_DIR = 'packages/vkui';
const TS_CONFIG_FOR_DIST = `${ROOT_DIR}/tsconfig.dist.json`;
const SRC_DIR = `${ROOT_DIR}/src`;
const COMPONENTS_DIR = `${SRC_DIR}/components`;

VKUI_TOKENS_CSS: [
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariables.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkBaseDark/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkIOS/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkIOSDark/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkCom/cssVars/declarations/onlyVariablesLocal.css',
'./node_modules/@vkontakte/vkui-tokens/themes/vkComDark/cssVars/declarations/onlyVariablesLocal.css',
],
module.exports.VKUI_PACKAGE = {
VERSION: vkuiPgk.version,

generateScopedName: 'vkui[folder]__[local]',
URLS: {
REPOSITORY: vkuiPgk.repository.url.replace('.git', ''),
ISSUES: vkuiPgk.bugs,
HOMEPAGE: vkuiPgk.homepage,
NPM: 'https://www.npmjs.com/package/@vkontakte/vkui',
TOKENS: tokensPkg.homepage,
ICONS: iconPkg.homepage,
},

PATHS: {
ROOT_DIR,
SRC_DIR,
TS_CONFIG_FOR_DIST,
COMPONENTS_DIR,
},
};
14 changes: 7 additions & 7 deletions stylelint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import path from 'node:path';
import shared from './shared.js';

const { VKUI_PACKAGE } = shared;

const config = {
extends: ['stylelint-config-standard', '@vkontakte/stylelint-config'],
Expand Down Expand Up @@ -57,9 +54,9 @@ const config = {
true,
{
importFrom: [
path.join(import.meta.dirname, VKUI_PACKAGE.PATHS.CSS_CONSTANTS),
path.join(import.meta.dirname, VKUI_PACKAGE.PATHS.CSS_DYNAMIC_TOKENS),
path.join(import.meta.dirname, VKUI_PACKAGE.PATHS.CSS_MISSED_THEME_TOKENS),
path.join(import.meta.dirname, 'packages/vkui/src/styles/constants.css'),
path.join(import.meta.dirname, 'packages/vkui/src/styles/dynamicTokens.css'),
path.join(import.meta.dirname, 'packages/vkui/src/styles/missedThemeTokens.css'),
path.join(
import.meta.dirname,
'node_modules/@vkontakte/vkui-tokens/themes/vkBase/cssVars/declarations/index.css',
Expand All @@ -70,7 +67,10 @@ const config = {
'csstools/media-use-custom-media': [
'known',
{
importFrom: path.join(import.meta.dirname, VKUI_PACKAGE.PATHS.CSS_CUSTOM_MEDIAS),
importFrom: path.join(
import.meta.dirname,
'packages/vkui/src/styles/customMedias.generated.css',
),
},
],
'selector-pseudo-class-disallowed-list': ['global'],
Expand Down
2 changes: 1 addition & 1 deletion webpack.common.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const { makePostcssPlugins } = require('./packages/vkui/scripts/postcss');
const { makePostcssPlugins } = require('./packages/vkui/scripts/postcss.cjs');

const isProduction = process.env.NODE_ENV === 'production';

Expand Down

0 comments on commit 941138e

Please sign in to comment.