Skip to content

Commit

Permalink
Merge pull request #951 from MTES-MCT/chore-reduce-build-size
Browse files Browse the repository at this point in the history
Reduce build size
  • Loading branch information
Falinor authored Oct 9, 2024
2 parents c551bdf + 18dc602 commit 911c5e9
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 57 deletions.
21 changes: 15 additions & 6 deletions frontend/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ module.exports = {
// See https://github.com/alex3165/react-mapbox-gl/issues/931
// See https://github.com/mapbox/mapbox-gl-js/issues/10565
// eslint-disable-next-line import/no-webpack-loader-syntax
ignore: ['./node_modules/maplibre-gl/dist/maplibre-gl.js'],
},
ignore: ['./node_modules/maplibre-gl/dist/maplibre-gl.js']
}
},
typescript: {
// Disable type checking by react-scripts because it takes tsconfig.json
// blindlessly, and compiles tests and mocks, although it should not.
// Instead, we manually compile with tsconfig.build.json,
// as we would do using vite.
enableTypeChecking: false
},
jest: {
configure(config) {
config.rootDir = '.';
config.setupFiles = ['<rootDir>/jest.polyfills.js'];
config.setupFilesAfterEnv = [
'jest-extended/all',
'<rootDir>/src/setupTests.ts',
'<rootDir>/src/setupTests.ts'
];
config.testTimeout = 30_000;
config.transformIgnorePatterns = [
'<rootDir>/node_modules/(?!@codegouvfr)/.+\\.js$',
'<rootDir>/node_modules/.store/(?!@codegouvfr)/.+\\.js$',
'<rootDir>/node_modules/.store/(?!@codegouvfr)/.+\\.js$'
];
config.moduleNameMapper['^@zerologementvacant/models/fixtures$'] =
'<rootDir>/node_modules/@zerologementvacant/models/dist/test/fixtures.js';
return config;
},
},
}
}
};
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scripts": {
"clean": "rimraf build",
"icons": "only-include-used-icons",
"build": "yarn clean && yarn icons && DISABLE_ESLINT_PLUGIN=true craco build",
"build": "yarn clean && yarn icons && tsc -b tsconfig.build.json && DISABLE_ESLINT_PLUGIN=true craco build",
"dev": "yarn icons && DISABLE_ESLINT_PLUGIN=true craco start",
"test": "DISABLE_ESLINT_PLUGIN=true craco test",
"postinstall": "copy-dsfr-to-public"
Expand Down Expand Up @@ -93,6 +93,7 @@
"jest-fetch-mock": "^3.0.3",
"jest-watch-typeahead": "^2.2.2",
"randomstring": "^1.3.0",
"react-dev-utils": "^12.0.1",
"rimraf": "^5.0.10",
"sass": "^1.79.4",
"typescript": "^5.6.2",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/GroupHeader/GroupHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { http, HttpResponse } from 'msw';
import { Provider } from 'react-redux';
import { MemoryRouter as Router } from 'react-router-dom';

import { genGroupDTO, genUserDTO, GroupDTO } from '@zerologementvacant/models';
import { GroupDTO } from '@zerologementvacant/models';
import { genGroupDTO, genUserDTO } from '@zerologementvacant/models/fixtures';
import GroupHeader, { DISPLAY_GROUPS } from './GroupHeader';
import configureTestStore from '../../utils/test/storeUtils';
import { mockAPI } from '../../mocks/mock-api';
Expand Down
16 changes: 9 additions & 7 deletions frontend/src/mocks/handlers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import {
DatafoncierHousing,
DraftDTO,
EventDTO,
GroupDTO,
HousingDTO,
NoteDTO,
OwnerDTO,
UserDTO
} from '@zerologementvacant/models';
import {
genCampaignDTO,
genDatafoncierHousingDTO,
genDraftDTO,
genGroupDTO,
genHousingDTO,
genOwnerDTO,
genSenderDTO,
genUserDTO,
GroupDTO,
HousingDTO,
NoteDTO,
OwnerDTO,
UserDTO
} from '@zerologementvacant/models';
genUserDTO
} from '@zerologementvacant/models/fixtures';

