Skip to content

fix: parse date objects from config files #6236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2023
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
5 changes: 5 additions & 0 deletions workspaces/config/lib/parse-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const parseField = (f, key, opts, listElement = false) => {
const isUmask = typeList.has(typeDefs.Umask.type)
const isNumber = typeList.has(typeDefs.Number.type)
const isList = !listElement && typeList.has(Array)
const isDate = typeList.has(typeDefs.Date.type)

if (Array.isArray(f)) {
return !isList ? f : f.map(field => parseField(field, key, opts, true))
Expand Down Expand Up @@ -53,6 +54,10 @@ const parseField = (f, key, opts, listElement = false) => {

f = envReplace(f, env)

if (isDate) {
return new Date(f)
}

if (isPath) {
const homePattern = platform === 'win32' ? /^~(\/|\\)/ : /^~\//
if (homePattern.test(f) && home) {
Expand Down
2 changes: 2 additions & 0 deletions workspaces/config/test/parse-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ t.equal(parseField('1234', 'maxsockets', opts), 1234, 'number is parsed')
t.equal(parseField('0888', 'umask', opts), '0888',
'invalid umask is not parsed (will warn later)')
t.equal(parseField('0777', 'umask', opts), 0o777, 'valid umask is parsed')

t.same(parseField('2020', 'before', opts), new Date('2020'), 'date is parsed')