Skip to content

Commit

Permalink
Refactor root imports (#2722)
Browse files Browse the repository at this point in the history
* refactor root imports. removed @

* Fix migration steps

* fix scripts

* Fix Logger.log

* Rename build:dev:client -> run:dev:client

* clean up scripts

* migrate panEu post data migration script

* fix run:prod command

* update test paths

* fix utils import / update jest utils moduleNameMapper

* add migrations:run to run:dev:server

* test import 'dotenv/config'

* integration test fix

* debug db config

* Revert "debug db config"

This reverts commit c797f0d.

* Revert "integration test fix"

This reverts commit 376a638.

* test

* used yarn command instead of sh

---------

Co-authored-by: sorja <[email protected]>
Co-authored-by: Roberto Fontanarosa <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2023
1 parent aded9f1 commit c8456fc
Show file tree
Hide file tree
Showing 930 changed files with 3,833 additions and 3,737 deletions.
26 changes: 15 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
jest: true,
node: true,
},
plugins: ['prettier', 'simple-import-sort', 'react-hooks'],
plugins: ['prettier', 'simple-import-sort', 'react-hooks', 'import'],
rules: {
'no-underscore-dangle': 0,
'prettier/prettier': 1,
Expand Down Expand Up @@ -75,15 +75,10 @@ module.exports = {
'^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)',
'^@?\\w',
],
['^@meta(\\/\\w)*'],
[
'^@client\\/store(\\/\\w)*',
'^@client\\/hooks(\\/\\w)*',
'^@client\\components(\\/\\w)*',
'^@client(\\/\\w)*',
],
['^@server(\\/\\w)*'],
['^@test(\\/\\w)*'],
['^meta(\\/\\w)*'],
['^client\\/store(\\/\\w)*', '^client\\/hooks(\\/\\w)*', '^client\\components(\\/\\w)*', '^client(\\/\\w)*'],
['^server(\\/\\w)*'],
['^test(\\/\\w)*'],
[
'^\\.\\.(?!/?$)',
'^\\.\\./?$', // Parent imports. Put `..` last.
Expand All @@ -100,10 +95,19 @@ module.exports = {
version: 'detect',
},
'import/resolver': {
node: {},
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
webpack: {
config: 'webpack.config.babel.js',
},
// typescript: {},
},
// 'import/resolver': {
// node: {},
// webpack: {
// config: 'webpack.config.babel.js',
// },
// },
},
}
15 changes: 7 additions & 8 deletions .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Install Playwright Browsers
run: npx playwright install --with-deps
# - run: yarn run-migrations
# env:
# PGHOST: localhost
# PGPORT: 5442
# PGDATABASE: frap-dev
# PGUSER: frap
# PGPASSWORD: frap
# Migrations are run on yarn build
- run: yarn migrations:run
env:
PGHOST: localhost
PGPORT: 5442
PGDATABASE: frap-dev
PGUSER: frap
PGPASSWORD: frap
- run: yarn build
env:
PGHOST: localhost
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 140,
"singleQuote": true,
"semi": false,
"trailingComma": "es5"
Expand Down
2 changes: 1 addition & 1 deletion .src.legacy/core/auth/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Lang } from '@meta/lang'
import { Lang } from 'meta/lang'

