-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
Expose the "lib" folder to consumers #1424
Comments
With the introduction of ESM you cannot just import from some sub-path. Basically you propose to re-enable that, but I think there are good reasons to keep the implementation private. Splitting everything is a internal (private) part and in a not so private part, I am not so sure that is the way to go. If I would change any of my internally functionality I would break API compatibility. And let's expose that in a clean and documented way. Do you need something like?: function isMimeTypeSupported(mime) function isFileSupported(path) Can you create a PR? |
@Borewit The "exports" field appears to be a Node.js thing, not an "ESM" thing. I'm using Deno, which only uses ESM, and that's not required at all. |
But that's a good idea. I can work on a PR. |
@Borewit I'm a bit conflicted on this. It may be smarter for users to catch the error when a file cannot be parsed. This would require a custom error class for the Otherwise, here's the basic code I would add. I assume it would go in /**
* Determines whether the {@link filepath} is supported for parsing.
* @param filepath Path, filename or extension of a file.
*/
export function isFileSupported(filepath: string) {
return Boolean(ParserFactory.getParserIdForExtension(filepath));
} |
It is already close to do something like that: music-metadata/lib/ParserFactory.ts Line 100 in 7cdebd1
& music-metadata/lib/ParserFactory.ts Line 105 in 7cdebd1
If we would throw an error with a good described error code, would that provide you the feedback you are looking for? What is the objective? |
the object is to throw a subclass of class ParserError extends Error { /* ... */ }
async function parse() {
throw new ParserError("...");
}
try {
await parse();
} catch (error) {
if (error instanceof ParserError) {
// This must be from music-metadata
} else {
throw error;
}
} |
@Borewit What do you think about using a custom error class? As it stands, I still cannot tell which errors are coming from this library in particular. Also, I just want to reiterate that the "exports" field is a Node.js creation, meant as an alternative to the "main" field. It is not related to ESM, and is not required. |
Sorry for this very late reply, custom error class sounds good to me. |
Scenario
The current
package.json
limits access to a single file, via a conditional export. This entry-point is the only file that consumers may import.music-metadata/package.json
Lines 14 to 19 in 72a4006
Personally, I was trying to import
./lib/ParserFactory.js
, so I could check whether a given format is supported.Solutions
The text was updated successfully, but these errors were encountered: