-
-
Notifications
You must be signed in to change notification settings - Fork 29
fix: improve type support for isolated dependencies in pnpm #289
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
base: main
Are you sure you want to change the base?
Conversation
"extends": "./tsconfig.json", | ||
"files": ["dist/esm/index.js"], | ||
"compilerOptions": { | ||
"allowImportingTsExtensions": true, |
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.
allowImportingTsExtensions
is required for TypeScript to accept import statements from "./types.ts"
in the generated dist/esm/index.js
file:
/** @import * as _typests from "./types.ts"; */
Another possibility to avoid allowImportingTsExtensions
is importing from "./types.js"
instead. This will work if a dummy file dist/esm/types.js
is added to the package, similarly to what is done in eslint/markdown
:
https://app.unpkg.com/@eslint/markdown@7.4.0/files/dist/esm/types.js
Is there a reason we can't do this? /** @import { ConfigObject as Config, LegacyConfigObject as LegacyConfig ) from "@eslint/core" */ |
The problem is that For example, this JSDoc comment: /** @import { ConfigObject as Config, LegacyConfigObject as LegacyConfig, Plugin, RuleConfig } from "@eslint/core"; */ Compiles into: import type { ConfigObject as Config } from "@eslint/core"; In this case, TypeScript even recognizes that |
const newSourceText = oldSourceText.replaceAll( | ||
'import("./types.ts")', | ||
'import("./types.cts")', | ||
' from "./types.ts";\n', |
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 double-checking -- are we sure there are no files that use import()
?
'import("./types.ts")', | ||
'import("./types.cts")', | ||
' from "./types.ts";\n', | ||
' from "./types.cts";\n', |
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 double-checking: Are we sure there aren't any files that are still using import()
?
// we haven't seen this typedef before, so process it | ||
typedefs.add(line); | ||
const { start, importSource, end } = match.groups; | ||
const importName = `_${importSource.replace(/\W/gu, "")}`; |
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'm not a fan of using _
as a signifier for this purpose. In most languages, this indicates that an identifier is not used, which is not the case here. Could we use $
instead?
Prerequisites checklist
What is the purpose of this pull request?
This pull request, together with eslint/eslint#20201 in the main repo, fixes issue #283 by replacing
import()
syntax inside JSDoc@typedef
tags with local module aliases in the bundled.js
output.Before:
After
This has the effect of creating a type import (
import type *
) in the generated .d.ts files:Before:
After
The type import doesn't change the exported types, but it overcomes a limitation of TypeScript when resolving types across symlinked directories. See also microsoft/TypeScript#62558.
The current change only affects packages built using the
dedupe-types
tools:config-array
config-helpers
plugin-kit
Anyway, these are not the only packages impacted by the TypeScript issue.
compat
is widely used and it is also impacted:StackBlitz demo
This could be fixed in a follow-up pull request if necessary.
What changes did you make? (Give an overview)
dedupe-types
andbuild-cts
tools to match the new format.Related Issues
fixes #283
Is there anything you'd like reviewers to focus on?