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 a manifest.json containing a modules section similar to this:
"modules": {
"root/main": "./src/main",
"root/#example": "./src/example/index",
"example/do-something": "./src/example/do-something"
}
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 generated tsconfig.json file:
"compilerOptions": {
"paths": {
"root/main": ["/some/path/main"],
"root/#example": ["/some/path/example/index"],
"example/do-something": ["/some/path/example/do-something"]
}
}
This results in a TypeScript compilation error such as:
# tsc tsconfig.json
src/main.ts:1:29 - error TS2792: Cannot find module '#example'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
1 import { doSomething } from '#example';
~~~~~~~~~~
Steps to Reproduce
- Clone this repo
- Switch to the "typescript" branch
- Run
mcconfig -m -d
Thoughts
I have not come up with an obvious/clean way to indicate to mcconfig that the root 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 the typescript / compiler option in manifest.json to run a small script that front-ends tsc and removes the artificial roots from tsconfig.json. This is working well for me, but it's a hack and not generic enough to be useful for others.
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#exampleone might use amanifest.jsoncontaining amodulessection similar to this:The artificial path component
rootis used to assist module resolution in translating between the file system pathing of JS and the namespace resolution used in Moddable.mcconfigthen carries these artificial roots over to the generatedtsconfig.jsonfile:This results in a TypeScript compilation error such as:
Steps to Reproduce
mcconfig -m -dThoughts
I have not come up with an obvious/clean way to indicate to
mcconfigthat therootis 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/compileroption inmanifest.jsonto run a small script that front-endstscand 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.