Skip to content

Commit

Permalink
refactor: remove .js ext from ALL local imports across the codebase
Browse files Browse the repository at this point in the history
ideally, imports should reference the source file, not the build file.
the triger for this change was a requirement for jest to work directly with typescript files rather than the build output. but not just that, this change should move the project to a more standard direction and also improve code editors to better understand the code structure since now they reference the source files.
  • Loading branch information
enapupe committed Nov 12, 2023
1 parent 0ef55b4 commit 419cd60
Show file tree
Hide file tree
Showing 115 changed files with 417 additions and 400 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ on:
push:
branches:
- develop
- test
pull_request:

jobs:
build:
runs-on: 'ubuntu-latest'


steps:
- name: 'Checkout Project'
uses: 'actions/checkout@v4'

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '16.15'
cache: 'yarn'

- name: 'Checkout Project'
uses: 'actions/checkout@v3'
with:
fetch-depth: 1
- name: Install dependencies
run: yarn install --immutable

- name: Install Dependencies and lint code
run: yarn install && yarn lint
- name: Lint code
run: yarn lint

- name: Start MongoDB
uses: supercharge/[email protected]
Expand All @@ -44,8 +48,8 @@ jobs:
run: |
docker container restart mongodb
- name: Build and run tests
run: yarn test
env:
NODE_OPTIONS: --experimental-vm-modules
- name: Run tests
run: yarn test:ci