import { AssessmentType } from '../assessment'
import { Role } from './role'
Expand Down
19 changes: 13 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ module.exports = {
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/'],
roots: ['<rootDir>'],
rootDir: 'src',
verbose: true,
testMatch: ['**/*.test.ts'],
moduleDirectories: ['node_modules'],
moduleNameMapper: {
'@i18n/(.*)': '<rootDir>/src/i18n/$1',
'@client/(.*)': '<rootDir>/src/client/$1',
'@meta/(.*)': '<rootDir>/src/meta/$1',
'@server/(.*)': '<rootDir>/src/server/$1',
'@test/(.*)': '<rootDir>/src/test/$1',
'@utils/(.*)': '<rootDir>/src/utils/$1',
'i18n/(.*)': '<rootDir>/i18n/$1',
'client/(.*)': '<rootDir>/client/$1',
'meta/(.*)': '<rootDir>/meta/$1',
'server/(.*)': '<rootDir>/server/$1',
'test/(.*)': '<rootDir>/test/$1',
'utils/objects(.*)': '<rootDir>/utils/objects$1',
'utils/arrays(.*)': '<rootDir>/utils/arrays$1',
'utils/dates(.*)': '<rootDir>/utils/dates$1',
'utils/functions(.*)': '<rootDir>/utils/functions$1',
'utils/numbers(.*)': '<rootDir>/utils/numbers$1',
'utils/strings(.*)': '<rootDir>/utils/strings$1',
'utils/uuids(.*)': '<rootDir>/utils/uuids$1',
},
globals: {
'ts-jest': {
Expand Down
11 changes: 6 additions & 5 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"target": "es2019",
"baseUrl": "./",
"paths": {
"@i18n/*": ["./src/i18n/*"],
"@client/*": ["./src/client/*"],
"@meta/*": ["./src/meta/*"],
"@server/*": ["./src/server/*"],
"@utils/*": ["./src/utils/*"]
"i18n/*": ["./src/i18n/*"],
"client/*": ["./src/client/*"],
"meta/*": ["./src/meta/*"],
"server/*": ["./src/server/*"],
"test/*": ["./src/test/*"],
"utils/*": ["./src/utils/*"]
}
},
"include": ["src"]
Expand Down
41 changes: 19 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@
"yarn": "^1.22.19"
},
"scripts": {
"migrate-panEuropean:migration": "ts-node tools/dataMigration/panEuropean.ts && yarn jest --no-cache --detectOpenHandles --setupFiles dotenv/config --config src/test/dataMigration/jest.config.panEu.js",
"build": "yarn build:client && yarn build:server && yarn build:copy && yarn run-migrations",
"build:server": "yarn tsc --project tsconfig.server.json && yarn tscpaths -v -p tsconfig.server.paths.json -s ./server -o ./dist",
"build:client": "cross-env NODE_ENV=production webpack --config webpack.config.babel.js",
"build:copy": "shx cp -Rf src/server/db/migration/* dist/server/db/migration/. && shx cp -Rf web-resources dist/ && shx cp -Rf src/server/static dist/server/",
"build:watch": "cross-env NODE_ENV=development webpack --config webpack.config.babel.js --watch",
"build:dev-server": "cross-env NODE_ENV=development webpack serve --config webpack.config.babel.js",
"migrate-panEuropean:migration": "ts-node tools/dataMigration/panEuropean.ts && ts-node src/test/dataMigration/panEuPostDataMigration.ts",
"build": "run-s build:prod:client build:prod:server build:prod:server:resources",
"build:prod:client": "cross-env NODE_ENV=production webpack --config webpack.config.babel.js",
"build:prod:server": "yarn tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json",
"build:prod:server:resources": "shx cp -Rf src/server/db/migration/* dist/server/db/migration/. && shx cp -Rf web-resources dist/ && shx cp -Rf src/server/static dist/server/",
"build:prod:report": "cross-env NODE_ENV=production BUILD_REPORT=true webpack --display-error-details -p --config webpack.config.babel.js",
"build:prod": "cross-env NODE_ENV=production webpack --display-error-details -p --config webpack.config.babel.js",
"clean": "shx rm -rf dist/",
"start": "node dist/server",
"watch": "run-p build:dev-server watch:server",
"watch-debug": "run-p build:dev-server watch:server-debug",
"watch:server": "ts-node-dev src/server",
"watch:server-debug": "cross-env NODE_ENV=development nodemon -e js --inspect --watch server src/server/serverLocal.js",
"create-migration": "./src/server/db/migration/create-migration.sh",
"create-migration-step": "src/test/migrations/create-migration-step.sh",
"run-migrations": "./src/server/db/migration/run-migrations.sh",
"run-migration-steps": "yarn jest --verbose false --no-cache --detectOpenHandles --setupFiles dotenv/config --config src/test/migrations/jest.config.js",
"heroku-prebuild": "echo \"//npm.pkg.github.com/:_authToken=${NPM_GITHUB_TOKEN}\" >> .npmrc",
"migrations:create": "./src/server/db/migration/create-migration.sh",
"migrations:run": "./src/server/db/migration/run-migrations.sh",
"migration-steps:run": "ts-node src/test/migrations/",
"migration-steps:create": "src/test/migrations/create-migration-step.sh",
"run:dev": "run-p run:dev:client run:dev:server",
"run:dev:client": "cross-env NODE_ENV=development webpack serve --config webpack.config.babel.js",
"run:dev:server": "yarn migrations:run && ts-node-dev src/server/start",
"run:prod": "run-s build start",
"run:prod:server": "node dist/server/start",
"start": "run-s migrations:run run:prod:server",
"generate-metacache": "yarn jest --verbose false --no-cache --detectOpenHandles --setupFiles dotenv/config --config src/test/generateMetaCache/jest.config.js",
"migrate": "run-s run-migrations run-migration-steps generate-metacache",
"//test": "mochapack --webpack-config webpack.config.babel.test.js",
"test": "run-s test:integration",
"test:integration": "yarn jest --no-cache --detectOpenHandles --setupFiles dotenv/config",
Expand All @@ -36,9 +34,7 @@
"postversion": "git push --tags && echo \"Successfully released version $npm_package_version!\"",
"prepare": "husky install",
"postinstall": "husky install",
"prod": "yarn build && yarn start",
"pre-commit": "lint-staged && eslint --cache --fix",
"heroku-prebuild": "echo \"//npm.pkg.github.com/:_authToken=${NPM_GITHUB_TOKEN}\" >> .npmrc",
"geo:forest-estimations-import": "ts-node tools/geo/forestEstimationsImport.ts",
"geo:bounds-import": "ts-node tools/geo/boundsImport.ts"
},
Expand Down Expand Up @@ -116,8 +112,9 @@
"eslint": "8.22.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-import-resolver-webpack": "^0.13.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
Expand Down Expand Up @@ -151,7 +148,7 @@
"ts-migrate": "^0.1.28",
"ts-node": "^10.7.0",
"ts-node-dev": "^2.0.0",
"tscpaths": "^0.0.9",
"tsc-alias": "^1.8.6",
"turndown": "^7.1.1",
"typescript": "^4.6.3",
"webpack": "^5.71.0",
Expand Down
2 changes: 1 addition & 1 deletion src/client/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './i18n'

import '@client/styles/style.scss'
import 'client/styles/style.scss'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { Provider } from 'react-redux'
Expand Down
12 changes: 6 additions & 6 deletions src/client/components/AreaSelector/AreaSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { useNavigate } from 'react-router-dom'

import classNames from 'classnames'

import { ClientRoutes } from '@meta/app'
import { Areas, CountryIso, Global, RegionCode } from '@meta/area'
import { Users } from '@meta/user'
import { ClientRoutes } from 'meta/app'
import { Areas, CountryIso, Global, RegionCode } from 'meta/area'
import { Users } from 'meta/user'

import { useAssessment, useCycle } from '@client/store/assessment'
import { useUser } from '@client/store/user'
import { useIsGeoPage } from '@client/hooks'
import { useAssessment, useCycle } from 'client/store/assessment'
import { useUser } from 'client/store/user'
import { useIsGeoPage } from 'client/hooks'

import Icon from '../Icon'
import CountryList from './CountryList'
Expand Down
10 changes: 5 additions & 5 deletions src/client/components/AreaSelector/CountryList/CountryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useTranslation } from 'react-i18next'

