-
Notifications
You must be signed in to change notification settings - Fork 147
Load file(s) outside package as ESM #77
Comments
Hi @mAAdhaTTah! There isn't at the moment. However, I'm open to API suggestions or heuristics to enable it. What I want to avoid is accidentally stepping on packages toes in production. So if there's a way to cater to CLIs without stepping on prod deps that would rock 🤘 |
Perhaps resolvable after we get some hooks (#75)? Assuming that's not happening soon though. Alternatively, possible to |
That could work! I'll kick it around ⚽️ |
Cool. Happy to beta test an API if you get something working. |
The more I'm thinking about it.... since we've changed the in-file API to be a loader factory you're opting-in by using the produced loader. That means we could make it so that: const LoaderFactory = require("@std/esm")
const loaderA = LoaderFactory(module)
const loaderB = LoaderFactory(module, options) which allow custom options (different than those specified in your package.json) and since you're opting-in by using the produced loader I can remove the package guard per module loaded after. |
Yeah, that would work. Is it currently possible to opt-out of the package guard per-module now via package.json? Or that would have to be added as part of this proposal/API? Also, if this is going to result in API changes, can we reopen the issue? |
If no extensions are used, this seems doable. Otherwise people will need to start guarding against the extensions. I would suggest adding a |
Can you clarify "extensions" in the above comment? File extensions or node extensions or...? |
@mAAdhaTTah non-spec behavior. The unlockables |
So there is no way to load import property from 'lodash-es/property'
// { import baseProperty from './_baseProperty.js';
// SyntaxError: Unexpected token import The local files are working |
Not without the requesting package opting-in. This issue will enable it through an options param though. It's already committed in the master branch btw. I just have to finish up unit tests to resolve this issue. |
Cool, thanks @jdalton I will be watching this thread, maybe soon my dream of rolling into smallest possible bundles will come true! Then I will build my library and roll in all dependencies to have 0 production deps. |
I couldn't find any packages that are distributed as |
v0.8.0 is released 🎉 |
Use case: Building a CLI tool where I'd like the rc file to be ESM.
Because
@std/esm
's behavior is to scope the loader to just the package, I getunexpected token import
whenrequire()
/import()
'ing the file. Is there any way to mark that this file should be parsed as ESM?The text was updated successfully, but these errors were encountered: