@socprime/master-configuration 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +7 -0
- package/.eslintrc.js +140 -0
- package/README.md +12 -0
- package/babel.config.js +16 -0
- package/package.json +45 -0
- package/stylelint.config.js +30 -0
- package/tsconfig.json +44 -0
- package/webpack.ts +133 -0
package/.editorconfig
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const { join } = require('path');
|
|
2
|
+
|
|
3
|
+
const tsConfigFile = require(join(__dirname, 'tsconfig.json'));
|
|
4
|
+
|
|
5
|
+
const extendAirBnBRules = [
|
|
6
|
+
'airbnb-base',
|
|
7
|
+
'airbnb/hooks',
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
const javascriptRules = {
|
|
11
|
+
'no-plusplus': 0,
|
|
12
|
+
'arrow-body-style': 0,
|
|
13
|
+
'no-nested-ternary': 0,
|
|
14
|
+
'no-await-in-loop': 1,
|
|
15
|
+
'no-param-reassign': 1,
|
|
16
|
+
'no-unused-vars': 1,
|
|
17
|
+
'no-undef': 0,
|
|
18
|
+
'no-shadow': 0,
|
|
19
|
+
'no-use-before-define': 0,
|
|
20
|
+
'global-require': 1,
|
|
21
|
+
'import/order': 0,
|
|
22
|
+
'import/prefer-default-export': 0,
|
|
23
|
+
'import/extensions': 0,
|
|
24
|
+
'import/no-extraneous-dependencies': 0,
|
|
25
|
+
'import/no-relative-packages': 0,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const html = [
|
|
29
|
+
{
|
|
30
|
+
files: ['*.html'],
|
|
31
|
+
parser: '@html-eslint/parser',
|
|
32
|
+
plugins: [
|
|
33
|
+
'@html-eslint',
|
|
34
|
+
'html',
|
|
35
|
+
],
|
|
36
|
+
extends: ['plugin:@html-eslint/recommended'],
|
|
37
|
+
rules: {
|
|
38
|
+
'@html-eslint/no-duplicate-id': 'error',
|
|
39
|
+
'@html-eslint/indent': ['error', 2],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const json = [
|
|
45
|
+
{
|
|
46
|
+
files: ['*.json'],
|
|
47
|
+
parser: 'jsonc-eslint-parser',
|
|
48
|
+
extends: [
|
|
49
|
+
'plugin:jsonc/all',
|
|
50
|
+
],
|
|
51
|
+
rules: {
|
|
52
|
+
'jsonc/indent': ['error', 2],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
files: ['tsconfig.json', 'package.json'],
|
|
57
|
+
rules: {
|
|
58
|
+
'jsonc/key-name-casing': 0,
|
|
59
|
+
'jsonc/sort-keys': 0,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const js = [
|
|
65
|
+
{
|
|
66
|
+
files: ['*.js', '*.jsx', '*.mjs'],
|
|
67
|
+
extends: [
|
|
68
|
+
...extendAirBnBRules,
|
|
69
|
+
],
|
|
70
|
+
parser: '@babel/eslint-parser',
|
|
71
|
+
rules: {
|
|
72
|
+
...javascriptRules,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
files: ['.eslintrc.js'],
|
|
77
|
+
rules: {
|
|
78
|
+
'import/no-dynamic-require': 0,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const typescript = [
|
|
84
|
+
{
|
|
85
|
+
files: ['*.ts', '*.tsx'],
|
|
86
|
+
parser: '@typescript-eslint/parser',
|
|
87
|
+
extends: [
|
|
88
|
+
...extendAirBnBRules,
|
|
89
|
+
'plugin:@typescript-eslint/recommended',
|
|
90
|
+
],
|
|
91
|
+
rules: {
|
|
92
|
+
...javascriptRules,
|
|
93
|
+
'@typescript-eslint/no-shadow': 1,
|
|
94
|
+
'@typescript-eslint/no-empty-function': 0,
|
|
95
|
+
'@typescript-eslint/ban-ts-comment': 0,
|
|
96
|
+
'@typescript-eslint/no-explicit-any': 1,
|
|
97
|
+
},
|
|
98
|
+
plugins: ['@typescript-eslint'],
|
|
99
|
+
settings: {
|
|
100
|
+
'import/resolver': {
|
|
101
|
+
node: {
|
|
102
|
+
extensions: ['.ts', '.tsx', '.d.ts'],
|
|
103
|
+
},
|
|
104
|
+
typescript: {
|
|
105
|
+
project: tsConfigFile,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
module.exports = {
|
|
113
|
+
root: true,
|
|
114
|
+
env: {
|
|
115
|
+
browser: true,
|
|
116
|
+
es2021: true,
|
|
117
|
+
jest: true,
|
|
118
|
+
node: true,
|
|
119
|
+
},
|
|
120
|
+
extends: [
|
|
121
|
+
'eslint:recommended',
|
|
122
|
+
],
|
|
123
|
+
parserOptions: {
|
|
124
|
+
ecmaVersion: 'latest',
|
|
125
|
+
sourceType: 'module',
|
|
126
|
+
},
|
|
127
|
+
ignorePatterns: [
|
|
128
|
+
'!.storybook',
|
|
129
|
+
'package-lock.json',
|
|
130
|
+
'node_modules',
|
|
131
|
+
'storybook-static',
|
|
132
|
+
'tmp'
|
|
133
|
+
],
|
|
134
|
+
overrides: [
|
|
135
|
+
...js,
|
|
136
|
+
...typescript,
|
|
137
|
+
...html,
|
|
138
|
+
...json,
|
|
139
|
+
],
|
|
140
|
+
};
|
package/README.md
ADDED
package/babel.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
sourceType: 'unambiguous',
|
|
3
|
+
presets: [
|
|
4
|
+
[
|
|
5
|
+
'@babel/preset-env',
|
|
6
|
+
{
|
|
7
|
+
targets: {
|
|
8
|
+
chrome: 100,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
'@babel/preset-typescript',
|
|
13
|
+
['@babel/preset-react', { runtime: 'automatic' }],
|
|
14
|
+
],
|
|
15
|
+
plugins: [],
|
|
16
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@socprime/master-configuration",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"author": "Pavel Nedzelskiy <pavlo.nedzelskyi@socprime.com>",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"stylelint": "npx stylelint \"**/*.{css,scss,sass}\" --allow-empty-input",
|
|
8
|
+
"test": "npx jest",
|
|
9
|
+
"eslint": "npx eslint --quiet ."
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@babel/core": "^7.23.0",
|
|
13
|
+
"@babel/eslint-parser": "^7.22.15",
|
|
14
|
+
"@babel/preset-env": "^7.22.20",
|
|
15
|
+
"@babel/preset-react": "^7.22.15",
|
|
16
|
+
"@babel/preset-typescript": "^7.23.0",
|
|
17
|
+
"@html-eslint/eslint-plugin": "^0.19.1",
|
|
18
|
+
"@html-eslint/parser": "^0.19.1",
|
|
19
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
21
|
+
"@typescript-eslint/parser": "^6.7.4",
|
|
22
|
+
"eslint": "^8.50.0",
|
|
23
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
24
|
+
"eslint-plugin-html": "^7.1.0",
|
|
25
|
+
"eslint-plugin-import": "^2.28.1",
|
|
26
|
+
"eslint-plugin-jsonc": "^2.9.0",
|
|
27
|
+
"eslint-plugin-local-rules": "^2.0.0",
|
|
28
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
29
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
30
|
+
"postcss": "^8.4.31",
|
|
31
|
+
"postcss-loader": "^7.3.3",
|
|
32
|
+
"postcss-preset-env": "^9.1.4",
|
|
33
|
+
"postcss-sass": "^0.5.0",
|
|
34
|
+
"react-refresh-typescript": "^2.0.9",
|
|
35
|
+
"stylelint": "^15.10.3",
|
|
36
|
+
"stylelint-config-sass-guidelines": "^10.0.0",
|
|
37
|
+
"stylelint-scss": "^5.2.1",
|
|
38
|
+
"terser-webpack-plugin": "^5.3.9",
|
|
39
|
+
"ts-loader": "^9.4.4",
|
|
40
|
+
"ts-node": "^10.9.1",
|
|
41
|
+
"typescript": "^5.2.2",
|
|
42
|
+
"webpack": "^5.88.2",
|
|
43
|
+
"webpack-cli": "^5.1.4"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: [
|
|
3
|
+
'stylelint-config-sass-guidelines',
|
|
4
|
+
],
|
|
5
|
+
ignoreFiles: [
|
|
6
|
+
'node_modules',
|
|
7
|
+
'tmp',
|
|
8
|
+
'**/*.md',
|
|
9
|
+
'**/*.html',
|
|
10
|
+
],
|
|
11
|
+
plugins: [
|
|
12
|
+
'stylelint-scss',
|
|
13
|
+
],
|
|
14
|
+
rules: {
|
|
15
|
+
indentation: 2,
|
|
16
|
+
'selector-max-id': 1,
|
|
17
|
+
'max-nesting-depth': 5,
|
|
18
|
+
},
|
|
19
|
+
overrides: [
|
|
20
|
+
{
|
|
21
|
+
files: ['*.sass', '**/*.sass'],
|
|
22
|
+
customSyntax: 'postcss-sass',
|
|
23
|
+
rules: {
|
|
24
|
+
'color-named': null,
|
|
25
|
+
'selector-no-qualifying-type': null,
|
|
26
|
+
'selector-max-compound-selectors': 5,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"jsx": "react",
|
|
8
|
+
"lib": [
|
|
9
|
+
"dom",
|
|
10
|
+
"ES5",
|
|
11
|
+
"ES6",
|
|
12
|
+
"ES7",
|
|
13
|
+
"ES2018",
|
|
14
|
+
"ES2020"
|
|
15
|
+
],
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"moduleResolution": "Node",
|
|
18
|
+
"noImplicitAny": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"removeComments": false,
|
|
22
|
+
"resolveJsonModule": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"sourceMap": true,
|
|
25
|
+
"strictNullChecks": true,
|
|
26
|
+
"target": "ESNext",
|
|
27
|
+
"typeRoots": [
|
|
28
|
+
"node_modules/@types",
|
|
29
|
+
"./@types"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"exclude": [
|
|
33
|
+
"**/*.js",
|
|
34
|
+
"**/*.mjs",
|
|
35
|
+
"node_modules",
|
|
36
|
+
"tmp"
|
|
37
|
+
],
|
|
38
|
+
"ts-node": {
|
|
39
|
+
"compilerOptions": {
|
|
40
|
+
"module": "CommonJS"
|
|
41
|
+
},
|
|
42
|
+
"require": ["tsconfig-paths/register"]
|
|
43
|
+
}
|
|
44
|
+
}
|
package/webpack.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { CallableOption, WebpackConfiguration } from 'webpack-cli/lib/types';
|
|
2
|
+
import { ModuleOptions, Compiler as WebpackCompiler } from 'webpack';
|
|
3
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
4
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
5
|
+
import ReactRefreshTypeScript from 'react-refresh-typescript';
|
|
6
|
+
import ReactRefreshPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
|
7
|
+
|
|
8
|
+
type LoaderType = 'typescript-file' | 'style-file';
|
|
9
|
+
|
|
10
|
+
export const getLoaderIndex = (
|
|
11
|
+
type: LoaderType,
|
|
12
|
+
rules: ModuleOptions['rules'],
|
|
13
|
+
): number => {
|
|
14
|
+
return (rules || []).findIndex((rule) => {
|
|
15
|
+
return Object.getOwnPropertySymbols(rule).some((symbol) => {
|
|
16
|
+
return symbol.toString() === 'Symbol(webpack-rule-name)' && (rule as any)[symbol] === type;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const adaptStorybookWebpackConfig = (
|
|
22
|
+
config: WebpackConfiguration,
|
|
23
|
+
options?: {
|
|
24
|
+
modulesNamesToMap?: string[];
|
|
25
|
+
aliases?: Required<WebpackConfiguration>['resolve']['alias'];
|
|
26
|
+
},
|
|
27
|
+
): WebpackConfiguration => {
|
|
28
|
+
const {
|
|
29
|
+
modulesNamesToMap = [],
|
|
30
|
+
} = options || {};
|
|
31
|
+
|
|
32
|
+
config.resolve = {
|
|
33
|
+
...(config.resolve || {}),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (options?.aliases) {
|
|
37
|
+
config.resolve.alias = {
|
|
38
|
+
...(config.resolve.alias || {}),
|
|
39
|
+
...options.aliases,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tsLoader = { loader: 'ts-loader' };
|
|
44
|
+
|
|
45
|
+
config.module = {
|
|
46
|
+
...(config.module || {}),
|
|
47
|
+
rules: [
|
|
48
|
+
...(config.module?.rules || []),
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
config.module.rules!.forEach((r: any) => {
|
|
53
|
+
if (r?.test?.test?.('.tsx') || r?.test?.test?.('.ts')
|
|
54
|
+
) {
|
|
55
|
+
r.use = [tsLoader];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
modulesNamesToMap.forEach((alias) => {
|
|
60
|
+
config.module!.rules!.push({
|
|
61
|
+
test: new RegExp(`${alias}\\/[^.]+\\.tsx?`, 'i'),
|
|
62
|
+
use: [tsLoader],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return config;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const getDefaultConfig = (
|
|
70
|
+
env: Parameters<CallableOption>[0],
|
|
71
|
+
mode: string,
|
|
72
|
+
): WebpackConfiguration => {
|
|
73
|
+
return {
|
|
74
|
+
resolve: {
|
|
75
|
+
extensions: ['.ts', '.tsx', '.js'],
|
|
76
|
+
},
|
|
77
|
+
optimization: {
|
|
78
|
+
minimizer: [
|
|
79
|
+
new TerserPlugin({ extractComments: false }),
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
devServer: {
|
|
83
|
+
hot: true,
|
|
84
|
+
compress: true,
|
|
85
|
+
},
|
|
86
|
+
module: {
|
|
87
|
+
rules: [
|
|
88
|
+
{
|
|
89
|
+
[Symbol('webpack-rule-name')]: 'typescript-file',
|
|
90
|
+
test: /\.tsx?$/,
|
|
91
|
+
use: [
|
|
92
|
+
{
|
|
93
|
+
loader: 'ts-loader',
|
|
94
|
+
options: {
|
|
95
|
+
getCustomTransformers: () => ({
|
|
96
|
+
before: [
|
|
97
|
+
env?.WEBPACK_SERVE && ReactRefreshTypeScript(),
|
|
98
|
+
].filter(Boolean),
|
|
99
|
+
}),
|
|
100
|
+
transpileOnly: true,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
[Symbol('webpack-rule-name')]: 'style-file',
|
|
107
|
+
test: /\.(s[ac]ss|css)$/i,
|
|
108
|
+
use: [
|
|
109
|
+
env?.WEBPACK_SERVE ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
110
|
+
'css-loader',
|
|
111
|
+
'postcss-loader',
|
|
112
|
+
'sass-loader',
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
plugins: [
|
|
118
|
+
env?.WEBPACK_SERVE && new ReactRefreshPlugin(),
|
|
119
|
+
!env?.WEBPACK_SERVE && new MiniCssExtractPlugin({
|
|
120
|
+
filename: '[name].css',
|
|
121
|
+
}),
|
|
122
|
+
{
|
|
123
|
+
apply(compiler: WebpackCompiler) {
|
|
124
|
+
compiler.hooks.done.tap('webpackOnDone', () => {
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
console.log(`===> [${mode}] done`);
|
|
127
|
+
}, 0);
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
].filter(Boolean),
|
|
132
|
+
} as WebpackConfiguration;
|
|
133
|
+
};
|