Skip to content

Commit

Permalink
GEN-126: Migrate hCore from Webpack 4 to Vite (#53)
Browse files Browse the repository at this point in the history
* Vite conversion; all but web workers are now online.

* Clean out old package.json dependnecies

* remove core's webpack config and other unused packages

* Restore working engine-web 'test' and 'build-stdlib' scripts

* repair 'yarn test'

* update browserslist target to match vite's target

https://vitejs.dev/guide/build#browser-compatibility

* repair yarn build/start by fixing a bug in how we passed 'max_old_space_size'

* build improvements

- remove sentry.io
- .gitignore 'dist'
- include 'embed.html' in the output

* yarn fmt

* Add vite-env.d.ts to provide vite environment types

* Add type-aware linting rules per Vite best practice

* Apply updated formatting

* eslint: restore common react/* linting rules

* eslint: restore recommended rules.

* eslint: restore some of the typescript-eslint basic rules

* eslint: apply linting to .cjs files; restore additional typescript-eslint rules

* restore the remaining typescript-eslint rules that we can

* s/MapBox/Mapbox

* eslint rules triage complete & global yarn fmt

* Updates to tsconfig.json

* gitignore tsbuildinfo

* fix most of the typescript errors; add tsx to 'check' command; add prettier caching; sundry

* Flag the remaining typescript build errors with todo's so we have a clean build

* add preview:core to package.json

* (repair webworkers) replace promise.resolve().then with setTimeout

- Turns out promise.resolve().then() doesn't actually accomplish the equivalent of a setImmediate.  I was mislead by something online, oh well...  setTimeout works.
- The main simulation worker was breaking when you used the 'run' functionality because the thread would lock. A setTimeout (and previously, setImmediate) was needed to allow other events in the thread.

* Spacing fix in husky's pre-push

* Update vercel.json for new vite build

* Remove auto-types.ts and hardcode its relevant items into types.ts

This file was ignored and persisted across branches, thus causing fresh checkouts to break (as Vite no longer generates this) but existing checkouts to act "normal".  I've removed the files and its special cases entirely, and added its contents into types.ts.

This now repairs the build. Next up is pruning out the unused generated items and only keeping the relevant ones.

* Remove unused types from types.ts

* adjust package.json lint and fmt commands to work cross-platform

* .gitignore .vercel
  • Loading branch information
judeallred authored Dec 14, 2023
1 parent f2be7a2 commit efe1801
Show file tree
Hide file tree
Showing 518 changed files with 8,761 additions and 33,720 deletions.
10 changes: 7 additions & 3 deletions .config/husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ set -e
. "$(dirname -- "$0")/_/husky.sh"

echo "************************************************************************"
echo "** Running sim-core's 'yarn fmt-check' **"
echo "** If this fails, run 'yarn fmt' and commit your fixes. **"
echo "** Running sim-core's 'yarn lint' **"
echo "** **"
echo "** If this fails, run 'yarn lint' for details. **"
echo "** You'll need to either fix formatting ('yarn fmt'), **"
echo "** or fix the typescript build ('yarn lint') **"
echo "** **"
echo "** (Output is stored in .config/husky/husky.log) **"
echo "** This takes about 10 seconds... **"
echo "************************************************************************"

cd apps/sim-core || exit 1
yarn fmt-check > ../../.config/husky/husky.log 2>&1;
yarn lint > ../../.config/husky/husky.log 2>&1;

echo "** Formatting check success. **"
echo "************************************************************************"
6 changes: 5 additions & 1 deletion apps/sim-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ yarn-error.log

# eslint cache
.eslintcache
packages/hashai/.eslintcache
packages/hashai/.eslintcache

#ts cache
tsconfig.tsbuildinfo
.vercel
56 changes: 23 additions & 33 deletions apps/sim-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"postinstall": "yarn build:utils && yarn build:engine-web",
"prepare": "cd ../.. && husky install .config/husky",
"all": "npx npm-run-all",
"fmt:scripts": "prettier \"scripts/**/*.{ts,tsx,js,json}\" --write",
"fmt-check:scripts": "prettier \"scripts/**/*.{ts,tsx,js,json}\" --check",
"fmt:scripts": "prettier --write --cache \"scripts/**/*.{ts,tsx,js,json}\" ",
"lint:scripts": "prettier --check --cache \"scripts/**/*.{ts,tsx,js,json}\" && tsc --noEmit",
"fmt": "yarn all fmt:*",
"fmt-check": "yarn all fmt-check:*",
"lint": "yarn all lint:*",
"test": "yarn all test:*",
"clippy": "touch packages/engine/src/lib.rs && cargo clippy --all",
"// 03": "",
Expand All @@ -24,7 +24,7 @@
"clean:engine-web": "yarn ws:engine-web clean",
"fmt:rustfmt": "cargo fmt -v --all",
"fmt:engine-web": "yarn ws:engine-web fmt",
"fmt-check:engine-web": "yarn ws:engine-web fmt-check",
"lint:engine-web": "yarn ws:engine-web lint",
"test:engine-web": "yarn ws:engine-web test",
"test:rust-engine": "cargo test --verbose",
"// 06": "",
Expand All @@ -38,10 +38,11 @@
"predeploy:core": "yarn build:engine-web",
"deploy:core": "yarn ws:core deploy",
"fmt:core": "yarn ws:core fmt",
"fmt-check:core": "yarn ws:core fmt-check",
"lint:core": "yarn ws:core lint",
"preserve:core": "yarn build:engine-web",
"serve:core": "yarn ws:core serve",
"start:core": "yarn ws:core start",
"preview:core": "yarn ws:core preview",
"test:core": "yarn ws:core test",
"g": "yarn ws:core g",
"// 09": "",
Expand All @@ -56,7 +57,7 @@
"ws:utils": "yarn workspace @hashintel/utils",
"build:utils": "yarn ws:utils build",
"fmt:utils": "yarn ws:utils fmt",
"fmt-check:utils": "yarn ws:utils fmt-check"
"lint:utils": "yarn ws:utils lint"
},
"workspaces": [
"packages/core",
Expand All @@ -66,11 +67,12 @@
],
"devDependencies": {
"@babel/core": "7.12.3",
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/plugin-proposal-numeric-separator": "7.12.7",
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-string-parser": "^7.23.4",
"@babel/preset-env": "7.12.11",
"@babel/preset-react": "7.14.5",
"@babel/preset-typescript": "7.12.1",
"@jridgewell/gen-mapping": "^0.3.3",
"@types/classnames": "2.2.11",
"@types/dom-mediacapture-record": "1.0.7",
"@types/file-saver": "2.0.2",
Expand All @@ -97,55 +99,43 @@
"@types/stats": "0.16.30",
"@types/url-join": "4.0.0",
"@types/uuid": "8.3.0",
"@typescript-eslint/eslint-plugin": "4.8.1",
"@typescript-eslint/parser": "4.15.2",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.10.0",
"babel-jest": "26.6.3",
"babel-loader": "8.2.1",
"core-js": "3.7.0",
"cross-env": "7.0.2",
"css-loader": "4.3.0",
"dotenv": "8.2.0",
"eslint": "7.29.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-react-hooks": "4.2.0",
"file-loader": "6.2.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"caniuse-lite": "^1.0.30001563",
"cross-env": "7.0.3",
"eslint": "^8.53.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"fork-ts-checker-webpack-plugin": "6.0.3",
"html-webpack-plugin": "4.5.1",
"husky": "^8.0.0",
"identity-obj-proxy": "3.0.0",
"jest": "26.6.3",
"jest-canvas-mock": "2.3.0",
"npm-run-all": "4.1.5",
"null-loader": "4.0.1",
"prettier": "2.2.1",
"prettier": "3.1.0",
"prop-types": "15.7.2",
"random-emoji": "1.0.2",
"request": "2.88.2",
"request-promise-native": "1.0.9",
"rimraf": "3.0.2",
"shelljs": "0.8.5",
"source-map-loader": "1.1.2",
"style-loader": "2.0.0",
"time-stamp": "2.2.0",
"tmp": "0.2.1",
"ts-jest": "26.4.4",
"ts-node": "9.1.1",
"typescript": "4.1.3",
"unused-modules-webpack-plugin": "1.0.1",
"url-loader": "4.1.1",
"typescript": "^4.3.5",
"webpack": "4.44.2",
"webpack-cli": "3.3.12",
"webpack-dev-server": "3.11.0",
"webpack-manifest-plugin": "2.2.0",
"webpack-messages": "2.0.4",
"webpack-retry-chunk-load-plugin": "1.4.0",
"yarn-audit-fix": "^10.0.1",
"yarn-run-all": "3.1.1"
},
"resolutions": {
"@types/react": "16.9.56"
},
"dependencies": {
"@sentry/tracing": "6.3.6"
}
"dependencies": {}
}
38 changes: 0 additions & 38 deletions apps/sim-core/packages/core/.eslintrc

