Skip to content

Commit

Permalink
Merge pull request #237 from leapfrogtechnology/feat/fix-relative-path
Browse files Browse the repository at this point in the history
Use relative base path respective to config file
  • Loading branch information
mesaugat authored Oct 15, 2024
2 parents 5fa895b + ac56373 commit 82ee723
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function getSqlBasePath(config: Configuration): string {
export async function loadConfig(configFilename: string = CONFIG_FILENAME): Promise<Configuration> {
log('Resolving config file.');
const isAbsolutePath = path.isAbsolute(configFilename);
const filename = isAbsolutePath ? path.parse(configFilename).base : configFilename;
const filename = path.parse(configFilename).base;
const match = filename.match(CONFIG_FILE_CONVENTION) || filename === CONFIG_FILENAME;

if (!match) {
Expand All @@ -63,8 +63,13 @@ export async function loadConfig(configFilename: string = CONFIG_FILENAME): Prom

validate(loaded);

// Resolve the base path relative to the config file location.
const configFileLocation = path.dirname(filepath);
const relativeBasePath = path.join(configFileLocation, loaded.basePath);

const result = {
...loaded,
basePath: relativeBasePath,
injectedConfig: {
...loaded.injectedConfig,
vars: prepareInjectionConfigVars(loaded.injectedConfig.vars)
Expand Down
4 changes: 1 addition & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Global Constants */

import * as path from 'path';

import Configuration from './domain/Configuration';

// General constants
Expand All @@ -13,7 +11,7 @@ export const CONNECTIONS_FILENAME = 'connections.sync-db.json';

export const INJECTED_CONFIG_TABLE = '__sync_db_injected_config';
export const DEFAULT_CONFIG: Configuration = {
basePath: path.resolve(process.cwd(), 'src'),
basePath: 'src',
connectionResolver: '',
execution: 'parallel',
sql: [],
Expand Down

0 comments on commit 82ee723

Please sign in to comment.