Skip to content

Commit

Permalink
fix: switch to @iarna/toml (#5508)
Browse files Browse the repository at this point in the history
* fix: switch to @iarna/toml

* chore: update snapshots

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
ascorbic and kodiakhq[bot] committed Feb 9, 2024
1 parent 596d7c1 commit ba81c85
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 21 deletions.
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/build-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
},
"author": "Netlify Inc.",
"dependencies": {
"@iarna/toml": "^2.2.5",
"@bugsnag/js": "^7.20.0",
"dot-prop": "^7.2.0",
"find-up": "^6.3.0",
"minimatch": "^9.0.0",
"read-pkg": "^7.1.0",
"semver": "^7.3.8",
"toml": "^3.0.0",
"yaml": "^2.1.3",
"yargs": "^17.6.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/build-info/src/settings/get-toml-settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Bugsnag from '@bugsnag/js'
import { parse } from 'toml'
import { parse } from '@iarna/toml'

import { FileSystem } from '../file-system.js'
import { Project } from '../project.js'
Expand All @@ -14,7 +14,7 @@ const {
/** Gracefully parses a toml file and reports errors to bugsnag */
function gracefulParseToml<T>(content: string): T {
try {
return parse(content)
return parse(content) as T
} catch (error) {
notify(error, (event) => {
event.context = '@netlify/build-info => gracefullyParseToml => toml.parse'
Expand Down
5 changes: 4 additions & 1 deletion packages/build/tests/error/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ Generated by [AVA](https://avajs.dev).
Error message␊
When resolving config file packages/build/tests/error/fixtures/toml_parsing/netlify.toml:␊
Could not parse configuration file␊
Expected "'", "/"", [ /external/path or [A-Za-z0-9_/-] but "]" found.␊
Empty bare keys are not allowed at row 1, col 4, pos 3:␊
1> [[]]␊
^␊
2: ␊
`

## Invalid error instances
Expand Down
Binary file modified packages/build/tests/error/snapshots/tests.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/build/tests/monitor/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ Generated by [AVA](https://avajs.dev).
Error monitoring payload:␊
{␊
"errorClass": "functionsBundling",␊
"errorMessage": "Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {/"basePath/":/"packages/build/tests/monitor/fixtures/edge_function_error",/"destPath/":/"packages/build/tests/monitor/fixtures/edge_function_error/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip",/"externals/":[],/"functions/":[{/"name/":/"trouble/",/"path/":/"packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/trouble.ts"}],/"importMapData/":/"{//"imports//":{//"@netlify/edge-functions//"://"https://edge.netlify.com/v1.0.0/index.ts//",//"netlify:edge//"://"https://edge.netlify.com/v1.0.0/index.ts?v=legacy//"},//"scopes//":{}}/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/file.ts/n const ret = new Error(getStringFromWasm0(arg0, arg1));/n ^/n at __wbg_new_HEXADECIMAL_ID (/node_module/path)/n at <anonymous> (/node_module/path)/n at <anonymous> (/node_module/path)/n at <anonymous> (/node_module/path)/n at __wbg_adapter_40 (/node_module/path)/n at real (/node_module/path)/n at eventLoopTick (ext:core/01_core.js:80:7)",␊
"errorMessage": "Command failed with exit code 1: deno run --allow-all --no-config --import-map=/node_module/path --quiet /node_module/path {/"basePath/":/"packages/build/tests/monitor/fixtures/edge_function_error",/"destPath/":/"packages/build/tests/monitor/fixtures/edge_function_error/.netlify/edge-functions-dist/HEXADECIMAL_ID.eszip",/"externals/":[],/"functions/":[{/"name/":/"trouble/",/"path/":/"packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/trouble.ts"}],/"importMapData/":/"{//"imports//":{//"@netlify/edge-functions//"://"https://edge.netlify.com/v1.0.0/index.ts//",//"netlify:edge//"://"https://edge.netlify.com/v1.0.0/index.ts?v=legacy//"},//"scopes//":{}}/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: packages/build/tests/monitor/fixtures/edge_function_error/netlify/edge-functions/file.ts/n const ret = new Error(getStringFromWasm0(arg0, arg1));/n ^/n at __wbg_new_HEXADECIMAL_ID (/node_module/path)/n at <anonymous> (/node_module/path)/n at <anonymous> (/node_module/path)/n at <anonymous> (/node_module/path)/n at __wbg_adapter_40 (/node_module/path)/n at real (/node_module/path)/n at eventLoopTick (ext:core/01_core.js:80:80)",␊
"context": "Bundling of edge function failed",␊
"groupingHash": "Bundling of edge function failed/nCommand failed with exit code 0: deno run --allow-all --no-config /external/path --quiet /external/path {/"/":/"/",/"/":/"/",/"/":[],/"/":[{/"/":/"/",/"/":/"/"}],/"/":/"/"/external/path"/"/external/path"/"/external/path"/"/external/path"/"/external/path"/"/external/path"/"}/nerror: Uncaught (in promise) Error: Error: Could not find file: /external/path const ret = new Error(getStringFromWasm0(arg0, arg0));/n ^/n at __wbg_new_hex /external/path at <anonymous> /external/path at <anonymous> /external/path at <anonymous> /external/path at __wbg_adapter_0 /external/path at real /external/path at eventLoopTick /external/path",␊
"severity": "info",␊
Expand Down
4 changes: 2 additions & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
},
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",
"chalk": "^5.0.0",
"cron-parser": "^4.1.0",
"deepmerge": "^4.2.2",
Expand All @@ -72,12 +73,11 @@
"map-obj": "^5.0.0",
"netlify": "^13.1.14",
"netlify-headers-parser": "^7.1.3",
"node-fetch": "^3.3.1",
"netlify-redirect-parser": "^14.2.1",
"node-fetch": "^3.3.1",
"omit.js": "^2.0.2",
"p-locate": "^6.0.0",
"path-type": "^5.0.0",
"toml": "^3.0.0",
"tomlify-j0.4": "^3.0.0",
"validate-npm-package-name": "^4.0.0",
"yargs": "^17.6.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/utils/toml.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse as loadToml } from 'toml'
import { parse as loadToml } from '@iarna/toml'
import tomlify from 'tomlify-j0.4'

// Parse from TOML to JavaScript
Expand Down
7 changes: 6 additions & 1 deletion packages/config/tests/parse/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ Generated by [AVA](https://avajs.dev).
`When resolving config file packages/config/tests/parse/fixtures/parse_error/netlify.toml:␊
Could not parse configuration file␊
Expected "/"", "/U", "//"", "//", "/b", "/f", "/n", "/r", "/t", "/u" or any character but end of input found.`
Unterminated string at row 1, col 3, pos 2:␊
1> "␊
^␊
2: ␊
`

## Configuration file - valid backslash sequences in TOML should not fail

Expand Down
Binary file modified packages/config/tests/parse/snapshots/tests.js.snap
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/headers-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"author": "Netlify",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",
"escape-string-regexp": "^5.0.0",
"fast-safe-stringify": "^2.0.7",
"is-plain-obj": "^4.0.0",
"map-obj": "^5.0.0",
"path-exists": "^5.0.0",
"toml": "^3.0.0"
"path-exists": "^5.0.0"
},
"devDependencies": {
"@types/node": "^14.18.53",
Expand Down
2 changes: 1 addition & 1 deletion packages/headers-parser/src/netlify_config_parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs } from 'fs'

import { parse as loadToml } from '@iarna/toml'
import { pathExists } from 'path-exists'
import { parse as loadToml } from 'toml'

import { splitResults } from './results.js'

Expand Down
4 changes: 2 additions & 2 deletions packages/redirect-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"author": "Netlify",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",
"fast-safe-stringify": "^2.1.1",
"filter-obj": "^5.0.0",
"is-plain-obj": "^4.0.0",
"path-exists": "^5.0.0",
"toml": "^3.0.0"
"path-exists": "^5.0.0"
},
"devDependencies": {
"@types/node": "^14.18.53",
Expand Down
2 changes: 1 addition & 1 deletion packages/redirect-parser/src/netlify_config_parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs } from 'fs'

import { parse as loadToml } from '@iarna/toml'
import { pathExists } from 'path-exists'
import { parse as loadToml } from 'toml'

import { splitResults } from './results.js'

Expand Down

0 comments on commit ba81c85

Please sign in to comment.