Skip to content

Commit

Permalink
feat: add typescript paths to the boilerplate (#310)
Browse files Browse the repository at this point in the history
* feat: add typescript paths to the boilerplate

* build: removed uneeded dep
  • Loading branch information
CptSchnitz authored Sep 24, 2024
1 parent 04dee76 commit 1bb2444
Show file tree
Hide file tree
Showing 16 changed files with 1,890 additions and 1,226 deletions.
3,048 changes: 1,846 additions & 1,202 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"release": "standard-version",
"test": "npm run test:unit && npm run test:integration",
"prebuild": "npm run clean",
"build": "tsc --project tsconfig.build.json && npm run assets:copy",
"build": "tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run assets:copy",
"start": "npm run build && cd dist && node --require ./common/tracing.js ./index.js",
"start:dev": "npm run build && cd dist && node --enable-source-maps --require ./common/tracing.js ./index.js",
"assets:copy": "copyfiles -f ./config/* ./dist/config && copyfiles -f ./openapi3.yaml ./dist/ && copyfiles ./package.json dist",
Expand Down Expand Up @@ -78,7 +78,7 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.43.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest": "^29.7.0",
"jest-create-mock-instance": "^2.0.0",
"jest-html-reporters": "^3.1.4",
"jest-openapi": "^0.14.2",
Expand All @@ -87,7 +87,8 @@
"rimraf": "^5.0.1",
"standard-version": "^9.5.0",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"ts-jest": "^29.2.5",
"tsc-alias": "^1.8.10",
"typescript": "^5.1.3"
}
}
6 changes: 3 additions & 3 deletions src/containerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { trace, metrics as OtelMetrics } from '@opentelemetry/api';
import { DependencyContainer } from 'tsyringe/dist/typings/types';
import jsLogger, { LoggerOptions } from '@map-colonies/js-logger';
import { Metrics } from '@map-colonies/telemetry';
import { SERVICES, SERVICE_NAME } from './common/constants';
import { tracing } from './common/tracing';
import { InjectionObject, registerDependencies } from '@common/dependencyRegistration';
import { SERVICES, SERVICE_NAME } from '@common/constants';
import { tracing } from '@common/tracing';
import { resourceNameRouterFactory, RESOURCE_NAME_ROUTER_SYMBOL } from './resourceName/routes/resourceNameRouter';
import { InjectionObject, registerDependencies } from './common/dependencyRegistration';
import { anotherResourceRouterFactory, ANOTHER_RESOURCE_ROUTER_SYMBOL } from './anotherResource/routes/anotherResourceRouter';

export interface RegisterOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createTerminus } from '@godaddy/terminus';
import { Logger } from '@map-colonies/js-logger';
import { container } from 'tsyringe';
import config from 'config';
import { DEFAULT_SERVER_PORT, SERVICES } from './common/constants';
import { DEFAULT_SERVER_PORT, SERVICES } from '@common/constants';

import { getApp } from './app';

Expand Down
2 changes: 1 addition & 1 deletion src/resourceName/controllers/resourceNameController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BoundCounter, Meter } from '@opentelemetry/api-metrics';
import { RequestHandler } from 'express';
import httpStatus from 'http-status-codes';
import { injectable, inject } from 'tsyringe';
import { SERVICES } from '../../common/constants';
import { SERVICES } from '@common/constants';

import { IResourceNameModel, ResourceNameManager } from '../models/resourceNameManager';

Expand Down
2 changes: 1 addition & 1 deletion src/resourceName/models/resourceNameManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@map-colonies/js-logger';
import { inject, injectable } from 'tsyringe';
import { SERVICES } from '../../common/constants';
import { SERVICES } from '@common/constants';

const resourceInstance: IResourceNameModel = {
id: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/serverBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { inject, injectable } from 'tsyringe';
import { Logger } from '@map-colonies/js-logger';
import httpLogger from '@map-colonies/express-access-log-middleware';
import { collectMetricsExpressMiddleware, getTraceContexHeaderMiddleware } from '@map-colonies/telemetry';
import { SERVICES } from './common/constants';
import { IConfig } from './common/interfaces';
import { SERVICES } from '@common/constants';
import { IConfig } from '@common/interfaces';
import { RESOURCE_NAME_ROUTER_SYMBOL } from './resourceName/routes/resourceNameRouter';
import { ANOTHER_RESOURCE_ROUTER_SYMBOL } from './anotherResource/routes/anotherResourceRouter';

Expand Down
5 changes: 5 additions & 0 deletions tests/configurations/integration/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('../../../tsconfig.json');

/** @type {import('jest').Config} */
module.exports = {
transform: {
'^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }],
},
coverageReporters: ['text', 'html'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
collectCoverage: true,
collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!*/node_modules/', '!/vendor/**', '!*/common/**', '!**/models/**', '!<rootDir>/src/*'],
coverageDirectory: '<rootDir>/coverage',
Expand Down
5 changes: 5 additions & 0 deletions tests/configurations/unit/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('../../../tsconfig.json');

/** @type {import('jest').Config} */
module.exports = {
transform: {
'^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }],
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
testMatch: ['<rootDir>/tests/unit/**/*.spec.ts'],
coverageReporters: ['text', 'html'],
collectCoverage: true,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/anotherResource/anotherResourceName.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import jsLogger from '@map-colonies/js-logger';
import { trace } from '@opentelemetry/api';
import httpStatusCodes from 'http-status-codes';
import { getApp } from '../../../src/app';
import { SERVICES } from '../../../src/common/constants';
import { IAnotherResourceModel } from '../../../src/anotherResource/models/anotherResourceManager';
import { getApp } from '@src/app';
import { SERVICES } from '@src/common/constants';
import { IAnotherResourceModel } from '@src/anotherResource/models/anotherResourceManager';
import { AnotherResourceRequestSender } from './helpers/requestSender';

describe('resourceName', function () {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/docs/docs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import jsLogger from '@map-colonies/js-logger';
import { trace } from '@opentelemetry/api';
import httpStatusCodes from 'http-status-codes';
import { getApp } from '../../../src/app';
import { SERVICES } from '../../../src/common/constants';
import { getApp } from '@src/app';
import { SERVICES } from '@src/common/constants';
import { DocsRequestSender } from './helpers/docsRequestSender';

describe('docs', function () {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/resourceName/resourceName.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import jsLogger from '@map-colonies/js-logger';
import { trace } from '@opentelemetry/api';
import httpStatusCodes from 'http-status-codes';

import { getApp } from '../../../src/app';
import { SERVICES } from '../../../src/common/constants';
import { IResourceNameModel } from '../../../src/resourceName/models/resourceNameManager';
import { getApp } from '@src/app';
import { SERVICES } from '@common/constants';
import { IResourceNameModel } from '@src/resourceName/models/resourceNameManager';
import { ResourceNameRequestSender } from './helpers/requestSender';

describe('resourceName', function () {
Expand Down
3 changes: 3 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.test.json"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jsLogger from '@map-colonies/js-logger';
import { AnotherResourceManager } from '../../../../src/anotherResource/models/anotherResourceManager';
import { AnotherResourceManager } from '@src/anotherResource/models/anotherResourceManager';

let anotherResourceManager: AnotherResourceManager;

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/resourceName/models/resourceNameModel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jsLogger from '@map-colonies/js-logger';
import { ResourceNameManager } from '../../../../src/resourceName/models/resourceNameManager';
import { ResourceNameManager } from '@src/resourceName/models/resourceNameManager';

let resourceNameManager: ResourceNameManager;

Expand Down
12 changes: 9 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"module": "NodeNext",
"declaration": true,
"outDir": "dist",
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"moduleResolution": "NodeNext",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
"emitDecoratorMetadata": true,
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"],
"@tests/*": ["tests/*"],
"@common/*": ["src/common/*"]
}
},
"include": ["src"],
"exclude": ["node_modules", "dist", "tests"]
Expand Down

0 comments on commit 1bb2444

Please sign in to comment.