@dsmrt/axiom-config 0.2.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +21 -19
- package/dist/index.mjs +17 -16
- package/package.json +14 -17
- package/tsconfig.json +10 -10
- package/vitest.config.mts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @dsmrt/axiom-config
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- d767a0e: Making loadConfig return a promise; adding typescript config support and better esm/mjs/mts support; better docs
|
|
8
|
+
|
|
9
|
+
## 0.2.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- f4c9e19: fix: remove debug and fix testing
|
|
14
|
+
|
|
3
15
|
## 0.2.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -38,8 +38,8 @@ interface LoadConfigInput {
|
|
|
38
38
|
*/
|
|
39
39
|
cwd?: string;
|
|
40
40
|
}
|
|
41
|
-
declare const importConfigFromPath: (path: string) => Config
|
|
42
|
-
declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer & T
|
|
41
|
+
declare const importConfigFromPath: (path: string) => Promise<Config>;
|
|
42
|
+
declare const loadConfig: <T extends object>(input?: LoadConfigInput) => Promise<ConfigContainer & T>;
|
|
43
43
|
/**
|
|
44
44
|
* Simple object check.
|
|
45
45
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ interface LoadConfigInput {
|
|
|
38
38
|
*/
|
|
39
39
|
cwd?: string;
|
|
40
40
|
}
|
|
41
|
-
declare const importConfigFromPath: (path: string) => Config
|
|
42
|
-
declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer & T
|
|
41
|
+
declare const importConfigFromPath: (path: string) => Promise<Config>;
|
|
42
|
+
declare const loadConfig: <T extends object>(input?: LoadConfigInput) => Promise<ConfigContainer & T>;
|
|
43
43
|
/**
|
|
44
44
|
* Simple object check.
|
|
45
45
|
*/
|
package/dist/index.js
CHANGED
|
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
ConfigContainer: () => ConfigContainer,
|
|
24
24
|
configPath: () => configPath,
|
|
25
25
|
importConfigFromPath: () => importConfigFromPath,
|
|
@@ -27,8 +27,8 @@ __export(src_exports, {
|
|
|
27
27
|
loadConfig: () => loadConfig,
|
|
28
28
|
mergeDeep: () => mergeDeep
|
|
29
29
|
});
|
|
30
|
-
module.exports = __toCommonJS(
|
|
31
|
-
var
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_node_fs = require("fs");
|
|
32
32
|
var import_find_up = require("find-up");
|
|
33
33
|
var ConfigContainer = class {
|
|
34
34
|
name;
|
|
@@ -45,31 +45,35 @@ var ConfigContainer = class {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
isProd() {
|
|
48
|
-
return this.env
|
|
48
|
+
return this.env === this.prodEnvName;
|
|
49
49
|
}
|
|
50
50
|
asParameterPath(name) {
|
|
51
|
-
return this.aws.baseParameterPath.replace(
|
|
51
|
+
return `${this.aws.baseParameterPath.replace(/\/+$/, "")}/${name}`;
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
var importConfigFromPath = (path) => {
|
|
54
|
+
var importConfigFromPath = async (path) => {
|
|
55
55
|
if (/\.json$/.test(path)) {
|
|
56
|
-
return JSON.parse((0,
|
|
56
|
+
return JSON.parse((0, import_node_fs.readFileSync)(path).toString());
|
|
57
57
|
}
|
|
58
|
-
if (/\.(m)?
|
|
59
|
-
|
|
58
|
+
if (/\.((m)?ts|mjs)$/.test(path)) {
|
|
59
|
+
const loaded = await import(path);
|
|
60
|
+
return loaded.default || loaded;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
if (/\.(m)?js$/.test(path)) {
|
|
63
|
+
const loaded = require(path);
|
|
64
|
+
return loaded.default || loaded;
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Unsupported file type or path not found: ${path}`);
|
|
62
67
|
};
|
|
63
|
-
var loadConfig = (input) => {
|
|
68
|
+
var loadConfig = async (input) => {
|
|
64
69
|
const baseConfigFile = configPath({
|
|
65
70
|
...input,
|
|
66
71
|
env: void 0
|
|
67
72
|
});
|
|
68
|
-
const baseConfig = importConfigFromPath(baseConfigFile);
|
|
73
|
+
const baseConfig = await importConfigFromPath(baseConfigFile);
|
|
69
74
|
let overrides = input?.overrides || {};
|
|
70
75
|
if (input?.env) {
|
|
71
|
-
|
|
72
|
-
const devConfig = importConfigFromPath(configPath(input));
|
|
76
|
+
const devConfig = await importConfigFromPath(configPath(input));
|
|
73
77
|
overrides = mergeDeep(devConfig, overrides);
|
|
74
78
|
}
|
|
75
79
|
const configObject = mergeDeep(baseConfig, overrides);
|
|
@@ -79,14 +83,12 @@ function isObject(item) {
|
|
|
79
83
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
80
84
|
}
|
|
81
85
|
function mergeDeep(target, ...sources) {
|
|
82
|
-
if (!sources.length)
|
|
83
|
-
return target;
|
|
86
|
+
if (!sources.length) return target;
|
|
84
87
|
const source = sources.shift();
|
|
85
88
|
if (isObject(target) && isObject(source)) {
|
|
86
89
|
for (const key in source) {
|
|
87
90
|
if (isObject(source[key])) {
|
|
88
|
-
if (!target[key])
|
|
89
|
-
Object.assign(target, { [key]: {} });
|
|
91
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
90
92
|
mergeDeep(target[key], source[key]);
|
|
91
93
|
} else {
|
|
92
94
|
Object.assign(target, { [key]: source[key] });
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
3
|
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
6
|
});
|
|
8
7
|
|
|
@@ -24,31 +23,35 @@ var ConfigContainer = class {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
isProd() {
|
|
27
|
-
return this.env
|
|
26
|
+
return this.env === this.prodEnvName;
|
|
28
27
|
}
|
|
29
28
|
asParameterPath(name) {
|
|
30
|
-
return this.aws.baseParameterPath.replace(
|
|
29
|
+
return `${this.aws.baseParameterPath.replace(/\/+$/, "")}/${name}`;
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
var importConfigFromPath = (path) => {
|
|
32
|
+
var importConfigFromPath = async (path) => {
|
|
34
33
|
if (/\.json$/.test(path)) {
|
|
35
34
|
return JSON.parse(readFileSync(path).toString());
|
|
36
35
|
}
|
|
37
|
-
if (/\.(m)?
|
|
38
|
-
|
|
36
|
+
if (/\.((m)?ts|mjs)$/.test(path)) {
|
|
37
|
+
const loaded = await import(path);
|
|
38
|
+
return loaded.default || loaded;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
if (/\.(m)?js$/.test(path)) {
|
|
41
|
+
const loaded = __require(path);
|
|
42
|
+
return loaded.default || loaded;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Unsupported file type or path not found: ${path}`);
|
|
41
45
|
};
|
|
42
|
-
var loadConfig = (input) => {
|
|
46
|
+
var loadConfig = async (input) => {
|
|
43
47
|
const baseConfigFile = configPath({
|
|
44
48
|
...input,
|
|
45
49
|
env: void 0
|
|
46
50
|
});
|
|
47
|
-
const baseConfig = importConfigFromPath(baseConfigFile);
|
|
51
|
+
const baseConfig = await importConfigFromPath(baseConfigFile);
|
|
48
52
|
let overrides = input?.overrides || {};
|
|
49
53
|
if (input?.env) {
|
|
50
|
-
|
|
51
|
-
const devConfig = importConfigFromPath(configPath(input));
|
|
54
|
+
const devConfig = await importConfigFromPath(configPath(input));
|
|
52
55
|
overrides = mergeDeep(devConfig, overrides);
|
|
53
56
|
}
|
|
54
57
|
const configObject = mergeDeep(baseConfig, overrides);
|
|
@@ -58,14 +61,12 @@ function isObject(item) {
|
|
|
58
61
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
59
62
|
}
|
|
60
63
|
function mergeDeep(target, ...sources) {
|
|
61
|
-
if (!sources.length)
|
|
62
|
-
return target;
|
|
64
|
+
if (!sources.length) return target;
|
|
63
65
|
const source = sources.shift();
|
|
64
66
|
if (isObject(target) && isObject(source)) {
|
|
65
67
|
for (const key in source) {
|
|
66
68
|
if (isObject(source[key])) {
|
|
67
|
-
if (!target[key])
|
|
68
|
-
Object.assign(target, { [key]: {} });
|
|
69
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
69
70
|
mergeDeep(target[key], source[key]);
|
|
70
71
|
} else {
|
|
71
72
|
Object.assign(target, { [key]: source[key] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsmrt/axiom-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Config library for axiom cli",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -24,28 +24,25 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@types/
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"typescript": "^5.2.2",
|
|
37
|
-
"@vitest/coverage-v8": "^1.2.1",
|
|
38
|
-
"vitest": "^1.2.1"
|
|
27
|
+
"@biomejs/biome": "^2.3.8",
|
|
28
|
+
"@changesets/cli": "^2.27.11",
|
|
29
|
+
"@types/node": "^22.12.0",
|
|
30
|
+
"@types/yargs": "^17.0.33",
|
|
31
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"tsup": "^8.3.5",
|
|
34
|
+
"typescript": "^5.7.2",
|
|
35
|
+
"vitest": "^4.0.0"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
38
|
"find-up": "^5.0.0",
|
|
42
39
|
"yargs": "^17.7.2"
|
|
43
40
|
},
|
|
44
41
|
"scripts": {
|
|
45
|
-
"lint": "
|
|
46
|
-
"lint:fix": "
|
|
47
|
-
"test": "vitest run --coverage
|
|
48
|
-
"watch": "vitest watch --coverage
|
|
42
|
+
"lint": "biome lint",
|
|
43
|
+
"lint:fix": "biome lint --fix",
|
|
44
|
+
"test": "vitest run --coverage",
|
|
45
|
+
"watch": "vitest watch --coverage",
|
|
49
46
|
"build": "tsup --entry ./src/bin/axiom.ts --entry ./src/index.ts --format cjs,esm --dts --clean",
|
|
50
47
|
"release": "pnpm run build && pnpm changeset publish"
|
|
51
48
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"noEmit": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/index.ts"]
|
|
12
12
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// vitest.config.ts
|
|
2
|
+
import { defineConfig } from "vitest/config";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
include: ["src/**/*.test.ts"],
|
|
7
|
+
coverage: {
|
|
8
|
+
provider: "v8",
|
|
9
|
+
all: true,
|
|
10
|
+
exclude: ["lib/**/*", "src/__mocks__/**/*"],
|
|
11
|
+
reporter: ["text-summary", "json-summary"],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
});
|