Skip to content

Fix published package exports #9163

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

Merged
merged 39 commits into from
Aug 22, 2024
Merged

Fix published package exports #9163

merged 39 commits into from
Aug 22, 2024

Conversation

pngwn
Copy link
Member

@pngwn pngwn commented Aug 21, 2024

This PR fixes the package exports for published NPM packages, and processes them appropriately for consumption.

Main changes:

  • we now run (a patched version of ) svelte-package which strips typescript from svelte files and generates typescript declaration files. Now all consumers can user use these packages in their project even if they aren't using typescript but they will still get fully typed components.
  • Updated the exports in each package.json to point to the correct files. I have also added a new gradio condition which points to the source, so we do not need to build the packages when developing in the repo.
  • Added the gradio condition to the resolution rules of the vite configs for lite + spa
  • Updated the utils package so that it no longer needs a special build process, instead the component loader is passed in as an argument to the class.
  • maybe some other stuff

Conditional exports

There is a concept of 'conditional exports' in node/npm/bundler ecosystem. This essentially allows you to have different entrypoints to you package based upon certain conditions. By default the conditions are just things like import and require which are for different module system but you can also use custom ones. We are using two.

Our exports look something like this:

"exports": {
  ".": {
    "gradio": "./Index.svelte",
    "svelte": "./dist/Index.svelte",
    "types": "./dist/Index.svelte.d.ts"
  },
  "./example": {
    "gradio": "./Example.svelte",
    "svelte": "./dist/Example.svelte",
    "types": "./dist/Example.svelte.d.ts"
  },
  "./package.json": "./package.json"
},
  • types is for typescript, this is a standard in the ecosystem.
  • svelte is a special condition that svelte tooling understand, so will work for the svelte ecosystem.
  • gradio is specific to us. I have set resolve.conditions in our vite config so it will resolve to this entrypoint in out build system.

Order matters here because multiple conditions can match, and the first one takes precedence.

This custom gradio condition may seem excessive but it means we can carry on working as normal and custom components are unaffected by these changes, without it we would need to repeatedly rebuild packages which is slow and tedious. I have also added this condition to the js client, so we will no longer need to rebuild the client to see changes reflected in the app.

@pngwn pngwn added v: patch A change that requires a patch release t: fix A change that implements a fix labels Aug 21, 2024
@pngwn pngwn changed the title Fix packages Fix published package exports Aug 21, 2024
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Aug 21, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/12fd18339821e6b47e38b04c26ca05ec23f7c42a/gradio-4.42.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@12fd18339821e6b47e38b04c26ca05ec23f7c42a#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/12fd18339821e6b47e38b04c26ca05ec23f7c42a/gradio-client-1.5.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Aug 21, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/accordion patch
@gradio/annotatedimage patch
@gradio/atoms patch
@gradio/audio patch
@gradio/box patch
@gradio/button patch
@gradio/chatbot patch
@gradio/checkbox patch
@gradio/checkboxgroup patch
@gradio/client patch
@gradio/code patch
@gradio/colorpicker patch
@gradio/column patch
@gradio/core patch
@gradio/dataframe patch
@gradio/dataset patch
@gradio/datetime patch
@gradio/downloadbutton patch
@gradio/dropdown patch
@gradio/fallback patch
@gradio/file patch
@gradio/fileexplorer patch
@gradio/form patch
@gradio/gallery patch
@gradio/group patch
@gradio/highlightedtext patch
@gradio/html patch
@gradio/icons patch
@gradio/image patch
@gradio/imageeditor patch
@gradio/json patch
@gradio/label patch
@gradio/lite patch
@gradio/markdown patch
@gradio/model3d patch
@gradio/multimodaltextbox patch
@gradio/nativeplot patch
@gradio/number patch
@gradio/paramviewer patch
@gradio/plot patch
@gradio/preview patch
@gradio/radio patch
@gradio/row patch
@gradio/simpledropdown patch
@gradio/simpleimage patch
@gradio/simpletextbox patch
@gradio/slider patch
@gradio/state patch
@gradio/statustracker patch
@gradio/tabitem patch
@gradio/tabs patch
@gradio/textbox patch
@gradio/theme patch
@gradio/timer patch
@gradio/tooltip patch
@gradio/upload patch
@gradio/uploadbutton patch
@gradio/utils patch
@gradio/video patch
@gradio/wasm patch
@self/app patch
@self/build patch
@self/component-test patch
@self/spa patch
@self/storybook patch
@self/tootils patch
website patch

With the following changelog entry.

fix exports and generate types

⚠️ The changeset file for this pull request has been modified manually, so the changeset generation bot has been disabled. To go back into automatic mode, delete the changeset file.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

Tested a lot of demos, all look good to me! Thanks @pngwn for taking care of this

Copy link
Member

@whitphx whitphx left a comment

Choose a reason for hiding this comment

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

I looked around Lite and looks like everything worked well.

@whitphx
Copy link
Member

whitphx commented Aug 22, 2024

Just found scripts/*_lite.sh didn't work and suggested #9170.

@hannahblair
Copy link
Collaborator

Do we also want to remove "private": true in gr.FileExplorer?

Copy link
Collaborator

@hannahblair hannahblair left a comment

Choose a reason for hiding this comment

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

!!! nice work !!!

@pngwn pngwn enabled auto-merge (squash) August 22, 2024 16:30
@pngwn pngwn merged commit 2b6cbf2 into main Aug 22, 2024
20 of 21 checks passed
@pngwn pngwn deleted the fix-packages branch August 22, 2024 16:38
This was referenced Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: fix A change that implements a fix v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants