-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
52 lines (46 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright 2022-2025 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
import appRoot from 'app-root-path';
import {createRequire} from 'node:module';
import {join} from 'node:path';
const require = createRequire(import.meta.url);
const requireDir = require('require-dir');
// get all the remote implementations in this dir
const remote = Object.values(requireDir('./'));
// gets local manifests from an optional config file
const getLocalManifest = fileName => {
try {
const path = join(
appRoot.toString(), fileName);
return require(path);
} catch(e) {
if(e?.code === 'MODULE_NOT_FOUND') {
return {};
}
throw e;
}
};
const localConfig = getLocalManifest('localConfig.cjs');
export const localSettings = (Object.keys(localConfig).length > 0) ?
// if there is a localConfig.settings overwrite local defaults
{...{enableInteropTests: false, testAllImplementations: false},
...localConfig?.settings} :
// otherwise, return the global defaults
// FIXME: ...consider renaming `localSettings` as it can hold global ones...
{enableInteropTests: true, testAllImplementations: true};
// get localConfig and look for an implementations property
let local = localConfig?.implementations || [];
// it's an easy typo to set `implementations` to an object...instead of an array
if(!Array.isArray(local)) {
local = [local];
}
// concat all the implementation manifests together
const all = remote.concat(local);
// if local implementations are defined only return local implementations
export const implementerFiles = local.length ?
// unless testAllImplementations is true...in which case, include them all
(localSettings.testAllImplementations === true ? all : local) :
all;