Skip to content

Commit 98fe0ea

Browse files
authored
Fix config loading (#976)
2 parents 7084f30 + 5280f9a commit 98fe0ea

File tree

11 files changed

+32
-52
lines changed

11 files changed

+32
-52
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
55
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format is based on [Common Changelog](https://common-changelog.org).\
66
Unlike Common Changelog, the `unreleased` section of [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) is preserved with the addition of a tag to specify which type of release should be published and to foster discussions about it inside pull requests. This tag should be one of the names mandated by SemVer, within brackets: `[patch]`, `[minor]` or `[major]`. For example: `## Unreleased [minor]`.
77

8-
## Unreleased
8+
## Unreleased [minor]
9+
### Added
10+
- Load both the configurations defined in this module and the configurations defined in the module which use it as dependency.
911

1012
## 0.17.2 - 2022-12-12
1113
### Fixed

bin/.env.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
process.env.SUPPRESS_NO_CONFIG_WARNING = 'y';
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
4+
5+
process.env.SUPPRESS_NO_CONFIG_WARNING = 'y'; // Caller don't get "no config files" warnings if it does define configuration files
6+
7+
const OTA_CONFIG_DIR = path.resolve(__dirname + "./../config/");
8+
const PROCESS_CONFIG_DIR = path.resolve(process.cwd() + "/config/");
9+
10+
process.env["NODE_CONFIG_DIR"] = OTA_CONFIG_DIR + path.delimiter + PROCESS_CONFIG_DIR; // Ensure OTA config is loaded and loaded before caller config

bin/lint-declarations.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@ import path from 'path';
99
import { fileURLToPath, pathToFileURL } from 'url';
1010

1111
import { program } from 'commander';
12-
import config from 'config';
1312

1413
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1514

16-
// Initialise configs to allow clients of this module to use it without requiring node-config in their own application.
17-
// see https://github.com/lorenwest/node-config/wiki/Sub-Module-Configuration
18-
19-
config.util.setModuleDefaults('services', { declarationsPath: path.resolve(process.cwd(), './declarations') });
2015
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)).toString());
2116

2217
program

bin/track.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ import fs from 'fs';
55
import path from 'path';
66
import { fileURLToPath, pathToFileURL } from 'url';
77

8-
import config from 'config';
8+
import { program } from 'commander';
99

1010
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1111

12-
const defaultConfigs = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../config/default.json')));
12+
const { description, version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)).toString());
1313

14-
// Initialise configs to allow clients of this module to use it without requiring node-config in their own application.
15-
// see https://github.com/lorenwest/node-config/wiki/Sub-Module-Configuration
16-
config.util.setModuleDefaults('services', { declarationsPath: path.resolve(process.cwd(), './declarations') });
17-
config.util.setModuleDefaults('fetcher', defaultConfigs.fetcher);
18-
config.util.setModuleDefaults('recorder', config.util.extendDeep({}, defaultConfigs.recorder, {
19-
versions: { storage: { git: { path: path.resolve(process.cwd(), './data/versions') } } },
20-
snapshots: { storage: { git: { path: path.resolve(process.cwd(), './data/snapshots') } } },
21-
}));
22-
config.util.setModuleDefaults('logger', defaultConfigs.logger);
23-
// we do not want any tracker when launching through this command line
24-
config.util.setModuleDefaults('tracker', {});
14+
program
15+
.name('ota-track')
16+
.description(description)
17+
.version(version)
18+
.option('-s, --services [serviceId...]', 'service IDs of services to handle')
19+
.option('-d, --documentTypes [documentType...]', 'terms types to handle')
20+
.option('-r, --refilter-only', 'only refilter exisiting snapshots with last declarations and engine\'s updates')
21+
.option('--schedule', 'schedule automatic document tracking');
2522

26-
import(pathToFileURL(path.resolve(__dirname, '../src/main.js')));
23+
const track = (await import(pathToFileURL(path.resolve(__dirname, '../src/index.js')))).default;
24+
25+
track(program.parse(process.argv).opts());

bin/validate-declarations.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@ import path from 'path';
66
import { fileURLToPath } from 'url';
77

88
import { program } from 'commander';
9-
import config from 'config';
109
import Mocha from 'mocha';
1110

1211
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)).toString());
1312

1413
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1514

16-
const defaultConfigs = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../config/default.json')));
17-
18-
// Initialise configs to allow clients of this module to use it without requiring node-config in their own application.
19-
// see https://github.com/lorenwest/node-config/wiki/Sub-Module-Configuration
20-
config.util.setModuleDefaults('services', { declarationsPath: path.resolve(process.cwd(), './declarations') });
21-
config.util.setModuleDefaults('fetcher', defaultConfigs.fetcher);
22-
2315
const VALIDATE_PATH = path.resolve(__dirname, '../scripts/declarations/validate/index.mocha.js');
2416

2517
// Mocha catches unhandled rejection from the user code and re-emits them to the process (see https://github.com/mochajs/mocha/blob/master/lib/runner.js#L198)

config/default.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"services": {
3-
"declarationsPath": "../declarations/declarations"
3+
"declarationsPath": "./declarations"
44
},
55
"recorder": {
66
"versions": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"lint": "eslint src test scripts bin",
4242
"lint:fix": "npm run lint -- --fix",
4343
"refilter": "npm start -- --refilter-only",
44-
"start": "node --max-http-header-size=32768 src/main.js",
44+
"start": "node --max-http-header-size=32768 bin/track.js",
4545
"start:scheduler": "npm start -- --schedule",
4646
"test": "cross-env NODE_ENV=test mocha --recursive \"./src/**/*.test.js\" \"./scripts/**/*.test.js\" --exit",
4747
"posttest": "npm run lint",

scripts/declarations/validate/index.mocha.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const SLOW_DOCUMENT_THRESHOLD = 10 * 1000; // number of milliseconds after which
2828
const eslint = new ESLint({ overrideConfigFile: ESLINT_CONFIG_PATH, fix: false });
2929
const eslintWithFix = new ESLint({ overrideConfigFile: ESLINT_CONFIG_PATH, fix: true });
3030

31-
const declarationsPath = path.resolve(ROOT_PATH, config.get('services.declarationsPath'));
31+
const declarationsPath = path.resolve(process.cwd(), config.get('services.declarationsPath'));
3232
const instancePath = path.resolve(declarationsPath, '../');
3333

3434
export default async options => {

src/archivist/recorder/repositories/git/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ let git;
3838
describe('GitRepository', () => {
3939
let subject;
4040

41-
before(async () => {
41+
before(async function () {
42+
this.timeout(5000);
4243
git = new Git({
4344
path: RECORDER_PATH,
4445
author: {

src/archivist/services/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Service from './service.js';
1010

1111
const fs = fsApi.promises;
1212
const __dirname = path.dirname(fileURLToPath(import.meta.url));
13-
const declarationsPath = path.resolve(__dirname, '../../..', config.get('services.declarationsPath'));
13+
const declarationsPath = path.resolve(process.cwd(), config.get('services.declarationsPath'));
1414

1515
export const DOCUMENT_TYPES = JSON.parse(fsApi.readFileSync(path.resolve(__dirname, './documentTypes.json')));
1616

0 commit comments

Comments
 (0)