Skip to content

Commit

Permalink
fix: parse date objects from config files (#6236)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored Mar 14, 2023
1 parent 4622b42 commit 968f63a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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')

0 comments on commit 968f63a

Please sign in to comment.