Skip to content

Commit

Permalink
chore(deps): Switch to smol-toml (#10746)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jun 7, 2024
1 parent 0b5408a commit b5ad2c3
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 63 deletions.
2 changes: 1 addition & 1 deletion packages/cli-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@babel/core": "^7.22.20",
"@iarna/toml": "2.2.5",
"@opentelemetry/api": "1.8.0",
"@redwoodjs/project-config": "workspace:*",
"@redwoodjs/telemetry": "workspace:*",
Expand All @@ -40,6 +39,7 @@
"pascalcase": "1.0.0",
"prettier": "3.2.5",
"prompts": "2.4.2",
"smol-toml": "1.2.1",
"terminal-link": "2.1.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ exports[`addEnvVar > addEnvVar adds environment variables as part of a setup tas
exports[`updateTomlConfig > updateTomlConfig configures a new CLI plugin > adds package but keeps autoInstall false 1`] = `
"[web]
title = "Redwood App"
port = 8_910
port = 8910
apiUrl = "/.redwood/functions"
includeEnvironmentVariables = [ ]
includeEnvironmentVariables = []
[api]
port = 8_911
port = 8911
[experimental]
[experimental.cli]
autoInstall = false
[experimental]
[experimental.cli]
[[experimental.cli.plugins]]
package = "@example/test-package-when-autoInstall-false"
enabled = true
Expand All @@ -72,19 +74,21 @@ enabled = true
exports[`updateTomlConfig > updateTomlConfig configures a new CLI plugin > adds when experimental cli has some plugins configured 1`] = `
"[web]
title = "Redwood App"
port = 8_910
port = 8910
apiUrl = "/.redwood/functions"
includeEnvironmentVariables = [ ]
includeEnvironmentVariables = []
[api]
port = 8_911
port = 8911
[experimental]
[experimental.cli]
autoInstall = true
[[experimental.cli.plugins]]
package = "@existing-example/some-package-when-cli-has-some-packages-configured"
[[experimental.cli.plugins]]
package = "@existing-example/some-package-when-cli-has-some-packages-configured"
[experimental]
[experimental.cli]
[[experimental.cli.plugins]]
package = "@example/test-package-name"
enabled = true
Expand All @@ -94,35 +98,37 @@ enabled = true
exports[`updateTomlConfig > updateTomlConfig configures a new CLI plugin > adds when experimental cli is not configured 1`] = `
"[web]
title = "Redwood App"
port = 8_910
port = 8910
apiUrl = "/.redwood/functions"
includeEnvironmentVariables = [ ]
includeEnvironmentVariables = []
[api]
port = 8_911
port = 8911
[experimental]
[experimental.cli]
autoInstall = true
[[experimental.cli.plugins]]
package = "@example/test-package-when-cli-not-configured"
enabled = true
[[experimental.cli.plugins]]
package = "@example/test-package-when-cli-not-configured"
enabled = true
"
`;

exports[`updateTomlConfig > updateTomlConfig configures a new CLI plugin > adds when experimental cli is setup but has no plugins configured 1`] = `
"[web]
title = "Redwood App"
port = 8_910
port = 8910
apiUrl = "/.redwood/functions"
includeEnvironmentVariables = [ ]
includeEnvironmentVariables = []
[api]
port = 8_911
port = 8911
[experimental]
[experimental.cli]
autoInstall = true
[experimental]
[experimental.cli]
[[experimental.cli.plugins]]
package = "@example/test-package-when-no-plugins-configured"
enabled = true
Expand All @@ -132,18 +138,18 @@ enabled = true
exports[`updateTomlConfig > updateTomlConfig configures a new CLI plugin > does not add duplicate place when experimental cli has that plugin configured 1`] = `
"[web]
title = "Redwood App"
port = 8_910
port = 8910
apiUrl = "/.redwood/functions"
includeEnvironmentVariables = [ ]
includeEnvironmentVariables = []
[api]
port = 8_911
port = 8911
[experimental]
[experimental.cli]
autoInstall = true
[[experimental.cli.plugins]]
package = "@existing-example/some-package-name-already-exists"
[[experimental.cli.plugins]]
package = "@existing-example/some-package-name-already-exists"
"
`;
2 changes: 1 addition & 1 deletion packages/cli-helpers/src/lib/__tests__/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vi.mock('node:fs', async () => {

import * as fs from 'node:fs'

import * as toml from '@iarna/toml'
import * as toml from 'smol-toml'
import { vi, describe, beforeEach, afterEach, it, expect } from 'vitest'

import { updateTomlConfig, addEnvVar } from '../project.js'
Expand Down
22 changes: 14 additions & 8 deletions packages/cli-helpers/src/lib/project.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as fs from 'node:fs'
import * as path from 'node:path'

import type { JsonMap } from '@iarna/toml'
import toml from '@iarna/toml'
import dotenv from 'dotenv'
import toml from 'smol-toml'

import type { Config } from '@redwoodjs/project-config'
import {
Expand Down Expand Up @@ -55,7 +54,7 @@ export const updateTomlConfig = (packageName: string) => {
const redwoodTomlPath = getConfigPath()
const originalTomlContent = fs.readFileSync(redwoodTomlPath, 'utf-8')

let tomlToAppend = {} as JsonMap
let tomlToAppend: Record<string, toml.TomlPrimitive> = {}

const config = getConfig(redwoodTomlPath)

Expand Down Expand Up @@ -94,7 +93,12 @@ export const updateTomlConfig = (packageName: string) => {
}
}

const newConfig = originalTomlContent + '\n' + toml.stringify(tomlToAppend)
const newConfig =
originalTomlContent +
'\n' +
(Object.keys(tomlToAppend).length > 0
? toml.stringify(tomlToAppend) + '\n'
: '')

return fs.writeFileSync(redwoodTomlPath, newConfig, 'utf-8')
}
Expand Down Expand Up @@ -207,11 +211,13 @@ export function setTomlSetting(
const redwoodTomlPath = getConfigPath()
const originalTomlContent = fs.readFileSync(redwoodTomlPath, 'utf-8')

// Can't type toml.parse because this PR has not been included in a released yet
// https://github.com/iarna/iarna-toml/commit/5a89e6e65281e4544e23d3dbaf9e8428ed8140e9
const redwoodTomlObject = toml.parse(originalTomlContent) as any
const redwoodTomlObject = toml.parse(originalTomlContent)
const sectionValue = redwoodTomlObject[section]

const existingValue = redwoodTomlObject?.[section]?.[setting]
const existingValue =
// I don't like this type cast, but I couldn't come up with a much better
// solution
(sectionValue as Record<string, toml.TomlPrimitive> | undefined)?.[setting]

// If the setting already exists in the given section, and has the given
// value already, just return
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.5",
"@iarna/toml": "2.2.5",
"@opentelemetry/api": "1.8.0",
"@opentelemetry/core": "1.22.0",
"@opentelemetry/exporter-trace-otlp-http": "0.49.1",
Expand Down Expand Up @@ -75,6 +74,7 @@
"prompts": "2.4.2",
"rimraf": "5.0.7",
"semver": "7.6.2",
"smol-toml": "1.2.1",
"string-env-interpolation": "1.0.1",
"systeminformation": "5.22.9",
"terminal-link": "2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/baremetal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path'

import toml from '@iarna/toml'
import boxen from 'boxen'
import fs from 'fs-extra'
import { Listr } from 'listr2'
import toml from 'smol-toml'
import { env as envInterpolation } from 'string-env-interpolation'
import terminalLink from 'terminal-link'
import { titleCase } from 'title-case'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path'

import toml from '@iarna/toml'
import { getSchema, getConfig } from '@prisma/internals'
import fs from 'fs-extra'
import { Listr } from 'listr2'
import toml from 'smol-toml'

import {
colors as c,
Expand Down
1 change: 0 additions & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@babel/plugin-transform-typescript": "^7.22.15",
"@babel/runtime-corejs3": "7.24.5",
"@babel/traverse": "^7.22.20",
"@iarna/toml": "2.2.5",
"@redwoodjs/project-config": "workspace:*",
"@svgr/core": "8.1.0",
"@svgr/plugin-jsx": "8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/project-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@iarna/toml": "2.2.5",
"deepmerge": "4.3.1",
"fast-glob": "3.3.2",
"smol-toml": "1.2.1",
"string-env-interpolation": "1.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/project-config/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'

import toml from '@iarna/toml'
import merge from 'deepmerge'
import toml from 'smol-toml'
import { env as envInterpolation } from 'string-env-interpolation'

import { getConfigPath } from './configPath.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/structure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
},
"dependencies": {
"@babel/runtime-corejs3": "7.24.5",
"@iarna/toml": "2.2.5",
"@prisma/internals": "5.14.0",
"@redwoodjs/project-config": "workspace:*",
"@types/line-column": "1.0.2",
Expand All @@ -44,6 +43,7 @@
"lodash-decorators": "6.0.1",
"lru-cache": "10.2.2",
"proxyquire": "2.1.3",
"smol-toml": "1.2.1",
"ts-morph": "15.1.0",
"vscode-languageserver": "6.1.1",
"vscode-languageserver-textdocument": "1.0.11",
Expand Down
10 changes: 3 additions & 7 deletions packages/structure/src/model/RWTOML.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { JsonMap } from '@iarna/toml'
import { parse as parseTOML } from '@iarna/toml'
import toml from 'smol-toml'
import { Range } from 'vscode-languageserver-types'

import { FileNode } from '../ide'
Expand All @@ -20,13 +19,10 @@ export class RWTOML extends FileNode {
// }
// TODO: diagnostics
@lazy() get parsedTOML() {
return parseTOML(this.text)
return toml.parse(this.text)
}
@lazy() get web_includeEnvironmentVariables(): string[] | undefined {
return (
((this.parsedTOML?.web as JsonMap)
?.includeEnvironmentVariables as string[]) ?? []
)
return this.parsedTOML?.web?.['includeEnvironmentVariables'] ?? []
}
*diagnostics() {
try {
Expand Down
Loading

0 comments on commit b5ad2c3

Please sign in to comment.