-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
feat(cli): allow the use of TS path mapping #554
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also please adjust tests so we stay on 100% branch coverage (should be quite easy via unit test as you are modifying public method).
@@ -32,6 +32,14 @@ export class ConfigurationLoader { | |||
return {}; | |||
} | |||
|
|||
static async getTsConfig(): Promise<Dictionary> { | |||
if (await pathExists(process.cwd() + '/tsconfig.json')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use the path from the package.json
settings (the one from getSettings
method, tsConfigPath
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.. Then I think I've found a bug (Assuming the default settings should be applied everywhere). In CLIHelper.ts
the configure
function directly calls the ConfigurationLoader::getSettings
method. But the defaults are set in the constructor of Configuration
.
CLIHelper::configure
is also used by the cli.ts
itself. Shouldn't the defaults supposed to be applied there too?
If not then then it's fine. But then I need to apply the default myself.
Another thing is, that if I want to only require
the Settings once then I'd have to require the tsconfig there. But it would look nicer in its own method, and anyway, eslint doesn't allow me to require into variables. But I've seen that await ConfigurationLoader.getSettings()
is used a few times anyway. I suggest memoizing this function, then it would be 100% correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really a bug, you are mixing two things, package.json settings (CLIHelper.getSettings()
) and ORM configuration (Configuration
class). They are for different things. I don't want to adjust the ORM config anyhow - overriding stuff based on something from package.json seems just wrong. The whole point of this package.json settings is to allow to configure CLI correctly - so to let user say where the right config is and whether we want to run via ts-node or not. And to do so, one can specify where the tsconfig.json file is.
All I was asking for is to use the settings.getTsConfig
as a path for the require, so as a parameter to this function. Usign the default from Configuration
seems wrong, although thee default is same, the class has nothing to do with CLI itself.
@@ -32,6 +32,16 @@ export class ConfigurationLoader { | |||
return {}; | |||
} | |||
|
|||
static async getTsConfig(): Promise<Dictionary> { | |||
const settings = await ConfigurationLoader.getSettings(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as said, this should not be here and it should not depend on Configuration
what you had there before was ok, i just wanted you to prefer the path from settings.tsConfigPath
if provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the problem with using the default value defined there as a fallback? The same one was there, I just didn't want to duplicate it after I saw it defined there already. Or this whole function shouldn't be there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole function shouldn't be here, if you need it, move it back to CLIHelper, but without that extra call to getSettings. I said you should pass that value via parameter, not call it again.
Again, what you had there in the first commit was ok, I just wanted to have 1 line change (using the path from already loaded settings object), instead you rewrote it and made it much more complex :]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do noticed that it doesn't really make sense to have a method like that at all. And it would make much more sense to just have this included at the config, and I did just that. But I need help because I can't make the test work. tsconfig.json
should be mocked in there, but it only works if it's required two directory levels more inside, in ConfigurationLoader.ts
, but if I put it in the configure
method it does not call the mock.
Also, the require is in an IIFE because eslint doesn't let me require into var. And I don't want to ignore or turn off rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add eslint ignore comment there, the rule is irrelevant here, by using IIFE (its IIFE, not IFEE :]) you are just getting around it, without fixing the root cause (you are still using require()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that was a typo. Before top level async was introduced I've used it a lot.
That's why I asked you what would you prefer, ignore it explicitly or placing it in a function.
@@ -32,6 +32,16 @@ export class ConfigurationLoader { | |||
return {}; | |||
} | |||
|
|||
static async getTsConfig(): Promise<Dictionary> { | |||
const settings = await ConfigurationLoader.getSettings(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole function shouldn't be here, if you need it, move it back to CLIHelper, but without that extra call to getSettings. I said you should pass that value via parameter, not call it again.
Again, what you had there in the first commit was ok, I just wanted to have 1 line change (using the path from already loaded settings object), instead you rewrote it and made it much more complex :]
I am sorry but I already spend more time giving you reviews than I would spend with implementing this myself. If you are stuck, I can finish this myself, no probs. Generally thanks for this, I was planning to do it myself for few months already :] |
I don't have enough experience with Jest to fix the test, so yes it would be nice to have some help.
This is a little discouraging. I'd like to use this library but there is a lot to implement and I don't want to demand every little change like this, but to contribute myself. |
Please understand that I am spending my own free time with this project. And I already spend 2+ hours with this small change, that I would have done in less then hour. I am spending dozens of hours every week like this. So I simply said that I will rather finish this myself than spend another 2+ hours on reviews, because my time is very limited and I have many things to work on. I am more than happy to see more contributions, but:
So I am sorry if you feel discouraged, but please try to understand my point of view as well. |
This last push is not "testing against the CI" I can run the tests myself. I just incorporated the last requested change you mentioned what I can solve. If you have the time to look at the mock issue I had please take a look at it. |
Ok so this was quite tricky, the problem was that Once again sorry if I offended or discourage you, and thanks for your contribution. |
This enables the use of path aliases in your entities and ORM configuration file. Example `tsconfig.json`: ```json { "compilerOptions": { "paths": { "@foo": ["src/foo/index.ts"] } }, } ```
This enables the use of path aliases in your entities and ORM configuration file. Example `tsconfig.json`: ```json { "compilerOptions": { "paths": { "@foo": ["src/foo/index.ts"] } }, } ```
This enables the use of path aliases in your entities and ORM configuration file. Example `tsconfig.json`: ```json { "compilerOptions": { "paths": { "@foo": ["src/foo/index.ts"] } }, } ```
This enables the use of path aliases in your entities and ORM configuration file. Example `tsconfig.json`: ```json { "compilerOptions": { "paths": { "@foo": ["src/foo/index.ts"] } }, } ```
This enables the use of path aliases in your entities and ORM configuration file. Example `tsconfig.json`: ```json { "compilerOptions": { "paths": { "@foo": ["src/foo/index.ts"] } }, } ```
This enables the use of path aliases in your entities and ORM configuration file. Example `tsconfig.json`: ```json { "compilerOptions": { "paths": { "@foo": ["src/foo/index.ts"] } }, } ```
This enables the use of path aliases in the config file.
Example
tsconfig.json
Example
mikro-orm.config.ts