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

feat: Support Export all for component parsing in svelte entrypoint #85

Merged
merged 2 commits into from
May 18, 2022

Conversation

ethan-jones-vizio
Copy link
Contributor

@ethan-jones-vizio ethan-jones-vizio commented May 5, 2022

In current main, if your entrypoint looks something like:

export { default as MyComponent } from './MyComponent.svelte';
export { default as AnotherComponent } from './AnotherComponent.svelte';

export * from './more-components';
export * from './other-components';

more-components/index.js

export { default as UtilComponent } from './UtilComponent.svelte';

other-components/index.js

export { default as AwesomeComponent } from './AwesomeComponent.svelte';

export * from './another-nested-components-dir';

another-nested-components-dir/index.js

export { default as CoolComponent } from './CoolComponent.svelte';

Will only generate types for MyComponent and AnotherComponent, but with this PR it parses the export * statements and will generate typings for all components

Temporary NPM package: @ethan-jones-vizio/sveld 0.15.2-pr

@metonym metonym self-requested a review May 15, 2022 13:47
Copy link
Collaborator

@metonym metonym left a comment

Choose a reason for hiding this comment

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

Great idea – I can definitely see the use case for sub component folders and the need to use the wildcard export.

When integration testing this, I had the following folder structure:

src/components/Card.svelte
src/index.js

and the following index.js:

export * from "./components";

I ran into an error saying that "./src/Card.svelte" did not exist. I believe this is because the value.source in exports_by_identifier is still "./src/Card.svelte" and does not include the folder value.

The solution would be to modify the source to include that folder path:

+ import { normalizeSeparators } from "./path";

for (const [key, value] of Object.entries(exports)) {
+ const source = normalizeSeparators("./" + path.join(node.source.value, value.source));

- exports_by_identifier[key] = value;
+ exports_by_identifier[key] = {
+  ...value,
+  source,
+ };
}

By doing this, I was able to build the library successfully.

The resulting types/index.d.ts looked like:

export { default as Card } from "./components/Card.svelte";

@ethan-jones-vizio
Copy link
Contributor Author

Thank you!

@metonym metonym merged commit d502bdb into carbon-design-system:main May 18, 2022
@metonym
Copy link
Collaborator

metonym commented May 20, 2022

Released in v0.16.0

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.

None yet

2 participants