Skip to content

Conversation

@NemoStein
Copy link

The current strategy for importing files from CLI (e.g.: jscad ./model.js) first converts the source path argument to absolute (if not absolute already) and then await import()s it

The issue is that import() only accepts URLs and, in Windows, the absolute path of a file is not an URL as it starts with a partition letter (e.g.: c:/path/to/file.js)
The proper way of handling this is with the file:// protocol

This PR converts the absolute path to a file:// URL before calling import()

note: pnpm test failed to run with error Based on your configuration, 7 test files were found, but did not match the CLI arguments: and, as such, no test was run
Regardless, I tested the implementation in Windows and Ubuntu (WSL) and both yielded a proper .stl file

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Does your submission pass tests?

@z3dev
Copy link
Member

z3dev commented Oct 4, 2025

@NemoStein Cool. An actual fix to V3. Even more cool!

I'll give this a try but the changes look fine. I'm surprised that the test suite could not be executed. Let's see what the CI does.

@z3dev z3dev requested review from platypii and z3dev October 4, 2025 02:55
@z3dev
Copy link
Member

z3dev commented Oct 4, 2025

Dynamic Import

The module to import from. The evaluation of the specifier is host-specified, but always follows the same algorithm as static import declarations.

Static Import

The module to import from. Only single quoted and double quoted string literals are allowed. The evaluation of the specifier is host-specified. Most hosts align with browsers and resolve the specifiers as URLs relative to the current module URL (see import.meta.url).

Import.meta

import.meta.resolve() is a built-in function defined on the import.meta object of a JavaScript module that resolves a module specifier to a URL using the current module's URL as base.

More tricks are available via import.meta.resolve()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve

@z3dev
Copy link
Member

z3dev commented Oct 4, 2025

@NemoStein Have you played with import.meta.url and import.meta.resolve()?

@z3dev
Copy link
Member

z3dev commented Dec 13, 2025

@platypii what do you think? these changes seems appropriate but may not be the ultimate solution.

@z3dev
Copy link
Member

z3dev commented Jan 3, 2026

@NemoStein What do you think about my comment above?

@NemoStein
Copy link
Author

NemoStein commented Jan 3, 2026

The import.meta.url is the URL of the current module (file) running the script and import.meta.resolve() tries to resolve a relative path (relative to import.meta.url) to an absolute path. But the issue here is that dynamic import() (and also static import * form '') don't accept absolute paths, only URLs.
In Unix, paths can be valid URLs, but not in Windows, hence, the proper fix is to always convert paths to URLs.

... may not be the ultimate solution.

I can't see why, since it's only appied to loading JS files in CLI

Copy link
Member

@z3dev z3dev left a comment

Choose a reason for hiding this comment

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

@NemoStein Thanks for the fixes.

FYI, I have some additional changes in progress for the CLI, and will test on both Linux and Windows. I'll let you know if there are any issues.

@z3dev z3dev merged commit 8cf518a into jscad:V3 Jan 4, 2026
2 checks passed
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