From a755ee8dc17a8ec649a3d1469e01d95f9d75b2a5 Mon Sep 17 00:00:00 2001 From: "Jakub P." Date: Fri, 26 Jul 2024 11:30:55 +0200 Subject: [PATCH] fix: improve paths for windows os --- packages/backend/knexfile.js | 6 +++--- packages/backend/src/helpers/app-assets-handler.js | 2 +- packages/backend/src/helpers/get-app.js | 6 +++--- packages/backend/src/models/app.js | 2 +- packages/e2e-tests/knexfile.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/backend/knexfile.js b/packages/backend/knexfile.js index 0748c74b..e38e94d6 100644 --- a/packages/backend/knexfile.js +++ b/packages/backend/knexfile.js @@ -1,6 +1,6 @@ import { knexSnakeCaseMappers } from 'objection'; import appConfig from './src/config/app.js'; -import path from 'path'; +import path, { join } from 'path'; import { fileURLToPath } from 'url'; const fileExtension = 'js'; @@ -20,12 +20,12 @@ const knexConfig = { searchPath: [appConfig.postgresSchema], pool: { min: 0, max: 20 }, migrations: { - directory: __dirname + '/src/db/migrations', + directory: join(__dirname, '/src/db/migrations'), extension: fileExtension, loadExtensions: [`.${fileExtension}`], }, seeds: { - directory: __dirname + '/src/db/seeds', + directory: join(__dirname, '/src/db/seeds'), }, ...(appConfig.isTest ? knexSnakeCaseMappers() : {}), }; diff --git a/packages/backend/src/helpers/app-assets-handler.js b/packages/backend/src/helpers/app-assets-handler.js index 778ad25b..e76287b2 100644 --- a/packages/backend/src/helpers/app-assets-handler.js +++ b/packages/backend/src/helpers/app-assets-handler.js @@ -7,7 +7,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); const appAssetsHandler = async (app) => { app.use('/apps/:appKey/assets/favicon.svg', (req, res, next) => { const { appKey } = req.params; - const svgPath = `${__dirname}/../apps/${appKey}/assets/favicon.svg`; + const svgPath = path.resolve(`${__dirname}/../apps/${appKey}/assets/favicon.svg`); const staticFileHandlerOptions = { /** * Disabling fallthrough is important to respond with HTTP 404. diff --git a/packages/backend/src/helpers/get-app.js b/packages/backend/src/helpers/get-app.js index 7d186977..395e761b 100644 --- a/packages/backend/src/helpers/get-app.js +++ b/packages/backend/src/helpers/get-app.js @@ -1,10 +1,10 @@ -import path from 'node:path'; +import path, { join } from 'path'; import fs from 'node:fs'; import omit from 'lodash/omit.js'; import cloneDeep from 'lodash/cloneDeep.js'; import addAuthenticationSteps from './add-authentication-steps.js'; import addReconnectionSteps from './add-reconnection-steps.js'; -import { fileURLToPath } from 'url'; +import { fileURLToPath, pathToFileURL } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -14,7 +14,7 @@ const apps = fs if (!dirent.isDirectory()) return apps; apps[dirent.name] = import( - path.resolve(__dirname, '../apps', dirent.name, 'index.js') + pathToFileURL(join(__dirname, '../apps', dirent.name, 'index.js')) ); return apps; diff --git a/packages/backend/src/models/app.js b/packages/backend/src/models/app.js index 3a85a139..efb513f1 100644 --- a/packages/backend/src/models/app.js +++ b/packages/backend/src/models/app.js @@ -10,7 +10,7 @@ class App { static folderPath = join(__dirname, '../apps'); static list = fs .readdirSync(this.folderPath) - .filter((file) => fs.statSync(this.folderPath + '/' + file).isDirectory()); + .filter((file) => fs.statSync(join(this.folderPath, file)).isDirectory()); static async findAll(name, stripFuncs = true) { if (!name) diff --git a/packages/e2e-tests/knexfile.js b/packages/e2e-tests/knexfile.js index b465bf0b..6ed3bd37 100644 --- a/packages/e2e-tests/knexfile.js +++ b/packages/e2e-tests/knexfile.js @@ -17,7 +17,7 @@ const knexConfig = { loadExtensions: [`.${fileExtension}`], }, seeds: { - directory: '../../packages/backend/src/db/seeds', + directory: '../../packages/backend/src/db/seeds/', }, ...(process.env.APP_ENV === 'test' ? knexSnakeCaseMappers() : {}), };