- name: Build files
run: yarn build-release
8 changes: 6 additions & 2 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', './build/'],
testMatch: [
'<rootDir>/build/**/__tests__/*.js'
'<rootDir>/**/__tests__/*.ts'
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"scripts": {
"lint": "yarn ts-standard",
"fix": "yarn ts-standard --fix",
"test": "yarn build && cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
"test": "jest",
"test:ci": "jest --runInBand --ci",
"build": "tsc -p tsconfig.json",
"build-release": "tsc -p tsconfig.release.json",
"clean": "tsc -b --clean && rm -rf build/*",
Expand Down
2 changes: 1 addition & 1 deletion src/GradeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getScale, GradeScales, GradeScalesTypes } from '@openbeta/sandbag'
import isoCountries from 'i18n-iso-countries'
import { DisciplineType, ClimbGradeContextType } from './db/ClimbTypes.js'
import { DisciplineType, ClimbGradeContextType } from './db/ClimbTypes'

/**
* Grade systems have minor variations between countries. gradeContext is a
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/areas.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApolloServer } from 'apollo-server'
import muuid from 'uuid-mongodb'
import { jest } from '@jest/globals'
import MutableAreaDataSource from '../model/MutableAreaDataSource.js'
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js'
import { AreaType } from '../db/AreaTypes.js'
import { OrgType, OrganizationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes.js'
import { queryAPI, setUpServer } from '../utils/testUtils.js'
import { muuidToString } from '../utils/helpers.js'
import MutableAreaDataSource from '../model/MutableAreaDataSource'
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource'
import { AreaType } from '../db/AreaTypes'
import { OrgType, OrganizationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes'
import { queryAPI, setUpServer } from '../utils/testUtils'
import { muuidToString } from '../utils/helpers'

jest.setTimeout(60000)

Expand Down
12 changes: 10 additions & 2 deletions src/__tests__/gradeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { DisciplineType } from '../db/ClimbTypes.js'
import { sanitizeDisciplines, createGradeObject, gradeContextToGradeScales } from '../GradeUtils.js'
import { DisciplineType } from '../db/ClimbTypes'
import { sanitizeDisciplines, createGradeObject, gradeContextToGradeScales } from '../GradeUtils'

beforeAll(() => {
console.warn = jest.fn()
})

afterAll(() => {
jest.mocked(console.warn).mockReset()
})

describe('Test grade utilities', () => {
it('sanitizes bad discipline object', () => {
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/history.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApolloServer } from 'apollo-server'
import muuid from 'uuid-mongodb'
import { jest } from '@jest/globals'
import MutableAreaDataSource from '../model/MutableAreaDataSource.js'
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js'
import MutableClimbDataSource from '../model/MutableClimbDataSource.js'
import { AreaType } from '../db/AreaTypes.js'
import { OrgType, OrganizationType } from '../db/OrganizationTypes.js'
import { muuidToString } from '../utils/helpers.js'
import { queryAPI, setUpServer } from '../utils/testUtils.js'
import MutableAreaDataSource from '../model/MutableAreaDataSource'
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource'
import MutableClimbDataSource from '../model/MutableClimbDataSource'
import { AreaType } from '../db/AreaTypes'
import { OrgType, OrganizationType } from '../db/OrganizationTypes'
import { muuidToString } from '../utils/helpers'
import { queryAPI, setUpServer } from '../utils/testUtils'

jest.setTimeout(60000)

Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/organizations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApolloServer } from 'apollo-server'
import muuid from 'uuid-mongodb'
import { jest } from '@jest/globals'
import MutableAreaDataSource from '../model/MutableAreaDataSource.js'
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js'
import { AreaType } from '../db/AreaTypes.js'
import { OrgType, OrganizationType, OperationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes.js'
import { changelogDataSource } from '../model/ChangeLogDataSource.js'
import { queryAPI, setUpServer } from '../utils/testUtils.js'
import { muuidToString } from '../utils/helpers.js'
import MutableAreaDataSource from '../model/MutableAreaDataSource'
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource'
import { AreaType } from '../db/AreaTypes'
import { OrgType, OrganizationType, OperationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes'
import { changelogDataSource } from '../model/ChangeLogDataSource'
import { queryAPI, setUpServer } from '../utils/testUtils'
import { muuidToString } from '../utils/helpers'
import { validate as validateMuuid } from 'uuid'

jest.setTimeout(60000)
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/ticks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApolloServer } from 'apollo-server'
import muuid from 'uuid-mongodb'
import { jest } from '@jest/globals'
import { queryAPI, setUpServer } from '../utils/testUtils.js'
import { muuidToString } from '../utils/helpers.js'
import { TickInput } from '../db/TickTypes.js'
import TickDataSource from '../model/TickDataSource.js'
import UserDataSource from '../model/UserDataSource.js'
import { UpdateProfileGQLInput } from '../db/UserTypes.js'
import { queryAPI, setUpServer } from '../utils/testUtils'
import { muuidToString } from '../utils/helpers'
import { TickInput } from '../db/TickTypes'
import TickDataSource from '../model/TickDataSource'
import UserDataSource from '../model/UserDataSource'
import { UpdateProfileGQLInput } from '../db/UserTypes'

jest.setTimeout(60000)

Expand Down
4 changes: 2 additions & 2 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import permissions from './permissions.js'
import { createContext } from './middleware.js'
import permissions from './permissions'
import { createContext } from './middleware'
export { permissions, createContext }
6 changes: 3 additions & 3 deletions src/auth/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import muid from 'uuid-mongodb'
import { AuthUserType } from '../types.js'
import { verifyJWT } from './util.js'
import { logger } from '../logger.js'
import { AuthUserType } from '../types'
import { verifyJWT } from './util'
import { logger } from '../logger'

/**
* Create a middleware context for Apollo server
Expand Down
2 changes: 1 addition & 1 deletion src/auth/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shield, allow, and, or } from 'graphql-shield'
import { isEditor, isUserAdmin, isOwner, isValidEmail, isMediaOwner } from './rules.js'
import { isEditor, isUserAdmin, isOwner, isValidEmail, isMediaOwner } from './rules'

const permissions = shield({
Query: {
Expand Down
4 changes: 2 additions & 2 deletions src/auth/rules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { rule, inputRule } from 'graphql-shield'

import MediaDataSource from '../model/MutableMediaDataSource.js'
import { MediaObjectGQLInput } from '../db/MediaObjectTypes.js'
import MediaDataSource from '../model/MutableMediaDataSource'
import { MediaObjectGQLInput } from '../db/MediaObjectTypes'

export const isEditor = rule()(async (parent, args, ctx, info) => {
return _hasUserUuid(ctx) && ctx.user.roles.includes('editor')
Expand Down
2 changes: 1 addition & 1 deletion src/auth/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jwksClient from 'jwks-rsa'
import jwt from 'jsonwebtoken'

import { checkVar } from '../db/index.js'
import { checkVar } from '../db/index'

const auth0Domain = checkVar('AUTH0_DOMAIN')
const auth0Kid = checkVar('AUTH0_KID')
Expand Down
8 changes: 4 additions & 4 deletions src/db/AreaSchema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import mongoose from 'mongoose'
import muuid from 'uuid-mongodb'

import { AreaType, IAreaContent, IAreaMetadata, AggregateType, CountByGroupType, CountByDisciplineType, CountByGradeBandType, DisciplineStatsType, OperationType } from './AreaTypes.js'
import { PointSchema } from './ClimbSchema.js'
import { ChangeRecordMetadataType } from './ChangeLogType.js'
import { GradeContexts } from '../GradeUtils.js'
import { AreaType, IAreaContent, IAreaMetadata, AggregateType, CountByGroupType, CountByDisciplineType, CountByGradeBandType, DisciplineStatsType, OperationType } from './AreaTypes'
import { PointSchema } from './ClimbSchema'
import { ChangeRecordMetadataType } from './ChangeLogType'
import { GradeContexts } from '../GradeUtils'

const { Schema, connection } = mongoose

Expand Down
10 changes: 5 additions & 5 deletions src/db/AreaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import mongoose from 'mongoose'
import { MUUID } from 'uuid-mongodb'

import { BBox, Point } from '@turf/helpers'
import { ClimbType } from './ClimbTypes.js'
import { ChangeRecordMetadataType } from './ChangeLogType.js'
import { GradeContexts } from '../GradeUtils.js'
import { ExperimentalAuthorType } from './UserTypes.js'
import { AuthorMetadata } from '../types.js'
import { ClimbType } from './ClimbTypes'
import { ChangeRecordMetadataType } from './ChangeLogType'
import { GradeContexts } from '../GradeUtils'
import { ExperimentalAuthorType } from './UserTypes'
import { AuthorMetadata } from '../types'

/**
* Areas are a grouping mechanism in the OpenBeta data model that allow
Expand Down
4 changes: 2 additions & 2 deletions src/db/ChangeLogSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose'

import { ChangeLogType, SupportedCollectionTypes } from './ChangeLogType.js'
import { OperationType } from './AreaTypes.js'
import { ChangeLogType, SupportedCollectionTypes } from './ChangeLogType'
import { OperationType } from './AreaTypes'

const { Schema, connection } = mongoose

Expand Down
6 changes: 3 additions & 3 deletions src/db/ChangeLogType.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mongose from 'mongoose'
import { MUUID } from 'uuid-mongodb'

import { OperationType as AreaOpType, AreaType } from './AreaTypes.js'
import { ClimbEditOperationType, ClimbType } from './ClimbTypes.js'
import { OperationType as OrganizationOpType, OrganizationType } from './OrganizationTypes.js'
import { OperationType as AreaOpType, AreaType } from './AreaTypes'
import { ClimbEditOperationType, ClimbType } from './ClimbTypes'
import { OperationType as OrganizationOpType, OrganizationType } from './OrganizationTypes'

export type DBOperation = 'insert' | 'update' | 'delete'
export enum DocumentKind {
Expand Down
8 changes: 4 additions & 4 deletions src/db/ClimbHistorySchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mongoose from 'mongoose'
import muuid from 'uuid-mongodb'
import { ClimbSchema } from './ClimbSchema.js'
import { AreaSchema } from './AreaSchema.js'
import ClimbHistoryType, { AreaHistoryType } from './ClimbHistoryType.js'
import ChangeEventType from './ChangeEventType.js'
import { ClimbSchema } from './ClimbSchema'
import { AreaSchema } from './AreaSchema'
import ClimbHistoryType, { AreaHistoryType } from './ClimbHistoryType'
import ChangeEventType from './ChangeEventType'
import { ClimbType } from './ClimbTypes'
import { AreaType } from './AreaTypes'

Expand Down
6 changes: 3 additions & 3 deletions src/db/ClimbSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import muuid from 'uuid-mongodb'
import { Point } from '@turf/helpers'
import { GradeScalesTypes } from '@openbeta/sandbag'

import { ClimbType, IClimbMetadata, IClimbContent, SafetyType, ClimbEditOperationType } from './ClimbTypes.js'
import { GradeContexts } from '../GradeUtils.js'
import { ChangeRecordMetadataType } from './ChangeLogType.js'
import { ClimbType, IClimbMetadata, IClimbContent, SafetyType, ClimbEditOperationType } from './ClimbTypes'
import { GradeContexts } from '../GradeUtils'
import { ChangeRecordMetadataType } from './ChangeLogType'

const { Schema } = mongoose

Expand Down
4 changes: 2 additions & 2 deletions src/db/ClimbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Point } from '@turf/helpers'
import { GradeScalesTypes } from '@openbeta/sandbag'

import { ChangeRecordMetadataType } from './ChangeLogType'
import { GradeContexts } from '../GradeUtils.js'
import { AreaType } from './AreaTypes.js'
import { GradeContexts } from '../GradeUtils'
import { AreaType } from './AreaTypes'

// For search climb by id queries
// Additional fields allow client to build breadcrumbs
Expand Down
4 changes: 2 additions & 2 deletions src/db/MediaObjectSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose'

import { MediaObject, EntityTag } from './MediaObjectTypes.js'
import { PointSchema } from './ClimbSchema.js'
import { MediaObject, EntityTag } from './MediaObjectTypes'
import { PointSchema } from './ClimbSchema'

const { Schema } = mongoose

Expand Down
4 changes: 2 additions & 2 deletions src/db/OrganizationSchema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mongoose from 'mongoose'
import muuid from 'uuid-mongodb'

import { OrganizationType, OrgType, IOrganizationContent, OperationType } from './OrganizationTypes.js'
import { ChangeRecordMetadataType } from './ChangeLogType.js'
import { OrganizationType, OrgType, IOrganizationContent, OperationType } from './OrganizationTypes'
import { ChangeRecordMetadataType } from './ChangeLogType'

const { Schema, connection } = mongoose

Expand Down
2 changes: 1 addition & 1 deletion src/db/OrganizationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose'
import { MUUID } from 'uuid-mongodb'

import { ChangeRecordMetadataType } from './ChangeLogType.js'
import { ChangeRecordMetadataType } from './ChangeLogType'

/**
* Organizations are OpenBeta accounts that are owned by organizations
Expand Down
4 changes: 2 additions & 2 deletions src/db/PostSchema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mongoose from 'mongoose'
import mongooseLeanVirtuals from 'mongoose-lean-virtuals'
import muuid from 'uuid-mongodb'
import { PostType } from './PostTypes.js'
import { XMediaSchema } from './XMediaSchema.js'
import { PostType } from './PostTypes'
import { XMediaSchema } from './XMediaSchema'

const { Schema } = mongoose

Expand Down
2 changes: 1 addition & 1 deletion src/db/TagSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import mongoose from 'mongoose'
import mongooseLeanVirtuals from 'mongoose-lean-virtuals'
import muuid from 'uuid-mongodb'

import { TagType, RefModelType } from './TagTypes.js'
import { TagType, RefModelType } from './TagTypes'

const { Schema } = mongoose

Expand Down
2 changes: 1 addition & 1 deletion src/db/UserSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose'
import muuid from 'uuid-mongodb'

import { ExperimentalUserType, User, UsernameInfo } from './UserTypes.js'
import { ExperimentalUserType, User, UsernameInfo } from './UserTypes'

const { Schema } = mongoose

Expand Down
2 changes: 1 addition & 1 deletion src/db/UserTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MUUID } from 'uuid-mongodb'
import { UserMedia } from './MediaObjectTypes.js'
import { UserMedia } from './MediaObjectTypes'
export interface ExperimentalUserType {
_id: MUUID
displayName: string
Expand Down
2 changes: 1 addition & 1 deletion src/db/XMediaSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import mongoose from 'mongoose'
import mongooseLeanVirtuals from 'mongoose-lean-virtuals'
import muuid from 'uuid-mongodb'

import { XMediaType } from './XMediaTypes.js'
import { XMediaType } from './XMediaTypes'

const { Schema } = mongoose

Expand Down
Loading

0 comments on commit 419cd60

Please sign in to comment.