import { i18n } from 'i18next'

import { Areas, CountryIso, Global, Region, RegionCode } from '@meta/area'
import { UserRoles } from '@meta/user/userRoles'
import { Areas, CountryIso, Global, Region, RegionCode } from 'meta/area'
import { UserRoles } from 'meta/user/userRoles'

import { useCountries, useCycle, useRegionGroups } from '@client/store/assessment'
import { useIsPanEuropean } from '@client/hooks'
import { checkMatch } from '@client/utils'
import { useCountries, useCycle, useRegionGroups } from 'client/store/assessment'
import { useIsPanEuropean } from 'client/hooks'
import { checkMatch } from 'client/utils'

import { useUserCountryISOs } from './hooks/useUserCountryISOs'
import CountryListDownload from './CountryListDownload'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import React from 'react'
import { CSVLink } from 'react-csv'
import { useTranslation } from 'react-i18next'

import { Areas } from '@meta/area'
import { Users } from '@meta/user'
import { Areas } from 'meta/area'
import { Users } from 'meta/user'

import { useCountries } from '@client/store/assessment'
import { useUser, useUserCountries } from '@client/store/user'
import Icon from '@client/components/Icon'
import { Dates } from '@client/utils'
import { useCountries } from 'client/store/assessment'
import { useUser, useUserCountries } from 'client/store/user'
import Icon from 'client/components/Icon'
import { Dates } from 'client/utils'

const CountryListDownload: React.FC = () => {
const user = useUser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useTranslation } from 'react-i18next'

import { i18n } from 'i18next'

import { Areas, Country, CountryIso, Global, RegionCode } from '@meta/area'
import { Assessments } from '@meta/assessment'
import { RoleName, Users } from '@meta/user'
import { UserRoles } from '@meta/user/userRoles'
import { Areas, Country, CountryIso, Global, RegionCode } from 'meta/area'
import { Assessments } from 'meta/assessment'
import { RoleName, Users } from 'meta/user'
import { UserRoles } from 'meta/user/userRoles'

