-
Notifications
You must be signed in to change notification settings - Fork 238
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
Unable to build TypeScript program using private scope modules #1363
Comments
Thanks for the example. On macOS, the
I assume this matches what you see. We'll take a look. |
Yes, and this is because the |
As the support for private scope modules was introduced as part of the work on Like Node, mcpack does not handle TypeScript sources. You have to run That uses a
There is some support for TypeScript in "build": {
"SRC": "./src"
},
"typescript": {
"tsconfig": {
"compilerOptions": {
"paths": {
"#example": [ "$(SRC)/example/index" ]
}
}
}
} Here is private-scope-example-3 that builds with:
That revealed a bug in Finally, about the "artificial path”. Private module specifiers look absolute but are relative to their package. XS does not support Node packages at runtime, so You are definitely working at the outer limits so this stuff is a definitely a bit subtle. I hope this helps. |
Thanks for taking the time to look at this. I agree that I'm on the outer limits - so I appreciate your time all the more! I can't use I have an extensive platform portability library that provides all the cross-platform services I depend on in Moddable with compatible implementations in Node (and also do things like simulate Flash on simulator using LittleFS and emulate NOR functionality). My system supported shared code (across all platforms) and XS-ESP32 specific code, XS-SIM specific code, and node-specific code as needed. This allows me to use Jest (on Node, and my private Jest implementation on XS), and the amazing WallabyJS product, to execute my hundreds (soon > 1000) unit and integration tests on Node with rapid iteration, on simulator for fast XS validation, and then on the true target platform (ESP32) for final validation, all 100% automatically (which, FYI, is why I asked for those This is all working perfectly now that we have private scopes working with Moddable for JavaScript (thank you!), with the one hiccup being that the Moddable-generated If my understanding is correct, anybody who wants private scope modules (not using NPM packages) with TypeScript on Moddable will encounter this issue. But seeing as I have a solution that works, and nobody else appears to be using TypeScript with private scope modules right now, perhaps it's best to drop this issue until others also encounter it? Especially since there isn't an obvious answer (at least to me), aside from a post-processor/filter. Thanks again. I'll leave it up to you if you want to close this or leave it dangling open for future reference. |
You can have a look at #1434 (comment) I created a starter template that simplifies development in module resolution in TS. Also check HipsterBrown/xs-dev#186 |
Build environment: Windows (I believe any)
Moddable SDK version: Requires recent version that supports private scope module build system changes
Target device: Any
Description
Private scope module resolution with Moddable requires an artificial path to create a common root (such as implemented by
mcpack
), which breaks TypeScript compilation. For example, to define the private scope package#example
one might use amanifest.json
containing amodules
section similar to this:The artificial path component
root
is used to assist module resolution in translating between the file system pathing of JS and the namespace resolution used in Moddable.mcconfig
then carries these artificial roots over to the generatedtsconfig.json
file:This results in a TypeScript compilation error such as:
Steps to Reproduce
mcconfig -m -d
Thoughts
I have not come up with an obvious/clean way to indicate to
mcconfig
that theroot
is artificial. While the best solution may be to change module resolution to not need artificial roots (easier to implement/understand for devs), that feels like a high-risk and low-reward endeavor. My solution has been to change thetypescript
/compiler
option inmanifest.json
to run a small script that front-endstsc
and removes the artificial roots fromtsconfig.json
. This is working well for me, but it's a hack and not generic enough to be useful for others.The text was updated successfully, but these errors were encountered: