Skip to content
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

Import paths for generated type definitions broken #270

Closed
4 tasks done
donmahallem opened this issue Aug 16, 2021 · 8 comments · Fixed by #271
Closed
4 tasks done

Import paths for generated type definitions broken #270

donmahallem opened this issue Aug 16, 2021 · 8 comments · Fixed by #271
Labels
☂️ area/types This affects typings 💪 phase/solved Post is done 🐢 platform/node This affects Node 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem

Comments

@donmahallem
Copy link

donmahallem commented Aug 16, 2021

Initial checklist

Affected packages and versions

remark-lint-list-item-indent and many more

Link to runnable example

No response

Steps to reproduce

Clone repository and run npm run build after bootstraping the repository

Expected behavior

It should generate type defintions like so that type acquisition isn't broken if the dependency is somewhere else.

export default remarkLintListItemIndent;
export type Root = import('mdast').Root;
export type Options = 'tab-size' | 'space' | 'mixed';
declare const remarkLintListItemIndent: import("unified").Plugin<void[] | [Options | import("unified-lint-rule").Label | import("unified-lint-rule").Severity | undefined] | [boolean | import("unified-lint-rule").Label | import("unified-lint-rule").Severity, Options | undefined], import("mdast").Root, import("mdast").Root>;

Actual behavior

But it generates which brakes if the unified package isn't a subpackage of unified-lint-rule for example on the same "level"

export default remarkLintListItemIndent;
export type Root = import('mdast').Root;
export type Options = 'tab-size' | 'space' | 'mixed';
declare const remarkLintListItemIndent: import("unified-lint-rule/node_modules/unified").Plugin<void[] | [Options | import("unified-lint-rule").Label | import("unified-lint-rule").Severity | undefined] | [boolean | import("unified-lint-rule").Label | import("unified-lint-rule").Severity, Options | undefined], import("mdast").Root, import("mdast").Root>;

Additonally it results in many duplicate installs unified etc.

Runtime

Node v16

Package manager

npm v7

OS

Windows

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 16, 2021
@donmahallem
Copy link
Author

One solution would be to run npx lerna bootstrap --hoist from my testing to remove these nested imports.

@ChristianMurphy
Copy link
Member

path issue can be seen with unpkg https://unpkg.com/browse/remark-lint-list-item-indent@3.0.0/index.d.ts

The way it links the path, make me wonder if there are/were multiple conflicting versions of unified included by package.json at the time. 🤔
Updating plugins may resolve this issue.

I'm not sure if --hoist is the best way to resolve this, if there is a version conflict, it could exacerbate the situation.

@ChristianMurphy ChristianMurphy added ☂️ area/types This affects typings 👍 phase/yes Post is accepted and can be worked on 🙆 yes/confirmed This is confirmed and ready to be worked on and removed 🤞 phase/open Post is being triaged manually labels Aug 16, 2021
@github-actions

This comment has been minimized.

@ChristianMurphy ChristianMurphy added 🐢 platform/node This affects Node 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem labels Aug 16, 2021
@donmahallem
Copy link
Author

I expected missmatching unified versions BUT it isn't only unified but several remark-lint packages referencing another remark-lint package too. I did clone this repository fresh and it resulted in the same build d.ts files so I suspect no conflicting versions.

--hoist is a hack too imho and should be avoided but it should be indicate that conflicting versions shouldn't be the issue.

wooorm added a commit that referenced this issue Aug 17, 2021
@wooorm
Copy link
Member

wooorm commented Aug 17, 2021

The presets went weird becasue they were essentially untyped, hence trying to load tons of external types. I fixed that (see reference above this comment), e.g., they now look like this:

export default remarkPresetLintRecommended;
export type Preset = import('unified').Preset;
/** @type {Preset} */
declare const remarkPresetLintRecommended: Preset;

For rules, they don’t depend on each other. So that should leave the problem to unified-lint-rules unified being used instead of the local unifieds

@donmahallem
Copy link
Author

donmahallem commented Aug 17, 2021

Currently away from my PC but I remember imports like

../[rule]/node_modules/[other dependency]

Maybe this is fixed with this commit too. I will check this later.

wooorm added a commit that referenced this issue Aug 17, 2021
@wooorm wooorm mentioned this issue Aug 17, 2021
5 tasks
wooorm added a commit that referenced this issue Aug 17, 2021
Closes GH-270.
Closes GH-271.

Reviewed-by: Merlijn Vos <merlijn@soverin.net>
Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Aug 17, 2021
@github-actions github-actions bot removed 👍 phase/yes Post is accepted and can be worked on 🙆 yes/confirmed This is confirmed and ready to be worked on labels Aug 17, 2021
@wooorm
Copy link
Member

wooorm commented Aug 17, 2021

Released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 💪 phase/solved Post is done 🐢 platform/node This affects Node 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem
Development

Successfully merging a pull request may close this issue.

3 participants