diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09b36280..cbdd5296 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['16', '18', '20'] + node: ['18', '20'] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/package-lock.json b/package-lock.json index a21d9de7..87c579ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "js-yaml": "^4.0.0", "json5": "^2.2.0", "minimatch": "^9.0.0", + "smol-toml": "^1.0.1", "yargs": "^17.0.1" }, "bin": { @@ -39,7 +40,7 @@ "prettier": "^3.0.0" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -3134,6 +3135,15 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "node_modules/smol-toml": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.1.4.tgz", + "integrity": "sha512-Y0OT8HezWsTNeEOSVxDnKOW/AyNXHQ4BwJNbAXlLTF5wWsBvrcHhIkE5Rf8kQMLmgf7nDX3PVOlgC6/Aiggu3Q==", + "engines": { + "node": ">= 18", + "pnpm": ">= 8" + } + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -5736,6 +5746,11 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "smol-toml": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.1.4.tgz", + "integrity": "sha512-Y0OT8HezWsTNeEOSVxDnKOW/AyNXHQ4BwJNbAXlLTF5wWsBvrcHhIkE5Rf8kQMLmgf7nDX3PVOlgC6/Aiggu3Q==" + }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", diff --git a/package.json b/package.json index f161b567..c0aca65b 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "js-yaml": "^4.0.0", "json5": "^2.2.0", "minimatch": "^9.0.0", + "smol-toml": "^1.0.1", "yargs": "^17.0.1" }, "devDependencies": { @@ -55,7 +56,7 @@ "prettier": "^3.0.0" }, "engines": { - "node": ">=16" + "node": ">=18" }, "type": "module", "keywords": [ diff --git a/src/cli.spec.js b/src/cli.spec.js index 745c0876..87c917c0 100644 --- a/src/cli.spec.js +++ b/src/cli.spec.js @@ -421,6 +421,16 @@ describe("CLI", function () { }); }); + it("should validate toml files", function () { + return cli({ + patterns: ["./testfiles/files/valid.toml"], + schema: "./testfiles/schemas/schema.json", + }).then((result) => { + assert.equal(result, 0); + assert(logContainsSuccess("./testfiles/files/valid.toml is valid")); + }); + }); + it("should use custom parser in preference to file extension if specified", function () { return cli({ patterns: ["./testfiles/files/with-comments.json"], diff --git a/src/parser.js b/src/parser.js index c775a2d0..32e46730 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,5 +1,6 @@ import JSON5 from "json5"; import yaml from "js-yaml"; +import { parse } from "smol-toml"; function parseDocument(contents, format) { switch (format) { @@ -13,6 +14,8 @@ function parseDocument(contents, format) { case ".yml": case ".yaml": return yaml.load(contents); + case ".toml": + return parse(contents); default: throw new Error(`Unsupported format ${format}`); } diff --git a/testfiles/files/valid.toml b/testfiles/files/valid.toml new file mode 100644 index 00000000..6d8f5f95 --- /dev/null +++ b/testfiles/files/valid.toml @@ -0,0 +1 @@ +num = 4 \ No newline at end of file