Skip to content

Add option to override locateFile for loading WASM files from custom sources#53

Closed
ronkorland wants to merge 5 commits into
moshen:masterfrom
ronkorland:locate-file
Closed

Add option to override locateFile for loading WASM files from custom sources#53
ronkorland wants to merge 5 commits into
moshen:masterfrom
ronkorland:locate-file

Conversation

@ronkorland

@ronkorland ronkorland commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Adds support for overriding the locateFile function to control how the WASM file is loaded (e.g., from local path, CDN, or Blob URL).

Backward-compatible and doesn’t change existing behavior.

@moshen moshen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is a great idea, and would certainly make the browser use-case for the module easier. However as it appears, I'm not exactly sure it would work as implemented.

Also please add a description of the option to the README.

Comment thread src/index.ts Outdated
loadDefaultMagicfile?: boolean;
magicFiles?: Uint8Array[];
stdio?: StdioOverrideFunction;
locateFile?: () => string,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should be changed to an explicit function type signature, or simply accepting a string and providing a function below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I update the README + update the function signature to locateFile?: (path: string, prefix: string) => string

Comment thread src/index.ts Outdated
): Promise<WASMagic> {
const Module = await libmagicFactory();
const Module = await libmagicFactory({
locateFile: options.locateFile,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

locateFile is define as function in the WASMagicOptions type

@ronkorland

Copy link
Copy Markdown
Contributor Author

This is a great idea, and would certainly make the browser use-case for the module easier. However as it appears, I'm not exactly sure it would work as implemented.

Also please add a description of the option to the README.

I update the README file, please validate again

@ronkorland

Copy link
Copy Markdown
Contributor Author

@moshen can you please take a look at my latest changes?

@moshen

moshen commented Oct 18, 2025

Copy link
Copy Markdown
Owner

@ronkorland Will do. Had to fix publishing with the recent npm changes.

@ronkorland

Copy link
Copy Markdown
Contributor Author

@ronkorland Will do. Had to fix publishing with the recent npm changes.

@moshen do you think you can release/merge this PR this week?

@ronkorland

Copy link
Copy Markdown
Contributor Author

@moshen I’d really like to use this change is there anything I can do to help move this PR forward or get it merged and released?

@moshen

moshen commented Nov 15, 2025

Copy link
Copy Markdown
Owner

Sorry I haven't gotten back to you. It's been a busy month unfortunately. I'm circling back to this now and was testing this out locally. I was going to flatten the property into the larger config object. Any objections?

@moshen

moshen commented Nov 16, 2025

Copy link
Copy Markdown
Owner

@ronkorland this is what I was thinking: #55

@ronkorland

Copy link
Copy Markdown
Contributor Author

I start with flatten object but I think it not I saw their is many properties that we can pass to the libmagicFactory

@moshen

moshen commented Nov 16, 2025

Copy link
Copy Markdown
Owner

My initial reaction is that there currently aren't any that are needed on Module, but several that would break the usage of this library. Accepting an object in Javascript and passing it whole into the constructor means potential issues (intentionally or unintentionally) that I'm not keen on supporting.

I'm much more of a fan of being explicit in what's accepted than implicit here.

Since it sounds like you're using this on the frontend, you might want fetchSettings exposed, but that's a separate config function.

@ronkorland

Copy link
Copy Markdown
Contributor Author

@moshen ok, lets continue with your PR

@moshen

moshen commented Nov 17, 2025

Copy link
Copy Markdown
Owner

If it needs more options exposed can do that later. I'm of two minds on it. Either expose everything from Module with a "you're on your own" warning, or just expose what's useful.

moshen added a commit that referenced this pull request Nov 17, 2025
- Add option to override locateFile for loading WASM files from custom sources (e.g., local path or remote URL)

Co-authored-by: Ron Korland <[email protected]>
@moshen

moshen commented Nov 17, 2025

Copy link
Copy Markdown
Owner

Closed by merging #55

@moshen moshen closed this Nov 17, 2025
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.

2 participants