Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/server/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable camelcase */
/* eslint-disable no-restricted-imports */
/* istanbul ignore file */
import './bootstrap'
import './bootstrap.js'
import http from 'http'
import express, { Express } from 'express'

Expand Down
4 changes: 2 additions & 2 deletions packages/server/bin/www
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
'use strict'

const { logger } = require('../dist/logging/logging')
const { init, startHttp } = require('../dist/app')
import { logger } from '../dist/logging/logging.js'
import { init, startHttp } from '../dist/app.js'

init()
.then(({ app, graphqlServer, server, readinessCheck }) =>
Expand Down
43 changes: 13 additions & 30 deletions packages/server/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
/* istanbul ignore file */
/**
* Bootstrap module that should be imported at the very top of each entry point module
*/

// Conditionally change appRoot and packageRoot according to whether we're running from /dist/ or not (ts-node)
const path = require('path')
const isTsNode = !!process[Symbol.for('ts-node.register.instance')]
const appRoot = __dirname
const packageRoot = isTsNode ? appRoot : path.resolve(__dirname, '../')

// Initializing module aliases for absolute import paths
const moduleAlias = require('module-alias')
moduleAlias.addAliases({
'@': appRoot,
'#': packageRoot
})

// Initializing env vars
const dotenv = require('dotenv')
const {
import dotenv from 'dotenv'
import {
isTestEnv,
isApolloMonitoringEnabled,
getApolloServerVersion,
getServerVersion
} = require('./modules/shared/helpers/envHelper')
const { logger } = require('@/logging/logging')
} from '@/modules/shared/helpers/envHelper'
import { logger } from '@/logging/logging'
import { initOpenTelemetry } from '@/otel'
import { patchKnex } from '@/modules/core/patches/knex'
import { appRoot, packageRoot } from '#/root.js'

/**
* Bootstrap module that should be imported at the very top of each entry point module
*/

// Initializing env vars
if (isApolloMonitoringEnabled() && !getApolloServerVersion()) {
process.env.APOLLO_SERVER_USER_VERSION = getServerVersion()
}
Expand All @@ -46,13 +35,7 @@ if (isTestEnv()) {
dotenv.config({ path: `${packageRoot}/.env` })

// knex is a singleton controlled by module so can't wait til app init
const { initOpenTelemetry } = require('./otel')
initOpenTelemetry()

const { patchKnex } = require('./modules/core/patches/knex')
patchKnex()

module.exports = {
appRoot,
packageRoot
}
export { appRoot, packageRoot }
6 changes: 3 additions & 3 deletions packages/server/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const configs = [
...baseConfigs,
{
languageOptions: {
sourceType: 'commonjs',
sourceType: 'module',
globals: {
...globals.node
}
}
},
{
files: ['**/*.mjs'],
files: ['**/*.cjs'],
languageOptions: {
sourceType: 'module'
sourceType: 'commonjs'
}
},
...tseslint.configs.recommendedTypeChecked.map((c) => ({
Expand Down
90 changes: 90 additions & 0 deletions packages/server/esmLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import path from 'node:path'
import { pathToFileURL } from 'node:url'
import { register } from 'node:module'
import { appRoot, packageRoot } from './root.js'

/**
* Must be invoked through --import when running the node app to set up path aliases
* and extensionless imports
*/

/**
* PATH ALIAS DEFINITIONS
*/
const aliases = {
'@/': appRoot + '/',
'#/': packageRoot + '/'
}

const packageAliases = {
lodash: 'lodash-es'
}

/**
* EXTENSIONS TO EVALUATE FOR EXTENSIONLESS IMPORTS
*/
const extensions = ['.js', '.mjs', '.cjs', '.json']

// Register the module hooks
register('./esmLoader.js', {
parentURL: import.meta.url
})

// Custom path resolver
function resolveAlias(specifier) {
for (const [alias, target] of Object.entries(aliases)) {
if (specifier.startsWith(alias)) {
const relativePath = specifier.replace(alias, target)
return pathToFileURL(path.resolve(relativePath)).href
}
}
for (const [alias, target] of Object.entries(packageAliases)) {
if (specifier === alias) {
return target
}
}
return null // No alias found, fall back to default resolution
}

export async function resolve(specifier, context, nextResolve) {
// Resolve alias
const aliasResolved = resolveAlias(specifier)
specifier = aliasResolved || specifier

// Try to resolve as is
let throwableError = undefined
try {
return await nextResolve(specifier)
} catch (e) {
throwableError = e
}

const isDirImport = throwableError.code === 'ERR_UNSUPPORTED_DIR_IMPORT'

// Didn't work, try with extensions
for (const ext of extensions) {
try {
return await nextResolve(specifier + ext)
} catch (e) {
if (!throwableError) {
throwableError = e
}
}
}

// If it was a dir import also, try that with extensions
specifier = isDirImport ? path.join(specifier, 'index') : specifier
for (const ext of extensions) {
try {
return await nextResolve(specifier + ext)
} catch (e) {
if (!throwableError) {
throwableError = e
}
}
}

throw throwableError
}

export { packageRoot, appRoot }
4 changes: 2 additions & 2 deletions packages/server/healthchecks/health.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ensureErrorOrWrapAsCause } from '@/modules/shared/errors/ensureError'
import { join, merge } from 'lodash'
import { MultiError } from 'verror'
import VError from 'verror'
import {
FreeConnectionsCalculators,
MultiDBCheck,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const handleLivenessFactory =
', '
)} is not available.`,
{
cause: new MultiError(
cause: new VError.MultiError(
Object.entries(allPostgresResults).map((kv) =>
ensureErrorOrWrapAsCause(
//HACK: kv[1] is not typed correctly as the filter does not narrow the type
Expand Down
2 changes: 1 addition & 1 deletion packages/server/knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-restricted-imports */
/* istanbul ignore file */
import { packageRoot } from './bootstrap'
import { packageRoot } from './bootstrap.js'
import fs from 'fs'
import path from 'path'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@ const resolvers: Resolvers = {
}
}

export = resolvers
export default resolvers
2 changes: 1 addition & 1 deletion packages/server/modules/accessrequests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ const ServerAccessRequestsModule: SpeckleModule = {
}
}

export = ServerAccessRequestsModule
export default ServerAccessRequestsModule
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const userTimelineQueryCore = async (
return { items, cursor, totalCount }
}

export = {
export default {
LimitedUser: {
async activity(parent, args) {
return await userActivityQueryCore(parent, args)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/activitystream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ const activityModule: SpeckleModule = {
}
}

export = {
export default {
...activityModule
}
2 changes: 1 addition & 1 deletion packages/server/modules/auth/graph/resolvers/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const revokeExistingAppCredentialsForUser = revokeExistingAppCredentialsForUserF
db
})

export = {
export default {
Query: {
async app(_parent, args) {
const app = await getApp({ id: args.id })
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/auth/graph/resolvers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAuthStrategies } from '@/modules/auth'
import { Resolvers } from '@/modules/core/graph/generated/graphql'

export = {
export default {
ServerInfo: {
authStrategies() {
return getAuthStrategies()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/auth/strategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ const setupStrategiesFactory =
return authStrategies
}

export = setupStrategiesFactory
export default setupStrategiesFactory
2 changes: 1 addition & 1 deletion packages/server/modules/auth/strategies/azureAd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ const azureAdStrategyBuilderFactory =
}
}

export = azureAdStrategyBuilderFactory
export default azureAdStrategyBuilderFactory
2 changes: 1 addition & 1 deletion packages/server/modules/auth/strategies/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ const githubStrategyBuilderFactory =
return strategy
}

export = githubStrategyBuilderFactory
export default githubStrategyBuilderFactory
2 changes: 1 addition & 1 deletion packages/server/modules/auth/strategies/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ const googleStrategyBuilderFactory =
return strategy
}

export = googleStrategyBuilderFactory
export default googleStrategyBuilderFactory
2 changes: 1 addition & 1 deletion packages/server/modules/auth/strategies/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ const localStrategyBuilderFactory =
return strategy
}

export = localStrategyBuilderFactory
export default localStrategyBuilderFactory
2 changes: 1 addition & 1 deletion packages/server/modules/auth/strategies/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ const oidcStrategyBuilderFactory =
}
}

export = oidcStrategyBuilderFactory
export default oidcStrategyBuilderFactory
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const createAppToken = createAppTokenFactory({
storeUserServerAppToken: storeUserServerAppTokenFactory({ db })
})

export = (FF_AUTOMATE_MODULE_ENABLED
export default (FF_AUTOMATE_MODULE_ENABLED
? {
/**
* If automate module is enabled
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/automate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,4 @@ const automateModule: SpeckleModule = {
}
}

export = automateModule
export default automateModule
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const streamBlobResolvers = {
}
}

export = {
export default {
ServerInfo: {
//deprecated
blobSizeLimitBytes() {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const command: CommandModule = {
handler: noop
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/activities/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ const command: CommandModule = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/bull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const command: CommandModule = {
handler: noop
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/bull/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ const command: CommandModule<unknown, { testQueueId: string }> = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/bull/test-consume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ const command: CommandModule = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/bull/test-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ const command: CommandModule = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const command: CommandModule = {
handler: noop
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/db/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ const command: CommandModule = {
handler: noop
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/db/migrate/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ const command: CommandModule<unknown, { name: string; module: string }> = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/db/migrate/down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ const command: CommandModule<unknown, { times: number } & CommonDbArgs> = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/db/migrate/latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ const command: CommandModule<unknown, CommonDbArgs> = {
}
}

export = command
export default command
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ const command: CommandModule<unknown, CommonDbArgs> = {
}
}

export = command
export default command
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/db/migrate/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const command: CommandModule<unknown, CommonDbArgs> = {
}
}

export = command
export default command
Loading