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): exclude co-located stories by default from build #666

Closed
wants to merge 1 commit into from
Closed

(feat): exclude co-located stories by default from build #666

wants to merge 1 commit into from

Conversation

kylemh
Copy link
Contributor

@kylemh kylemh commented Apr 7, 2020

A brute attempt to resolve the issue I'm encountering in #663

Resolves #663

@@ -154,6 +154,8 @@ export async function createRollupConfig(
'**/*.test.ts',
'**/*.spec.tsx',
'**/*.test.tsx',
// storybook files
'**/*.stories.tsx',
Copy link
Contributor Author

@kylemh kylemh Apr 7, 2020

Choose a reason for hiding this comment

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

I wonder if we need to do

...(!!opts.tsconfig.exclude ? [opts.tsconfig.exclude] : [])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested the logic in rpts2:
Screen Shot 2020-04-07 at 1 53 08 AM

I don't see an issue... it should work fine.

Although strangely enough a different merge loses some options which I'm surprised get lost...
Screen Shot 2020-04-07 at 1 56 39 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There exists a few lines after L44 in that rpts2 file I linked which I believe also do some merging.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not because of rpts2 -- that's how _.merge works with arrays. exclude is an array, so your custom exclude would just override the same indices.
In your first "test", **/*.stories.tsx also overrides the first entry, **/*.spec.ts

I think this jogged my brain a bit -- I'm pretty sure that line in rpts2 is around where the bug is.
TSDX has similar logic as rpts2 using TS's custom parsers to read a tsconfig and then get its compilerOptions through all extends chains. But that's only for compilerOptions, meaning exclude etc from an extends aren't actually parsed.

Problem there is that I don't know if there's a way to get the rest. This part of the TS API isn't documented but is used in lots of places in the wild for parsing, it took me a while to figure out how to do it myself, c.f. #489

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, the original config gets mutated with the new include/exclude, while compilerOptions is unchanged and returned per facebook/create-react-app#5537

I'll have to look into rpts2 config and see if there's actually a bug or not, I'm not sure. I still haven't repro'd #663

Copy link
Collaborator

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

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

I still need to repro the bug, investigate, and then possibly investigate upstream, but I was thinking this feature is good to have in any case for simplifying config for those who have co-located stories. But this entire default exclude wouldn't be needed if we could use file: ['src/index.ts'] instead, but that's blocked on ezolenko/rollup-plugin-typescript2#211.

In any case, this would need tests if it were to be merged. Would have to add an empty story file to the build-default fixture (similar to the empty test/ files that just have comments in them) and then check that it's not output to dist/ after build

@agilgur5 agilgur5 added the kind: feature New feature or request label Apr 7, 2020
@agilgur5 agilgur5 changed the title Exclude Storybook files in default config (feat): exclude co-located stories by default from build Apr 7, 2020
@kylemh
Copy link
Contributor Author

kylemh commented Apr 7, 2020

Sounds like I should just wait for ezolenko/rollup-plugin-typescript2#211

Thanks for diving deep! Love having you on this project. ❤️

@kylemh kylemh closed this Apr 7, 2020
@kylemh kylemh deleted the patch-1 branch April 7, 2020 17:41
@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 7, 2020

Sounds like I should just wait for ezolenko/rollup-plugin-typescript2#211

I don't think that'll be fixed any time soon, especially not if it requires parsing declarations.

Hence why I'd be fine with this going in, as, for the time-being we have to use include instead of file (even if we changed to the latter, we'd still have older users of the former).

@kylemh
Copy link
Contributor Author

kylemh commented Apr 7, 2020

I see. My guess is a relevant test would be considered e2e? I can do a default build with a Storybook file. Make a uniquely named type, and assert that none of the file contents in dist include the type name?

@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 7, 2020

Yea you'd like create e2e/fixtures/build-default/src/story-test.stories.tsx that's empty other than a comment (see the build-default/test/ for what that would look like) and then use the same style tests as in the e2e/tsdx-build-default.test.ts except you'd have a toBeFalsy() for this file instead of toBeTruthy()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request solution: unresolved Issue has been closed by OP but root cause has not necessarily been resolved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tsconfig exclude from an extends not working
2 participants