-
Notifications
You must be signed in to change notification settings - Fork 24
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
Skott does not read typescript path aliases if entrypoint is not a TS file #84
Comments
Hello @ACHP, thanks for opening that very well detailed issue! It's actually an interesting use case, but I'm curious to know why would a JavaScript file be the entrypoint of a TypeScript project in the first place? Using the Maybe an even more straightforward solution would be to try to build path aliases all the time as skott might support #78 Node.js path aliases (https://nodejs.org/api/packages.html#subpath-imports) as well. I'm not really a fan of doing this type of thing but actually with all the mixes that can happen in a JS/TS project with |
Because we can … 😆 More seriously, I don't think that this is something a user would like to do on purpose, but it can happen with
I don't think this will happens really often, but when it will, user will have to debug
Yes, you're right. I tried to implement a fix yesterday after opening the issue, and as you mention
I think there are 2 distinct issue here:
I think we first need to correctly load config that skott support ( for now Typescript only ), then, think of a strategy to "merge" or select one aliases config over another. Something like private async buildFromEntrypoint(entrypoint: string): Promise<void> {
if (isTypeScriptProject()) {
this.#workspaceConfiguration.typescript = await buildTSConfig(/*...*/);
}
// later
if (isBabelProject()) {
this.#workspaceConfiguration.babel = await buildBabelConfig(/*...*/);
}
// later
if (hasJSConfig()) {
this.#workspaceConfiguration.jsonConfig = await buildJSConfig(/*...*/);
}
this.#workspaceConfiguration.pathAliases = readPathAliasesFrom([this.#workspaceConfiguration.typescript, this.#workspaceConfiguration.babel, this.#workspaceConfiguration.jsonConfig]);
/*...*/
} This is, IMO, one possible way to do this, if you plan to add multiple pathAliases resolution strategy. For now if you keep typescript only you can just keep your actual code and replace
function isTypeScriptProject(){
// naïve "generic" approach
return fs.existsSync(config.tsConfig);
}
private async buildFromEntrypoint(entrypoint: string): Promise<void> {
if (isTypeScriptProject()) {
this.#workspaceConfiguration.typescript = await buildTSConfig(/*...*/);
}
/*...*/
} |
Yeah you can do many things, even executing SQL inside CSS, that ecosystem is burning my brain sometimes 😆 By the way I was not judging in any kind of way there, just curiously wondering what was the setup because I tried to anticipate as much scenarios as possible but this missed this one. Anyway I think this type of use case and even the possibility of turning on
Yeah absolutely! We'll definitely need at some point to have this type of strategy to resolve path alias configurations from different sources (tsconfig.json, package.json, vite.config.js...).
Yes you're right, that's pretty much what I had in mind feature-wise :) Regarding the implementation what I was saying Also, we must be careful semantically because it's hard to settle whether a given project is TypeScript or not based only on
For the future dealing with multiple strategies, we might just need to remove |
Totally agree with all of this :)
|
Yeah you're right both fit well for now, so let's go on the solution you suggested, I think it's pretty good for the first iteration! Would be willing to land a PR and contributing on this subject and/or the other issue you opened #83? It's totally up to you, on my side I'm already grateful for the discussion and the opening of the issues, so I could do it myself as well but mainly working on #72 so it could take a bit longer for me to land it :) |
Yes, I'll do that ;) |
Glad to hear that, sounds good to me! You can go full TypeScript if you're more comfortable with it, I'm mainly using Effect for dependency injection on skott for now so nothing really fancy. If you ever want to know more though, I authored an introduction about it https://github.com/antoine-coulon/effect-introduction :) |
…ath) by doesTsConfigExist
…ath) by doesTsConfigExist
…89) * fix: (#84) replace isTypeScriptModule(entrypointModulePath) by doesTsConfigExist * fix: use fileReader.getCurrentWorkingDir() inside isTypeScriptProject * fix; use fileReader exist instead of stats * update changeset --------- Co-authored-by: Antoine Coulon <43391199+antoine-coulon@users.noreply.github.com>
@ACHP nice, glad to see that you made it work! Now I need to speed up the revamp #72 because that visualization is getting ugly and messy for big graphs... To improve the graph visualization I would suggest you to filter a little bit the parts of your project so that you reduce the number of nodes displayed (either via |
Context
I tried s skott on a React-Native project where almost all files are using Typescript except for the entry file.
And I noticed that all my path aliases were considered as "third party module". Even with the
--tsconfig="./tsconfig.json"
argument.How to reproduce
.js
file extensionThat's because if the entry point is not a TS file, the TS configuration is not loaded
See here:
https://github.com/antoine-coulon/skott/blame/d18c1f800276752431d0177597d1fa4f86db5938/packages/skott/src/skott.ts#L494-L502
Suggestion
If the user use
tsconfig
as argument for the cli, skott should consider that the project is using typescriptThe text was updated successfully, but these errors were encountered: