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

Packaging & publishing to npm #202

Closed
wants to merge 23 commits into from
Closed

Packaging & publishing to npm #202

wants to merge 23 commits into from

Conversation

mishig25
Copy link
Contributor

@mishig25 mishig25 commented Jul 16, 2021

Update: 2021-09-09

@Pierrci @beurkinger
Since internal was merged, I've advanced this PR.
To remind:

  1. This PR published widgets as a npm package https://www.npmjs.com/package/huggingface-widgets
  2. Removed the $lib usage since Resolve aliases while running svelte-kit package sveltejs/kit#1950 is still open. (You mentioned about it here)
  3. Files that are being export are:
".": "./InferenceWidget/InferenceWidget.svelte",
"./WidgetHeader.svelte": "./InferenceWidget/shared/WidgetHeader/WidgetHeader.svelte",
"./ModelPipelineIcon.svelte": "./ModelPipelineIcon/ModelPipelineIcon.svelte",
"./ModelPipelineTag.svelte": "./ModelPipelineTag/ModelPipelineTag.svelte",
"./inferenceSnippets": "./inferenceSnippets/index.js",
"./inferenceSnippets/inputs": "./inferenceSnippets/inputs.js",
"./interfaces/DefaultWidget": "./interfaces/DefaultWidget.js",
"./interfaces/Language": "./interfaces/Language.js",
"./interfaces/Libraries": "./interfaces/Libraries.js",
"./interfaces/Types": "./interfaces/Types.js"

And it gets consumed as:

import InferenceWidget from "huggingface-widgets";
import ModelPipelineTag from "huggingface-widgets/ModelPipelineTag.svelte";
import { Language } from "huggingface-widgets/interfaces/Language";
import type { PipelineType } from "huggingface-widgets/interfaces/Types";
...

  1. Checkout its companion PR internally here

@mishig25 mishig25 requested review from julien-c, Pierrci and beurkinger and removed request for julien-c, Pierrci and beurkinger July 16, 2021 10:55
@mishig25 mishig25 closed this Jul 16, 2021
@Pierrci
Copy link
Member

Pierrci commented Jul 16, 2021

Did you close this accidentally @mishig25 or was it intended?

@mishig25
Copy link
Contributor Author

@Pierrci Yeah it was intended. I think changes I've made to tsconfig is causing svelte-check to fail

@mishig25
Copy link
Contributor Author

mishig25 commented Jul 16, 2021

@Pierrci Please let me know if you think this approach is acceptable.

Why we can't use a package generated by svelte-kit package?

svelte-kit package expects the consumer (in this case, moon-landing) to be using svelte-kit, which directly consumes third party component sources (rather than bundled files).
However, on moon-landing, we don't use svelte-kit. There are 2 ways a component gets compiled on moon-landing: build-svelte.mjs on server and rollup on front (rollup can consume svelte component sources directly, so we can use svelte-kit package for the front (not server) see here).

As a intermediary solution

I've copied moon-landing/server/build-svelte.mjs into hub/widgets/build.js. In hub/widgets/package folder:

  1. a component source code is copied here from hub/widgets/package(withsvelte-kit packageformoon-landing/front`)
  2. a component gets compiled here with hub/widgets/build.js (for moon-landing/server)

And npm package is published.

I think this approach is quite "hacky". As we add more svelte components, we should definitely switch to what @beurkinger suggested.

@julien-c
Copy link
Member

nit, but the npm package name (if we go that way) would be better named huggingface-widgets for consistency w/ other library etc. naming

@Pierrci
Copy link
Member

Pierrci commented Jul 22, 2021

I finally had a look at it, and IMO it looks very promising @mishig25 :)

I think changes I've made to tsconfig is causing svelte-check to fail

I bumped the version of svelte-check to the last one locally (2.2.3) and it seems to be working fine, it was probably linked to some bug :)

I think this approach is quite "hacky". As we add more svelte components, we should definitely switch to what @beurkinger suggested.

I agree the approach can be considered as "hacky", but I'm not sure why adding more components would make it worse than it is now?

More generally, I think we could refactor a bit the js structure in this repo w/ a more generic js (or similar) top-level directory instead of widgets, move interfaces in lib and publish a more generic huggingface(-hub?) package exposing both the widgets through InferenceWidget and what would be in lib/interfaces. (+ ModelPipelineIcon and ModelPipelineTag since we also use them in moon-landing). wdyt @julien-c?

This way we can import all the js code we need from huggingface_hub in a unified way (and not using the npm package in some places and weird paths pointing to the submodule in others).

@mishig25 mishig25 reopened this Jul 22, 2021
@mishig25
Copy link
Contributor Author

mishig25 commented Jul 23, 2021

I made an ambiguous statement above. I meant: we should switch to rollup if/when we add third-party svelte component libraries.

but I'm not sure why adding more components would make it worse than it is now?

@julien-c
Copy link
Member

More generally, I think we could refactor a bit the js structure in this repo w/ a more generic js (or similar) top-level directory instead of widgets, move interfaces in lib and publish a more generic huggingface(-hub?) package exposing both the widgets through InferenceWidget and what would be in lib/interfaces. (+ ModelPipelineIcon and ModelPipelineTag since we also use them in moon-landing). wdyt @julien-c?

No strong opinion (I think git-submodules are fine for non-Svelte files), I'll leave that up to you guys.

@Pierrci
Copy link
Member

Pierrci commented Jul 23, 2021

No strong opinion (I think git-submodules are fine for non-Svelte files), I'll leave that up to you guys.

Yes, we can leave the hub doc outside of the package 😄. But moving interfaces would also simplify both their use inside the widgets and the package's build (@mishig25 had to add a specific build step because of their current path). What do you think of the idea @mishig25?

@LysandreJik, what do you think would be the best way to regroup all the js code (widgets + interfaces - if we go this way) without interfering too much with all the pythonic stuff? something inside src? next to it?

@julien-c
Copy link
Member

julien-c commented Jul 24, 2021

What about keeping interfaces/ and nesting inside interfaces/widgets/?

@LysandreJik
Copy link
Member

I'd rather we don't move it inside src as that's the current location of the python source code and is what we use in the setup.py to create the wheels.

Moving widgets under interfaces/widgets is ok for me. Moving both folders under an unambiguous folder frontend or hub is also good for me if you'd like to keep the same structure.

@mishig25
Copy link
Contributor Author

mishig25 commented Jul 24, 2021

Moving both folders under an unambiguous folder frontend

sounds great to me.

In that case, @Pierrci, could we just add huggingface_hub/frontend dir to tsconfig files & build-svelte.mjs script and not use rollup at the moment? And use tsconfig#paths so that we don't use really long import statements like import huggingface_hub/frontend/widgets/src/lib/InferenceWidget?

@julien-c
Copy link
Member

I'll reiterate that I'd prefer to nest widgets under interfaces/ given that we already have a interfaces/ directory (and its contents does not need to be moved unless I'm mistaken)

@mishig25
Copy link
Contributor Author

got it 👍
then, I'll move widgets inside interfaces as interfaces/widgets/

@Pierrci
Copy link
Member

Pierrci commented Jul 26, 2021

What benefits do you see @julien-c in keeping interfaces and move widgets in it?

Moving interface inside widgets/lib would simplify a lot the build setup (from my tests we can remove the second half of the steps - maybe more), but the opposite doesn't change anything, except a few relative paths that lose a /interface in them...

(w/ the current setup - same w/ simply moving widgets in interfaces - even the basic svelte-kit package needs tweaking b/c what's in interfaces can't be imported properly, and typings generation is a mess)

@julien-c
Copy link
Member

Ok ok, I haven't tested the whole tooling so let's go with what @Pierrci preconizes. 🙏

@mishig25
Copy link
Contributor Author

@Pierrci in terms for publishing the widgets, what should be the next step:
Option A: use the build script plus svelte-kit package method suggested by this PR
Option B: something else, as referred:

(from my tests we can remove the second half of the steps - maybe more

@Pierrci
Copy link
Member

Pierrci commented Jul 29, 2021

@mishig25 option A, but following #227 we can simplify what's done in this PR and remove a few steps from the build.js file since you'll find that moving interfaces inside lib/ makes the svelte-kit package command runs more as one would expect (files aren't outputted in 2 different dirs inside package/ anymore for example).

Ideally we would end up exposing InferenceWidget, ModelPipelineTag, ModelPipelineTag and WidgetHeader from the "root" of the package, and everything that's in interfaces from huggingface-widgets/interfaces? You'll probably need to create one root index.ts and another one in interfaces (they talk about creating an index.ts or index.svelte in https://kit.svelte.dev/docs#packaging, but it's a pretty common way of packaging anyway).

widgets/package.json Outdated Show resolved Hide resolved
@mishig25 mishig25 marked this pull request as ready for review July 30, 2021 15:51
@mishig25 mishig25 requested a review from Pierrci July 30, 2021 15:51
widgets/build.js Outdated Show resolved Hide resolved
widgets/package.json Outdated Show resolved Hide resolved
widgets/package.json Outdated Show resolved Hide resolved
Comment on lines +7 to +10
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictBindCallApply": true,
"lib": ["es6", "es2016", "es2017", "es2018", "esnext"]
Copy link
Member

Choose a reason for hiding this comment

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

I think the lib entry can be removed here no? (see https://www.typescriptlang.org/tsconfig#target: "Changing target also changes the default value of lib.")

@mishig25
Copy link
Contributor Author

mishig25 commented Sep 9, 2021

@Pierrci @beurkinger
Since internal was merged, I've advanced this PR.
To remind:

  1. This PR published widgets as a npm package https://www.npmjs.com/package/huggingface-widgets
  2. Removed the $lib usage since Resolve aliases while running svelte-kit package sveltejs/kit#1950 is still open. (You mentioned about it here)
  3. Files that are being export are:
".": "./InferenceWidget/InferenceWidget.svelte",
"./WidgetHeader.svelte": "./InferenceWidget/shared/WidgetHeader/WidgetHeader.svelte",
"./ModelPipelineIcon.svelte": "./ModelPipelineIcon/ModelPipelineIcon.svelte",
"./ModelPipelineTag.svelte": "./ModelPipelineTag/ModelPipelineTag.svelte",
"./inferenceSnippets": "./inferenceSnippets/index.js",
"./inferenceSnippets/inputs": "./inferenceSnippets/inputs.js",
"./interfaces/DefaultWidget": "./interfaces/DefaultWidget.js",
"./interfaces/Language": "./interfaces/Language.js",
"./interfaces/Libraries": "./interfaces/Libraries.js",
"./interfaces/Types": "./interfaces/Types.js"

And it gets consumed as:

import InferenceWidget from "huggingface-widgets";
import ModelPipelineTag from "huggingface-widgets/ModelPipelineTag.svelte";
import { Language } from "huggingface-widgets/interfaces/Language";
import type { PipelineType } from "huggingface-widgets/interfaces/Types";
...

  1. Checkout its companion PR internally here

Copy link
Member

@Pierrci Pierrci left a comment

Choose a reason for hiding this comment

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

We're almost there! :)

Comment on lines +3 to +5
import type { ModelData } from "../../src/lib/interfaces/Types";

import InferenceWidget from "$lib/InferenceWidget/InferenceWidget.svelte";
import InferenceWidget from "../../src/lib/InferenceWidget/InferenceWidget.svelte";
Copy link
Member

Choose a reason for hiding this comment

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

why not ../lib directly here?

delete pkg.type;
fs.writeFileSync(pathtToJson, JSON.stringify(pkg));

copyRecursiveSync("../docs", "./package/docs");
Copy link
Member

Choose a reason for hiding this comment

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

As discussed in https://github.com/huggingface/moon-landing/pull/1172, let's keep the docs separate, at least for now.

Comment on lines +58 to +61
"./interfaces/DefaultWidget": "./interfaces/DefaultWidget.js",
"./interfaces/Language": "./interfaces/Language.js",
"./interfaces/Libraries": "./interfaces/Libraries.js",
"./interfaces/Types": "./interfaces/Types.js"
Copy link
Member

@Pierrci Pierrci Sep 17, 2021

Choose a reason for hiding this comment

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

Can we have an interfaces/index.js that re-exports those rather, so that we can do import { DefaultWidget, Language, ... } from "huggingface-widgets/interfaces"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it make sense to do so? because, the use case has always been:
import { x, y, z } from Interfaces or Language,
not import Interfaces

Copy link
Member

@Pierrci Pierrci Sep 17, 2021

Choose a reason for hiding this comment

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

Yes, you're right actually, let's keep it that way! I think I'm feeling the effects of the jetlag x)

"version": "0.0.1",
"version": "0.15.0",
"type": "module",
"main": "./InferenceWidget/InferenceWidget.svelte",
Copy link
Member

Choose a reason for hiding this comment

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

main is supposed to be something in plain js I think (that's why you can add a specific svelte entry for the "non-compiled" version), but for now, we can leave it as is - and add a "compiled" version later if there is a demand for it.

@@ -1,10 +1,23 @@
{
"name": "huggingface-widgets",
"version": "0.0.1",
"version": "0.15.0",
Copy link
Member

Choose a reason for hiding this comment

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

What about bumping the version to 1.0.0 when we release for good? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea!

@mishig25
Copy link
Contributor Author

Closing it for now

@mishig25 mishig25 closed this Oct 11, 2021
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.

4 participants