-
Notifications
You must be signed in to change notification settings - Fork 486
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
fix: remove 'src' dir from being packaged with npm #5687
Conversation
hmm, I think this is actually gonna be blocked by https://liferay.atlassian.net/browse/LPS-188001 I made a pre-release and tried to use with portal and ran into issues when building because the d.ts files generated contain a reference to src, something like |
nvm, the reason src was being referenced is because the tsconfig at the root of the repo is telling TS to always reference the src under it's paths when finding @clayui/ |
published a test version @3.105.1-alpha.9. See example publish |
Oh thanks for that @bryceosterhaus, I'll take a look at the use cases where the reference still contains. |
tsconfig.json
Outdated
@@ -21,7 +21,6 @@ | |||
"strictNullChecks": true, | |||
"target": "es2015", | |||
"paths": { | |||
"@clayui/*": ["node_modules/@clayui/*/src"], |
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 think the problem with this is that we need the storybook to work correctly and also the inference in the IDE for development. I think we can define a new "paths" just for the declaration configuration file so this only changes in the types' build output, what do you think?
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.
Yeah that was a concern of mine as well. I figured I would let you investigate it further though since you might have a bit more context.
My main goal was making sure that the published ./lib
folder contained no references or dependencies to ./src
. Because right now in clay's published packages, it references src which I don't think was originally intended. See line 79 of this file.
Making this change fixed that, but I think we could make this change just in the definitions tsconfig
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 see @bryceosterhaus, I'll delve deeper into this thanks for the work on this.
@matuzalemsteles I worked on it a bit more, I think this seems to work as expected. Also worked for storybook and the ability to update types across packages without having to re-build every time |
I did a new pre-release(3.106.0-alpha.0) as well and it looks to work in DXP, |
How strange now that build is adding the package types to each package that depends on it instead of importing by package and not copying the types to each package. I'm investigating this further. |
@matuzalemsteles let me know if you make any progress on your concerns. I think what I have here should work for our use case and I don't see any issues with the new configs. Our release of DXP with react 18 is dependent on these changes in clay, because otherwise it causes a types issue. Happy to work on this more if there is an area of concern for you. |
My concern is that by having types, for example buttons, in different packages, TypeScript may report errors due to having different types for each dependency in different packages. |
@matuzalemsteles I'm not really sure I understand your concern there. Each package should now produce For example, looking at my prerelease:
When So I believe all the types should be synced to whatever package is installed in the node_modules. So if for some reason, you use a new version of |
@bryceosterhaus I see but for some reason when I get this PR, clean it and build it again this is how the types are generated instead of being imported. That's what I was trying to say, maybe it's the change of "paths". |
@bryceosterhaus I did some more tests and it seems that this is indeed the problem because we added "paths" to I think we can solve this just by leaving "paths": {
- "@clayui/*": ["packages/clay-*/src"]
} |
I updated the path to be identical to the base path. Since we have configs structured in a flow like this:
We really just needed to omit the "paths" in the "declarations" config, so by overriding paths in declarations and then re-setting it in global, we get our intended result. |
@bryceosterhaus I was investigating this further today and it seems that it is still consuming the packages in the wrong way. I don't know why this is happening, this happens in the case of VerticalNav.
|
@matuzalemsteles good catch again. I think the reason for this was because then you use "extend" in TS, the path references are generated from the directory that the config is in. So when generating types, the config used was using a baseDir of With my changes, we now get |
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.
LGTM! Thanks @bryceosterhaus
Right now we bundle all src files with our npm packages when we publish. This isn't necessary and also can cause issues with TS projects that use Clay because TS will resolve to the
src
file before it resolves to thelib
's.js
+.d.ts
files, which should be the primary entry point into the packages.This should also help speed up build times in DXP and additionally reduce the amount of files we publish.