Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/smol-toml-1-9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"wrangler": patch
"create-cloudflare": patch
"@cloudflare/workers-utils": patch
"@cloudflare/workers-auth": patch
---

Update `smol-toml` to 1.9.0 to fix slow parsing of very large TOML files

Parse time for TOML config files now grows linearly with their size, instead of with its square: a 40,000-line file that took 259 ms to parse now takes 17 ms, while typical `wrangler.toml` files parse in the same time as before. This addresses the `GHSA-r4xh-jqrq-34v2` advisory against earlier versions of the parser.

Some TOML syntax errors now point at the character that caused them. For example, a `wrangler.toml` containing `INVALID "FILE` is now reported as `illegal character in key` at the `"`, rather than `incomplete key-value` at the start of the line.
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { C3_DEFAULTS, openInBrowser } from "helpers/cli";
import { readFile } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import { poll } from "helpers/poll";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { isInsideGitRepo } from "./git";
import { chooseAccount, wranglerLogin } from "./wrangler/accounts";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/helpers/files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs, { existsSync, statSync } from "node:fs";
import { join } from "node:path";
import { parse, stringify } from "comment-json";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import type { C3Context, PackageJson } from "types";

export const copyFile = (path: string, dest: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { readFile, readJSON, usesTypescript, writeFile } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import { installPackages } from "helpers/packages";
import * as jsonc from "jsonc-parser";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import {
readWranglerJsonOrJsonc,
readWranglerToml,
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/wrangler/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
readJSONWithComments,
writeJSONWithComments,
} from "helpers/json";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import type { CommentObject, Reviver } from "comment-json";
import type { TomlTable } from "smol-toml";
import type { C3Context } from "types";
Expand Down
2 changes: 1 addition & 1 deletion packages/workers-auth/src/core/file-format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseTOML } from "@cloudflare/workers-utils";
import TOML from "smol-toml";
import * as TOML from "smol-toml";

/**
* On-disk serialization format for a CLI's config/credential files.
Expand Down
2 changes: 1 addition & 1 deletion packages/workers-utils/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { parseJSONC, parseTOML, readFileSync } from "../parse";
import { resolveWranglerConfigPath } from "./config-helpers";
import type { Config, RawConfig } from "./config";
Expand Down
2 changes: 1 addition & 1 deletion packages/workers-utils/src/config/patch-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from "node:fs";
import { applyEdits, format, modify } from "jsonc-parser";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { parseJSONC, parseTOML, readFileSync } from "../parse";
import type { RawConfig } from "./config";
import type { JSONPath } from "jsonc-parser";
Expand Down
4 changes: 2 additions & 2 deletions packages/workers-utils/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync as fsReadFileSync } from "node:fs";
import { resolve } from "node:path";
import * as jsoncParser from "jsonc-parser";
import TOML, { TomlError } from "smol-toml";
import * as TOML from "smol-toml";
import { UserError } from "./errors";
import type { TelemetryMessage } from "./errors";
import type { ParseError as JsoncParseError } from "jsonc-parser";
Expand Down Expand Up @@ -117,7 +117,7 @@ export function parseTOML(tomlContent: string, filePath?: string): unknown {
try {
return TOML.parse(tomlContent);
} catch (err) {
if (!(err instanceof TomlError)) {
if (!(err instanceof TOML.TomlError)) {
throw err;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { assert, describe, it, test, vi } from "vitest";
import { normalizeAndValidateConfig } from "../../../src/config/validation";
import { normalizeString } from "../../../src/test-helpers";
Expand Down
6 changes: 3 additions & 3 deletions packages/workers-utils/tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

describe("parseTOML", () => {
it("should parse toml that is empty", ({ expect }) => {
expect(parseTOML("")).toStrictEqual({});
expect(parseTOML("")).toEqual({});
});

it("should parse toml with basic values", ({ expect }) => {
Expand All @@ -20,7 +20,7 @@ describe("parseTOML", () => {
name = "basic"
version = 1
`)
).toStrictEqual({
).toEqual({
name: "basic",
version: 1,
});
Expand All @@ -37,7 +37,7 @@ describe("parseTOML", () => {
[owner.dog]
exists = true
`)
).toStrictEqual({
).toEqual({
name: "complex",
owner: {
alive: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/pages/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@cloudflare/workers-utils/test-helpers";
import ci from "ci-info";
import { http, HttpResponse } from "msw";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { x } from "tinyexec";
import dedent from "ts-dedent";
/* eslint-disable-next-line no-restricted-imports --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ describe("pages build env", () => {

expect(process.exitCode).toEqual(EXIT_CODE_INVALID_PAGES_CONFIG);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Invalid TOML document: incomplete key-value: cannot find end of key
"X [ERROR] Invalid TOML document: illegal character in key

<cwd>/wrangler.toml:1:0:
 1 │ INVALID "FILE
╵ ^
<cwd>/wrangler.toml:1:8:
 1 │ INVALID "FILE
╵ ^

"
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UserError,
} from "@cloudflare/workers-utils";
import chalk from "chalk";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { FormData } from "undici";
import { fetchResult } from "./cfetch";
import { readConfig } from "./config";
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/pages/download-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
UserError,
} from "@cloudflare/workers-utils";
import chalk from "chalk";
import TOML from "smol-toml";
import * as TOML from "smol-toml";
import { fetchResult } from "../cfetch";
import { getConfigCache } from "../config-cache";
import { createCommand } from "../core/create-command";
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ catalog:
"@cloudflare/workers-types": "^5.20260923.1"
workerd: "1.20260923.1"
jsonc-parser: "3.2.0"
smol-toml: "1.8.0"
smol-toml: "1.9.0"
msw: "2.14.6"
tinyglobby: "0.2.16"
"tree-kill": "1.2.2"
Expand Down
Loading