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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export already packaged lib folder #283

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

espretto
Copy link

@espretto espretto commented May 8, 2024

Hello 馃憢 ,
the lib folder is part of the npm package as configured in the package.json field files. However it is not accessible unless listed in the exports field. Currently I have to override my bundlers dependency resolution to access the folder's contents.

@espretto espretto changed the title export ./lib folder from npm package Export already packaged lib folder May 8, 2024
@12wrigja
Copy link
Contributor

12wrigja commented May 8, 2024

We originally include our sources in the bundle so they can be referenced using source maps when debugging, not to be consumed directly by bundlers.

Can you help me understand why you can't apply the transpilation to the relevant bundled ESM in dist, which is the intended artifact to consume? My recollection is that running the Babel transform for JSBI -> native bigint over that file will get you want you want (based on my previous comments here), though the thread there implies that configuring webpack in practice (vs my toy example) is non-trivial.

@espretto
Copy link
Author

I didn't realize the ts sources where included for debugging purposes. Makes sense.

Also, I didn't think of using the babel plugin on the ESM build but yes, that should definitely work. Using ESM modules however, is still a little tricky to configure when targeting non-ESM environments.

My intention is to create a partial polyfill by picking only those parts of the polyfill that I need in my codebase. Since tree-shaking is not really an option w/ Temporal's OOP design and its cross-referencing conversion methods, this approach seems to hold the best balance between flexibility/bundle-size and spec compliance.

I am aware that this is branching out quite far from where I started.

@espretto
Copy link
Author

Here is what my partial polyfill looks like. This would become possible if the ./lib folder were accessible.

import * as PlainDateLib from "@js-temporal/polyfill/lib/plaindate";

export namespace Temporal {
  /** @see https://www.typescriptlang.org/docs/handbook/namespaces.html#aliases */
  export import PlainDate = PlainDateLib.PlainDate;
}

Of course I'll have to setup my toolchain to be compatible w/ the sourcecode.

@12wrigja
Copy link
Contributor

12wrigja commented May 20, 2024

My intention is to create a partial polyfill by picking only those parts of the polyfill that I need in my codebase. Since tree-shaking is not really an option w/ Temporal's OOP design and its cross-referencing conversion methods, this approach seems to hold the best balance between flexibility/bundle-size and spec compliance.

The intent seems reasonable, but doing this by depending on a released artifact seems like the wrong approach. Instead, given you are effectively forking the polyfill, I would suggest you depend on our repository directly using a git URL dependency: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies

Note that we give absolutely no guarantees about the content of our repository.

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

2 participants