v8r 4.1.0 → 4.2.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 +7 -1
- package/package.json +1 -1
- package/src/ajv.js +1 -1
- package/src/bootstrap.js +21 -27
- package/src/catalogs.js +1 -1
- package/src/cli.js +3 -3
- package/src/config-validators.js +1 -1
- package/src/io.js +2 -2
- package/src/parser.js +1 -1
- package/src/plugins.js +1 -1
- package/src/test-helpers.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 📦 [4.2.0](https://www.npmjs.com/package/v8r/v/4.2.0) - 2024-10-24
|
|
4
|
+
|
|
5
|
+
* Add `V8R_CONFIG_FILE` environment variable.
|
|
6
|
+
This allows loading a config file from a location other than the directory v8r is invoked from.
|
|
7
|
+
More info: https://chris48s.github.io/v8r/configuration/
|
|
8
|
+
|
|
3
9
|
## 📦 [4.1.0](https://www.npmjs.com/package/v8r/v/4.1.0) - 2024-08-25
|
|
4
10
|
|
|
5
11
|
* v8r can now parse and validate files that contain multiple yaml documents
|
|
6
12
|
More info: https://chris48s.github.io/v8r/usage-examples/#files-containing-multiple-documents
|
|
7
|
-
* The `parseInputFile()` plugin hook may now
|
|
13
|
+
* The `parseInputFile()` plugin hook may now conditionally return an array of `Document` objects
|
|
8
14
|
* The `ValidationResult` object now contains a `documentIndex` property.
|
|
9
15
|
This identifies the document when a multi-doc file has been validated.
|
|
10
16
|
|
package/package.json
CHANGED
package/src/ajv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRequire } from "module";
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
// TODO: once JSON modules is stable these requires could become imports
|
|
3
3
|
// https://nodejs.org/api/esm.html#esm_experimental_json_modules
|
|
4
4
|
const require = createRequire(import.meta.url);
|
package/src/bootstrap.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { createRequire } from "module";
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
// TODO: once JSON modules is stable these requires could become imports
|
|
3
3
|
// https://nodejs.org/api/esm.html#esm_experimental_json_modules
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
5
|
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
6
8
|
import { cosmiconfig } from "cosmiconfig";
|
|
7
9
|
import decamelize from "decamelize";
|
|
8
|
-
import isUrl from "is-url";
|
|
9
|
-
import path from "path";
|
|
10
10
|
import yargs from "yargs";
|
|
11
11
|
import { hideBin } from "yargs/helpers";
|
|
12
12
|
import {
|
|
@@ -17,27 +17,28 @@ import {
|
|
|
17
17
|
import logger from "./logger.js";
|
|
18
18
|
import { loadAllPlugins, resolveUserPlugins } from "./plugins.js";
|
|
19
19
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
schema.location = path.join(
|
|
27
|
-
path.dirname(configFile.filepath),
|
|
28
|
-
schema.location,
|
|
29
|
-
);
|
|
20
|
+
async function getCosmiConfig(cosmiconfigOptions) {
|
|
21
|
+
let configFile;
|
|
22
|
+
|
|
23
|
+
if (process.env.V8R_CONFIG_FILE) {
|
|
24
|
+
if (!fs.existsSync(process.env.V8R_CONFIG_FILE)) {
|
|
25
|
+
throw new Error(`File ${process.env.V8R_CONFIG_FILE} does not exist.`);
|
|
30
26
|
}
|
|
27
|
+
configFile = await cosmiconfig("v8r", cosmiconfigOptions).load(
|
|
28
|
+
process.env.V8R_CONFIG_FILE,
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
cosmiconfigOptions.stopDir = process.cwd();
|
|
32
|
+
configFile = (await cosmiconfig("v8r", cosmiconfigOptions).search(
|
|
33
|
+
process.cwd(),
|
|
34
|
+
)) || { config: {} };
|
|
31
35
|
}
|
|
32
|
-
}
|
|
33
36
|
|
|
34
|
-
async function getCosmiConfig(cosmiconfigOptions) {
|
|
35
|
-
cosmiconfigOptions.stopDir = process.cwd();
|
|
36
|
-
const configFile = (await cosmiconfig("v8r", cosmiconfigOptions).search(
|
|
37
|
-
process.cwd(),
|
|
38
|
-
)) || { config: {} };
|
|
39
37
|
if (configFile.filepath) {
|
|
40
38
|
logger.info(`Loaded config file from ${getRelativeFilePath(configFile)}`);
|
|
39
|
+
logger.info(
|
|
40
|
+
`Patterns and relative paths will be resolved relative to current working directory: ${process.cwd()}`,
|
|
41
|
+
);
|
|
41
42
|
} else {
|
|
42
43
|
logger.info(`No config file found`);
|
|
43
44
|
}
|
|
@@ -200,7 +201,6 @@ async function bootstrap(argv, config, cosmiconfigOptions = {}) {
|
|
|
200
201
|
// we can finish validating and processing the config
|
|
201
202
|
validateConfigDocumentParsers(configFile, documentFormats);
|
|
202
203
|
validateConfigOutputFormats(configFile, outputFormats);
|
|
203
|
-
preProcessConfig(configFile);
|
|
204
204
|
|
|
205
205
|
// parse command line arguments
|
|
206
206
|
const args = parseArgs(argv, configFile, documentFormats, outputFormats);
|
|
@@ -213,10 +213,4 @@ async function bootstrap(argv, config, cosmiconfigOptions = {}) {
|
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
export {
|
|
217
|
-
bootstrap,
|
|
218
|
-
getDocumentFormats,
|
|
219
|
-
getOutputFormats,
|
|
220
|
-
parseArgs,
|
|
221
|
-
preProcessConfig,
|
|
222
|
-
};
|
|
216
|
+
export { bootstrap, getDocumentFormats, getOutputFormats, parseArgs };
|
package/src/catalogs.js
CHANGED
package/src/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
1
4
|
import flatCache from "flat-cache";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import os from "os";
|
|
4
|
-
import path from "path";
|
|
5
5
|
import isUrl from "is-url";
|
|
6
6
|
import { validate } from "./ajv.js";
|
|
7
7
|
import { bootstrap } from "./bootstrap.js";
|
package/src/config-validators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRequire } from "module";
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
// TODO: once JSON modules is stable these requires could become imports
|
|
3
3
|
// https://nodejs.org/api/esm.html#esm_experimental_json_modules
|
|
4
4
|
const require = createRequire(import.meta.url);
|
package/src/io.js
CHANGED
package/src/parser.js
CHANGED
package/src/plugins.js
CHANGED
package/src/test-helpers.js
CHANGED
|
@@ -4,6 +4,7 @@ import logger from "./logger.js";
|
|
|
4
4
|
const origWriteOut = logger.writeOut;
|
|
5
5
|
const origWriteErr = logger.writeErr;
|
|
6
6
|
const testCacheName = process.env.V8R_CACHE_NAME;
|
|
7
|
+
const env = process.env;
|
|
7
8
|
|
|
8
9
|
function setUp() {
|
|
9
10
|
flatCache.clearCacheById(testCacheName);
|
|
@@ -11,6 +12,7 @@ function setUp() {
|
|
|
11
12
|
logger.resetStderr();
|
|
12
13
|
logger.writeOut = function () {};
|
|
13
14
|
logger.writeErr = function () {};
|
|
15
|
+
process.env = { ...env };
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
function tearDown() {
|
|
@@ -19,6 +21,7 @@ function tearDown() {
|
|
|
19
21
|
logger.resetStderr();
|
|
20
22
|
logger.writeOut = origWriteOut;
|
|
21
23
|
logger.writeErr = origWriteErr;
|
|
24
|
+
process.env = env;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
function isString(el) {
|