diff --git a/bin/commands/lint.js b/bin/commands/lint.js index a51836c..76ff649 100644 --- a/bin/commands/lint.js +++ b/bin/commands/lint.js @@ -8,6 +8,7 @@ module.exports = { type: 'boolean', }), handler: (args) => { - call('eslint', `${args.cache ? '--cache' : ''} --no-error-on-unmatched-pattern ${(args.strings || []).join(' ')} "src/**/*.ts{,x}" "tests/**/*.ts{,x}" "cypress/**/*.ts{,x}"`); + // TODO: Remove --fix to ensure all linting errors are reported in CI. Disable until a codebase is fully migrated, as otherwise formatting causes merge conflicts. + call('eslint', `--fix ${args.cache ? '--cache' : ''} --no-error-on-unmatched-pattern ${(args.strings || []).join(' ')} "src/**/*.ts{,x}" "tests/**/*.ts{,x}" "cypress/**/*.ts{,x}"`); }, }; diff --git a/config/eslintrc.template.js b/config/eslintrc.template.js index 6718593..b9fcdd6 100755 --- a/config/eslintrc.template.js +++ b/config/eslintrc.template.js @@ -49,6 +49,7 @@ module.exports = ({ tsconfigRootDir }) => ({ 'no-prototype-builtins': 'warn', 'no-minusminus': 'off', 'no-underscore-dangle': 'off', + '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-unused-expressions': [ 'error', { @@ -57,6 +58,7 @@ module.exports = ({ tsconfigRootDir }) => ({ allowTaggedTemplates: true, }, ], + '@typescript-eslint/no-unused-vars': 'warn', 'max-classes-per-file': 'off', 'no-param-reassign': ['warn', { props: true, ignorePropertyModificationsFor: ['state'] }], // Exclude state as required by redux-toolkit: https://redux-toolkit.js.org/usage/immer-reducers#linting-state-mutations 'cypress/unsafe-to-chain-command': 'off', diff --git a/config/jest.config.template.js b/config/jest.config.template.js index 6988cd5..98285ad 100644 --- a/config/jest.config.template.js +++ b/config/jest.config.template.js @@ -3,10 +3,7 @@ const pluginsNotToTransform = [ 'd3v3', ].join('|'); -/** - * TODO check if we can process inline webpack loaders (e.g. as found in https://github.com/phovea/phovea_ui/blob/master/src/_bootstrap.ts) - * see also https://jestjs.io/docs/en/webpack#mocking-css-modules - */ +/** @type {import('jest').Config} */ module.exports = { testEnvironment: 'jsdom', transform: { @@ -22,6 +19,8 @@ module.exports = { '\\.xml$': 'jest-raw-loader', }, testRegex: '(.*(test|spec))\\.(tsx?)$', + testPathIgnorePatterns: ['playwright'], + coveragePathIgnorePatterns: ['playwright'], moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], modulePaths: ['src'], resolver: 'visyn_scripts/config/jest_export_maps_resolver.js', @@ -32,5 +31,7 @@ module.exports = { }, moduleNameMapper: { '^.+\\.(css|less|scss|sass|png|jpg|gif|svg|html)$': 'identity-obj-proxy', + // Add tslib alias as otherwise we get a TypeError: Cannot destructure property '__extends' of '_tslib.default' as it is undefined. + tslib: 'tslib/tslib.es6.js', }, }; diff --git a/config/tsconfig.template.json b/config/tsconfig.template.json index def4ff8..17a306d 100755 --- a/config/tsconfig.template.json +++ b/config/tsconfig.template.json @@ -17,11 +17,14 @@ "allowSyntheticDefaultImports": true, "preserveWatchOutput": true }, + // Old "moduleResolution": "Node" option required for Cypress + // https://github.com/cypress-io/cypress/issues/26308#issuecomment-1663592648 + // + // TODO: Remove when issue is resolved https://github.com/cypress-io/cypress/issues/27448 "ts-node": { "compilerOptions": { - "module": "es2022", - "moduleResolution": "node16", - "sourceMap": false, + "module": "ESNext", + "moduleResolution": "Node" } - }, + } } \ No newline at end of file diff --git a/config/webpack.config.js b/config/webpack.config.js index 3f71d52..3f471e5 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -308,7 +308,8 @@ module.exports = (webpackEnv, argv) => { ? { static: path.resolve(workspacePath, 'bundles'), compress: true, - host: 'localhost', + // Listen to all interfaces, as Node 18+ resolves IPv6 first: https://github.com/cypress-io/github-action/blob/master/README.md#wait-on-with-nodejs-18 + host: '0.0.0.0', open: true, // Needs to be enabled to make SPAs work: https://stackoverflow.com/questions/31945763/how-to-tell-webpack-dev-server-to-serve-index-html-for-any-route historyApiFallback: historyApiFallback == null ? true : historyApiFallback, @@ -495,6 +496,20 @@ module.exports = (webpackEnv, argv) => { }, }, }, + // Process application TS with swc-loader even if they are coming from node_modules, i.e. from non-built dependencies. + { + test: /\.(ts|tsx)$/, + loader: 'swc-loader', + options: { + jsc: { + parser: { + syntax: 'typescript', + decorators: true, + // TODO: Check what other settings should be supported: https://swc.rs/docs/configuration/swcrc#compilation + }, + }, + }, + }, // "postcss" loader applies autoprefixer to our CSS. // "css" loader resolves paths in CSS and adds assets as dependencies. // "style" loader turns CSS into JS modules that inject