Skip to content

#15 added basic tsconfig extends support #16

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bennobuilder
Copy link

@bennobuilder bennobuilder commented Jul 14, 2023

see #15

Note: Sry for the wrong formatting.. maybe add normal eslint & prettier config with .prettierrc and .eslintrc :)

@simonhaenisch
Copy link
Owner

There's a normal prettier config in the package.json which is officially supported by Prettier 🤓 (first option in the list here)

I don't think I added linting to this project 😅

index.ts Outdated
},
};
const { compilerOptions } = getTsConfig(tsConfigPath);
const outDir = compilerOptions.outDir ?? '.';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pointed out here already: #14 (comment)

Copy link
Author

@bennobuilder bennobuilder Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right in my case, outDir was always the default (".") since I've defined it in my compilerOptions -> never was read in.

Since the resolvedFileName is already an absolute path, joining (with path.join()) it with the default outDir (".") resulted in the correct absolute path, as resolvedFileName seems already correct?

Example resolvedFileName: "C:/path/to/my/monorepo/packages/dtif-to-svg/src/d3.ts"

However, now that it reads in the outDir correctly due to your suggested getParsedCommandLineOfConfigFile() method that works like a charm, the outDir is something like "C:/path/to/my/monorepo/packages/dtif-to-svg/dist" which I defined in the compilerOptions of my tsconfig.json. However, now path.join() will join these both absolute paths that result in: "C:/path/to/my/monorepo/packages\dtif-to-svg\dist\C:/path/to/my/monorepo/packages\dtif-to-svg\src\d3.ts". And thats not correct.

-> For me it works best without any defined outDir as resolvedFileName already points to the correct location
-> Do we actually need to define the outDir and when might it be required, because for me it isn't?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same issue comments I think further down there's a solution with using path.relative instead of path.join.

Copy link
Author

@bennobuilder bennobuilder Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I tested that but the resulting relative path was something like ../src/path/to/file and since the script was executed in the root of the package it navigated out of the package and tried to find the src/path/to/file.ts there..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but anyway if the MR doesn't fit the project's philosophy that's ok too :) I've implemented your very useful plugin in my scripts and updated it to my project's needs (represented in this MR).. but I've not tested it in other environments and everyone has different requirements and expectations, which is of course hard to cover in a single project.. cheers :)

image

index.ts Outdated
// Try to resolve as a file relative to the current config
extendedConfigPath = path.join(
path.dirname(rootConfigPath),
config.extends
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends can actually be an array since TS 5.0. I'm pretty sure there's probably a better method from the TypeScript API to retrieve the tsconfig.

I wrote this a long time ago when I was still completely unfamiliar with the API 😅

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stackoverflow.com/a/70013087/2897426 maybe this is the correct solution

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that actually worked quite good :)

@bennobuilder
Copy link
Author

There's a normal prettier config in the package.json which is officially supported by Prettier 🤓 (first option in the list here)

I don't think I added linting to this project 😅

thanks for pointing that out.. did totally miss that 😅 prettier is good enough, just forgot that it can be configured in package.json :)

@@ -63,15 +57,16 @@ export const typescriptPaths = ({
return null;
}

const targetFileName = join(
outDir,
// TODO: Do we need outDir as "resolvedFileName" is already correct absolute path
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think resolvedFileName is only the correct absolute path with Rollup 3 but not Rollup 2 or so.

if (!configJson) {
return defaults;
// Read in tsconfig.json
const parsedCommandLine = ts.getParsedCommandLineOfConfigFile(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a lot slower than what happened before, so probably it makes sense to memoize the getTsConfig function for performance. I can add this (hopefully i'll find some time to properly go through this PR in the next few weeks).

outDir: string;
}
} & Omit<ts.CompilerOptions, 'outDir'>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be like

Suggested change
} & Omit<ts.CompilerOptions, 'outDir'>;
} & { compilerOptions: Omit<ts.CompilerOptions, 'outDir'> };

Anyway, I thought having outDir next to compilerOptions in the tsconfig was wrong in the first place?

@mdorda
Copy link

mdorda commented Dec 12, 2023

Any progress with merging? Still an issue :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants