@centreon/js-config 24.7.3 → 24.8.0

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/jest/index.js CHANGED
@@ -1,12 +1,15 @@
1
1
  module.exports = {
2
2
  moduleNameMapper: {
3
3
  '\\.(s?css|png|svg|jpg)$': 'identity-obj-proxy',
4
+ '^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
5
+ 'jest-transform-stub',
4
6
  '^react($|/.+)': '<rootDir>/node_modules/react$1'
5
7
  },
6
- setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
7
8
  testEnvironment: 'jsdom',
8
- testPathIgnorePatterns: ['/node_modules/'],
9
+ testPathIgnorePatterns: ['/node_modules/', '!*.cypress.spec.tsx'],
9
10
  transform: {
11
+ '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
12
+ 'jest-transform-stub',
10
13
  '^.+\\.[jt]sx?$': [
11
14
  '@swc/jest',
12
15
  {
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Copyright 2023 Centreon Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // For a detailed explanation regarding each configuration property, visit:
18
+ // https://jestjs.io/docs/en/configuration.html
19
+ const path = require('path');
20
+
21
+ const rootPath = path.join(__dirname);
22
+
23
+
24
+
25
+ module.exports = {
26
+ rootDir: rootPath,
27
+ // Automatically clear mock calls and instances between every test
28
+ clearMocks: true,
29
+ // The directory where Jest should output its coverage files
30
+ coverageDirectory: '<rootDir>/coverage',
31
+ // An array of regexp pattern strings used to skip coverage collection
32
+ coveragePathIgnorePatterns: ['\\\\node_modules\\\\', 'tests'],
33
+
34
+ // An array of file extensions your modules use
35
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
36
+
37
+ // Automatically reset mock state between every test
38
+ // resetMocks: true,
39
+
40
+ testMatch: ['**/*.(test|tests|spec|specs).+(ts|tsx|js)'],
41
+
42
+ // This option allows the use of a custom results processor
43
+ // testResultsProcessor: 'jest-sonar-reporter',
44
+
45
+ // A map from regular expressions to paths to transformers
46
+ transform: {
47
+ '^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.json' }],
48
+ },
49
+ };
package/package.json CHANGED
@@ -1,47 +1,59 @@
1
1
  {
2
- "name": "@centreon/js-config",
3
- "description": "Centreon Frontend shared build configuration",
4
- "version": "24.7.3",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/centreon/centreon-frontend.git"
8
- },
9
- "keywords": [
10
- "centreon",
11
- "eslint"
12
- ],
13
- "author": "centreon@centreon.com",
14
- "license": "GPL-2.0",
15
- "bugs": {
16
- "url": "https://github.com/centreon/centreon-frontend/issues"
17
- },
18
- "devDependencies": {
19
- "@badeball/cypress-cucumber-preprocessor": "^14.0.0",
20
- "@types/dockerode": "^3.3.16",
21
- "dockerode": "^3.3.5",
22
- "eslint": "^8.17.0",
23
- "eslint-config-airbnb": "19.0.4",
24
- "eslint-config-prettier": "^8.5.0",
25
- "eslint-import-resolver-alias": "^1.1.2",
26
- "eslint-plugin-babel": "^5.3.1",
27
- "eslint-plugin-hooks": "^0.4.3",
28
- "eslint-plugin-import": "^2.26.0",
29
- "eslint-plugin-jest": "^26.1.5",
30
- "eslint-plugin-jsx-a11y": "^6.5.1",
31
- "eslint-plugin-node": "^11.1.0",
32
- "eslint-plugin-prefer-arrow-functions": "^3.1.4",
33
- "eslint-plugin-prettier": "^4.0.0",
34
- "eslint-plugin-react": "^7.29.4",
35
- "eslint-plugin-react-hooks": "^4.5.0",
36
- "eslint-plugin-sort-keys-fix": "^1.1.2",
37
- "eslint-plugin-typescript-sort-keys": "^2.1.0"
38
- },
39
- "homepage": "https://github.com/centreon/centreon-frontend#readme",
40
- "files": [
41
- "eslint",
42
- "jest",
43
- "tsconfig",
44
- "webpack",
45
- "cypress"
46
- ]
2
+ "name": "@centreon/js-config",
3
+ "description": "Centreon Frontend shared build configuration",
4
+ "version": "24.8.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/centreon/centreon-frontend.git"
8
+ },
9
+ "keywords": [
10
+ "centreon",
11
+ "eslint"
12
+ ],
13
+ "author": "centreon@centreon.com",
14
+ "license": "MIT",
15
+ "bugs": {
16
+ "url": "https://github.com/centreon/centreon-frontend/issues"
17
+ },
18
+ "homepage": "https://github.com/centreon/centreon-frontend#readme",
19
+ "peerDependencies": {
20
+ "eslint": "^8.53.0",
21
+ "prettier": "^3.0.0"
22
+ },
23
+ "dependencies": {
24
+ "@badeball/cypress-cucumber-preprocessor": "^20.0.7",
25
+ "@bahmutov/cypress-esbuild-preprocessor": "^2.2.1",
26
+ "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
27
+ "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
28
+ "@tsconfig/node16": "^16.1.3",
29
+ "@tsconfig/node20": "^20.1.4",
30
+ "@types/cypress-cucumber-preprocessor": "^4.0.5",
31
+ "cypress": "^13.6.4",
32
+ "cypress-multi-reporters": "^1.6.4",
33
+ "cypress-terminal-report": "^6.1.0",
34
+ "cypress-wait-until": "^3.0.1",
35
+ "dotenv": "^16.4.5",
36
+ "esbuild": "^0.21.5",
37
+ "eslint": "^8.53.0",
38
+ "eslint-config-airbnb": "19.0.4",
39
+ "eslint-config-prettier": "^8.5.0",
40
+ "eslint-import-resolver-alias": "^1.1.2",
41
+ "eslint-import-resolver-typescript": "^3.5.5",
42
+ "eslint-plugin-babel": "^5.3.1",
43
+ "eslint-plugin-hooks": "^0.4.3",
44
+ "eslint-plugin-import": "^2.26.0",
45
+ "eslint-plugin-jest": "^26.1.5",
46
+ "eslint-plugin-jsx-a11y": "^6.5.1",
47
+ "eslint-plugin-node": "^11.1.0",
48
+ "eslint-plugin-prefer-arrow-functions": "^3.1.4",
49
+ "eslint-plugin-prettier": "^5.0.0",
50
+ "eslint-plugin-react": "^7.29.4",
51
+ "eslint-plugin-react-hooks": "^4.5.0",
52
+ "eslint-plugin-sort-keys-fix": "^1.1.2",
53
+ "eslint-plugin-typescript-sort-keys": "^2.1.0",
54
+ "mochawesome": "^7.1.3",
55
+ "mysql2": "^3.10.1",
56
+ "tar-fs": "^3.0.6",
57
+ "testcontainers": "^10.9.0"
58
+ }
47
59
  }
