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: built-in web bundle #339

Merged
merged 9 commits into from
Dec 27, 2022
Merged

feat: built-in web bundle #339

merged 9 commits into from
Dec 27, 2022

Conversation

roziscoding
Copy link
Contributor

Besided being called inside bundle-all.sh, deno task bundle-web can also be used to create the new bundle.
Two files will be created inside the out folder: web.js and web.d.ts

The web.d.ts file only re-exports everything from out/mod.d.ts. This
file is needed because typescript refuses to search for types for the
web.js file in anywhere other than a web.d.ts placed next to it.
That behavior should be overriden by the typesVersions property in
package.json, but for some reason it's not. The typesVersions
property is necessary to make typescript detect the /web entrypoint,
though.

Besided being called inside `bundle-all.sh`, `deno task bundle-web` can also be used to create the new bundle.
Two files will be created inside the `out` folder: web.js and web.d.ts

The `web.d.ts` file only re-exports everything from `out/mod.d.ts`. This
file is needed because typescript refuses to search for types for the
`web.js` file in anywhere other than a `web.d.ts` placed next to it.
That behavior should be overriden by the `typesVersions` property in
`package.json`, but for some reason it's not. The `typesVersions`
property is necessary to make typescript detect the `/web` entrypoint,
though.
@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2022

Codecov Report

Base: 36.93% // Head: 36.93% // No change to project coverage 👍

Coverage data is based on head (de8cac9) compared to base (63ac43a).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #339   +/-   ##
=======================================
  Coverage   36.93%   36.93%           
=======================================
  Files          17       17           
  Lines        4364     4364           
  Branches      157      157           
=======================================
  Hits         1612     1612           
  Misses       2750     2750           
  Partials        2        2           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

src/types.web.ts Outdated Show resolved Hide resolved
@KnorpelSenf
Copy link
Member

@roziscoding LMK if you need help fixing up CI. I'll be back later today or maybe tomorrow. I'll also want to test everything thoroughly once more.

@roziscoding
Copy link
Contributor Author

I guess we don't need to backport platform.web.ts, do we?
The web code has nothing to do with the backport code

Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

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

LGTM but will test all possible combinations manually before approving.

  • from npm tarball
  • from npm link
  • from GitHub install

and

  • from a JS file
  • from an MJS file
  • from a CJS file
  • from a TS file
  • from TS build output

and

  • in Deno
  • in Node
  • in a browser script
  • in a browser module
  • in a browser with Deno tooling
  • in a browser with Node tooling

and

  • compile time
  • runtime

@roziscoding
Copy link
Contributor Author

Will ESM work on browser scripts?

@KnorpelSenf
Copy link
Member

No, that's one of the impossible combinations, I think. I'll test it.

@KnorpelSenf KnorpelSenf changed the title FEAT: builtin web bundle feat: built-in web bundle Dec 27, 2022
Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

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

Amazing changes! I tried this and one can now easily import { Bot } from "grammy/web" with VuePress 2.0 in order to run a bot inside the browser. Thank you so much!

@KnorpelSenf KnorpelSenf merged commit 1bf565f into main Dec 27, 2022
@KnorpelSenf KnorpelSenf deleted the feat/builtin-web-bundle branch December 27, 2022 15:08
@KnorpelSenf
Copy link
Member

@all-contributors add @roziscoding for this idea!

@allcontributors
Copy link
Contributor

@KnorpelSenf

@roziscoding already contributed before to ideas

Comment on lines +12 to +16
if (specifier.endsWith(".deno.ts")) {
const baseLength = specifier.length - ".deno.ts".length;
specifier = specifier.substring(0, baseLength) + ".web.ts";
}
return cache.load(specifier);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (specifier.endsWith(".deno.ts")) {
const baseLength = specifier.length - ".deno.ts".length;
specifier = specifier.substring(0, baseLength) + ".web.ts";
}
return cache.load(specifier);
return cache.load(specifier.replace(/\.deno\.ts$/, ".web.ts"));

Copy link
Member

Choose a reason for hiding this comment

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

Do you think that code is more readable?

@KnorpelSenf
Copy link
Member

@KnorpelSenf

@roziscoding already contributed before to ideas

oh … right, good

@roziscoding
Copy link
Contributor Author

Happy to see this merged! :D

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

4 participants