From 1f60b51af23dd1b48379f19cc81ad708de0022dd Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Wed, 21 Feb 2024 18:02:26 +0100 Subject: [PATCH] refactor(blank-typescript): upgrade packages, config jest, tsconfig and remove nlp dependencies --- blank-typescript/babel.config.js | 1 + blank-typescript/jest.config.js | 17 +++++++++++++++ blank-typescript/package.json | 33 +++++++++++------------------- blank-typescript/src/plugins.ts | 2 +- blank-typescript/tests/app.test.js | 10 ++++----- blank-typescript/tsconfig.json | 5 +++-- blank-typescript/webpack.config.js | 29 +------------------------- 7 files changed, 40 insertions(+), 57 deletions(-) create mode 100644 blank-typescript/jest.config.js diff --git a/blank-typescript/babel.config.js b/blank-typescript/babel.config.js index 55345b5..c4fae71 100644 --- a/blank-typescript/babel.config.js +++ b/blank-typescript/babel.config.js @@ -24,6 +24,7 @@ module.exports = { '@babel/typescript', ], plugins: [ + '@babel/plugin-transform-modules-commonjs', '@babel/plugin-transform-runtime', ], } diff --git a/blank-typescript/jest.config.js b/blank-typescript/jest.config.js new file mode 100644 index 0000000..5914ebf --- /dev/null +++ b/blank-typescript/jest.config.js @@ -0,0 +1,17 @@ +const path = require('path') + +module.exports = { + rootDir: "tests", + transform: { + "^.+\\.[j|t]sx?$": [ + "ts-jest", + ], + }, + transformIgnorePatterns: [ + "/node_modules/(?!@botonic).+\\.(js|jsx|ts|tsx)$" + ], + moduleNameMapper: { + "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/__mocks__/fileMock.js", + "\\.(scss|css|less)$": "/__mocks__/styleMock.js" + } +} \ No newline at end of file diff --git a/blank-typescript/package.json b/blank-typescript/package.json index 3aed682..c5ee41b 100644 --- a/blank-typescript/package.json +++ b/blank-typescript/package.json @@ -7,50 +7,41 @@ "deploy": "botonic deploy -c build", "test": "jest" }, - "jest": { - "rootDir": "tests", - "transformIgnorePatterns": [ - "/node_modules/(?!@botonic).+\\.(js|jsx|ts|tsx|mjs)$" - ], - "moduleNameMapper": { - "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/__mocks__/fileMock.js", - "\\.(scss|css|less)$": "/__mocks__/styleMock.js" - } - }, "dependencies": { "@babel/runtime": "^7.23.9", "@botonic/react": "0.25.0-alpha.4" }, "devDependencies": { "@babel/core": "^7.23.9", + "@babel/plugin-transform-modules-commonjs": "^7.23.3", "@babel/plugin-transform-runtime": "^7.23.9", "@babel/preset-env": "^7.23.9", "@babel/preset-react": "^7.23.3", "@babel/preset-typescript": "^7.23.3", "@hot-loader/react-dom": "^16.14.0", - "analytics-node": "^3.5.0", "babel-jest": "^29.7.0", - "babel-loader": "^8.3.0", + "babel-loader": "^9.1.3", "chokidar": "^3.6.0", - "clean-webpack-plugin": "^3.0.0", - "copy-webpack-plugin": "^7.0.0", - "css-loader": "^5.2.7", + "clean-webpack-plugin": "^4.0.0", + "css-loader": "^6.10.0", "file-loader": "^6.2.0", "html-webpack-plugin": "^5.6.0", - "imagemin-gifsicle": "^6.0.1", - "imagemin-jpegtran": "^6.0.0", - "imagemin-optipng": "^7.1.0", - "imagemin-svgo": "^7.1.0", + "image-minimizer-webpack-plugin": "^4.0.0", + "imagemin-gifsicle": "^7.0.0", + "imagemin-jpegtran": "^7.0.0", + "imagemin-optipng": "^8.0.0", + "imagemin-svgo": "^10.0.1", "imagemin-webpack": "^5.1.1", "jest": "^29.7.0", "null-loader": "^4.0.1", "process": "^0.11.10", "react-hot-loader": "4.12.21", - "sass": "^1.71.0", - "sass-loader": "^10.5.2", + "sass": "^1.71.1", + "sass-loader": "^14.1.1", "style-loader": "^3.3.4", "terser": "^5.27.2", "terser-webpack-plugin": "^5.3.10", + "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "typescript": "^4.9.5", "webpack": "^5.90.3", diff --git a/blank-typescript/src/plugins.ts b/blank-typescript/src/plugins.ts index 7d797bf..9f7cc5e 100644 --- a/blank-typescript/src/plugins.ts +++ b/blank-typescript/src/plugins.ts @@ -1,3 +1,3 @@ -import { PluginConfig } from '@botonic/core' +import type { PluginConfig } from '@botonic/core' export const plugins: PluginConfig[] = [] diff --git a/blank-typescript/tests/app.test.js b/blank-typescript/tests/app.test.js index 18e0a44..81a6176 100644 --- a/blank-typescript/tests/app.test.js +++ b/blank-typescript/tests/app.test.js @@ -11,11 +11,11 @@ import { routes } from '../src/routes' const app = new NodeApp({ routes, locales, plugins, ...config }) -const i = new BotonicInputTester(app) -const o = new BotonicOutputTester(app) +const session = { user: { id: '123' } } +const input = new BotonicInputTester(app) +const output = new BotonicOutputTester(app) test('TEST: (404) NOT FOUND', async () => { - await expect(i.text('whatever')).resolves.toBe( - o.text("I don't understand you") - ) + const response = await input.text('whatever', session) + expect(response).toBe(output.text("I don't understand you")) }) diff --git a/blank-typescript/tsconfig.json b/blank-typescript/tsconfig.json index f210594..8c9b50d 100644 --- a/blank-typescript/tsconfig.json +++ b/blank-typescript/tsconfig.json @@ -7,8 +7,9 @@ //ERROR in [at-loader] ./node_modules/@botonic/react/node_modules/@types/react/index.d.ts:2814:14 //TS2300: Duplicate identifier 'LibraryManagedAttributes'. "sourceMap": true, - "target": "ES2022", - "module": "ES2015", + "target": "ES2015", + "module": "Node16", + "moduleResolution": "Node16", "baseUrl": "src", "paths": { "*": ["src/*", "lib/*", "types/*"] diff --git a/blank-typescript/webpack.config.js b/blank-typescript/webpack.config.js index 6dc3d4b..b349e7d 100644 --- a/blank-typescript/webpack.config.js +++ b/blank-typescript/webpack.config.js @@ -1,34 +1,15 @@ const path = require('path') const webpack = require('webpack') -const CopyPlugin = require('copy-webpack-plugin') const TerserPlugin = require('terser-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') const { CleanWebpackPlugin } = require('clean-webpack-plugin') const ImageminPlugin = require('imagemin-webpack') const ROOT = path.resolve(__dirname, 'src') -const NLP_DIRNAME = 'nlp' const ASSETS_DIRNAME = 'assets' -const MODELS_DIRNAME = 'models' -const TASKS_DIRNAME = 'tasks' -const INTENT_CLASSIFICATION_DIRNAME = 'intent-classification' const OUTPUT_PATH = path.resolve(__dirname, 'dist') const WEBVIEWS_PATH = path.resolve(OUTPUT_PATH, 'webviews') -const TASKS_PATH = path.join(ROOT, NLP_DIRNAME, TASKS_DIRNAME) - -const INTENT_CLASSIFICATION_MODELS_PATH = path.join( - NLP_DIRNAME, - TASKS_DIRNAME, - INTENT_CLASSIFICATION_DIRNAME, - MODELS_DIRNAME -) -const INTENTS_ASSETS_MODELS_PATH = path.join( - ASSETS_DIRNAME, - TASKS_DIRNAME, - INTENT_CLASSIFICATION_DIRNAME, - MODELS_DIRNAME -) const BOTONIC_PATH = path.resolve( __dirname, @@ -199,7 +180,7 @@ function botonicDevConfig(mode) { }, resolve: resolveConfig, devServer: { - static: [OUTPUT_PATH, TASKS_PATH], + static: [OUTPUT_PATH], liveReload: true, historyApiFallback: true, hot: true, @@ -332,14 +313,6 @@ function botonicNodeConfig(mode) { IS_NODE: true, HUBTYPE_API_URL: JSON.stringify(process.env.HUBTYPE_API_URL), }), - new CopyPlugin({ - patterns: [ - { - from: INTENT_CLASSIFICATION_MODELS_PATH, - to: INTENTS_ASSETS_MODELS_PATH, - }, - ], - }), ], } }