ember-cli-typescript
ember-cli-typescript copied to clipboard
Does not work with monorepo / yarn workspaces
I do have a setup with a monorepo / yarn workspace and lerna. Mostly identical with ember-decorators
repo. For reference I added lerna.json
and package.json
(for the workspace) as reference below. The structure typically looks like this:
[root]
|- packages
|-- packageA
|-- packageB
|- node_modules
|- package.json
`- lerna.json
So, when packageA
requires ember-cli-typescript
it is installed to [root]/node_modules/ember-cli-typescript
and so is typescript
. Hence the watcher is setup to watch in the folder [root]/packages/packageA/node_modules/***
which doesn't exist.
As such the watcher tries to endlessly find something that doesn't exist. There should be some mechanism first to detect, wether this is a yarn workspace and an which folders to look for (it still can be the package related node_modules
folder).
// lerna.json
{
"lerna": "2.11.0",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
],
"version": "0.0.0"
}
// package.json
{
"private": true,
"devDependencies": {
"lerna": "^2.11.0"
},
"workspaces": [
"packages/*"
]
}
Have you tried the branch in #223?
After getting it the compilation step to work, there's another issue with the current setup (previously mentioned on slack).
If one has a workspace with multiple packages (A, B), where A depends on B and both of them use cli-typescript, then typescript files from B aren't compiled because:
error TS6059: File '/path/to/projectB/addon/utils/something.ts' is not under 'rootDir' '/path/to/projectA'. 'rootDir' is expected to contain all source files.
Basically typescript expects any typescript file to lie under A which isn't the case as B is in the workspace root.
workspace-root
|- A
|- B
This is the case with yarn as yarn workspaces simply link node_modules. I'm not sure if the same behavior exists when using lerna/npnm
Is there any solution to this? Followed the same path, with #223 compilation started to work, but I stuck on converting ember addons in yarn workspace to typescript. Having the TS6059 issue when building ts project that depends on ts addons.
I'm not sure what work (if any) will be necessary on this end to support monorepos, but you might start by experimenting with the new Project References feature in TS3.0.
@gossi @loginovma were you able to derive a solution from the suggestions above or otherwise? I'm setting up a similar monorepo with lerna and want to see what the community has arrived at
I currently solve it by not using ember-cli-typescript for compilation, but ember-cli-babel@7
with the TypeScript transform.
// ember-cli-build.js or index.js in addons
{
'ember-cli-babel': {
includePolyfill: true,
extensions: ['js', 'ts']
},
babel: {
sourceMaps: 'inline',
plugins: [
'@babel/transform-typescript',
['@babel/proposal-decorators', { legacy: true }],
['@babel/proposal-class-properties', { loose: true }],
'@babel/proposal-object-rest-spread'
]
}
}
However, instead of manually configuring Babel, I recommend trying out https://github.com/typed-ember/ember-cli-typescript/pull/333, which will essentially do the same, but better. 😄
And then in the tsconfig.js
I manually setup paths for IntelliSense:
{
"paths": {
"client/tests/*": ["tests/*"],
"client/mirage/*": ["mirage/*"],
"client/*": ["app/*"],
"@clark/some-addon/*": ["../client-packages/addons/some-addon/addon/*"],
"@clark/another-addon/*": ["../client-packages/addons/another-addon/addon/*"],
// ...
"*": ["types/*"]
}
}
I was gonna write a script to automate the generation of these paths, but I couldn't be be bothered to do so, yet. 😄
I'll be the first to say I haven't given any real deep thought to the details of this setup, but I threw together a workspace-based repo and everything appeared to work pretty nicely out of the box (beyond needing to set up some tsconfig.json
paths) with the current ember-cli-typescript@2
beta.
https://github.com/dfreeman/ember-workspace-playground
Awesome! @dfreeman any concrete ETA on when ember-cli-typescript@2
will be released?
Thanks for clarifying @buschtoens
As annoying as I know this is, the answer is "when it's ready." You can track progress over on #333 🙂
We're still getting some real-world burn in with the new implementation, and we also have a few more things to clean up both in the code and in terms of documenting the migration process.
@buschtoens I'm confused why you need to specify the the paths to your other modules because when you run a yarn install
at the root of your monorepo, it will create symlinks in the node_modules
directory to each of your packages in the mono repo (rather than the actual, built library files). Given that, it's supposed to "just work."
ember-cli-typescript
itself works fine with Yarn (and nom and pnpm) workspaces and has since v2. Additionally, we now recommend that people switch to using ember-cli-babel
and running glint
or tsc
directly. In that case, Glint and TypeScript’s built-in support for project references comes “for free”.