josephtzeng / hocon-parser

A HOCON Parser for Node.js
ISC License
31 stars 10 forks source link

parse-hocon fails with `Invalid component 'classpath'.` #33

Closed ddebrecenijr closed 1 year ago

ddebrecenijr commented 1 year ago

According to the Hocon Spec you should be able to use classpath() for classpath resources. But if you were to test this with a small example like so:

myconf.conf

simple-test {
  description = "Using classpath fails with error"
  include classpath("lib/common.conf")
}

lib/common.conf

common-value = 42

With an execution of $ parse-hocon myconf.conf, you will get the error Invalid component 'classpath'

I did a little digging into the source code and (pardon my JS) it seems that adding classpath to the FLAGS const in Context.js would get you partially there. It'll attempt to use the FileSource component. However, I am guessing that a custom component is required to get it working correctly, similarly to ModulepathSource.

josephtzeng commented 1 year ago

Because classpath is a Java concept, I used modulepath to make it more specific to Node.js. Your example should work If you change classpath to modulepath. I will add classpath as an alias of modulepath later this week.

ddebrecenijr commented 1 year ago

I see. That makes sense. Locally, I could not get modulepath to work, but my use case wouldn't support that anyways. I have a Go application that uses parse-hocon in order to read some specific settings, such as the port number of a service, that I want to start via docker. That same service (Scala) also reads the configuration file on startup, but is using Lightbend's Typesafe Config for loading. There modulepath wouldn't be recognized unfortunately. I'm not using the library that is available for Go because that has its own issues 😅

josephtzeng commented 1 year ago

resolved by 28684ae.