You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to use precompiled *.ts config files without ts-node? #416
You could put your .ts files in a different directory, and compile the .js files into the /config directory. Or you could change the extension of .ts to .tscript and tell the compiler to look for those files. Maybe other ways...
@lorenwest
I've met the issue as well, and want to join @V1c70r's question.
I don't think it is correct to force people to use ts-node, in my case the thing was, that as soon as config requires and registers ts-node - it starts to require and compile my ts files by it's own. However, this is something I do by myself, before I start the application.
It results into such kind of errors:
Cannot write file '/Users/PavelPolyakov/Sites/f1t100/api/$$ts-node$$/user.js' because it would be overwritten by multiple input files. (5056)
As for me, expected behaviour would be - js files have higher priority (if this was the case, config wouldn't even find .ts files, as I do compile them into .js) OR only config ts files are affected, the other part of the project should continue to work as it is designed.
@PavelPolyakov I'm author of TS changes. I understand your problem. Turned out that running ts-node wasn't ideal idea. It should be done:
using TS standalone compiler
using Babel 7 preset/typescript
For now I would advice you to just skip TS file and run config on transformed versions. I'm working on own config library, modern & more composable in which I'll probably use Babel 7 approach to parse TS files. Can ping you when ready (probably until end of this year) as I don't consider further contributions to node-config because it has some technical debt.
@benedyktdryl I'll be interested to see what you come up with, also the specifics of what you see as the technical debt there. We have the option to make breaking changes and release a new major version when that seems best, and contributors are welcome to help address open issues.
Ok, let me point strongly at first that I appreciate your work on this stuff and I remember it helped me a lot in several projects. For now, however, I think it's time to move on and I don't think it will be possible with current codebase. I will also point out to my repository with very first version of my concept of config but it's not an ad as it's for now not even tested or published on NPM.
I don't want to argue with anyone, I'll try to put arguments next to my opinions about technical debt:
codebase is not extensible
main file have 1772 lines of code, I like that it's commented strongly but I do think that putting core into separate files should be first thing to do to keep this config library maintainers friendly
ES5 and CommonJS modules usage node-config is not using ES2015 module system, it's not using modern language constructions. It's still ES5, despite minimal version of node is marked as v4, which means it should handle most of ES6 expressions by default. Still we can distribute cutting edge version with ES6 and TC39 4th stage features. It should also make it more friendly for maintainers. Lot of beginners is learning ES6 so we can encourage them to maintain node-config by such changes.
Utils
Currently utils are containing methods which are already implemented by ie. lodash. Why not to use methods from widely used and tested library which became JS STD library instead of creating own versions of them?
Polluting returned values prototype unnecessary
I don't agree that adding some utils to prototype of returned config value is good idea. From 2015, node-config still don't have getRaw method equivalent to retrieve plain JS configuration object
Not allowing async configuration
Imagine that we want to handle AWS config or use same node-config module to retrieve some configuration from files, some from env variables and some from Redis. Native async support is needed.
How my config is different:
I made initial architecture decisions so they are either fixing or allowing to fix some issues which I mentioned or issues which are actually waiting for contribution or that are simply not solvable for now.
core/handlers/providers: @config is utilising concept of:
core: core which is injecting settings to providers and executing them in user preserved order
providers: they are providing values from which our config is composed and passing content to handlers so at the end they are returning JS object
handlers: they are handling providers content. It's not only parsing as it can be stream or binary content so it's not always string parsing
Thanks to such splitting, we are separating strategy of preserving values for config from parsing them. Lot of different providers can use same handler. This means that we don't need to change core for some customisation requests, we can simply write new provider. In example, I want to implement provider which is providing values with same strategy as this module (full description HERE):
Also if you want to handle big files, nothing stop you from making stream based handler.
monorepo approach: @config is library split into several packages which are managed by Lerna. Thanks to this, we have separated modules with own dependencies and also separation of concerns is more enforced.
TS based
Library is written in TypeScript to make easier tasks like tracking dependencies and generating documentation. Interface of handlers/providers is clean and described by TypeScript which will detect most of issues during compilation
Async by default
Configuration initialisation is async by default code is using async/await which is converted to generators under hood. Handlers are asynchronous so parsing is completely non-blocking. Providers are also asynchronous so we can create Redis provider which will use async connection.
Preset which mimic node-config
I created preset which is my kind of tests for now (as I don't have any tests) and it's trying to have same features as node-config (not all for now obviously).
@PavelPolyakov Regarding TS, I wrote handler which is using Babel 7.x beta with preset/typescript to parse TS files. No type checking for now but I'm considering some type checking using THIS. If you want to use node-config, my proposition is to implement TS handling as I described above.
Of course you're right about all of this. If anyone reading this thread is interested in this functionality, I suggest heading over there and giving it a try.
Had this project started in 2017 it would likely have taken this shape. That it started in 2010 and is relied on by so many projects means it will move in this direction more methodically.
Activity
lorenwest commentedon May 4, 2017
You could put your .ts files in a different directory, and compile the .js files into the /config directory. Or you could change the extension of .ts to .tscript and tell the compiler to look for those files. Maybe other ways...
PavloPoliakov commentedon Sep 28, 2017
@lorenwest
I've met the issue as well, and want to join @V1c70r's question.
I don't think it is correct to force people to use
ts-node, in my case the thing was, that as soon asconfigrequires and registersts-node- it starts to require and compile my ts files by it's own. However, this is something I do by myself, before I start the application.It results into such kind of errors:
As for me, expected behaviour would be - js files have higher priority (if this was the case, config wouldn't even find
.tsfiles, as I do compile them into.js) OR only configtsfiles are affected, the other part of the project should continue to work as it is designed.Regards,
benedyktdryl commentedon Dec 24, 2017
@PavelPolyakov I'm author of TS changes. I understand your problem. Turned out that running
ts-nodewasn't ideal idea. It should be done:preset/typescriptFor now I would advice you to just skip TS file and run config on transformed versions. I'm working on own config library, modern & more composable in which I'll probably use Babel 7 approach to parse TS files. Can ping you when ready (probably until end of this year) as I don't consider further contributions to
node-configbecause it has some technical debt.markstos commentedon Dec 26, 2017
@benedyktdryl I'll be interested to see what you come up with, also the specifics of what you see as the technical debt there. We have the option to make breaking changes and release a new major version when that seems best, and contributors are welcome to help address open issues.
benedyktdryl commentedon Dec 26, 2017
@markstos I'll come back with technical preview soon.
benedyktdryl commentedon Dec 27, 2017
Ok, let me point strongly at first that I appreciate your work on this stuff and I remember it helped me a lot in several projects. For now, however, I think it's time to move on and I don't think it will be possible with current codebase. I will also point out to my repository with very first version of my concept of config but it's not an ad as it's for now not even tested or published on NPM.
I don't want to argue with anyone, I'll try to put arguments next to my opinions about technical debt:
codebase is not extensible
main file have 1772 lines of code, I like that it's commented strongly but I do think that putting core into separate files should be first thing to do to keep this config library maintainers friendly
ES5 and CommonJS modules usage
node-configis not using ES2015 module system, it's not using modern language constructions. It's still ES5, despite minimal version of node is marked as v4, which means it should handle most of ES6 expressions by default. Still we can distribute cutting edge version with ES6 and TC39 4th stage features. It should also make it more friendly for maintainers. Lot of beginners is learning ES6 so we can encourage them to maintainnode-configby such changes.Strip comments are buggy
https://github.com/lorenwest/node-config/blob/master/lib/config.js#L1532 - we shouldn't strip comments without AST, it's just risky as simple regex used there is buggy in some case
Utils
Currently utils are containing methods which are already implemented by ie.
lodash. Why not to use methods from widely used and tested library which became JS STD library instead of creating own versions of them?Polluting returned values prototype unnecessary
I don't agree that adding some utils to prototype of returned config value is good idea. From 2015,
node-configstill don't havegetRawmethod equivalent to retrieve plain JS configuration objectNot allowing async configuration
Imagine that we want to handle AWS config or use same
node-configmodule to retrieve some configuration from files, some from env variables and some from Redis. Native async support is needed.How my config is different:
I made initial architecture decisions so they are either fixing or allowing to fix some issues which I mentioned or issues which are actually waiting for contribution or that are simply not solvable for now.
core/handlers/providers:
@configis utilising concept of:Thanks to such splitting, we are separating strategy of preserving values for config from parsing them. Lot of different providers can use same handler. This means that we don't need to change core for some customisation requests, we can simply write new provider. In example, I want to implement provider which is providing values with same strategy as this module (full description HERE):
https://github.com/fedor/node-no-config
Also if you want to handle big files, nothing stop you from making stream based handler.
monorepo approach:
@configis library split into several packages which are managed by Lerna. Thanks to this, we have separated modules with own dependencies and also separation of concerns is more enforced.TS based
Library is written in TypeScript to make easier tasks like tracking dependencies and generating documentation. Interface of handlers/providers is clean and described by TypeScript which will detect most of issues during compilation
Async by default
Configuration initialisation is async by default code is using async/await which is converted to generators under hood. Handlers are asynchronous so parsing is completely non-blocking. Providers are also asynchronous so we can create Redis provider which will use async connection.
Link to library:
https://github.com/benedyktdryl/config
Preset which mimic
node-configI created preset which is my kind of tests for now (as I don't have any tests) and it's trying to have same features as
node-config(not all for now obviously).https://github.com/benedyktdryl/config/tree/master/packages/preset-node-config
Check THIS file to run it.
@PavelPolyakov Regarding TS, I wrote handler which is using Babel 7.x beta with
preset/typescriptto parse TS files. No type checking for now but I'm considering some type checking using THIS. If you want to usenode-config, my proposition is to implement TS handling as I described above.lorenwest commentedon Dec 27, 2017
Of course you're right about all of this. If anyone reading this thread is interested in this functionality, I suggest heading over there and giving it a try.
Had this project started in 2017 it would likely have taken this shape. That it started in 2010 and is relied on by so many projects means it will move in this direction more methodically.