Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate build of modules to Rollup. #892

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ next-app/build
next-app/.vercel
next-app/npm-debug.log*
next-app/yarn-debug.log*
next-app/yarn-error.log*
next-app/yarn-error.log*

# autogenerated .tsconfig.json
.tsconfig.json
19 changes: 4 additions & 15 deletions app/.config/constants.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
const path = require("path");
const { getPkgFoldersRegexMatcher } = require("./utils/packageUtils");
const { getBabelProcessedFolders } = require("./utils/packageUtils");
const { normSlashes } = require("./utils/configUtils");
const escapeForRegex = require("escape-string-regexp");

const makeAbsolute = pathStr => path.resolve(UUI_ROOT, pathStr)

/** Assumption: the cwd is ./app/ folder. */
const UUI_ROOT = path.resolve(normSlashes('../'));

/**
* Folders which babel should include from each module
* @type {string[]}
*/
const PKG_FOLDERS_BABEL_INCLUDED = ['']
/**
* Folders which babel should exclude from each module
* @type {string[]}
*/
const PKG_FOLDERS_BABEL_EXCLUDED = ['build', 'node_modules']
//
const BABEL_INCLUDED_REGEXP = getPkgFoldersRegexMatcher({ uuiRoot: UUI_ROOT, folders: PKG_FOLDERS_BABEL_INCLUDED })
const BABEL_EXCLUDED_REGEXP = getPkgFoldersRegexMatcher({ uuiRoot: UUI_ROOT, folders: PKG_FOLDERS_BABEL_EXCLUDED })
const BABEL_INCLUDED_REGEXP = getBabelProcessedFolders({ uuiRoot: UUI_ROOT, isIncluded: true });
const BABEL_EXCLUDED_REGEXP = getBabelProcessedFolders({ uuiRoot: UUI_ROOT, isIncluded: false });

const CSS_URL_ROOT_PATH = makeAbsolute(normSlashes('app/public'));