This file was deleted.

83 changes: 83 additions & 0 deletions apps/sim-core/packages/core/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
jsx: true,
useJSXTextNode: true,
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json"],
tsconfigRootDir: __dirname,
},
env: { browser: true, es2020: true, node: true },
ignorePatterns: ["dist"],
settings: {
react: {
version: "detect",
},
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:react/jsx-runtime",
"plugin:react/recommended",
"prettier",
],
plugins: ["@typescript-eslint", "react-hooks", "react", "import"],
rules: {
// Augmentations
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": [
"warn",
{
additionalHooks: "(^useModal$)|(^useUserGatedEffect$)",
},
],

// Preferences
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_+", varsIgnorePattern: "^_+" },
],
"no-unused-expressions": "error",
"prefer-const": "error",
"react/jsx-key": "error",
"react/jsx-no-useless-fragment": "error",
"react/self-closing-comp": "error",
eqeqeq: ["error", "always", { null: "ignore" }],

// Disabled due to tech debt
// Ideally each of these would be brought back into play, but they're not small potatoes.
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/prefer-nullish-coalescing": [
"error",
{ ignoreMixedLogicalExpressions: true, ignorePrimitives: true },
],

// Deliberately disabled to ease use of React/Redux
"@typescript-eslint/await-thenable": "off", // Redux/Dispatch uses this a lot.
"@typescript-eslint/no-empty-function": "off", // React uses this a lot.
"@typescript-eslint/no-floating-promises": "off", // redux 'dispatch' and other react hooks create lots of floating promises.
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false, // Void-returned promises come up a lot in react
},
],
"react/prop-types": [
"error",
{ skipUndeclared: true, ignore: ["children"] }, // 'children' prop type detection is buggy
],
"react/display-name": "off", // Set automatically during transpilation, so disable it here.
"react/no-unescaped-entities": "off", // Permits more natural language in html, e.g. aprostrophies.
},
};
4 changes: 1 addition & 3 deletions apps/sim-core/packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
coverage

# auto-generated types for API queries
src/util/api/auto-types.ts
dist
2 changes: 0 additions & 2 deletions apps/sim-core/packages/core/.prettierignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ module.exports = {
["@babel/preset-env", { useBuiltIns: "usage", corejs: { version: "3.8" } }],
"@babel/preset-typescript",
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-numeric-separator",
],
plugins: [],
};
13 changes: 0 additions & 13 deletions apps/sim-core/packages/core/codegen.yml

This file was deleted.

Loading

0 comments on commit efe1801

Please sign in to comment.