Skip to content

Conversation

@rvanasa
Copy link
Contributor

@rvanasa rvanasa commented Oct 24, 2025

Possible (hacky) solution for dfinity/vscode-motoko#394. Tested in VS Code and works as expected.

Adds a setBlobImportPlaceholders(boolean) function to moc.js which ignores unresolved blob: imports (trapping at runtime) when enabled. This is a workaround for the virtual file system currently only including Motoko and Candid files from the VS Code workspace.

@rvanasa rvanasa requested a review from a team as a code owner October 24, 2025 18:44
@rvanasa rvanasa requested a review from ggreif October 24, 2025 18:44
@rvanasa rvanasa changed the title Add blob: import placeholder flag for moc.js feat(moc.js): add blob: import placeholder flag for moc.js Oct 24, 2025
@rvanasa rvanasa changed the title feat(moc.js): add blob: import placeholder flag for moc.js feat(moc.js): add blob: import placeholder setting Oct 24, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

Comparing from 82171b1 to 044e801:
The produced WebAssembly code seems to be completely unchanged.
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

Copy link
Contributor

@ggreif ggreif left a comment

Choose a reason for hiding this comment

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

One could also use https://ocsigen.org/js_of_ocaml/latest/api/js_of_ocaml/Js_of_ocaml/Sys_js/index.html#val-create_file
to just male the file and then let the rest of the mechanism import it.

And there is the mount function too, which would actually allow importing the exact content.

Edit: Oh, I see, having that module conditionally included may be tricky.

assert T.(t = Prim Blob);
blobE contents
if !Mo_config.Flags.blob_import_placeholders then
raise (Invalid_argument ("blob import placeholder"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, block the desugaring!

Copy link
Contributor

@ggreif ggreif left a comment

Choose a reason for hiding this comment

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

LGTM!

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