@@ -0,0 +1,71 @@
1
+ const isDev = process.env.NODE_ENV !== 'production';
2
+
3
+ const excludeNodeModulesExceptCentreonUi =
4
+ /node_modules(\\|\/)\.pnpm(\\|\/)(?!(@centreon|file\+packages\+ui-context))/;
5
+
6
+ module.exports = {
7
+ cache: false,
8
+ excludeNodeModulesExceptCentreonUi,
9
+ getModuleConfiguration: (enableCoverage) => ({
10
+ rules: [
11
+ {
12
+ exclude: [excludeNodeModulesExceptCentreonUi],
13
+ test: /\.[jt]sx?$/,
14
+ use: {
15
+ loader: 'swc-loader',
16
+ options: {
17
+ jsc: {
18
+ experimental: {
19
+ plugins: [
20
+ enableCoverage && ['swc-plugin-coverage-instrument', {}]
21
+ ].filter(Boolean)
22
+ },
23
+ parser: {
24
+ syntax: 'typescript',
25
+ tsx: true
26
+ },
27
+ transform: {
28
+ react: {
29
+ development: isDev,
30
+ refresh: isDev
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ },
37
+ {
38
+ test: /\.icon.svg$/,
39
+ use: ['@svgr/webpack']
40
+ },
41
+ {
42
+ exclude: excludeNodeModulesExceptCentreonUi,
43
+ test: /\.(bmp|png|jpg|jpeg|gif|svg)$/,
44
+ type: 'asset/inline'
45
+ },
46
+ {
47
+ generator: {
48
+ filename: '[name][ext]'
49
+ },
50
+ test: /\.(woff|woff2|eot|ttf|otf)$/i,
51
+ type: 'asset/resource'
52
+ },
53
+ {
54
+ test: /\.css$/i,
55
+ use: ['style-loader', 'css-loader']
56
+ }
57
+ ]
58
+ }),
59
+ optimization: {
60
+ splitChunks: {
61
+ chunks: 'all',
62
+ maxSize: 400 * 1024
63
+ }
64
+ },
65
+ output: {
66
+ chunkFilename: '[name].[chunkhash:8].chunk.js',
67
+ filename: '[name].[chunkhash:8].js',
68
+ libraryTarget: 'umd',
69
+ umdNamedDefine: true
70
+ }
71
+ };
@@ -0,0 +1,89 @@
1
+ const path = require('path');
2
+
3
+ const rspack = require('@rspack/core');
4
+
5
+ const {
6
+ getModuleConfiguration,
7
+ optimization,
8
+ output,
9
+ cache
10
+ } = require('./globalConfig');
11
+
12
+ const getBaseConfiguration = ({
13
+ moduleName,
14
+ moduleFederationConfig,
15
+ enableCoverage
16
+ }) => ({
17
+ cache,
18
+ module: getModuleConfiguration(enableCoverage),
19
+ optimization,
20
+ output: {
21
+ ...output,
22
+ clean: true,
23
+ library: moduleName,
24
+ uniqueName: moduleName
25
+ },
26
+ plugins: [
27
+ moduleName &&
28
+ new rspack.container.ModuleFederationPlugin({
29
+ filename: 'remoteEntry.[chunkhash:8].js',
30
+ library: { name: moduleName, type: 'umd' },
31
+ name: moduleName,
32
+ shared: [
33
+ {
34
+ '@centreon/ui-context': {
35
+ requiredVersion: '1.x',
36
+ singleton: true
37
+ }
38
+ },
39
+ {
40
+ jotai: {
41
+ requiredVersion: '2.x',
42
+ singleton: true
43
+ }
44
+ },
45
+ {
46
+ 'jotai-suspense': {
47
+ singleton: true
48
+ }
49
+ },
50
+ {
51
+ react: {
52
+ requiredVersion: '18.x',
53
+ singleton: true
54
+ }
55
+ },
56
+ {
57
+ 'react-dom': {
58
+ requiredVersion: '18.x',
59
+ singleton: true
60
+ }
61
+ },
62
+ {
63
+ 'react-i18next': {
64
+ requiredVersion: '14.x',
65
+ singleton: true
66
+ }
67
+ },
68
+ {
69
+ 'react-router-dom': {
70
+ requiredVersion: '6.x',
71
+ singleton: true
72
+ }
73
+ }
74
+ ],
75
+ ...moduleFederationConfig
76
+ })
77
+ ].filter(Boolean),
78
+ resolve: {
79
+ alias: {
80
+ '@centreon/ui/fonts': path.resolve(
81
+ './node_modules/@centreon/ui/public/fonts'
82
+ ),
83
+ react: path.resolve('./node_modules/react')
84
+ },
85
+ extensions: ['.js', '.jsx', '.ts', '.tsx']
86
+ }
87
+ });
88
+
89
+ module.exports = getBaseConfiguration;
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ getDevConfiguration: () => ({
3
+ cache: true,
4
+ devtool: 'eval-cheap-module-source-map',
5
+ optimization: {
6
+ splitChunks: false
7
+ },
8
+ output: {
9
+ filename: '[name].js'
10
+ }
11
+ })
12
+ };
@@ -1,6 +1,6 @@
1
1
  const os = require('os');
2
2
 
3
- const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
3
+ const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
4
4
 
5
5
  const devServerPort = 9090;
6
6
 
@@ -19,10 +19,9 @@ const devServerAddress = externalInterface
19
19
 
20
20
  const publicPath = `http://${devServerAddress}:${devServerPort}/static/`;
21
21
 
22
- const isServeMode = process.env.WEBPACK_ENV === 'serve';
23
- const isDevelopmentMode = process.env.WEBPACK_ENV === 'development';
22
+ const isDevelopmentMode = process.env.NODE_ENV !== 'production';
24
23
 
25
- const devServerPlugins = isServeMode ? [new ReactRefreshWebpackPlugin()] : [];
24
+ const devServerPlugins = isDevelopmentMode ? [new ReactRefreshPlugin()] : [];
26
25
 
27
26
  module.exports = {
28
27
  devServer: {
@@ -32,6 +31,5 @@ module.exports = {
32
31
  },
33
32
  devServerPlugins,
34
33
  isDevelopmentMode,
35
- isServeMode,
36
34
  publicPath
37
35
  };
@@ -0,0 +1,13 @@
1
+ const WriteRemoteEntryNameToModuleFederation = require('../plugins/WriteRemoteEntryNameToModuleFederation');
2
+ const TransformPreloadScript = require('../plugins/TransformPreloadScript');
3
+
4
+ module.exports = ({ outputPath, federatedComponentConfiguration }) => ({
5
+ output: {
6
+ library: '[chunkhash:8]',
7
+ path: outputPath
8
+ },
9
+ plugins: [
10
+ new WriteRemoteEntryNameToModuleFederation(federatedComponentConfiguration),
11
+ new TransformPreloadScript(federatedComponentConfiguration)
12
+ ]
13
+ });
@@ -0,0 +1,37 @@
1
+ const fs = require('fs');
2
+
3
+ const swc = require('@swc/core');
4
+
5
+ module.exports = class TransformPreloadScript {
6
+ constructor(federatedComponentConfiguration) {
7
+ this.federatedComponentConfiguration = federatedComponentConfiguration;
8
+ }
9
+
10
+ apply(compiler) {
11
+ compiler.hooks.done.tap('TransformPreloadScript', () => {
12
+ if (!fs.existsSync(compiler.options.output.path)) {
13
+ fs.mkdirSync(compiler.options.output.path, { recursive: true });
14
+ }
15
+
16
+ if (this.federatedComponentConfiguration.preloadScript) {
17
+ const { code } = swc.transformFileSync(
18
+ `./${this.federatedComponentConfiguration.preloadScript}.ts`,
19
+ {
20
+ filename: `${this.federatedComponentConfiguration.preloadScript}.ts`,
21
+ jsc: {
22
+ parser: {
23
+ syntax: 'typescript'
24
+ }
25
+ },
26
+ minify: true
27
+ }
28
+ );
29
+
30
+ fs.writeFileSync(
31
+ `${compiler.options.output.path}/${this.federatedComponentConfiguration.preloadScript}.js`,
32
+ code
33
+ );
34
+ }
35
+ });
36
+ }
37
+ };
@@ -0,0 +1,30 @@
1
+ const fs = require('fs');
2
+
3
+ module.exports = class WriteRemoteEntryNameToModuleFederation {
4
+ constructor(federatedComponentConfiguration) {
5
+ this.federatedComponentConfiguration = federatedComponentConfiguration;
6
+ }
7
+
8
+ apply(compiler) {
9
+ compiler.hooks.done.tap(
10
+ 'WriteRemoteEntryNameToModuleFederation',
11
+ (stats) => {
12
+ const newFederatedComponentConfiguration = {
13
+ ...this.federatedComponentConfiguration,
14
+ remoteEntry: Object.keys(stats.compilation.assets).find((assetName) =>
15
+ assetName.match(/(^remoteEntry)\S+.js$/)
16
+ )
17
+ };
18
+
19
+ if (!fs.existsSync(compiler.options.output.path)) {
20
+ fs.mkdirSync(compiler.options.output.path, { recursive: true });
21
+ }
22
+
23
+ fs.writeFileSync(
24
+ `${compiler.options.output.path}/moduleFederation.json`,
25
+ JSON.stringify(newFederatedComponentConfiguration, null, 2)
26
+ );
27
+ }
28
+ );
29
+ }
30
+ };
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "moduleResolution": "node",
4
3
  "downlevelIteration": true,
5
- "module": "es6",
6
- "target": "es6",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
6
+ "target": "es2018",
7
7
  "jsx": "react-jsx",
8
8
  "strict": true,
9
9
  "noImplicitAny": false,
10
10
  "skipLibCheck": true,
11
- "esModuleInterop": true
11
+ "esModuleInterop": true,
12
+ "resolveJsonModule": true
12
13
  }
13
14
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "@tsconfig/node20/tsconfig.json",
3
+ "compilerOptions": {
4
+ "sourceMap": true,
5
+ "allowJs": true,
6
+ "strictNullChecks": false,
7
+ "declaration": false,
8
+ "esModuleInterop": true,
9
+ "strict": true,
10
+ "types": ["@types/jest", "node"]
11
+ }
12
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "@tsconfig/node16/tsconfig.json",
3
+ "compilerOptions": {
4
+ "sourceMap": true,
5
+ "allowJs": true,
6
+ "strictNullChecks": false,
7
+ "declaration": false,
8
+ "esModuleInterop": true,
9
+ "types": [
10
+ "@types/jest",
11
+ "node"
12
+ ]
13
+ }
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "./tsconfig/index.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "./",
5
+ "outDir": "./dist",
6
+ "declaration": true,
7
+ "skipLibCheck": true,
8
+ "pretty": true,
9
+ "emitDeclarationOnly": true,
10
+ "types": ["cypress", "cypress-wait-until"],
11
+ "esModuleInterop": true,
12
+ "paths": {
13
+ "@badeball/cypress-cucumber-preprocessor/*": ["./node_modules/@badeball/cypress-cucumber-preprocessor/dist/subpath-entrypoints/*"]
14
+ }
15
+ },
16
+ "exclude": [
17
+ "./node_modules",
18
+ "./dist",
19
+ "../../node_modules"
20
+ ],
21
+ }
@@ -1,130 +0,0 @@
1
- const path = require('path');
2
-
3
- const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4
- const { ModuleFederationPlugin } = require('webpack').container;
5
-
6
- const excludeNodeModulesExceptCentreonUi =
7
- /node_modules(\\|\/)\.pnpm(\\|\/)(?!(@centreon))/;
8
-
9
- const getBaseConfiguration = ({
10
- moduleName,
11
- moduleFederationConfig,
12
- jscTransformConfiguration
13
- }) => ({
14
- cache: false,
15
- module: {
16
- rules: [
17
- {
18
- parser: { system: false },
19
- test: /\.[cm]?(j|t)sx?$/
20
- },
21
- {
22
- exclude: excludeNodeModulesExceptCentreonUi,
23
- test: /\.[jt]sx?$/,
24
- use: {
25
- loader: 'swc-loader',
26
- options: {
27
- jsc: {
28
- parser: {
29
- syntax: 'typescript',
30
- tsx: true
31
- },
32
- transform: jscTransformConfiguration
33
- }
34
- }
35
- }
36
- },
37
- {
38
- test: /\.icon.svg$/,
39
- use: ['@svgr/webpack']
40
- },
41
- {
42
- exclude: excludeNodeModulesExceptCentreonUi,
43
- test: /\.(bmp|png|jpg|jpeg|gif|svg)$/,
44
- use: [
45
- {
46
- loader: 'url-loader',
47
- options: {
48
- limit: 10000,
49
- name: '[name].[hash:8].[ext]'
50
- }
51
- }
52
- ]
53
- }
54
- ]
55
- },
56
- optimization: {
57
- splitChunks: {
58
- chunks: 'all',
59
- maxSize: 400 * 1024
60
- }
61
- },
62
- output: {
63
- chunkFilename: '[name].[chunkhash:8].chunk.js',
64
- filename: '[name].[chunkhash:8].js',
65
- libraryTarget: 'umd',
66
- umdNamedDefine: true
67
- },
68
- plugins: [
69
- new CleanWebpackPlugin(),
70
- moduleName &&
71
- new ModuleFederationPlugin({
72
- filename: 'remoteEntry.[chunkhash:8].js',
73
- library: { name: moduleName, type: 'var' },
74
- name: moduleName,
75
- shared: [
76
- {
77
- '@centreon/ui-context': {
78
- requiredVersion: '22.10.0',
79
- singleton: true
80
- }
81
- },
82
- {
83
- jotai: {
84
- requiredVersion: '1.x',
85
- singleton: true
86
- }
87
- },
88
- {
89
- 'jotai-suspense': {
90
- requiredVersion: '0.1.x',
91
- singleton: true
92
- }
93
- },
94
- {
95
- react: {
96
- requiredVersion: '18.x',
97
- singleton: true
98
- }
99
- },
100
- {
101
- 'react-dom': {
102
- requiredVersion: '18.x',
103
- singleton: true
104
- }
105
- },
106
- {
107
- 'react-i18next': {
108
- requiredVersion: '11.x',
109
- singleton: true
110
- }
111
- },
112
- {
113
- 'react-router-dom': {
114
- requiredVersion: '6.x',
115
- singleton: true
116
- }
117
- }
118
- ],
119
- ...moduleFederationConfig
120
- })
121
- ].filter(Boolean),
122
- resolve: {
123
- alias: {
124
- react: path.resolve('./node_modules/react')
125
- },
126
- extensions: ['.js', '.jsx', '.ts', '.tsx']
127
- }
128
- });
129
-
130
- module.exports = getBaseConfiguration;