import { useAssessment, useCountries, useCycle } from '@client/store/assessment'
import { checkMatch } from '@client/utils'
import { useAssessment, useCountries, useCycle } from 'client/store/assessment'
import { checkMatch } from 'client/utils'

import CountryListRow from '../CountryListRow'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useTranslation } from 'react-i18next'

import classNames from 'classnames'

import { Areas, CountryIso, Global, RegionCode } from '@meta/area'
import { UserRoles } from '@meta/user/userRoles'
import { Areas, CountryIso, Global, RegionCode } from 'meta/area'
import { UserRoles } from 'meta/user/userRoles'

import { useCountry } from '@client/store/assessment'
import { useIsCycleLanding } from '@client/hooks'
import { Dates } from '@client/utils'
import { useCountry } from 'client/store/assessment'
import { useIsCycleLanding } from 'client/hooks'
import { Dates } from 'client/utils'

type Props = {
country: { countryIso: CountryIso | Global | RegionCode }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CountryIso } from '@meta/area'
import { CycleUuid } from '@meta/assessment'
import { RoleName, Users } from '@meta/user'
import { UserRoles } from '@meta/user/userRoles'
import { CountryIso } from 'meta/area'
import { CycleUuid } from 'meta/assessment'
import { RoleName, Users } from 'meta/user'
import { UserRoles } from 'meta/user/userRoles'

import { useCountries, useCycle } from '@client/store/assessment'
import { useUser, useUserCountries } from '@client/store/user'
import { useCountries, useCycle } from 'client/store/assessment'
import { useUser, useUserCountries } from 'client/store/user'

export const useUserCountryISOs = (): Record<CycleUuid, Record<string, Array<CountryIso>>> => {
const cycle = useCycle()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useParams } from 'react-router-dom'

import { AssessmentNames } from '@meta/assessment'
import { AssessmentNames } from 'meta/assessment'

type Props = {
components: Record<string, React.FC<{ query?: string }>>
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import './Autocomplete.scss'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'

import { Objects } from '@utils/objects'
import { Objects } from 'utils/objects'
import classNames from 'classnames'
import { useCombobox, UseComboboxStateChange } from 'downshift'

import AutocompleteInput from '@client/components/Autocomplete/AutocompleteInput'
import AutocompleteInput from 'client/components/Autocomplete/AutocompleteInput'

type Option = {
label: string
Expand Down
16 changes: 8 additions & 8 deletions src/client/components/ButtonTableClear/ButtonTableClear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { useTranslation } from 'react-i18next'

import classNames from 'classnames'

import { Table } from '@meta/assessment'
import { Table } from 'meta/assessment'

import { useAppDispatch } from '@client/store'
import { useCycle } from '@client/store/assessment'
import { DataActions } from '@client/store/data'
import { useIsDataLocked } from '@client/store/ui/dataLock'
import { useCountryIso } from '@client/hooks'
import { useIsPrint } from '@client/hooks/useIsPath'
import Icon from '@client/components/Icon'
import { useAppDispatch } from 'client/store'
import { useCycle } from 'client/store/assessment'
import { DataActions } from 'client/store/data'
import { useIsDataLocked } from 'client/store/ui/dataLock'
import { useCountryIso } from 'client/hooks'
import { useIsPrint } from 'client/hooks/useIsPath'
import Icon from 'client/components/Icon'

type Props = {
disabled?: boolean
Expand Down
6 changes: 3 additions & 3 deletions src/client/components/ButtonTableExport/ButtonTableExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CSVLink } from 'react-csv'

import classNames from 'classnames'

import { useIsDataLocked } from '@client/store/ui/dataLock'
import { useIsPrint } from '@client/hooks/useIsPath'
import Icon from '@client/components/Icon'
import { useIsDataLocked } from 'client/store/ui/dataLock'
import { useIsPrint } from 'client/hooks/useIsPath'
import Icon from 'client/components/Icon'

import * as Utils from './utils'

Expand Down
2 changes: 1 addition & 1 deletion src/client/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import { ChartData, ChartOptions, DefaultDataPoint, Plugin } from 'chart.js'
import Chart, { ChartTypeRegistry } from 'chart.js/auto'

import { useOnUpdate } from '@client/hooks'
import { useOnUpdate } from 'client/hooks'

export type ChartDataType = ChartData<keyof ChartTypeRegistry, DefaultDataPoint<keyof ChartTypeRegistry>, unknown>

Expand Down
Loading

0 comments on commit c8456fc

Please sign in to comment.