Skip to content

Commit c9c1c17

Browse files
committed
chore: update more dependencies
1 parent 4984dec commit c9c1c17

12 files changed

Lines changed: 331 additions & 244 deletions

File tree

‎package-lock.json‎

Lines changed: 245 additions & 179 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,31 @@
4444
},
4545
"type": "module",
4646
"dependencies": {
47-
"@aws-sdk/client-lambda": "^3.1102.0",
47+
"@aws-sdk/client-lambda": "^3.1110.0",
4848
"@inquirer/prompts": "^8.5.2",
4949
"@smartthings/core-sdk": "^8.5.3",
5050
"axios": "1.19.0",
5151
"chalk": "^6.0.0",
52-
"env-paths": "^3.0.0",
53-
"eventsource": "^4.1.0",
52+
"env-paths": "^4.0.0",
53+
"eventsource": "^5.1.0",
5454
"express": "^5.2.1",
5555
"get-port-please": "^3.2.0",
56-
"js-yaml": "^4.2.0",
56+
"js-yaml": "^5.3.0",
5757
"jszip": "^3.10.1",
5858
"lodash.at": "^4.6.0",
5959
"log4js": "^6.9.1",
60-
"open": "^11.0.0",
60+
"open": "^11.0.1",
6161
"ora": "^9.4.1",
6262
"os-locale": "^8.0.0",
6363
"picomatch": "^4.0.5",
6464
"qs": "^6.15.3",
6565
"table": "^6.9.0",
6666
"ts-node": "^10.9.2",
6767
"tslib": "^2.8.1",
68-
"tsx": "^4.23.5",
68+
"tsx": "^4.23.12",
6969
"undici": "^8.10.0",
7070
"uuid": "^14.0.1",
71-
"yargs": "^18.0.0"
71+
"yargs": "^18.1.0"
7272
},
7373
"devDependencies": {
7474
"@changesets/changelog-github": "^0.7.0",
@@ -88,13 +88,13 @@
8888
"@types/picomatch": "^4.0.3",
8989
"@types/qs": "^6.15.1",
9090
"@types/yargs": "^17.0.35",
91-
"@vercel/ncc": "^0.44.1",
91+
"@vercel/ncc": "^0.45.0",
9292
"archiver": "^8.0.0",
9393
"cz-conventional-changelog": "^3.3.0",
9494
"eslint": "^10.8.0",
9595
"eslint-plugin-import-x": "^4.17.1",
9696
"eslint-plugin-jest": "^29.16.0",
97-
"globals": "^17.9.0",
97+
"globals": "^17.11.0",
9898
"jest": "^30.4.2",
9999
"jest-environment-jsdom": "^30.4.1",
100100
"jest-extended": "^7.0.0",

‎src/__tests__/lib/cli-config.test.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { jest } from '@jest/globals'
22

33
import type { readFile, writeFile } from 'node:fs/promises'
44

5-
import type yaml from 'js-yaml'
5+
import { type load, type dump, YAML11_SCHEMA } from 'js-yaml'
66

77
import type {
88
CLIConfig,
@@ -20,15 +20,17 @@ jest.unstable_mockModule('node:fs/promises', () => ({
2020
writeFile: writeFileMock,
2121
}))
2222

23-
const yamlLoadMock = jest.fn<typeof yaml.load>()
24-
const yamlDumpMock = jest.fn<typeof yaml.dump>()
23+
const yamlLoadMock = jest.fn<typeof load>()
24+
const yamlDumpMock = jest.fn<typeof dump>()
2525
jest.unstable_mockModule('js-yaml', () => ({
26-
default: {
27-
load: yamlLoadMock,
28-
dump: yamlDumpMock,
29-
},
26+
load: yamlLoadMock,
27+
dump: yamlDumpMock,
28+
// eslint-disable-next-line @typescript-eslint/naming-convention
29+
YAML11_SCHEMA,
3030
}))
3131

32+
const yamlLoadOptions = { schema: YAML11_SCHEMA }
33+
3234
const { loggerMock, warnMock } = await import('../test-lib/logger-mock.js')
3335

3436
const yamlExistsMock = jest.fn<typeof yamlExists>()
@@ -67,18 +69,16 @@ describe('loadConfigFile', () => {
6769
expect(readFileMock).toHaveBeenCalledTimes(0)
6870
})
6971

70-
it('returns empty object for empty file', async () => {
71-
readFileMock.mockResolvedValueOnce('empty contents')
72-
yamlLoadMock.mockReturnValueOnce('')
72+
it.each([undefined, null, ''])('returns empty object for empty file', async (fileContents) => {
73+
readFileMock.mockResolvedValueOnce(fileContents as string)
7374

7475
expect(await loadConfigFile('empty file')).toEqual({})
7576

7677
expect(yamlExistsMock).toHaveBeenCalledTimes(1)
7778
expect(yamlExistsMock).toHaveBeenCalledWith('empty file')
7879
expect(readFileMock).toHaveBeenCalledTimes(1)
7980
expect(readFileMock).toHaveBeenCalledWith('empty file', 'utf-8')
80-
expect(yamlLoadMock).toHaveBeenCalledTimes(1)
81-
expect(yamlLoadMock).toHaveBeenCalledWith('empty contents')
81+
expect(yamlLoadMock).not.toHaveBeenCalled()
8282
})
8383

8484
it.each(['string', ['array']])('throws error for non-object yaml file', async (parsedYAML) => {
@@ -92,7 +92,7 @@ describe('loadConfigFile', () => {
9292
expect(readFileMock).toHaveBeenCalledTimes(1)
9393
expect(readFileMock).toHaveBeenCalledWith('configFilename.json', 'utf-8')
9494
expect(yamlLoadMock).toHaveBeenCalledTimes(1)
95-
expect(yamlLoadMock).toHaveBeenCalledWith('file contents')
95+
expect(yamlLoadMock).toHaveBeenCalledWith('file contents', yamlLoadOptions)
9696
expect(fatalErrorMock).toHaveBeenCalledExactlyOnceWith(
9797
'invalid config file format\n' + seeConfigDocs,
9898
)
@@ -113,7 +113,7 @@ describe('loadConfigFile', () => {
113113
expect(readFileMock).toHaveBeenCalledTimes(1)
114114
expect(readFileMock).toHaveBeenCalledWith('file with bad configs', 'utf-8')
115115
expect(yamlLoadMock).toHaveBeenCalledTimes(1)
116-
expect(yamlLoadMock).toHaveBeenCalledWith('config with multiple errors')
116+
expect(yamlLoadMock).toHaveBeenCalledWith('config with multiple errors', yamlLoadOptions)
117117
expect(fatalErrorMock).toHaveBeenCalledExactlyOnceWith(
118118
'bad profile badProfile1; profile must be an object\n' +
119119
'bad profile badProfile2; profile must be an object\n' +
@@ -141,7 +141,7 @@ describe('loadConfigFile', () => {
141141
expect(readFileMock).toHaveBeenCalledTimes(1)
142142
expect(readFileMock).toHaveBeenCalledWith('good file', 'utf-8')
143143
expect(yamlLoadMock).toHaveBeenCalledTimes(1)
144-
expect(yamlLoadMock).toHaveBeenCalledWith('good contents')
144+
expect(yamlLoadMock).toHaveBeenCalledWith('good contents', yamlLoadOptions)
145145
})
146146
})
147147

‎src/__tests__/lib/file-util.test.ts‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { jest } from '@jest/globals'
22

33
import { readFileSync, promises as fsPromises, Stats } from 'node:fs'
44

5-
import type yaml from 'js-yaml'
5+
import { type load, YAML11_SCHEMA } from 'js-yaml'
66

77
import { type YAMLFileData } from '../../lib/file-util.js'
88
import type { fatalError } from '../../lib/util.js'
@@ -24,13 +24,11 @@ jest.unstable_mockModule('node:fs/promises', () => ({
2424
realpath: realpathMock,
2525
}))
2626

27-
const yamlLoadMock = jest.fn<typeof yaml.load>()
28-
const yamlDumpMock = jest.fn<typeof yaml.dump>()
27+
const yamlLoadMock = jest.fn<typeof load>()
2928
jest.unstable_mockModule('js-yaml', () => ({
30-
default: {
31-
load: yamlLoadMock,
32-
dump: yamlDumpMock,
33-
},
29+
load: yamlLoadMock,
30+
// eslint-disable-next-line @typescript-eslint/naming-convention
31+
YAML11_SCHEMA,
3432
}))
3533

3634
const fatalErrorMock = jest.fn<typeof fatalError>()
@@ -271,7 +269,7 @@ describe('readYAMLFile', () => {
271269
expect(readYAMLFile('filename')).toBe(yamlFile)
272270

273271
expect(readFileSyncMock).toHaveBeenCalledExactlyOnceWith('filename', 'utf-8')
274-
expect(yamlLoadMock).toHaveBeenCalledExactlyOnceWith('file contents')
272+
expect(yamlLoadMock).toHaveBeenCalledExactlyOnceWith('file contents', { schema: YAML11_SCHEMA })
275273
})
276274

277275
it('passes error message into user-facing error', () => {
@@ -285,18 +283,31 @@ describe('readYAMLFile', () => {
285283
})
286284

287285
it.each`
288-
invalidYaml | errorMessage
289-
${{}} | ${'invalid file filename'}
290-
${null} | ${'empty file filename'}
291-
${''} | ${'invalid file filename'}
292-
${0} | ${'invalid file filename'}
293-
`('throws $errorMessage when reading $invalidYaml', ({ invalidYaml, errorMessage }) => {
286+
invalidYaml
287+
${{}}
288+
${0}
289+
`('throws "invalid file filename" when reading $invalidYaml', ({ invalidYaml }) => {
294290
readFileSyncMock.mockReturnValueOnce('file contents')
295291
yamlLoadMock.mockReturnValueOnce(invalidYaml)
296292
fatalErrorMock.mockReturnValueOnce('never return' as never)
297293

298294
expect(readYAMLFile('filename')).toBe('never return')
299295

300-
expect(fatalErrorMock).toHaveBeenCalledWith(errorMessage)
296+
expect(fatalErrorMock).toHaveBeenCalledWith('invalid file filename')
297+
})
298+
299+
it.each`
300+
invalidYaml
301+
${null}
302+
${''}
303+
${undefined}
304+
`('throws "empty file filename" when reading $invalidYaml', ({ invalidYaml }) => {
305+
readFileSyncMock.mockReturnValueOnce(invalidYaml)
306+
fatalErrorMock.mockReturnValueOnce('never return' as never)
307+
308+
expect(readYAMLFile('filename')).toBe('never return')
309+
310+
expect(fatalErrorMock).toHaveBeenCalledWith('empty file filename')
311+
expect(yamlLoadMock).not.toHaveBeenCalled()
301312
})
302313
})

‎src/__tests__/lib/log-utils.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { jest } from '@jest/globals'
33
import { type readFileSync } from 'node:fs'
44

55
import log4js, { type Logger } from 'log4js'
6-
import type yaml from 'js-yaml'
6+
import { type load, YAML11_SCHEMA } from 'js-yaml'
77

88
import type { yamlExists } from '../../lib/io-util.js'
99
import { fatalError } from '../../lib/util.js'
@@ -16,11 +16,11 @@ jest.unstable_mockModule('node:fs', () => ({
1616
},
1717
}))
1818

19-
const yamlLoadMock = jest.fn<typeof yaml.load>()
19+
const yamlLoadMock = jest.fn<typeof load>()
2020
jest.unstable_mockModule('js-yaml', () => ({
21-
default: {
22-
load: yamlLoadMock,
23-
},
21+
load: yamlLoadMock,
22+
// eslint-disable-next-line @typescript-eslint/naming-convention
23+
YAML11_SCHEMA,
2424
}))
2525

2626
const yamlExistsMock = jest.fn<typeof yamlExists>()
@@ -101,7 +101,7 @@ describe('loadLog4jsConfig', () => {
101101
expect(loadLog4jsConfig('filename', defaultConfig)).toStrictEqual(loadedConfig)
102102

103103
expect(readFileSyncMock).toHaveBeenCalledExactlyOnceWith('filename', 'utf-8')
104-
expect(yamlLoadMock).toHaveBeenCalledExactlyOnceWith('file contents')
104+
expect(yamlLoadMock).toHaveBeenCalledExactlyOnceWith('file contents', { schema: YAML11_SCHEMA })
105105
})
106106

107107
it('ends with error if config is invalid', () => {
@@ -115,7 +115,7 @@ describe('loadLog4jsConfig', () => {
115115
expect(loadLog4jsConfig('filename', defaultConfig)).toBe('never return')
116116

117117
expect(readFileSyncMock).toHaveBeenCalledExactlyOnceWith('filename', 'utf-8')
118-
expect(yamlLoadMock).toHaveBeenCalledExactlyOnceWith('bad file contents')
118+
expect(yamlLoadMock).toHaveBeenCalledExactlyOnceWith('bad file contents', { schema: YAML11_SCHEMA })
119119

120120
expect(fatalErrorMock).toHaveBeenCalledExactlyOnceWith(
121121
expect.stringContaining('invalid or unreadable logging config file format'),

‎src/commands/config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'node:path'
22

3-
import yaml from 'js-yaml'
3+
import { dump } from 'js-yaml'
44
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'
55

66
import { type Profile } from '../lib/cli-config.js'
@@ -52,7 +52,7 @@ const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> =>
5252
]
5353
const tableFieldDefinitions: TableFieldDefinition<ProfileWithName>[] = [
5454
...listTableFieldDefinitions,
55-
{ label: 'Definition', value: item => yaml.dump(item.profile) },
55+
{ label: 'Definition', value: item => dump(item.profile) },
5656
]
5757

5858
const outputListConfig: OutputListConfig<ProfileWithName> = {

‎src/lib/cli-config.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFile, writeFile } from 'node:fs/promises'
22

33
import { type Logger } from 'log4js'
4-
import yaml from 'js-yaml'
4+
import { dump, load, YAML11_SCHEMA } from 'js-yaml'
55

66
import { yamlExists } from './io-util.js'
77
import { fatalError } from './util.js'
@@ -72,7 +72,8 @@ export const loadConfigFile = async (filename: string): Promise<ProfilesByName>
7272
return {}
7373
}
7474

75-
const parsed = yaml.load(await readFile(filename, 'utf-8'))
75+
const contents = await readFile(filename, 'utf-8')
76+
const parsed = contents?.trim() ? load(contents, { schema: YAML11_SCHEMA }) : {}
7677
if (parsed) {
7778
if (typeof parsed === 'object' && !Array.isArray(parsed)) {
7879
const errors: string[] = []
@@ -178,13 +179,13 @@ export const loadConfig = async (description: CLIConfigDescription, logger: Logg
178179

179180
/**
180181
* Generate managed config file contents. If there are no profiles to save, we skip calling
181-
* `yaml.dump` which returns `{}` in that case.
182+
* `dump` which returns `{}` in that case.
182183
*/
183184
export const buildManagedConfigFileContents = (config: CLIConfig): string =>
184185
`# This file is used to store settings managed by the CLI. Users are not meant to edit it directly.
185186
# Any options in the main config file will override values from this one.
186187
187-
` + (Object.keys(config.managedProfiles).length > 0 ? yaml.dump(config.managedProfiles) : '')
188+
` + (Object.keys(config.managedProfiles).length > 0 ? dump(config.managedProfiles) : '')
188189

189190
/**
190191
* Save the specified configuration key into managed config so it will be picked up

‎src/lib/command/output.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { writeFile } from 'node:fs/promises'
22

3-
import yaml from 'js-yaml'
3+
import { dump } from 'js-yaml'
44
import { Argv } from 'yargs'
55

66
import { formatFromFilename, IOFormat, stdoutIsTTY } from '../io-util.js'
@@ -52,7 +52,7 @@ export const jsonFormatter = <T extends object>(indent: number): OutputFormatter
5252
(data: T) => JSON.stringify(data, null, indent)
5353

5454
export const yamlFormatter = <T extends object>(indent: number): OutputFormatter<T> =>
55-
(data: T) => yaml.dump(data, { indent })
55+
(data: T) => dump(data, { indent })
5656

5757
export const itemTableFormatter =
5858
<T extends object>(tableGenerator: TableGenerator, fieldDefinitions: TableFieldDefinition<T>[]): OutputFormatter<T> =>

‎src/lib/command/smartthings-command.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ export const getConfigDirsCheckingForOldConfig = async (
8585
// The documentation says not to use `suffix` "unless you really have to" but the directories
8686
// get suffixed with `-nodejs` without using it. This would be fine for the data directory,
8787
// but for the config and log directories that users might use, it seems rather ugly.
88-
const { config: configDir, data: dataDir, log: logDir } = envPaths('@smartthings/cli', { suffix: '' })
88+
const { config, data, log } = envPaths('@smartthings_cli', { suffix: '' })
89+
90+
// Version 4.0.0 no longer allows `/` as part of the path so we use `_` in the request
91+
// and substitute `/` back in the results.
92+
const backToSlash = (path: string): string => path.replace(/@smartthings_cli/, '@smartthings/cli')
93+
const configDir = backToSlash(config)
94+
const dataDir = backToSlash(data)
95+
const logDir = backToSlash(log)
8996
if (options.verboseLogging) {
9097
console.error(`config dir = ${configDir}`)
9198
console.error(`data dir = ${dataDir}`)

‎src/lib/file-util.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFileSync } from 'node:fs'
22
import { lstat, mkdir, realpath, stat } from 'node:fs/promises'
33

4-
import yaml from 'js-yaml'
4+
import { load, YAML11_SCHEMA } from 'js-yaml'
55

66
import { fatalError } from './util.js'
77

@@ -75,13 +75,14 @@ const isYAMLFileData = (data: unknown): data is YAMLFileData =>
7575

7676
export const readYAMLFile = (filename: string): YAMLFileData => {
7777
try {
78-
const data = yaml.load(readFileSync(filename, 'utf-8'))
79-
if (isYAMLFileData(data)) {
80-
return data
78+
const contents = readFileSync(filename, 'utf-8')
79+
if (!contents?.trim()) {
80+
return fatalError(`empty file ${filename}`)
8181
}
8282

83-
if (data == null) {
84-
return fatalError(`empty file ${filename}`)
83+
const data = load(contents, { schema: YAML11_SCHEMA })
84+
if (isYAMLFileData(data)) {
85+
return data
8586
}
8687

8788
return fatalError(`invalid file ${filename}`)

0 commit comments

Comments
 (0)