const campaigns: CampaignDTO[] = Array.from({ length: 10 }, genCampaignDTO);

Expand Down
8 changes: 3 additions & 5 deletions frontend/src/mocks/handlers/group-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { faker } from '@faker-js/faker';
import { http, HttpResponse, RequestHandler } from 'msw';
import { constants } from 'node:http2';

import {
genGroupDTO,
GroupDTO,
GroupPayloadDTO
} from '@zerologementvacant/models';
import { GroupDTO, GroupPayloadDTO } from '@zerologementvacant/models';
import { genGroupDTO } from '@zerologementvacant/models/fixtures';

import config from '../../utils/config';
import data from './data';

Expand Down
17 changes: 11 additions & 6 deletions frontend/src/views/Campaign/test/CampaignView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import Notification from '../../../components/Notification/Notification';
import {
CampaignDTO,
DraftDTO,
genCampaignDTO,
genDraftDTO,
genHousingDTO,
genOwnerDTO,
genSenderDTO,
HousingDTO,
OwnerDTO,
SenderDTO
} from '@zerologementvacant/models';
import {
genCampaignDTO,
genDraftDTO,
genHousingDTO,
genOwnerDTO,
genSenderDTO
} from '@zerologementvacant/models/fixtures';

import data from '../../../mocks/handlers/data';
import { sources } from '../../../../test/event-source-mock';
import config from '../../../utils/config';
Expand Down Expand Up @@ -96,7 +99,9 @@ describe('Campaign view', () => {

renderComponent();

const rename = await screen.findByRole('button', { name: /^Modifier le nom/ });
const rename = await screen.findByRole('button', {
name: /^Modifier le nom/
});
await user.click(rename);
const modal = await screen.findByRole('dialog');
const input = within(modal).getByRole('textbox', {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/views/Group/GroupView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import { GroupDTO } from '@zerologementvacant/models';
import {
genCampaignDTO,
genGroupDTO,
genUserDTO,
GroupDTO
} from '@zerologementvacant/models';
genUserDTO
} from '@zerologementvacant/models/fixtures';

import data from '../../mocks/handlers/data';
import configureTestStore from '../../utils/test/storeUtils';
import GroupView from './GroupView';
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/views/Housing/test/HousingView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import {
genHousingDTO,
genHousingOwnerDTO,
genOwnerDTO,
HousingDTO,
HousingOwnerDTO,
OwnerDTO
} from '@zerologementvacant/models';
import {
genHousingDTO,
genHousingOwnerDTO,
genOwnerDTO
} from '@zerologementvacant/models/fixtures';
import configureTestStore from '../../../utils/test/storeUtils';
import HousingView from '../HousingView';
import data from '../../../mocks/handlers/data';
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/views/HousingList/HousingListView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import * as randomstring from 'randomstring';
import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import { HousingKind } from '@zerologementvacant/models';
import {
genDatafoncierHousingDTO,
genGroupDTO,
genUserDTO,
HousingKind
} from '@zerologementvacant/models';
genUserDTO
} from '@zerologementvacant/models/fixtures';

import HousingListView from './HousingListView';
import config from '../../utils/config';
import configureTestStore from '../../utils/test/storeUtils';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Login/LoginView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter as Router, Route } from 'react-router-dom';

import { genUserDTO } from '@zerologementvacant/models';
import { genUserDTO } from '@zerologementvacant/models/fixtures';
import { store } from '../../store/store';
import LoginView from './LoginView';
import data from '../../mocks/handlers/data';
Expand Down
8 changes: 3 additions & 5 deletions frontend/test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import { Prospect } from '../src/models/Prospect';
import { LocalityKinds } from '../src/models/Locality';
import { Group } from '../src/models/Group';
import { DatafoncierHousing } from '../../shared';
import {
AddressKinds,
genAddressDTO,
HousingStatus
} from '@zerologementvacant/models';
import { AddressKinds, HousingStatus } from '@zerologementvacant/models';
import { genAddressDTO } from '@zerologementvacant/models/fixtures';

import fp from 'lodash/fp';

export const genBoolean = () => Math.random() < 0.5;
Expand Down
18 changes: 14 additions & 4 deletions frontend/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"moduleResolution": "bundler"
},
"exclude": ["node_modules", "dist","src/**/*.test.ts", "src/**/*.test.tsx"]
"references": [
{ "path": "../packages/models/tsconfig.build.json" },
{ "path": "../packages/utils/tsconfig.build.json" },
{ "path": "../queue/tsconfig.build.json" }
],
"exclude": [
"node_modules",
"build",
"src/mocks/**/*.ts",
"src/setupTests.ts",
"src/**/*.test.ts",
"src/**/*.test.tsx",
"test/fixtures.test.ts"
]
}
3 changes: 0 additions & 3 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "@tsconfig/create-react-app/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node"
},
"include": ["src"]
}
16 changes: 13 additions & 3 deletions packages/models/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{
"name": "@zerologementvacant/models",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./fixtures": {
"import": "./dist/test/fixtures.js",
"require": "./dist/test/fixtures.js",
"types": "./dist/test/fixtures.d.ts"
}
},
"scripts": {
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
"build": "tsc -b tsconfig.build.json",
"test": "jest",
"dev": "nodemon --watch src -e ts --exec 'yarn build'"
},
"dependencies": {
"@faker-js/faker": "^8.4.1",
"@zerologementvacant/draft": "workspace:*",
"lodash": "^4.17.21"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@tsconfig/node20": "^20.1.4",
"@types/geojson": "^7946.0.14",
"@types/jest": "^29.5.13",
Expand Down
1 change: 0 additions & 1 deletion packages/models/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './test/fixtures';
export * from './AddressDTO';
export * from './BeneficiaryCount';
export * from './BuildingPeriod';
Expand Down
7 changes: 6 additions & 1 deletion packages/models/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "./tsconfig.json",
"references": [{ "path": "../draft/tsconfig.build.json" }],
"exclude": ["node_modules", "dist", "src/**/*.test.ts"]
"exclude": [
"node_modules",
"dist",
"src/**/*.test.ts",
"src/test/setup-tests.ts"
]
}
10 changes: 6 additions & 4 deletions server/src/controllers/ownerController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { v4 as uuidv4 } from 'uuid';
import {
AddressDTO,
AddressKinds,
genHousingOwnerDTO,
HousingOwnerPayloadDTO,
OwnerDTO,
OwnerPayloadDTO
Expand All @@ -31,7 +30,7 @@ import {
OwnerEventDBO,
ownerEventsTable
} from '~/repositories/eventRepository';
import { OwnerApi, toOwnerDTO } from '~/models/OwnerApi';
import { OwnerApi } from '~/models/OwnerApi';
import db from '~/infra/database';
import {
banAddressesTable,
Expand Down Expand Up @@ -309,8 +308,11 @@ describe('Owner API', () => {
rank: number
): HousingOwnerPayloadDTO {
return {
...genHousingOwnerDTO(toOwnerDTO(owner)),
rank
id: owner.id,
rank: rank,
locprop: null,
idprocpte: null,
idprodroit: null
};
}

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9414,6 +9414,7 @@ __metadata:
prop-types: "npm:^15.8.1"
randomstring: "npm:^1.3.0"
react: "npm:^18.3.1"
react-dev-utils: "npm:^12.0.1"
react-dom: "npm:^18.3.1"
react-map-gl: "npm:^7.1.7"
react-redux: "npm:^8.1.3"
Expand Down

0 comments on commit 911c5e9

Please sign in to comment.