@ivuorinen/config-checker 2.5.7 → 2.6.1
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/README.md +26 -68
- package/lib/config-checker.js +3 -4
- package/lib/configuration-paths.js +54 -25
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -43,74 +43,32 @@ if (foundConfig.length > 0) {
|
|
|
43
43
|
|
|
44
44
|
### Locations scanned
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
| `[module name]`
|
|
50
|
-
| `[module name]`rc
|
|
51
|
-
| `[module name]`rc.yaml
|
|
52
|
-
| `[module name]
|
|
53
|
-
| `[module name]
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
| .`[module name]`rc.cjs |
|
|
73
|
-
| .`[module name]`.jsonc |
|
|
74
|
-
| .`[module name]`.yaml |
|
|
75
|
-
| .`[module name]`.json |
|
|
76
|
-
| .`[module name]`.config.js |
|
|
77
|
-
| .`[module name]`.config.ts |
|
|
78
|
-
| .`[module name]`.config.mjs |
|
|
79
|
-
| .`[module name]`.config.cjs |
|
|
80
|
-
| .config/`[module name]` |
|
|
81
|
-
| .config/`[module name]`rc |
|
|
82
|
-
| .config/`[module name]`rc.json |
|
|
83
|
-
| .config/`[module name]`rc.yaml |
|
|
84
|
-
| .config/`[module name]`rc.yml |
|
|
85
|
-
| .config/`[module name]`rc.js |
|
|
86
|
-
| .config/`[module name]`rc.ts |
|
|
87
|
-
| .config/`[module name]`rc.mjs |
|
|
88
|
-
| .config/`[module name]`rc.cjs |
|
|
89
|
-
| .config/`[module name]`.jsonc |
|
|
90
|
-
| .config/`[module name]`.yaml |
|
|
91
|
-
| .config/`[module name]`.json |
|
|
92
|
-
| .config/`[module name]`.config.js |
|
|
93
|
-
| .config/`[module name]`.config.ts |
|
|
94
|
-
| .config/`[module name]`.config.mjs |
|
|
95
|
-
| .config/`[module name]`.config.cjs |
|
|
96
|
-
| .config/.`[module name]` |
|
|
97
|
-
| .config/.`[module name]`rc |
|
|
98
|
-
| .config/.`[module name]`rc.json |
|
|
99
|
-
| .config/.`[module name]`rc.yaml |
|
|
100
|
-
| .config/.`[module name]`rc.yml |
|
|
101
|
-
| .config/.`[module name]`rc.js |
|
|
102
|
-
| .config/.`[module name]`rc.ts |
|
|
103
|
-
| .config/.`[module name]`rc.mjs |
|
|
104
|
-
| .config/.`[module name]`rc.cjs |
|
|
105
|
-
| .config/.`[module name]`.jsonc |
|
|
106
|
-
| .config/.`[module name]`.yaml |
|
|
107
|
-
| .config/.`[module name]`.json |
|
|
108
|
-
| .config/.`[module name]`.config.js |
|
|
109
|
-
| .config/.`[module name]`.config.ts |
|
|
110
|
-
| .config/.`[module name]`.config.mjs |
|
|
111
|
-
| .config/.`[module name]`.config.cjs |
|
|
112
|
-
|
|
113
|
-
This list has been generated using `npm run generate-table`.
|
|
46
|
+
<!-- BEGIN GENERATED CONFIG TABLE -->
|
|
47
|
+
| Searched configuration files |
|
|
48
|
+
| -------------------------------------------------------------------------------------- |
|
|
49
|
+
| `[module name]` |
|
|
50
|
+
| `[module name]`rc |
|
|
51
|
+
| `[module name]`rc.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
52
|
+
| `[module name]`.{json,jsonc,json5,yaml,yml,toml} |
|
|
53
|
+
| `[module name]`.config.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
54
|
+
| .`[module name]` |
|
|
55
|
+
| .`[module name]`rc |
|
|
56
|
+
| .`[module name]`rc.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
57
|
+
| .`[module name]`.{json,jsonc,json5,yaml,yml,toml} |
|
|
58
|
+
| .`[module name]`.config.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
59
|
+
| .config/`[module name]` |
|
|
60
|
+
| .config/`[module name]`rc |
|
|
61
|
+
| .config/`[module name]`rc.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
62
|
+
| .config/`[module name]`.{json,jsonc,json5,yaml,yml,toml} |
|
|
63
|
+
| .config/`[module name]`.config.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
64
|
+
| .config/.`[module name]` |
|
|
65
|
+
| .config/.`[module name]`rc |
|
|
66
|
+
| .config/.`[module name]`rc.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
67
|
+
| .config/.`[module name]`.{json,jsonc,json5,yaml,yml,toml} |
|
|
68
|
+
| .config/.`[module name]`.config.{json,jsonc,json5,yaml,yml,toml,js,cjs,mjs,ts,cts,mts} |
|
|
69
|
+
<!-- END GENERATED CONFIG TABLE -->
|
|
70
|
+
|
|
71
|
+
This list is generated with `yarn generate-table`; do not edit the table by hand.
|
|
114
72
|
|
|
115
73
|
## Contributing
|
|
116
74
|
|
package/lib/config-checker.js
CHANGED
|
@@ -13,10 +13,9 @@ const configurationPaths = require("./configuration-paths");
|
|
|
13
13
|
* @returns {string[]} - The paths to the configuration files.
|
|
14
14
|
*/
|
|
15
15
|
const configChecker = (moduleName, pathPrefix = "") => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
// INIT_CWD is only set by npm/yarn during lifecycle scripts; fall back to
|
|
17
|
+
// cwd so direct/programmatic calls don't throw on an undefined path.
|
|
18
|
+
const searchPath = pathPrefix || process.env.INIT_CWD || process.cwd();
|
|
20
19
|
|
|
21
20
|
const allFiles = configurationPaths(moduleName);
|
|
22
21
|
|
|
@@ -1,35 +1,64 @@
|
|
|
1
1
|
const path = require("node:path");
|
|
2
2
|
|
|
3
|
+
// Data-serialisation formats a config file can use, and the JS/TS module
|
|
4
|
+
// formats. rc files and `*.config.*` files accept both; a bare `name.<ext>`
|
|
5
|
+
// accepts only data formats, since a bare `name.js` is too ambiguous to treat
|
|
6
|
+
// as a config file.
|
|
7
|
+
const DATA = ["json", "jsonc", "json5", "yaml", "yml", "toml"];
|
|
8
|
+
const CODE = ["js", "cjs", "mjs", "ts", "cts", "mts"];
|
|
9
|
+
|
|
10
|
+
// Single source of truth for the config filenames we detect. Each group is a
|
|
11
|
+
// stem plus the extensions that may follow it: a group with no extensions is a
|
|
12
|
+
// single literal name; a group with extensions expands to one name per
|
|
13
|
+
// extension at runtime and renders as brace-expansion in the generated table.
|
|
14
|
+
const groups = [
|
|
15
|
+
{ stem: "", exts: [] }, // [module name]
|
|
16
|
+
{ stem: "rc", exts: [] }, // [module name]rc
|
|
17
|
+
{ stem: "rc.", exts: [...DATA, ...CODE] },
|
|
18
|
+
{ stem: ".", exts: DATA },
|
|
19
|
+
{ stem: ".config.", exts: [...DATA, ...CODE] },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Multiplies each base name into its dotfile and .config/ variants.
|
|
24
|
+
* @param {string[]} bases The base file names.
|
|
25
|
+
* @param {(...parts: string[]) => string} join Path joiner: native `path.join`
|
|
26
|
+
* for runtime detection, `path.posix.join` for the generated README table so
|
|
27
|
+
* its `.config/` rows stay POSIX-style on every platform.
|
|
28
|
+
* @returns {string[]} - Every base plus its `.`-prefixed and `.config/` forms.
|
|
29
|
+
*/
|
|
30
|
+
const expand = (bases, join) => {
|
|
31
|
+
const both = bases.concat(bases.map((file) => `.${file}`));
|
|
32
|
+
return both.concat(both.map((file) => join(".config", file)));
|
|
33
|
+
};
|
|
34
|
+
|
|
3
35
|
/**
|
|
4
36
|
* Returns an array of configuration paths.
|
|
5
37
|
* @param {string} moduleName The name of the module to check for.
|
|
6
38
|
* @returns {string[]} - The paths to the configuration files.
|
|
7
39
|
*/
|
|
8
|
-
const configurationPaths = (moduleName) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`${moduleName}rc.js`,
|
|
16
|
-
`${moduleName}rc.ts`,
|
|
17
|
-
`${moduleName}rc.mjs`,
|
|
18
|
-
`${moduleName}rc.cjs`,
|
|
19
|
-
`${moduleName}.jsonc`,
|
|
20
|
-
`${moduleName}.yaml`,
|
|
21
|
-
`${moduleName}.json`,
|
|
22
|
-
`${moduleName}.config.js`,
|
|
23
|
-
`${moduleName}.config.ts`,
|
|
24
|
-
`${moduleName}.config.mjs`,
|
|
25
|
-
`${moduleName}.config.cjs`,
|
|
26
|
-
];
|
|
40
|
+
const configurationPaths = (moduleName) =>
|
|
41
|
+
expand(
|
|
42
|
+
groups.flatMap(({ stem, exts }) =>
|
|
43
|
+
exts.length === 0 ? [`${moduleName}${stem}`] : exts.map((ext) => `${moduleName}${stem}${ext}`),
|
|
44
|
+
),
|
|
45
|
+
path.join,
|
|
46
|
+
);
|
|
27
47
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the same paths as {@link configurationPaths}, but with the varying
|
|
50
|
+
* extensions collapsed into brace-expansion groups for display, e.g.
|
|
51
|
+
* `foo.{jsonc,yaml,json}`. Used to generate the README table.
|
|
52
|
+
* @param {string} moduleName The name of the module to check for.
|
|
53
|
+
* @returns {string[]} - The collapsed configuration path patterns.
|
|
54
|
+
*/
|
|
55
|
+
const configurationPatterns = (moduleName) =>
|
|
56
|
+
expand(
|
|
57
|
+
groups.map(({ stem, exts }) =>
|
|
58
|
+
exts.length === 0 ? `${moduleName}${stem}` : `${moduleName}${stem}{${exts.join(",")}}`,
|
|
59
|
+
),
|
|
60
|
+
path.posix.join,
|
|
61
|
+
);
|
|
34
62
|
|
|
35
63
|
module.exports = configurationPaths;
|
|
64
|
+
module.exports.patterns = configurationPatterns;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ivuorinen/config-checker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Checks the commonly used configuration locations for configuration files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"check-config",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "node ./__tests__/config-checker.test.js",
|
|
37
37
|
"generate-table": "node ./helpers/generate-md-table.js",
|
|
38
|
+
"generate-table:check": "node ./helpers/generate-md-table.js --check",
|
|
38
39
|
"semantic-release": "semantic-release"
|
|
39
40
|
},
|
|
40
41
|
"bugs": {
|
|
@@ -42,11 +43,16 @@
|
|
|
42
43
|
},
|
|
43
44
|
"packageManager": "yarn@4.17.1",
|
|
44
45
|
"devDependencies": {
|
|
46
|
+
"@eslint/js": "^10.0.1",
|
|
45
47
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
46
48
|
"@semantic-release/github": "^12.0.9",
|
|
47
49
|
"@semantic-release/npm": "^13.1.5",
|
|
48
50
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
49
51
|
"conventional-changelog-conventionalcommits": "^10.2.1",
|
|
52
|
+
"eslint": "^10.2.0",
|
|
53
|
+
"eslint-config-eslint": "^14.0.0",
|
|
54
|
+
"eslint-config-prettier": "^10.1.8",
|
|
55
|
+
"globals": "^17.4.0",
|
|
50
56
|
"semantic-release": "^25.0.7"
|
|
51
57
|
},
|
|
52
58
|
"resolutions": {
|