From 71c0c5db3305811dcc6f4670af34846f32148f24 Mon Sep 17 00:00:00 2001 From: vmaubert <v.maubert@code-troopers.com> Date: Wed, 19 Jan 2022 12:01:22 +0100 Subject: [PATCH] =?UTF-8?q?build(npm):=20pr=C3=A9pare=20le=20projet=20pour?= =?UTF-8?q?=20une=20future=20migration=20en=20ESM=20(#881)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.dev.yml | 2 +- docker-compose.local.yml | 2 +- docker-compose.yml | 2 +- package.json | 14 +++++++------- src/@types/express-jwt.d.ts | 5 ----- src/api/graphql/resolvers/metas.ts | 2 +- src/server/rest.ts | 4 ++-- src/tools/geojson.ts | 3 +-- src/tools/matomo.ts | 1 - tsconfig.json | 17 ++++++++++++++--- 10 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 src/@types/express-jwt.d.ts diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 008622dc5..7cfe2580c 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -25,7 +25,7 @@ services: cron: container_name: camino_api_cron build: . - command: node ./dist/cron.js + command: node ./dist/src/cron.js depends_on: - db environment: diff --git a/docker-compose.local.yml b/docker-compose.local.yml index d2d054b23..091ca374e 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -22,7 +22,7 @@ services: cron: container_name: camino_api_cron build: . - command: node ./dist/cron.js + command: node ./dist/src/cron.js depends_on: - db environment: diff --git a/docker-compose.yml b/docker-compose.yml index de9b4531f..94579f3fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: cron: container_name: camino_api_cron image: caminofr/camino-api - command: node ./dist/cron.js + command: node ./dist/src/cron.js depends_on: - db environment: diff --git a/package.json b/package.json index 3132f015a..8590a9284 100644 --- a/package.json +++ b/package.json @@ -17,15 +17,15 @@ "node": ">=16.12.0", "npm": ">=7.24.0" }, - "main": "dist/index.js", + "main": "dist/src/index.js", "scripts": { "bim": "npm i && npm run build && npm run db:recreate && npm run db:import", - "build": "rm -rf dist && tsc && mkdir -p ./dist/api/graphql && cp -r ./src/api/graphql/schemas ./dist/api/graphql", + "build": "rm -rf dist && tsc && mkdir -p ./dist/src/api/graphql && cp -r ./src/api/graphql/schemas ./dist/src/api/graphql", "commit": "lint-staged && git-cz", - "daily": "node ./dist/scripts/daily.js", - "monthly": "node ./dist/scripts/monthly.js", + "daily": "node ./dist/src/scripts/daily.js", + "monthly": "node ./dist/src/scripts/monthly.js", "db:dump": "pg_dump --host=localhost --username=postgres --clean --if-exists --format=c --no-owner --no-privileges --dbname=camino --file=./backups/camino.sql", - "db:export": "rm -rf sources && node ./dist/scripts/database-to-json-export.js", + "db:export": "rm -rf sources && node ./dist/src/scripts/database-to-json-export.js", "db:import": "pg_restore --host=localhost --username=postgres --clean --if-exists --no-owner --no-privileges --dbname=camino ./backups/camino.sql", "db:prod-fetch": "scp -P 212 $u@camino.beta.gouv.fr:/srv/backups/camino.sql backups/", "db:public-dump": "ts-node ./src/knex/public-copy.ts && pg_dump --clean --if-exists --host=localhost --username=postgres --format=c --no-owner --no-privileges --dbname=camino_public --file=./backups/camino-public.sql && dropdb --host=localhost --username=postgres camino_public", @@ -42,9 +42,9 @@ "dev:schema": "node src/dev/api/graphql-dsl-to-query-convert.js", "dev:update": "npm-check-updates -u && npm install && npm audit fix", "docs": "rm -rf docs && typedoc src --sourcefile-url-prefix \"https://github.com/MTES-MCT/camino-api/blob/master/\"", - "documents:check": "node ./dist/scripts/documents-check.js", + "documents:check": "node ./dist/src/scripts/documents-check.js", "lint": "prettier --write . && eslint --fix .", - "start": "node ./dist/index.js", + "start": "node ./dist/src/index.js", "test": "prettier --check . && eslint . && npm run build && cross-env PGDATABASE=camino_tests jest --testPathIgnorePatterns=tests --runInBand --detectOpenHandles --forceExit", "test:unit": "cross-env PGDATABASE=camino_tests jest --testPathIgnorePatterns=tests --runInBand --detectOpenHandles --watch", "test:integration": "cross-env PGDATABASE=camino_tests JWT_SECRET=secret-tests jest --testPathIgnorePatterns=src --runInBand --detectOpenHandles --watch --testTimeout=20000", diff --git a/src/@types/express-jwt.d.ts b/src/@types/express-jwt.d.ts deleted file mode 100644 index 5fcda6b4b..000000000 --- a/src/@types/express-jwt.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare namespace Express { - interface User { - id: string - } -} diff --git a/src/api/graphql/resolvers/metas.ts b/src/api/graphql/resolvers/metas.ts index 9a2b95972..36b788817 100644 --- a/src/api/graphql/resolvers/metas.ts +++ b/src/api/graphql/resolvers/metas.ts @@ -79,7 +79,7 @@ import { demarcheDefinitionFind } from '../../../business/rules-demarches/defini import { userSuper } from '../../../database/user-super' import { titresEtapesHeritageContenuUpdate } from '../../../business/processes/titres-etapes-heritage-contenu-update' -const npmPackage = require('../../../../package.json') +import npmPackage from '../../../../package.json' const devises = async () => devisesGet() diff --git a/src/server/rest.ts b/src/server/rest.ts index 3ce340f68..7df47e19e 100644 --- a/src/server/rest.ts +++ b/src/server/rest.ts @@ -1,4 +1,4 @@ -import { IFormat, Index } from '../types' +import { IFormat, Index, IUser } from '../types' import express from 'express' import { join } from 'path' @@ -53,7 +53,7 @@ const restify = try { const result = await resolver( { query: req.query, params: req.params }, - req.user?.id + (req.user as unknown as IUser).id ) if (!result) { diff --git a/src/tools/geojson.ts b/src/tools/geojson.ts index 33c1eb3f1..f7336ffcd 100644 --- a/src/tools/geojson.ts +++ b/src/tools/geojson.ts @@ -1,5 +1,3 @@ -/// <reference types="../@types/geojson-rewind" /> -/// <reference types="../@types/turf-center" /> import rewind from 'geojson-rewind' import center from '@turf/center' @@ -13,6 +11,7 @@ import { Feature, FeatureCollection, Geometry } from '@turf/helpers' const geojsonFeatureMultiPolygon = (points: ITitrePoint[]) => ({ type: 'Feature', properties: { etapeId: points[0].titreEtapeId }, + coordinates: [], geometry: rewind( { type: 'MultiPolygon', diff --git a/src/tools/matomo.ts b/src/tools/matomo.ts index 23f3ac80a..d7fc442ad 100644 --- a/src/tools/matomo.ts +++ b/src/tools/matomo.ts @@ -1,4 +1,3 @@ -/// <reference types="../@types/matomo-tracker" /> import MatomoTracker from 'matomo-tracker' const matomo = diff --git a/tsconfig.json b/tsconfig.json index c12b039b3..ad7875727 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,15 +13,26 @@ "noImplicitReturns": true, "noImplicitThis": true, "outDir": "dist", - "rootDir": "src", + "rootDir": ".", "strict": true, "strictNullChecks": true, "sourceMap": true, "target": "ES2020", - "types": ["node", "jest"] + "types": ["node", "jest"], + "resolveJsonModule": true, + "paths": { + "geojson-rewind": ["./src/@types/geojson-rewind"], + "graphql-fields": ["./src/@types/graphql-fields"], + "html-to-text": ["./src/@types/html-to-text"], + "knex-db-manager": ["./src/@types/knex-db-manager"], + "matomo-tracker": ["./src/@types/matomo-tracker"], + "momoa": ["./src/@types/momoa"], + "turf-center": ["./src/@types/turf-center"], + "tus-node-server": ["./src/@types/tus-node-server"] + } }, "exclude": ["node_modules", "**/*.test.ts", "**/__mocks__/*"], - "include": ["src/**/*"], + "include": ["src/**/*", "sources/**/*"], "typedocOptions": { "out": "docs", "exclude": ["**/*+(.test|.spec|.e2e).ts", "**/__mocks__/**/*"], -- GitLab