Skip to content

Commit cb611a9

Browse files
committed
refactor: type global configuration file
Follow-up to a comment thread in #7199. This changeset adds types for the global configuration file (`$CONFIG_HOME/netlify/config.json`). This is mainly a step forward in documenting the configuration format. The type safety on it isn't ideal; e.g. you can try to read or write properties that don't exist in the config schema. That said, it's an improvement on the read side in the sense that any property you read is typed--even unknown ones default to `undefined`. This comes with two _potential_ breaking changes; I didn't find that they actually broke anything in practice, but they're worth looking out for in review: 1. We now set defaults for some values we did not previously set defaults for, e.g. `users[id: string].auth` defaults to an object. This could only break if a code path assumes e.g. the presence of `auth.github` means the user is authenticated; however, the way the types are structured marks all properties on that object as undefined, so this is a difficult error to make now. 2. We now validate that `users[id: string].id` is set. Failing to set it would make looking up user configuration impossible (we index into this object using the top-level `userId` field), so this prevents a class of mysterious logic errors. Stronger typing caused some issues in tests that mock the global config store; broke the `GlobalConfigStore`'s storage logic out into an adapter and implemented an in-memory adapter for use in tests. There are better ways to solve this problem--tests should be able to mock the global config without resorting to module mocking--but this will do for now. I think the global config store interface could use some work: at this point I think the dot-prop style of setting and getting properties only adds complexity vs something like a Proxy-wrapped object. That said, this is a step forward without committing to a bigger change.
1 parent 546f156 commit cb611a9

18 files changed

+509
-436
lines changed

package-lock.json

+79-100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@
152152
"uuid": "11.1.0",
153153
"wait-port": "1.1.0",
154154
"write-file-atomic": "5.0.1",
155-
"ws": "8.18.1"
155+
"ws": "8.18.1",
156+
"zod": "^3.24.3"
156157
},
157158
"devDependencies": {
158159
"@babel/preset-react": "7.26.3",
@@ -208,6 +209,7 @@
208209
"temp-dir": "3.0.0",
209210
"tree-kill": "1.2.2",
210211
"tsx": "^4.19.3",
212+
"type-fest": "4.40.0",
211213
"typescript": "5.8.3",
212214
"typescript-eslint": "^8.26.0",
213215
"verdaccio": "6.1.2",

src/commands/logs/build.ts

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export const logsBuild = async (options: OptionValues, command: BaseCommand) =>
3939
const { id: siteId } = site
4040
const userId = command.netlify.globalConfig.get('userId')
4141

42+
if (!userId) {
43+
log('You must authenticate before attempting to view deploy logs')
44+
return
45+
}
46+
4247
if (!siteId) {
4348
log('You must link a site before attempting to view deploy logs')
4449
return

src/commands/status/status.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type BaseCommand from '../base-command.js'
1616

1717
export const status = async (options: OptionValues, command: BaseCommand) => {
1818
const { accounts, api, globalConfig, site, siteInfo } = command.netlify
19-
const currentUserId = globalConfig.get('userId') as string | undefined
19+
const currentUserId = globalConfig.get('userId')
2020
const [accessToken] = await getToken()
2121

2222
if (!accessToken) {
@@ -48,7 +48,7 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
4848

4949
const ghuser =
5050
currentUserId != null
51-
? (globalConfig.get(`users.${currentUserId}.auth.github.user`) as string | undefined)
51+
? (globalConfig.get(`users.${currentUserId}.auth.github.user`))
5252
: undefined
5353
const accountData = {
5454
Name: user.full_name,

0 commit comments

Comments
 (0)