// ignore all node_modules unless their names start with "@epam"
Expand Down
48 changes: 35 additions & 13 deletions app/.config/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@ const FileLoader = require.resolve("file-loader");
module.exports = function uuiConfig() {
return {
eslint: { enable: false }, // EsLint is disabled as of now, but it would be enabled in the future.
webpack: {
configure: configureWebpack,
webpack: { configure: configureWebpack },
devServer: config => {
return config;
},
devServer: configureDevServer,
};
};

function configureDevServer(config) {
return config;
}

function configureWebpack(config) {
function configureWebpack(config, { paths }) {
// reason: no such use case in UUI.
removeRuleByTestAttr(config, /\.module\.css$/);
// reason: .sass files are always modules in UUI
removeRuleByTestAttr(config, /\.(scss|sass)$/);
// reason: all .css files are not modules in UUI
changeRuleByTestAttr(config, /\.css$/, r => { delete r.exclude; return r; })
changeRuleByTestAttr(config, /\.css$/, r => { delete r.exclude; return r; });

/**
* Reason: bug in vfile package which only reproduced in webpack 5.
Expand All @@ -39,8 +35,8 @@ function configureWebpack(config) {
*/
addRule(config, {
test: VFILE_SPECIAL_CASE_REGEX,
use: [{ loader: require.resolve('imports-loader'), options: { type: 'commonjs', imports: ['single process/browser process'] } }],
})
use: [{ loader: require.resolve("imports-loader"), options: { type: "commonjs", imports: ["single process/browser process"] } }],
});
/** Use older version of @svgr/webpack as a workaround for https://github.com/facebook/create-react-app/issues/11770
* Use older version of file-loader as a workaround for https://github.com/gregberge/svgr/issues/367
* related bug: https://github.com/gregberge/svgr/issues/727
Expand All @@ -56,9 +52,13 @@ function configureWebpack(config) {

/**
* This is Babel for our source files. We need to include sources of all our modules, not only "app/src".
* TODO: should be applied only for dev, i.e. the production build should use "./build" folder of modules instead of their sources.
*/
changeRuleByTestAttr(config, /\.(js|mjs|jsx|ts|tsx)$/, r => Object.assign(r, { include: BABEL_INCLUDED_REGEXP, exclude: BABEL_EXCLUDED_REGEXP }));
changeRuleByTestAttr(config, /\.(js|mjs|jsx|ts|tsx)$/, r => {
const include = isUseBuildFolderOfDeps() ? BABEL_INCLUDED_REGEXP.BUILD_FOLDERS : BABEL_INCLUDED_REGEXP.DEFAULT;
const exclude = isUseBuildFolderOfDeps() ? BABEL_EXCLUDED_REGEXP.BUILD_FOLDERS : BABEL_EXCLUDED_REGEXP.DEFAULT;
return Object.assign(r, { include, exclude });
});

// Fix for the issue when some modules have no source maps. see this discussion for details https://github.com/facebook/create-react-app/discussions/11767
changeRuleByTestAttr(config, /\.(js|mjs|jsx|ts|tsx|css)$/, r =>
Object.assign(r, { exclude: [ r.exclude, VFILE_SPECIAL_CASE_REGEX, ...LIBS_WITHOUT_SOURCE_MAPS ] }));
Expand Down Expand Up @@ -86,5 +86,27 @@ function configureWebpack(config) {
* we need to get rid of it in the future.
* */
config.resolve.alias.path = "path-browserify";
if (isUseBuildFolderOfDeps()) {
config.resolve.mainFields = ["epam:uui:main", "browser", "module", "main"];
}
return config;
}

function isUseBuildFolderOfDeps() {
/**
* TODO: need to change the approach to process "docs". I.e. get rid of "require.context" and use explicit imports instead.
* Known places:
* app/src/common/docs/ComponentEditor.tsx
* app/src/common/docs/DocExample.tsx
* epam-assets/icons/index.ts
* epam-assets/icons/legacy/index.ts
* epam-assets/icons/loaders/index.ts
* epam-promo/index.docs.ts
* loveship/index.docs.ts
* uui/index.docs.ts
*
* @type {boolean}
*/
//return !!process.argv.find(a => a === '--use-build-folder-of-deps');
return false;
}
49 changes: 42 additions & 7 deletions app/.config/utils/packageUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,51 @@ function readPackages({ uuiRoot }) {
*/
function getPkgFoldersRegexMatcher({ uuiRoot, folders }) {
const pkgs = readPackages({ uuiRoot });
return pkgs.reduce((acc, p) => {
folders.forEach(f => {
const e = escapeForRegex(path.join(path.sep, p, f))
acc.push(new RegExp(e))
})
return acc
return pkgs.reduce((acc, pkg) => {
return acc.concat(getSinglePkgFolderRegexMatcher({ pkg, folders }))
}, [])
}

function getSinglePkgFolderRegexMatcher({ pkg, folders }) {
const acc = [];
folders(pkg).forEach(f => {
const e = escapeForRegex(path.join(path.sep, pkg, f))
acc.push(new RegExp(e))
})
return acc;
}
function getBabelProcessedFolders({ uuiRoot, isIncluded }) {
/**
* Folders which babel should include from each module
*/
const PKG_FOLDERS_BABEL_INCLUDED = ['']
const PKG_FOLDERS_BABEL_INCLUDED_BUILD = ['build', 'assets']
/**
* Folders which babel should exclude from each module
*/
const PKG_FOLDERS_BABEL_EXCLUDED = ['build', 'node_modules']
const PKG_FOLDERS_BABEL_EXCLUDED_BUILD = ['node_modules']

const getFoldersFn = isUseBuildFolderOfDeps => pkg => {
if (isIncluded) {
if (isUseBuildFolderOfDeps) {
if (['app', 'epam-assets'].indexOf(pkg) !== -1) {
return PKG_FOLDERS_BABEL_INCLUDED
}
return PKG_FOLDERS_BABEL_INCLUDED_BUILD
}
return PKG_FOLDERS_BABEL_INCLUDED;
}
if (isUseBuildFolderOfDeps) {
return PKG_FOLDERS_BABEL_EXCLUDED_BUILD;
}
return PKG_FOLDERS_BABEL_EXCLUDED;
}
const DEFAULT = getPkgFoldersRegexMatcher({ uuiRoot, folders: getFoldersFn(false) });
const BUILD_FOLDERS = getPkgFoldersRegexMatcher({ uuiRoot, folders: getFoldersFn(true) });
return { DEFAULT, BUILD_FOLDERS }
}

module.exports = {
getPkgFoldersRegexMatcher,
getBabelProcessedFolders,
}
10 changes: 6 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "craco start",
"build": "craco build",
"server": "node ../server/app.js",
"analyze": "source-map-explorer 'build/static/js/*.js'"
"analyzer": "source-map-explorer 'build/static/**/*.js'"
},
"cracoConfig": "./.config/craco.config.js",
"eslintConfig": {
Expand Down Expand Up @@ -52,8 +52,7 @@
"react-measure": "2.5.2",
"react-router": "5.2.0",
"react-router-dom": "5.2.0",
"slate": "0.47.9",
"path-browserify": "1.0.1"
"slate": "0.47.9"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -91,6 +90,9 @@
"file-loader": "4.3.0",
"imports-loader": "4.0.1",
"escape-string-regexp": "1.0.5",
"react-scripts": "5.0.1"
"react-scripts": "5.0.1",
"process": "0.11.10",
"webpack-stats-plugin": "1.1.1",
"path-browserify": "1.0.1"
}
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module.exports = {
"presets": [
"react-app"
]
}
}
4 changes: 3 additions & 1 deletion draft-rte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"author": "EPAM",
"license": "MIT",
"main": "index.js",
"epam:uui:main": "build/index.js",
"typings": "index.d.ts",
"scripts": {
"build": "node ../uui-build/scripts/buildModule",
Expand All @@ -21,7 +22,8 @@
"draft-js-clear-formatting": "^1.0.0",
"draft-js-plugins-utils": "^2.0.2",
"immutable": "*",
"markdown-draft-js": "1.6.0"
"markdown-draft-js": "1.6.0",
"lodash": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.0.0",
Expand Down
4 changes: 2 additions & 2 deletions draft-rte/src/utils/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { convertFromHTML as draftConvertFromHTML, convertToHTML as draftConvertToHTML } from 'draft-convert';
import { ContentBlock, ContentState, convertToRaw, EditorState, RawDraftEntity, SelectionState } from 'draft-js';
import getContentStateFragment from 'draft-js/lib/getContentStateFragment';
import getContentStateFragment from 'draft-js/lib/getContentStateFragment.js';
import * as React from 'react';
import { Link } from '../decorators';

Expand Down Expand Up @@ -183,4 +183,4 @@ export function getEntityRange(editorState: EditorState): { startOffset: number,
}

return { startOffset: finalPrevOffset, endOffset: finalNextOffset };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dayjs, { Dayjs } from "dayjs";
import { RangeDatePickerValue, rangeDatePickerPresets, Day, IconContainer } from '@epam/uui-components';
import { Button, Text } from '../..';
import { ReactComponent as Point } from "../../../icons/radio-point.svg";
import isBetween from 'dayjs/plugin/isBetween';
import isBetween from 'dayjs/plugin/isBetween.js';
dayjs.extend(isBetween);

const getCustomDay = (day: Dayjs) => {
Expand Down
2 changes: 1 addition & 1 deletion epam-promo/components/inputs/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DropdownContainer } from '../overlays';
import { TextInput } from './TextInput';
import { TimePickerBody } from './TimePickerBody';
import css from './TimePicker.scss';
import customParseFormat from "dayjs/plugin/customParseFormat";
import customParseFormat from "dayjs/plugin/customParseFormat.js";
dayjs.extend(customParseFormat);

const defaultMode = EditMode.FORM;
Expand Down
1 change: 1 addition & 0 deletions epam-promo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "EPAM",
"license": "MIT",
"main": "index.js",
"epam:uui:main": "build/index.js",
"typings": "index.d.ts",
"scripts": {
"build": "node ../uui-build/scripts/buildModule",
Expand Down
1 change: 1 addition & 0 deletions extra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "EPAM",
"license": "MIT",
"main": "index.js",
"epam:uui:main": "build/index.js",
"typings": "index.d.ts",
"scripts": {
"build": "node ../uui-build/scripts/buildModule"
Expand Down
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
// ...tsjPreset.transform,
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
// "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/ts-jest",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/uui-build/config/jest/fileTransform.js",
"^.+\\.css$": "<rootDir>/uui-build/config/jest/cssTransform.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/uui-build/jest/fileTransform.js",
"^.+\\.css$": "<rootDir>/uui-build/jest/cssTransform.js",
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
Expand All @@ -41,7 +41,7 @@ module.exports = {
],
"moduleNameMapper": {
"^react-native$": "react-native-web",
"^.+\\.(sass|scss|less)$": "<rootDir>/uui-build/config/jest/cssModuleTransform.js",
"^.+\\.(sass|scss|less)$": "<rootDir>/uui-build/jest/cssModuleTransform.js",
"@epam/test-utils": "<rootDir>/test-utils",
"@epam/uui-core": "<rootDir>/uui-core",
"\\.svg": "<rootDir>/test-utils/mocks/svgrMock.js"
Expand Down
1 change: 1 addition & 0 deletions loveship/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "EPAM",
"license": "MIT",
"main": "index.js",
"epam:uui:main": "build/index.js",
"typings": "index.d.ts",
"scripts": {
"build": "node ../uui-build/scripts/buildModule",
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
"private": true,
"version": "2.1.434",
"description": "",
"main": "index.js",
"scripts": {
"analyzer": "webpack-bundle-analyzer app/build/bundle-stats.json",
"analyzer": "cd app && yarn analyzer",
"postinstall": "cd server && yarn",
"test": "node uui-build/scripts/runTests.js",
"coverage": "yarn test --coverage",
"process-icons": "node uui-build/scripts/processIcons.js",
"start": "cd ./app && cross-env DEV=TRUE yarn start",
"start": "cd ./app && yarn start",
"next:dev": "cd ./next-app && yarn && node ../uui-build/scripts/runNextApp.js && yarn dev",
"build": "cd ./app && yarn build --stats",
"build-dev": "cd ./app && yarn build-dev",
"build": "cd ./app && yarn build",
"start-server": "cd ./app && yarn server",
"lint": "npx tslint -p ./tsconfig.json -e node_modules",
"style-lint": "npx stylelint \"**/*.{scss,less}\"\n",
"format": "npx tslint -p ./tsconfig.json --fix -e node_modules",
"copy-to-template": "node uui-build/scripts/copyToTemplate",
"build-server-helpers": "npx tsc uui-core/src/data/querying/getFilterPredicate.ts --outDir ./server/helpers/",
"build-server-helpers": "tsc --esModuleInterop uui-core/src/data/querying/getFilterPredicate.ts --outDir ./server/helpers/",
"generate-components-api": "cd uui-build && yarn generate-components-api",
"transform-tokens": "tsc --esModuleInterop uui-build/tokens-converter/index.ts && node uui-build/tokens-converter",
"release": "lerna publish --force-publish",
Expand Down
4 changes: 2 additions & 2 deletions server/helpers/getFilterPredicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
exports.__esModule = true;
exports.getFilterPredicate = exports.simplifyPredicates = void 0;
var dayjs_1 = __importDefault(require("dayjs"));
var isSameOrBefore_1 = __importDefault(require("dayjs/plugin/isSameOrBefore"));
var isSameOrAfter_1 = __importDefault(require("dayjs/plugin/isSameOrAfter"));
var isSameOrBefore_1 = __importDefault(require("dayjs/plugin/isSameOrBefore.js"));
var isSameOrAfter_1 = __importDefault(require("dayjs/plugin/isSameOrAfter.js"));
dayjs_1["default"].extend(isSameOrBefore_1["default"]);
dayjs_1["default"].extend(isSameOrAfter_1["default"]);
function simplifyPredicates(filter) {
Expand Down
Loading